not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / kxkb / kxkbwidget.h
blobad18b89329b5430277a6ca8790c066f13c388933
1 /*
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.
20 #ifndef KXKBWIDGET_H
21 #define KXKBWIDGET_H
24 #include <QList>
25 #include <QToolButton>
27 #include <ksystemtrayicon.h>
29 #include "kxkbconfig.h"
32 class QMenu;
33 class XkbRules;
34 class QAction;
35 class QPixmap;
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
43 Q_OBJECT
45 public:
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;
56 signals:
57 void menuTriggered(QAction*);
58 void iconToggled();
60 protected:
61 int m_controlType;
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;
69 private:
70 bool m_showFlag;
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
82 Q_OBJECT
84 public:
85 KxkbSysTrayIcon(int controlType=MENU_FULL);
86 ~KxkbSysTrayIcon() { delete m_indicatorWidget; }
88 protected:
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); }
95 protected slots:
96 void trayActivated(QSystemTrayIcon::ActivationReason);
98 private:
99 KSystemTrayIcon* m_indicatorWidget;
104 Flexible widget to show layouts
106 class KxkbLabel : public KxkbWidget
108 Q_OBJECT
110 public:
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; }
117 protected:
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); }
124 protected slots:
125 void contextMenuEvent(const QPoint& pos);
127 private:
128 int m_displayMode;
129 QToolButton* m_indicatorWidget;
130 QMenu* m_menu;
133 #endif