diff options
Diffstat (limited to 'Swift/QtUI/QtHighlightEditor.cpp')
| -rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 8488d7d..134155c 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -43,73 +43,73 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect())); connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect())); connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(soundCustomSelect())); /* replace the static line-edit control with the roster autocompleter */ ui_.dummySenderName->setVisible(false); jid_ = new QtSuggestingJIDInput(this, settings); ui_.senderName->addWidget(jid_); jid_->onUserSelected.connect(boost::bind(&QtHighlightEditor::handleOnUserSelected, this, _1)); /* handle autocomplete */ connect(jid_, SIGNAL(textEdited(QString)), SLOT(handleContactSuggestionRequested(QString))); /* we need to be notified if any of the state changes so that we can update our textual rule description */ connect(ui_.chatRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.roomRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.allMsgRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.senderRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(jid_, SIGNAL(textChanged(const QString&)), SLOT(widgetClick())); connect(ui_.keywordRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.keyword, SIGNAL(textChanged(const QString&)), SLOT(widgetClick())); connect(ui_.matchPartialWords, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.matchCase, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(widgetClick())); connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(widgetClick())); /* allow selection of a custom sound file */ connect(ui_.soundFileButton, SIGNAL(clicked()), SLOT(selectSoundFile())); - /* if these are not needed, then they should be removed */ - ui_.moveUpButton->setVisible(false); - ui_.moveDownButton->setVisible(false); + /* allowing reordering items */ + connect(ui_.moveUpButton, SIGNAL(clicked()), this, SLOT(onUpButtonClicked())); + connect(ui_.moveDownButton, SIGNAL(clicked()), this, SLOT(onDownButtonClicked())); setWindowTitle(tr("Highlight Rules")); } QtHighlightEditor::~QtHighlightEditor() { } std::string formatShortDescription(const HighlightRule &rule) { const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room"); std::vector<std::string> senders = rule.getSenders(); std::vector<std::string> keywords = rule.getKeywords(); if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) { return std::string("All ") + chatOrRoom + " messages."; } if (rule.getNickIsKeyword()) { return std::string("All ") + chatOrRoom + " messages that mention my name."; } if (!senders.empty()) { return std::string("All ") + chatOrRoom + " messages from " + senders[0] + "."; } if (!keywords.empty()) { return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'."; } return "Unknown Rule"; } void QtHighlightEditor::show() @@ -163,70 +163,86 @@ void QtHighlightEditor::soundCustomSelect() ui_.soundFileButton->setEnabled(true); } void QtHighlightEditor::onNewButtonClicked() { int row = getSelectedRow() + 1; populateList(); HighlightRule newRule; newRule.setMatchMUC(true); highlightManager_->insertRule(row, newRule); QListWidgetItem *item = new QListWidgetItem(); item->setText(P2QSTRING(formatShortDescription(newRule))); ui_.listWidget->insertItem(row, item); selectRow(row); } void QtHighlightEditor::onDeleteButtonClicked() { int selectedRow = getSelectedRow(); assert(selectedRow>=0 && selectedRow<ui_.listWidget->count()); delete ui_.listWidget->takeItem(selectedRow); highlightManager_->removeRule(selectedRow); if (!ui_.listWidget->count()) { disableDialog(); ui_.deleteButton->setEnabled(false); } else { if (selectedRow == ui_.listWidget->count()) { selectRow(ui_.listWidget->count() - 1); } else { selectRow(selectedRow); } } } +void QtHighlightEditor::onUpButtonClicked() { + const size_t moveFrom = ui_.listWidget->currentRow(); + const size_t moveTo = moveFrom - 1; + highlightManager_->swapRules(moveFrom, moveTo); + populateList(); + selectRow(moveTo); +} + +void QtHighlightEditor::onDownButtonClicked() { + const size_t moveFrom = ui_.listWidget->currentRow(); + const size_t moveTo = moveFrom + 1; + highlightManager_->swapRules(moveFrom, moveTo); + populateList(); + selectRow(moveTo); +} + void QtHighlightEditor::onCurrentRowChanged(int currentRow) { ui_.deleteButton->setEnabled(currentRow != -1); ui_.moveUpButton->setEnabled(currentRow != -1 && currentRow != 0); ui_.moveDownButton->setEnabled(currentRow != -1 && currentRow != (ui_.listWidget->count()-1)); if (previousRow_ != -1) { if (ui_.listWidget->count() > previousRow_) { highlightManager_->setRule(previousRow_, ruleFromDialog()); } } if (currentRow != -1) { HighlightRule rule = highlightManager_->getRule(currentRow); ruleToDialog(rule); if (ui_.listWidget->currentItem()) { ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule))); } } /* grey the dialog if we have nothing selected */ if (currentRow == -1) { disableDialog(); } previousRow_ = currentRow; } void QtHighlightEditor::onApplyButtonClick() { selectRow(getSelectedRow()); /* force save */ highlightManager_->storeSettings(); } void QtHighlightEditor::onCancelButtonClick() |
Swift