From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kontact/src/iconsidepane.h | 193 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 kontact/src/iconsidepane.h (limited to 'kontact/src/iconsidepane.h') diff --git a/kontact/src/iconsidepane.h b/kontact/src/iconsidepane.h new file mode 100644 index 000000000..281d25aec --- /dev/null +++ b/kontact/src/iconsidepane.h @@ -0,0 +1,193 @@ +/* + This file is part of the KDE Kontact. + + Copyright (C) 2003 Cornelius Schumacher + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KONTACT_ICONSIDEPANEBASE_H +#define KONTACT_ICONSIDEPANEBASE_H + +#include + +#include + +#include "sidepanebase.h" +#include "prefs.h" + + +class QSignalMapper; + +namespace KParts { class Part; } + +namespace Kontact +{ + +class Core; +class Plugin; +class Navigator; + +enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 22, ShowText = 3, ShowIcons = 5 }; + + +/** + A QListBoxPixmap Square Box with an optional icon and a text + underneath. +*/ +class EntryItem : public QListBoxItem +{ + public: + EntryItem( Navigator *, Kontact::Plugin * ); + ~EntryItem(); + + Kontact::Plugin *plugin() const { return mPlugin; } + + const QPixmap *pixmap() const { return &mPixmap; } + + Navigator* navigator() const; + + void setHover( bool ); + void setPaintActive( bool ); + bool paintActive() const { return mPaintActive; } + /** + returns the width of this item. + */ + virtual int width( const QListBox * ) const; + /** + returns the height of this item. + */ + virtual int height( const QListBox * ) const; + + protected: + void reloadPixmap(); + + virtual void paint( QPainter *p ); + + private: + Kontact::Plugin *mPlugin; + QPixmap mPixmap; + bool mHasHover; + bool mPaintActive; +}; + +/** + * Tooltip that changes text depending on the item it is above. + * Compliments of "Practical Qt" by Dalheimer, Petersen et al. + */ +class EntryItemToolTip : public QToolTip +{ + public: + EntryItemToolTip( QListBox* parent ) + : QToolTip( parent->viewport() ), mListBox( parent ) + {} + protected: + void maybeTip( const QPoint& p ) { + // We only show tooltips when there are no texts shown + if ( Prefs::self()->sidePaneShowText() ) return; + if ( !mListBox ) return; + QListBoxItem* item = mListBox->itemAt( p ); + if ( !item ) return; + const QRect itemRect = mListBox->itemRect( item ); + if ( !itemRect.isValid() ) return; + + const EntryItem *entryItem = static_cast( item ); + QString tipStr = entryItem->text(); + tip( itemRect, tipStr ); + } + private: + QListBox* mListBox; +}; + +/** + Navigation pane showing all parts relevant to the user +*/ +class Navigator : public KListBox +{ + Q_OBJECT + public: + Navigator( SidePaneBase *parent = 0, const char *name = 0 ); + + virtual void setSelected( QListBoxItem *, bool ); + + void updatePlugins( QValueList plugins ); + + QSize sizeHint() const; + + void highlightItem( EntryItem* item ); + + IconViewMode viewMode() { return mViewMode; } + IconViewMode sizeIntToEnum(int size) const; + const QPtrList & actions() { return mActions; } + bool showIcons() const { return mShowIcons; } + bool showText() const { return mShowText; } + signals: + void pluginActivated( Kontact::Plugin * ); + + protected: + void dragEnterEvent( QDragEnterEvent * ); + void dragMoveEvent ( QDragMoveEvent * ); + void dropEvent( QDropEvent * ); + void resizeEvent( QResizeEvent * ); + void enterEvent( QEvent* ); + void leaveEvent( QEvent* ); + + void setHoverItem( QListBoxItem*, bool ); + void setPaintActiveItem( QListBoxItem*, bool ); + + protected slots: + void slotExecuted( QListBoxItem * ); + void slotMouseOn( QListBoxItem *item ); + void slotMouseOff(); + void slotShowRMBMenu( QListBoxItem *, const QPoint& ); + void shortCutSelected( int ); + void slotStopHighlight(); + + private: + SidePaneBase *mSidePane; + IconViewMode mViewMode; + + QListBoxItem* mMouseOn; + + EntryItem* mHighlightItem; + + QSignalMapper *mMapper; + QPtrList mActions; + bool mShowIcons; + bool mShowText; +}; + +class IconSidePane : public SidePaneBase +{ + Q_OBJECT + public: + IconSidePane( Core *core, QWidget *parent, const char *name = 0 ); + ~IconSidePane(); + + virtual void indicateForegrunding( Kontact::Plugin* ); + + public slots: + virtual void updatePlugins(); + virtual void selectPlugin( Kontact::Plugin* ); + virtual void selectPlugin( const QString &name ); + const QPtrList & actions() { return mNavigator->actions(); } + + private: + Navigator *mNavigator; +}; + +} + +#endif -- cgit v1.2.1