void EditToolBar::addAction() { //get the id from the action selected in the available actions list QString availableActionSelectedId = ui.availableActions->currentItem()->data(32).toString(); //check that the action we want to add isn't already in the list, exept if its a separator for(int i=0; i<ui.currentActions->count(); i++){ if((ui.currentActions->item(i)->data(32).toString() == availableActionSelectedId) && (ui.currentActions->item(i)->data(32).toString() != "_separator")){ return; } } //add the action to the widget this->addItem(availableActionSelectedId, ui.currentActions, getPositionToUse()); //add the action to the list if(searchMade){ actionsUsed.append(availableActionSelectedId); } else{ actionsUsed = this->getActionsList(); } //select the added action in the list ui.currentActions->setCurrentRow(-1); //emit the signal the actions list has changed emit actionsListChanged(); }
EditToolBar::EditToolBar(QWidget *parent) : QDialog(parent) { //configure u ui.setupUi(this); //no search made yet searchMade = false; //icons size - copied from kedittoolbar class, in kdelibs iconSize = this->style()->pixelMetric(QStyle::PM_SmallIconSize); //separator item separatorItem = new QListWidgetItem(QString("--- %1 ---").arg(tr("Separator"))); separatorItem->setData(32, "_separator"); //setup icons ui.okButton->setIcon(QIcon::fromTheme("dialog-ok")); ui.applyButton->setIcon(QIcon::fromTheme("dialog-ok-apply")); ui.cancelButton->setIcon(QIcon::fromTheme("dialog-cancel")); ui.clearButton1->setIcon(QIcon::fromTheme("edit-clear-locationbar-rtl")); ui.clearButton2->setIcon(QIcon::fromTheme("edit-clear-locationbar-rtl")); ui.addButton->setIcon(QIcon::fromTheme("go-next")); ui.removeButton->setIcon(QIcon::fromTheme("go-previous")); ui.moveDownButton->setIcon(QIcon::fromTheme("go-down")); ui.moveUpButton->setIcon(QIcon::fromTheme("go-up")); ui.setDefaultsButton->setIcon(QIcon::fromTheme("document-revert")); //connections connect(this, SIGNAL(actionsListChanged()), this, SLOT(updateButtons())); connect(ui.currentActions, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons())); connect(ui.availableActions, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons())); connect(this, SIGNAL(actionsListChanged()), this, SLOT(actionsChangedSlot())); connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okSlot())); connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applySlot())); connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addAction())); connect(ui.removeButton, SIGNAL(clicked()), this, SLOT(removeAction())); connect(ui.moveDownButton, SIGNAL(clicked()), this, SLOT(moveDownAction())); connect(ui.moveUpButton, SIGNAL(clicked()), this, SLOT(moveUpAction())); connect(ui.currentFilter, SIGNAL(textChanged(QString)), this, SLOT(searchInCurrentActionsSlot(QString))); connect(ui.availableFilter, SIGNAL(textChanged(QString)), this, SLOT(searchInAvailableActionsSlot(QString))); connect(ui.setDefaultsButton, SIGNAL(clicked()), this, SLOT(setDefaults())); this->setWindowTitle(tr("Configure toolbar")); }
void EditToolBar::moveAction(int d) { /* if d > 0, that means i have to move up the action, so i need to insert in the previous position. By the other way, if d < 0, i have to move down the action, so i need to insert it in the next position. So the new action position will be actualPosition - d */ //get current position int g = ui.currentActions->currentRow() - d; //move the action ui.currentActions->insertItem(g, ui.currentActions->takeItem(g + d)); //set the action moved as the selected ui.currentActions->setCurrentRow(g); emit actionsListChanged(); }
void EditToolBar::removeAction() { //if i did a search, then remove the item fomr the list, so, when it clears the search field //the current list widget will filled with the actions according to the list, and the one removed //won't be there if(searchMade){ actionsUsed.removeAll(ui.currentActions->currentItem()->data(32).toString()); // remove the item ui.currentActions->currentItem()->~QListWidgetItem(); } else{ // remove the item ui.currentActions->currentItem()->~QListWidgetItem(); actionsUsed = this->getActionsList(); } //emit the signal emit actionsListChanged(); }
EditToolBar::EditToolBar(QWidget *parent) : QDialog(parent) { ui.setupUi(this); ui.okButton->setIcon(QIcon::fromTheme("dialog-ok")); ui.applyButton->setIcon(QIcon::fromTheme("dialog-ok-apply")); ui.cancelButton->setIcon(QIcon::fromTheme("dialog-cancel")); tbe = new ToolBarEdit(this); tbe->setMaximumWidth(ui.widget->maximumWidth()); tbe->setMaximumHeight(ui.widget->maximumHeight()); connect(tbe, SIGNAL(actionsListChanged()), this, SLOT(actionsChangedSlot())); connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okSlot())); connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applySlot())); ui.widget = tbe; this->setWindowTitle(tr("Configure toolbar")); }