Rev 15021 | Rev 17295 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
13761 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
14610 | cbradney | 8 | #include <QDomDocument> |
9 | #include <QFileDialog> |
||
10 | #include <QInputDialog> |
||
11 | #include <QMessageBox> |
||
13761 | cbradney | 12 | |
14610 | cbradney | 13 | #include "ui/prefs_keyboardshortcuts.h" |
14 | #include "actionmanager.h" |
||
15 | #include "commonstrings.h" |
||
16 | #include "pluginmanager.h" |
||
17 | #include "prefsmanager.h" |
||
18 | #include "prefsstructs.h" |
||
19 | #include "prefsfile.h" |
||
20 | #include "prefscontext.h" |
||
21 | #include "scpaths.h" |
||
22 | #include "scplugin.h" |
||
23 | #include "scraction.h" |
||
24 | #include "util.h" |
||
25 | #include "util_icon.h" |
||
26 | |||
15021 | cbradney | 27 | Prefs_KeyboardShortcuts::Prefs_KeyboardShortcuts(QWidget* parent, ScribusDoc* doc) |
14610 | cbradney | 28 | : Prefs_Pane(parent) |
13761 | cbradney | 29 | { |
30 | setupUi(this); |
||
14610 | cbradney | 31 | languageChange(); |
13761 | cbradney | 32 | |
14610 | cbradney | 33 | defMenus=ActionManager::defaultMenus(); |
34 | defNonMenuActions=ActionManager::defaultNonMenuActions(); |
||
35 | |||
36 | QVector< QPair<QString, QStringList> >::Iterator itnmenua = defNonMenuActions->begin(); |
||
37 | PluginManager& pluginManager(PluginManager::instance()); |
||
38 | QStringList pluginNames(pluginManager.pluginNames(false)); |
||
39 | ScPlugin* plugin; |
||
40 | ScActionPlugin* ixplug; |
||
41 | QString pName; |
||
42 | for (int i = 0; i < pluginNames.count(); ++i) |
||
43 | { |
||
44 | pName = pluginNames.at(i); |
||
45 | plugin = pluginManager.getPlugin(pName, true); |
||
46 | Q_ASSERT(plugin); // all the returned names should represent loaded plugins |
||
47 | if (plugin->inherits("ScActionPlugin")) |
||
48 | { |
||
49 | ixplug = dynamic_cast<ScActionPlugin*>(plugin); |
||
50 | Q_ASSERT(ixplug); |
||
51 | ScActionPlugin::ActionInfo ai(ixplug->actionInfo()); |
||
52 | itnmenua->second << ai.name; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | Q_CHECK_PTR(defMenus); |
||
57 | lviToActionMap.clear(); |
||
58 | lviToMenuMap.clear(); |
||
59 | keyTable->clear(); |
||
60 | keyMap.clear(); |
||
61 | //keyMap = oldKeyMap; |
||
62 | Part0 = ""; |
||
63 | Part1 = ""; |
||
64 | Part2 = ""; |
||
65 | Part3 = ""; |
||
66 | Part4 = ""; |
||
67 | keyCode = 0; |
||
68 | keyDisplay->setMinimumWidth(fontMetrics().width("CTRL+ALT+SHIFT+W")); |
||
69 | keyDisplay->setText(""); |
||
70 | |||
71 | clearSearchButton->setIcon(loadIcon("clear_right.png")); |
||
72 | // signals and slots connections |
||
73 | connect( keyTable, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), |
||
74 | this, SLOT(dispKey(QTreeWidgetItem *, QTreeWidgetItem *))); |
||
75 | connect( noKey, SIGNAL(clicked()), this, SLOT(setNoKey())); |
||
76 | connect( setKeyButton, SIGNAL(clicked()), this, SLOT(setKeyText())); |
||
77 | connect( loadSetButton, SIGNAL(clicked()), this, SLOT(loadKeySetFile())); |
||
78 | connect( importSetButton, SIGNAL(clicked()), this, SLOT(importKeySetFile())); |
||
79 | connect( exportSetButton, SIGNAL(clicked()), this, SLOT(exportKeySetFile())); |
||
80 | connect( resetSetButton, SIGNAL(clicked()), this, SLOT(resetKeySet())); |
||
81 | connect( clearSearchButton, SIGNAL(clicked()), this, SLOT(clearSearchString())); |
||
82 | connect( searchTextLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(applySearch(const QString&))); |
||
83 | |||
13761 | cbradney | 84 | } |
85 | |||
86 | Prefs_KeyboardShortcuts::~Prefs_KeyboardShortcuts() |
||
87 | { |
||
88 | } |
||
89 | |||
14610 | cbradney | 90 | void Prefs_KeyboardShortcuts::languageChange() |
91 | { |
||
92 | } |
||
93 | |||
94 | void Prefs_KeyboardShortcuts::restoreDefaults(struct ApplicationPrefs *prefsData) |
||
95 | { |
||
96 | keyMap=prefsData->keyShortcutPrefs.KeyActions; |
||
97 | loadableSets->clear(); |
||
98 | loadableSets->addItems(scanForSets()); |
||
99 | insertActions(); |
||
100 | dispKey(0); |
||
101 | } |
||
102 | |||
103 | void Prefs_KeyboardShortcuts::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const |
||
104 | { |
||
105 | prefsData->keyShortcutPrefs.KeyActions=keyMap; |
||
106 | } |
||
107 | |||
108 | void Prefs_KeyboardShortcuts::setNoKey() |
||
109 | { |
||
110 | if (noKey->isChecked()) |
||
111 | { |
||
112 | if (selectedLVI!=0) |
||
113 | { |
||
114 | selectedLVI->setText(1,""); |
||
115 | keyMap[lviToActionMap[selectedLVI]].keySequence=QKeySequence(); |
||
116 | } |
||
117 | keyDisplay->setText(""); |
||
118 | noKey->setChecked(true); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | void Prefs_KeyboardShortcuts::loadKeySetFile() |
||
123 | { |
||
124 | if (keySetList.contains(loadableSets->currentText())) |
||
125 | importKeySet(keySetList[loadableSets->currentText()]); |
||
126 | } |
||
127 | |||
128 | void Prefs_KeyboardShortcuts::importKeySetFile() |
||
129 | { |
||
130 | PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); |
||
131 | QString currentPath = dirs->get("keymapprefs_import", ScPaths::instance().shareDir() + "keysets/"); |
||
132 | QString s = QFileDialog::getOpenFileName(this, tr("Select a Key set file to read"), currentPath, tr("Key Set XML Files (*.xml)")); |
||
133 | if (!s.isEmpty()) |
||
134 | importKeySet(s); |
||
135 | } |
||
136 | void Prefs_KeyboardShortcuts::exportKeySetFile() |
||
137 | { |
||
138 | PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs"); |
||
139 | QString currentPath= dirs->get("keymapprefs_export", "."); |
||
140 | QString s = QFileDialog::getSaveFileName(this, tr("Select a Key set file to save to"), currentPath, tr("Key Set XML Files (*.xml)") ); |
||
141 | if (!s.isEmpty()) |
||
142 | exportKeySet(s); |
||
143 | } |
||
144 | |||
145 | void Prefs_KeyboardShortcuts::importKeySet(QString filename) |
||
146 | { |
||
147 | searchTextLineEdit->clear(); |
||
148 | QFileInfo fi = QFileInfo(filename); |
||
149 | if (fi.exists()) |
||
150 | { |
||
151 | //import the file into qdomdoc |
||
152 | QDomDocument doc( "keymapentries" ); |
||
153 | QFile file1( filename ); |
||
154 | if ( !file1.open( QIODevice::ReadOnly ) ) |
||
155 | return; |
||
156 | QTextStream ts(&file1); |
||
157 | ts.setCodec("UTF-8"); |
||
158 | QString errorMsg; |
||
159 | int eline; |
||
160 | int ecol; |
||
161 | if ( !doc.setContent( ts.readAll(), &errorMsg, &eline, &ecol )) |
||
162 | { |
||
163 | qDebug("%s", QString("Could not open key set file: %1\nError:%2 at line: %3, row: %4").arg(filename).arg(errorMsg).arg(eline).arg(ecol).toAscii().constData()); |
||
164 | file1.close(); |
||
165 | return; |
||
166 | } |
||
167 | file1.close(); |
||
168 | //load the file now |
||
169 | QDomElement docElem = doc.documentElement(); |
||
170 | if (docElem.tagName()=="shortcutset" && docElem.hasAttribute("name")) |
||
171 | { |
||
172 | QDomAttr keysetAttr = docElem.attributeNode( "name" ); |
||
173 | |||
174 | //clear current menu entries |
||
175 | for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=keyMap.end(); ++it) |
||
176 | it.value().keySequence = QKeySequence(); |
||
177 | |||
178 | //load in new set |
||
179 | QDomNode n = docElem.firstChild(); |
||
180 | while( !n.isNull() ) |
||
181 | { |
||
182 | QDomElement e = n.toElement(); // try to convert the node to an element. |
||
183 | if( !e.isNull() ) |
||
184 | { |
||
185 | if (e.hasAttribute("name") && e.hasAttribute( "shortcut" )) |
||
186 | { |
||
187 | QDomAttr nameAttr = e.attributeNode( "name" ); |
||
188 | QDomAttr shortcutAttr = e.attributeNode( "shortcut" ); |
||
189 | if (keyMap.contains(nameAttr.value())) |
||
190 | keyMap[nameAttr.value()].keySequence=QKeySequence(shortcutAttr.value()); |
||
191 | } |
||
192 | } |
||
193 | n = n.nextSibling(); |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | insertActions(); |
||
198 | } |
||
199 | |||
200 | bool Prefs_KeyboardShortcuts::exportKeySet(QString filename) |
||
201 | { |
||
202 | QFileInfo fi = QFileInfo(filename); |
||
203 | QString exportFileName; |
||
204 | if (filename.endsWith(".xml")) |
||
205 | exportFileName = filename; |
||
206 | else |
||
207 | exportFileName = filename+".xml"; |
||
208 | if (overwrite(this, exportFileName)) |
||
209 | { |
||
210 | bool ok; |
||
211 | QString setName = QInputDialog::getText(this, tr("Export Keyboard Shortcuts to File"), tr("Enter the name of the shortcut set:"), QLineEdit::Normal, QString::null, &ok); |
||
212 | if (!( ok && !setName.isEmpty()) ) |
||
213 | return false; |
||
214 | |||
215 | QDomDocument doc( "keymapentries" ); |
||
216 | QString keyset=QString("<shortcutset name=\"%1\"></shortcutset>").arg(setName); |
||
217 | doc.setContent(keyset); |
||
218 | QDomElement keySetElement=doc.documentElement(); |
||
219 | QMap<QString,Keys>::Iterator itEnd=keyMap.end(); |
||
220 | for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=itEnd; ++it) |
||
221 | { |
||
222 | if (it.value().keySequence.isEmpty() && it.key().isEmpty()) |
||
223 | continue; |
||
224 | QDomElement function_shortcut=doc.createElement("function"); |
||
225 | function_shortcut.setAttribute("name",it.key()); |
||
226 | function_shortcut.setAttribute("shortcut",getKeyText(it.value().keySequence)); |
||
227 | keySetElement.appendChild(function_shortcut); |
||
228 | } |
||
229 | QFile f(filename); |
||
230 | if(!f.open(QIODevice::WriteOnly)) |
||
231 | return false; |
||
232 | QDataStream s(&f); |
||
233 | QByteArray xmltag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
||
234 | s.writeRawData(xmltag.data(), xmltag.length()); |
||
235 | QByteArray xmldoc = doc.toByteArray(4); |
||
236 | s.writeRawData(xmldoc, xmldoc.length()); |
||
237 | f.close(); |
||
238 | } |
||
239 | return true; |
||
240 | } |
||
241 | |||
242 | void Prefs_KeyboardShortcuts::resetKeySet() |
||
243 | { |
||
244 | QString location=ScPaths::instance().shareDir(); |
||
16577 | craig | 245 | QString defaultKeySetFileName=QDir::toNativeSeparators(location+"keysets/scribus15.xml"); |
14610 | cbradney | 246 | importKeySet(defaultKeySetFileName); |
247 | } |
||
248 | |||
249 | QStringList Prefs_KeyboardShortcuts::scanForSets() |
||
250 | { |
||
251 | keySetList.clear(); |
||
252 | QString location=ScPaths::instance().shareDir(); |
||
16577 | craig | 253 | QString keySetLocation=QDir::toNativeSeparators(location+"keysets/"); |
14610 | cbradney | 254 | QDir keySetsDir(keySetLocation, "*.xml", QDir::Name, QDir::Files | QDir::NoSymLinks); |
255 | if ((keySetsDir.exists()) && (keySetsDir.count() != 0)) |
||
256 | { |
||
257 | QStringList appNames; |
||
258 | for (uint fileCounter = 0; fileCounter < keySetsDir.count(); ++fileCounter) |
||
259 | { |
||
16577 | craig | 260 | QString filename=QDir::toNativeSeparators(location+"keysets/"+keySetsDir[fileCounter]); |
14610 | cbradney | 261 | |
262 | QDomDocument doc( "keymapentries" ); |
||
263 | QFile file( filename ); |
||
264 | if ( !file.open( QIODevice::ReadOnly ) ) |
||
265 | continue; |
||
266 | QString errorMsg; |
||
267 | int eline; |
||
268 | int ecol; |
||
269 | |||
270 | if ( !doc.setContent( &file, &errorMsg, &eline, &ecol )) |
||
271 | { |
||
272 | qDebug("%s", QString("Could not open key set file: %1\nError:%2 at line: %3, row: %4").arg(keySetsDir[fileCounter]).arg(errorMsg).arg(eline).arg(ecol).toAscii().constData()); |
||
273 | file.close(); |
||
274 | continue; |
||
275 | } |
||
276 | file.close(); |
||
277 | |||
278 | QDomElement docElem = doc.documentElement(); |
||
279 | if (docElem.tagName()=="shortcutset" && docElem.hasAttribute("name")) |
||
280 | { |
||
281 | QDomAttr nameAttr = docElem.attributeNode( "name" ); |
||
282 | appNames.append(nameAttr.value()); |
||
283 | keySetList.insert(nameAttr.value(), filename); |
||
284 | } |
||
285 | } |
||
286 | return QStringList(appNames); |
||
287 | } |
||
288 | return QStringList(); |
||
289 | } |
||
290 | |||
291 | QString Prefs_KeyboardShortcuts::getKeyText(int KeyC) |
||
292 | { |
||
293 | if ((KeyC & ~(Qt::META | Qt::CTRL | Qt::ALT | Qt::SHIFT)) == 0) |
||
294 | return ""; |
||
295 | // on OSX Qt translates modifiers to forsaken symbols, arrows and the like |
||
296 | // we prefer plain English |
||
297 | QString res; |
||
298 | if ((KeyC & Qt::META) != 0) |
||
299 | res += "Meta+"; |
||
300 | if ((KeyC & Qt::CTRL) != 0) |
||
301 | res += "Ctrl+"; |
||
302 | if ((KeyC & Qt::ALT) != 0) |
||
303 | res += "Alt+"; |
||
304 | if ((KeyC & Qt::SHIFT) != 0) |
||
305 | res += "Shift+"; |
||
306 | return res + QString(QKeySequence(KeyC & ~(Qt::META | Qt::CTRL | Qt::ALT | Qt::SHIFT))); |
||
307 | } |
||
308 | |||
309 | void Prefs_KeyboardShortcuts::setKeyText() |
||
310 | { |
||
311 | if (keyTable->currentItem()==0) |
||
312 | { |
||
313 | setKeyButton->setChecked(false); |
||
314 | return; |
||
315 | } |
||
316 | if (setKeyButton->isChecked()) |
||
317 | { |
||
318 | keyCode = 0; |
||
319 | Part0 = ""; |
||
320 | Part1 = ""; |
||
321 | Part2 = ""; |
||
322 | Part3 = ""; |
||
323 | Part4 = ""; |
||
324 | grabKeyboard(); |
||
325 | } |
||
326 | else |
||
327 | releaseKeyboard(); |
||
328 | } |
||
329 | |||
330 | void Prefs_KeyboardShortcuts::insertActions() |
||
331 | { |
||
332 | lviToActionMap.clear(); |
||
333 | lviToMenuMap.clear(); |
||
334 | keyTable->clear(); |
||
335 | bool first, firstMenu=true; |
||
336 | QTreeWidgetItem *currLVI = NULL; |
||
337 | QTreeWidgetItem *currMenuLVI = NULL; |
||
338 | QTreeWidgetItem *prevLVI = NULL; |
||
339 | QTreeWidgetItem *prevMenuLVI = NULL; |
||
340 | for (QVector< QPair<QString, QStringList> >::Iterator itmenu = defMenus->begin(); itmenu != defMenus->end(); ++itmenu ) |
||
341 | { |
||
342 | if (firstMenu) |
||
343 | { |
||
344 | currMenuLVI = new QTreeWidgetItem(keyTable); |
||
345 | firstMenu = false; |
||
346 | } |
||
347 | else |
||
348 | currMenuLVI = new QTreeWidgetItem(keyTable, prevMenuLVI); |
||
349 | Q_CHECK_PTR(currMenuLVI); |
||
350 | lviToMenuMap.append(currMenuLVI); |
||
351 | currMenuLVI->setText(0, itmenu->first); |
||
352 | currMenuLVI->setExpanded(true); |
||
353 | prevMenuLVI=currMenuLVI; |
||
354 | first=true; |
||
355 | currLVI=0; |
||
356 | prevLVI=0; |
||
357 | for ( QStringList::Iterator it = itmenu->second.begin(); it != itmenu->second.end(); ++it ) |
||
358 | { |
||
359 | if (first) |
||
360 | { |
||
361 | currLVI = new QTreeWidgetItem(currMenuLVI); |
||
362 | first = false; |
||
363 | } |
||
364 | else |
||
365 | currLVI = new QTreeWidgetItem(currMenuLVI, prevLVI); |
||
366 | Q_CHECK_PTR(currLVI); |
||
367 | lviToActionMap.insert(currLVI, *it); |
||
368 | currLVI->setText(0, keyMap[*it].cleanMenuText); |
||
369 | currLVI->setText(1, keyMap[*it].keySequence); |
||
370 | prevLVI=currLVI; |
||
371 | } |
||
372 | } |
||
373 | //Non menu actions |
||
374 | for (QVector< QPair<QString, QStringList> >::Iterator itmenu = defNonMenuActions->begin(); itmenu != defNonMenuActions->end(); ++itmenu ) |
||
375 | { |
||
376 | if (firstMenu) |
||
377 | { |
||
378 | currMenuLVI = new QTreeWidgetItem(keyTable); |
||
379 | firstMenu = false; |
||
380 | } |
||
381 | else |
||
382 | currMenuLVI = new QTreeWidgetItem(keyTable, prevMenuLVI); |
||
383 | Q_CHECK_PTR(currMenuLVI); |
||
384 | lviToMenuMap.append(currMenuLVI); |
||
385 | currMenuLVI->setText(0, itmenu->first); |
||
386 | currMenuLVI->setExpanded(true); |
||
387 | prevMenuLVI=currMenuLVI; |
||
388 | first=true; |
||
389 | currLVI=0; |
||
390 | prevLVI=0; |
||
391 | for ( QStringList::Iterator it = itmenu->second.begin(); it != itmenu->second.end(); ++it ) |
||
392 | { |
||
393 | if (first) |
||
394 | { |
||
395 | currLVI=new QTreeWidgetItem(currMenuLVI); |
||
396 | first=false; |
||
397 | } |
||
398 | else |
||
399 | currLVI=new QTreeWidgetItem(currMenuLVI, prevLVI); |
||
400 | Q_CHECK_PTR(currLVI); |
||
401 | lviToActionMap.insert(currLVI, *it); |
||
402 | currLVI->setText(0, keyMap[*it].cleanMenuText); |
||
403 | currLVI->setText(1, keyMap[*it].keySequence); |
||
404 | prevLVI=currLVI; |
||
405 | } |
||
406 | } |
||
407 | keyTable->resizeColumnToContents(0); |
||
408 | } |
||
409 | |||
410 | void Prefs_KeyboardShortcuts::applySearch( const QString & newss ) |
||
411 | { |
||
412 | //Must run this as if newss is not empty and we go to the next for loop, the set visible doesnt work |
||
413 | for (QList<QTreeWidgetItem*>::iterator it=lviToMenuMap.begin(); it!=lviToMenuMap.end(); ++it) |
||
414 | (*it)->setHidden(false); |
||
415 | if (newss.isEmpty()) |
||
416 | { |
||
417 | for (QMap<QTreeWidgetItem*, QString>::iterator it=lviToActionMap.begin(); it!=lviToActionMap.end(); ++it) |
||
418 | it.key()->setHidden(false); |
||
419 | return; |
||
420 | } |
||
421 | //Seem to need to do this.. isOpen doesnt seem to do what it says |
||
422 | for (QMap<QTreeWidgetItem*, QString>::iterator it=lviToActionMap.begin(); it!=lviToActionMap.end(); ++it) |
||
423 | { |
||
424 | if (it.key()->text(0).contains(newss, Qt::CaseInsensitive)) |
||
425 | it.key()->setHidden(false); |
||
426 | else |
||
427 | it.key()->setHidden(true); |
||
428 | } |
||
429 | } |
||
430 | |||
431 | void Prefs_KeyboardShortcuts::dispKey(QTreeWidgetItem* qlvi, QTreeWidgetItem*) |
||
432 | { |
||
433 | if (qlvi!=0 && lviToActionMap.contains(qlvi)) |
||
434 | { |
||
435 | selectedLVI=qlvi; |
||
436 | QString actionName=lviToActionMap[qlvi]; |
||
437 | if (actionName.isEmpty()) |
||
438 | return; |
||
439 | keyDisplay->setText(keyMap[actionName].keySequence); |
||
440 | if (keyMap[actionName].keySequence.isEmpty()) |
||
441 | noKey->setChecked(true); |
||
442 | else |
||
443 | userDef->setChecked(true); |
||
444 | } |
||
445 | else |
||
446 | { |
||
447 | noKey->setChecked(true); |
||
448 | keyDisplay->setText(""); |
||
449 | selectedLVI=0; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | bool Prefs_KeyboardShortcuts::event( QEvent* ev ) |
||
454 | { |
||
455 | bool ret = QWidget::event( ev ); |
||
456 | if ( ev->type() == QEvent::KeyPress ) |
||
457 | keyPressEvent((QKeyEvent*)ev); |
||
458 | if ( ev->type() == QEvent::KeyRelease ) |
||
459 | keyReleaseEvent((QKeyEvent*)ev); |
||
460 | return ret; |
||
461 | } |
||
462 | |||
463 | void Prefs_KeyboardShortcuts::keyPressEvent(QKeyEvent *k) |
||
464 | { |
||
465 | if (setKeyButton->isChecked()) |
||
466 | { |
||
467 | QStringList tl; |
||
468 | Part4 = ""; |
||
469 | if (!keyDisplay->text().isEmpty()) |
||
470 | { |
||
471 | tl = keyDisplay->text().split("+", QString::SkipEmptyParts); |
||
472 | if (tl.count() > 0) |
||
473 | { |
||
474 | Part4 = tl[tl.count()-1]; |
||
475 | if (Part4 == tr("Alt") || Part4 == tr("Ctrl") || Part4 == tr("Shift") || Part4 == tr("Meta")) |
||
476 | Part4 = ""; |
||
477 | } |
||
478 | } |
||
479 | switch (k->key()) |
||
480 | { |
||
481 | case Qt::Key_Meta: |
||
482 | Part0 = tr("Meta+"); |
||
483 | keyCode |= Qt::META; |
||
484 | break; |
||
485 | case Qt::Key_Shift: |
||
486 | Part3 = tr("Shift+"); |
||
487 | keyCode |= Qt::SHIFT; |
||
488 | break; |
||
489 | case Qt::Key_Alt: |
||
490 | Part2 = tr("Alt+"); |
||
491 | keyCode |= Qt::ALT; |
||
492 | break; |
||
493 | case Qt::Key_Control: |
||
494 | Part1 = tr("Ctrl+"); |
||
495 | keyCode |= Qt::CTRL; |
||
496 | break; |
||
497 | default: |
||
498 | keyCode |= k->key(); |
||
499 | keyDisplay->setText(getKeyText(keyCode)); |
||
500 | releaseKeyboard(); |
||
501 | if (checkKey(keyCode)) |
||
502 | { |
||
503 | QMessageBox::information(this, CommonStrings::trWarning, |
||
504 | tr("This key sequence is already in use"), |
||
505 | CommonStrings::tr_OK); |
||
506 | selectedLVI->setText(1,keyMap[lviToActionMap[selectedLVI]].keySequence); |
||
507 | keyDisplay->setText(keyMap[lviToActionMap[selectedLVI]].keySequence); |
||
508 | } |
||
509 | else |
||
510 | { |
||
511 | QKeySequence newKeySequence(keyCode); |
||
512 | selectedLVI->setText(1, QString(newKeySequence)); |
||
513 | keyMap[lviToActionMap[selectedLVI]].keySequence=newKeySequence; |
||
514 | userDef->setChecked(true); |
||
515 | } |
||
516 | setKeyButton->setChecked(false); |
||
517 | } |
||
518 | } |
||
519 | if (setKeyButton->isChecked()) |
||
520 | keyDisplay->setText(Part0+Part1+Part2+Part3+Part4); |
||
521 | } |
||
522 | |||
523 | void Prefs_KeyboardShortcuts::keyReleaseEvent(QKeyEvent *k) |
||
524 | { |
||
525 | if (setKeyButton->isChecked()) |
||
526 | { |
||
527 | Part4 = ""; |
||
528 | if (!keyDisplay->text().isEmpty()) |
||
529 | { |
||
530 | QStringList tl; |
||
531 | tl = keyDisplay->text().split("+", QString::SkipEmptyParts); |
||
532 | if (tl.count() > 0) |
||
533 | { |
||
534 | Part4 = tl[tl.count()-1]; |
||
535 | if (Part4 == tr("Alt") || Part4 == tr("Ctrl") || Part4 == tr("Shift") || Part4 == tr("Meta")) |
||
536 | Part4 = ""; |
||
537 | } |
||
538 | } |
||
539 | if (k->key() == Qt::Key_Meta) |
||
540 | { |
||
541 | Part0 = ""; |
||
542 | keyCode &= ~Qt::META; |
||
543 | } |
||
544 | if (k->key() == Qt::Key_Shift) |
||
545 | { |
||
546 | Part3 = ""; |
||
547 | keyCode &= ~Qt::SHIFT; |
||
548 | } |
||
549 | if (k->key() == Qt::Key_Alt) |
||
550 | { |
||
551 | Part2 = ""; |
||
552 | keyCode &= ~Qt::ALT; |
||
553 | } |
||
554 | if (k->key() == Qt::Key_Control) |
||
555 | { |
||
556 | Part1 = ""; |
||
557 | keyCode &= ~Qt::CTRL; |
||
558 | } |
||
559 | keyDisplay->setText(Part0+Part1+Part2+Part3+Part4); |
||
560 | } |
||
561 | } |
||
562 | |||
563 | bool Prefs_KeyboardShortcuts::checkKey(int code) |
||
564 | { |
||
565 | bool ret = false; |
||
566 | QKeySequence key = QKeySequence(code); |
||
567 | for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=keyMap.end(); ++it) |
||
568 | { |
||
569 | if (key.matches(it.value().keySequence) != QKeySequence::NoMatch) |
||
570 | { |
||
571 | ret = true; |
||
572 | break; |
||
573 | } |
||
574 | } |
||
575 | return ret; |
||
576 | } |
||
577 | |||
578 | void Prefs_KeyboardShortcuts::clearSearchString( ) |
||
579 | { |
||
580 | searchTextLineEdit->clear(); |
||
581 | } |
||
582 |