]> cloud.milkyroute.net Git - dolphin.git/blob - src/filterbar.cpp
f7c582262f85cbc1375bf16dbe5560d24c33bf94
[dolphin.git] / src / filterbar.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
4 * *
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. *
9 * *
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. *
14 * *
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"
21
22 #include <QBoxLayout>
23 #include <QKeyEvent>
24 #include <QLabel>
25 #include <QToolButton>
26
27 #include <kdialog.h>
28 #include <klocale.h>
29 #include <klineedit.h>
30 #include <kiconloader.h>
31
32 #include "dolphinmainwindow.h"
33
34 FilterBar::FilterBar(QWidget* parent) :
35 QWidget(parent)
36 {
37 const int gap = 3;
38
39 QVBoxLayout* vLayout = new QVBoxLayout(this);
40 vLayout->setMargin(0);
41 vLayout->addSpacing(gap);
42
43 QHBoxLayout* hLayout = new QHBoxLayout(vLayout);
44 hLayout->setMargin(0);
45 hLayout->addSpacing(gap);
46
47 m_filter = new QLabel(i18n("Filter:"), this);
48 hLayout->addWidget(m_filter);
49 hLayout->addSpacing(KDialog::spacingHint());
50
51 m_filterInput = new KLineEdit(this);
52 m_filter->setBuddy(m_filterInput);
53 hLayout->addWidget(m_filterInput);
54
55 m_close = new QToolButton(this);
56 m_close->setAutoRaise(true);
57 m_close->setIcon(KIcon("list-remove"));
58 m_close->setToolTip(i18n("Hide Filter Bar"));
59 hLayout->addWidget(m_close);
60 hLayout->addSpacing(gap);
61
62 connect(m_filterInput, SIGNAL(textChanged(const QString&)),
63 this, SIGNAL(filterChanged(const QString&)));
64 connect(m_close, SIGNAL(clicked()), this, SLOT(emitCloseRequest()));
65 }
66
67 FilterBar::~FilterBar()
68 {
69 }
70
71 void FilterBar::hideEvent(QHideEvent* event)
72 {
73 if (!event->spontaneous()) {
74 m_filterInput->clear();
75 m_filterInput->clearFocus();
76 }
77 }
78
79 void FilterBar::showEvent(QShowEvent* event)
80 {
81 if (!event->spontaneous()) {
82 m_filterInput->setFocus();
83 }
84 }
85
86 void FilterBar::keyReleaseEvent(QKeyEvent* event)
87 {
88 QWidget::keyReleaseEvent(event);
89 if ((event->key() == Qt::Key_Escape)) {
90 emitCloseRequest();
91 }
92 }
93
94 void FilterBar::emitCloseRequest()
95 {
96 emit closeRequest();
97 }
98
99 #include "filterbar.moc"