• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

searchWidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Wilfried Huss                                   *
00003  *   Wilfried.Huss@gmx.at                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <config.h>
00022 
00023 #include <qlabel.h>
00024 #include <qpushbutton.h>
00025 #include <qcheckbox.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028 #include <qwhatsthis.h>
00029 
00030 #include <kdebug.h>
00031 #include <kiconloader.h>
00032 #include <kglobalsettings.h>
00033 #include <klocale.h>
00034 #include <klineedit.h>
00035 
00036 
00037 #include "searchWidget.h"
00038 
00039 SearchWidget::SearchWidget(QWidget* parent, const char* name, WFlags fl)
00040   : QWidget(parent, name, fl)
00041 {
00042   setName("SearchWidget");
00043 
00044   setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00045 
00046   layout = new QHBoxLayout(this, 4, 6, "SearchWidgetLayout");
00047 
00048   stopButton = new QPushButton(this, "stopButton");
00049   stopButton->setPixmap(KGlobal::iconLoader()->loadIcon("stop", KIcon::Small, KIcon::SizeSmall));
00050   layout->addWidget(stopButton);
00051 
00052   searchLabel = new QLabel(this, "searchLabel");
00053   searchLabel->setText(i18n("Search:"));
00054   layout->addWidget(searchLabel);
00055 
00056   searchText = new KLineEdit(this, "searchText");
00057   layout->addWidget(searchText);
00058 
00059   searchLabel->setBuddy(searchText);
00060 
00061   findPrevButton = new QPushButton(this, "findPrevButton");
00062   findPrevButton->setPixmap(KGlobal::iconLoader()->loadIcon("back", KIcon::NoGroup, KIcon::SizeSmall));
00063   QToolTip::add(findPrevButton, i18n("Find previous"));
00064   layout->addWidget(findPrevButton);
00065 
00066   findNextButton = new QPushButton(this, "findNextButton");
00067   findNextButton->setPixmap(KGlobal::iconLoader()->loadIcon("forward", KIcon::NoGroup, KIcon::SizeSmall));
00068   QToolTip::add(findNextButton, i18n("Find next"));
00069   layout->addWidget(findNextButton);
00070 
00071   caseSensitiveCheckBox = new QCheckBox(this, "caseSensitiveCheckBox");
00072   caseSensitiveCheckBox->setText(i18n("Case sensitive"));
00073   layout->addWidget(caseSensitiveCheckBox);
00074 
00075   connect(stopButton, SIGNAL(clicked()), this, SIGNAL(stopSearch()));
00076 
00077   connect(findNextButton, SIGNAL(clicked()), this, SIGNAL(findNextText()));
00078   connect(findPrevButton, SIGNAL(clicked()), this, SIGNAL(findPrevText()));
00079 
00080   connect(searchText, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged()));
00081 
00082   textChanged();
00083 }
00084 
00085 SearchWidget::~SearchWidget()
00086 {
00087 }
00088 
00089 QString SearchWidget::getText() const
00090 {
00091   return searchText->text();
00092 }
00093 
00094 bool SearchWidget::caseSensitive() const
00095 {
00096   return caseSensitiveCheckBox->isChecked();
00097 }
00098 
00099 void SearchWidget::textChanged()
00100 {
00101   bool empty = searchText->text().isEmpty();
00102 
00103   findNextButton->setDisabled(empty);
00104   findPrevButton->setDisabled(empty);
00105   emit searchEnabled(!empty);
00106 }
00107 
00108 void SearchWidget::show()
00109 {
00110   searchText->setEnabled(true);
00111   searchText->selectAll();
00112   QWidget::show();
00113   emit searchEnabled(!searchText->text().isEmpty());
00114 }
00115 
00116 void SearchWidget::hide()
00117 {
00118   searchText->setEnabled(false);
00119   QWidget::hide();
00120 }
00121 
00122 void SearchWidget::setFocus()
00123 {
00124   searchText->setFocus();
00125 }
00126 
00127 void SearchWidget::keyPressEvent(QKeyEvent* e)
00128 {
00129   if (e->key() == Qt::Key_Escape)
00130     emit stopSearch();
00131 
00132   if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)
00133   {
00134     if (e->state() == Qt::ShiftButton)
00135       emit findPrevText();
00136     else
00137       emit findNextText();
00138   }
00139 }
00140 
00141 #include "searchWidget.moc"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal