1
/***************************************************************************
2
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3
* Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19
***************************************************************************/
20
#include "filterbar.h"
22
#include <QtGui/QBoxLayout>
23
#include <QtGui/QKeyEvent>
24
#include <QtGui/QLabel>
25
#include <QtGui/QToolButton>
29
#include <klineedit.h>
30
#include <kiconloader.h>
32
FilterBar::FilterBar(QWidget* parent) :
35
QHBoxLayout* hLayout = new QHBoxLayout(this);
36
hLayout->setMargin(0);
38
m_close = new QToolButton(this);
39
m_close->setAutoRaise(true);
40
m_close->setIcon(KIcon("dialog-close"));
41
m_close->setToolTip(i18nc("@info:tooltip", "Hide Filter Bar"));
42
hLayout->addWidget(m_close);
43
hLayout->addSpacing(KDialog::spacingHint());
45
m_filter = new QLabel(i18nc("@label:textbox", "Filter:"), this);
46
hLayout->addWidget(m_filter);
48
m_filterInput = new KLineEdit(this);
49
m_filterInput->setLayoutDirection(Qt::LeftToRight);
50
m_filterInput->setClearButtonShown(true);
51
m_filter->setBuddy(m_filterInput);
52
hLayout->addWidget(m_filterInput);
54
connect(m_filterInput, SIGNAL(textChanged(const QString&)),
55
this, SIGNAL(filterChanged(const QString&)));
56
connect(m_close, SIGNAL(clicked()), this, SIGNAL(closeRequest()));
59
FilterBar::~FilterBar()
63
void FilterBar::clear()
65
m_filterInput->clear();
68
void FilterBar::showEvent(QShowEvent* event)
70
if (!event->spontaneous()) {
71
m_filterInput->setFocus();
75
void FilterBar::keyReleaseEvent(QKeyEvent* event)
77
QWidget::keyReleaseEvent(event);
78
if ((event->key() == Qt::Key_Escape)) {
79
if (m_filterInput->text().isEmpty()) {
82
m_filterInput->clear();
87
#include "filterbar.moc"