22 #include <tqptrlist.h>
23 #include <tqwidgetstack.h>
25 #include <tqobjectlist.h>
28 #include <tqpainter.h>
30 #include <tqfontmetrics.h>
31 #include <tqsignalmapper.h>
34 #include <tqdrawutil.h>
37 #include <tqtooltip.h>
39 #include <tdepopupmenu.h>
40 #include <tdeapplication.h>
42 #include <tdelocale.h>
43 #include <kiconloader.h>
44 #include <sidebarextension.h>
48 #include "mainwindow.h"
53 #include "iconsidepane.h"
67 PluginProxy(
Plugin *plugin )
71 PluginProxy & operator=(
Plugin *plugin )
77 bool operator<( PluginProxy &rhs )
const
79 return mPlugin->
weight() < rhs.mPlugin->weight();
93 using namespace Kontact;
96 : TQListBoxItem( parent ),
102 setCustomHighlighting(
true );
103 setText( plugin->
title() );
106 EntryItem::~EntryItem()
110 void EntryItem::reloadPixmap()
112 int size = (int)navigator()->viewMode();
114 mPixmap = TDEGlobal::iconLoader()->loadIcon( mPlugin->
icon(),
115 TDEIcon::Desktop, size,
116 mPlugin->disabled() ?
117 TDEIcon::DisabledState
118 : TDEIcon::DefaultState);
120 mPixmap = TQPixmap();
125 return static_cast<Navigator*
>( listBox() );
131 if( navigator()->showIcons() ) {
132 w = navigator()->viewMode();
133 if ( navigator()->viewMode() == SmallIcons )
136 if( navigator()->showText() ) {
137 if ( navigator()->viewMode() == SmallIcons )
138 w += listbox->fontMetrics().width( text() );
140 w = TQMAX( w, listbox->fontMetrics().width( text() ) );
142 return w + ( KDialog::marginHint() * 2 );
148 if ( navigator()->showIcons() )
149 h = (int)navigator()->viewMode() + 4;
150 if ( navigator()->showText() ) {
151 if ( navigator()->viewMode() == SmallIcons || !navigator()->showIcons() )
152 h = TQMAX( h, listbox->fontMetrics().lineSpacing() ) + KDialog::spacingHint() * 2;
154 h = (int)navigator()->viewMode() + listbox->fontMetrics().lineSpacing() + 4;
159 void EntryItem::paint( TQPainter *p )
163 TQListBox *box = listBox();
164 bool iconAboveText = ( navigator()->viewMode() > SmallIcons )
165 && navigator()->showIcons();
166 int w = box->viewport()->width();
167 int y = iconAboveText ? 2 :
168 ( (
height( box ) - mPixmap.height() ) / 2 );
171 if ( isCurrent() || isSelected() || mHasHover || mPaintActive ) {
175 if ( isCurrent() || isSelected() || mPaintActive )
176 brush = box->colorGroup().brush( TQColorGroup::Highlight );
178 brush = TQBrush(box->colorGroup().highlight().light( 115 ));
179 p->fillRect( 1, 0, w - 2, h - 1, brush );
180 TQPen pen = p->pen();
182 pen.setColor( box->colorGroup().mid() );
185 p->drawPoint( 1, 0 );
186 p->drawPoint( 1, h - 2 );
187 p->drawPoint( w - 2, 0 );
188 p->drawPoint( w - 2, h - 2 );
193 if ( !mPixmap.isNull() && navigator()->showIcons() ) {
194 int x = iconAboveText ? ( ( w - mPixmap.width() ) / 2 ) :
195 KDialog::marginHint();
196 p->drawPixmap( x, y, mPixmap );
199 TQColor shadowColor = listBox()->colorGroup().background().dark(115);
200 if ( isCurrent() || isSelected() ) {
201 p->setPen( box->colorGroup().highlightedText() );
204 if ( !text().isEmpty() && navigator()->showText() ) {
205 TQFontMetrics fm = p->fontMetrics();
208 if ( iconAboveText ) {
209 x = ( w - fm.width( text() ) ) / 2;
210 y += fm.height() - fm.descent();
211 if ( navigator()->showIcons() )
212 y += mPixmap.height();
214 x = KDialog::marginHint() + 4;
215 if( navigator()->showIcons() ) {
216 x += mPixmap.width();
219 if ( !navigator()->showIcons() || mPixmap.height() < fm.height() )
220 y =
height( box )/2 - fm.height()/2 + fm.ascent();
222 y += mPixmap.height()/2 - fm.height()/2 + fm.ascent();
225 if ( plugin()->disabled() ) {
226 p->setPen( box->palette().disabled().text( ) );
227 }
else if ( isCurrent() || isSelected() || mHasHover ) {
228 p->setPen( box->colorGroup().highlight().dark(115) );
229 p->drawText( x + ( TQApplication::reverseLayout() ? -1 : 1),
231 p->setPen( box->colorGroup().highlightedText() );
234 p->setPen( box->colorGroup().text() );
236 p->drawText( x, y, text() );
240 if ( isCurrent() || isSelected() ) mHasHover =
false;
243 void EntryItem::setHover(
bool hasHover )
245 mHasHover = hasHover;
248 void EntryItem::setPaintActive(
bool paintActive )
250 mPaintActive = paintActive;
253 Navigator::Navigator( IconSidePane *parent,
const char *name )
254 : TDEListBox( parent, name ), mSidePane( parent ),
255 mShowIcons( true ), mShowText( true )
259 mViewMode = sizeIntToEnum( Prefs::self()->sidePaneIconSize() );
260 mShowIcons = Prefs::self()->sidePaneShowIcons();
261 mShowText = Prefs::self()->sidePaneShowText();
262 setSelectionMode( TDEListBox::Single );
263 viewport()->setBackgroundMode( PaletteBackground );
264 setFrameStyle( TQFrame::NoFrame );
265 setHScrollBarMode( TQScrollView::AlwaysOff );
266 setAcceptDrops(
true );
268 setFocusPolicy( TQWidget::NoFocus );
270 connect(
this, TQ_SIGNAL( selectionChanged( TQListBoxItem* ) ),
271 TQ_SLOT( slotExecuted( TQListBoxItem* ) ) );
272 connect(
this, TQ_SIGNAL( rightButtonPressed( TQListBoxItem*,
const TQPoint& ) ),
273 TQ_SLOT( slotShowRMBMenu( TQListBoxItem*,
const TQPoint& ) ) );
274 connect(
this, TQ_SIGNAL( onItem( TQListBoxItem * ) ),
275 TQ_SLOT( slotMouseOn( TQListBoxItem * ) ) );
276 connect(
this, TQ_SIGNAL( onViewport() ), TQ_SLOT( slotMouseOff() ) );
278 mMapper =
new TQSignalMapper(
this );
279 connect( mMapper, TQ_SIGNAL( mapped(
int ) ), TQ_SLOT( shortCutSelected(
int ) ) );
281 TQToolTip::remove(
this );
287 TQSize Navigator::sizeHint()
const
289 return TQSize( 100, 100 );
292 void Navigator::highlightItem(
EntryItem * item )
294 mHighlightItem = item;
296 setPaintActiveItem( mHighlightItem,
true );
298 TQTimer::singleShot( 2000,
this, TQ_SLOT( slotStopHighlight() ) );
301 void Navigator::slotStopHighlight()
303 setPaintActiveItem( mHighlightItem,
false );
306 void Navigator::setSelected( TQListBoxItem *item,
bool selected )
313 emit pluginActivated( entry->plugin() );
317 void Navigator::updatePlugins( TQValueList<Kontact::Plugin*> plugins_ )
319 TQValueList<Kontact::PluginProxy> plugins;
320 TQValueList<Kontact::Plugin*>::ConstIterator end_ = plugins_.end();
321 TQValueList<Kontact::Plugin*>::ConstIterator it_ = plugins_.begin();
322 for ( ; it_ != end_; ++it_ )
323 plugins += PluginProxy( *it_ );
327 mActions.setAutoDelete(
true );
329 mActions.setAutoDelete(
false );
332 qBubbleSort( plugins );
333 TQValueList<Kontact::PluginProxy>::ConstIterator end = plugins.end();
334 TQValueList<Kontact::PluginProxy>::ConstIterator it = plugins.begin();
335 for ( ; it != end; ++it ) {
341 item->setSelectable( !plugin->disabled() );
343 if ( item->
width(
this ) > minWidth )
344 minWidth = item->
width(
this );
347 parentWidget()->setFixedWidth( minWidth );
350 void Navigator::dragEnterEvent( TQDragEnterEvent *event )
352 kdDebug(5600) <<
"Navigator::dragEnterEvent()" << endl;
354 dragMoveEvent( event );
357 void Navigator::dragMoveEvent( TQDragMoveEvent *event )
359 kdDebug(5600) <<
"Navigator::dragEnterEvent()" << endl;
361 kdDebug(5600) <<
" Format: " <<
event->format() << endl;
363 TQListBoxItem *item = itemAt( event->pos() );
366 event->accept(
false );
372 kdDebug(5600) <<
" PLUGIN: " << entry->plugin()->
identifier() << endl;
377 void Navigator::dropEvent( TQDropEvent *event )
379 kdDebug(5600) <<
"Navigator::dropEvent()" << endl;
381 TQListBoxItem *item = itemAt( event->pos() );
389 kdDebug(5600) <<
" PLUGIN: " << entry->plugin()->
identifier() << endl;
394 void Navigator::resizeEvent( TQResizeEvent *event )
396 TQListBox::resizeEvent( event );
397 triggerUpdate(
true );
400 void Navigator::enterEvent( TQEvent *event )
403 TDEListBox::enterEvent( event );
404 emit onItem( itemAt( mapFromGlobal( TQCursor::pos() ) ) );
407 void Navigator::leaveEvent( TQEvent *event )
409 TDEListBox::leaveEvent( event );
414 void Navigator::slotExecuted( TQListBoxItem *item )
421 emit pluginActivated( entry->plugin() );
424 IconViewMode Navigator::sizeIntToEnum(
int size)
const
427 case int(LargeIcons):
430 case int(NormalIcons):
433 case int(SmallIcons):
439 kdDebug() <<
"View mode not implemented!" << endl;
444 void Navigator::slotShowRMBMenu( TQListBoxItem *,
const TQPoint &pos )
447 menu.insertTitle( i18n(
"Icon Size" ) );
448 menu.insertItem( i18n(
"Large" ), (
int)LargeIcons );
449 menu.setItemEnabled( (
int)LargeIcons, mShowIcons );
450 menu.insertItem( i18n(
"Normal" ), (
int)NormalIcons );
451 menu.setItemEnabled( (
int)NormalIcons, mShowIcons );
452 menu.insertItem( i18n(
"Small" ), (
int)SmallIcons );
453 menu.setItemEnabled( (
int)SmallIcons, mShowIcons );
455 menu.setItemChecked( (
int)mViewMode,
true );
456 menu.insertSeparator();
458 menu.insertItem( i18n(
"Show Icons" ), (
int)ShowIcons );
459 menu.setItemChecked( (
int)ShowIcons, mShowIcons );
460 menu.setItemEnabled( (
int)ShowIcons, mShowText );
461 menu.insertItem( i18n(
"Show Text" ), (
int)ShowText );
462 menu.setItemChecked( (
int)ShowText, mShowText );
463 menu.setItemEnabled( (
int)ShowText, mShowIcons );
464 int choice = menu.exec( pos );
469 if ( choice >= SmallIcons ) {
470 mViewMode = sizeIntToEnum( choice );
471 Prefs::self()->setSidePaneIconSize( choice );
474 if ( choice == ShowIcons ) {
475 mShowIcons = !mShowIcons;
476 Prefs::self()->setSidePaneShowIcons( mShowIcons );
477 TQToolTip::remove(
this );
481 mShowText = !mShowText;
482 Prefs::self()->setSidePaneShowText( mShowText );
483 TQToolTip::remove(
this );
487 TQListBoxItem* it = 0;
488 for (
int i = 0; (it = item(i)) != 0; ++i)
490 int width = it->width(
this);
491 if (width > maxWidth)
494 parentWidget()->setFixedWidth( maxWidth );
496 triggerUpdate(
true );
499 void Navigator::shortCutSelected(
int pos )
501 setCurrentItem( pos );
504 void Navigator::setHoverItem( TQListBoxItem* item,
bool hover )
506 static_cast<EntryItem*
>( item )->setHover( hover );
510 void Navigator::setPaintActiveItem( TQListBoxItem* item,
bool paintActive )
512 static_cast<EntryItem*
>( item )->setPaintActive( paintActive );
516 void Navigator::slotMouseOn( TQListBoxItem* newItem )
518 TQListBoxItem* oldItem = mMouseOn;
519 if ( oldItem == newItem )
return;
521 if ( oldItem && !oldItem->isCurrent() && !oldItem->isSelected() )
523 setHoverItem( oldItem,
false );
526 if ( newItem && !newItem->isCurrent() && !newItem->isSelected() )
528 setHoverItem( newItem,
true );
533 void Navigator::slotMouseOff()
538 IconSidePane::IconSidePane(
Core *core, TQWidget *parent,
const char *name )
539 : SidePaneBase( core, parent, name )
545 setAcceptDrops(
true );
548 IconSidePane::~IconSidePane()
552 void IconSidePane::updatePlugins()
554 mNavigator->updatePlugins( core()->pluginList() );
559 bool blocked = signalsBlocked();
560 blockSignals(
true );
562 for ( uint i = 0; i < mNavigator->count(); ++i ) {
564 if ( item->plugin() == plugin ) {
565 mNavigator->setCurrentItem( i );
570 blockSignals( blocked );
573 void IconSidePane::selectPlugin(
const TQString &name )
575 bool blocked = signalsBlocked();
576 blockSignals(
true );
578 for ( uint i = 0; i < mNavigator->count(); ++i ) {
581 mNavigator->setCurrentItem( i );
586 blockSignals( blocked );
591 for ( uint i = 0; i < mNavigator->count(); ++i ) {
593 if ( item->plugin() == plugin ) {
594 mNavigator->highlightItem( item );
601 #include "iconsidepane.moc"
This class provides the interface to the Kontact core for the plugins.
Tooltip that changes text depending on the item it is above.
A TQListBoxPixmap Square Box with an optional icon and a text underneath.
virtual int width(const TQListBox *) const
returns the width of this item.
virtual int height(const TQListBox *) const
returns the height of this item.
Navigation pane showing all parts relevant to the user.
Base class for all Plugins in Kontact.
TQString title() const
Returns the localized title.
virtual bool canDecodeDrag(TQMimeSource *)
Return, if the plugin can handle the drag object of the given mime type.
virtual bool showInSideBar() const
Returns whether the plugin provides a part that should be shown in the sidebar.
virtual void processDropEvent(TQDropEvent *)
Process drop event.
TQString identifier() const
Returns the identifier.
TQString icon() const
Returns the icon name.
virtual int weight() const
Return the weight of the plugin.