koshell

iconsidepane.h

00001 /*
00002   This file is part of the KDE KOffice project.
00003 
00004   Copyright (C) 2003 Cornelius Schumacher <schumacher@kde.org>
00005   Copyright (C) 2005 Fredrik Edemar <f_edemar@linux.se>
00006 
00007   This program is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; see the file COPYING.  If not, write to
00019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 #ifndef KOFFICE_ICONSIDEPANEBASE_H
00023 #define KOFFICE_ICONSIDEPANEBASE_H
00024 
00025 #include <kactioncollection.h>
00026 #include <klistbox.h>
00027 
00028 #include <qbuttongroup.h> 
00029 #include <qlayout.h>
00030 #include <qtooltip.h>
00031 #include <qvbox.h>
00032 #include <qwidgetstack.h>
00033 
00034 #include "koshellsettings.h"
00035 
00036 
00037 class Navigator;
00038 class IconSidePane;
00039 
00040 enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 };
00041 
00046 class EntryItem : public QListBoxItem
00047 {
00048   public:
00049     EntryItem( Navigator *, int _id, const QString &_text, const QString & _pix );
00050     ~EntryItem();
00051 
00052 
00053     const QPixmap *pixmap() const { return &mPixmap; }
00054 
00055     int id() { return mId; }
00056 
00057     void setNewText( const QString &_text );
00058 
00059     void setHover( bool );
00060     void setPaintActive( bool );
00061     bool paintActive() const { return mPaintActive; }
00062 
00066     virtual int width( const QListBox * ) const;
00070     virtual int height( const QListBox * ) const;
00071 
00072   protected:
00073     void reloadPixmap();
00074 
00075     virtual void paint( QPainter *p );
00076 
00077   private:
00078     QPixmap mPixmap;
00079     QString mPixmapName;
00080     int const mId;
00081     Navigator* navigator() const;
00082     bool mHasHover;
00083     bool mPaintActive;
00084 };
00085 
00090 class EntryItemToolTip : public QToolTip
00091 {
00092   public:
00093     EntryItemToolTip( QListBox* parent )
00094       : QToolTip( parent->viewport() ), mListBox( parent ) 
00095       {}
00096   protected:
00097     void maybeTip( const QPoint& p ) {
00098       // We only show tooltips when there are no texts shown
00099       if ( KoShellSettings::sidePaneShowText() ) return;
00100       if ( !mListBox ) return;
00101       QListBoxItem* item = mListBox->itemAt( p );
00102       if ( !item ) return;
00103       const QRect itemRect = mListBox->itemRect( item );
00104       if ( !itemRect.isValid() ) return;
00105 
00106       const EntryItem *entryItem = static_cast<EntryItem*>( item );
00107       QString tipStr = entryItem->text();
00108       tip( itemRect, tipStr );
00109     }
00110   private:
00111     QListBox* mListBox;
00112 };
00113 
00117 class Navigator : public KListBox
00118 {
00119     Q_OBJECT
00120   public:
00121     Navigator(bool _selectable, KPopupMenu*, IconSidePane *, QWidget *parent = 0, const char *name = 0 );
00122 
00123     int insertItem(const QString &_text, const QString &_pix);
00124 
00125     QSize sizeHint() const;
00126     IconViewMode viewMode();
00127     bool showText();
00128     bool showIcons();
00129     void calculateMinWidth();
00130     bool leftMouseButtonPressed(){return mLeftMouseButtonPressed;}
00131     int minWidth() { return mMinWidth; }
00132     void resetWidth() { mMinWidth = 0; }
00133 
00134   signals:
00135     void itemSelected( int );
00136     void updateAllWidgets();
00137 
00138   protected:
00139     void resizeEvent( QResizeEvent * );
00140     void enterEvent( QEvent* );
00141     void mouseReleaseEvent(QMouseEvent *e);
00142     void mousePressEvent(QMouseEvent *e);
00143 
00144     void setHoverItem( QListBoxItem*, bool );
00145     void setPaintActiveItem( QListBoxItem*, bool );
00146 
00147   protected slots:
00148     void slotExecuted( QListBoxItem * );
00149     void slotMouseOn( QListBoxItem *item );
00150     void slotMouseOff();
00151     void slotShowRMBMenu( QListBoxItem *, const QPoint& );
00152 
00153   private:
00154     IconSidePane *mSidePane;
00155     int mMinWidth;
00156     QListBoxItem *executedItem;
00157     bool mLeftMouseButtonPressed;
00158     KPopupMenu *mPopupMenu;
00159     bool mSelectable;
00160     QListBoxItem* mMouseOn;
00161 };
00162 
00163 class IconSidePane :public QVBox
00164 {
00165     Q_OBJECT
00166   public:
00167     IconSidePane( QWidget *parent, const char *name = 0 );
00168     ~IconSidePane();
00169 
00170     void setActionCollection( KActionCollection *actionCollection );
00171     KActionCollection *actionCollection() const;
00172 
00173     int insertItem(const QString & _pix, const QString &_text);
00174     int insertItem(int _grp, const QString & _pix, const QString &_text);
00175     int insertGroup(const QString &_text, bool _selectable, QObject *_obj = 0L, const char *_slot = 0L);
00176     void renameItem( int _grp, int _id, const QString & _text );
00177     void removeItem( int _grp, int _id );
00178     void selectGroup(int);
00179     Navigator *group(int);
00180 
00181     IconViewMode sizeIntToEnum(int size) const;
00182     IconViewMode viewMode() { return mViewMode; }
00183     void setViewMode(int choice){mViewMode = sizeIntToEnum(choice);}
00184     bool showText() { return mShowText; }
00185     void toogleText(){mShowText=!mShowText;}
00186     bool showIcons() { return mShowIcons; }
00187     void toogleIcons(){mShowIcons=!mShowIcons;}
00188     QButtonGroup *buttonGroup() { return m_buttongroup; }
00189     int minWidth();
00190     void resetWidth();
00191 
00192   public slots:
00193     void itemSelected(int);
00194     void updateAllWidgets();
00195 
00196   private slots:
00197     void buttonClicked();
00198 
00199   private:
00200     QWidgetStack *mWidgetstack;
00201     QValueList<int> mWidgetStackIds;
00202     Navigator *mCurrentNavigator;
00203     QButtonGroup *m_buttongroup;
00204     KActionCollection *mActionCollection;
00205     KPopupMenu *mPopupMenu;
00206 
00207     IconViewMode mViewMode;
00208     bool mShowIcons;
00209     bool mShowText;
00210 };
00211 
00212 
00213 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys