00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KTOOLBAR_H
00025 #define KTOOLBAR_H
00026
00027 #include <qtoolbar.h>
00028 #include <qmainwindow.h>
00029 #include <qcombobox.h>
00030 #include <qmap.h>
00031 #include <qptrlist.h>
00032 #include <kglobal.h>
00033 #include <qguardedptr.h>
00034 #include <qframe.h>
00035 #include <qiconset.h>
00036
00037 class QDomElement;
00038 class QSize;
00039 class QPixmap;
00040 class QPopupMenu;
00041 class QStringList;
00042 class QDomDocument;
00043 class QTimer;
00044
00045 class KLineEdit;
00046 class KToolBar;
00047 class KToolBarButton;
00048 class KToolBoxManager;
00049 class KAnimWidget;
00050 class KPopupMenu;
00051 class KInstance;
00052 class KComboBox;
00053 class KXMLGUIClient;
00054
00055 class KToolBarPrivate;
00056
00057 class KToolBarSeparator : public QFrame
00058 {
00059 Q_OBJECT
00060 public:
00061 KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 );
00062
00063 QSize sizeHint() const;
00064 Orientation orientation() const { return orient; }
00065 QSizePolicy sizePolicy() const;
00066 bool showLine() const { return line; }
00067 public slots:
00068 void setOrientation( Orientation );
00069 protected:
00070 void styleChange( QStyle& );
00071 void drawContents( QPainter* );
00072 private:
00073 Orientation orient;
00074 bool line;
00075 };
00076
00077
00103 class KToolBar : public QToolBar
00104 {
00105 Q_OBJECT
00106 Q_ENUMS( IconText BarPosition )
00107 Q_PROPERTY( IconText iconText READ iconText WRITE setIconText )
00108 Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos )
00109 Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize )
00110 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
00111 Q_PROPERTY( QString text READ text WRITE setText )
00112
00113 public:
00114 enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom};
00119 enum BarStatus{Toggle, Show, Hide};
00123 enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat};
00124
00142 KToolBar( QWidget *parent, const char *name = 0, bool honorStyle = false, bool readConfig = true );
00143
00159 KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock , bool newLine = false,
00160 const char *name = 0, bool honorStyle = false, bool readConfig = true );
00161
00177 KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false,
00178 const char *name = 0, bool honorStyle = false, bool readConfig = true );
00179
00183 virtual ~KToolBar();
00184
00206 int insertButton(const QString& icon, int id, bool enabled = true,
00207 const QString& text = QString::null, int index=-1,
00208 KInstance *_instance = KGlobal::instance());
00209
00228 int insertButton(const QString& icon, int id, const char *signal,
00229 const QObject *receiver, const char *slot,
00230 bool enabled = true, const QString& text = QString::null,
00231 int index=-1, KInstance *_instance = KGlobal::instance() );
00232
00257 int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
00258 const QString& text = QString::null, int index=-1 );
00259
00277 int insertButton(const QPixmap& pixmap, int id, const char *signal,
00278 const QObject *receiver, const char *slot,
00279 bool enabled = true, const QString& text = QString::null,
00280 int index=-1 );
00281
00294 int insertButton(const QString& icon, int id, QPopupMenu *popup,
00295 bool enabled, const QString&_text, int index=-1);
00296
00309 int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
00310 bool enabled, const QString&_text, int index=-1);
00311
00324 int insertLined (const QString& text, int id,
00325 const char *signal,
00326 const QObject *receiver, const char *slot,
00327 bool enabled = true,
00328 const QString& toolTipText = QString::null,
00329 int size = 70, int index =-1);
00330
00345 int insertCombo (const QStringList &list, int id, bool writable,
00346 const char *signal, const QObject *receiver,
00347 const char *slot, bool enabled=true,
00348 const QString& tooltiptext=QString::null,
00349 int size=70, int index=-1,
00350 QComboBox::Policy policy = QComboBox::AtBottom);
00351
00361 int insertCombo (const QString& text, int id, bool writable,
00362 const char *signal, QObject *receiver,
00363 const char *slot, bool enabled=true,
00364 const QString& tooltiptext=QString::null,
00365 int size=70, int index=-1,
00366 QComboBox::Policy policy = QComboBox::AtBottom);
00367
00372 int insertSeparator( int index = -1, int id = -1 );
00373
00378 int insertLineSeparator( int index = -1, int id = -1 );
00379
00390 int insertWidget(int id, int width, QWidget *_widget, int index=-1);
00391
00408 int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
00409 const QString& icons, int index = -1);
00410
00419 KAnimWidget *animatedWidget( int id );
00420
00427 void addConnection (int id, const char *signal,
00428 const QObject *receiver, const char *slot);
00432 void setItemEnabled( int id, bool enabled );
00433
00439 void setButtonIcon( int id, const QString& _icon );
00440
00446 void setButtonPixmap( int id, const QPixmap& _pixmap );
00447
00453 void setButtonIconSet( int id, const QIconSet& iconset );
00454
00481 void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
00482
00496 void setAutoRepeat (int id, bool flag=true);
00497
00498
00502 void setToggle (int id, bool flag = true);
00503
00513 void toggleButton (int id);
00514
00524 void setButton (int id, bool flag);
00525
00531 bool isButtonOn (int id) const;
00532
00538 void setLinedText (int id, const QString& text);
00539
00544 QString getLinedText (int id) const;
00545
00549 void insertComboItem (int id, const QString& text, int index);
00550
00554 void insertComboList (int id, const QStringList &list, int index);
00555
00559 void removeComboItem (int id, int index);
00560
00564 void setCurrentComboItem (int id, int index);
00565
00571 void changeComboItem (int id, const QString& text, int index=-1);
00572
00578 void clearCombo (int id);
00579
00587 QString getComboItem (int id, int index=-1) const;
00588
00600 KComboBox * getCombo(int id);
00601
00614 KLineEdit * getLined (int id);
00615
00628 KToolBarButton * getButton (int id);
00629
00636 void alignItemRight (int id, bool right = true);
00637
00649 QWidget *getWidget (int id);
00650
00664 void setItemAutoSized (int id, bool yes = true);
00665
00671 void clear ();
00672
00678 void removeItem (int id);
00679
00685 void removeItemDelayed (int id);
00686
00690 void hideItem (int id);
00691
00695 void showItem (int id);
00696
00702 int itemIndex (int id);
00703
00708 int idAt(int index);
00709
00722 void setFullSize(bool flag = true);
00723
00728 bool fullSize() const;
00729
00734 void enableMoving(bool flag = true) KDE_DEPRECATED;
00735
00740 void setBarPos (BarPosition bpos);
00741
00746 BarPosition barPos() const;
00747
00756 bool enable(BarStatus stat) KDE_DEPRECATED;
00757
00762 void setMaxHeight (int h) KDE_DEPRECATED;
00763
00770 int maxHeight() KDE_DEPRECATED;
00771
00777 void setMaxWidth (int dw) KDE_DEPRECATED;
00778
00785 int maxWidth() KDE_DEPRECATED;
00786
00793 void setTitle (const QString& _title);
00794
00799 void enableFloating (bool flag) KDE_DEPRECATED;
00800
00812 void setIconText(IconText it);
00813
00814
00821 void setIconText(IconText it, bool update);
00822
00827 IconText iconText() const;
00828
00839 void setIconSize(int size);
00840
00841
00850 void setIconSize(int size, bool update);
00851
00856 int iconSize() const;
00857
00863 void setEnableContextMenu(bool enable = true);
00864
00869 bool contextMenuEnabled() const;
00870
00879 void setItemNoStyle(int id, bool no_style = true);
00880
00881 void setFlat (bool flag);
00882
00887 int count() const;
00888
00894 void saveState();
00895
00896
00900 void saveSettings(KConfig *config, const QString &configGroup);
00901
00906 void applySettings(KConfig *config, const QString &configGroup,bool force);
00907
00908 void applySettings(KConfig *config, const QString &configGroup);
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923 void setXMLGUIClient( KXMLGUIClient *client );
00924
00929 void setText( const QString & txt );
00930
00935 QString text() const;
00936
00937 void setStretchableWidget( QWidget *w );
00938 QSizePolicy sizePolicy() const;
00939 bool highlight() const;
00940 QSize sizeHint() const;
00941 QSize minimumSizeHint() const;
00942 QSize minimumSize() const;
00943
00944 void hide();
00945 void show();
00946
00947 void updateRects( bool = false ) {}
00948
00949 void loadState( const QDomElement &e );
00950 void saveState( QDomElement &e );
00951
00955 void positionYourself( bool force = false);
00956
00957 signals:
00961 void clicked(int id);
00962
00976 void doubleClicked (int id);
00977
00981 void pressed(int);
00982
00986 void released(int);
00987
00997 void toggled(int);
00998
01009 void highlighted(int id, bool isHighlighted);
01010
01019 void highlighted(int id );
01020
01030 void moved( BarPosition );
01031
01039 void modechange ();
01040
01048 void toolbarDestroyed();
01049
01050 public:
01055 static bool highlightSetting();
01056
01061 static bool transparentSetting();
01062
01067 static IconText iconTextSetting();
01068
01069 public slots:
01070 virtual void setIconText( const QString &txt )
01071 { QToolBar::setIconText( txt ); }
01072
01073 protected:
01074 void mousePressEvent( QMouseEvent * );
01075 void childEvent( QChildEvent *e );
01076 void showEvent( QShowEvent *e );
01077 void resizeEvent( QResizeEvent *e );
01078 bool event( QEvent *e );
01079 void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
01080 QString settingsGroup() const;
01081
01082 private slots:
01083 void rebuildLayout();
01084 void slotReadConfig ();
01085 void slotAppearanceChanged();
01086 void slotIconChanged(int);
01087 void slotRepaint();
01088 void toolBarPosChanged( QToolBar *tb );
01089 void slotContextAboutToShow();
01090 void slotContextAboutToHide();
01091 void widgetDestroyed();
01092
01093 private:
01094 void init( bool readConfig = true, bool honorStyle = false );
01095 void doConnections( KToolBarButton *button );
01096 void insertWidgetInternal( QWidget *w, int &index, int id );
01097 void removeWidgetInternal( QWidget *w );
01098 void getAttributes( QString &position, QString &icontext, int &index );
01099 int dockWindowIndex();
01100 KPopupMenu *contextMenu();
01101 void doModeChange();
01102
01103 QMap<QWidget*, int > widget2id;
01104 typedef QMap<int, QWidget* > Id2WidgetMap;
01105 Id2WidgetMap id2widget;
01106 KPopupMenu *context;
01107 QPtrList<QWidget> widgets;
01108 QTimer *layoutTimer;
01109 QGuardedPtr<QWidget> stretchableWidget, rightAligned;
01110 protected:
01111 virtual void virtual_hook( int id, void* data );
01112 private:
01113 KToolBarPrivate *d;
01114 };
01115
01116 #endif