iconsidepane.h
00001 /* 00002 This file is part of the KDE Kontact. 00003 00004 Copyright (C) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; see the file COPYING. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef KONTACT_ICONSIDEPANEBASE_H 00022 #define KONTACT_ICONSIDEPANEBASE_H 00023 00024 #include <tqtooltip.h> 00025 00026 #include <tdelistbox.h> 00027 00028 #include "sidepanebase.h" 00029 #include "prefs.h" 00030 00031 00032 class TQSignalMapper; 00033 00034 namespace KParts { class Part; } 00035 00036 namespace Kontact 00037 { 00038 00039 class Core; 00040 class IconSidePane; 00041 class Plugin; 00042 class Navigator; 00043 00044 enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 }; 00045 00046 00051 class EntryItem : public TQListBoxItem 00052 { 00053 public: 00054 EntryItem( Navigator *, Kontact::Plugin * ); 00055 ~EntryItem(); 00056 00057 Kontact::Plugin *plugin() const { return mPlugin; } 00058 00059 const TQPixmap *pixmap() const { return &mPixmap; } 00060 00061 Navigator* navigator() const; 00062 00063 void setHover( bool ); 00064 void setPaintActive( bool ); 00065 bool paintActive() const { return mPaintActive; } 00069 virtual int width( const TQListBox * ) const; 00073 virtual int height( const TQListBox * ) const; 00074 00075 protected: 00076 void reloadPixmap(); 00077 00078 virtual void paint( TQPainter *p ); 00079 00080 private: 00081 Kontact::Plugin *mPlugin; 00082 TQPixmap mPixmap; 00083 bool mHasHover; 00084 bool mPaintActive; 00085 }; 00086 00091 class EntryItemToolTip : public TQToolTip 00092 { 00093 public: 00094 EntryItemToolTip( TQListBox* parent ) 00095 : TQToolTip( parent->viewport() ), mListBox( parent ) 00096 {} 00097 protected: 00098 void maybeTip( const TQPoint& p ) { 00099 // We only show tooltips when there are no texts shown 00100 if ( Prefs::self()->sidePaneShowText() ) return; 00101 if ( !mListBox ) return; 00102 TQListBoxItem* item = mListBox->itemAt( p ); 00103 if ( !item ) return; 00104 const TQRect itemRect = mListBox->itemRect( item ); 00105 if ( !itemRect.isValid() ) return; 00106 00107 const EntryItem *entryItem = static_cast<EntryItem*>( item ); 00108 TQString tipStr = entryItem->text(); 00109 tip( itemRect, tipStr ); 00110 } 00111 private: 00112 TQListBox* mListBox; 00113 }; 00114 00118 class Navigator : public TDEListBox 00119 { 00120 Q_OBJECT 00121 00122 public: 00123 Navigator( IconSidePane *parent = 0, const char *name = 0 ); 00124 00125 virtual void setSelected( TQListBoxItem *, bool ); 00126 00127 void updatePlugins( TQValueList<Kontact::Plugin*> plugins ); 00128 00129 TQSize sizeHint() const; 00130 00131 void highlightItem( EntryItem* item ); 00132 00133 IconViewMode viewMode() { return mViewMode; } 00134 IconViewMode sizeIntToEnum(int size) const; 00135 const TQPtrList<TDEAction> & actions() { return mActions; } 00136 bool showIcons() const { return mShowIcons; } 00137 bool showText() const { return mShowText; } 00138 signals: 00139 void pluginActivated( Kontact::Plugin * ); 00140 00141 protected: 00142 void dragEnterEvent( TQDragEnterEvent * ); 00143 void dragMoveEvent ( TQDragMoveEvent * ); 00144 void dropEvent( TQDropEvent * ); 00145 void resizeEvent( TQResizeEvent * ); 00146 void enterEvent( TQEvent* ); 00147 void leaveEvent( TQEvent* ); 00148 00149 void setHoverItem( TQListBoxItem*, bool ); 00150 void setPaintActiveItem( TQListBoxItem*, bool ); 00151 00152 protected slots: 00153 void slotExecuted( TQListBoxItem * ); 00154 void slotMouseOn( TQListBoxItem *item ); 00155 void slotMouseOff(); 00156 void slotShowRMBMenu( TQListBoxItem *, const TQPoint& ); 00157 void shortCutSelected( int ); 00158 void slotStopHighlight(); 00159 00160 private: 00161 IconSidePane *mSidePane; 00162 IconViewMode mViewMode; 00163 00164 TQListBoxItem* mMouseOn; 00165 00166 EntryItem* mHighlightItem; 00167 00168 TQSignalMapper *mMapper; 00169 TQPtrList<TDEAction> mActions; 00170 bool mShowIcons; 00171 bool mShowText; 00172 }; 00173 00174 class IconSidePane : public SidePaneBase 00175 { 00176 Q_OBJECT 00177 00178 public: 00179 IconSidePane( Core *core, TQWidget *parent, const char *name = 0 ); 00180 ~IconSidePane(); 00181 00182 virtual void indicateForegrunding( Kontact::Plugin* ); 00183 00184 public slots: 00185 virtual void updatePlugins(); 00186 virtual void selectPlugin( Kontact::Plugin* ); 00187 virtual void selectPlugin( const TQString &name ); 00188 const TQPtrList<TDEAction> & actions() { return mNavigator->actions(); } 00189 00190 private: 00191 Navigator *mNavigator; 00192 }; 00193 00194 } 00195 00196 #endif