Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/extension') (more/less context) (ignore whitespace changes)
16 files changed, 1429 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp new file mode 100644 index 0000000..00a43d1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.cpp @@ -0,0 +1,110 @@ +#include "ExtensionFactory.h" + +ExtensionFactory::ExtensionFactory() +{ + qDebug("ExtensionFactory::ExtensionFactory()"); + m_pLoadList = NULL; +} + +ExtensionFactory::~ExtensionFactory() +{ + qDebug("ExtensionFactory::~ExtensionFactory()"); +} + +ExtensionInterface* ExtensionFactory::createInstance(const QString& kind) +{ + ExtensionInterface* ext; + QString kindstr = kind.lower(); + + if(kindstr == "switch"){ + ext = new TaskSwitcher(kindstr); + } else if(kindstr == "select"){ + ext = new TaskSelector(kindstr); + } else if(kindstr.find("launch") == 0){ + ext = new KeyLauncher(kindstr); + } else if(kindstr.find("menu") == 0){ + ext = new MenuLauncher(kindstr); + } else { + return(NULL); + } + m_oExtList.append(ext); + return(ext); +} + +ExtensionInterface* ExtensionFactory::createInstance(const QString& kind, + int keycode, int keymask) +{ + ExtensionInterface* ext; + QString kindstr = kind.lower(); + + ext = loadInstance(kindstr, keycode, keymask); + if(ext != NULL){ + return(ext); + } + + if(kindstr == "switch"){ + ext = new TaskSwitcher(kindstr); + } else if(kindstr == "select"){ + ext = new TaskSelector(kindstr); + } else if(kindstr.find("launch") == 0){ + ext = new KeyLauncher(kindstr); + } else if(kindstr.find("menu") == 0){ + ext = new MenuLauncher(kindstr); + } else { + return(NULL); + } + ext->setKeycode(keycode); + ext->setKeymask(keymask); + + m_oExtList.append(ext); + return(ext); +} + +ExtensionInterface* ExtensionFactory::loadInstance(const QString& kindstr, + int keycode, int keymask) +{ + if(m_pLoadList == NULL){ + return(NULL); + } + + for(ExtensionList::Iterator it=m_pLoadList->begin(); + it!=m_pLoadList->end(); ++it){ + if((*it)->kind() == kindstr + && (*it)->getKeycode() == keycode + && (*it)->getKeymask() == keymask){ + m_oExtList.append(*it); + return(*it); + } + } + return(NULL); +} + +void ExtensionFactory::clear() +{ + for(ExtensionList::Iterator it=m_oExtList.begin(); + it!=m_oExtList.end(); ++it){ + delete *it; + } + m_oExtList.clear(); +} + +void ExtensionFactory::reset() +{ + m_pLoadList = new ExtensionList(m_oExtList); + m_oExtList.clear(); +} + +void ExtensionFactory::sweep() +{ + if(m_pLoadList == NULL){ + return; + } + for(ExtensionList::Iterator it=m_pLoadList->begin(); + it!=m_pLoadList->end(); ++it){ + if(m_oExtList.contains(*it) == false){ + delete *it; + } + } + delete m_pLoadList; + m_pLoadList = NULL; +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h new file mode 100644 index 0000000..7fa6a5f --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionFactory.h @@ -0,0 +1,35 @@ +#ifndef _EXTENSION_FACTORY_H_ +#define _EXTENSION_FACTORY_H_ + +#include "ExtensionInterface.h" +#include "TaskSwitcher.h" +#include "KeyLauncher.h" +#include "TaskSelector.h" +#include "MenuLauncher.h" + +class ExtensionFactory +{ +public: + ExtensionFactory(); + virtual ~ExtensionFactory(); + + ExtensionInterface* createInstance(const QString& kind); + ExtensionInterface* createInstance(const QString& kind, + int keycode, int keymask); + ExtensionList& getList() + { + return(m_oExtList); + } + void clear(); + void reset(); + void sweep(); +private: + ExtensionList m_oExtList; + ExtensionList* m_pLoadList; + + ExtensionInterface* loadInstance(const QString& kind, + int keycode, int keymask); +}; + +#endif /* _EXTENSION_FACTORY_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h new file mode 100644 index 0000000..1a81141 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/ExtensionInterface.h @@ -0,0 +1,26 @@ +#ifndef _EXTENSION_INTERFACE_H_ +#define _EXTENSION_INTERFACE_H_ + +#include <qvaluelist.h> + +class ExtensionInterface +{ +public: + //ExtensionInterface(); + virtual ~ExtensionInterface(){} + virtual bool onKeyPress(int keycode) = 0; + virtual bool onModRelease(int modcode) = 0; + virtual int getKeycode() = 0; + virtual int getKeymask() = 0; + virtual const QValueList<int>& getModcodes() = 0; + virtual void setKeycode(int keycode) = 0; + virtual void setKeymask(int keymask) = 0; + virtual void setModcodes(const QValueList<int>& modcodes) = 0; + virtual const QString& kind() = 0; +private: +}; + +typedef QValueList<ExtensionInterface*> ExtensionList; + +#endif /* _EXTENSION_INTERFACE_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp new file mode 100644 index 0000000..a61ea0a --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.cpp @@ -0,0 +1,111 @@ +#include "KeyExtensions.h" + +KeyExtensions::KeyExtensions() +{ + qDebug("KeyExtensions::KeyExtensions()"); + m_cancelcode = 0; +} + +KeyExtensions::~KeyExtensions() +{ + qDebug("KeyExtensions::~KeyExtensions()"); + clear(); +} + +void KeyExtensions::assign(const QString& kind, int keycode, + int keymask, const QValueList<int>& modcodes) +{ + ExtensionInterface* ext; +#if 0 + ext = m_oExtFactory.createInstance(kind); + if(ext != NULL){ + ext->setKeycode(keycode); + ext->setKeymask(keymask); + ext->setModcodes(modcodes); + } +#else + ext = m_oExtFactory.createInstance(kind, keycode, keymask); + if(ext != NULL){ + ext->setModcodes(modcodes); + } +#endif +} + +void KeyExtensions::assign(const QString& kind, int keycode, + int keymask, int modcode) +{ + QValueList<int> modcodes; + modcodes.append(modcode); + assign(kind, keycode, keymask, modcodes); +} + +bool KeyExtensions::doKey(int keycode, int keymask, bool isPress) +{ + bool fCancel = false; + ExtensionList& list = m_oExtFactory.getList(); + for(ExtensionList::Iterator it=list.begin(); + it!=list.end(); ++it){ + if(isPress){ + int code = (*it)->getKeycode(); + if((*it)->getKeymask() == keymask + && (code == 0 || code == keycode)){ + if((*it)->onKeyPress(keycode)){ + fCancel = true; + } + qWarning("ext:onKeyPress[%s][%x][%d]", + (*it)->kind().latin1(), + (*it)->getKeycode(), + fCancel); + } + } else { + if(keycode == m_cancelcode){ + fCancel = true; + } + const QValueList<int>& rlist = (*it)->getModcodes(); + if(rlist.contains(keycode)){ + if((*it)->onModRelease(keycode)){ + m_pModifiers->resetToggles(); + } + qWarning("ext:onModRelease[%s][%x]", + (*it)->kind().latin1(), + keycode); + } + } + } + if(isPress && fCancel){ + m_cancelcode = keycode; + } else { + m_cancelcode = 0; + } + return(fCancel); +} + +void KeyExtensions::clear() +{ + m_oExtFactory.clear(); +} + +void KeyExtensions::reset() +{ + //clear(); + m_oExtFactory.reset(); +} + +void KeyExtensions::init() +{ + m_oExtFactory.sweep(); +} + +void KeyExtensions::statistics() +{ + qWarning("KeyExtensions::statistics()"); + ExtensionList& list = m_oExtFactory.getList(); + for(ExtensionList::Iterator it=list.begin(); + it!=list.end(); ++it){ + qWarning(" [%s][%x][%x]", + (*it)->kind().latin1(), + (*it)->getKeycode(), + (*it)->getKeymask()); + } +} + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h new file mode 100644 index 0000000..20ffc45 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyExtensions.h @@ -0,0 +1,40 @@ +#ifndef _KEY_EXTENSIONS_H_ +#define _KEY_EXTENSIONS_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include "KeyNames.h" +#include "KeyModifiers.h" +#include "ExtensionFactory.h" + +class KeyExtensions +{ +public: + KeyExtensions(); + ~KeyExtensions(); + + void setKeyModifiers(KeyModifiers* mod) + { + m_pModifiers = mod; + } + + void assign(const QString& kind, int keycode, + int keymask, const QValueList<int>& modcodes); + void assign(const QString& kind, int keycode, + int keymask, int modcode); + bool doKey(int keycode, int keymask, bool isPress); + + void statistics(); + + void reset(); + void init(); +private: + KeyModifiers* m_pModifiers; + ExtensionFactory m_oExtFactory; + int m_cancelcode; + + void clear(); +}; + +#endif /* _KEY_EXTENSIONS_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp new file mode 100644 index 0000000..7a0b88c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.cpp @@ -0,0 +1,57 @@ +#include "KeyLauncher.h" +#include "KHUtil.h" + +KeyLauncher::KeyLauncher(const QString& kind) : m_kind(kind) +{ + qDebug("KeyLauncher::KeyLauncher()"); +} + +KeyLauncher::~KeyLauncher() +{ + qDebug("KeyLauncher::~KeyLauncher()"); +} + +bool KeyLauncher::onKeyPress(int keycode) +{ + QString key; + QStringList args; + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + key = KeyNames::getName(keycode); + if(key == QString::null){ + return(false); + } + + QString group = kind(); + group[0] = group[0].upper(); + + /* read application launcher */ + QString app = KHUtil::currentApp(); + if(!app.isEmpty()){ + cfg.setGroup(group + "_" + app); + /* read config */ + args = cfg.readListEntry(key, '\t'); + } + + /* read default launcher */ + if(args.isEmpty()){ + cfg.setGroup(group); + + /* read config */ + args = cfg.readListEntry(key, '\t'); + } + + if(args.isEmpty()){ + return(false); + } + + /* launch application */ + LnkWrapper lnk(args); + if(lnk.isValid()){ + //args.remove(args.begin()); + lnk.instance().execute(); + } + + return(true); +} + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h new file mode 100644 index 0000000..fbad3da --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/KeyLauncher.h @@ -0,0 +1,63 @@ +#ifndef _KEY_LAUNCHER_H_ +#define _KEY_LAUNCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> + +#include <qpe/qpeapplication.h> +#include <qpe/config.h> +#include <qpe/applnk.h> +#include <qpe/global.h> +#include <qpe/qcopenvelope_qws.h> + +#include "ExtensionInterface.h" +#include "KeyNames.h" +#include "LnkWrapper.h" +#include "ConfigEx.h" + +class KeyLauncher : public ExtensionInterface +{ +public: + KeyLauncher(const QString& kind = "launch"); + virtual ~KeyLauncher(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int /*modcode*/){return(false);} + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; +}; + +#endif /* _KEY_LAUNCHER_H_ */ + diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp new file mode 100644 index 0000000..0595a3e --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.cpp @@ -0,0 +1,324 @@ +#include "MenuLauncher.h" +extern QWidget* g_Widget; + +MenuLauncher::MenuLauncher(const QString& kind) : m_kind(kind) +{ + qDebug("MenuLauncher::MenuLauncher()"); + m_pMenu = m_pTopMenu = NULL; + + m_isShowing = false; + m_id = -1; + + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), + this, SLOT(select())); + + init(); +} + +MenuLauncher::~MenuLauncher() +{ + qDebug("MenuLauncher::~MenuLauncher()"); + delete m_pTopMenu; + delete m_pTimer; +} + +void MenuLauncher::init() +{ + buildMenu(); +} + +QPopupMenu* MenuLauncher::initMenu(QWidget* parent, const QString& name) +{ + QPopupMenu* pMenu; + pMenu = new QPopupMenuEx(parent, name); + pMenu->installEventFilter(this); + connect(pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); + connect(pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); + //connect(pMenu, SIGNAL(aboutToHide()), this, SLOT(execute())); + return(pMenu); +} + +bool MenuLauncher::onKeyPress(int /*keycode*/) +{ + if(m_isShowing){ + qDebug("showing ..."); + } else if(m_pMenu->isVisible()){ + next(); + } else { + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayPopup", 5); + QTimer::singleShot(delay, this, SLOT(show())); + m_isShowing = true; + } + return true; +} + +bool MenuLauncher::onModRelease(int /*modcode*/) +{ + if(m_pMenu->isVisible()){ + QTimer::singleShot(0, this, SLOT(select())); + return(true); + } else { + return(false); + } +} + +QString MenuLauncher::getMenuText(const QString& key, const QString& name) +{ + QRegExp rx("^[0-9]+_"); + QString text; + QString ackey; + int len; + if(rx.match(key, 0, &len) == 0){ + ackey = key.mid(len); + } else { + ackey = key; + } + if(ackey.length() == 1){ + text = name; + text.append("(&"); + text.append(ackey); + text.append(")"); + } else { + text = ackey; + } + return(text); +} + +int MenuLauncher::buildMenu(const QString& section, + QPopupMenu* pMenu, int& id) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + if(m_oMenuList.contains(pMenu)){ + /* ̵¸Â¥ë¡¼¥×ËÉ»ß */ + return(0); + } + m_oMenuList.append(pMenu); + + QString oldgroup = cfg.getGroup(); + + QString group = section; + group[0] = group[0].upper(); + + cfg.setGroup(group); + + QStringList apps = cfg.getKeys(); + int cnt = 0; + if(apps.isEmpty() == false){ + for(QStringList::Iterator it=apps.begin(); + it!=apps.end(); ++it){ + QStringList args = cfg.readListEntry(*it, '\t'); + LnkWrapper lnk(args); + if(lnk.isValid()){ + cnt++; + QString text = getMenuText(*it, lnk.instance().name()); + if(args[0] == "@menu"){ + QPopupMenu* pSubMenu = initMenu(m_pTopMenu, args[1]); + pMenu->insertItem(lnk.instance().pixmap(), text, + pSubMenu, id); + m_oItemList.append(ItemInfo(section)); + id++; + buildMenu(args[1], pSubMenu, id); + } else { + pMenu->insertItem(lnk.instance().pixmap(), text, id); + m_oItemList.append(ItemInfo(section, *it)); + id++; + } + } + } + } + cfg.setGroup(oldgroup); + return(cnt); +} + +void MenuLauncher::clearSubMenu() +{ + for(QValueList<QPopupMenu*>::Iterator it=m_oMenuList.begin(); + it!=m_oMenuList.end(); ++it){ + if(*it != m_pTopMenu){ + delete *it; + } + } + m_oMenuList.clear(); + m_oItemList.clear(); +} + +int MenuLauncher::buildMenu(bool force) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + if(!force && m_lastmodify == cfg.lastRead()){ + return(m_pTopMenu->count()); + } + qDebug("buildMenu"); + + QString oldgroup = cfg.getGroup(); + + cfg.setGroup("Global"); + m_submenuTimeout = cfg.readNumEntry("SubMenuTimeout", 500); + + if(m_pTopMenu){ + delete m_pTopMenu; + } + m_pMenu = m_pTopMenu = initMenu(g_Widget, kind()); + m_oLastId.clear(); + m_oMenuList.clear(); + m_oItemList.clear(); + + MenuTitle* pTitle = new MenuTitle("MenuLauncher", + m_pTopMenu->font(), kind()); + m_pTopMenu->insertItem(pTitle); + + int id = 0; + int cnt = buildMenu(kind(), m_pTopMenu, id); + if(cnt > 0){ + m_lastmodify = cfg.lastRead(); + } + + cfg.setGroup(oldgroup); + return(cnt); +} + +void MenuLauncher::show() +{ + m_enablePopup = false; + int cnt = buildMenu(); + if(cnt > 0){ + m_pMenu = m_pTopMenu; + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Style"); + int x,y; + QString key = "Position_" + kind(); + if(cfg.hasKey(key)){ + const QStringList& list = cfg.readListEntry(key, ','); + x = list[0].toInt(); + y = list[1].toInt(); + } else { + x = (qt_screen->width() - m_pTopMenu->sizeHint().width()) / 2; + y = (qt_screen->height() - m_pTopMenu->sizeHint().height()) / 2; + } + QPoint pos(x, y); + m_pTopMenu->popup(pos); + m_pTopMenu->setActiveItem(1); + } + m_isShowing = false; +} + +void MenuLauncher::next() +{ + int index = m_pMenu->indexOf(m_id); + index++; + if(index >= (signed int)m_pMenu->count()){ + if(m_pMenu == m_pTopMenu){ + index = 1; + } else { + index = 0; + } + } + m_pMenu->setActiveItem(index); + m_id = m_pMenu->idAt(index); +} + +void MenuLauncher::select() +{ + if(m_pMenu->isVisible()){ + QMenuItem* item = m_pMenu->findItem(m_id); + int index = m_pMenu->indexOf(m_id); + QPopupMenu* p = m_pMenu; + //m_pMenu->activateItemAt(index); + if(item && item->popup()){ + m_pMenu = item->popup(); + } + p->activateItemAt(index); + } +} + +void MenuLauncher::select(int id) +{ + if(id >= 0 && m_oItemList[id].entry != QString::null){ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayExec", 100); + + QString group = m_oItemList[id].group; + group[0] = group[0].upper(); + cfg.setGroup(group); + + //QStringList args = cfg.readListEntry(m_oItemList[id].entry, '\t'); + m_args = cfg.readListEntry(m_oItemList[id].entry, '\t'); + +#if 0 + LnkWrapper lnk(args); + if(lnk.isValid()){ + lnk.instance().execute(); + } +#else + QTimer::singleShot(delay, this, SLOT(execute())); +#endif + } + m_pMenu = m_pTopMenu; + m_id = -1; +} + +void MenuLauncher::execute() +{ + LnkWrapper lnk(m_args); + if(lnk.isValid()){ + lnk.instance().execute(); + } + m_args.clear(); +} + +void MenuLauncher::highlight(int id) +{ + if(m_pMenu && m_pMenu->isVisible()){ + m_id = id; + if(m_enablePopup){ + QMenuItem* item = m_pMenu->findItem(m_id); + if(item && item->popup()){ + if(m_submenuTimeout > 0){ + m_pTimer->start(m_submenuTimeout, true); + } + } else { + m_pTimer->stop(); + } + } else { + /* ¥á¥Ë¥å¡¼É½¼¨Ä¾¸å¤Ï¥Ý¥Ã¥×¥¢¥Ã¥×¤·¤Ê¤¤ */ + m_enablePopup = true; + } + } +} + +bool MenuLauncher::eventFilter(QObject* o, QEvent* e) +{ + if(m_pTopMenu->isVisible()){ + QKeyEvent* ke = (QKeyEvent*)e; + switch(e->type()){ + case QEvent::Accel: + if(ke->key() == Qt::Key_Space + && ke->isAutoRepeat() == false){ + select(); + } + break; + case QEvent::FocusIn: + //qDebug("FocusIn[%p][%p]", o, m_pMenu); + m_pMenu = (QPopupMenu*)o; + if(m_oLastId.contains(o)){ + m_id = m_oLastId[o]; + } + m_pMenu->updateItem(m_id); + break; + case QEvent::FocusOut: + //qDebug("FocusOut[%p][%p]", o, m_pMenu); + m_oLastId[o] = m_id; + break; + default: + //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); + break; + } + } + return QObject::eventFilter(o, e); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h new file mode 100644 index 0000000..5eebe78 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuLauncher.h @@ -0,0 +1,110 @@ +#ifndef _MENU_LAUNCHER_H_ +#define _MENU_LAUNCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> +#define INCLUDE_MENUITEM_DEF +#include <qpopupmenu.h> +#include <qpoint.h> +#include <qtimer.h> +#include <qgfx_qws.h> + +#include <qpe/global.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/qpeapplication.h> + +#include "ExtensionInterface.h" +#include "MenuTitle.h" +#include "KeyNames.h" +#include "ConfigEx.h" +#include "LnkWrapper.h" +#include "QPopupMenuEx.h" + +struct ItemInfo{ + ItemInfo(QString g=QString::null, QString e=QString::null) + : group(g), entry(e){} + QString group; + QString entry; +}; + +class MenuLauncher : public QObject, public ExtensionInterface +{ + Q_OBJECT +public: + MenuLauncher(const QString& kind = "menu"); + virtual ~MenuLauncher(); + + typedef QValueList<ItemInfo> ItemList; + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +public slots: + void show(); + void select(); + void select(int id); + void highlight(int id); +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + int m_submenuTimeout; + bool m_isShowing; + bool m_enablePopup; + int m_id; + QPopupMenu* m_pMenu; + QPopupMenu* m_pTopMenu; + QDateTime m_lastmodify; + + QMap<QObject*, int> m_oLastId; + QValueList<QPopupMenu*> m_oMenuList; + ItemList m_oItemList; + QTimer* m_pTimer; + + QStringList m_args; + + QString getMenuText(const QString& key, const QString& name); + QPopupMenu* initMenu(QWidget* parent, const QString& name); + int buildMenu(bool force=false); + int buildMenu(const QString& section, QPopupMenu* pMenu, int& id); + void clearSubMenu(); + void init(); + void next(); +private slots: + bool eventFilter(QObject* o, QEvent* e); + void execute(); +}; + +#endif /* _MENU_LAUNCHER_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp new file mode 100644 index 0000000..d8fd2a3 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp @@ -0,0 +1,67 @@ +#include "MenuTitle.h" + +MenuTitle::MenuTitle(const QString& s, const QFont& f, const QString& k) +{ + font = f; + kind = k; + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + + const QString curGroup = cfg.getGroup(); + cfg.setGroup("Style"); + + caption = cfg.readEntry("Caption_" + k, s); + cfg.setGroup(curGroup); +} + +bool MenuTitle::fullSpan() const +{ + return(true); +} + +bool MenuTitle::isSeparator() const +{ + return(true); +} + +void MenuTitle::paint(QPainter* p, const QColorGroup& cg, bool /*act*/, + bool /*enabled*/, int x, int y, int w, int h) +{ + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + const QString& curGroup = cfg.getGroup(); + + cfg.setGroup("Style"); + + QString name; + QColor color; + + p->setFont(font); + + /* set fontcolor */ + name = cfg.readEntry("FontColor_" + kind, QString::null); + if(name != QString::null){ + color.setNamedColor(name); + if(color.isValid()){ + p->setPen(color); + } + } + + /* set bgcolor */ + name = cfg.readEntry("BgColor_" + kind, QString::null); + if(name != QString::null){ + color.setNamedColor(name); + if(color.isValid() == false){ + color = cg.mid(); + } + } else { + color = cg.mid(); + } + p->fillRect(x, y, w, h, QBrush(color)); + p->drawText(x, y, w, h, AlignCenter, caption); + cfg.setGroup(curGroup); +} + +QSize MenuTitle::sizeHint() +{ + return(QFontMetrics(font).size(AlignCenter, caption)); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h new file mode 100644 index 0000000..77e46a5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.h @@ -0,0 +1,29 @@ +#ifndef _MENU_TITLE_ITEM_H_ +#define _MENU_TITLE_ITEM_H_ + +#include <qmenudata.h> +#include <qpainter.h> +#include <qbrush.h> +#include <qcolor.h> +#include <qpalette.h> +#include <qpe/config.h> +#include "ConfigEx.h" + +class MenuTitle : public QCustomMenuItem +{ +public: + MenuTitle(const QString& s, const QFont& f, const QString& k = "default"); + virtual ~MenuTitle(){} + + bool fullSpan () const; + bool isSeparator() const; + void paint(QPainter* p, const QColorGroup& cg, bool act, + bool enabled, int x, int y, int w, int h); + QSize sizeHint(); +private: + QString caption; + QString kind; + QFont font; +}; + +#endif /* _MENU_TITLE_ITEM_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h b/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h new file mode 100644 index 0000000..16e18a1 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/QPopupMenuEx.h @@ -0,0 +1,28 @@ +#ifndef _QPOPUPMENUEX_H_ +#define _QPOPUPMENUEX_H_ + +#include <qpopupmenu.h> +#include <qstring.h> +#include <qevent.h> + +class QPopupMenuEx : public QPopupMenu +{ +public: + QPopupMenuEx(QWidget* parent=0, const char* name=0) + : QPopupMenu(parent, name){} +protected: + void keyPressEvent(QKeyEvent* e){ + QChar c = e->text()[0]; + QKeyEvent* ke = new QKeyEvent( + e->type(), + e->key(), + c.lower().latin1(), + 0, + c.lower(), + e->isAutoRepeat()); + QPopupMenu::keyPressEvent(ke); + } +private: +}; + +#endif /* _QPOPUPMENUEX_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp new file mode 100644 index 0000000..4fc9cc4 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp @@ -0,0 +1,225 @@ +#include "TaskSelector.h" +extern QWidget* g_Widget; + +static const char* defkeys = +"QWERTYUIOPASDFGHJKLZXCVBNM1234567890"; + +#define START_INDEX 1 + +TaskSelector::TaskSelector(const QString& kind) : m_kind(kind) +{ + qDebug("TaskSelector::TaskSelector()"); + m_pMenu = new QPopupMenuEx(g_Widget); + m_pMenu->installEventFilter(this); + + m_isShowing = false; + m_index = START_INDEX-1; + connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); + connect(m_pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); +} + +TaskSelector::~TaskSelector() +{ + qDebug("TaskSelector::~TaskSelector()"); + delete m_pMenu; +} + +bool TaskSelector::onKeyPress(int /*keycode*/) +{ + if(m_isShowing){ + qDebug("showing ..."); + } else if(m_pMenu->isVisible()){ + next(); + } else { + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Global"); + int delay = cfg.readNumEntry("DelayPopup", 5); + QTimer::singleShot(delay, this, SLOT(show())); + m_isShowing = true; + } + return true; +} + +bool TaskSelector::onModRelease(int /*modcode*/) +{ + if(m_pMenu->isVisible()){ + //m_pMenu->hide(); + QTimer::singleShot(0, this, SLOT(select())); + return(true); + } else { + return(false); + } +} + +int TaskSelector::buildMenu() +{ + const AppLnk* lnk; + + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup; + + oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + QString accesskeys = cfg.readEntry("AccessKeys", defkeys); + if(accesskeys.length() <= 0){ + accesskeys = defkeys; + } + cfg.setGroup(oldgroup); + + /* get list */ + int cnt = 0; + m_index = START_INDEX+1; + m_applist.clear(); + m_pMenu->clear(); + MenuTitle* pTitle = new MenuTitle("TaskSelector", m_pMenu->font(), kind()); + m_pMenu->insertItem(pTitle); + const QList<QWSWindow>& list = qwsServer->clientWindows(); + QWSWindow* w; + for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ + if(w->isVisible() == false + || w->caption() == QString::null){ + continue; + } + QString app = w->client()->identity(); + if(app == NULL || m_applist.contains(app)){ + continue; + } + /* exclude "launcher" */ + if(app == "launcher"){ + if(cnt == 0){ + m_index--; + } + continue; + } + m_applist.append(app); + /* append menu */ + cnt++; + AppLnkSet* lnkSet = AppLnkManager::getInstance(); + lnk = lnkSet->findExec(app); + QString text; + QPixmap icon; +#if 0 + if(lnk != NULL){ + icon = lnk->pixmap(); + text = lnk->name(); + } else { + AppLnkManager::notfound(); + icon = QPixmap(); + text = w->caption(); + } +#else + if(lnk != NULL){ + icon = lnk->pixmap(); + if(w->caption().length() > 0){ + text = w->caption(); + } else { + text = lnk->name(); + } + } else { + AppLnkManager::notfound(); + icon = QPixmap(); + text = w->caption(); + } +#endif + if(cnt <= (int)accesskeys.length()){ + text.append("(&"); + text.append(accesskeys[cnt-1].upper()); + text.append(")"); + } + m_pMenu->insertItem(icon, text, cnt); + } + return(cnt); +} + +void TaskSelector::show() +{ + /* build task selector menu */ + int cnt = buildMenu(); + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + QString oldgroup = cfg.getGroup(); + cfg.setGroup("Global"); + int min = cfg.readNumEntry("SelectMenuMin", 2); + if(min != 1 && min != 3){ + min = 2; + } + cfg.setGroup(oldgroup); + + if(cnt == 0){ + qDebug("no applications"); + } else if(cnt < min){ + //m_index = START_INDEX; + if(m_index > cnt){ + m_index = cnt; + } + QTimer::singleShot(0, this, SLOT(select())); + } else { + if(m_index > cnt){ + m_index = cnt; + } + ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); + cfg.setGroup("Style"); + int x,y; + QString key = "Position_" + kind(); + if(cfg.hasKey(key)){ + const QStringList& list = cfg.readListEntry(key, ','); + x = list[0].toInt(); + y = list[1].toInt(); + } else { + x = (qt_screen->width() - m_pMenu->sizeHint().width()) / 2; + y = (qt_screen->height() - m_pMenu->sizeHint().height()) / 2; + } + QPoint pos(x, y); + m_pMenu->popup(pos); + m_pMenu->setActiveItem(m_index); + } + m_isShowing = false; +} + +void TaskSelector::next() +{ + m_index++; + if(m_index > (signed int)m_applist.count()){ + m_index = START_INDEX; + } + m_pMenu->setActiveItem(m_index); +} + +void TaskSelector::select() +{ + //select(m_index); + m_pMenu->activateItemAt(m_index); +} + +void TaskSelector::select(int index) +{ + if(index > 0){ + Global::execute(m_applist[index-1]); + } + m_index = 0; +} + +void TaskSelector::highlight(int index) +{ + if(m_pMenu->isVisible()){ + m_index = index; + } +} + +bool TaskSelector::eventFilter(QObject* o, QEvent* e) +{ + if(m_pMenu->isVisible()){ + QKeyEvent* ke = (QKeyEvent*)e; + switch(e->type()){ + case QEvent::Accel: + if(ke->key() == Qt::Key_Space + && ke->isAutoRepeat() == false){ + select(); + } + break; + default: + //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); + break; + } + } + return QObject::eventFilter(o, e); +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h new file mode 100644 index 0000000..ceb157d --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.h @@ -0,0 +1,85 @@ +#ifndef _TASK_SELECTOR_H_ +#define _TASK_SELECTOR_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> +#include <qpopupmenu.h> +#include <qpoint.h> +#include <qtimer.h> +#include <qgfx_qws.h> + +#include <qpe/global.h> +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/mimetype.h> + +#include "ExtensionInterface.h" +#include "MenuTitle.h" +#include "KeyNames.h" +#include "AppLnkManager.h" +#include "ConfigEx.h" +#include "QPopupMenuEx.h" + +class TaskSelector : public QObject, public ExtensionInterface +{ + Q_OBJECT +public: + TaskSelector(const QString& kind = "select"); + virtual ~TaskSelector(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +public slots: + void show(); + void select(); + void select(int); + void highlight(int id); +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + bool m_isShowing; + int m_index; + QPopupMenu* m_pMenu; + QStringList m_applist; + QString m_accesskeys; + + int buildMenu(); + void next(); +private slots: + bool eventFilter(QObject* o, QEvent* e); +}; + +#endif /* _TASK_SELECTOR_H_ */ diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp new file mode 100644 index 0000000..c51eba5 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.cpp @@ -0,0 +1,58 @@ +#include "TaskSwitcher.h" + +TaskSwitcher::TaskSwitcher(const QString& kind) : m_kind(kind) +{ + qDebug("TaskSwitcher::TaskSwitcher()"); +} + +TaskSwitcher::~TaskSwitcher() +{ + qDebug("TaskSwitcher::~TaskSwitcher()"); +} + +bool TaskSwitcher::onKeyPress(int /*keycode*/) +{ + if(m_applist.isEmpty()){ + /* get list */ + const QList<QWSWindow>& list = qwsServer->clientWindows(); + QWSWindow* w; + for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ + if(w->isVisible()){ + QString app = w->client()->identity(); + qDebug("applist[%s]", app.latin1()); + if(app != NULL && m_applist.contains(app) == false){ + m_applist.append(app); + } + } + } + m_appit = m_applist.begin(); + } + if(m_applist.count() > 1){ + /* switch next */ + next(); + if(*m_appit == "launcher"){ + next(); + } + Global::execute(*m_appit); + } else if(m_applist.count() == 1 + && *m_appit != "launcher"){ + Global::execute(*m_appit); + } else { + qDebug("no applications"); + } + return(true); +} + +bool TaskSwitcher::onModRelease(int /*keycode*/) +{ + m_applist.clear(); + return(false); +} + +void TaskSwitcher::next() +{ + ++m_appit; + if(m_appit == m_applist.end()){ + m_appit = m_applist.begin(); + } +} diff --git a/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h new file mode 100644 index 0000000..7bbde55 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/extension/TaskSwitcher.h @@ -0,0 +1,61 @@ +#ifndef _TASK_SWITCHER_H_ +#define _TASK_SWITCHER_H_ + +#include <qstring.h> +#include <qstringlist.h> +#include <qvaluelist.h> +#include <qwindowsystem_qws.h> + +#include <qpe/global.h> + +#include "ExtensionInterface.h" + +class TaskSwitcher : public ExtensionInterface +{ +public: + TaskSwitcher(const QString& kind = "switch"); + virtual ~TaskSwitcher(); + + virtual bool onKeyPress(int keycode); + virtual bool onModRelease(int modcode); + virtual int getKeycode() + { + return(m_keycode); + } + virtual int getKeymask() + { + return(m_keymask); + } + virtual const QValueList<int>& getModcodes() + { + return(m_modcodes); + } + virtual void setKeycode(int keycode) + { + m_keycode = keycode; + } + virtual void setKeymask(int keymask) + { + m_keymask = keymask; + } + virtual void setModcodes(const QValueList<int>& modcodes) + { + m_modcodes = modcodes; + } + virtual const QString& kind() + { + return(m_kind); + } +private: + int m_keycode; + int m_keymask; + QString m_kind; + QValueList<int> m_modcodes; + + QStringList m_applist; + QStringList::Iterator m_appit; + + void next(); +}; + +#endif /* _TASK_SWITCHER_H_ */ |