00001 /* -*- c++ -*- (for Emacs) 00002 * 00003 * searchwidget.h 00004 * Digest 00005 * 00006 * Created by Aidan Lane on Thu Aug 04 2005. 00007 * Copyright (c) 2005-2006 Optimisation and Constraint Solving Group, 00008 * Monash University. All rights reserved. 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 00025 #ifndef SEARCHWIDGET_H 00026 #define SEARCHWIDGET_H 00027 00028 00029 #include <QWidget> 00030 00031 #include <QFlags> 00032 #include <QPixmap> 00033 00034 class QLineEdit; 00035 class QMenu; 00036 00037 class SimpleIconToolButton; 00038 00039 00040 class SearchWidget : public QWidget { 00041 00042 Q_OBJECT 00043 00044 public: 00045 enum SearchTrigger { 00046 NoTriggers = 0x0, 00047 OnReturnPressed = 0x1, 00048 OnTextEdited = 0x2, 00049 OnMenuActionTriggered = 0x4, 00050 AllTriggers = OnReturnPressed | OnTextEdited | OnMenuActionTriggered 00051 }; 00052 Q_DECLARE_FLAGS( SearchTriggers, SearchTrigger ); // typesafe flags 00053 00054 SearchWidget( QWidget* parent = 0 ); 00055 00056 QMenu* menu() const; 00057 void setMenu( QMenu* menu ); 00058 00059 SearchTriggers searchTriggers() const; 00060 void setSearchTriggers( SearchTriggers triggers ); 00061 00062 00063 signals: 00064 void beginSearch( const QString& text ); 00065 void endSearch(); 00066 00067 00068 public slots: 00069 virtual void search(); 00070 virtual void clear(); 00071 virtual void setText( const QString& text, bool startSearch=true ); 00072 00073 00074 protected: 00075 virtual void paintEvent( QPaintEvent* ); 00076 00077 QLineEdit* lineEdit() const; 00078 SimpleIconToolButton* searchButton() const; 00079 SimpleIconToolButton* clearButton() const; 00080 00081 00082 private slots: 00083 void onReturnPressed(); 00084 void onTextEdited( const QString& text ); 00085 00086 00087 private: 00088 QLineEdit* m_lineEdit; 00089 SimpleIconToolButton* m_searchButton; 00090 SimpleIconToolButton* m_clearButton; 00091 SearchTriggers m_searchTriggers; 00092 00093 QPixmap m_leftCapPixmap; 00094 QPixmap m_middleTilePixmap; 00095 QPixmap m_rightCapPixmap; 00096 }; 00097 00098 Q_DECLARE_OPERATORS_FOR_FLAGS( SearchWidget::SearchTriggers ); 00099 00100 00101 #endif // ! SEARCHWIDGET_H
1.5.2