[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] New Sidebar for kontact
From:       "Mischael Schill" <me () mschill ! ch>
Date:       2008-02-04 20:27:25
Message-ID: 200802042127.26352.me () mschill ! ch
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


So, i've done all my corrections.

Here is the patch, if the new "style" is acceptable :). It's 
pretty much a total rewrite using KToolBar instead of a List, 
because of my lack of qt-skills.
I tried to make my coding style better and learned a lot. 

Cheers,
Mischa

["newsidepane.diff" (text/x-diff)]

Index: mainwindow.cpp
===================================================================
--- mainwindow.cpp	(Revision 770947)
+++ mainwindow.cpp	(Arbeitskopie)
@@ -285,7 +285,7 @@
   sizes << 0;
   mSplitter->setSizes(sizes);
 */
-  mSidePane->setActionCollection( actionCollection() );
+  //mSidePane->setActionCollection( actionCollection() );
 
   connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ),
            SLOT( selectPlugin( Kontact::Plugin * ) ) );
@@ -638,7 +638,7 @@
 
   if ( plugin->isRunningStandalone() ) {
     statusBar()->showMessage( i18n( "Application is running standalone. Foregrounding..." ), 1000 );
-    mSidePane->indicateForegrunding( plugin );
+    mSidePane->indicateForegrounding( plugin );
     plugin->bringToForeground();
     return;
   }
Index: iconsidepane.h
===================================================================
--- iconsidepane.h	(Revision 770947)
+++ iconsidepane.h	(Arbeitskopie)
@@ -31,8 +31,8 @@
 #include <QResizeEvent>
 #include <QDragEnterEvent>
 
-#include <k3listbox.h>
-
+#include <ktoolbar.h>
+#include <klistwidget.h>
 #include "sidepanebase.h"
 #include "prefs.h"
 
@@ -48,138 +48,33 @@
 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 Q3ListBoxItem
-{
-  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 Q3ListBox * ) const;
-    /**
-      returns the height of this item.
-    */
-    virtual int height( const Q3ListBox * ) 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.
- */
-#ifdef __GNUC__
-#warning Port me!
-#endif
-#if 0
-class EntryItemToolTip : public QToolTip
-{
-  public:
-    EntryItemToolTip( Q3ListBox* 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;
-      Q3ListBoxItem* item = mListBox->itemAt( p );
-      if ( !item ) return;
-      const QRect itemRect = mListBox->itemRect( item );
-      if ( !itemRect.isValid() ) return;
-
-      const EntryItem *entryItem = static_cast<EntryItem*>( item );
-      QString tipStr = entryItem->text();
-      tip( itemRect, tipStr );
-    }
-  private:
-    Q3ListBox* mListBox;
-};
-#endif
-
-/**
   Navigation pane showing all parts relevant to the user
 */
-class Navigator : public K3ListBox
+class Navigator : public KToolBar
 {
     Q_OBJECT
   public:
-    Navigator( SidePaneBase *parent = 0, const char *name = 0 );
+    Navigator( SidePaneBase *parent = 0 );
+    ~Navigator();
 
-    virtual void setSelected( Q3ListBoxItem *, bool );
-
     void updatePlugins( QList<Kontact::Plugin*> plugins );
+    void selectPlugin( Kontact::Plugin* plugin );
+    void selectPlugin( const QString &name );
+    void disablePlugin( Kontact::Plugin *plugin );
+    void enablePlugin( Kontact::Plugin *plugin );
 
-    QSize sizeHint() const;
-
-    void highlightItem( EntryItem* item );
-
-    IconViewMode viewMode() { return mViewMode; }
-    IconViewMode sizeIntToEnum(int size) const;
-    const QList<QAction*> & 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( Q3ListBoxItem*, bool );
-    void setPaintActiveItem( Q3ListBoxItem*, bool );
-
-  protected slots:
-    void slotExecuted( Q3ListBoxItem * );
-    void slotMouseOn( Q3ListBoxItem *item );
-    void slotMouseOff();
-    void slotShowRMBMenu( Q3ListBoxItem *, const QPoint& );
-    void shortCutSelected( int );
-    void slotStopHighlight();
-
+  private slots:
+    void slotExecuted( QAction* action );
+    void slotShowRMBMenu( const QPoint& );
   private:
     SidePaneBase *mSidePane;
-    IconViewMode mViewMode;
-
-    Q3ListBoxItem* mMouseOn;
-
-    EntryItem*    mHighlightItem;
-
-    QSignalMapper *mMapper;
-    QList<QAction*> mActions;
-    bool mShowIcons;
-    bool mShowText;
+    QList<Plugin*> mPlugins;
+    QAction* mLastAction;
+    void restorePreferences();
 };
 
 class IconSidePane : public SidePaneBase
@@ -189,13 +84,12 @@
     IconSidePane( Core *core, QWidget *parent );
     ~IconSidePane();
 
-    virtual void indicateForegrunding( Kontact::Plugin* );
+    virtual void indicateForegrounding( Kontact::Plugin* );
 
   public slots:
     virtual void updatePlugins();
     virtual void selectPlugin( Kontact::Plugin* );
     virtual void selectPlugin( const QString &name );
-    const QList<QAction*> & actions() { return mNavigator->actions(); }
 
   private:
     Navigator *mNavigator;
Index: iconsidepane.cpp
===================================================================
--- iconsidepane.cpp	(Revision 770947)
+++ iconsidepane.cpp	(Arbeitskopie)
@@ -42,11 +42,13 @@
 #include <QResizeEvent>
 #include <QDragEnterEvent>
 
+#include <QListWidget>
+#include <QListWidgetItem>
+
 #include <kmenu.h>
 #include <kdialog.h>
 #include <kactioncollection.h>
 #include <klocale.h>
-#include <kiconloader.h>
 
 #include <kdebug.h>
 #include <kicon.h>
@@ -61,7 +63,8 @@
 {
 
 //ugly wrapper class for adding an operator< to the Plugin class
-
+//currently unused, no sorting
+/*
 class PluginProxy
 {
   public:
@@ -92,401 +95,180 @@
   private:
     Plugin *mPlugin;
 };
-
+*/
 } //namespace
 
 using namespace Kontact;
 
-EntryItem::EntryItem( Navigator *parent, Kontact::Plugin *plugin )
-  : Q3ListBoxItem( parent ),
-    mPlugin( plugin ),
-    mHasHover( false ),
-    mPaintActive( false )
+Navigator::Navigator( SidePaneBase *parent )
+  : KToolBar( parent )
 {
-  reloadPixmap();
-  setCustomHighlighting( true );
-  setText( plugin->title() );
-}
+  mSidePane = parent;
+  mLastAction = 0;
 
-EntryItem::~EntryItem()
-{
-}
+  setOrientation ( Qt::Vertical );
+  setContextMenuPolicy( Qt::CustomContextMenu );
+  restorePreferences();
 
-void EntryItem::reloadPixmap()
-{
-  int size = (int)navigator()->viewMode();
-  if ( size != 0 )
-    mPixmap = KIconLoader::global()->loadIcon( mPlugin->icon(),
-                                                KIconLoader::Desktop, size,
-                                                mPlugin->disabled() ?
-                                                  KIconLoader::DisabledState
-                                                : KIconLoader::DefaultState);
-  else
-    mPixmap = QPixmap();
+  connect( this, SIGNAL( actionTriggered ( QAction * ) ), 
+           this, SLOT( slotExecuted( QAction* ) ) );
+  connect( this, SIGNAL( customContextMenuRequested( const QPoint & ) ), 
+           this, SLOT( slotShowRMBMenu( const QPoint & ) ) );
 }
 
-Navigator* EntryItem::navigator() const
+Navigator::~Navigator()
 {
-  return static_cast<Navigator*>( listBox() );
 }
 
-int EntryItem::width( const Q3ListBox *listbox ) const
+void Navigator::restorePreferences()
 {
-  int w = 0;
-  if( navigator()->showIcons() ) {
-    w = navigator()->viewMode();
-    if ( navigator()->viewMode() == SmallIcons )
-      w += 4;
+  if(Prefs::self()->sidePaneShowIcons()){
+    if(Prefs::self()->sidePaneShowText()){
+      setToolButtonStyle( Qt::ToolButtonTextUnderIcon );    
+    }else{
+      setToolButtonStyle( Qt::ToolButtonIconOnly );    
+    }
+  }else{
+      setToolButtonStyle( Qt::ToolButtonTextOnly );    
   }
-  if( navigator()->showText() ) {
-    if ( navigator()->viewMode() == SmallIcons )
-      w += listbox->fontMetrics().width( text() );
-    else
-      w = qMax( w, listbox->fontMetrics().width( text() ) );
-  }
-  return w + ( KDialog::marginHint() * 2 );
+
+  setIconDimensions( Prefs::self()->sidePaneIconSize() );
+  parentWidget()->setMaximumWidth( sizeHint().width() );
 }
 
-int EntryItem::height( const Q3ListBox *listbox ) const
+void Navigator::selectPlugin( Kontact::Plugin *plugin )
 {
-  int h = 0;
-  if ( navigator()->showIcons() )
-    h = (int)navigator()->viewMode() + 4;
-  if ( navigator()->showText() ) {
-    if ( navigator()->viewMode() == SmallIcons || !navigator()->showIcons() )
-      h = qMax( h, listbox->fontMetrics().lineSpacing() ) + KDialog::spacingHint() * 2;
-    else
-      h = (int)navigator()->viewMode() + listbox->fontMetrics().lineSpacing() + 4;
+  int index = mPlugins.indexOf( plugin );
+  QList<QAction *> actlist = actions();
+  for( QList<QAction *>::ConstIterator it = actlist.begin();
+       it != actlist.end(); it++ ){
+    if( (*it)->data() == index ){
+      if( mLastAction != 0 )
+	mLastAction->setChecked( false );
+      (*it)->setChecked( true );
+      mLastAction = (*it);
+      return;
+    }
   }
-  return h;
 }
 
-void EntryItem::paint( QPainter *p )
+void Navigator::selectPlugin( const QString &name )
 {
-  reloadPixmap();
-
-  Q3ListBox *box = listBox();
-  bool iconAboveText = ( navigator()->viewMode() > SmallIcons )
-                     && navigator()->showIcons();
-  int w = box->viewport()->width();
-  int y = iconAboveText ? 2 :
-                        ( ( height( box ) - mPixmap.height() ) / 2 );
-
-  // draw selected
-  if ( isCurrent() || isSelected() || mHasHover || mPaintActive ) {
-    int h = height( box );
-
-    QBrush brush;
-    if ( isCurrent() || isSelected() || mPaintActive )
-      brush = box->palette().color( QPalette::Highlight );
-    else
-      brush = QBrush( box->palette().color( QPalette::Highlight ).light( 115 ) );
-    p->fillRect( 1, 0, w - 2, h - 1, brush );
-    QPen pen = p->pen();
-    QPen oldPen = pen;
-    pen.setColor( box->palette().color( QPalette::Mid ) );
-    p->setPen( pen );
-
-    p->drawPoint( 1, 0 );
-    p->drawPoint( 1, h - 2 );
-    p->drawPoint( w - 2, 0 );
-    p->drawPoint( w - 2, h - 2 );
-
-    p->setPen( oldPen );
-  }
-
-  if ( !mPixmap.isNull() && navigator()->showIcons() ) {
-      int x = iconAboveText ? ( ( w - mPixmap.width() ) / 2 ) :
-                              KDialog::marginHint();
-    p->drawPixmap( x, y, mPixmap );
-  }
-
-  QColor shadowColor = listBox()->palette().color( QPalette::Background ).dark(115);
-  if ( isCurrent() || isSelected() ) {
-    p->setPen( box->palette().color( QPalette::HighlightedText ) );
-  }
-
-  if ( !text().isEmpty() && navigator()->showText() ) {
-    QFontMetrics fm = p->fontMetrics();
-
-    int x = 0;
-    if ( iconAboveText ) {
-      x = ( w - fm.width( text() ) ) / 2;
-      y += fm.height() - fm.descent();
-      if ( navigator()->showIcons() )
-        y += mPixmap.height();
-    } else {
-      x = KDialog::marginHint() + 4;
-      if( navigator()->showIcons() ) {
-        x += mPixmap.width();
-      }
-
-      if ( !navigator()->showIcons() || mPixmap.height() < fm.height() )
-        y = height( box )/2 - fm.height()/2 + fm.ascent();
-      else
-        y += mPixmap.height()/2 - fm.height()/2 + fm.ascent();
+  for( QList<Plugin *>::ConstIterator it = mPlugins.begin();
+       it != mPlugins.end(); it++ ){
+    if( (*it)->title() == name){
+      selectPlugin( *it );
+      return;
     }
-
-    if ( plugin()->disabled() ) {
-      p->setPen( box->palette().disabled().text( ) );
-    } else if ( isCurrent() || isSelected() || mHasHover ) {
-      p->setPen( box->palette().color( QPalette::Highlight ).dark(115) );
-      p->drawText( x + ( QApplication::isRightToLeft() ? -1 : 1),
-          y + 1, text() );
-      p->setPen( box->palette().color( QPalette::HighlightedText ) );
-    }
-    else
-      p->setPen( box->palette().color( QPalette::Text ) );
-
-    p->drawText( x, y, text() );
   }
-
-  // ensure that we don't have a stale flag around
-  if (  isCurrent() || isSelected() ) mHasHover = false;
 }
 
-void EntryItem::setHover( bool hasHover )
+void Navigator::disablePlugin( Kontact::Plugin *plugin )
 {
-  mHasHover = hasHover;
+  int index = mPlugins.indexOf( plugin );
+  QList<QAction *> actlist = actions();
+  for( QList<QAction *>::ConstIterator it = actlist.begin();
+       it != actlist.end(); it++ ){
+    if( (*it) ->data() == index){
+      (*it)->setEnabled( false );
+      return;
+    }
+  }
 }
 
-void EntryItem::setPaintActive( bool paintActive )
+void Navigator::enablePlugin( Kontact::Plugin *plugin )
 {
-  mPaintActive = paintActive;
+  int index = mPlugins.indexOf( plugin );
+  QList<QAction *> actlist = actions();
+  for( QList<QAction *>::ConstIterator it = actlist.begin();
+       it != actlist.end(); it++ ){
+    if( (*it)->data() == index){
+      (*it)->setEnabled( true );
+      return;
+    }
+  }
 }
 
-Navigator::Navigator( SidePaneBase *parent, const char *name )
-  : K3ListBox( parent, name ), mSidePane( parent ),
-    mShowIcons( true ), mShowText( true )
+void Navigator::updatePlugins( QList<Kontact::Plugin*> plugins )
 {
-  mMouseOn = 0;
-  mHighlightItem = 0;
-  mViewMode = sizeIntToEnum( Prefs::self()->sidePaneIconSize() );
-  mShowIcons = Prefs::self()->sidePaneShowIcons();
-  mShowText = Prefs::self()->sidePaneShowText();
-  setSelectionMode( K3ListBox::Single );
-  viewport()->setBackgroundRole( QPalette::Background );
-  setHScrollBarMode( Q3ScrollView::AlwaysOff );
-  setAcceptDrops( true );
-
-  setFocusPolicy( Qt::NoFocus );
-
-  connect( this, SIGNAL( selectionChanged( Q3ListBoxItem* ) ),
-           SLOT( slotExecuted( Q3ListBoxItem* ) ) );
-  connect( this, SIGNAL( rightButtonPressed( Q3ListBoxItem*, const QPoint& ) ),
-           SLOT( slotShowRMBMenu( Q3ListBoxItem*, const QPoint& ) ) );
-  connect( this, SIGNAL( onItem( Q3ListBoxItem * ) ),
-            SLOT(  slotMouseOn( Q3ListBoxItem * ) ) );
-  connect( this, SIGNAL( onViewport() ), SLOT(  slotMouseOff() ) );
-
-  mMapper = new QSignalMapper( this );
-  connect( mMapper, SIGNAL( mapped( int ) ), SLOT( shortCutSelected( int ) ) );
-
-  this->setToolTip("");
-#ifdef __GNUC__
-#warning Port me!
-#endif
-//  if ( !mShowText )
-//    new EntryItemToolTip( this );
-
-}
-
-QSize Navigator::sizeHint() const
-{
-  return QSize( 100, 100 );
-}
-
-void Navigator::highlightItem( EntryItem * item )
-{
-  mHighlightItem = item;
-
-  setPaintActiveItem( mHighlightItem, true );
-
-  QTimer::singleShot( 2000, this, SLOT( slotStopHighlight() ) );
-}
-
-void Navigator::slotStopHighlight()
-{
-  setPaintActiveItem( mHighlightItem, false );
-}
-
-void Navigator::setSelected( Q3ListBoxItem *item, bool selected )
-{
-  // Reimplemented to avoid the immediate activation of
-  // the item. might turn out it doesn't work, we check that
-  // an confirm from MainWindow::selectPlugin()
-  if ( selected ) {
-    EntryItem *entry = static_cast<EntryItem*>( item );
-    emit pluginActivated( entry->plugin() );
+  QList<QAction *> actlist = actions();
+  for( QList<QAction *>::ConstIterator it = actlist.begin();
+       it != actlist.end(); it++ ){
+    delete *it;
   }
-}
 
-void Navigator::updatePlugins( QList<Kontact::Plugin*> plugins_ )
-{
-  QList<Kontact::PluginProxy> plugins;
-  QList<Kontact::Plugin*>::ConstIterator end_ = plugins_.end();
-  QList<Kontact::Plugin*>::ConstIterator it_ = plugins_.begin();
-  for ( ; it_ != end_; ++it_ )
-    plugins += PluginProxy( *it_ );
-
   clear();
-
-  qDeleteAll( mActions );
-  mActions.clear();
-
-  int counter = 0;
-  int minWidth = 0;
-#ifdef __GNUC__
-#warning Port me!
-#endif
-//  qSort( plugins );
-  QList<Kontact::PluginProxy>::ConstIterator end = plugins.end();
-  QList<Kontact::PluginProxy>::ConstIterator it = plugins.begin();
-  for ( ; it != end; ++it ) {
-    Kontact::Plugin *plugin = ( *it ).plugin();
-    if ( !plugin->showInSideBar() )
+  mPlugins.clear();
+  QList<Kontact::Plugin*>::ConstIterator end = plugins.end();
+  QList<Kontact::Plugin*>::ConstIterator it = plugins.begin();
+  int counter = 0; //Counts added items
+  int index = -1; //Counts iterated plugins
+  for ( ; it != end; ++it ){
+    index++;
+    Kontact::Plugin *plugin = *it;
+    mPlugins += plugin;
+    if ( !plugin->showInSideBar() ){
       continue;
+    }
+    QAction* action = new QAction( KIcon( plugin->icon() ),
+      i18n( (char *)plugin->title().toUtf8().data() ), this);
+    action->setEnabled( !plugin->disabled() );
+    action->setCheckable( true );
+    action->setData( index );
+    if( counter < 9 ){
+      QString shortcut = QString( "Ctrl+%1" ).arg( counter + 1 );
+      action->setShortcut( QKeySequence( shortcut ) );
+      action->setToolTip( shortcut );
+    }
 
-    EntryItem *item = new EntryItem( this, plugin );
-    item->setSelectable( !plugin->disabled() );
+    kDebug(5600) << "action added, title: " << plugin->title() << ", icon: " << plugin->icon();
 
-    if ( item->width( this ) > minWidth )
-      minWidth = item->width( this );
-
-    QString name = QString( "CTRL+%1" ).arg( counter + 1 );
-    KAction *action = new KAction(KIcon(plugin->icon()),  plugin->title(), this);
-    mSidePane->actionCollection()->addAction(name.toLatin1(), action);
-    connect(action, SIGNAL(triggered(bool) ), mMapper, SLOT( map() ));
-    action->setShortcut(KShortcut( name ));
-    mActions.append( action );
-    mMapper->setMapping( action, counter );
+    addAction(action);
     counter++;
   }
 
-  parentWidget()->setFixedWidth( minWidth );
+  restorePreferences();
 }
 
-void Navigator::dragEnterEvent( QDragEnterEvent *event )
+void Navigator::slotExecuted( QAction* action )
 {
-  kDebug(5600) <<"Navigator::dragEnterEvent()";
+  int index = action->data().toInt();
 
-  dragMoveEvent( event );
-}
-
-void Navigator::dragMoveEvent( QDragMoveEvent *event )
-{
-  kDebug(5600) <<"Navigator::dragEnterEvent()";
-
-  kDebug(5600) <<"  Format:" << event->format();
-
-  Q3ListBoxItem *item = itemAt( event->pos() );
-
-  if ( !item ) {
-    event->setAccepted( false );
-    return;
+  if( index < mPlugins.size() ){
+    if( mLastAction != 0 )
+      mLastAction->setChecked( false );
+    emit pluginActivated( mPlugins.value(index) );
+    mLastAction = action;
   }
-
-  EntryItem *entry = static_cast<EntryItem*>( item );
-
-  kDebug(5600) <<"  PLUGIN:" << entry->plugin()->identifier();
-
-  event->setAccepted( entry->plugin()->canDecodeMimeData( event->mimeData() ) );
 }
 
-void Navigator::dropEvent( QDropEvent *event )
+void Navigator::slotShowRMBMenu( const QPoint& pos )
 {
-  kDebug(5600) <<"Navigator::dropEvent()";
-
-  Q3ListBoxItem *item = itemAt( event->pos() );
-
-  if ( !item ) {
-    return;
-  }
-
-  EntryItem *entry = static_cast<EntryItem*>( item );
-
-  kDebug(5600) <<"  PLUGIN:" << entry->plugin()->identifier();
-
-  entry->plugin()->processDropEvent( event );
-}
-
-void Navigator::resizeEvent( QResizeEvent *event )
-{
-  Q3ListBox::resizeEvent( event );
-  triggerUpdate( true );
-}
-
-void Navigator::enterEvent( QEvent *event )
-{
-  // work around Qt behaviour: onItem is not emmitted in enterEvent()
-  K3ListBox::enterEvent( event );
-  emit onItem( itemAt( mapFromGlobal( QCursor::pos() ) ) );
-}
-
-void Navigator::leaveEvent( QEvent *event )
-{
-  K3ListBox::leaveEvent( event );
-  slotMouseOn( 0 );
-  mMouseOn = 0;
-}
-
-void Navigator::slotExecuted( Q3ListBoxItem *item )
-{
-  if ( !item )
-    return;
-
-  EntryItem *entry = static_cast<EntryItem*>( item );
-
-  emit pluginActivated( entry->plugin() );
-}
-
-IconViewMode Navigator::sizeIntToEnum(int size) const
-{
-  switch ( size ) {
-    case int(LargeIcons):
-      return LargeIcons;
-      break;
-    case int(NormalIcons):
-      return NormalIcons;
-      break;
-    case int(SmallIcons):
-      return SmallIcons;
-      break;
-    default:
-      // Stick with sane values
-      return NormalIcons;
-      kDebug() <<"View mode not implemented!";
-      break;
-  }
-}
-
-void Navigator::slotShowRMBMenu( Q3ListBoxItem *, const QPoint &pos )
-{
   KMenu menu( i18n( "Icon Size" ) );
 
   QAction *large = menu.addAction( i18n( "Large" ) );
-  large->setEnabled( mShowIcons );
+  large->setEnabled( Prefs::self()->sidePaneShowIcons() );
   large->setCheckable( true );
-  large->setChecked( mViewMode == LargeIcons );
+  large->setChecked( Prefs::self()->sidePaneIconSize() == KIconLoader::SizeLarge );
   QAction *normal = menu.addAction( i18n( "Normal" ) );
-  normal->setEnabled( mShowIcons );
+  normal->setEnabled( Prefs::self()->sidePaneShowIcons() );
   normal->setCheckable( true );
-  normal->setChecked( mViewMode == NormalIcons );
+  normal->setChecked( Prefs::self()->sidePaneIconSize() == KIconLoader::SizeMedium );
   QAction *small = menu.addAction( i18n( "Small" ) );
-  small->setEnabled( mShowIcons );
+  small->setEnabled( Prefs::self()->sidePaneShowIcons() );
   small->setCheckable( true );
-  small->setChecked( mViewMode == SmallIcons );
+  small->setChecked( Prefs::self()->sidePaneIconSize() == KIconLoader::SizeSmallMedium );
 
   menu.addSeparator();
 
   QAction *showIcons = menu.addAction( i18n( "Show Icons" ) );
   showIcons->setCheckable( true );
-  showIcons->setChecked( mShowIcons );
-  showIcons->setEnabled( mShowText );
+  showIcons->setChecked( Prefs::self()->sidePaneShowIcons() );
+  showIcons->setEnabled( Prefs::self()->sidePaneShowText() );
   QAction *showText = menu.addAction( i18n( "Show Text" ) );
   showText->setCheckable( true );
-  showText->setChecked( mShowText );
-  showText->setEnabled( mShowIcons );
+  showText->setChecked( Prefs::self()->sidePaneShowText() );
+  showText->setEnabled( Prefs::self()->sidePaneShowIcons() );
 
   QAction *choice = menu.exec( pos );
 
@@ -494,82 +276,25 @@
     return;
 
   if ( choice == large ) {
-    mViewMode = sizeIntToEnum( LargeIcons );
-    Prefs::self()->setSidePaneIconSize( LargeIcons );
+    Prefs::self()->setSidePaneIconSize( KIconLoader::SizeLarge );
   } else if ( choice == normal ) {
-    mViewMode = sizeIntToEnum( NormalIcons );
-    Prefs::self()->setSidePaneIconSize( NormalIcons );
+    Prefs::self()->setSidePaneIconSize( KIconLoader::SizeMedium );
   } else if ( choice == small ) {
-    mViewMode = sizeIntToEnum( SmallIcons );
-    Prefs::self()->setSidePaneIconSize( SmallIcons );
+    Prefs::self()->setSidePaneIconSize( KIconLoader::SizeSmallMedium );
   } else if ( choice == showIcons ) {
-    mShowIcons = !mShowIcons;
-    Prefs::self()->setSidePaneShowIcons( mShowIcons );
+    Prefs::self()->setSidePaneShowIcons( !Prefs::self()->sidePaneShowIcons() );
   } else if ( choice == showText ) {
-    mShowText = !mShowText;
-    Prefs::self()->setSidePaneShowText( mShowText );
+    Prefs::self()->setSidePaneShowText( !Prefs::self()->sidePaneShowText() );
   }
-
-  int maxWidth = 0;
-  Q3ListBoxItem* it = 0;
-  for (int i = 0; (it = item(i)) != 0; ++i)
-  {
-    int width = it->width(this);
-    if (width > maxWidth)
-      maxWidth = width;
-  }
-  parentWidget()->setFixedWidth( maxWidth );
-
-  triggerUpdate( true );
+  restorePreferences();
 }
 
-void Navigator::shortCutSelected( int pos )
-{
-  setCurrentItem( pos );
-}
-
-void Navigator::setHoverItem( Q3ListBoxItem* item, bool hover )
-{
-    static_cast<EntryItem*>( item )->setHover( hover );
-    updateItem( item );
-}
-
-void Navigator::setPaintActiveItem( Q3ListBoxItem* item, bool paintActive )
-{
-    static_cast<EntryItem*>( item )->setPaintActive( paintActive );
-    updateItem( item );
-}
-
-void Navigator::slotMouseOn( Q3ListBoxItem* newItem )
-{
-  Q3ListBoxItem* oldItem = mMouseOn;
-  if ( oldItem == newItem ) return;
-
-  if ( oldItem && !oldItem->isCurrent() && !oldItem->isSelected() )
-  {
-    setHoverItem( oldItem, false );
-  }
-
-  if ( newItem && !newItem->isCurrent() && !newItem->isSelected() )
-  {
-    setHoverItem( newItem, true );
-  }
-  mMouseOn = newItem;
-}
-
-void Navigator::slotMouseOff()
-{
-  slotMouseOn( 0 );
-}
-
 IconSidePane::IconSidePane( Core *core, QWidget *parent )
   : SidePaneBase( core, parent )
 {
   mNavigator = new Navigator( this );
   connect( mNavigator, SIGNAL( pluginActivated( Kontact::Plugin* ) ),
            SIGNAL( pluginSelected( Kontact::Plugin* ) ) );
-
-  setAcceptDrops( true );
 }
 
 IconSidePane::~IconSidePane()
@@ -583,47 +308,17 @@
 
 void IconSidePane::selectPlugin( Kontact::Plugin *plugin )
 {
-  bool blocked = signalsBlocked();
-  blockSignals( true );
-
-  for ( uint i = 0; i < mNavigator->count(); ++i ) {
-    EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
-    if ( item->plugin() == plugin ) {
-      mNavigator->setCurrentItem( i );
-      break;
-    }
-  }
-
-  blockSignals( blocked );
+  mNavigator->selectPlugin( plugin );
 }
 
 void IconSidePane::selectPlugin( const QString &name )
 {
-  bool blocked = signalsBlocked();
-  blockSignals( true );
-
-  for ( uint i = 0; i < mNavigator->count(); ++i ) {
-    EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
-    if ( item->plugin()->identifier() == name ) {
-      mNavigator->setCurrentItem( i );
-      break;
-    }
-  }
-
-  blockSignals( blocked );
+  mNavigator->selectPlugin( name );
 }
 
-void IconSidePane::indicateForegrunding( Kontact::Plugin *plugin )
+void IconSidePane::indicateForegrounding( Kontact::Plugin *plugin )
 {
-  for ( uint i = 0; i < mNavigator->count(); ++i ) {
-    EntryItem *item = static_cast<EntryItem*>( mNavigator->item( i ) );
-    if ( item->plugin() == plugin ) {
-      mNavigator->highlightItem( item );
-      break;
-    }
-  }
-
-
+  mNavigator->disablePlugin( plugin );
 }
 #include "iconsidepane.moc"
 
Index: sidepanebase.h
===================================================================
--- sidepanebase.h	(Revision 770947)
+++ sidepanebase.h	(Arbeitskopie)
@@ -40,11 +40,6 @@
     SidePaneBase( Core *core, QWidget *parent );
     virtual ~SidePaneBase();
 
-    void setActionCollection( KActionCollection *actionCollection );
-    KActionCollection *actionCollection() const;
-
-    virtual const QList<QAction*> & actions() = 0;
-
   signals:
     void pluginSelected( Kontact::Plugin* );
 
@@ -67,13 +62,12 @@
      */
     virtual void selectPlugin( const QString &name ) = 0;
 
-    virtual void indicateForegrunding( Kontact::Plugin* ) = 0;
+    virtual void indicateForegrounding( Kontact::Plugin* ) = 0;
   protected:
     Core* core() const;
 
   private:
     Core* mCore;
-    KActionCollection *mActionCollection;
 };
 
 }
Index: sidepanebase.cpp
===================================================================
--- sidepanebase.cpp	(Revision 770947)
+++ sidepanebase.cpp	(Arbeitskopie)
@@ -39,14 +39,4 @@
   return mCore;
 }
 
-void SidePaneBase::setActionCollection( KActionCollection *actionCollection )
-{
-  mActionCollection = actionCollection;
-}
-
-KActionCollection *SidePaneBase::actionCollection() const
-{
-  return mActionCollection;
-}
-
 #include "sidepanebase.moc"

["signature.asc" (application/pgp-signature)]

_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic