diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 57 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 1 |
2 files changed, 40 insertions, 18 deletions
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 457d397..87e16d3 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -25,7 +25,7 @@ namespace Swift { QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent) - : QWidget(parent), settings_(settings) + : QWidget(parent), settings_(settings), previousRow_(-1) { ui_.setupUi(this); @@ -79,15 +79,6 @@ QtHighlightEditor::~QtHighlightEditor() { } -void QtHighlightEditor::show() -{ - //if (itemModel_->rowCount(QModelIndex())) { - //selectRow(0); - //} - QWidget::show(); - QWidget::activateWindow(); -} - std::string formatNaturalDescription(const HighlightRule& rule) { //This rule will match messages either in chats or in rooms if the sender @@ -137,18 +128,29 @@ std::string formatNaturalDescription(const HighlightRule& rule) return text; } -void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager) +void QtHighlightEditor::show() { - highlightManager_ = highlightManager; - ui_.listWidget->clear(); + highlightManager_->loadSettings(); foreach(const HighlightRule &rule, highlightManager_->getRules()) { QListWidgetItem *item = new QListWidgetItem(); item->setText(P2QSTRING(formatNaturalDescription(rule))); ui_.listWidget->addItem(item); } + if (ui_.listWidget->count()) { + selectRow(0); + } + + QWidget::show(); + QWidget::activateWindow(); +} + +void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager) +{ + highlightManager_ = highlightManager; + //itemModel_->setHighlightManager(highlightManager); //ui_.newButton->setEnabled(highlightManager != NULL); // @@ -185,6 +187,7 @@ void QtHighlightEditor::soundCustomSelect() void QtHighlightEditor::onNewButtonClicked() { int row = getSelectedRow() + 1; + highlightManager_->insertRule(row, HighlightRule()); QListWidgetItem *item = new QListWidgetItem(); item->setText("New rule"); ui_.listWidget->insertItem(row, item); @@ -193,7 +196,9 @@ void QtHighlightEditor::onNewButtonClicked() void QtHighlightEditor::onDeleteButtonClicked() { - delete ui_.listWidget->takeItem(getSelectedRow()); + int selectedRow = getSelectedRow(); + delete ui_.listWidget->takeItem(selectedRow); + highlightManager_->removeRule(selectedRow); } void QtHighlightEditor::onMoveUpButtonClicked() @@ -229,12 +234,25 @@ 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) { + ruleToDialog(highlightManager_->getRule(currentRow)); + } else { + /* grey/disable entire dialog */ + } + + previousRow_ = currentRow; } void QtHighlightEditor::onApplyButtonClick() { - ui_.textEdit_2->setText(P2QSTRING(formatNaturalDescription(ruleFromDialog()))); -// close(); + highlightManager_->storeSettings(); } void QtHighlightEditor::onCancelButtonClick() @@ -244,15 +262,18 @@ void QtHighlightEditor::onCancelButtonClick() void QtHighlightEditor::onOkButtonClick() { + highlightManager_->storeSettings(); close(); } void QtHighlightEditor::selectRow(int row) { for (int i = 0; i < ui_.listWidget->count(); ++i) { - ui_.listWidget->item(i)->setSelected(i == row); + if (i == row) { + ui_.listWidget->item(i)->setSelected(true); + onCurrentRowChanged(i); + } } - onCurrentRowChanged(row); } /** Return index of selected row or -1 if none is selected */ diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index ebae432..b195c13 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -56,6 +56,7 @@ namespace Swift { QtSettingsProvider* settings_; HighlightManager* highlightManager_; QtSuggestingJIDInput* jid_; + int previousRow_; }; } |