ktoolbar.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org) 00003 (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 00004 (C) 1997, 1998 Sven Radej (radej@kde.org) 00005 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 00006 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 00007 (C) 1999, 2000 Kurt Granroth (granroth@kde.org) 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License version 2 as published by the Free Software Foundation. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef KTOOLBAR_H 00025 #define KTOOLBAR_H 00026 00027 #include <tqtoolbar.h> 00028 #include <tqmainwindow.h> 00029 #include <tqcombobox.h> 00030 #include <tqmap.h> 00031 #include <tqptrlist.h> 00032 #include <tqguardedptr.h> 00033 #include <tqframe.h> 00034 #include <tqiconset.h> 00035 00036 #include <kglobal.h> 00037 00038 class TQDomElement; 00039 class TQSize; 00040 class TQPixmap; 00041 class TQPopupMenu; 00042 class TQStringList; 00043 class TQDomDocument; 00044 class TQTimer; 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 TQFrame 00059 { 00060 Q_OBJECT 00061 TQ_OBJECT 00062 public: 00063 KToolBarSeparator( Orientation, bool l, TQToolBar *parent, const char* name=0 ); 00064 00065 TQSize sizeHint() const; 00066 Orientation orientation() const { return orient; } 00067 TQSizePolicy sizePolicy() const; 00068 bool showLine() const { return line; } 00069 public slots: 00070 void setOrientation( Orientation ); 00071 protected: 00072 void styleChange( TQStyle& ); 00073 void drawContents( TQPainter* ); 00074 private: 00075 Orientation orient; 00076 bool line; 00077 }; 00078 00079 00104 class KDEUI_EXPORT KToolBar : public TQToolBar 00105 { 00106 Q_OBJECT 00107 TQ_OBJECT 00108 Q_ENUMS( IconText BarPosition ) 00109 Q_PROPERTY( IconText iconText READ iconText WRITE setIconText ) 00110 Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos ) 00111 Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize ) 00112 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize ) 00113 Q_PROPERTY( TQString text READ text WRITE setText ) 00114 00115 public: 00116 enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom}; 00121 enum BarStatus{Toggle, Show, Hide}; 00125 enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat}; 00126 00144 KToolBar( TQWidget *parent, const char *name = 0, bool honorStyle = false, bool readConfig = true ); 00145 00161 KToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock /*= TQMainWindow::Top*/, bool newLine = false, 00162 const char *name = 0, bool honorStyle = false, bool readConfig = true ); 00163 00179 KToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine = false, 00180 const char *name = 0, bool honorStyle = false, bool readConfig = true ); 00181 00185 virtual ~KToolBar(); 00186 00208 int insertButton(const TQString& icon, int id, bool enabled = true, 00209 const TQString& text = TQString::null, int index=-1, 00210 KInstance *_instance = KGlobal::instance()); 00211 00230 int insertButton(const TQString& icon, int id, const char *signal, 00231 const TQObject *receiver, const char *slot, 00232 bool enabled = true, const TQString& text = TQString::null, 00233 int index=-1, KInstance *_instance = KGlobal::instance() ); 00234 00259 int insertButton(const TQPixmap& pixmap, int id, bool enabled = true, 00260 const TQString& text = TQString::null, int index=-1 ); 00261 00279 int insertButton(const TQPixmap& pixmap, int id, const char *signal, 00280 const TQObject *receiver, const char *slot, 00281 bool enabled = true, const TQString& text = TQString::null, 00282 int index=-1 ); 00283 00296 int insertButton(const TQString& icon, int id, TQPopupMenu *popup, 00297 bool enabled, const TQString&_text, int index=-1); 00298 00311 int insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup, 00312 bool enabled, const TQString&_text, int index=-1); 00313 00326 int insertLined (const TQString& text, int id, 00327 const char *signal, 00328 const TQObject *receiver, const char *slot, 00329 bool enabled = true, 00330 const TQString& toolTipText = TQString::null, 00331 int size = 70, int index =-1); 00332 00347 int insertCombo (const TQStringList &list, int id, bool writable, 00348 const char *signal, const TQObject *receiver, 00349 const char *slot, bool enabled=true, 00350 const TQString& tooltiptext=TQString::null, 00351 int size=70, int index=-1, 00352 TQComboBox::Policy policy = TQComboBox::AtBottom); 00353 00363 int insertCombo (const TQString& text, int id, bool writable, 00364 const char *signal, TQObject *receiver, 00365 const char *slot, bool enabled=true, 00366 const TQString& tooltiptext=TQString::null, 00367 int size=70, int index=-1, 00368 TQComboBox::Policy policy = TQComboBox::AtBottom); 00369 00374 int insertSeparator( int index = -1, int id = -1 ); 00375 00380 int insertLineSeparator( int index = -1, int id = -1 ); 00381 00392 int insertWidget(int id, int width, TQWidget *_widget, int index=-1); 00393 00410 int insertAnimatedWidget(int id, TQObject *receiver, const char *slot, 00411 const TQString& icons, int index = -1); 00412 00421 KAnimWidget *animatedWidget( int id ); 00422 00429 void addConnection (int id, const char *signal, 00430 const TQObject *receiver, const char *slot); 00434 void setItemEnabled( int id, bool enabled ); 00435 00441 void setButtonIcon( int id, const TQString& _icon ); 00442 00448 void setButtonPixmap( int id, const TQPixmap& _pixmap ); 00449 00455 void setButtonIconSet( int id, const TQIconSet& iconset ); 00456 00483 void setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle = false); 00484 00498 void setAutoRepeat (int id, bool flag=true); 00499 00500 00504 void setToggle (int id, bool flag = true); 00505 00515 void toggleButton (int id); 00516 00526 void setButton (int id, bool flag); 00527 00533 bool isButtonOn (int id) const; 00534 00540 void setLinedText (int id, const TQString& text); 00541 00546 TQString getLinedText (int id) const; 00547 00551 void insertComboItem (int id, const TQString& text, int index); 00552 00556 void insertComboList (int id, const TQStringList &list, int index); 00557 00561 void removeComboItem (int id, int index); 00562 00566 void setCurrentComboItem (int id, int index); 00567 00573 void changeComboItem (int id, const TQString& text, int index=-1); 00574 00580 void clearCombo (int id); 00581 00589 TQString getComboItem (int id, int index=-1) const; 00590 00602 KComboBox * getCombo(int id); 00603 00616 KLineEdit * getLined (int id); 00617 00630 KToolBarButton * getButton (int id); 00631 00638 void alignItemRight (int id, bool right = true); 00639 00651 TQWidget *getWidget (int id); // ### KDE4: make this const! 00652 00666 void setItemAutoSized (int id, bool yes = true); 00667 00673 void clear (); 00674 00680 void removeItem (int id); 00681 00687 void removeItemDelayed (int id); 00688 00692 void hideItem (int id); 00693 00697 void showItem (int id); 00698 00704 int itemIndex (int id); // ### KDE4: make this const! 00705 00710 int idAt(int index); // ### KDE4: make this const! 00711 00724 void setFullSize(bool flag = true); 00725 00730 bool fullSize() const; 00731 00736 void enableMoving(bool flag = true) KDE_DEPRECATED; 00737 00742 void setBarPos (BarPosition bpos); 00743 00748 BarPosition barPos() const; 00749 00758 bool enable(BarStatus stat) KDE_DEPRECATED; 00759 00764 void setMaxHeight (int h) KDE_DEPRECATED; // Set max height for vertical toolbars 00765 00772 int maxHeight() KDE_DEPRECATED; 00773 00779 void setMaxWidth (int dw) KDE_DEPRECATED; 00780 00787 int maxWidth() KDE_DEPRECATED; 00788 00795 void setTitle (const TQString& _title); 00796 00801 void enableFloating (bool flag) KDE_DEPRECATED; 00802 00814 void setIconText(IconText it); 00815 // Note: don't merge with the next one, it breaks Qt properties 00816 00823 void setIconText(IconText it, bool update); 00824 00829 IconText iconText() const; 00830 00841 void setIconSize(int size); 00842 // Note: don't merge with the next one, it breaks Qt properties 00843 00852 void setIconSize(int size, bool update); 00853 00858 int iconSize() const; 00859 00864 int iconSizeDefault() const; 00865 00871 void setEnableContextMenu(bool enable = true); 00872 00877 bool contextMenuEnabled() const; 00878 00887 void setItemNoStyle(int id, bool no_style = true); 00888 00889 void setFlat (bool flag); 00890 00895 int count() const; 00896 00902 void saveState(); // BIC: remove for KDE4? This doesn't appear to be used internally, 00903 // and apps use saveMainWindowSettings in KMainWindow anyway. 00904 00908 void saveSettings(KConfig *config, const TQString &configGroup); 00909 00914 void applySettings(KConfig *config, const TQString &configGroup,bool force); 00915 // KDE4 merge with force=false 00916 void applySettings(KConfig *config, const TQString &configGroup); 00917 00918 /* 00919 * Tell the toolbar what XML-GUI resource file it should use to save 00920 * it's state. The state of the toolbar (position, size, etc) is 00921 * saved in KConfig files if the application does not use XML-GUI 00922 * but if the app does, then it's saved the XML file. This function 00923 * allows this to happen. 00924 * 00925 * @param xmlfile The XML-GUI resource file to write to 00926 * @param xml The DOM document for the XML-GUI building 00927 * @internal 00928 */ 00929 // void setXML(const TQString& xmlfile, const TQDomDocument& xml); 00930 00931 void setXMLGUIClient( KXMLGUIClient *client ); 00932 00937 void setText( const TQString & txt ); 00938 00943 TQString text() const; 00944 00945 void setStretchableWidget( TQWidget *w ); 00946 TQSizePolicy sizePolicy() const; 00947 bool highlight() const; 00948 TQSize sizeHint() const; 00949 TQSize minimumSizeHint() const; 00950 TQSize minimumSize() const; 00951 00952 void hide(); 00953 void show(); 00954 00955 void updateRects( bool = false ) {} 00956 00960 void loadState( const TQDomElement &e ); 00961 /* 00962 * Save state into an XML element, called by KXMLGUIBuilder 00963 */ 00964 void saveState( TQDomElement &e ); 00965 00969 void positionYourself( bool force = false); 00970 00971 signals: 00975 void clicked(int id); 00976 00990 void doubleClicked (int id); 00991 00995 void pressed(int); 00996 01000 void released(int); 01001 01011 void toggled(int); 01012 01023 void highlighted(int id, bool isHighlighted); 01024 01033 void highlighted(int id ); 01034 01044 void moved( BarPosition ); 01045 01053 void modechange (); 01054 01062 void toolbarDestroyed(); 01063 01064 public: 01069 static bool highlightSetting(); 01070 01075 static bool transparentSetting(); 01076 01081 static IconText iconTextSetting(); 01082 01083 public slots: 01084 virtual void setIconText( const TQString &txt ) 01085 { TQToolBar::setIconText( txt ); } 01086 01087 protected: 01088 void mousePressEvent( TQMouseEvent * ); 01089 void childEvent( TQChildEvent *e ); 01090 void showEvent( TQShowEvent *e ); 01091 void resizeEvent( TQResizeEvent *e ); 01092 bool event( TQEvent *e ); 01093 void applyAppearanceSettings(KConfig *config, const TQString &_configGroup, bool forceGlobal = false); 01094 TQString settingsGroup() const; 01095 01096 private slots: 01097 void rebuildLayout(); 01098 void slotReadConfig (); 01099 void slotAppearanceChanged(); 01100 void slotIconChanged(int); 01101 void slotRepaint(); 01102 void toolBarPosChanged( TQToolBar *tb ); 01103 void slotContextAboutToShow(); 01104 void slotContextAboutToHide(); 01105 void widgetDestroyed(); 01106 01107 private: 01108 void init( bool readConfig = true, bool honorStyle = false ); 01109 void doConnections( KToolBarButton *button ); 01110 void insertWidgetInternal( TQWidget *w, int &index, int id ); 01111 void removeWidgetInternal( TQWidget *w ); 01112 void getAttributes( TQString &position, TQString &icontext, int &index ); 01113 int dockWindowIndex(); 01114 KPopupMenu *contextMenu(); 01115 void doModeChange(); 01116 01117 TQMap<TQWidget*, int > widget2id; 01118 typedef TQMap<int, TQWidget* > Id2WidgetMap; 01119 Id2WidgetMap id2widget; 01120 KPopupMenu *context; 01121 TQPtrList<TQWidget> widgets; 01122 TQTimer *layoutTimer; 01123 TQGuardedPtr<TQWidget> stretchableWidget, rightAligned; 01124 protected: 01125 virtual void virtual_hook( int id, void* data ); 01126 private: 01127 KToolBarPrivate *d; 01128 }; 01129 01130 #endif