summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.cpp149
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.h44
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.ui124
-rw-r--r--Swift/QtUI/QtHighlightRulesItemModel.cpp284
-rw-r--r--Swift/QtUI/QtHighlightRulesItemModel.h64
5 files changed, 0 insertions, 665 deletions
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 <cassert>
-
-#include <Swift/QtUI/QtHighlightEditorWidget.h>
-#include <Swift/QtUI/QtHighlightRulesItemModel.h>
-
-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 <Swift/Controllers/UIInterfaces/HighlightEditorWidget.h>
-#include <Swift/QtUI/ui_QtHighlightEditorWidget.h>
-
-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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>QtHighlightEditorWidget</class>
- <widget class="QWidget" name="QtHighlightEditorWidget">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>419</width>
- <height>373</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Incoming messages are checked against the following rules. First rule that matches will be executed.</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QTreeView" name="treeView">
- <property name="rootIsDecorated">
- <bool>false</bool>
- </property>
- <property name="itemsExpandable">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="Swift::QtHighlightRuleWidget" name="ruleWidget" native="true"/>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QPushButton" name="newButton">
- <property name="text">
- <string>New</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteButton">
- <property name="text">
- <string>Delete</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Fixed</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="moveUpButton">
- <property name="text">
- <string>Move up</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="moveDownButton">
- <property name="text">
- <string>Move down</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer_3">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="closeButton">
- <property name="text">
- <string>Close</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <customwidgets>
- <customwidget>
- <class>Swift::QtHighlightRuleWidget</class>
- <extends>QWidget</extends>
- <header>QtHighlightRuleWidget.h</header>
- <container>1</container>
- </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>
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 <boost/algorithm/string.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/numeric/conversion/cast.hpp>
-
-#include <QStringList>
-#include <QColor>
-
-#include <Swift/Controllers/HighlightManager.h>
-#include <Swift/QtUI/QtHighlightRulesItemModel.h>
-#include <Swift/QtUI/QtSwiftUtil.h>
-
-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<std::vector<std::string>::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("<nick>") + (qs.isEmpty() ? "" : separator + qs);
- }
- return QVariant(qs);
- }
- case Action: {
- std::vector<std::string> 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<std::vector<std::string>::size_type>(index.row()) < highlightManager_->getRules().size()) {
- HighlightRule r = highlightManager_->getRule(index.row());
- std::vector<int> 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<std::string> 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); // "<nick>"
- 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<QColor>();
- r.getAction().setTextColor(c.isValid() ? Q2PSTRING(c.name()) : "");
- break;
- }
- case TextBackground: {
- QColor c = value.value<QColor>();
- 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<void*>(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<void*>(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<std::vector<std::string>::size_type>(row1) < highlightManager_->getRules().size() && boost::numeric_cast<std::vector<std::string>::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 <QAbstractItemModel>
-
-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_;
- };
-
-}