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
22 #include "quicksearchwidget.h"
25 #include <KLocalizedString>
29 #include <QVBoxLayout>
31 QuickSearchWidget::QuickSearchWidget(QWidget
*parent
)
34 QVBoxLayout
*layout
= new QVBoxLayout(this);
37 mEdit
= new QLineEdit
;
38 //If change shortcut changes it in mainwidget
39 mEdit
->setClearButtonEnabled(true);
41 i18nc("@info:tooltip", "Search contacts in list"));
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()
72 void QuickSearchWidget::resetTimer()
78 void QuickSearchWidget::delayedTextChanged()
81 Q_EMIT
filterStringChanged(mEdit
->text());
84 void QuickSearchWidget::keyPressEvent(QKeyEvent
*event
)
86 if (event
->key() == Qt::Key_Down
) {
89 Q_EMIT
arrowDownKeyPressed();
93 QWidget::keyPressEvent(event
);
96 void QuickSearchWidget::updateQuickSearchText(const QString
&text
)
98 mEdit
->setPlaceholderText(text
);