00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __ko_koolbar_h__
00022 #define __ko_koolbar_h__
00023
00024 #include <q3frame.h>
00025 #include <QPixmap>
00026 #include <q3intdict.h>
00027
00028 #include <QMouseEvent>
00029 #include <QResizeEvent>
00030 #include <koffice_export.h>
00031 class QPushButton;
00032 class QPixmap;
00033 class KoKoolBar;
00034 class KoKoolBarGroup;
00035
00036 class KoKoolBarItem : public QObject
00037 {
00038 private:
00039 Q_OBJECT
00040 public:
00041 KoKoolBarItem( KoKoolBarGroup *_grp, const QPixmap& _pix, const QString& _text = QString::null );
00042
00043 int id() const { return m_id; }
00044 void press();
00045 bool isEnabled() const { return m_bEnabled; }
00046 void setEnabled( bool _e ) { m_bEnabled = _e; }
00047
00048 int height() const { return m_iHeight; }
00049 QPixmap pixmap() const { return m_pixmap; }
00050 void setText( const QString & text ) { m_strText = text; }
00051 QString text() const { return m_strText; }
00052
00053 signals:
00054 void pressed( int _group, int _id );
00055 void pressed();
00056 protected:
00057 void calc( QWidget* );
00058
00059 int m_iHeight;
00060 KoKoolBarGroup* m_pGroup;
00061 QString m_strText;
00062 QPixmap m_pixmap;
00063 int m_id;
00064 bool m_bEnabled;
00065 class KoKoolBarItemPrivate;
00066 KoKoolBarItemPrivate *d;
00067 };
00068
00069 class KoKoolBarGroup : public QObject
00070 {
00071 Q_OBJECT
00072 public:
00073 KoKoolBarGroup( KoKoolBar *_bar, const QString& _text );
00074 ~KoKoolBarGroup();
00075
00076 void append( KoKoolBarItem *_i ) { m_mapItems.insert( _i->id(), _i ); }
00077 void remove( int _id );
00078
00079 KoKoolBar* bar() const { return m_pBar; }
00080 QPushButton* button() const { return m_pButton; }
00081 int id() const { return m_id; }
00082 bool isEnabled() const { return m_bEnabled; }
00083 void setEnabled( bool _e ) { m_bEnabled = _e; }
00084 KoKoolBarItem* item( int _id ) const { return m_mapItems[ _id ]; }
00085 int items() const { return m_mapItems.size(); }
00086 Q3IntDictIterator<KoKoolBarItem> iterator() const { return Q3IntDictIterator<KoKoolBarItem>( m_mapItems ); }
00087
00088 public slots:
00089 void pressed();
00090
00091 protected:
00092 Q3IntDict<KoKoolBarItem> m_mapItems;
00093 KoKoolBar* m_pBar;
00094 QString m_strText;
00095 int m_id;
00096 QPushButton* m_pButton;
00097 bool m_bEnabled;
00098 class KoKoolBarGroupPrivate;
00099 KoKoolBarGroupPrivate *d;
00100 };
00101
00102 class KoKoolBarBox : public Q3Frame
00103 {
00104 Q_OBJECT
00105 public:
00106 KoKoolBarBox( KoKoolBar *_bar );
00107
00108 void setActiveGroup( KoKoolBarGroup *_grp );
00109 int maxHeight() const;
00110
00111 void sizeChanged() { resizeEvent(0L); }
00112
00113 protected slots:
00114 void scrollUp();
00115 void scrollDown();
00116
00117 protected:
00118 virtual void resizeEvent( QResizeEvent *_ev );
00119 virtual void drawContents( QPainter * );
00120 virtual void mousePressEvent( QMouseEvent *_ev )
00121 { KoKoolBarItem *item = findByPos( _ev->pos().y() + m_iYOffset ); if ( !item ) return; item->press(); }
00122
00123 KoKoolBarItem* findByPos( int _abs_y ) const;
00124
00125 bool needsScrolling() const;
00126 bool isAtBottom() const;
00127 bool isAtTop() const;
00128 void updateScrollButtons();
00129
00130 KoKoolBar *m_pBar;
00131 int m_iYOffset;
00132 int m_iYIcon;
00133 KoKoolBarGroup *m_pGroup;
00134 QPushButton* m_pButtonUp;
00135 QPushButton* m_pButtonDown;
00136 class KoKoolBarBoxPrivate;
00137 KoKoolBarBoxPrivate *d;
00138 };
00139
00140 class KOFFICEUI_EXPORT KoKoolBar : public QWidget
00141 {
00142 Q_OBJECT
00143 public:
00144 KoKoolBar( QWidget *_parent = 0L, const char *_name = 0L );
00145 virtual ~KoKoolBar() { };
00146
00147 virtual int insertGroup( const QString& _text );
00148 virtual int insertItem( int _grp, const QPixmap& _pix, const QString& _text = QString::null,
00149 QObject *_obj = 0L, const char *_slot = 0L );
00150 virtual void removeGroup( int _grp );
00151 virtual void removeItem( int _grp, int _id );
00152 virtual void renameItem( int _grp, int _id, const QString & _text );
00153 virtual void setActiveGroup( int _grp );
00154 virtual int activeGroup() const { return m_iActiveGroup; }
00155 virtual void enableItem( int _grp, int _id, bool _enable );
00156 virtual void enableGroup( int _grp, bool _enable );
00157
00158 protected:
00159 virtual void resizeEvent( QResizeEvent *_ev );
00160
00161 Q3IntDict<KoKoolBarGroup> m_mapGroups;
00162
00163 int m_iActiveGroup;
00164 KoKoolBarBox* m_pBox;
00165 class KoKoolBarPrivate;
00166 KoKoolBarPrivate *d;
00167 };
00168
00169 #endif