lib Library API Documentation

koKoolBar.h

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __ko_koolbar_h__
00022 #define __ko_koolbar_h__
00023 
00024 #include <qframe.h>
00025 #include <qpixmap.h>
00026 #include <qintdict.h>
00027 
00028 class QPushButton;
00029 class QPixmap;
00030 class KoKoolBar;
00031 class KoKoolBarGroup;
00032 
00033 class KoKoolBarItem : public QObject
00034 {
00035 private:
00036   Q_OBJECT
00037 public:
00038   KoKoolBarItem( KoKoolBarGroup *_grp, const QPixmap& _pix, const QString& _text = QString::null );
00039 
00040   int id() const { return m_id; }
00041   void press();
00042   bool isEnabled() const { return m_bEnabled; }
00043   void setEnabled( bool _e ) { m_bEnabled = _e; }
00044 
00045   int height() const { return m_iHeight; }
00046   QPixmap pixmap() const { return m_pixmap; }
00047   void setText( const QString & text ) { m_strText = text; }
00048   QString text() const { return m_strText; }
00049 
00050 signals:
00051   void pressed( int _group, int _id );
00052   void pressed();
00053 protected:
00054   void calc( QWidget* );
00055 
00056   int m_iHeight;
00057   KoKoolBarGroup* m_pGroup;
00058   QString m_strText;
00059   QPixmap m_pixmap;
00060   int m_id;
00061   bool m_bEnabled;
00062   class KoKoolBarItemPrivate;
00063   KoKoolBarItemPrivate *d;
00064 };
00065 
00066 class KoKoolBarGroup : public QObject
00067 {
00068   Q_OBJECT
00069 public:
00070   KoKoolBarGroup( KoKoolBar *_bar, const QString& _text );
00071   ~KoKoolBarGroup();
00072 
00073   void append( KoKoolBarItem *_i ) { m_mapItems.insert( _i->id(), _i ); }
00074   void remove( int _id );
00075 
00076   KoKoolBar* bar() const { return m_pBar; }
00077   QPushButton* button() const { return m_pButton; }
00078   int id() const { return m_id; }
00079   bool isEnabled() const { return m_bEnabled; }
00080   void setEnabled( bool _e ) { m_bEnabled = _e; }
00081   KoKoolBarItem* item( int _id ) const { return m_mapItems[ _id ]; }
00082   int items() const { return m_mapItems.size(); }
00083   QIntDictIterator<KoKoolBarItem> iterator() const { return QIntDictIterator<KoKoolBarItem>( m_mapItems ); }
00084 
00085 public slots:
00086   void pressed();
00087 
00088 protected:
00089   QIntDict<KoKoolBarItem> m_mapItems;
00090   KoKoolBar* m_pBar;
00091   QString m_strText;
00092   int m_id;
00093   QPushButton* m_pButton;
00094   bool m_bEnabled;
00095   class KoKoolBarGroupPrivate;
00096   KoKoolBarGroupPrivate *d;
00097 };
00098 
00099 class KoKoolBarBox : public QFrame
00100 {
00101   Q_OBJECT
00102 public:
00103   KoKoolBarBox( KoKoolBar *_bar );
00104 
00105   void setActiveGroup( KoKoolBarGroup *_grp );
00106   int maxHeight() const;
00107 
00108   void sizeChanged() { resizeEvent(0L); }
00109 
00110 protected slots:
00111   void scrollUp();
00112   void scrollDown();
00113 
00114 protected:
00115   virtual void resizeEvent( QResizeEvent *_ev );
00116   virtual void drawContents( QPainter * );
00117   virtual void mousePressEvent( QMouseEvent *_ev )
00118   { KoKoolBarItem *item = findByPos( _ev->pos().y() + m_iYOffset ); if ( !item ) return; item->press(); }
00119 
00120   KoKoolBarItem* findByPos( int _abs_y ) const;
00121 
00122   bool needsScrolling() const;
00123   bool isAtBottom() const;
00124   bool isAtTop() const;
00125   void updateScrollButtons();
00126 
00127   KoKoolBar *m_pBar;
00128   int m_iYOffset;
00129   int m_iYIcon;
00130   KoKoolBarGroup *m_pGroup;
00131   QPushButton* m_pButtonUp;
00132   QPushButton* m_pButtonDown;
00133   class KoKoolBarBoxPrivate;
00134   KoKoolBarBoxPrivate *d;
00135 };
00136 
00137 class KoKoolBar : public QWidget
00138 {
00139   Q_OBJECT
00140 public:
00141   KoKoolBar( QWidget *_parent = 0L, const char *_name = 0L );
00142   virtual ~KoKoolBar() { };
00143 
00144   virtual int insertGroup( const QString& _text );
00145   virtual int insertItem( int _grp, const QPixmap& _pix, const QString& _text = QString::null,
00146               QObject *_obj = 0L, const char *_slot = 0L );
00147   virtual void removeGroup( int _grp );
00148   virtual void removeItem( int _grp, int _id );
00149   virtual void renameItem( int _grp, int _id, const QString & _text );
00150   virtual void setActiveGroup( int _grp );
00151   virtual int activeGroup() const { return m_iActiveGroup; }
00152   virtual void enableItem( int _grp, int _id, bool _enable );
00153   virtual void enableGroup( int _grp, bool _enable );
00154 
00155 protected:
00156   virtual void resizeEvent( QResizeEvent *_ev );
00157 
00158   QIntDict<KoKoolBarGroup> m_mapGroups;
00159 
00160   int m_iActiveGroup;
00161   KoKoolBarBox* m_pBox;
00162   class KoKoolBarPrivate;
00163   KoKoolBarPrivate *d;
00164 };
00165 
00166 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003