kontact

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 <klistbox.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 QListBoxItem
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 QToolTip
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 KListBox
00119 {
00120     Q_OBJECT
00121   public:
00122     Navigator( IconSidePane *parent = 0, const char *name = 0 );
00123 
00124     virtual void setSelected( TQListBoxItem *, bool );
00125 
00126     void updatePlugins( TQValueList<Kontact::Plugin*> plugins );
00127 
00128     TQSize sizeHint() const;
00129 
00130     void highlightItem( EntryItem* item );
00131 
00132     IconViewMode viewMode() { return mViewMode; }
00133     IconViewMode sizeIntToEnum(int size) const;
00134     const TQPtrList<KAction> & actions() { return mActions; }
00135     bool showIcons() const { return mShowIcons; }
00136     bool showText() const { return mShowText; }
00137   signals:
00138     void pluginActivated( Kontact::Plugin * );
00139 
00140   protected:
00141     void dragEnterEvent( TQDragEnterEvent * );
00142     void dragMoveEvent ( TQDragMoveEvent * );
00143     void dropEvent( TQDropEvent * );
00144     void resizeEvent( TQResizeEvent * );
00145     void enterEvent( TQEvent* );
00146     void leaveEvent( TQEvent* );
00147 
00148     void setHoverItem( TQListBoxItem*, bool );
00149     void setPaintActiveItem( TQListBoxItem*, bool );
00150 
00151   protected slots:
00152     void slotExecuted( TQListBoxItem * );
00153     void slotMouseOn( TQListBoxItem *item );
00154     void slotMouseOff();
00155     void slotShowRMBMenu( TQListBoxItem *, const TQPoint& );
00156     void shortCutSelected( int );
00157     void slotStopHighlight();
00158 
00159   private:
00160     IconSidePane *mSidePane;
00161     IconViewMode mViewMode;
00162 
00163     TQListBoxItem* mMouseOn;
00164 
00165     EntryItem*    mHighlightItem;
00166 
00167     TQSignalMapper *mMapper;
00168     TQPtrList<KAction> mActions;
00169     bool mShowIcons;
00170     bool mShowText;
00171 };
00172 
00173 class IconSidePane : public SidePaneBase
00174 {
00175     Q_OBJECT
00176   public:
00177     IconSidePane( Core *core, TQWidget *parent, const char *name = 0 );
00178     ~IconSidePane();
00179 
00180     virtual void indicateForegrunding( Kontact::Plugin* );
00181 
00182   public slots:
00183     virtual void updatePlugins();
00184     virtual void selectPlugin( Kontact::Plugin* );
00185     virtual void selectPlugin( const TQString &name );
00186     const TQPtrList<KAction> & actions() { return mNavigator->actions(); }
00187 
00188   private:
00189     Navigator *mNavigator;
00190 };
00191 
00192 }
00193 
00194 #endif