kontact
iconsidepane.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KONTACT_ICONSIDEPANEBASE_H
00022 #define KONTACT_ICONSIDEPANEBASE_H
00023
00024 #include <qtooltip.h>
00025
00026 #include <klistbox.h>
00027
00028 #include "sidepanebase.h"
00029 #include "prefs.h"
00030
00031
00032 class QSignalMapper;
00033
00034 namespace KParts { class Part; }
00035
00036 namespace Kontact
00037 {
00038
00039 class Core;
00040 class Plugin;
00041 class Navigator;
00042
00043 enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 };
00044
00045
00050 class EntryItem : public QListBoxItem
00051 {
00052 public:
00053 EntryItem( Navigator *, Kontact::Plugin * );
00054 ~EntryItem();
00055
00056 Kontact::Plugin *plugin() const { return mPlugin; }
00057
00058 const QPixmap *pixmap() const { return &mPixmap; }
00059
00060 Navigator* navigator() const;
00061
00062 void setHover( bool );
00063 void setPaintActive( bool );
00064 bool paintActive() const { return mPaintActive; }
00068 virtual int width( const QListBox * ) const;
00072 virtual int height( const QListBox * ) const;
00073
00074 protected:
00075 void reloadPixmap();
00076
00077 virtual void paint( QPainter *p );
00078
00079 private:
00080 Kontact::Plugin *mPlugin;
00081 QPixmap mPixmap;
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 ( Prefs::self()->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( SidePaneBase *parent = 0, const char *name = 0 );
00122
00123 virtual void setSelected( QListBoxItem *, bool );
00124
00125 void updatePlugins( QValueList<Kontact::Plugin*> plugins );
00126
00127 QSize sizeHint() const;
00128
00129 void highlightItem( EntryItem* item );
00130
00131 IconViewMode viewMode() { return mViewMode; }
00132 IconViewMode sizeIntToEnum(int size) const;
00133 const QPtrList<KAction> & actions() { return mActions; }
00134 bool showIcons() const { return mShowIcons; }
00135 bool showText() const { return mShowText; }
00136 signals:
00137 void pluginActivated( Kontact::Plugin * );
00138
00139 protected:
00140 void dragEnterEvent( QDragEnterEvent * );
00141 void dragMoveEvent ( QDragMoveEvent * );
00142 void dropEvent( QDropEvent * );
00143 void resizeEvent( QResizeEvent * );
00144 void enterEvent( QEvent* );
00145 void leaveEvent( QEvent* );
00146
00147 void setHoverItem( QListBoxItem*, bool );
00148 void setPaintActiveItem( QListBoxItem*, bool );
00149
00150 protected slots:
00151 void slotExecuted( QListBoxItem * );
00152 void slotMouseOn( QListBoxItem *item );
00153 void slotMouseOff();
00154 void slotShowRMBMenu( QListBoxItem *, const QPoint& );
00155 void shortCutSelected( int );
00156 void slotStopHighlight();
00157
00158 private:
00159 SidePaneBase *mSidePane;
00160 IconViewMode mViewMode;
00161
00162 QListBoxItem* mMouseOn;
00163
00164 EntryItem* mHighlightItem;
00165
00166 QSignalMapper *mMapper;
00167 QPtrList<KAction> mActions;
00168 bool mShowIcons;
00169 bool mShowText;
00170 };
00171
00172 class IconSidePane : public SidePaneBase
00173 {
00174 Q_OBJECT
00175 public:
00176 IconSidePane( Core *core, QWidget *parent, const char *name = 0 );
00177 ~IconSidePane();
00178
00179 virtual void indicateForegrunding( Kontact::Plugin* );
00180
00181 public slots:
00182 virtual void updatePlugins();
00183 virtual void selectPlugin( Kontact::Plugin* );
00184 virtual void selectPlugin( const QString &name );
00185 const QPtrList<KAction> & actions() { return mNavigator->actions(); }
00186
00187 private:
00188 Navigator *mNavigator;
00189 };
00190
00191 }
00192
00193 #endif
|