koshell
iconsidepane.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
|