Commit 0e2ac4b5 authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Allow for changing the sidebars icon size via RMB Menu. This implementation has two issues:

- RMB can trigger part loading (qlistbox bug I assume)
- I found cases where redraw doesn't happen properly. Working on that

Also, the icon size defaults to 32x32 now, to keep the sidebar free of scrollbars in the common case.

svn path=/trunk/kdepim/; revision=374336
parent 3e5719ed
......@@ -32,8 +32,8 @@
#include <qframe.h>
#include <qdrawutil.h>
#include <kpopupmenu.h>
#include <kapplication.h>
#include <kconfig.h>
#include <klocale.h>
#include <kiconloader.h>
#include <sidebarextension.h>
......@@ -44,6 +44,7 @@
#include "plugin.h"
#include "prefs.h"
#include "iconsidepane.h"
namespace Kontact
......@@ -85,12 +86,11 @@ private:
using namespace Kontact;
EntryItem::EntryItem( QListBox *parent, Kontact::Plugin *plugin )
EntryItem::EntryItem( Navigator *parent, Kontact::Plugin *plugin )
: QListBoxItem( parent ),
mPlugin( plugin )
{
mPixmap = KGlobal::iconLoader()->loadIcon( plugin->icon(),
KIcon::Desktop, 48 );
reloadPixmap();
setCustomHighlighting( true );
setText( plugin->title() );
}
......@@ -99,13 +99,28 @@ EntryItem::~EntryItem()
{
}
void EntryItem::reloadPixmap()
{
int size = (int)navigator()->viewMode();
if (size != 0)
mPixmap = KGlobal::iconLoader()->loadIcon( mPlugin->icon(),
KIcon::Desktop, size );
else
mPixmap = QPixmap();
}
Navigator* EntryItem::navigator() const
{
return static_cast<Navigator*>(listBox());
}
int EntryItem::width( const QListBox *listbox) const
{
int w;
if ( text().isEmpty() )
w = mPixmap.width();
else
w = QMAX( mPixmap.width(), listbox->fontMetrics().width( text() ) );
w = QMAX( (int)navigator()->viewMode(), listbox->fontMetrics().width( text() ) );
return w + 36;
}
......@@ -116,13 +131,15 @@ int EntryItem::height( const QListBox *listbox) const
if ( text().isEmpty() )
h = mPixmap.height();
else
h = mPixmap.height() + listbox->fontMetrics().lineSpacing();
h = (int)navigator()->viewMode() + listbox->fontMetrics().lineSpacing();
return h + 4;
}
void EntryItem::paint( QPainter *p )
{
reloadPixmap();
QListBox *box = listBox();
int w = box->viewport()->width();
int y = 2;
......@@ -157,14 +174,18 @@ void EntryItem::paint( QPainter *p )
Navigator::Navigator( SidePaneBase *parent, const char *name)
: KListBox( parent, name ), mSidePane( parent )
{
mViewMode = sizeIntToEnum( Prefs::self()->sidePaneIconSize() );
setSelectionMode( KListBox::Single );
viewport()->setBackgroundMode( PaletteMid );
setHScrollBarMode( QScrollView::AlwaysOff );
setAcceptDrops( true );
connect( this, SIGNAL( currentChanged( QListBoxItem * ) ),
connect( this, SIGNAL( selectionChanged( QListBoxItem * ) ),
SLOT( slotExecuted( QListBoxItem * ) ) );
connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint& ) ),
SLOT( slotShowRMBMenu( QListBoxItem *, const QPoint& ) ) );
mMapper = new QSignalMapper( this );
connect( mMapper, SIGNAL( mapped( int ) ), SLOT( shortCutSelected( int ) ) );
}
......@@ -176,7 +197,7 @@ QSize Navigator::sizeHint() const
void Navigator::setSelected( QListBoxItem *i, bool sel )
{
// Reimplmemented to avoid the immediate activation of
// 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 (sel) {
......@@ -225,15 +246,6 @@ void Navigator::updatePlugins( QValueList<Kontact::Plugin*> plugins_ )
parentWidget()->setFixedWidth( minWidth );
}
void Navigator::slotExecuted( QListBoxItem *item )
{
if ( !item ) return;
EntryItem *entry = static_cast<EntryItem *>( item );
emit pluginActivated( entry->plugin() );
}
void Navigator::dragEnterEvent( QDragEnterEvent *event )
{
kdDebug(5600) << "Navigator::dragEnterEvent()" << endl;
......@@ -278,12 +290,62 @@ void Navigator::dropEvent( QDropEvent *event )
entry->plugin()->processDropEvent( event );
}
void Navigator::resizeEvent( QResizeEvent *event )
{
QListBox::resizeEvent( event );
triggerUpdate( true );
}
void Navigator::slotExecuted( QListBoxItem *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;
case int(TextOnly):
return TextOnly;
break;
default:
// Stick with sane values
return NormalIcons;
kdDebug() << "View mode not implemented!" << endl;
break;
}
}
void Navigator::slotShowRMBMenu( QListBoxItem *, const QPoint& pos )
{
KPopupMenu menu;
menu.insertTitle( i18n("Icon size") );
menu.insertItem( i18n("Large"), (int)LargeIcons );
menu.insertItem( i18n("Nomal "), (int)NormalIcons );
menu.insertItem( i18n("Small"), (int)SmallIcons );
menu.insertItem( i18n("Text only"), (int)TextOnly );
int choice = menu.exec( pos );
mViewMode = sizeIntToEnum(choice);
Prefs::self()->setSidePaneIconSize( choice );
triggerUpdate( true );
}
void Navigator::shortCutSelected( int pos )
{
setCurrentItem( pos );
......
......@@ -25,8 +25,6 @@
#include <klistbox.h>
#include <qlistbox.h>
class QSignalMapper;
namespace KParts { class Part; }
......@@ -36,21 +34,26 @@ namespace Kontact
class Core;
class Plugin;
class Navigator;
enum IconViewMode { LargeIcons = 48, NormalIcons = 32, SmallIcons = 16, TextOnly = 0 };
/**
A @see QListBoxPixmap Square Box with a large icon and a text
A @see QListBoxPixmap Square Box with an optional icon and a text
underneath.
*/
class EntryItem : public QListBoxItem
{
public:
EntryItem( QListBox *, Kontact::Plugin * );
EntryItem( Navigator *, Kontact::Plugin * );
~EntryItem();
Kontact::Plugin *plugin() const { return mPlugin; }
const QPixmap *pixmap() const { return &mPixmap; }
Navigator* navigator() const;
/**
returns the width of this item.
*/
......@@ -61,6 +64,8 @@ class EntryItem : public QListBoxItem
virtual int height( const QListBox * ) const;
protected:
void reloadPixmap();
virtual void paint( QPainter *p );
private:
......@@ -82,22 +87,26 @@ class Navigator : public KListBox
void updatePlugins( QValueList<Kontact::Plugin*> plugins );
QSize sizeHint() const;
IconViewMode viewMode() { return mViewMode; }
IconViewMode sizeIntToEnum(int size) const;
signals:
void pluginActivated( Kontact::Plugin * );
protected:
void dragEnterEvent( QDragEnterEvent * );
void dragMoveEvent ( QDragMoveEvent * );
void dropEvent( QDropEvent * );
void resizeEvent( QResizeEvent * );
private slots:
void slotExecuted( QListBoxItem *item );
protected slots:
void slotExecuted( QListBoxItem * );
void slotShowRMBMenu( QListBoxItem *, const QPoint& );
void shortCutSelected( int );
private:
SidePaneBase *mSidePane;
IconViewMode mViewMode;
QSignalMapper *mMapper;
QPtrList<KAction> mActions;
......
......@@ -9,6 +9,13 @@
<entry type="String" name="ActivePlugin">
<default>kontact_summaryplugin</default>
</entry>
<entry type="Bool" name="ForceStartupPlugin">
<default>false</default>
<label>Always start with specified component</label>
<whatsthis>Usually Kontact will come up with the component used before shutdown. Check this box if you would like a specific component to come up on start instead.</whatsthis>
</entry>
<entry type="String" name="ForcedStartupPlugin">
</entry>
<entry type="IntList" name="SidePaneSplitter">
</entry>
......@@ -25,6 +32,9 @@
</choices>
<default>SidePaneIcons</default>
</entry>
</group>
<entry type="Int" name="SidePaneIconSize">
<default>32</default>
</entry>
</group>
</kcfg>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment