Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ocombobox.h

Go to the documentation of this file.
00001 /*
00002   This file                  Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
00003     is part of the           Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
00004        Opie Project          Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org>
00005 
00006               =.             Originally part of the KDE projects
00007             .=l.
00008            .>+-=
00009  _;:,     .>    :=|.         This program is free software; you can
00010 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00011 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00012 .="- .-=="i,     .._         License as published by the Free Software
00013  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00014      ._= =}       :          or (at your option) any later version.
00015     .%`+i>       _;_.
00016     .i_,=:_.      -<s.       This program is distributed in the hope that
00017      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00018     : ..    .:,     . . .    without even the implied warranty of
00019     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00020   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00021 ..}^=.=       =       ;      Library General Public License for more
00022 ++=   -.     .`     .:       details.
00023  :     =  ...= . :.=-
00024  -.   .:....=;==+<;          You should have received a copy of the GNU
00025   -_. . .   )=.  =           Library General Public License along with
00026     --        :-=`           this library; see the file COPYING.LIB.
00027                              If not, write to the Free Software Foundation,
00028                              Inc., 59 Temple Place - Suite 330,
00029                              Boston, MA 02111-1307, USA.
00030 
00031 */
00032 
00033 #ifndef OCOMBOBOX_H
00034 #define OCOMBOBOX_H
00035 
00036 /* QT */
00037 
00038 #include <qcombobox.h>
00039 
00040 /* OPIE */
00041 
00042 #include <opie2/olineedit.h>
00043 #include <opie2/ocompletion.h>
00044 #include <opie2/ocompletionbase.h>
00045 
00046 /* FORWARDS */
00047 
00048 class QListBoxItem;
00049 class QPopupMenu;
00050 class OCompletionBox;
00051 typedef QString OURL;
00052 
00143 class OComboBox : public QComboBox, public OCompletionBase
00144 {
00145   Q_OBJECT
00146 
00147   //Q_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion )
00148   //Q_PROPERTY( bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled )
00149   //Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
00150 
00151 public:
00152 
00160     OComboBox( QWidget *parent=0, const char *name=0 );
00161 
00171     OComboBox( bool rw, QWidget *parent=0, const char *name=0 );
00172 
00176     virtual ~OComboBox();
00177 
00183     //void setEditURL( const OURL& url );
00184 
00190     //void insertURL( const OURL& url, int index = -1 );
00191 
00198     //void insertURL( const QPixmap& pixmap, const OURL& url, int index = -1 );
00199 
00205     //void changeURL( const OURL& url, int index );
00206 
00212     //void changeURL( const QPixmap& pixmap, const OURL& url, int index );
00213 
00222     int cursorPosition() const { return ( lineEdit() ) ? lineEdit()->cursorPosition() : -1; }
00223 
00234     virtual void setAutoCompletion( bool autocomplete );
00235 
00245     bool autoCompletion() const {
00246         return completionMode() == OGlobalSettings::CompletionAuto;
00247     }
00248 
00265     virtual void setContextMenuEnabled( bool showMenu );
00266 
00270     bool isContextMenuEnabled() const { return m_bEnableMenu; }
00271 
00279     //void setURLDropsEnabled( bool enable );
00280 
00284     //bool isURLDropsEnabled() const;
00285 
00295     bool contains( const QString& text ) const;
00296 
00311     void setTrapReturnKey( bool trap );
00312 
00319     bool trapReturnKey() const;
00320 
00326     virtual bool eventFilter( QObject *, QEvent * );
00327 
00337     OCompletionBox * completionBox( bool create = true );
00338 
00339     virtual void setLineEdit( OLineEdit * );
00340 
00341 signals:
00348     void returnPressed();
00349 
00362     void returnPressed( const QString& );
00363 
00375     void completion( const QString& );
00376 
00380     void substringCompletion( const QString& );
00381 
00394     void textRotation( OCompletionBase::KeyBindingType );
00395 
00400     void completionModeChanged( OGlobalSettings::Completion );
00401 
00414     void aboutToShowContextMenu( QPopupMenu * );
00415 
00416 public slots:
00417 
00435     void rotateText( OCompletionBase::KeyBindingType /* type */ );
00436 
00443     virtual void setCompletedText( const QString& );
00444 
00449     void setCompletedItems( const QStringList& items );
00450 
00451   public:
00457     void setCurrentItem( const QString& item, bool insert = false, int index = -1 );
00458     void setCurrentItem(int index);
00459 
00460 protected slots:
00461 
00465     virtual void itemSelected( QListBoxItem* ) {};
00466 
00478     virtual void makeCompletion( const QString& );
00479 
00480 protected:
00481     /*
00482     * This function simply sets the lineedit text and
00483     * highlights the text appropriately if the boolean
00484     * value is set to true.
00485     *
00486     * @param
00487     * @param
00488     */
00489     virtual void setCompletedText( const QString& /* */, bool /*marked*/ );
00490 
00494     virtual void create( WId = 0, bool initializeWindow = true,
00495                          bool destroyOldWindow = true );
00496 
00497 private:
00498     // Constants that represent the ID's of the popup menu.
00499     // TODO: See if we can replace this mess with OActionMenu
00500     // in the future though this is working lovely.
00501     enum MenuID {
00502         Default=0,
00503         Cut,
00504         Copy,
00505         Paste,
00506         Clear,
00507         Unselect,
00508         SelectAll,
00509         NoCompletion,
00510         AutoCompletion,
00511         ShellCompletion,
00512         PopupCompletion,
00513         SemiAutoCompletion
00514     };
00515 
00519     void init();
00524     void deleteWordBack();
00525     void deleteWordForward();
00526 
00527     bool m_bEnableMenu;
00528 
00529     // indicating if we should stop return-key events from propagating
00530     bool m_trapReturnKey;
00531 
00532 //protected:
00533 //    virtual void virtual_hook( int id, void* data );
00534 private:
00535     class OComboBoxPrivate;
00536     OComboBoxPrivate *d;
00537 };
00538 
00539 
00540 class OPixmapProvider;
00541 
00552 class OHistoryCombo : public OComboBox
00553 {
00554     Q_OBJECT
00555     Q_PROPERTY( QStringList historyItems READ historyItems WRITE setHistoryItems )
00556 
00557 public:
00577     OHistoryCombo( QWidget *parent = 0L, const char *name = 0L );
00578 
00579     // ### merge these two constructors
00586     OHistoryCombo( bool useCompletion,
00587                    QWidget *parent = 0L, const char *name = 0L );
00588 
00592     ~OHistoryCombo();
00593 
00600     inline void setHistoryItems( QStringList items ) {
00601         setHistoryItems(items, false);
00602     }
00603 
00645     void setHistoryItems( QStringList items, bool setCompletionList );
00646 
00653     QStringList historyItems() const;
00654 
00662     bool removeFromHistory( const QString& item );
00663 
00676     void setPixmapProvider( OPixmapProvider *prov );
00677 
00683     OPixmapProvider * pixmapProvider() const { return myPixProvider; }
00684 
00689     void reset() { slotReset(); }
00690 
00691 public slots:
00711     void addToHistory( const QString& item );
00712 
00716     void clearHistory();
00717 
00718 signals:
00722     void cleared();
00723 
00724 protected:
00728     virtual void keyPressEvent( QKeyEvent * );
00729 
00730 
00739     void insertItems( const QStringList& items );
00740 
00744     bool useCompletion() const { return compObj() != 0L; }
00745 
00746 private slots:
00750     void slotReset();
00751 
00756     void slotClear();
00757 
00761     void addContextMenuItems( QPopupMenu* );
00762 
00763 private:
00764     void init( bool useCompletion );
00765 
00769     int myIterateIndex;
00770 
00774     QString myText;
00775 
00780     bool myRotated;
00781     OPixmapProvider *myPixProvider;
00782 
00783 private:
00784     class OHistoryComboPrivate;
00785     OHistoryComboPrivate *d;
00786 };
00787 
00788 
00789 #endif
00790 

Generated on Sat Nov 5 16:16:29 2005 for OPIE by  doxygen 1.4.2