summaryrefslogtreecommitdiffstats
path: root/kxkb/kxkbtraywindow.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kxkb/kxkbtraywindow.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kxkb/kxkbtraywindow.cpp')
-rw-r--r--kxkb/kxkbtraywindow.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/kxkb/kxkbtraywindow.cpp b/kxkb/kxkbtraywindow.cpp
new file mode 100644
index 000000000..50fab7323
--- /dev/null
+++ b/kxkb/kxkbtraywindow.cpp
@@ -0,0 +1,130 @@
+//
+// C++ Implementation: kxkbtraywindow
+//
+// Description:
+//
+//
+// Author: Andriy Rysin <rysin@kde.org>, (C) 2006
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include <qtooltip.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(QLabel* label_, QPopupMenu* 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 QString& tip)
+{
+ QToolTip::remove(label);
+ QToolTip::add(label, tip);
+}
+
+void KxkbLabelController::setPixmap(const QPixmap& 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 QString& layoutInfo)
+{
+ QString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo);
+ setToolTip(msg);
+
+ label->setPixmap(LayoutIcon::getInstance().findPixmap("error", m_showFlag));
+}
+
+
+void KxkbLabelController::initLayoutList(const QValueList<LayoutUnit>& layouts, const XkbRules& rules)
+{
+// KPopupMenu* menu = contextMenu();
+ QPopupMenu* 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;
+ QValueList<LayoutUnit>::ConstIterator it;
+ for (it=layouts.begin(); it != layouts.end(); ++it)
+ {
+ const QString layoutName = (*it).layout;
+ const QString variantName = (*it).variant;
+
+ const QPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap(layoutName, m_showFlag, (*it).displayName);
+ const QPixmap pix = iconeffect.apply(layoutPixmap, KIcon::Small, KIcon::DefaultState);
+
+ QString 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, SIGNAL(quitSelected()), actionCollection());
+ if (quitAction)
+ quitAction->plug(menu);
+ }*/
+}
+
+// void KxkbLabelController::mouseReleaseEvent(QMouseEvent *ev)
+// {
+// if (ev->button() == QMouseEvent::LeftButton)
+// emit toggled();
+// KSystemTray::mouseReleaseEvent(ev);
+// }
+
+#include "kxkbtraywindow.moc"