author | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
commit | 2b64a84d39eeed5681d0ee5068c7d11a01527750 (patch) (unidiff) | |
tree | c8693340dbc5ef5e2f9afa90b690829ddff2c4bd /noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp | |
parent | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (diff) | |
download | opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.zip opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.gz opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.bz2 |
other keymapping tool - not working this moment, I have to check it out
- the reason is that the config file is somewhat easier to understand than
from zkbapplet and has a nice config tool.
Please don't put it into any repositories this moment.
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperapplet/extension/TaskSelector.cpp | 225 |
1 files changed, 225 insertions, 0 deletions
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 @@ | |||
1 | #include "TaskSelector.h" | ||
2 | extern QWidget* g_Widget; | ||
3 | |||
4 | static const char* defkeys = | ||
5 | "QWERTYUIOPASDFGHJKLZXCVBNM1234567890"; | ||
6 | |||
7 | #define START_INDEX 1 | ||
8 | |||
9 | TaskSelector::TaskSelector(const QString& kind) : m_kind(kind) | ||
10 | { | ||
11 | qDebug("TaskSelector::TaskSelector()"); | ||
12 | m_pMenu = new QPopupMenuEx(g_Widget); | ||
13 | m_pMenu->installEventFilter(this); | ||
14 | |||
15 | m_isShowing = false; | ||
16 | m_index = START_INDEX-1; | ||
17 | connect(m_pMenu, SIGNAL(activated(int)), this, SLOT(select(int))); | ||
18 | connect(m_pMenu, SIGNAL(highlighted(int)), this, SLOT(highlight(int))); | ||
19 | } | ||
20 | |||
21 | TaskSelector::~TaskSelector() | ||
22 | { | ||
23 | qDebug("TaskSelector::~TaskSelector()"); | ||
24 | delete m_pMenu; | ||
25 | } | ||
26 | |||
27 | bool TaskSelector::onKeyPress(int /*keycode*/) | ||
28 | { | ||
29 | if(m_isShowing){ | ||
30 | qDebug("showing ..."); | ||
31 | } else if(m_pMenu->isVisible()){ | ||
32 | next(); | ||
33 | } else { | ||
34 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
35 | cfg.setGroup("Global"); | ||
36 | int delay = cfg.readNumEntry("DelayPopup", 5); | ||
37 | QTimer::singleShot(delay, this, SLOT(show())); | ||
38 | m_isShowing = true; | ||
39 | } | ||
40 | return true; | ||
41 | } | ||
42 | |||
43 | bool TaskSelector::onModRelease(int /*modcode*/) | ||
44 | { | ||
45 | if(m_pMenu->isVisible()){ | ||
46 | //m_pMenu->hide(); | ||
47 | QTimer::singleShot(0, this, SLOT(select())); | ||
48 | return(true); | ||
49 | } else { | ||
50 | return(false); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | int TaskSelector::buildMenu() | ||
55 | { | ||
56 | const AppLnk* lnk; | ||
57 | |||
58 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
59 | QString oldgroup; | ||
60 | |||
61 | oldgroup = cfg.getGroup(); | ||
62 | cfg.setGroup("Global"); | ||
63 | QString accesskeys = cfg.readEntry("AccessKeys", defkeys); | ||
64 | if(accesskeys.length() <= 0){ | ||
65 | accesskeys = defkeys; | ||
66 | } | ||
67 | cfg.setGroup(oldgroup); | ||
68 | |||
69 | /* get list */ | ||
70 | int cnt = 0; | ||
71 | m_index = START_INDEX+1; | ||
72 | m_applist.clear(); | ||
73 | m_pMenu->clear(); | ||
74 | MenuTitle* pTitle = new MenuTitle("TaskSelector", m_pMenu->font(), kind()); | ||
75 | m_pMenu->insertItem(pTitle); | ||
76 | const QList<QWSWindow>& list = qwsServer->clientWindows(); | ||
77 | QWSWindow* w; | ||
78 | for(QListIterator<QWSWindow> it(list); (w=it.current()); ++it){ | ||
79 | if(w->isVisible() == false | ||
80 | || w->caption() == QString::null){ | ||
81 | continue; | ||
82 | } | ||
83 | QString app = w->client()->identity(); | ||
84 | if(app == NULL || m_applist.contains(app)){ | ||
85 | continue; | ||
86 | } | ||
87 | /* exclude "launcher" */ | ||
88 | if(app == "launcher"){ | ||
89 | if(cnt == 0){ | ||
90 | m_index--; | ||
91 | } | ||
92 | continue; | ||
93 | } | ||
94 | m_applist.append(app); | ||
95 | /* append menu */ | ||
96 | cnt++; | ||
97 | AppLnkSet* lnkSet = AppLnkManager::getInstance(); | ||
98 | lnk = lnkSet->findExec(app); | ||
99 | QString text; | ||
100 | QPixmap icon; | ||
101 | #if 0 | ||
102 | if(lnk != NULL){ | ||
103 | icon = lnk->pixmap(); | ||
104 | text = lnk->name(); | ||
105 | } else { | ||
106 | AppLnkManager::notfound(); | ||
107 | icon = QPixmap(); | ||
108 | text = w->caption(); | ||
109 | } | ||
110 | #else | ||
111 | if(lnk != NULL){ | ||
112 | icon = lnk->pixmap(); | ||
113 | if(w->caption().length() > 0){ | ||
114 | text = w->caption(); | ||
115 | } else { | ||
116 | text = lnk->name(); | ||
117 | } | ||
118 | } else { | ||
119 | AppLnkManager::notfound(); | ||
120 | icon = QPixmap(); | ||
121 | text = w->caption(); | ||
122 | } | ||
123 | #endif | ||
124 | if(cnt <= (int)accesskeys.length()){ | ||
125 | text.append("(&"); | ||
126 | text.append(accesskeys[cnt-1].upper()); | ||
127 | text.append(")"); | ||
128 | } | ||
129 | m_pMenu->insertItem(icon, text, cnt); | ||
130 | } | ||
131 | return(cnt); | ||
132 | } | ||
133 | |||
134 | void TaskSelector::show() | ||
135 | { | ||
136 | /* build task selector menu */ | ||
137 | int cnt = buildMenu(); | ||
138 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
139 | QString oldgroup = cfg.getGroup(); | ||
140 | cfg.setGroup("Global"); | ||
141 | int min = cfg.readNumEntry("SelectMenuMin", 2); | ||
142 | if(min != 1 && min != 3){ | ||
143 | min = 2; | ||
144 | } | ||
145 | cfg.setGroup(oldgroup); | ||
146 | |||
147 | if(cnt == 0){ | ||
148 | qDebug("no applications"); | ||
149 | } else if(cnt < min){ | ||
150 | //m_index = START_INDEX; | ||
151 | if(m_index > cnt){ | ||
152 | m_index = cnt; | ||
153 | } | ||
154 | QTimer::singleShot(0, this, SLOT(select())); | ||
155 | } else { | ||
156 | if(m_index > cnt){ | ||
157 | m_index = cnt; | ||
158 | } | ||
159 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
160 | cfg.setGroup("Style"); | ||
161 | int x,y; | ||
162 | QString key = "Position_" + kind(); | ||
163 | if(cfg.hasKey(key)){ | ||
164 | const QStringList& list = cfg.readListEntry(key, ','); | ||
165 | x = list[0].toInt(); | ||
166 | y = list[1].toInt(); | ||
167 | } else { | ||
168 | x = (qt_screen->width() - m_pMenu->sizeHint().width()) / 2; | ||
169 | y = (qt_screen->height() - m_pMenu->sizeHint().height()) / 2; | ||
170 | } | ||
171 | QPoint pos(x, y); | ||
172 | m_pMenu->popup(pos); | ||
173 | m_pMenu->setActiveItem(m_index); | ||
174 | } | ||
175 | m_isShowing = false; | ||
176 | } | ||
177 | |||
178 | void TaskSelector::next() | ||
179 | { | ||
180 | m_index++; | ||
181 | if(m_index > (signed int)m_applist.count()){ | ||
182 | m_index = START_INDEX; | ||
183 | } | ||
184 | m_pMenu->setActiveItem(m_index); | ||
185 | } | ||
186 | |||
187 | void TaskSelector::select() | ||
188 | { | ||
189 | //select(m_index); | ||
190 | m_pMenu->activateItemAt(m_index); | ||
191 | } | ||
192 | |||
193 | void TaskSelector::select(int index) | ||
194 | { | ||
195 | if(index > 0){ | ||
196 | Global::execute(m_applist[index-1]); | ||
197 | } | ||
198 | m_index = 0; | ||
199 | } | ||
200 | |||
201 | void TaskSelector::highlight(int index) | ||
202 | { | ||
203 | if(m_pMenu->isVisible()){ | ||
204 | m_index = index; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | bool TaskSelector::eventFilter(QObject* o, QEvent* e) | ||
209 | { | ||
210 | if(m_pMenu->isVisible()){ | ||
211 | QKeyEvent* ke = (QKeyEvent*)e; | ||
212 | switch(e->type()){ | ||
213 | case QEvent::Accel: | ||
214 | if(ke->key() == Qt::Key_Space | ||
215 | && ke->isAutoRepeat() == false){ | ||
216 | select(); | ||
217 | } | ||
218 | break; | ||
219 | default: | ||
220 | //qDebug(">>>>> [%p][%d] <<<<<", o, e->type()); | ||
221 | break; | ||
222 | } | ||
223 | } | ||
224 | return QObject::eventFilter(o, e); | ||
225 | } | ||