52 #include "optionsWidget.hh"
56 for (uint i=0; i < plugins_.size(); i++)
57 if (plugins_[i].name == pluginName)
66 std::cerr <<
"set focus\n";
68 if (_item == 0 || _item->parent() == 0 || _item->columnCount() < 7)
71 shortcutButton->setFocus(Qt::TabFocusReason);
77 if (current == 0 || current->parent() == 0 || current->columnCount() < 7){
78 shortcutBox->setEnabled(
false);
79 shortcutButton->setText(
"");
80 defaultShortcut->setText(
"");
82 shortcutBox->setEnabled(
true);
84 shortcutButton->setCurrentShortcut( current->text(4).toInt(), (Qt::KeyboardModifiers) current->text(5).toInt() );
85 defaultShortcut->setText( current->text(2) );
93 if ( keyTree->currentItem() == 0)
96 bool myMultiUse = (bool) keyTree->currentItem()->text(6).toInt();
97 QString myNewKey = shortcutButton->text();
100 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
101 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
103 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
104 QString key = item->text(1);
105 bool multiUse = (bool) item->text(6).toInt();
107 if (keyTree->currentItem() == item)
110 if (key == myNewKey && ( !multiUse || !myMultiUse ) ){
111 QMessageBox::warning(
this, tr(
"OpenFlipper"), tr(
"Could not add Shortcut. Shortcut already assigned."), QMessageBox::Ok);
117 if ( keyTree->currentItem() != 0){
118 keyTree->currentItem()->setText( 1, shortcutButton->text() );
119 keyTree->currentItem()->setText( 4, QString::number( shortcutButton->key() ) );
120 keyTree->currentItem()->setText( 5, QString::number( shortcutButton->modifiers() ) );
123 keyTree->setFocus(Qt::TabFocusReason);
131 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
132 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
135 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
137 if ( item->text(1) != item->text(7) ){
139 QString pluginName = item->parent()->text(0);
143 if (pluginName !=
"Core"){
151 plugin = plugins_[index].plugin;
154 int bindingID = item->text(3).toInt();
155 int key = item->text(4).toInt();
157 Qt::KeyboardModifiers modi = (Qt::KeyboardModifiers) item->text(5).toInt();
159 emit addKeyMapping(key, modi, plugin, bindingID);
167 for (
int i=0; i < keyTree->topLevelItemCount(); i++)
168 for (
int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
170 QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
171 QString key = item->text(1);
173 QString pluginName = item->parent()->text(0);
174 int bindingID = item->text(3).toInt();
176 if (pluginName ==
"Core"){
178 item->setText( 1, item->text(2) );
179 item->setText( 4, QString::number(coreKeys_[ bindingID ].key) );
180 item->setText( 5, QString::number(coreKeys_[ bindingID ].modifiers) );
190 item->setText( 1, item->text(2) );
191 item->setText( 4, QString::number(plugins_[index].keys[ bindingID ].key) );
192 item->setText( 5, QString::number(plugins_[index].keys[ bindingID ].modifiers) );
196 keyTree->setFocus(Qt::TabFocusReason);
205 keyTree->setEditTriggers(QAbstractItemView::NoEditTriggers);
207 keyTree->setColumnCount ( 8 );
209 QStringList headerdata;
210 headerdata <<
"Action" <<
"Shortcut" <<
"Default" <<
"keyIndex" <<
"currentKey" <<
"currentModi" <<
"MultiUse" <<
"initShortcut";
211 keyTree->setHeaderLabels(headerdata);
214 std::map< QString, QTreeWidgetItem* > parentMap;
216 InverseKeyMap::iterator it;
217 for (it=keys_.begin(); it != keys_.end(); ++it){
219 QObject* plugin = (*it).first.first;
220 int bindingID = (*it).first.second;
221 int key = (*it).second.first;
222 Qt::KeyboardModifiers modifiers = (*it).second.second;
234 name = basePlugin->
name();
252 if ( parentMap.find(name) == parentMap.end() ){
253 parentMap[name] =
new QTreeWidgetItem(keyTree, QStringList(name));
254 keyTree->addTopLevelItem( parentMap[name] );
257 QTreeWidgetItem* parent = parentMap[name];
263 Qt::KeyboardModifiers defModi;
267 description = coreKeys_[bindingID].description;
268 multiUse = coreKeys_[bindingID].multiUse;
269 defKey = coreKeys_[bindingID].key;
270 defModi = coreKeys_[bindingID].modifiers;
274 description = plugins_[i].keys[bindingID].description;
275 multiUse = plugins_[i].keys[bindingID].multiUse;
276 defKey = plugins_[i].keys[bindingID].key;
277 defModi = plugins_[i].keys[bindingID].modifiers;
285 if (key == -1 && modifiers == 0){
286 keyString =
"unassigned";
287 }
else if (key == Qt::Key_AltGr || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Meta){
288 keyString = QKeySequence( modifiers ).toString();
289 keyString = keyString.left(keyString.size()-1);
291 keyString = QKeySequence( key + modifiers ).toString();
295 if (defKey == -1 && defModi == 0){
296 defaultStr =
"unassigned";
297 }
else if (defKey == Qt::Key_AltGr || defKey == Qt::Key_Alt || defKey == Qt::Key_Control
298 || defKey == Qt::Key_Shift || defKey == Qt::Key_Meta){
299 defaultStr = QKeySequence( defModi ).toString();
300 defaultStr = defaultStr.left(defaultStr.size()-1);
302 defaultStr = QKeySequence( defKey + defModi ).toString();
305 rows << description << keyString << defaultStr << QString::number(bindingID) << QString::number(key)
306 << QString::number(modifiers) << QString::number(multiUse) << keyString;
308 QTreeWidgetItem* keyItem =
new QTreeWidgetItem(parent, rows);
310 parent->addChild( keyItem );
314 keyTree->setColumnWidth(0,350);
315 keyTree->setColumnHidden(3,
true);
316 keyTree->setColumnHidden(4,
true);
317 keyTree->setColumnHidden(5,
true);
318 keyTree->setColumnHidden(6,
true);
319 keyTree->setColumnHidden(7,
true);
Interface class from which all plugins have to be created.
int getPluginInfo(QString pluginName)
get the pluginInfo object corresponding to the given pluginName
void keyTreeItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
keyBinding TreeWidget-Item changed
void restoreKeyPresets()
restore keyBinding Presets
virtual QString name()=0
Return a name for the plugin.
void updateShortcut()
check if the shortcut exists and add it if not
void initKeyTree()
init the TreeWidget containing the keyBindings
void keyTreeDoubleClicked(QTreeWidgetItem *_item, int col)
doubleclick in the keyTree
void applyShortcuts()
check which of the shortcuts changed and inform the core about the change