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 / kmultitabbar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  9.6 KB  |  317 lines

  1. /***************************************************************************
  2.                           kmultitabbar.h -  description
  3.                              -------------------
  4.     begin                :  2001
  5.     copyright            : (C) 2001,2002,2003 by Joseph Wenninger <jowenn@kde.org>
  6.  ***************************************************************************/
  7.  
  8. /***************************************************************************
  9.     This library is free software; you can redistribute it and/or
  10.     modify it under the terms of the GNU Library General Public
  11.     License as published by the Free Software Foundation; either
  12.     version 2 of the License, or (at your option) any later version.
  13.  
  14.     This library is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.     Library General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU Library General Public License
  20.     along with this library; see the file COPYING.LIB.  If not, write to
  21.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22.     Boston, MA 02110-1301, USA.
  23.  ***************************************************************************/
  24.  
  25. #ifndef _KMultitabbar_h_
  26. #define _KMultitabbar_h_
  27.  
  28. #include <qscrollview.h>
  29. #include <qvbox.h>
  30. #include <qhbox.h>
  31. #include <qlayout.h>
  32. #include <qstring.h>
  33. #include <qptrlist.h>
  34. #include <qpushbutton.h>
  35.  
  36. #include <kdelibs_export.h>
  37.  
  38. class QPixmap;
  39. class QPainter;
  40. class QFrame;
  41.  
  42. class KMultiTabBarPrivate;
  43. class KMultiTabBarTabPrivate;
  44. class KMultiTabBarButtonPrivate;
  45. class KMultiTabBarInternal;
  46.  
  47. /**
  48.  * @ingroup main
  49.  * @ingroup multitabbar
  50.  * A Widget for horizontal and vertical tabs.
  51.  * It is possible to add normal buttons to the top/left
  52.  * The handling if only one tab at a time or multiple tabs
  53.  * should be raisable is left to the "user".
  54.  *@author Joseph Wenninger
  55.  */
  56. class KUTILS_EXPORT KMultiTabBar: public QWidget
  57. {
  58.     Q_OBJECT
  59. public:
  60.     /**
  61.      * The tab bar's orientation. Also constraints the bar's position.
  62.      */
  63.     enum KMultiTabBarMode {
  64.         Horizontal,  ///< Horizontal orientation (i.e. on top or bottom)
  65.         Vertical     ///< Vertical orientation (i.e. on the left or right hand side)
  66.     };
  67.     
  68.     /**
  69.      * The tab bar's position
  70.      */
  71.     enum KMultiTabBarPosition {
  72.         Left,   ///< Left hand side
  73.         Right,  ///< Right hand side
  74.         Top,    ///< On top
  75.         Bottom  ///< On bottom
  76.     };
  77.  
  78.     /**
  79.      * The list of available styles for KMultiTabBar
  80.      */
  81.     enum KMultiTabBarStyle {
  82.         VSNET=0,          ///< Visual Studio .Net like (only show the text of active tabs)
  83.         KDEV3=1,          ///< KDevelop 3 like (always show the text)
  84.         KONQSBC=2,        ///< Konqueror's classic sidebar style (unthemed) (currently disabled)
  85.         KDEV3ICON=3,      ///< KDevelop 3 like with icons
  86.         STYLELAST=0xffff  ///< Last style
  87.     };
  88.  
  89.     /**
  90.      * Constructor.
  91.      * @param bm The tab bar's orientation
  92.      * @param parent The parent widget
  93.      * @param name The widget's name
  94.      */
  95.     KMultiTabBar(KMultiTabBarMode bm,QWidget *parent=0,const char *name=0);
  96.     
  97.     /**
  98.      * Destructor.
  99.      */
  100.     virtual ~KMultiTabBar();
  101.  
  102.     /**
  103.       * append  a new button to the button area. The button can later on be accessed with button(ID)
  104.      * eg for connecting signals to it
  105.      * @param pic a pixmap for the button
  106.       * @param id an arbitraty ID value. It will be emitted in the clicked signal for identifying the button
  107.      *    if more than one button is connected to a signals.
  108.      * @param popup A popup menu which should be displayed if the button is clicked
  109.      * @param not_used_yet will be used for a popup text in the future
  110.      */
  111.      int appendButton(const QPixmap &pic,int id=-1,QPopupMenu* popup=0,const QString& not_used_yet=QString::null);
  112.     /** 
  113.          * remove a button with the given ID
  114.      */
  115.     void removeButton(int id);
  116.     /**
  117.      * append a new tab to the tab area. It can be accessed lateron with tabb(id);
  118.      * @param pic a bitmap for the tab
  119.      * @param id an arbitrary ID which can be used later on to identify the tab
  120.      * @param text if a mode with text is used it will be the tab text, otherwise a mouse over hint
  121.      * @return Always zero. Can be safely ignored.
  122.      */
  123.     int appendTab(const QPixmap &pic,int id=-1,const QString& text=QString::null);
  124.     /**
  125.      * remove a tab with a given ID
  126.      * @param id The ID of the tab to remove
  127.      */
  128.     void removeTab(int id);
  129.     /**
  130.      * set a tab to "raised"
  131.      * @param id The ID of the tab to manipulate
  132.      * @param state true == activated/raised, false == not active
  133.      */
  134.     void setTab(int id ,bool state);
  135.     /**
  136.      * return the state of a tab, identified by it's ID
  137.      * @param id The ID of the tab to raise
  138.      */
  139.     bool isTabRaised(int id) const;
  140.     /**
  141.      * get a pointer to a button within the button area identified by its ID
  142.      * @param id The id of the tab
  143.      */
  144.     class KMultiTabBarButton *button(int id) const;
  145.  
  146.     /**
  147.      * get a pointer to a tab within the tab area, identified by its ID
  148.      */
  149.     class KMultiTabBarTab *tab(int id) const;
  150.     /**
  151.      * set the real position of the widget.
  152.      * @param pos if the mode is horizontal, only use top, bottom, if it is vertical use left or right
  153.      */
  154.     void setPosition(KMultiTabBarPosition pos);
  155.     /**
  156.      * get the tabbar position.
  157.      * @return The tab bar's position
  158.      */
  159.     KMultiTabBarPosition position() const;
  160.     /**
  161.      * set the display style of the tabs
  162.      * @param style The new display style
  163.      */
  164.     void setStyle(KMultiTabBarStyle style);
  165.     /**
  166.      * get the display style of the tabs
  167.      * @return display style
  168.      */
  169.     KMultiTabBarStyle tabStyle() const;
  170.     /**
  171.      * Returns the list of pointers to the tabs of type KMultiTabBarTab.
  172.      * @return The list of tabs.
  173.      * @warning be careful, don't delete tabs yourself and don't delete the list itself
  174.      */
  175.         QPtrList<KMultiTabBarTab>* tabs();
  176.     /**
  177.      * Returns the list of pointers to the tab buttons of type KMultiTabBarButton.
  178.      * @return The list of tab buttons.
  179.      * @warning be careful, don't delete buttons yourself and don't delete the list itself
  180.      */
  181.     QPtrList<KMultiTabBarButton>* buttons();
  182.  
  183.     /**
  184.      * might vanish, not sure yet
  185.      */
  186.     void showActiveTabTexts(bool show=true);
  187. protected:
  188.     friend class KMultiTabBarButton;
  189.     virtual void fontChange( const QFont& );
  190.     void updateSeparator();
  191. private:
  192.     class KMultiTabBarInternal *m_internal;
  193.     QBoxLayout *m_l;
  194.     QFrame *m_btnTabSep;
  195.     QPtrList<KMultiTabBarButton> m_buttons;
  196.     KMultiTabBarPosition m_position;
  197.     KMultiTabBarPrivate *d;
  198. };
  199.  
  200. /**
  201.  * @ingroup multitabbar
  202.  * This class represents a tab bar button in a KMultiTabBarWidget.
  203.  * This class should never be created except with the appendButton call of KMultiTabBar
  204.  */
  205. class KUTILS_EXPORT KMultiTabBarButton: public QPushButton
  206. {
  207.     Q_OBJECT
  208. public:
  209.     /** @internal */
  210.     KMultiTabBarButton(const QPixmap& pic,const QString&, QPopupMenu *popup,
  211.         int id,QWidget *parent, KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style);
  212.     /** @internal */
  213.     KMultiTabBarButton(const QString&, QPopupMenu *popup,
  214.         int id,QWidget *parent, KMultiTabBar::KMultiTabBarPosition pos, KMultiTabBar::KMultiTabBarStyle style);
  215.     /**
  216.      * Destructor
  217.      */
  218.     virtual  ~KMultiTabBarButton();
  219.     /**
  220.      * Returns the tab's ID
  221.      * @return The tab's ID
  222.      */
  223.     int id() const;
  224.  
  225. public slots:
  226.     /**
  227.      * this is used internaly, but can be used by the user, if (s)he wants to
  228.      * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
  229.      */
  230.     void setPosition(KMultiTabBar::KMultiTabBarPosition);
  231.         /**
  232.          * this is used internaly, but can be used by the user, if (s)he wants to
  233.          * It the according call of KMultiTabBar is invoked though this modifications will be overwritten
  234.          */
  235.     void setStyle(KMultiTabBar::KMultiTabBarStyle);
  236.  
  237.         /**
  238.      * modify the text of the button
  239.          */
  240.     void setText(const QString &);
  241.  
  242.     QSize sizeHint() const;
  243.  
  244. protected:
  245.     KMultiTabBar::KMultiTabBarPosition m_position;
  246.     KMultiTabBar::KMultiTabBarStyle m_style;
  247.     QString m_text;
  248.     virtual void hideEvent( class QHideEvent*);
  249.     virtual void showEvent( class QShowEvent*);
  250. private:
  251.     int m_id;
  252.     KMultiTabBarButtonPrivate *d;
  253. signals:
  254.     /**
  255.      * this is emitted if  the button is clicked
  256.      * @param id    the ID identifying the button
  257.      */
  258.     void clicked(int id);
  259. protected slots:
  260.     virtual void slotClicked();
  261. };
  262.  
  263. /**
  264.  * @ingroup multitabbar
  265.  * This class represents a tab bar's tab in a KMultiTabBarWidget.
  266.  * This class should never be created except with the appendTab call of KMultiTabBar
  267.  */
  268. class KUTILS_EXPORT KMultiTabBarTab: public KMultiTabBarButton
  269. {
  270.     Q_OBJECT
  271. public:
  272.   /** @internal */
  273.     KMultiTabBarTab(const QPixmap& pic,const QString&,int id,QWidget *parent,
  274.         KMultiTabBar::KMultiTabBarPosition pos,KMultiTabBar::KMultiTabBarStyle style);
  275.     /**
  276.      * Destructor.
  277.      */
  278.     virtual ~KMultiTabBarTab();
  279.     /**
  280.      * set the active state of the tab
  281.      * @param  state @c true if the tab should become active, @c false otherwise
  282.      */
  283.     void setState(bool state);
  284.     /**
  285.      * choose if the text should always be displayed
  286.      * this is only used in classic mode if at all
  287.      * @param show Whether or not to show the text
  288.      */
  289.     void showActiveTabText(bool show);
  290.     /**
  291.      * Resized the tab to the needed size.
  292.      */
  293.     void resize(){ setSize( neededSize() ); }
  294. private:
  295.     bool m_showActiveTabText;
  296.     int m_expandedSize;
  297.     KMultiTabBarTabPrivate *d;
  298. protected:
  299.     friend class KMultiTabBarInternal;
  300.     void setSize(int);
  301.     int neededSize();
  302.     void updateState();
  303.     virtual void drawButton(QPainter *);
  304.     virtual void drawButtonLabel(QPainter *);
  305.     void drawButtonStyled(QPainter *);
  306.     void drawButtonClassic(QPainter *);
  307. protected slots:
  308.     virtual void slotClicked();
  309.     void setTabsPosition(KMultiTabBar::KMultiTabBarPosition);
  310.  
  311. public slots:
  312.     virtual void setIcon(const QString&);
  313.     virtual void setIcon(const QPixmap&);
  314. };
  315.  
  316. #endif
  317.