diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
commit | cfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch) | |
tree | 18d94153a302445196fc0c18586abf44a1ce4a38 /Swift/QtUI/MUCSearch | |
parent | 1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff) | |
download | swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2 |
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines
in the process.
Changed CheckTabs.py tool to disallow hard tabs in source
files.
Test-Information:
Manually checked 30 random files that the conversion worked
as expected.
Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swift/QtUI/MUCSearch')
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp | 96 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchDelegate.h | 22 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp | 30 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h | 18 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchItem.h | 10 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchModel.cpp | 104 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchModel.h | 34 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp | 12 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchRoomItem.h | 22 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/MUCSearchServiceItem.h | 34 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp | 238 | ||||
-rw-r--r-- | Swift/QtUI/MUCSearch/QtMUCSearchWindow.h | 74 |
12 files changed, 347 insertions, 347 deletions
diff --git a/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp b/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp index c5f4685..0163e03 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp +++ b/Swift/QtUI/MUCSearch/MUCSearchDelegate.cpp @@ -25,63 +25,63 @@ MUCSearchDelegate::~MUCSearchDelegate() { } // QSize MUCSearchDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { -// // MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); -// // if (item && dynamic_cast<MUCSearchMUCItem*>(item)) { -// // return mucSizeHint(option, index); -// // } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) { -// // return groupDelegate_->sizeHint(option, index); -// // } -// return QStyledItemDelegate::sizeHint(option, index); +// // MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); +// // if (item && dynamic_cast<MUCSearchMUCItem*>(item)) { +// // return mucSizeHint(option, index); +// // } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) { +// // return groupDelegate_->sizeHint(option, index); +// // } +// return QStyledItemDelegate::sizeHint(option, index); // } // QSize MUCSearchDelegate::mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const { -// QFontMetrics nameMetrics(common_.nameFont); -// QFontMetrics statusMetrics(common_.detailFont); -// int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); -// return QSize(150, sizeByText); +// QFontMetrics nameMetrics(common_.nameFont); +// QFontMetrics statusMetrics(common_.detailFont); +// int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); +// return QSize(150, sizeByText); // } // void MUCSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { -// MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); -// if (item && dynamic_cast<MUCSearchMUCItem*>(item)) { -// paintMUC(painter, option, dynamic_cast<MUCSearchMUCItem*>(item)); -// } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) { -// MUCSearchGroupItem* group = dynamic_cast<MUCSearchGroupItem*>(item); -// groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open); -// } else { -// QStyledItemDelegate::paint(painter, option, index); -// } +// MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); +// if (item && dynamic_cast<MUCSearchMUCItem*>(item)) { +// paintMUC(painter, option, dynamic_cast<MUCSearchMUCItem*>(item)); +// } else if (item && dynamic_cast<MUCSearchGroupItem*>(item)) { +// MUCSearchGroupItem* group = dynamic_cast<MUCSearchGroupItem*>(item); +// groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open); +// } else { +// QStyledItemDelegate::paint(painter, option, index); +// } // } // void MUCSearchDelegate::paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const { -// painter->save(); -// QRect fullRegion(option.rect); -// if ( option.state & QStyle::State_Selected ) { -// painter->fillRect(fullRegion, option.palette.highlight()); -// painter->setPen(option.palette.highlightedText().color()); -// } else { -// QColor nameColor = item->data(Qt::TextColorRole).value<QColor>(); -// painter->setPen(QPen(nameColor)); -// } - -// QFontMetrics nameMetrics(common_.nameFont); -// painter->setFont(common_.nameFont); -// int extraFontWidth = nameMetrics.width("H"); -// int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; -// QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); - -// int nameHeight = nameMetrics.height() + common_.verticalMargin; -// QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - -// painter->drawText(nameRegion, Qt::AlignTop, item->data(Qt::DisplayRole).toString()); - -// painter->setFont(common_.detailFont); -// painter->setPen(QPen(QColor(160,160,160))); - -// QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); -// painter->drawText(detailRegion, Qt::AlignTop, item->data(DetailTextRole).toString()); - -// painter->restore(); +// painter->save(); +// QRect fullRegion(option.rect); +// if ( option.state & QStyle::State_Selected ) { +// painter->fillRect(fullRegion, option.palette.highlight()); +// painter->setPen(option.palette.highlightedText().color()); +// } else { +// QColor nameColor = item->data(Qt::TextColorRole).value<QColor>(); +// painter->setPen(QPen(nameColor)); +// } + +// QFontMetrics nameMetrics(common_.nameFont); +// painter->setFont(common_.nameFont); +// int extraFontWidth = nameMetrics.width("H"); +// int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; +// QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); + +// int nameHeight = nameMetrics.height() + common_.verticalMargin; +// QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); + +// painter->drawText(nameRegion, Qt::AlignTop, item->data(Qt::DisplayRole).toString()); + +// painter->setFont(common_.detailFont); +// painter->setPen(QPen(QColor(160,160,160))); + +// QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); +// painter->drawText(detailRegion, Qt::AlignTop, item->data(DetailTextRole).toString()); + +// painter->restore(); // } } diff --git a/Swift/QtUI/MUCSearch/MUCSearchDelegate.h b/Swift/QtUI/MUCSearch/MUCSearchDelegate.h index d521d7b..5bf9646 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchDelegate.h +++ b/Swift/QtUI/MUCSearch/MUCSearchDelegate.h @@ -11,18 +11,18 @@ #include <Swift/QtUI/Roster/DelegateCommons.h> namespace Swift { - class MUCSearchDelegate : public QStyledItemDelegate { - public: - MUCSearchDelegate(); - ~MUCSearchDelegate(); - /* QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; */ - /* void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; */ - private: -// void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const; -// QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; + class MUCSearchDelegate : public QStyledItemDelegate { + public: + MUCSearchDelegate(); + ~MUCSearchDelegate(); + /* QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; */ + /* void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; */ + private: +// void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, MUCSearchMUCItem* item) const; +// QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const; - DelegateCommons common_; - }; + DelegateCommons common_; + }; } diff --git a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp index 5ab6391..d95682c 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp +++ b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.cpp @@ -13,27 +13,27 @@ namespace Swift { MUCSearchEmptyItem::MUCSearchEmptyItem(MUCSearchServiceItem* parent) : parent(parent) { - parent->addRoom(this); + parent->addRoom(this); } MUCSearchServiceItem* MUCSearchEmptyItem::getParent() { - return parent; + return parent; } QVariant MUCSearchEmptyItem::data(int role) { - switch (role) { - case Qt::DisplayRole: - return QVariant(QObject::tr("No rooms found")); - case Qt::FontRole: { - QFont font; - font.setItalic(true); - return font; - } - case Qt::ForegroundRole: - return QColor(Qt::gray); - default: - return QVariant(); - } + switch (role) { + case Qt::DisplayRole: + return QVariant(QObject::tr("No rooms found")); + case Qt::FontRole: { + QFont font; + font.setItalic(true); + return font; + } + case Qt::ForegroundRole: + return QColor(Qt::gray); + default: + return QVariant(); + } } } diff --git a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h index 74e0154..ca4b2b2 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h +++ b/Swift/QtUI/MUCSearch/MUCSearchEmptyItem.h @@ -9,17 +9,17 @@ #include <Swift/QtUI/MUCSearch/MUCSearchItem.h> namespace Swift { - class MUCSearchServiceItem; + class MUCSearchServiceItem; - class MUCSearchEmptyItem : public MUCSearchItem { - public: - MUCSearchEmptyItem(MUCSearchServiceItem* parent); + class MUCSearchEmptyItem : public MUCSearchItem { + public: + MUCSearchEmptyItem(MUCSearchServiceItem* parent); - MUCSearchServiceItem* getParent(); + MUCSearchServiceItem* getParent(); - QVariant data(int role); + QVariant data(int role); - private: - MUCSearchServiceItem* parent; - }; + private: + MUCSearchServiceItem* parent; + }; } diff --git a/Swift/QtUI/MUCSearch/MUCSearchItem.h b/Swift/QtUI/MUCSearch/MUCSearchItem.h index d2a2c2d..c378247 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchItem.h +++ b/Swift/QtUI/MUCSearch/MUCSearchItem.h @@ -9,9 +9,9 @@ #include <QVariant> namespace Swift { - class MUCSearchItem { - public: - virtual ~MUCSearchItem() {} - virtual QVariant data(int role) = 0; - }; + class MUCSearchItem { + public: + virtual ~MUCSearchItem() {} + virtual QVariant data(int role) = 0; + }; } diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp index 1a3ccc4..af6f17f 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchModel.cpp +++ b/Swift/QtUI/MUCSearch/MUCSearchModel.cpp @@ -14,78 +14,78 @@ MUCSearchModel::MUCSearchModel() { } void MUCSearchModel::clear() { - emit layoutAboutToBeChanged(); - services_.clear(); - emit layoutChanged(); + emit layoutAboutToBeChanged(); + services_.clear(); + emit layoutChanged(); } void MUCSearchModel::addService(MUCSearchServiceItem* service) { - emit layoutAboutToBeChanged(); - services_.push_back(service); - emit layoutChanged(); + emit layoutAboutToBeChanged(); + services_.push_back(service); + emit layoutChanged(); } int MUCSearchModel::columnCount(const QModelIndex& /*parent*/) const { - return 1; + return 1; } QVariant MUCSearchModel::data(const QModelIndex& index, int role) const { - return index.isValid() ? static_cast<MUCSearchItem*>(index.internalPointer())->data(role) : QVariant(); + return index.isValid() ? static_cast<MUCSearchItem*>(index.internalPointer())->data(role) : QVariant(); } QModelIndex MUCSearchModel::index(int row, int column, const QModelIndex & parent) const { - if (!hasIndex(row, column, parent)) { - return QModelIndex(); - } - - if (parent.isValid()) { - MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer()); - return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); - } else { - return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex(); - } + if (!hasIndex(row, column, parent)) { + return QModelIndex(); + } + + if (parent.isValid()) { + MUCSearchServiceItem* parentItem = static_cast<MUCSearchServiceItem*>(parent.internalPointer()); + return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); + } else { + return row < services_.size() ? createIndex(row, column, services_[row]) : QModelIndex(); + } } QModelIndex MUCSearchModel::parent(const QModelIndex& index) const { - if (!index.isValid()) { - return QModelIndex(); - } - MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); - if (!item) { - return QModelIndex(); - } - else if (dynamic_cast<MUCSearchServiceItem*>(item)) { - return QModelIndex(); - } - - MUCSearchServiceItem* parent = NULL; - if (MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(item)) { - parent = roomItem->getParent(); - } - else if (MUCSearchEmptyItem* emptyItem = dynamic_cast<MUCSearchEmptyItem*>(item)) { - parent = emptyItem->getParent(); - } - if (parent) { - int row = services_.indexOf(parent); - return createIndex(row, 1, parent); - } - else { - return QModelIndex(); - } + if (!index.isValid()) { + return QModelIndex(); + } + MUCSearchItem* item = static_cast<MUCSearchItem*>(index.internalPointer()); + if (!item) { + return QModelIndex(); + } + else if (dynamic_cast<MUCSearchServiceItem*>(item)) { + return QModelIndex(); + } + + MUCSearchServiceItem* parent = NULL; + if (MUCSearchRoomItem* roomItem = dynamic_cast<MUCSearchRoomItem*>(item)) { + parent = roomItem->getParent(); + } + else if (MUCSearchEmptyItem* emptyItem = dynamic_cast<MUCSearchEmptyItem*>(item)) { + parent = emptyItem->getParent(); + } + if (parent) { + int row = services_.indexOf(parent); + return createIndex(row, 1, parent); + } + else { + return QModelIndex(); + } } int MUCSearchModel::rowCount(const QModelIndex& parentIndex) const { - if (!parentIndex.isValid()) { - return services_.size(); - } - if (dynamic_cast<MUCSearchServiceItem*>(static_cast<MUCSearchItem*>(parentIndex.internalPointer()))) { - return services_[parentIndex.row()]->rowCount(); - } - else { - return 0; - } + if (!parentIndex.isValid()) { + return services_.size(); + } + if (dynamic_cast<MUCSearchServiceItem*>(static_cast<MUCSearchItem*>(parentIndex.internalPointer()))) { + return services_[parentIndex.row()]->rowCount(); + } + else { + return 0; + } } } diff --git a/Swift/QtUI/MUCSearch/MUCSearchModel.h b/Swift/QtUI/MUCSearch/MUCSearchModel.h index 4ea811f..d6a24f3 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchModel.h +++ b/Swift/QtUI/MUCSearch/MUCSearchModel.h @@ -14,22 +14,22 @@ #include <Swift/QtUI/MUCSearch/MUCSearchServiceItem.h> namespace Swift { - class MUCSearchModel : public QAbstractItemModel { - Q_OBJECT - public: - MUCSearchModel(); - void clear(); - void addService(MUCSearchServiceItem* service); - int columnCount(const QModelIndex& parent = QModelIndex()) const; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex& index) const; - int rowCount(const QModelIndex& parent = QModelIndex()) const; -// ChatListItem* getItemForIndex(const QModelIndex& index) const; - private: -// ChatListGroupItem* mucBookmarks_; -// ChatListGroupItem* root_; - QList<MUCSearchServiceItem*> services_; - }; + class MUCSearchModel : public QAbstractItemModel { + Q_OBJECT + public: + MUCSearchModel(); + void clear(); + void addService(MUCSearchServiceItem* service); + int columnCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex& index) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; +// ChatListItem* getItemForIndex(const QModelIndex& index) const; + private: +// ChatListGroupItem* mucBookmarks_; +// ChatListGroupItem* root_; + QList<MUCSearchServiceItem*> services_; + }; } diff --git a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp index 169ab49..cb7ee2d 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp +++ b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.cpp @@ -10,17 +10,17 @@ namespace Swift { MUCSearchRoomItem::MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent) : parent_(parent), node_(node) { - parent_->addRoom(this); + parent_->addRoom(this); } MUCSearchServiceItem* MUCSearchRoomItem::getParent() { - return parent_; + return parent_; } QVariant MUCSearchRoomItem::data(int role) { - switch (role) { - case Qt::DisplayRole: return QVariant(node_); - default: return QVariant(); - } + switch (role) { + case Qt::DisplayRole: return QVariant(node_); + default: return QVariant(); + } } } diff --git a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h index c853221..d2b88bc 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h +++ b/Swift/QtUI/MUCSearch/MUCSearchRoomItem.h @@ -9,15 +9,15 @@ #include <Swift/QtUI/MUCSearch/MUCSearchItem.h> namespace Swift { - class MUCSearchServiceItem; - class MUCSearchRoomItem : public MUCSearchItem { - public: - MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent); - MUCSearchServiceItem* getParent(); - QVariant data(int role); - QString getNode() const {return node_;} - private: - MUCSearchServiceItem* parent_; - QString node_; - }; + class MUCSearchServiceItem; + class MUCSearchRoomItem : public MUCSearchItem { + public: + MUCSearchRoomItem(const QString& node, MUCSearchServiceItem* parent); + MUCSearchServiceItem* getParent(); + QVariant data(int role); + QString getNode() const {return node_;} + private: + MUCSearchServiceItem* parent_; + QString node_; + }; } diff --git a/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h b/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h index 421ac25..cfde071 100644 --- a/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h +++ b/Swift/QtUI/MUCSearch/MUCSearchServiceItem.h @@ -12,21 +12,21 @@ #include <Swift/QtUI/MUCSearch/MUCSearchRoomItem.h> namespace Swift { - class MUCSearchServiceItem : public MUCSearchItem { - public: - MUCSearchServiceItem(const QString& jidString) : jidString_(jidString) {} - void addRoom(MUCSearchItem* room) {rooms_.push_back(room);} - int rowCount() {return rooms_.count();} - MUCSearchItem* getItem(int i) {return rooms_[i];} - QVariant data(int role) { - switch (role) { - case Qt::DisplayRole: return QVariant(jidString_); - default: return QVariant(); - } - } - QString getHost() const {return jidString_;} - private: - QList<MUCSearchItem*> rooms_; - QString jidString_; - }; + class MUCSearchServiceItem : public MUCSearchItem { + public: + MUCSearchServiceItem(const QString& jidString) : jidString_(jidString) {} + void addRoom(MUCSearchItem* room) {rooms_.push_back(room);} + int rowCount() {return rooms_.count();} + MUCSearchItem* getItem(int i) {return rooms_[i];} + QVariant data(int role) { + switch (role) { + case Qt::DisplayRole: return QVariant(jidString_); + default: return QVariant(); + } + } + QString getHost() const {return jidString_;} + private: + QList<MUCSearchItem*> rooms_; + QString jidString_; + }; } diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp index e3bd7f3..03fa582 100644 --- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp +++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp @@ -24,37 +24,37 @@ namespace Swift { QtMUCSearchWindow::QtMUCSearchWindow() { - ui_.setupUi(this); + ui_.setupUi(this); #ifndef Q_OS_MAC - setWindowIcon(QIcon(":/logo-icon-16.png")); + setWindowIcon(QIcon(":/logo-icon-16.png")); #endif - setModal(true); - ui_.filter_->hide(); - model_ = new MUCSearchModel(); - delegate_ = new MUCSearchDelegate(); - ui_.results_->setModel(model_); - ui_.results_->setItemDelegate(delegate_); - ui_.results_->setHeaderHidden(true); - ui_.results_->setRootIsDecorated(true); - ui_.results_->setAnimated(true); - ui_.results_->setAlternatingRowColors(true); - connect(ui_.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch())); - connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&))); - connect(ui_.results_->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(handleSelectionChanged (const QItemSelection&, const QItemSelection&))); - connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&))); - connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&))); - // Not using a button box, because i can't seem to be able to make the ok button non-default (on mac) - connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept())); - ui_.okButton->setEnabled(false); - connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); - - throbber_ = new QLabel(tr("Searching"), ui_.results_); - throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_)); - throbber_->setToolTip(tr("Searching")); - - hasHadScrollBars_ = false; - updateThrobberPosition(); - setSearchInProgress(false); + setModal(true); + ui_.filter_->hide(); + model_ = new MUCSearchModel(); + delegate_ = new MUCSearchDelegate(); + ui_.results_->setModel(model_); + ui_.results_->setItemDelegate(delegate_); + ui_.results_->setHeaderHidden(true); + ui_.results_->setRootIsDecorated(true); + ui_.results_->setAnimated(true); + ui_.results_->setAlternatingRowColors(true); + connect(ui_.searchButton, SIGNAL(clicked()), this, SLOT(handleSearch())); + connect(ui_.service_, SIGNAL(activated(const QString&)), this, SLOT(handleSearch(const QString&))); + connect(ui_.results_->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)), this, SLOT(handleSelectionChanged (const QItemSelection&, const QItemSelection&))); + connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&))); + connect(ui_.results_, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleActivated(const QModelIndex&))); + // Not using a button box, because i can't seem to be able to make the ok button non-default (on mac) + connect(ui_.okButton, SIGNAL(clicked()), this, SLOT(accept())); + ui_.okButton->setEnabled(false); + connect(ui_.cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + + throbber_ = new QLabel(tr("Searching"), ui_.results_); + throbber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), throbber_)); + throbber_->setToolTip(tr("Searching")); + + hasHadScrollBars_ = false; + updateThrobberPosition(); + setSearchInProgress(false); } QtMUCSearchWindow::~QtMUCSearchWindow() { @@ -62,136 +62,136 @@ QtMUCSearchWindow::~QtMUCSearchWindow() { } void QtMUCSearchWindow::resizeEvent(QResizeEvent* /*event*/) { - updateThrobberPosition(); + updateThrobberPosition(); } void QtMUCSearchWindow::updateThrobberPosition() { - bool isShown = throbber_->isVisible(); - int resultWidth = ui_.results_->width(); - int resultHeight = ui_.results_->height(); - //throbberWidth = throbber_->movie()->scaledSize().width(); - //throbberHeight = throbber_->movie()->scaledSize().height(); - int throbberWidth = 16; /* This is nasty, but the above doesn't work! */ - int throbberHeight = 16; - /* It's difficult (or I spent a while trying) to work out whether the scrollbars are currently shown and their appropriate size, - * because if you listen for the expanded/collapsed signals, you seem to get them before the scrollbars are updated. - * This seems an acceptable workaround. - */ - hasHadScrollBars_ |= ui_.results_->verticalScrollBar()->isVisible(); - int hMargin = hasHadScrollBars_ ? ui_.results_->verticalScrollBar()->width() + 2 : 2; - int vMargin = 2; /* We don't get horizontal scrollbars */ - throbber_->setGeometry(QRect(resultWidth - throbberWidth - hMargin, resultHeight - throbberHeight - vMargin, throbberWidth, throbberHeight)); /* include margins */ - throbber_->setVisible(isShown); + bool isShown = throbber_->isVisible(); + int resultWidth = ui_.results_->width(); + int resultHeight = ui_.results_->height(); + //throbberWidth = throbber_->movie()->scaledSize().width(); + //throbberHeight = throbber_->movie()->scaledSize().height(); + int throbberWidth = 16; /* This is nasty, but the above doesn't work! */ + int throbberHeight = 16; + /* It's difficult (or I spent a while trying) to work out whether the scrollbars are currently shown and their appropriate size, + * because if you listen for the expanded/collapsed signals, you seem to get them before the scrollbars are updated. + * This seems an acceptable workaround. + */ + hasHadScrollBars_ |= ui_.results_->verticalScrollBar()->isVisible(); + int hMargin = hasHadScrollBars_ ? ui_.results_->verticalScrollBar()->width() + 2 : 2; + int vMargin = 2; /* We don't get horizontal scrollbars */ + throbber_->setGeometry(QRect(resultWidth - throbberWidth - hMargin, resultHeight - throbberHeight - vMargin, throbberWidth, throbberHeight)); /* include margins */ + throbber_->setVisible(isShown); } void QtMUCSearchWindow::addSavedServices(const std::list<JID>& services) { - ui_.service_->clear(); - foreach (const JID& jid, services) { - ui_.service_->addItem(P2QSTRING(jid.toString())); - } - if (!services.empty()) { - ui_.service_->setEditText(P2QSTRING(services.begin()->toString())); - } - else { - ui_.service_->clearEditText(); - } + ui_.service_->clear(); + foreach (const JID& jid, services) { + ui_.service_->addItem(P2QSTRING(jid.toString())); + } + if (!services.empty()) { + ui_.service_->setEditText(P2QSTRING(services.begin()->toString())); + } + else { + ui_.service_->clearEditText(); + } } void QtMUCSearchWindow::handleActivated(const QModelIndex& index) { - if (!index.isValid()) { - return; - } - if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) { - accept(); - } + if (!index.isValid()) { + return; + } + if (dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(index.internalPointer()))) { + accept(); + } } void QtMUCSearchWindow::handleSearch() { - handleSearch(ui_.service_->currentText()); + handleSearch(ui_.service_->currentText()); } void QtMUCSearchWindow::handleSearch(const QString& service) { - if (!service.isEmpty()) { - onSearchService(JID(Q2PSTRING(service))); - } + if (!service.isEmpty()) { + onSearchService(JID(Q2PSTRING(service))); + } } void QtMUCSearchWindow::show() { - QWidget::show(); - QWidget::activateWindow(); + QWidget::show(); + QWidget::activateWindow(); } void QtMUCSearchWindow::clearList() { - model_->clear(); + model_->clear(); } void QtMUCSearchWindow::addService(const MUCService& service) { - updateThrobberPosition(); - MUCSearchServiceItem* serviceItem = new MUCSearchServiceItem(P2QSTRING(service.getJID().toString())); - if (service.getRooms().size() > 0) { - foreach (MUCService::MUCRoom room, service.getRooms()) { - new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem); - } - } - else { - new MUCSearchEmptyItem(serviceItem); - } - model_->addService(serviceItem); - ui_.results_->expandAll(); + updateThrobberPosition(); + MUCSearchServiceItem* serviceItem = new MUCSearchServiceItem(P2QSTRING(service.getJID().toString())); + if (service.getRooms().size() > 0) { + foreach (MUCService::MUCRoom room, service.getRooms()) { + new MUCSearchRoomItem(P2QSTRING(room.getNode()), serviceItem); + } + } + else { + new MUCSearchEmptyItem(serviceItem); + } + model_->addService(serviceItem); + ui_.results_->expandAll(); } void QtMUCSearchWindow::setSearchInProgress(bool searching) { - if (searching) { - throbber_->movie()->start(); - } else { - throbber_->movie()->stop(); - } - throbber_->setVisible(searching); + if (searching) { + throbber_->movie()->start(); + } else { + throbber_->movie()->stop(); + } + throbber_->setVisible(searching); } void QtMUCSearchWindow::accept() { - MUCSearchRoomItem* room = getSelectedRoom(); - if (room) { - onFinished(JID(Q2PSTRING(room->getNode()), Q2PSTRING(room->getParent()->getHost()))); - } - else { - onFinished(boost::optional<JID>()); - } - QDialog::accept(); + MUCSearchRoomItem* room = getSelectedRoom(); + if (room) { + onFinished(JID(Q2PSTRING(room->getNode()), Q2PSTRING(room->getParent()->getHost()))); + } + else { + onFinished(boost::optional<JID>()); + } + QDialog::accept(); } void QtMUCSearchWindow::reject() { - onFinished(boost::optional<JID>()); - QDialog::reject(); + onFinished(boost::optional<JID>()); + QDialog::reject(); } void QtMUCSearchWindow::handleSelectionChanged(const QItemSelection&, const QItemSelection&) { - ui_.okButton->setEnabled(getSelectedRoom()); + ui_.okButton->setEnabled(getSelectedRoom()); } MUCSearchRoomItem* QtMUCSearchWindow::getSelectedRoom() const { - // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the - // QModelIndexList destructor. - // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case - // was resolved by linking against the debug libs, ours isn't, and we're not alone) - QItemSelection ranges = ui_.results_->selectionModel()->selection(); - QModelIndexList lstIndex; - for (int i = 0; i < ranges.count(); ++i) { - QModelIndex parent = ranges.at(i).parent(); - int right = ranges.at(i).model()->columnCount(parent) - 1; - if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) { - for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) { - lstIndex.append(ranges.at(i).model()->index(r, 0, parent)); - } - } - } - if (lstIndex.isEmpty()) { - return NULL; - } - else { - return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer())); - } + // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the + // QModelIndexList destructor. + // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case + // was resolved by linking against the debug libs, ours isn't, and we're not alone) + QItemSelection ranges = ui_.results_->selectionModel()->selection(); + QModelIndexList lstIndex; + for (int i = 0; i < ranges.count(); ++i) { + QModelIndex parent = ranges.at(i).parent(); + int right = ranges.at(i).model()->columnCount(parent) - 1; + if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) { + for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) { + lstIndex.append(ranges.at(i).model()->index(r, 0, parent)); + } + } + } + if (lstIndex.isEmpty()) { + return NULL; + } + else { + return dynamic_cast<MUCSearchRoomItem*>(static_cast<MUCSearchItem*>(lstIndex.first().internalPointer())); + } } } diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h index 4ac845a..b115e6f 100644 --- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h +++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.h @@ -11,41 +11,41 @@ #include <Swift/QtUI/MUCSearch/ui_QtMUCSearchWindow.h> namespace Swift { - class MUCSearchModel; - class MUCSearchDelegate; - class MUCSearchRoomItem; - - class QtMUCSearchWindow : public QDialog, public MUCSearchWindow { - Q_OBJECT - public: - QtMUCSearchWindow(); - virtual ~QtMUCSearchWindow(); - - virtual void clearList(); - virtual void addService(const MUCService& service); - virtual void addSavedServices(const std::list<JID>& services); - virtual void setSearchInProgress(bool searching); - - virtual void show(); - virtual void accept(); - virtual void reject(); - - protected: - virtual void resizeEvent(QResizeEvent* event); - - private slots: - void handleSearch(); - void handleSearch(const QString&); - void handleActivated(const QModelIndex& index); - void updateThrobberPosition(); - void handleSelectionChanged (const QItemSelection&, const QItemSelection&); - MUCSearchRoomItem* getSelectedRoom() const; - - private: - Ui::QtMUCSearchWindow ui_; - MUCSearchModel* model_; - MUCSearchDelegate* delegate_; - QLabel* throbber_; - bool hasHadScrollBars_; - }; + class MUCSearchModel; + class MUCSearchDelegate; + class MUCSearchRoomItem; + + class QtMUCSearchWindow : public QDialog, public MUCSearchWindow { + Q_OBJECT + public: + QtMUCSearchWindow(); + virtual ~QtMUCSearchWindow(); + + virtual void clearList(); + virtual void addService(const MUCService& service); + virtual void addSavedServices(const std::list<JID>& services); + virtual void setSearchInProgress(bool searching); + + virtual void show(); + virtual void accept(); + virtual void reject(); + + protected: + virtual void resizeEvent(QResizeEvent* event); + + private slots: + void handleSearch(); + void handleSearch(const QString&); + void handleActivated(const QModelIndex& index); + void updateThrobberPosition(); + void handleSelectionChanged (const QItemSelection&, const QItemSelection&); + MUCSearchRoomItem* getSelectedRoom() const; + + private: + Ui::QtMUCSearchWindow ui_; + MUCSearchModel* model_; + MUCSearchDelegate* delegate_; + QLabel* throbber_; + bool hasHadScrollBars_; + }; } |