00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef OCOMBOBOX_H
00034 #define OCOMBOBOX_H
00035
00036
00037
00038 #include <qcombobox.h>
00039
00040
00041
00042 #include <opie2/olineedit.h>
00043 #include <opie2/ocompletion.h>
00044 #include <opie2/ocompletionbase.h>
00045
00046
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
00148
00149
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
00184
00190
00191
00198
00199
00205
00206
00212
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
00280
00284
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 );
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
00483
00484
00485
00486
00487
00488
00489 virtual void setCompletedText( const QString& , bool );
00490
00494 virtual void create( WId = 0, bool initializeWindow = true,
00495 bool destroyOldWindow = true );
00496
00497 private:
00498
00499
00500
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
00530 bool m_trapReturnKey;
00531
00532
00533
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
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