Prepare future 5.1.1
[kdepim.git] / kaddressbook / quicksearchwidget.cpp
blobddbc3b593b4a5c500da539e17f976f0093bfaef7
1 /*
2 This file is part of KAddressBook.
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
22 #include "quicksearchwidget.h"
24 #include <QLineEdit>
25 #include <KLocalizedString>
27 #include <QTimer>
28 #include <QKeyEvent>
29 #include <QVBoxLayout>
31 QuickSearchWidget::QuickSearchWidget(QWidget *parent)
32 : QWidget(parent)
34 QVBoxLayout *layout = new QVBoxLayout(this);
35 layout->setMargin(0);
37 mEdit = new QLineEdit;
38 //If change shortcut changes it in mainwidget
39 mEdit->setClearButtonEnabled(true);
40 mEdit->setToolTip(
41 i18nc("@info:tooltip", "Search contacts in list"));
42 mEdit->setWhatsThis(
43 i18nc("@info:whatsthis",
44 "Start typing a search string in this box and the list of contacts "
45 "matching that string will be displayed. This is a quick way of searching "
46 "for contacts of interest."));
47 mEdit->installEventFilter(this);
49 layout->addWidget(mEdit);
51 mTimer = new QTimer(this);
53 connect(mEdit, &QLineEdit::textChanged, this, &QuickSearchWidget::resetTimer);
54 connect(mTimer, &QTimer::timeout, this, &QuickSearchWidget::delayedTextChanged);
57 QuickSearchWidget::~QuickSearchWidget()
61 QSize QuickSearchWidget::sizeHint() const
63 const QSize size = mEdit->sizeHint();
64 return QSize(200, size.height());
67 void QuickSearchWidget::slotFocusQuickSearch()
69 mEdit->setFocus();
72 void QuickSearchWidget::resetTimer()
74 mTimer->stop();
75 mTimer->start(500);
78 void QuickSearchWidget::delayedTextChanged()
80 mTimer->stop();
81 Q_EMIT filterStringChanged(mEdit->text());
84 void QuickSearchWidget::keyPressEvent(QKeyEvent *event)
86 if (event->key() == Qt::Key_Down) {
87 event->accept();
88 delayedTextChanged();
89 Q_EMIT arrowDownKeyPressed();
90 return;
93 QWidget::keyPressEvent(event);
96 void QuickSearchWidget::updateQuickSearchText(const QString &text)
98 mEdit->setPlaceholderText(text);