1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
//
// C++ Implementation: kxkbtraywindow
//
// Description:
//
//
// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <tqtooltip.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <tdepopupmenu.h>
#include <tdeaction.h>
#include <kuniqueapplication.h>
#include "kxkbtraywindow.h"
#include "pixmap.h"
#include "rules.h"
KxkbSystemTray::KxkbSystemTray(KxkbConfig *kxkbConfig)
: KSystemTray(nullptr),
m_prevLayoutCount(0)
{
m_icoMgr = new LayoutIconManager(kxkbConfig);
}
KxkbSystemTray::~KxkbSystemTray()
{
delete m_icoMgr;
}
void KxkbSystemTray::setToolTip(const TQString& tip)
{
TQToolTip::remove(this);
TQToolTip::add(this, tip);
}
void KxkbSystemTray::setPixmap(const TQPixmap& pix)
{
TDEIconEffect iconeffect;
KSystemTray::setPixmap(iconeffect.apply(pix, TDEIcon::Panel, TDEIcon::DefaultState));
}
void KxkbSystemTray::setCurrentLayout(const LayoutUnit& layoutUnit)
{
setToolTip(m_descriptionMap[layoutUnit.toPair()]);
setPixmap(m_icoMgr->find(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName));
}
void KxkbSystemTray::setError(const TQString& layoutInfo)
{
TQString layout(layoutInfo);
if (layout.isNull()) {
layout = i18n("Unknown");
}
TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo);
setToolTip(msg);
setPixmap(m_icoMgr->find(ERROR_CODE, PIXMAP_STYLE_NORMAL));
}
void KxkbSystemTray::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules)
{
m_descriptionMap.clear();
int i;
for (i = 0; i < m_prevLayoutCount; ++i) {
contextMenu()->removeItem(START_MENU_ID + i);
}
TDEIconEffect iconeffect;
i = 0;
TQValueList<LayoutUnit>::ConstIterator it;
for (it = layouts.begin(); it != layouts.end(); ++it)
{
const TQString layoutName = (*it).layout;
const TQString variantName = (*it).variant;
const TQPixmap& layoutPixmap = m_icoMgr->find((*it).layout, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName);
const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, TDEIcon::DefaultState);
TQString fullName = rules.getLayoutName((*it));
contextMenu()->insertItem(pix, fullName, START_MENU_ID + i, i + 1);
m_descriptionMap.insert((*it).toPair(), fullName);
++i;
}
m_prevLayoutCount = i;
if (contextMenu()->indexOf(CONFIG_MENU_ID) == -1) {
contextMenu()->insertSeparator();
contextMenu()->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID);
if (contextMenu()->indexOf(HELP_MENU_ID) == -1) {
contextMenu()->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID);
}
}
connect(contextMenu(), TQ_SIGNAL(activated(int)), this, TQ_SIGNAL(menuActivated(int)));
}
void KxkbSystemTray::mouseReleaseEvent(TQMouseEvent *ev) {
if (ev->button() == TQt::LeftButton) {
emit toggled();
}
KSystemTray::mouseReleaseEvent(ev);
}
#include "kxkbtraywindow.moc"
|