kdeui Library API Documentation

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., 59 Temple Place - Suite 330,
00021     Boston, MA 02111-1307, USA.
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 /*= QMainWindow::Top*/, 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 
00205     int insertButton(const QString& icon, int id, bool enabled = true,
00206              const QString& text = QString::null, int index=-1,
00207              KInstance *_instance = KGlobal::instance());
00208 
00226     int insertButton(const QString& icon, int id, const char *signal,
00227              const QObject *receiver, const char *slot,
00228              bool enabled = true, const QString& text = QString::null,
00229              int index=-1, KInstance *_instance = KGlobal::instance() );
00230 
00255     int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
00256              const QString& text = QString::null, int index=-1 );
00257 
00275     int insertButton(const QPixmap& pixmap, int id, const char *signal,
00276              const QObject *receiver, const char *slot,
00277              bool enabled = true, const QString& text = QString::null,
00278              int index=-1 );
00279 
00292     int insertButton(const QString& icon, int id, QPopupMenu *popup,
00293              bool enabled, const QString&_text, int index=-1);
00294 
00307     int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
00308              bool enabled, const QString&_text, int index=-1);
00309 
00322     int insertLined (const QString& text, int id,
00323              const char *signal,
00324              const QObject *receiver, const char *slot,
00325              bool enabled = true,
00326              const QString& toolTipText = QString::null,
00327              int size = 70, int index =-1);
00328 
00343     int insertCombo (const QStringList &list, int id, bool writable,
00344              const char *signal, const QObject *receiver,
00345              const char *slot, bool enabled=true,
00346              const QString& tooltiptext=QString::null,
00347              int size=70, int index=-1,
00348              QComboBox::Policy policy = QComboBox::AtBottom);
00349 
00359     int insertCombo (const QString& text, int id, bool writable,
00360              const char *signal, QObject *receiver,
00361              const char *slot, bool enabled=true,
00362              const QString& tooltiptext=QString::null,
00363              int size=70, int index=-1,
00364              QComboBox::Policy policy = QComboBox::AtBottom);
00365 
00370     int insertSeparator( int index = -1, int id = -1 );
00371 
00376     int insertLineSeparator( int index = -1, int id = -1 );
00377 
00388     int insertWidget(int id, int width, QWidget *_widget, int index=-1);
00389 
00406     int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
00407                  const QString& icons, int index = -1);
00408 
00417     KAnimWidget *animatedWidget( int id );
00418 
00425     void addConnection (int id, const char *signal,
00426                         const QObject *receiver, const char *slot);
00430     void setItemEnabled( int id, bool enabled );
00431 
00437     void setButtonIcon( int id, const QString& _icon );
00438 
00444     void setButtonPixmap( int id, const QPixmap& _pixmap );
00445 
00451     void setButtonIconSet( int id, const QIconSet& iconset );
00452 
00479     void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
00480 
00494     void setAutoRepeat (int id, bool flag=true);
00495 
00496 
00500     void setToggle (int id, bool flag = true);
00501 
00511     void toggleButton (int id);
00512 
00522     void setButton (int id, bool flag);
00523 
00529     bool isButtonOn (int id) const;
00530 
00536     void setLinedText (int id, const QString& text);
00537 
00542     QString getLinedText (int id) const;
00543 
00547     void insertComboItem (int id, const QString& text, int index);
00548 
00552     void insertComboList (int id, const QStringList &list, int index);
00553 
00557     void removeComboItem (int id, int index);
00558 
00562     void setCurrentComboItem (int id, int index);
00563 
00569     void changeComboItem  (int id, const QString& text, int index=-1);
00570 
00576     void clearCombo (int id);
00577 
00585     QString getComboItem (int id, int index=-1) const;
00586 
00598     KComboBox * getCombo(int id);
00599 
00612     KLineEdit * getLined (int id);
00613 
00626     KToolBarButton * getButton (int id);
00627 
00634     void alignItemRight (int id, bool right = true);
00635 
00647     QWidget *getWidget (int id); // ### KDE4: make this const!
00648 
00662     void setItemAutoSized (int id, bool yes = true);
00663 
00669     void clear ();
00670 
00676     void removeItem (int id);
00677 
00683     void removeItemDelayed (int id);
00684 
00688     void hideItem (int id);
00689 
00693     void showItem (int id);
00694 
00700     int itemIndex (int id); // ### KDE4: make this const!
00701 
00706     int idAt(int index); // ### KDE4: make this const!
00707 
00720     void setFullSize(bool flag = true);
00721 
00726     bool fullSize() const;
00727 
00732     void enableMoving(bool flag = true) KDE_DEPRECATED;
00733 
00738     void setBarPos (BarPosition bpos);
00739 
00744     BarPosition barPos() const;
00745 
00754     bool enable(BarStatus stat) KDE_DEPRECATED;
00755 
00760     void setMaxHeight (int h) KDE_DEPRECATED;  // Set max height for vertical toolbars
00761 
00768     int maxHeight() KDE_DEPRECATED;
00769 
00775     void setMaxWidth (int dw) KDE_DEPRECATED;
00776 
00783     int maxWidth() KDE_DEPRECATED;
00784 
00791     void setTitle (const QString& _title);
00792 
00797     void enableFloating (bool flag) KDE_DEPRECATED;
00798 
00810     void setIconText(IconText it);
00811    // Note: don't merge with the next one, it breaks Qt properties
00812 
00819     void setIconText(IconText it, bool update);
00820 
00825     IconText iconText() const;
00826 
00837     void setIconSize(int size);
00838     // Note: don't merge with the next one, it breaks Qt properties
00839 
00848     void setIconSize(int size, bool update);
00849 
00854     int iconSize() const;
00855 
00861     void setEnableContextMenu(bool enable = true);
00862 
00867     bool contextMenuEnabled() const;
00868 
00877     void setItemNoStyle(int id, bool no_style = true);
00878 
00879     void setFlat (bool flag);
00880 
00885     int count() const;
00886 
00892     void saveState(); // BIC: remove for KDE4? This doesn't appear to be used internally,
00893                       // and apps use saveMainWindowSettings in KMainWindow anyway.
00894 
00898     void saveSettings(KConfig *config, const QString &configGroup);
00899 
00904     void applySettings(KConfig *config, const QString &configGroup);
00905 
00906   /*
00907    * Tell the toolbar what XML-GUI resource file it should use to save
00908    * it's state.  The state of the toolbar (position, size, etc) is
00909    * saved in KConfig files if the application does not use XML-GUI
00910    * but if the app does, then it's saved the XML file.  This function
00911    * allows this to happen.
00912    *
00913    * @param xmlfile The XML-GUI resource file to write to
00914    * @param xml     The DOM document for the XML-GUI building
00915    * @internal
00916    */
00917   //  void setXML(const QString& xmlfile, const QDomDocument& xml);
00918 
00919     void setXMLGUIClient( KXMLGUIClient *client );
00920 
00925     void setText( const QString & txt );
00926 
00931     QString text() const;
00932 
00933     void setStretchableWidget( QWidget *w );
00934     QSizePolicy sizePolicy() const;
00935     bool highlight() const;
00936     QSize sizeHint() const;
00937     QSize minimumSizeHint() const;
00938     QSize minimumSize() const;
00939 
00940     void hide();
00941     void show();
00942 
00943     void updateRects( bool = false ) {}
00944 
00945     void loadState( const QDomElement &e );
00946     void saveState( QDomElement &e );
00947 
00951     void positionYourself( bool force = false);
00952 
00953 signals:
00957     void clicked(int id);
00958 
00972     void doubleClicked (int id);
00973 
00977     void pressed(int);
00978 
00982     void released(int);
00983 
00993     void toggled(int);
00994 
01005     void highlighted(int id, bool isHighlighted);
01006 
01015     void highlighted(int id );
01016 
01026     void moved( BarPosition );
01027 
01035     void modechange ();
01036 
01044     void toolbarDestroyed();
01045 
01046 public:
01051     static bool highlightSetting();
01052 
01057     static bool transparentSetting();
01058 
01063     static IconText iconTextSetting();
01064 
01065 public slots:
01066     virtual void setIconText( const QString &txt )
01067     { QToolBar::setIconText( txt ); }
01068 
01069 protected:
01070     void mousePressEvent( QMouseEvent * );
01071     void childEvent( QChildEvent *e );
01072     void showEvent( QShowEvent *e );
01073     void resizeEvent( QResizeEvent *e );
01074     bool event( QEvent *e );
01075     void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
01076     QString settingsGroup() const;
01077 
01078 private slots:
01079     void rebuildLayout();
01080     void slotReadConfig ();
01081     void slotAppearanceChanged();
01082     void slotIconChanged(int);
01083     void slotRepaint();
01084     void toolBarPosChanged( QToolBar *tb );
01085     void slotContextAboutToShow();
01086     void slotContextAboutToHide();
01087     void widgetDestroyed();
01088 
01089 private:
01090     void init( bool readConfig = true, bool honorStyle = false );
01091     void doConnections( KToolBarButton *button );
01092     void insertWidgetInternal( QWidget *w, int &index, int id );
01093     void removeWidgetInternal( QWidget *w );
01094     void getAttributes( QString &position, QString &icontext, int &index );
01095     int dockWindowIndex();
01096     KPopupMenu *contextMenu();
01097 
01098     QMap<QWidget*, int > widget2id;
01099     typedef QMap<int, QWidget* > Id2WidgetMap;
01100     Id2WidgetMap id2widget;
01101     KPopupMenu *context;
01102     QPtrList<QWidget> widgets;
01103     QTimer *layoutTimer;
01104     QGuardedPtr<QWidget> stretchableWidget, rightAligned;
01105 protected:
01106     virtual void virtual_hook( int id, void* data );
01107 private:
01108     KToolBarPrivate *d;
01109 };
01110 
01111 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Jan 21 09:57:30 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003