[Kde-pim] KDE/kdepim/kontact/src

Rafael Fernández López ereslibre at kde.org
Mon Jun 9 00:02:05 BST 2008


SVN commit 818605 by ereslibre:

The sidebar needed lots of intrinsec logic for working properly. This fixes the problem of a huge sidebar when the environment is clean (aka. "new user" test). This also fixes some problems with
layouts. Now the sidebar will automagically adopt the needed size, and the only thing one can do with the slider is to hide or show it. I have double reviewed it is correct with the kde pim coding
style, but if something is wrong, please tell me.

CCMAIL: kde-pim at kde.org


 M  +32 -13    iconsidepane.cpp  
 M  +2 -0      iconsidepane.h  
 M  +12 -13    mainwindow.cpp  


--- trunk/KDE/kdepim/kontact/src/iconsidepane.cpp #818604:818605
@@ -30,6 +30,7 @@
 #include <QtGui/QDragEnterEvent>
 #include <QtGui/QDragMoveEvent>
 #include <QtGui/QStyledItemDelegate>
+#include <QtGui/QScrollBar>
 
 #include <KLocalizedString>
 #include <KDialog>
@@ -147,24 +148,17 @@
       QStyleOptionViewItemV4 optionCopy( *static_cast<const QStyleOptionViewItemV4*>( &option ) );
       optionCopy.decorationPosition = QStyleOptionViewItem::Top;
       optionCopy.decorationSize = QSize( mNavigator->iconSize(), mNavigator->iconSize() );
+      optionCopy.textElideMode = Qt::ElideNone;
       QStyledItemDelegate::paint( painter, optionCopy, index );
     }
 
     QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
     {
-      QString title = index.model()->data( index ).toString();
-
-      if ( !mNavigator->showText() ) {
-        return QSize( mNavigator->iconSize(), mNavigator->iconSize() + KDialog::spacingHint() );
-      }
-
-      if ( !mNavigator->showIcons() ) {
-        return QSize( option.fontMetrics.width( title ),
-                      option.fontMetrics.height() + KDialog::spacingHint() );
-      }
-
-      return QSize( qMax( mNavigator->iconSize(), option.fontMetrics.width( title ) ),
-                   mNavigator->iconSize() + option.fontMetrics.height() + KDialog::spacingHint() );
+      QStyleOptionViewItemV4 optionCopy( *static_cast<const QStyleOptionViewItemV4*>( &option ) );
+      optionCopy.decorationPosition = QStyleOptionViewItem::Top;
+      optionCopy.decorationSize = mNavigator->showIcons() ? QSize( mNavigator->iconSize(), mNavigator->iconSize() ) : QSize();
+      optionCopy.textElideMode = Qt::ElideNone;
+      return QStyledItemDelegate::sizeHint(optionCopy, index);
     }
 
   private:
@@ -274,6 +268,28 @@
   }
 }
 
+QSize Navigator::sizeHint() const
+{
+  //### TODO: We can cache this value, so this reply is faster. Since here we won't
+  //          have too many elements, it is not that important. When caching this value
+  //          make sure it is updated correctly when new rows have been added or
+  //          removed. (ereslibre)
+
+  int maxWidth = 0;
+  for ( int i = 0; i < model()->rowCount(); i++ ) {
+    const QModelIndex index = model()->index( i, 0 );
+    maxWidth = qMax( maxWidth, sizeHintForIndex( index ).width() );
+  }
+
+  if ( !verticalScrollBar()->isVisible() ) {
+    maxWidth += style()->pixelMetric( QStyle::PM_ScrollBarExtent ) * 2;
+  }
+
+  int viewHeight = QListView::sizeHint().height();
+
+  return QSize( maxWidth + rect().width() - contentsRect().width(), viewHeight );
+}
+
 void Navigator::dragEnterEvent( QDragEnterEvent *event )
 {
   if ( event->proposedAction() == Qt::IgnoreAction ) {
@@ -365,6 +381,9 @@
   Prefs::self()->setSidePaneShowText( mShowText );
 
   scheduleDelayedItemsLayout();
+
+  parentWidget()->setMaximumWidth( sizeHint().width() );
+  parentWidget()->setMinimumWidth( sizeHint().width() );
 }
 
 IconSidePane::IconSidePane( Core *core, QWidget *parent )
--- trunk/KDE/kdepim/kontact/src/iconsidepane.h #818604:818605
@@ -67,6 +67,8 @@
       return mShowText;
     }
 
+    virtual QSize sizeHint() const;
+
   signals:
     void pluginActivated( Kontact::Plugin *plugin );
 
--- trunk/KDE/kdepim/kontact/src/mainwindow.cpp #818604:818605
@@ -143,8 +143,8 @@
 }
 
 MainWindow::MainWindow()
-  : Kontact::Core(), mTopWidget( 0 ), mSplitter( 0 ),
-    mCurrentPlugin( 0 ), mAboutDialog( 0 ), mReallyClose( false ), mSyncActionsEnabled( true )
+  : Kontact::Core(), mSplitter( 0 ), mCurrentPlugin( 0 ), mAboutDialog( 0 ),
+    mReallyClose( false ), mSyncActionsEnabled( true )
 {
   // The ServiceStarter created here will be deleted by the KDbusServiceStarter
   // base class, which is a global static.
@@ -159,6 +159,9 @@
 
   initGUI();
   initObject();
+
+  mSidePane->setMaximumWidth( mSidePane->sizeHint().width() );
+  mSidePane->setMinimumWidth( mSidePane->sizeHint().width() );
 }
 
 void MainWindow::initGUI()
@@ -267,16 +270,14 @@
 
 void MainWindow::initWidgets()
 {
-  // includes sidebar and part stack
-  mTopWidget = new KHBox( this );
-  mTopWidget->setFrameStyle( QFrame::NoFrame );
+  QWidget *mTopWidget = new QWidget( this );
+  QVBoxLayout *layout = new QVBoxLayout;
+  mTopWidget->setLayout( layout );
   setCentralWidget( mTopWidget );
 
-  KHBox *mBox = 0;
   mSplitter = new QSplitter( mTopWidget );
-  mBox = new KHBox( mTopWidget );
+  layout->addWidget( mSplitter );
   mSidePane = new IconSidePane( this, mSplitter );
-  mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
 /*
   // don't occupy screen estate on load
 
@@ -287,11 +288,7 @@
   connect( mSidePane, SIGNAL(pluginSelected(Kontact::Plugin *)),
            SLOT(selectPlugin(Kontact::Plugin *)) );
 
-  KVBox *vBox = new KVBox( mSplitter );
-
-  vBox->setSpacing( 0 );
-
-  mPartsStack = new QStackedWidget( vBox );
+  mPartsStack = new QStackedWidget( mSplitter );
   mPartsStack->layout()->setSpacing( 0 );
 
   initAboutScreen();
@@ -315,6 +312,8 @@
   statusBar()->addWidget( mStatusMsgLabel, 10 );
   statusBar()->addPermanentWidget( mLittleProgress, 0 );
   mLittleProgress->show();
+
+  mSplitter->setCollapsible( 1, false );
 }
 
 void MainWindow::paintAboutScreen( const QString &msg )
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list