]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsearchbox.cpp
show the actions of a revision control plugin in the context menu
[dolphin.git] / src / dolphinsearchbox.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19 #include "dolphinsearchbox.h"
20
21 #include <kdialog.h>
22 #include <kglobalsettings.h>
23 #include <klineedit.h>
24 #include <klocale.h>
25 #include <kicon.h>
26 #include <kiconloader.h>
27
28 #include <QEvent>
29 #include <QKeyEvent>
30 #include <QHBoxLayout>
31 #include <QToolButton>
32
33 DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
34 QWidget(parent),
35 m_searchInput(0),
36 m_searchButton(0)
37 {
38 QHBoxLayout* hLayout = new QHBoxLayout(this);
39 hLayout->setMargin(0);
40 hLayout->setSpacing(0);
41
42 m_searchInput = new KLineEdit(this);
43 m_searchInput->setClearButtonShown(true);
44 m_searchInput->setMinimumWidth(150);
45 m_searchInput->setClickMessage(i18nc("@label:textbox", "Search..."));
46 hLayout->addWidget(m_searchInput);
47 connect(m_searchInput, SIGNAL(returnPressed()),
48 this, SLOT(emitSearchSignal()));
49
50 m_searchButton = new QToolButton(this);
51 m_searchButton->setAutoRaise(true);
52 m_searchButton->setIcon(KIcon("edit-find"));
53 m_searchButton->setToolTip(i18nc("@info:tooltip", "Click to begin the search"));
54 hLayout->addWidget(m_searchButton);
55 connect(m_searchButton, SIGNAL(clicked()),
56 this, SLOT(emitSearchSignal()));
57 }
58
59 DolphinSearchBox::~DolphinSearchBox()
60 {
61 }
62
63 bool DolphinSearchBox::event(QEvent* event)
64 {
65 if (event->type() == QEvent::Polish) {
66 m_searchInput->setFont(KGlobalSettings::generalFont());
67 } else if (event->type() == QEvent::KeyPress) {
68 if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) {
69 m_searchInput->clear();
70 }
71 }
72 return QWidget::event(event);
73 }
74
75 void DolphinSearchBox::emitSearchSignal()
76 {
77 emit search(KUrl("nepomuksearch:/" + m_searchInput->text()));
78 }
79
80 #include "dolphinsearchbox.moc"