aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/fancylineedit.cpp
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-02-13 13:54:39 +0100
committerhjk <hjk121@nokiamail.com>2014-02-14 16:58:43 +0100
commita74de6af81b659ef0dcbbbe25f94d9b527c2be98 (patch)
tree79c7d50c5afb664ec392a016b1abee178d528d2d /src/libs/utils/fancylineedit.cpp
parent5fd7c0bceceae795125ae32429365b021cd05e4b (diff)
Utils: Merge FilterLineEdit into FancyLineEdit
Change-Id: Ic53836dade3985c36b0f6767e43b5af0ddb80d72 Reviewed-by: Eike Ziller <eike.ziller@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src/libs/utils/fancylineedit.cpp')
-rw-r--r--src/libs/utils/fancylineedit.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp
index 5956884f9a4..f6ae4d0e222 100644
--- a/src/libs/utils/fancylineedit.cpp
+++ b/src/libs/utils/fancylineedit.cpp
@@ -77,11 +77,14 @@ public:
bool m_iconEnabled[2];
HistoryCompleter *m_historyCompleter;
+
+ bool m_isFiltering;
+ QString m_lastFilterText;
};
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
- QObject(parent), m_lineEdit(parent), m_historyCompleter(0)
+ QObject(parent), m_lineEdit(parent), m_historyCompleter(0), m_isFiltering(false)
{
for (int i = 0; i < 2; ++i) {
m_menu[i] = 0;
@@ -297,6 +300,45 @@ void FancyLineEdit::setButtonFocusPolicy(Side side, Qt::FocusPolicy policy)
d->m_iconbutton[side]->setFocusPolicy(policy);
}
+void FancyLineEdit::setFiltering(bool on)
+{
+ if (on == d->m_isFiltering)
+ return;
+
+ d->m_isFiltering = on;
+ if (on) {
+ d->m_lastFilterText = text();
+ // KDE has custom icons for this. Notice that icon namings are counter intuitive.
+ // If these icons are not available we use the freedesktop standard name before
+ // falling back to a bundled resource.
+ QIcon icon = QIcon::fromTheme(layoutDirection() == Qt::LeftToRight ?
+ QLatin1String("edit-clear-locationbar-rtl") :
+ QLatin1String("edit-clear-locationbar-ltr"),
+ QIcon::fromTheme(QLatin1String("edit-clear"), QIcon(QLatin1String(":/core/images/editclear.png"))));
+
+ setButtonPixmap(Right, icon.pixmap(16));
+ setButtonVisible(Right, true);
+ setPlaceholderText(tr("Filter"));
+ setButtonToolTip(Right, tr("Clear text"));
+ setAutoHideButton(Right, true);
+ connect(this, SIGNAL(rightButtonClicked()), this, SLOT(clear()));
+ connect(this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged()));
+ } else {
+ disconnect(this, SIGNAL(rightButtonClicked()), this, SLOT(clear()));
+ disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged()));
+ }
+}
+
+void FancyLineEdit::slotTextChanged()
+{
+ const QString newlyTypedText = text();
+ if (newlyTypedText != d->m_lastFilterText) {
+ d->m_lastFilterText = newlyTypedText;
+ emit filterChanged(d->m_lastFilterText);
+ }
+}
+
+
// IconButton - helper class to represent a clickable icon
IconButton::IconButton(QWidget *parent)