From a7c29c0f2452e37fae82596c9eb89cecac3f8d1b Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 29 Oct 2012 10:59:26 +0000 Subject: [PATCH] Removed the filter comboboxes and replaced it with a menu in LineEditClear. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5737 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ForumsDialog.cpp | 65 ++---- retroshare-gui/src/gui/ForumsDialog.h | 2 +- retroshare-gui/src/gui/ForumsDialog.ui | 59 +----- retroshare-gui/src/gui/FriendsDialog.cpp | 2 - retroshare-gui/src/gui/MessagesDialog.cpp | 68 ++----- retroshare-gui/src/gui/MessagesDialog.h | 2 +- retroshare-gui/src/gui/MessagesDialog.ui | 52 +---- retroshare-gui/src/gui/NetworkDialog.cpp | 23 +-- retroshare-gui/src/gui/NetworkDialog.h | 2 +- retroshare-gui/src/gui/NetworkDialog.ui | 41 +--- retroshare-gui/src/gui/SearchDialog.cpp | 21 +- retroshare-gui/src/gui/SearchDialog.ui | 53 +---- .../src/gui/common/FriendSelectionWidget.cpp | 2 + .../src/gui/common/FriendSelectionWidget.ui | 8 +- .../src/gui/common/GroupTreeWidget.cpp | 19 +- .../src/gui/common/GroupTreeWidget.ui | 35 +--- .../src/gui/common/LineEditClear.cpp | 187 +++++++++++++++--- retroshare-gui/src/gui/common/LineEditClear.h | 36 +++- 18 files changed, 289 insertions(+), 388 deletions(-) diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 5799f3936..1996ce503 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -97,38 +97,6 @@ #define IS_FORUM_ADMIN(subscribeFlags) (subscribeFlags & RS_DISTRIB_ADMIN) #define IS_FORUM_SUBSCRIBED(subscribeFlags) (subscribeFlags & (RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED)) -static int FilterColumnFromComboBox(int nIndex) -{ - switch (nIndex) { - case 0: - return COLUMN_THREAD_DATE; - case 1: - return COLUMN_THREAD_TITLE; - case 2: - return COLUMN_THREAD_AUTHOR; - case 3: - return COLUMN_THREAD_CONTENT; - } - - return COLUMN_THREAD_TITLE; -} - -static int FilterColumnToComboBox(int nIndex) -{ - switch (nIndex) { - case COLUMN_THREAD_DATE: - return 0; - case COLUMN_THREAD_TITLE: - return 1; - case COLUMN_THREAD_AUTHOR: - return 2; - case COLUMN_THREAD_CONTENT: - return 3; - } - - return FilterColumnToComboBox(COLUMN_THREAD_TITLE); -} - /** Constructor */ ForumsDialog::ForumsDialog(QWidget *parent) : RsAutoUpdatePage(1000,parent) @@ -161,7 +129,7 @@ ForumsDialog::ForumsDialog(QWidget *parent) connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadAllFiles())); connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); - connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged())); + connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int))); connect(NotifyQt::getInstance(), SIGNAL(forumMsgReadSatusChanged(QString,QString,int)), this, SLOT(forumMsgReadSatusChanged(QString,QString,int))); @@ -198,6 +166,15 @@ ForumsDialog::ForumsDialog(QWidget *parent) lastViewType = -1; + /* add filter actions */ + ui.filterLineEdit->addFilter(QIcon(), tr("Title"), COLUMN_THREAD_TITLE); + ui.filterLineEdit->addFilter(QIcon(), tr("Date"), COLUMN_THREAD_DATE); + ui.filterLineEdit->addFilter(QIcon(), tr("Author"), COLUMN_THREAD_AUTHOR); + ui.filterLineEdit->addFilter(QIcon(), tr("Content"), COLUMN_THREAD_CONTENT); + ui.filterLineEdit->setCurrentFilter(COLUMN_THREAD_TITLE); + // can be removed when the actions of the filter line edit have own placeholder text + ui.filterLineEdit->setPlaceholderText(tr("Search this forum...")) ; + // load settings processSettings(true); @@ -214,12 +191,8 @@ ForumsDialog::ForumsDialog(QWidget *parent) insertThreads(); - ui.threadTreeWidget->installEventFilter(this); - -#if QT_VERSION >= 0x040700 - ui.filterLineEdit->setPlaceholderText(tr("Search this forum...")) ; -#endif - + ui.threadTreeWidget->installEventFilter(this); + /* Hide platform specific features */ #ifdef Q_WS_WIN @@ -260,8 +233,7 @@ void ForumsDialog::processSettings(bool bLoad) togglethreadview_internal(); // filterColumn - int nValue = FilterColumnToComboBox(Settings->value("filterColumn", COLUMN_THREAD_TITLE).toInt()); - ui.filterColumnComboBox->setCurrentIndex(nValue); + ui.filterLineEdit->setCurrentFilter(Settings->value("filterColumn", COLUMN_THREAD_TITLE).toInt()); // index of viewBox ui.viewBox->setCurrentIndex(Settings->value("viewBox", VIEW_THREADED).toInt()); @@ -916,7 +888,7 @@ void ForumsDialog::insertThreads() // set data fillThread->forumId = mCurrForumId; - fillThread->filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + fillThread->filterColumn = ui.filterLineEdit->currentFilter(); fillThread->subscribeFlags = subscribeFlags; fillThread->viewType = ui.viewBox->currentIndex(); if (lastViewType != fillThread->viewType || lastForumID != mCurrForumId) { @@ -1599,14 +1571,13 @@ void ForumsDialog::changedViewBox() insertThreads(); } -void ForumsDialog::filterColumnChanged() +void ForumsDialog::filterColumnChanged(int column) { if (m_bProcessSettings) { return; } - int filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); - if (filterColumn == COLUMN_THREAD_CONTENT) { + if (column == COLUMN_THREAD_CONTENT) { // need content ... refill insertThreads(); } else { @@ -1614,12 +1585,12 @@ void ForumsDialog::filterColumnChanged() } // save index - Settings->setValueToGroup("ForumsDialog", "filterColumn", filterColumn); + Settings->setValueToGroup("ForumsDialog", "filterColumn", column); } void ForumsDialog::filterItems(const QString& text) { - int filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + int filterColumn = ui.filterLineEdit->currentFilter(); int nCount = ui.threadTreeWidget->topLevelItemCount (); for (int nIndex = 0; nIndex < nCount; nIndex++) { diff --git a/retroshare-gui/src/gui/ForumsDialog.h b/retroshare-gui/src/gui/ForumsDialog.h index 904e94ad3..c885781de 100644 --- a/retroshare-gui/src/gui/ForumsDialog.h +++ b/retroshare-gui/src/gui/ForumsDialog.h @@ -98,7 +98,7 @@ private slots: void changedViewBox(); - void filterColumnChanged(); + void filterColumnChanged(int column); void filterItems(const QString &text); void generateMassData(); diff --git a/retroshare-gui/src/gui/ForumsDialog.ui b/retroshare-gui/src/gui/ForumsDialog.ui index c5a23614e..2e52cf057 100644 --- a/retroshare-gui/src/gui/ForumsDialog.ui +++ b/retroshare-gui/src/gui/ForumsDialog.ui @@ -549,54 +549,7 @@ - - - 2 - - - - - Search forums - - - - - - - - - - 0 - 0 - - - - - - - 1 - - - - Date - - - - - Title - - - - - Author - - - - - Content - - - + @@ -670,17 +623,17 @@ QTextBrowser
gui/common/LinkTextBrowser.h
+ + LineEditClear + QLineEdit +
gui/common/LineEditClear.h
+
GroupTreeWidget QWidget
gui/common/GroupTreeWidget.h
1
- - LineEditClear - QLineEdit -
gui/common/LineEditClear.h
-
diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 66cb39a15..21e8e55b8 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -92,9 +92,7 @@ FriendsDialog::FriendsDialog(QWidget *parent) connect( ui.actionFriendRecommendations, SIGNAL(triggered()), this, SLOT(recommendFriends())); connect( ui.filter_lineEdit, SIGNAL(textChanged(QString)), ui.friendList, SLOT(filterItems(QString))); -#if QT_VERSION >= 0x040700 ui.filter_lineEdit->setPlaceholderText(tr("Search")) ; -#endif ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setOwnId(); diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 2c6bf311a..0f7f4f8aa 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -106,46 +106,6 @@ void MessagesDialog::LockUpdate::setUpdate(bool bUpdate) m_bUpdate = bUpdate; } -static int FilterColumnFromComboBox(int nIndex) -{ - switch (nIndex) { - case 0: - return COLUMN_ATTACHEMENTS; - case 1: - return COLUMN_SUBJECT; - case 2: - return COLUMN_FROM; - case 3: - return COLUMN_DATE; - case 4: - return COLUMN_CONTENT; - case 5: - return COLUMN_TAGS; - } - - return COLUMN_SUBJECT; -} - -static int FilterColumnToComboBox(int nIndex) -{ - switch (nIndex) { - case COLUMN_ATTACHEMENTS: - return 0; - case COLUMN_SUBJECT: - return 1; - case COLUMN_FROM: - return 2; - case COLUMN_DATE: - return 3; - case COLUMN_CONTENT: - return 4; - case COLUMN_TAGS: - return 5; - } - - return FilterColumnToComboBox(COLUMN_SUBJECT); -} - /** Constructor */ MessagesDialog::MessagesDialog(QWidget *parent) : MainPage(parent) @@ -176,8 +136,7 @@ MessagesDialog::MessagesDialog(QWidget *parent) ui.actionTextUnderIcon->setData(Qt::ToolButtonTextUnderIcon); connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); - - connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged())); + connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int))); msgWidget = new MessageWidget(true, this); ui.msgLayout->addWidget(msgWidget); @@ -260,8 +219,17 @@ MessagesDialog::MessagesDialog(QWidget *parent) //viewmenu->addAction(ui.actionTextUnderIcon); ui.viewtoolButton->setMenu(viewmenu); + /* add filter actions */ + ui.filterLineEdit->addFilter(QIcon(), tr("Subject"), COLUMN_SUBJECT); + ui.filterLineEdit->addFilter(QIcon(), tr("From"), COLUMN_FROM); + ui.filterLineEdit->addFilter(QIcon(), tr("Date"), COLUMN_DATE); + ui.filterLineEdit->addFilter(QIcon(), tr("Content"), COLUMN_CONTENT); + ui.filterLineEdit->addFilter(QIcon(), tr("Tags"), COLUMN_TAGS); + ui.filterLineEdit->addFilter(QIcon(), tr("Attachments"), COLUMN_ATTACHEMENTS); + //setting default filter by column as subject - proxyModel->setFilterKeyColumn(FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex())); + ui.filterLineEdit->setCurrentFilter(COLUMN_SUBJECT); + proxyModel->setFilterKeyColumn(COLUMN_SUBJECT); // load settings processSettings(true); @@ -336,8 +304,7 @@ void MessagesDialog::processSettings(bool load) // load settings // filterColumn - int nValue = FilterColumnToComboBox(Settings->value("filterColumn", true).toInt()); - ui.filterColumnComboBox->setCurrentIndex(nValue); + ui.filterLineEdit->setCurrentFilter(Settings->value("filterColumn", COLUMN_SUBJECT).toInt()); // state of message tree if (Settings->value("MessageTreeVersion").toInt() == messageTreeVersion) { @@ -847,7 +814,7 @@ void MessagesDialog::insertMessages() std::cerr << "MessagesDialog::insertMessages()" << std::endl; - int filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + int filterColumn = ui.filterLineEdit->currentFilter(); /* check the mode we are in */ unsigned int msgbox = 0; @@ -1597,21 +1564,20 @@ void MessagesDialog::filterChanged(const QString& text) proxyModel->setFilterRegExp(regExp); } -void MessagesDialog::filterColumnChanged() +void MessagesDialog::filterColumnChanged(int column) { if (inProcessSettings) { return; } - int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); - if (nFilterColumn == COLUMN_CONTENT) { + if (column == COLUMN_CONTENT) { // need content ... refill insertMessages(); } - proxyModel->setFilterKeyColumn(nFilterColumn); + proxyModel->setFilterKeyColumn(column); // save index - Settings->setValueToGroup("MessageDialog", "filterColumn", nFilterColumn); + Settings->setValueToGroup("MessageDialog", "filterColumn", column); } void MessagesDialog::updateMessageSummaryList() diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index bed74cf4a..63b578adc 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -80,7 +80,7 @@ private slots: void buttonStyle(); void filterChanged(const QString &text); - void filterColumnChanged(); + void filterColumnChanged(int column); void tagAboutToShow(); void tagSet(int tagId, bool set); diff --git a/retroshare-gui/src/gui/MessagesDialog.ui b/retroshare-gui/src/gui/MessagesDialog.ui index 3fccd7f11..41ea73e73 100644 --- a/retroshare-gui/src/gui/MessagesDialog.ui +++ b/retroshare-gui/src/gui/MessagesDialog.ui @@ -367,53 +367,6 @@ - - - - 1 - - - - - - - - - - 0 - - - - Attachments - - - - - Subject - - - - - From - - - - - Date - - - - - Content - - - - - Tags - - - - @@ -443,6 +396,9 @@ + + + @@ -811,7 +767,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
RSTabWidget diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 0ea086813..12adb4c21 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -57,18 +57,6 @@ #define COLUMN_PEERNAME 1 #define COLUMN_PEERID 4 -static int FilterColumnFromComboBox(int nIndex) -{ - switch (nIndex) { - case 0: - return COLUMN_PEERNAME; - case 1: - return COLUMN_PEERID; - } - - return COLUMN_PEERNAME; -} - RsCertId getNeighRsCertId(QTreeWidgetItem *i); /****** @@ -90,7 +78,7 @@ NetworkDialog::NetworkDialog(QWidget *parent) connect( ui.unvalidGPGkeyWidget, SIGNAL( itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT( peerdetails () ) ); connect( ui.filterLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterItems(QString))); - connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged())); + connect( ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int))); connect( ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect())); @@ -177,6 +165,11 @@ NetworkDialog::NetworkDialog(QWidget *parent) connect(timer2, SIGNAL(timeout()), this, SLOT(updateNetworkStatus())); timer2->start(1000); + /* add filter actions */ + ui.filterLineEdit->addFilter(QIcon(), tr("Name"), COLUMN_PEERNAME); + ui.filterLineEdit->addFilter(QIcon(), tr("Peer ID"), COLUMN_PEERID); + ui.filterLineEdit->setCurrentFilter(COLUMN_PEERNAME); + updateNetworkStatus(); loadtabsettings(); @@ -793,14 +786,14 @@ void NetworkDialog::loadtabsettings() Settings->endGroup(); } -void NetworkDialog::filterColumnChanged() +void NetworkDialog::filterColumnChanged(int) { filterItems(ui.filterLineEdit->text()); } void NetworkDialog::filterItems(const QString &text) { - int filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + int filterColumn = ui.filterLineEdit->currentFilter(); int count = ui.connecttreeWidget->topLevelItemCount (); for (int index = 0; index < count; index++) { diff --git a/retroshare-gui/src/gui/NetworkDialog.h b/retroshare-gui/src/gui/NetworkDialog.h index 88977b3e0..b8329de7a 100644 --- a/retroshare-gui/src/gui/NetworkDialog.h +++ b/retroshare-gui/src/gui/NetworkDialog.h @@ -79,7 +79,7 @@ private slots: void on_actionTabsRounded_activated(); void on_actionTabsTriangular_activated(); - void filterColumnChanged(); + void filterColumnChanged(int); void filterItems(const QString &text); private: diff --git a/retroshare-gui/src/gui/NetworkDialog.ui b/retroshare-gui/src/gui/NetworkDialog.ui index b223be7f2..2c78b545d 100644 --- a/retroshare-gui/src/gui/NetworkDialog.ui +++ b/retroshare-gui/src/gui/NetworkDialog.ui @@ -171,43 +171,10 @@ - - - 2 + + + Search Network - - - - Search Network - - - - - - - - - - 0 - 0 - - - - - - - 0 - - - - Name - - - - - Peer ID - - @@ -504,7 +471,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index cedf71813..27346873f 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -75,18 +75,6 @@ const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8; QMap * SearchDialog::FileTypeExtensionMap = new QMap(); bool SearchDialog::initialised = false; -static int FilterColumnFromComboBox(int nIndex) -{ - switch (nIndex) { - case 0: - return SR_NAME_COL; - case 1: - return SR_SIZE_COL; - } - - return SR_NAME_COL; -} - /** Constructor */ SearchDialog::SearchDialog(QWidget *parent) : MainPage(parent), @@ -127,7 +115,7 @@ SearchDialog::SearchDialog(QWidget *parent) connect(ui.FileTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFileType(int))); connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems())); - connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterItems())); + connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterItems())); compareSummaryRole = new RSTreeWidgetItemCompareRole; compareSummaryRole->setRole(SS_COUNT_COL, ROLE_SORT); @@ -187,6 +175,11 @@ SearchDialog::SearchDialog(QWidget *parent) sizes << 250 << width(); // Qt calculates the right sizes ui.splitter->setSizes(sizes); + /* add filter actions */ + ui.filterLineEdit->addFilter(QIcon(), tr("File Name"), SR_NAME_COL); +// ui.filterLineEdit->addFilter(QIcon(), tr("File Size"), SR_SIZE_COL); + ui.filterLineEdit->setCurrentFilter(SR_NAME_COL); + // load settings processSettings(true); @@ -1233,7 +1226,7 @@ void SearchDialog::hideOrShowSearchResult(QTreeWidgetItem* resultItem, QString c if (ui.filterLineEdit->text().isEmpty()) { resultItem->setHidden(false); } else { - int filterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); + int filterColumn = ui.filterLineEdit->currentFilter(); filterItem(resultItem, ui.filterLineEdit->text(), filterColumn); } } diff --git a/retroshare-gui/src/gui/SearchDialog.ui b/retroshare-gui/src/gui/SearchDialog.ui index 132b2e71c..efa2a82a6 100644 --- a/retroshare-gui/src/gui/SearchDialog.ui +++ b/retroshare-gui/src/gui/SearchDialog.ui @@ -281,50 +281,6 @@ - - - - 6 - - - 2 - - - - - 2 - - - - - Filter Search Result - - - - - - - - - false - - - 0 - - - - File Name - - - - - File Size - - - - - - @@ -382,6 +338,13 @@ + + + + Filter Search Result + + + @@ -550,7 +513,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
SearchTreeWidget diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 304288b05..11b32d6df 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -95,6 +95,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) : // sort list by name ascending ui->friendList->sortItems(COLUMN_NAME, Qt::AscendingOrder); + + ui->filterLineEdit->setPlaceholderText(tr("Search Friends")); } FriendSelectionWidget::~FriendSelectionWidget() diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.ui b/retroshare-gui/src/gui/common/FriendSelectionWidget.ui index f97ccd039..48c4204d4 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.ui +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.ui @@ -33,11 +33,7 @@
- - - Search Friends - - + @@ -77,7 +73,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index d7d9c2aee..364e967b9 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -44,8 +44,8 @@ #define ROLE_LASTPOST Qt::UserRole + 4 #define ROLE_SEARCH_SCORE Qt::UserRole + 5 -#define COMBO_NAME_INDEX 0 -#define COMBO_DESC_INDEX 1 +#define FILTER_NAME_INDEX 0 +#define FILTER_DESC_INDEX 1 GroupTreeWidget::GroupTreeWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GroupTreeWidget) @@ -64,7 +64,7 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) : /* Connect signals */ connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged())); - connect(ui->filterCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterChanged())); + connect(ui->filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterChanged())); connect(ui->treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint))); connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); @@ -83,6 +83,13 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) : header->resizeSection(COLUMN_NAME, 170); header->setResizeMode(COLUMN_POPULARITY, QHeaderView::Fixed); header->resizeSection(COLUMN_POPULARITY, 25); + + /* add filter actions */ + ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_NAME_INDEX); + ui->filterLineEdit->addFilter(QIcon(), tr("Description"), FILTER_DESC_INDEX); + ui->filterLineEdit->setCurrentFilter(FILTER_NAME_INDEX); + // can be removed when the actions of the filter line edit have own placeholder text + ui->filterLineEdit->setPlaceholderText(tr("Enter a Keyword here")); } GroupTreeWidget::~GroupTreeWidget() @@ -388,11 +395,11 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte } else { QString scoreString; - switch (ui->filterCombo->currentIndex()) { - case COMBO_NAME_INDEX: + switch (ui->filterLineEdit->currentFilter()) { + case FILTER_NAME_INDEX: scoreString = item->data(COLUMN_DATA, ROLE_NAME).toString(); break; - case COMBO_DESC_INDEX: + case FILTER_DESC_INDEX: scoreString = item->data(COLUMN_DATA, ROLE_DESCRIPTION).toString(); break; } diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.ui b/retroshare-gui/src/gui/common/GroupTreeWidget.ui index f8f6f8012..bd1b8c835 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.ui +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.ui @@ -18,38 +18,7 @@ 0 - - - 2 - - - - - Enter a Keyword here - - - - - - - - 0 - 0 - - - - - Title - - - - - Description - - - - - + @@ -101,7 +70,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
diff --git a/retroshare-gui/src/gui/common/LineEditClear.cpp b/retroshare-gui/src/gui/common/LineEditClear.cpp index f639fd47e..3f8fd0596 100644 --- a/retroshare-gui/src/gui/common/LineEditClear.cpp +++ b/retroshare-gui/src/gui/common/LineEditClear.cpp @@ -24,46 +24,183 @@ #include #include +#include +#if QT_VERSION < 0x040700 +#include +#endif + +#define IMAGE_FILTER ":/images/find-16.png" LineEditClear::LineEditClear(QWidget *parent) : QLineEdit(parent) { - findButton = new QToolButton(this); - QPixmap findPixmap(":/images/find-16.png"); - findButton->setIcon(QIcon(findPixmap)); - findButton->setIconSize(findPixmap.size()); - findButton->setCursor(Qt::ArrowCursor); - findButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + mActionGroup = NULL; - clearButton = new QToolButton(this); - clearButton->setFixedSize(16, 16); - clearButton->setIconSize(QSize(16, 16)); - clearButton->setCursor(Qt::ArrowCursor); - clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }" - "QToolButton { border-image: url(:/images/closenormal.png) }" - "QToolButton:hover { border-image: url(:/images/closehover.png) }" - "QToolButton:pressed { border-image: url(:/images/closepressed.png) }"); - clearButton->hide(); + mFilterButton = new QToolButton(this); + mFilterButton->setFixedSize(16, 16); + QPixmap filterPixmap(IMAGE_FILTER); + mFilterButton->setIcon(QIcon(filterPixmap)); + mFilterButton->setIconSize(filterPixmap.size()); + mFilterButton->setCursor(Qt::ArrowCursor); + mFilterButton->setStyleSheet("QToolButton { border: none; padding: 0px; }" + "QToolButton[popupMode=\"2\"] { padding-right: 10px; }" + "QToolButton::menu-indicator[popupMode=\"2\"] { subcontrol-origin: padding; subcontrol-position: bottom right; top: 5px; left: -3px; width: 7px; }"); + mFilterButton->move(2, 2); - connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); - connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&))); + mClearButton = new QToolButton(this); + mClearButton->setFixedSize(16, 16); + mClearButton->setIconSize(QSize(16, 16)); + mClearButton->setCursor(Qt::ArrowCursor); + mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }" + "QToolButton { border-image: url(:/images/closenormal.png) }" + "QToolButton:hover { border-image: url(:/images/closehover.png) }" + "QToolButton:pressed { border-image: url(:/images/closepressed.png) }"); + mClearButton->hide(); + + connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&))); + +#if QT_VERSION < 0x040700 + mFilterLabel = new QLabel("", this); + mFilterLabel->setStyleSheet("QLabel { color: gray; }"); +#endif + + reposButtons(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - setStyleSheet(QString("QLineEdit { padding-right: %1px; padding-left: %2px; } "). - arg(clearButton->sizeHint().width() + frameWidth + 1). - arg(findButton->sizeHint().width() + frameWidth + 1)); QSize msz = minimumSizeHint(); - setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2), qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2)); + setMinimumSize( + qMax(msz.width(), mClearButton->sizeHint().height() + mFilterButton->sizeHint().width() + frameWidth * 2), + qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2)); } void LineEditClear::resizeEvent(QResizeEvent *) { - QSize sz = clearButton->sizeHint(); + QSize sz = mClearButton->sizeHint(); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - clearButton->move(rect().right() - frameWidth - sz.width() + 2, (rect().bottom() - sz.height()) / 2 + 2); + mClearButton->move(rect().right() - frameWidth - sz.width() + 2, (rect().bottom() - sz.height()) / 2 + 2); + +#if QT_VERSION < 0x040700 + sz = mFilterLabel->sizeHint(); + mFilterLabel->move(frameWidth + mFilterButton->sizeHint().width() + 5, (rect().bottom() + 1 - sz.height())/2); +#endif } -void LineEditClear::updateCloseButton(const QString& text) +void LineEditClear::setPlaceholderText(const QString &text) { - clearButton->setVisible(!text.isEmpty()); +#if QT_VERSION < 0x040700 + mFilterLabel->setText(text); +#else + QLineEdit::setPlaceholderText(text); +#endif + + setToolTip(text); +} + +#if QT_VERSION < 0x040700 +void LineEditClear::focusInEvent(QFocusEvent *event) +{ + mFilterLabel->setVisible(false); + QLineEdit::focusInEvent(event); +} + +void LineEditClear::focusOutEvent(QFocusEvent *event) +{ + if (text().isEmpty()) { + mFilterLabel->setVisible(true); + } + QLineEdit::focusOutEvent(event); +} +#endif + +void LineEditClear::reposButtons() +{ + int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); + setStyleSheet(QString("QLineEdit { padding-right: %1px; padding-left: %2px; }") + .arg(mClearButton->sizeHint().width() + frameWidth + 1) + .arg(mFilterButton->sizeHint().width() + frameWidth + 1)); +} + +void LineEditClear::updateClearButton(const QString& text) +{ + mClearButton->setVisible(!text.isEmpty()); +} + +void LineEditClear::addFilter(const QIcon &icon, const QString &text, int id, const QString &description) +{ + QAction *action = new QAction(icon, text, this); + action->setData(id); + action->setCheckable(true); + mDescription[id] = description; + + if (mActionGroup == NULL) { + mFilterButton->setFixedSize(26, 16); + mFilterButton->setPopupMode(QToolButton::InstantPopup); + + mActionGroup = new QActionGroup(this); + mActionGroup->setExclusive(true); + + QMenu *menu = new QMenu; + mFilterButton->setMenu(menu); + + connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(filterTriggered(QAction*))); + reposButtons(); + + /* set first action checked */ + action->setChecked(true); + activateAction(action); + } + + mFilterButton->menu()->addAction(action); + mActionGroup->addAction(action); +} + +void LineEditClear::setCurrentFilter(int id) +{ + QMenu *menu = mFilterButton->menu(); + if (menu) { + Q_FOREACH (QAction *action, menu->actions()) { + if (action->data().toInt() == id) { + action->setChecked(true); + activateAction(action); +// emit filterChanged(id); + break; + } + } + } +} + +int LineEditClear::currentFilter() +{ + if (mActionGroup == NULL) { + return 0; + } + + QAction *action = mActionGroup->checkedAction(); + if (action) { + return action->data().toInt(); + } + + return 0; +} + +void LineEditClear::filterTriggered(QAction *action) +{ + activateAction(action); + emit filterChanged(action->data().toInt()); +} + +void LineEditClear::activateAction(QAction *action) +{ + QMap::iterator description = mDescription.find(action->data().toInt()); + if (description != mDescription.end() && !description->isEmpty()) { + setPlaceholderText(*description); + } + + QIcon icon = action->icon(); + if (icon.isNull()) { + icon = QIcon(IMAGE_FILTER); + } + + mFilterButton->setIcon(icon); } diff --git a/retroshare-gui/src/gui/common/LineEditClear.h b/retroshare-gui/src/gui/common/LineEditClear.h index 1abb76bfa..f0cee2fe7 100644 --- a/retroshare-gui/src/gui/common/LineEditClear.h +++ b/retroshare-gui/src/gui/common/LineEditClear.h @@ -24,8 +24,13 @@ #define LINEEDITCLEAR_H #include +#include class QToolButton; +class QActionGroup; +#if QT_VERSION < 0x040700 +class QLabel; +#endif class LineEditClear : public QLineEdit { @@ -34,15 +39,40 @@ class LineEditClear : public QLineEdit public: LineEditClear(QWidget *parent = 0); + void addFilter(const QIcon &icon, const QString &text, int id, const QString &description = ""); + void setCurrentFilter(int id); + int currentFilter(); + +//#if QT_VERSION < 0x040700 + // for Qt version with setPlaceholderText too to set the tooltip of the lineedit + void setPlaceholderText(const QString &text); +//#endif + +signals: + void filterChanged(int id); + protected: void resizeEvent(QResizeEvent *); +#if QT_VERSION < 0x040700 + void focusInEvent(QFocusEvent *event); + void focusOutEvent(QFocusEvent *event); +#endif + void reposButtons(); + void activateAction(QAction *action); private slots: - void updateCloseButton(const QString &text); + void updateClearButton(const QString &text); + void filterTriggered(QAction *action); private: - QToolButton *clearButton; - QToolButton *findButton; + QToolButton *mClearButton; + QToolButton *mFilterButton; + QActionGroup *mActionGroup; + QMap mDescription; + +#if QT_VERSION < 0x040700 + QLabel *mFilterLabel; +#endif }; #endif // LINEEDITCLEAR_H