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
This commit is contained in:
thunder2 2012-10-29 10:59:26 +00:00
parent 68f48a802c
commit a7c29c0f24
18 changed files with 289 additions and 388 deletions

View File

@ -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);
@ -216,10 +193,6 @@ ForumsDialog::ForumsDialog(QWidget *parent)
ui.threadTreeWidget->installEventFilter(this);
#if QT_VERSION >= 0x040700
ui.filterLineEdit->setPlaceholderText(tr("Search this forum...")) ;
#endif
/* 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++) {

View File

@ -98,7 +98,7 @@ private slots:
void changedViewBox();
void filterColumnChanged();
void filterColumnChanged(int column);
void filterItems(const QString &text);
void generateMassData();

View File

@ -549,54 +549,7 @@
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Search forums</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="filterColumnComboBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font/>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>Date</string>
</property>
</item>
<item>
<property name="text">
<string>Title</string>
</property>
</item>
<item>
<property name="text">
<string>Author</string>
</property>
</item>
<item>
<property name="text">
<string>Content</string>
</property>
</item>
</widget>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</widget>
@ -670,17 +623,17 @@
<extends>QTextBrowser</extends>
<header>gui/common/LinkTextBrowser.h</header>
</customwidget>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
<customwidget>
<class>GroupTreeWidget</class>
<extends>QWidget</extends>
<header>gui/common/GroupTreeWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="images.qrc"/>

View File

@ -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();

View File

@ -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()

View File

@ -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);

View File

@ -367,53 +367,6 @@
</property>
</spacer>
</item>
<item row="0" column="11">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>1</number>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</item>
<item row="0" column="12">
<widget class="QComboBox" name="filterColumnComboBox">
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Attachments</string>
</property>
</item>
<item>
<property name="text">
<string>Subject</string>
</property>
</item>
<item>
<property name="text">
<string>From</string>
</property>
</item>
<item>
<property name="text">
<string>Date</string>
</property>
</item>
<item>
<property name="text">
<string>Content</string>
</property>
</item>
<item>
<property name="text">
<string>Tags</string>
</property>
</item>
</widget>
</item>
<item row="0" column="6">
<widget class="QToolButton" name="tagButton">
<property name="focusPolicy">
@ -443,6 +396,9 @@
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</widget>
</item>
@ -811,7 +767,7 @@
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
<customwidget>
<class>RSTabWidget</class>

View File

@ -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++) {

View File

@ -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:

View File

@ -171,43 +171,10 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Search Network</string>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Search Network</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="filterColumnComboBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font/>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>Name</string>
</property>
</item>
<item>
<property name="text">
<string>Peer ID</string>
</property>
</item>
</widget>
</item>
<item>
@ -504,7 +471,7 @@
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources>

View File

@ -75,18 +75,6 @@ const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
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);
}
}

View File

@ -281,50 +281,6 @@
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>6</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Filter Search Result</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="filterColumnComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<item>
<property name="text">
<string>File Name</string>
</property>
</item>
<item>
<property name="text">
<string>File Size</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="SearchTreeWidget" name="searchResultWidget">
<property name="sizePolicy">
@ -382,6 +338,13 @@
</column>
</widget>
</item>
<item row="0" column="0">
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Filter Search Result</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -550,7 +513,7 @@
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
<customwidget>
<class>SearchTreeWidget</class>

View File

@ -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()

View File

@ -33,11 +33,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Search Friends</string>
</property>
</widget>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
</layout>
</item>
@ -77,7 +73,7 @@
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -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;
}

View File

@ -18,38 +18,7 @@
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Enter a Keyword here</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="filterCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Title</string>
</property>
</item>
<item>
<property name="text">
<string>Description</string>
</property>
</item>
</widget>
</item>
</layout>
<widget class="LineEditClear" name="filterLineEdit"/>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget">
@ -101,7 +70,7 @@
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@ -24,46 +24,183 @@
#include <QToolButton>
#include <QStyle>
#include <QMenu>
#if QT_VERSION < 0x040700
#include <QLabel>
#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<int, QString>::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);
}

View File

@ -24,8 +24,13 @@
#define LINEEDITCLEAR_H
#include <QLineEdit>
#include <QMap>
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<int, QString> mDescription;
#if QT_VERSION < 0x040700
QLabel *mFilterLabel;
#endif
};
#endif // LINEEDITCLEAR_H