46 #include "optionsWidget.hh" 47 #include <QMessageBox> 51 for (uint i=0; i < plugins_.size(); i++)
52 if (plugins_[i].name == pluginName)
61 std::cerr <<
"set focus\n";
63 if (_item == 0 || _item->parent() == 0 || _item->columnCount() < 7)
66 shortcutButton->setFocus(Qt::TabFocusReason);
72 if (current == 0 || current->parent() == 0 || current->columnCount() < 7){
73 shortcutBox->setEnabled(
false);
74 shortcutButton->setText(
"");
75 defaultShortcut->setText(
"");
77 shortcutBox->setEnabled(
true);
79 shortcutButton->setCurrentShortcut( current->text(4).toInt(), (Qt::KeyboardModifiers) current->text(5).toInt() );
80 defaultShortcut->setText( current->text(2) );
88 if ( keyTree->currentItem() == 0)
91 bool myMultiUse = (bool) keyTree->currentItem()->text(6).toInt();
92 QString myNewKey = shortcutButton->text();
95 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
96 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
98 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
99 QString key = item->text(1);
100 bool multiUse = (bool) item->text(6).toInt();
102 if (keyTree->currentItem() == item)
105 if (key == myNewKey && ( !multiUse || !myMultiUse ) ){
106 QMessageBox::warning(
this, tr(
"OpenFlipper"), tr(
"Could not add Shortcut. Shortcut already assigned."), QMessageBox::Ok);
112 if ( keyTree->currentItem() != 0){
113 keyTree->currentItem()->setText( 1, shortcutButton->text() );
114 keyTree->currentItem()->setText( 4, QString::number( shortcutButton->key() ) );
115 keyTree->currentItem()->setText( 5, QString::number( shortcutButton->modifiers() ) );
118 keyTree->setFocus(Qt::TabFocusReason);
126 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
127 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
130 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
132 if ( item->text(1) != item->text(7) ){
134 QString pluginName = item->parent()->text(0);
138 if (pluginName !=
"Core"){
146 plugin = plugins_[index].plugin;
149 int bindingID = item->text(3).toInt();
150 int key = item->text(4).toInt();
152 Qt::KeyboardModifiers modi = (Qt::KeyboardModifiers) item->text(5).toInt();
154 emit addKeyMapping(key, modi, plugin, bindingID);
162 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
163 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
165 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
166 QString key = item->text(1);
168 QString pluginName = item->parent()->text(0);
169 int bindingID = item->text(3).toInt();
171 if (pluginName ==
"Core"){
173 item->setText( 1, item->text(2) );
174 item->setText( 4, QString::number(coreKeys_[ bindingID ].key) );
175 item->setText( 5, QString::number(coreKeys_[ bindingID ].modifiers) );
185 item->setText( 1, item->text(2) );
186 item->setText( 4, QString::number(plugins_[index].keys[ bindingID ].key) );
187 item->setText( 5, QString::number(plugins_[index].keys[ bindingID ].modifiers) );
191 keyTree->setFocus(Qt::TabFocusReason);
200 keyTree->setEditTriggers(QAbstractItemView::NoEditTriggers);
202 keyTree->setColumnCount ( 8 );
204 QStringList headerdata;
205 headerdata <<
"Action" <<
"Shortcut" <<
"Default" <<
"keyIndex" <<
"currentKey" <<
"currentModi" <<
"MultiUse" <<
"initShortcut";
206 keyTree->setHeaderLabels(headerdata);
209 std::map< QString, QTreeWidgetItem* > parentMap;
211 InverseKeyMap::iterator it;
212 for (it=keys_.begin(); it != keys_.end(); ++it){
214 QObject* plugin = (*it).first.first;
215 int bindingID = (*it).first.second;
216 int key = (*it).second.first;
217 Qt::KeyboardModifiers modifiers = (*it).second.second;
229 name = basePlugin->
name();
247 if ( parentMap.find(name) == parentMap.end() ){
248 parentMap[name] =
new QTreeWidgetItem(keyTree, QStringList(name));
249 keyTree->addTopLevelItem( parentMap[name] );
252 QTreeWidgetItem* parent = parentMap[name];
258 Qt::KeyboardModifiers defModi;
262 description = coreKeys_[bindingID].description;
263 multiUse = coreKeys_[bindingID].multiUse;
264 defKey = coreKeys_[bindingID].key;
265 defModi = coreKeys_[bindingID].modifiers;
269 description = plugins_[i].keys[bindingID].description;
270 multiUse = plugins_[i].keys[bindingID].multiUse;
271 defKey = plugins_[i].keys[bindingID].key;
272 defModi = plugins_[i].keys[bindingID].modifiers;
280 if (key == -1 && modifiers == 0){
281 keyString =
"unassigned";
282 }
else if (key == Qt::Key_AltGr || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta){
283 keyString = QKeySequence( modifiers ).toString();
284 keyString = keyString.left(keyString.size()-1);
286 keyString = QKeySequence( key + modifiers ).toString();
290 if (defKey == -1 && defModi == 0){
291 defaultStr =
"unassigned";
292 }
else if (defKey == Qt::Key_AltGr || defKey == Qt::Key_Alt || defKey == Qt::Key_Control
293 || defKey == Qt::Key_Shift || defKey == Qt::Key_Meta){
294 defaultStr = QKeySequence( defModi ).toString();
295 defaultStr = defaultStr.left(defaultStr.size()-1);
297 defaultStr = QKeySequence( defKey + defModi ).toString();
300 rows << description << keyString << defaultStr << QString::number(bindingID) << QString::number(key)
301 << QString::number(modifiers) << QString::number(multiUse) << keyString;
303 QTreeWidgetItem* keyItem =
new QTreeWidgetItem(parent, rows);
305 parent->addChild( keyItem );
309 keyTree->setColumnWidth(0,350);
310 keyTree->setColumnHidden(3,
true);
311 keyTree->setColumnHidden(4,
true);
312 keyTree->setColumnHidden(5,
true);
313 keyTree->setColumnHidden(6,
true);
314 keyTree->setColumnHidden(7,
true);
virtual QString name()=0
Return a name for the plugin.
Interface class from which all plugins have to be created.