diff options
Diffstat (limited to 'kxkb/kxkbtraywindow.cpp')
-rw-r--r-- | kxkb/kxkbtraywindow.cpp | 125 |
1 files changed, 53 insertions, 72 deletions
diff --git a/kxkb/kxkbtraywindow.cpp b/kxkb/kxkbtraywindow.cpp index 573b0b4ef..da0c7c0b4 100644 --- a/kxkb/kxkbtraywindow.cpp +++ b/kxkb/kxkbtraywindow.cpp @@ -24,109 +24,90 @@ #include "rules.h" #include "kxkbconfig.h" - -KxkbLabelController::KxkbLabelController(TQLabel* label_, TDEPopupMenu* contextMenu_) : - label(label_), - contextMenu(contextMenu_), - m_menuStartIndex(contextMenu_->count()), - m_prevLayoutCount(0) +KxkbSystemTray::KxkbSystemTray() + : KSystemTray(nullptr), + m_prevLayoutCount(0) { -// kdDebug() << "Creating KxkbLabelController with " << label_ << ", " << contextMenu_ << endl; -// kdDebug() << "Creating KxkbLabelController with startMenuIndex " << m_menuStartIndex << endl; } -void KxkbLabelController::setToolTip(const TQString& tip) +void KxkbSystemTray::setToolTip(const TQString& tip) { - TQToolTip::remove(label); - TQToolTip::add(label, tip); + TQToolTip::remove(this); + TQToolTip::add(this, tip); } -void KxkbLabelController::setPixmap(const TQPixmap& pixmap) +void KxkbSystemTray::setPixmap(const TQPixmap& pix) { - TDEIconEffect iconeffect; - label->setPixmap( iconeffect.apply(pixmap, TDEIcon::Panel, TDEIcon::DefaultState) ); + TDEIconEffect iconeffect; + KSystemTray::setPixmap(iconeffect.apply(pix, TDEIcon::Panel, TDEIcon::DefaultState)); } - -void KxkbLabelController::setCurrentLayout(const LayoutUnit& layoutUnit) +void KxkbSystemTray::setCurrentLayout(const LayoutUnit& layoutUnit) { - setToolTip(m_descriptionMap[layoutUnit.toPair()]); - setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName) ); + setToolTip(m_descriptionMap[layoutUnit.toPair()]); + setPixmap(LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName)); } - -void KxkbLabelController::setError(const TQString& layoutInfo) +void KxkbSystemTray::setError(const TQString& layoutInfo) { - TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo); - setToolTip(msg); + TQString layout(layoutInfo); + if (layout.isNull()) { + layout = i18n("Unknown"); + } - label->setPixmap(LayoutIcon::getInstance().findPixmap("error", PIXMAP_STYLE_NORMAL)); + TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo); + setToolTip(msg); + setPixmap(LayoutIcon::getInstance().findPixmap("error", PIXMAP_STYLE_NORMAL)); } - -void KxkbLabelController::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules) +void KxkbSystemTray::initLayoutList(const TQValueList<LayoutUnit>& layouts, const XkbRules& rules) { - TDEPopupMenu* 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);*/ + int i; + for (i = 0; i < m_prevLayoutCount; ++i) { + contextMenu()->removeItem(START_MENU_ID + i); + } TDEIconEffect iconeffect; - int cnt = 0; + i = 0; TQValueList<LayoutUnit>::ConstIterator it; - for (it=layouts.begin(); it != layouts.end(); ++it) + for (it = layouts.begin(); it != layouts.end(); ++it) { - const TQString layoutName = (*it).layout; - const TQString variantName = (*it).variant; + const TQString layoutName = (*it).layout; + const TQString variantName = (*it).variant; + + const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap((*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); - const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap( - (*it).layout, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName); - const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, - TDEIcon::DefaultState); + m_descriptionMap.insert((*it).toPair(), fullName); - TQString fullName = rules.getLayoutName((*it)); - contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, - m_menuStartIndex + cnt); + ++i; + } + + m_prevLayoutCount = i; - m_descriptionMap.insert((*it).toPair(), fullName); + if (contextMenu()->indexOf(CONFIG_MENU_ID) == -1) { + contextMenu()->insertSeparator(); + contextMenu()->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID); - cnt++; + if (contextMenu()->indexOf(HELP_MENU_ID) == -1) { + contextMenu()->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID); + } } - 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(); - TDEAction* quitAction = KStdAction::quit(this, TQ_SIGNAL(quitSelected()), actionCollection()); - if (quitAction) - quitAction->plug(menu); - }*/ + connect(contextMenu(), TQ_SIGNAL(activated(int)), this, TQ_SIGNAL(menuActivated(int))); } -// void KxkbLabelController::mouseReleaseEvent(TQMouseEvent *ev) -// { -// if (ev->button() == TQMouseEvent::LeftButton) -// emit toggled(); -// KSystemTray::mouseReleaseEvent(ev); -// } +void KxkbSystemTray::mouseReleaseEvent(TQMouseEvent *ev) { + if (ev->button() == TQt::LeftButton) { + emit toggled(); + } + KSystemTray::mouseReleaseEvent(ev); +} #include "kxkbtraywindow.moc" |