2 * Copyright (C) 2006 Andriy Rysin (rysin@kde.org)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <QToolButton>
27 #include <ksystemtrayicon.h>
29 #include "kxkbconfig.h"
37 /* This class is responsible for displaying flag/label for the layout,
38 catching keyboard/mouse events and displaying menu when selected
39 This class is abstract and subclasses define how exactly UI will be shown
41 class KxkbWidget
: public QObject
46 enum { START_MENU_ID
= 100, CONFIG_MENU_ID
= 130 };
47 enum { INDICATOR_ONLY
=1, NO_MENU
= 2, MENU_LAYOUTS_ONLY
= 3, MENU_FULL
=4 };
48 enum { WIDGET_TRAY
=0, WIDGET_LABEL
=1 };
50 void initLayoutList(const QList
<LayoutUnit
>& layouts
, const XkbRules
& rule
);
51 void setCurrentLayout(const LayoutUnit
& layout
);
52 void setError(const QString
& layoutInfo
="");
53 void setShowFlag(bool showFlag
) { m_showFlag
= showFlag
; }
54 virtual void setVisible(bool visible
) = 0;
57 void menuTriggered(QAction
*);
63 KxkbWidget(int controlType
);
64 virtual QMenu
* contextMenu() = 0;
65 virtual void setToolTip(const QString
& tip
) = 0;
66 virtual void setPixmap(const QPixmap
& pixmap
) = 0;
67 virtual void setText(const QString
& text
) = 0;
71 QMap
<QString
, QString
> m_descriptionMap
;
72 QList
<QAction
*> m_actions
;
73 QAction
* m_configSeparator
;
78 System tray icon to show layouts
80 class KxkbSysTrayIcon
: public KxkbWidget
85 KxkbSysTrayIcon(int controlType
=MENU_FULL
);
86 ~KxkbSysTrayIcon() { delete m_indicatorWidget
; }
89 QMenu
* contextMenu() { return m_indicatorWidget
->contextMenu(); }
90 void setToolTip(const QString
& tip
) { m_indicatorWidget
->setToolTip(tip
); }
91 void setPixmap(const QPixmap
& pixmap
);
92 void setText(const QString
& /*text*/) { } //m_indicatorWidget->setText(text); }
93 void setVisible(bool visible
) { m_indicatorWidget
->setVisible(visible
); }
96 void trayActivated(QSystemTrayIcon::ActivationReason
);
99 KSystemTrayIcon
* m_indicatorWidget
;
104 Flexible widget to show layouts
106 class KxkbLabel
: public KxkbWidget
111 enum { ICON
= 1, TEXT
= 2 };
113 KxkbLabel(int controlType
=MENU_FULL
, QWidget
* parent
=0);
114 virtual ~KxkbLabel() { delete m_indicatorWidget
; }
115 QWidget
* widget() { return m_indicatorWidget
; }
118 QMenu
* contextMenu() { return m_menu
; }
119 void setToolTip(const QString
& tip
) { if (m_displayMode
==ICON
) m_indicatorWidget
->setToolTip(tip
); }
120 void setPixmap(const QPixmap
& pixmap
);
121 void setText(const QString
& text
) { if (m_displayMode
==TEXT
) m_indicatorWidget
->setText(text
); }
122 void setVisible(bool visible
) { m_indicatorWidget
->setVisible(visible
); }
125 void contextMenuEvent(const QPoint
& pos
);
129 QToolButton
* m_indicatorWidget
;