From 04a84b0eee359aafaafcbfe3e692c3be0b17d235 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Wed, 17 Feb 2016 13:23:20 +0100 Subject: Remove unneeded files from old highlight editor UI Test-Information: ./scons test=unit passed without errors on OS X 10.11.3. Change-Id: I9303fd2d5a08a17d1e8f2ca015bec7c883aeedad diff --git a/Swift/QtUI/QtHighlightEditorWidget.cpp b/Swift/QtUI/QtHighlightEditorWidget.cpp deleted file mode 100644 index 7ff094e..0000000 --- a/Swift/QtUI/QtHighlightEditorWidget.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2012 Maciej Niedzielski - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#include - -#include -#include - -namespace Swift { - -QtHighlightEditorWidget::QtHighlightEditorWidget(QWidget* parent) - : QWidget(parent) -{ - ui_.setupUi(this); - - itemModel_ = new QtHighlightRulesItemModel(this); - ui_.treeView->setModel(itemModel_); - ui_.ruleWidget->setModel(itemModel_); - - for (int i = 0; i < QtHighlightRulesItemModel::NumberOfColumns; ++i) { - switch (i) { - case QtHighlightRulesItemModel::ApplyTo: - case QtHighlightRulesItemModel::Sender: - case QtHighlightRulesItemModel::Keyword: - case QtHighlightRulesItemModel::Action: - ui_.treeView->showColumn(i); - break; - default: - ui_.treeView->hideColumn(i); - break; - } - } - - setHighlightManager(NULL); // setup buttons for empty rules list - - connect(ui_.treeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), SLOT(onCurrentRowChanged(QModelIndex))); - - connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked())); - connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked())); - - connect(ui_.moveUpButton, SIGNAL(clicked()), SLOT(onMoveUpButtonClicked())); - connect(ui_.moveDownButton, SIGNAL(clicked()), SLOT(onMoveDownButtonClicked())); - - connect(ui_.closeButton, SIGNAL(clicked()), SLOT(close())); - - setWindowTitle(tr("Highlight Rules")); -} - -QtHighlightEditorWidget::~QtHighlightEditorWidget() -{ -} - -void QtHighlightEditorWidget::show() -{ - if (itemModel_->rowCount(QModelIndex())) { - selectRow(0); - } - QWidget::show(); - QWidget::activateWindow(); -} - -void QtHighlightEditorWidget::setHighlightManager(HighlightManager* highlightManager) -{ - itemModel_->setHighlightManager(highlightManager); - ui_.newButton->setEnabled(highlightManager != NULL); - - ui_.ruleWidget->setEnabled(false); - ui_.deleteButton->setEnabled(false); - ui_.moveUpButton->setEnabled(false); - ui_.moveDownButton->setEnabled(false); -} - -void QtHighlightEditorWidget::closeEvent(QCloseEvent* event) { - ui_.ruleWidget->save(); - event->accept(); -} - -void QtHighlightEditorWidget::onNewButtonClicked() -{ - int row = getSelectedRow() + 1; - itemModel_->insertRow(row, QModelIndex()); - selectRow(row); -} - -void QtHighlightEditorWidget::onDeleteButtonClicked() -{ - int row = getSelectedRow(); - assert(row >= 0); - - itemModel_->removeRow(row, QModelIndex()); - if (row == itemModel_->rowCount(QModelIndex())) { - --row; - } - selectRow(row); -} - -void QtHighlightEditorWidget::onMoveUpButtonClicked() -{ - int row = getSelectedRow(); - assert(row > 0); - - ui_.ruleWidget->save(); - ui_.ruleWidget->setActiveIndex(QModelIndex()); - itemModel_->swapRows(row, row - 1); - selectRow(row - 1); -} - -void QtHighlightEditorWidget::onMoveDownButtonClicked() -{ - int row = getSelectedRow(); - assert(row < itemModel_->rowCount(QModelIndex()) - 1); - - ui_.ruleWidget->save(); - ui_.ruleWidget->setActiveIndex(QModelIndex()); - if (itemModel_->swapRows(row, row + 1)) { - selectRow(row + 1); - } -} - -void QtHighlightEditorWidget::onCurrentRowChanged(const QModelIndex& index) -{ - ui_.ruleWidget->save(); - ui_.ruleWidget->setActiveIndex(index); - - ui_.ruleWidget->setEnabled(index.isValid()); - - ui_.deleteButton->setEnabled(index.isValid()); - - ui_.moveUpButton->setEnabled(index.isValid() && index.row() != 0); - ui_.moveDownButton->setEnabled(index.isValid() && index.row() != itemModel_->rowCount(QModelIndex()) - 1); -} - -void QtHighlightEditorWidget::selectRow(int row) -{ - QModelIndex index = itemModel_->index(row, 0, QModelIndex()); - ui_.treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); -} - -/** Return index of selected row or -1 if none is selected */ -int QtHighlightEditorWidget::getSelectedRow() const -{ - QModelIndexList rows = ui_.treeView->selectionModel()->selectedRows(); - return rows.isEmpty() ? -1 : rows[0].row(); -} - -} diff --git a/Swift/QtUI/QtHighlightEditorWidget.h b/Swift/QtUI/QtHighlightEditorWidget.h deleted file mode 100644 index 1293c87..0000000 --- a/Swift/QtUI/QtHighlightEditorWidget.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2012 Maciej Niedzielski - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#pragma once - -#include -#include - -namespace Swift { - - class QtHighlightRulesItemModel; - - class QtHighlightEditorWidget : public QWidget, public HighlightEditorWidget { - Q_OBJECT - - public: - QtHighlightEditorWidget(QWidget* parent = NULL); - virtual ~QtHighlightEditorWidget(); - - void show(); - - void setHighlightManager(HighlightManager* highlightManager); - - private slots: - void onNewButtonClicked(); - void onDeleteButtonClicked(); - void onMoveUpButtonClicked(); - void onMoveDownButtonClicked(); - void onCurrentRowChanged(const QModelIndex&); - - private: - virtual void closeEvent(QCloseEvent* event); - - void selectRow(int row); - int getSelectedRow() const; - - Ui::QtHighlightEditorWidget ui_; - QtHighlightRulesItemModel* itemModel_; - }; - -} diff --git a/Swift/QtUI/QtHighlightEditorWidget.ui b/Swift/QtUI/QtHighlightEditorWidget.ui deleted file mode 100644 index 0f39168..0000000 --- a/Swift/QtUI/QtHighlightEditorWidget.ui +++ /dev/null @@ -1,124 +0,0 @@ - - - QtHighlightEditorWidget - - - - 0 - 0 - 419 - 373 - - - - Form - - - - - - - - Incoming messages are checked against the following rules. First rule that matches will be executed. - - - true - - - - - - - false - - - false - - - - - - - - - - - - - - New - - - - - - - Delete - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Move up - - - - - - - Move down - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Close - - - - - - - - - - Swift::QtHighlightRuleWidget - QWidget -
QtHighlightRuleWidget.h
- 1 -
-
- - -
diff --git a/Swift/QtUI/QtHighlightRulesItemModel.cpp b/Swift/QtUI/QtHighlightRulesItemModel.cpp deleted file mode 100644 index fcbaddc..0000000 --- a/Swift/QtUI/QtHighlightRulesItemModel.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (c) 2012 Maciej Niedzielski - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include - -namespace Swift { - -QtHighlightRulesItemModel::QtHighlightRulesItemModel(QObject* parent) : QAbstractItemModel(parent), highlightManager_(NULL) -{ -} - -void QtHighlightRulesItemModel::setHighlightManager(HighlightManager* highlightManager) -{ - emit layoutAboutToBeChanged(); - highlightManager_ = highlightManager; - emit layoutChanged(); -} - -QVariant QtHighlightRulesItemModel::headerData(int section, Qt::Orientation /* orientation */, int role) const -{ - if (role == Qt::DisplayRole) { - switch (section) { - case ApplyTo: return QVariant(tr("Apply to")); - case Sender: return QVariant(tr("Sender")); - case Keyword: return QVariant(tr("Keyword")); - case Action: return QVariant(tr("Action")); - case NickIsKeyword: return QVariant(tr("Nick Is Keyword")); - case MatchCase: return QVariant(tr("Match Case")); - case MatchWholeWords: return QVariant(tr("Match Whole Words")); - case HighlightText: return QVariant(tr("Highlight Text")); - case TextColor: return QVariant(tr("Text Color")); - case TextBackground: return QVariant(tr("Text Background")); - case PlaySound: return QVariant(tr("Play Sounds")); - case SoundFile: return QVariant(tr("Sound File")); - } - } - - return QVariant(); -} - -int QtHighlightRulesItemModel::columnCount(const QModelIndex& /* parent */) const -{ - return NumberOfColumns; -} - -QVariant QtHighlightRulesItemModel::data(const QModelIndex &index, int role) const -{ - if (index.isValid() && highlightManager_ && (role == Qt::DisplayRole || role == Qt::EditRole)) { - - const char* separator = (role == Qt::DisplayRole) ? " ; " : "\n"; - - if (boost::numeric_cast::size_type>(index.row()) < highlightManager_->getRules().size()) { - const HighlightRule& r = highlightManager_->getRules()[index.row()]; - switch (index.column()) { - case ApplyTo: { - int applyTo = 0; - if (r.getMatchChat() && r.getMatchMUC()) { - applyTo = 1; - } else if (r.getMatchChat()) { - applyTo = 2; - } else if (r.getMatchMUC()) { - applyTo = 3; - } - - if (role == Qt::DisplayRole) { - return QVariant(getApplyToString(applyTo)); - } else { - return QVariant(applyTo); - } - } - case Sender: { - std::string s = boost::join(r.getSenders(), separator); - return QVariant(P2QSTRING(s)); - } - case Keyword: { - std::string s = boost::join(r.getKeywords(), separator); - QString qs(P2QSTRING(s)); - if (role == Qt::DisplayRole && r.getNickIsKeyword()) { - qs = tr("") + (qs.isEmpty() ? "" : separator + qs); - } - return QVariant(qs); - } - case Action: { - std::vector v; - const HighlightAction & action = r.getAction(); - if (action.highlightText()) { - v.push_back(Q2PSTRING(tr("Highlight text"))); - } - if (action.playSound()) { - v.push_back(Q2PSTRING(tr("Play sound"))); - } - std::string s = boost::join(v, separator); - return QVariant(P2QSTRING(s)); - } - case NickIsKeyword: { - return QVariant(r.getNickIsKeyword()); - } - case MatchCase: { - return QVariant(r.getMatchCase()); - } - case MatchWholeWords: { - return QVariant(r.getMatchWholeWords()); - } - case HighlightText: { - return QVariant(r.getAction().highlightText()); - } - case TextColor: { - return QVariant(QColor(P2QSTRING(r.getAction().getTextColor()))); - } - case TextBackground: { - return QVariant(QColor(P2QSTRING(r.getAction().getTextBackground()))); - } - case PlaySound: { - return QVariant(r.getAction().playSound()); - } - case SoundFile: { - return QVariant(P2QSTRING(r.getAction().getSoundFile())); - } - } - } - } - return QVariant(); -} - -bool QtHighlightRulesItemModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (index.isValid() && highlightManager_ && role == Qt::EditRole) { - if (boost::numeric_cast::size_type>(index.row()) < highlightManager_->getRules().size()) { - HighlightRule r = highlightManager_->getRule(index.row()); - std::vector changedColumns; - switch (index.column()) { - case ApplyTo: { - bool ok = false; - int applyTo = value.toInt(&ok); - if (!ok) { - return false; - } - r.setMatchChat(applyTo == ApplyToAll || applyTo == ApplyToChat); - r.setMatchMUC(applyTo == ApplyToAll || applyTo == ApplyToMUC); - break; - } - case Sender: - case Keyword: { - std::string s = Q2PSTRING(value.toString()); - std::vector v; - boost::split(v, s, boost::is_any_of("\n")); - v.erase(std::remove_if(v.begin(), v.end(), boost::lambda::_1 == ""), v.end()); - if (index.column() == Sender) { - r.setSenders(v); - } else { - r.setKeywords(v); - } - break; - } - case NickIsKeyword: { - r.setNickIsKeyword(value.toBool()); - changedColumns.push_back(Keyword); // "" - break; - } - case MatchCase: { - r.setMatchCase(value.toBool()); - break; - } - case MatchWholeWords: { - r.setMatchWholeWords(value.toBool()); - break; - } - case HighlightText: { - r.getAction().setHighlightText(value.toBool()); - changedColumns.push_back(Action); - break; - } - case TextColor: { - QColor c = value.value(); - r.getAction().setTextColor(c.isValid() ? Q2PSTRING(c.name()) : ""); - break; - } - case TextBackground: { - QColor c = value.value(); - r.getAction().setTextBackground(c.isValid() ? Q2PSTRING(c.name()) : ""); - break; - } - case PlaySound: { - r.getAction().setPlaySound(value.toBool()); - changedColumns.push_back(Action); - break; - } - case SoundFile: { - r.getAction().setSoundFile(Q2PSTRING(value.toString())); - break; - } - } - - highlightManager_->setRule(index.row(), r); - emit dataChanged(index, index); - foreach (int column, changedColumns) { - QModelIndex i = createIndex(index.row(), column, static_cast(0)); - emit dataChanged(i, i); - } - } - } - - return false; -} - -QModelIndex QtHighlightRulesItemModel::parent(const QModelIndex& /* child */) const -{ - return QModelIndex(); -} - -int QtHighlightRulesItemModel::rowCount(const QModelIndex& /* parent */) const -{ - return highlightManager_ ? highlightManager_->getRules().size() : 0; -} - -QModelIndex QtHighlightRulesItemModel::index(int row, int column, const QModelIndex& /* parent */) const -{ - return createIndex(row, column, static_cast(0)); -} - -bool QtHighlightRulesItemModel::insertRows(int row, int count, const QModelIndex& /* parent */) -{ - if (highlightManager_) { - beginInsertRows(QModelIndex(), row, row + count); - while (count--) { - highlightManager_->insertRule(row, HighlightRule()); - } - endInsertRows(); - return true; - } - return false; -} - -bool QtHighlightRulesItemModel::removeRows(int row, int count, const QModelIndex& /* parent */) -{ - if (highlightManager_) { - beginRemoveRows(QModelIndex(), row, row + count); - while (count--) { - highlightManager_->removeRule(row); - } - endRemoveRows(); - return true; - } - return false; -} - -bool QtHighlightRulesItemModel::swapRows(int row1, int row2) -{ - if (highlightManager_) { - assert(row1 >= 0 && row2 >= 0 && boost::numeric_cast::size_type>(row1) < highlightManager_->getRules().size() && boost::numeric_cast::size_type>(row2) < highlightManager_->getRules().size()); - HighlightRule r = highlightManager_->getRule(row1); - highlightManager_->setRule(row1, highlightManager_->getRule(row2)); - highlightManager_->setRule(row2, r); - emit dataChanged(index(row1, 0, QModelIndex()), index(row1, 0, QModelIndex())); - emit dataChanged(index(row2, 0, QModelIndex()), index(row2, 0, QModelIndex())); - return true; - } - return false; -} - -QString QtHighlightRulesItemModel::getApplyToString(int applyTo) -{ - switch (applyTo) { - case ApplyToNone: return tr("None"); - case ApplyToAll: return tr("Chat or MUC"); - case ApplyToChat: return tr("Chat"); - case ApplyToMUC: return tr("MUC"); - default: return ""; - } -} - -} diff --git a/Swift/QtUI/QtHighlightRulesItemModel.h b/Swift/QtUI/QtHighlightRulesItemModel.h deleted file mode 100644 index ac85628..0000000 --- a/Swift/QtUI/QtHighlightRulesItemModel.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2012 Maciej Niedzielski - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#pragma once - -#include - -namespace Swift { - - class HighlightManager; - - class QtHighlightRulesItemModel : public QAbstractItemModel { - Q_OBJECT - - public: - QtHighlightRulesItemModel(QObject* parent = NULL); - - void setHighlightManager(HighlightManager* highlightManager); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int columnCount(const QModelIndex& parent) const; - QVariant data(const QModelIndex& index, int role) const; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - QModelIndex parent(const QModelIndex& child) const; - int rowCount(const QModelIndex& parent) const; - QModelIndex index(int row, int column, const QModelIndex& parent) const; - bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()); - bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()); - bool swapRows(int row1, int row2); - - static QString getApplyToString(int); - - enum Columns { - ApplyTo = 0, - Sender, - Keyword, - Action, - NickIsKeyword, - MatchCase, - MatchWholeWords, - HighlightText, - TextColor, - TextBackground, - PlaySound, - SoundFile, - NumberOfColumns // end of list marker - }; - - enum ApplyToValues { - ApplyToNone = 0, - ApplyToAll, - ApplyToChat, - ApplyToMUC, - ApplyToEOL // end of list marker - }; - - private: - HighlightManager* highlightManager_; - }; - -} -- cgit v0.10.2-6-g49f6