]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsearchbox.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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"
22 #include <kglobalsettings.h>
23 #include <klineedit.h>
26 #include <kiconloader.h>
30 #include <QHBoxLayout>
31 #include <QToolButton>
33 DolphinSearchBox::DolphinSearchBox(QWidget
* parent
) :
38 QHBoxLayout
* hLayout
= new QHBoxLayout(this);
39 hLayout
->setMargin(0);
40 hLayout
->setSpacing(0);
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()));
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()));
59 DolphinSearchBox::~DolphinSearchBox()
63 bool DolphinSearchBox::event(QEvent
* event
)
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();
72 return QWidget::event(event
);
75 void DolphinSearchBox::emitSearchSignal()
77 emit
search(KUrl("nepomuksearch:/" + m_searchInput
->text()));
80 #include "dolphinsearchbox.moc"