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 <qguardedptr.h>
00033 #include <qframe.h>
00034 #include <qiconset.h>
00035
00036 #include <kglobal.h>
00037
00038 class QDomElement;
00039 class QSize;
00040 class QPixmap;
00041 class QPopupMenu;
00042 class QStringList;
00043 class QDomDocument;
00044 class QTimer;
00045
00046 class KLineEdit;
00047 class KToolBar;
00048 class KToolBarButton;
00049 class KToolBoxManager;
00050 class KAnimWidget;
00051 class KPopupMenu;
00052 class KInstance;
00053 class KComboBox;
00054 class KXMLGUIClient;
00055
00056 class KToolBarPrivate;
00057
00058 class KDEUI_EXPORT KToolBarSeparator : public QFrame
00059 {
00060 Q_OBJECT
00061 public:
00062 KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 );
00063
00064 QSize sizeHint() const;
00065 Orientation orientation() const { return orient; }
00066 QSizePolicy sizePolicy() const;
00067 bool showLine() const { return line; }
00068 public slots:
00069 void setOrientation( Orientation );
00070 protected:
00071 void styleChange( QStyle& );
00072 void drawContents( QPainter* );
00073 private:
00074 Orientation orient;
00075 bool line;
00076 };
00077
00078
00103 class KDEUI_EXPORT 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
00862 int iconSizeDefault() const;
00863
00869 void setEnableContextMenu(bool enable = true);
00870
00875 bool contextMenuEnabled() const;
00876
00885 void setItemNoStyle(int id, bool no_style = true);
00886
00887 void setFlat (bool flag);
00888
00893 int count() const;
00894
00900 void saveState();
00901
00902
00906 void saveSettings(KConfig *config, const QString &configGroup);
00907
00912 void applySettings(KConfig *config, const QString &configGroup,bool force);
00913
00914 void applySettings(KConfig *config, const QString &configGroup);
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 void setXMLGUIClient( KXMLGUIClient *client );
00930
00935 void setText( const QString & txt );
00936
00941 QString text() const;
00942
00943 void setStretchableWidget( QWidget *w );
00944 QSizePolicy sizePolicy() const;
00945 bool highlight() const;
00946 QSize sizeHint() const;
00947 QSize minimumSizeHint() const;
00948 QSize minimumSize() const;
00949
00950 void hide();
00951 void show();
00952
00953 void updateRects( bool = false ) {}
00954
00958 void loadState( const QDomElement &e );
00959
00960
00961
00962 void saveState( QDomElement &e );
00963
00967 void positionYourself( bool force = false);
00968
00969 signals:
00973 void clicked(int id);
00974
00988 void doubleClicked (int id);
00989
00993 void pressed(int);
00994
00998 void released(int);
00999
01009 void toggled(int);
01010
01021 void highlighted(int id, bool isHighlighted);
01022
01031 void highlighted(int id );
01032
01042 void moved( BarPosition );
01043
01051 void modechange ();
01052
01060 void toolbarDestroyed();
01061
01062 public:
01067 static bool highlightSetting();
01068
01073 static bool transparentSetting();
01074
01079 static IconText iconTextSetting();
01080
01081 public slots:
01082 virtual void setIconText( const QString &txt )
01083 { QToolBar::setIconText( txt ); }
01084
01085 protected:
01086 void mousePressEvent( QMouseEvent * );
01087 void childEvent( QChildEvent *e );
01088 void showEvent( QShowEvent *e );
01089 void resizeEvent( QResizeEvent *e );
01090 bool event( QEvent *e );
01091 void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
01092 QString settingsGroup() const;
01093
01094 private slots:
01095 void rebuildLayout();
01096 void slotReadConfig ();
01097 void slotAppearanceChanged();
01098 void slotIconChanged(int);
01099 void slotRepaint();
01100 void toolBarPosChanged( QToolBar *tb );
01101 void slotContextAboutToShow();
01102 void slotContextAboutToHide();
01103 void widgetDestroyed();
01104
01105 private:
01106 void init( bool readConfig = true, bool honorStyle = false );
01107 void doConnections( KToolBarButton *button );
01108 void insertWidgetInternal( QWidget *w, int &index, int id );
01109 void removeWidgetInternal( QWidget *w );
01110 void getAttributes( QString &position, QString &icontext, int &index );
01111 int dockWindowIndex();
01112 KPopupMenu *contextMenu();
01113 void doModeChange();
01114
01115 QMap<QWidget*, int > widget2id;
01116 typedef QMap<int, QWidget* > Id2WidgetMap;
01117 Id2WidgetMap id2widget;
01118 KPopupMenu *context;
01119 QPtrList<QWidget> widgets;
01120 QTimer *layoutTimer;
01121 QGuardedPtr<QWidget> stretchableWidget, rightAligned;
01122 protected:
01123 virtual void virtual_hook( int id, void* data );
01124 private:
01125 KToolBarPrivate *d;
01126 };
01127
01128 #endif