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
119
120
121
122
123
124
125
126
127
128
129
130
|
//
// 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 <klocale.h>
#include <kiconeffect.h>
#include <kiconloader.h>
#include <kpopupmenu.h>
#include <kaction.h>
#include <kuniqueapplication.h>
#include "kxkbtraywindow.h"
#include "pixmap.h"
#include "rules.h"
#include "kxkbconfig.h"
KxkbLabelController::KxkbLabelController(TQLabel* label_, TQPopupMenu* contextMenu_) :
label(label_),
contextMenu(contextMenu_),
m_menuStartIndex(contextMenu_->count()),
m_prevLayoutCount(0)
{
// kdDebug() << "Creating KxkbLabelController with " << label_ << ", " << contextMenu_ << endl;
// kdDebug() << "Creating KxkbLabelController with startMenuIndex " << m_menuStartIndex << endl;
}
void KxkbLabelController::setToolTip(const TQString& tip)
{
TQToolTip::remove(label);
TQToolTip::add(label, tip);
}
void KxkbLabelController::setPixmap(const TQPixmap& pixmap)
{
KIconEffect iconeffect;
label->setPixmap( iconeffect.apply(pixmap, KIcon::Panel, KIcon::DefaultState) );
}
void KxkbLabelController::setCurrentLayout(const LayoutUnit& layoutUnit)
{
setToolTip(m_descriptionMap[layoutUnit.toPair()]);
setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, m_showFlag, layoutUnit.displayName) );
}
void KxkbLabelController::setError(const TQString& layoutInfo)
{
TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo);
setToolTip(msg);
label->setPixmap(LayoutIcon::getInstance().findPixmap("error", m_showFlag));
}
void KxkbLabelController::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules)
{
// KPopupMenu* menu = contextMenu();
TQPopupMenu* menu = contextMenu;
// int index = menu->indexOf(0);
m_descriptionMap.clear();
// menu->clear();
// menu->insertTitle( kapp->miniIcon(), kapp->caption() );
for(int ii=0; ii<m_prevLayoutCount; ++ii) {
menu->removeItem(START_MENU_ID + ii);
kdDebug() << "remove item: " << START_MENU_ID + ii << endl;
}
/* menu->removeItem(CONFIG_MENU_ID);
menu->removeItem(HELP_MENU_ID);*/
KIconEffect iconeffect;
int cnt = 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 = LayoutIcon::getInstance().findPixmap(layoutName, m_showFlag, (*it).displayName);
const TQPixmap pix = iconeffect.apply(layoutPixmap, KIcon::Small, KIcon::DefaultState);
TQString fullName = i18n((rules.layouts()[layoutName]));
if( variantName.isEmpty() == false )
fullName += " (" + variantName + ")";
contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, m_menuStartIndex + cnt);
m_descriptionMap.insert((*it).toPair(), fullName);
cnt++;
}
m_prevLayoutCount = cnt;
// if show config, if show help
if( menu->indexOf(CONFIG_MENU_ID) == -1 ) {
contextMenu->insertSeparator();
contextMenu->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID);
if( menu->indexOf(HELP_MENU_ID) == -1 )
contextMenu->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID);
}
/* if( index != -1 ) { //not first start
menu->insertSeparator();
KAction* quitAction = KStdAction::quit(this, TQT_SIGNAL(quitSelected()), actionCollection());
if (quitAction)
quitAction->plug(menu);
}*/
}
// void KxkbLabelController::mouseReleaseEvent(TQMouseEvent *ev)
// {
// if (ev->button() == TQMouseEvent::LeftButton)
// emit toggled();
// KSystemTray::mouseReleaseEvent(ev);
// }
#include "kxkbtraywindow.moc"
|