home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoKoolBar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  4.5 KB  |  167 lines

  1. /*
  2.    This file is part of the KDE project
  3.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef __ko_koolbar_h__
  22. #define __ko_koolbar_h__
  23.  
  24. #include <qframe.h>
  25. #include <qpixmap.h>
  26. #include <qintdict.h>
  27. #include <koffice_export.h>
  28. class QPushButton;
  29. class QPixmap;
  30. class KoKoolBar;
  31. class KoKoolBarGroup;
  32.  
  33. class KoKoolBarItem : public QObject
  34. {
  35. private:
  36.   Q_OBJECT
  37. public:
  38.   KoKoolBarItem( KoKoolBarGroup *_grp, const QPixmap& _pix, const QString& _text = QString::null );
  39.  
  40.   int id() const { return m_id; }
  41.   void press();
  42.   bool isEnabled() const { return m_bEnabled; }
  43.   void setEnabled( bool _e ) { m_bEnabled = _e; }
  44.  
  45.   int height() const { return m_iHeight; }
  46.   QPixmap pixmap() const { return m_pixmap; }
  47.   void setText( const QString & text ) { m_strText = text; }
  48.   QString text() const { return m_strText; }
  49.  
  50. signals:
  51.   void pressed( int _group, int _id );
  52.   void pressed();
  53. protected:
  54.   void calc( QWidget* );
  55.  
  56.   int m_iHeight;
  57.   KoKoolBarGroup* m_pGroup;
  58.   QString m_strText;
  59.   QPixmap m_pixmap;
  60.   int m_id;
  61.   bool m_bEnabled;
  62.   class KoKoolBarItemPrivate;
  63.   KoKoolBarItemPrivate *d;
  64. };
  65.  
  66. class KoKoolBarGroup : public QObject
  67. {
  68.   Q_OBJECT
  69. public:
  70.   KoKoolBarGroup( KoKoolBar *_bar, const QString& _text );
  71.   ~KoKoolBarGroup();
  72.  
  73.   void append( KoKoolBarItem *_i ) { m_mapItems.insert( _i->id(), _i ); }
  74.   void remove( int _id );
  75.  
  76.   KoKoolBar* bar() const { return m_pBar; }
  77.   QPushButton* button() const { return m_pButton; }
  78.   int id() const { return m_id; }
  79.   bool isEnabled() const { return m_bEnabled; }
  80.   void setEnabled( bool _e ) { m_bEnabled = _e; }
  81.   KoKoolBarItem* item( int _id ) const { return m_mapItems[ _id ]; }
  82.   int items() const { return m_mapItems.size(); }
  83.   QIntDictIterator<KoKoolBarItem> iterator() const { return QIntDictIterator<KoKoolBarItem>( m_mapItems ); }
  84.  
  85. public slots:
  86.   void pressed();
  87.  
  88. protected:
  89.   QIntDict<KoKoolBarItem> m_mapItems;
  90.   KoKoolBar* m_pBar;
  91.   QString m_strText;
  92.   int m_id;
  93.   QPushButton* m_pButton;
  94.   bool m_bEnabled;
  95.   class KoKoolBarGroupPrivate;
  96.   KoKoolBarGroupPrivate *d;
  97. };
  98.  
  99. class KoKoolBarBox : public QFrame
  100. {
  101.   Q_OBJECT
  102. public:
  103.   KoKoolBarBox( KoKoolBar *_bar );
  104.  
  105.   void setActiveGroup( KoKoolBarGroup *_grp );
  106.   int maxHeight() const;
  107.  
  108.   void sizeChanged() { resizeEvent(0L); }
  109.  
  110. protected slots:
  111.   void scrollUp();
  112.   void scrollDown();
  113.  
  114. protected:
  115.   virtual void resizeEvent( QResizeEvent *_ev );
  116.   virtual void drawContents( QPainter * );
  117.   virtual void mousePressEvent( QMouseEvent *_ev )
  118.   { KoKoolBarItem *item = findByPos( _ev->pos().y() + m_iYOffset ); if ( !item ) return; item->press(); }
  119.  
  120.   KoKoolBarItem* findByPos( int _abs_y ) const;
  121.  
  122.   bool needsScrolling() const;
  123.   bool isAtBottom() const;
  124.   bool isAtTop() const;
  125.   void updateScrollButtons();
  126.  
  127.   KoKoolBar *m_pBar;
  128.   int m_iYOffset;
  129.   int m_iYIcon;
  130.   KoKoolBarGroup *m_pGroup;
  131.   QPushButton* m_pButtonUp;
  132.   QPushButton* m_pButtonDown;
  133.   class KoKoolBarBoxPrivate;
  134.   KoKoolBarBoxPrivate *d;
  135. };
  136.  
  137. class KOFFICEUI_EXPORT KoKoolBar : public QWidget
  138. {
  139.   Q_OBJECT
  140. public:
  141.   KoKoolBar( QWidget *_parent = 0L, const char *_name = 0L );
  142.   virtual ~KoKoolBar() { };
  143.  
  144.   virtual int insertGroup( const QString& _text );
  145.   virtual int insertItem( int _grp, const QPixmap& _pix, const QString& _text = QString::null,
  146.               QObject *_obj = 0L, const char *_slot = 0L );
  147.   virtual void removeGroup( int _grp );
  148.   virtual void removeItem( int _grp, int _id );
  149.   virtual void renameItem( int _grp, int _id, const QString & _text );
  150.   virtual void setActiveGroup( int _grp );
  151.   virtual int activeGroup() const { return m_iActiveGroup; }
  152.   virtual void enableItem( int _grp, int _id, bool _enable );
  153.   virtual void enableGroup( int _grp, bool _enable );
  154.  
  155. protected:
  156.   virtual void resizeEvent( QResizeEvent *_ev );
  157.  
  158.   QIntDict<KoKoolBarGroup> m_mapGroups;
  159.  
  160.   int m_iActiveGroup;
  161.   KoKoolBarBox* m_pBox;
  162.   class KoKoolBarPrivate;
  163.   KoKoolBarPrivate *d;
  164. };
  165.  
  166. #endif
  167.