]> cloud.milkyroute.net Git - dolphin.git/blob - src/filterbar.cpp
Forwardport 773570:
[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 <QtGui/QBoxLayout>
23 #include <QtGui/QKeyEvent>
24 #include <QtGui/QLabel>
25 #include <QtGui/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 QHBoxLayout* hLayout = new QHBoxLayout(this);
40 hLayout->setMargin(0);
41 hLayout->addSpacing(gap);
42
43 m_filter = new QLabel(i18nc("@label:textbox", "Filter:"), this);
44 hLayout->addWidget(m_filter);
45 hLayout->addSpacing(KDialog::spacingHint());
46
47 m_filterInput = new KLineEdit(this);
48 m_filter->setBuddy(m_filterInput);
49 hLayout->addWidget(m_filterInput);
50
51 m_close = new QToolButton(this);
52 m_close->setAutoRaise(true);
53 m_close->setIcon(KIcon("dialog-close"));
54 m_close->setToolTip(i18nc("@info:tooltip", "Hide Filter Bar"));
55 hLayout->addWidget(m_close);
56 hLayout->addSpacing(gap);
57
58 connect(m_filterInput, SIGNAL(textChanged(const QString&)),
59 this, SIGNAL(filterChanged(const QString&)));
60 connect(m_close, SIGNAL(clicked()), this, SLOT(emitCloseRequest()));
61 }
62
63 FilterBar::~FilterBar()
64 {
65 }
66
67 void FilterBar::hideEvent(QHideEvent* event)
68 {
69 if (!event->spontaneous()) {
70 m_filterInput->clear();
71 m_filterInput->clearFocus();
72 }
73 }
74
75 void FilterBar::showEvent(QShowEvent* event)
76 {
77 if (!event->spontaneous()) {
78 m_filterInput->setFocus();
79 }
80 }
81
82 void FilterBar::keyReleaseEvent(QKeyEvent* event)
83 {
84 QWidget::keyReleaseEvent(event);
85 if ((event->key() == Qt::Key_Escape)) {
86 emitCloseRequest();
87 }
88 }
89
90 void FilterBar::emitCloseRequest()
91 {
92 emit closeRequest();
93 }
94
95 #include "filterbar.moc"