25#include <tqdrawutil.h>
26#include <tqfontmetrics.h>
29#include <tqobjectlist.h>
34#include <tqwidgetstack.h>
37#include <tdeapplication.h>
40#include <kiconloader.h>
42#include <tdepopupmenu.h>
43#include <kpushbutton.h>
45#include "iconsidepane.h"
47EntryItem::EntryItem(
Navigator *parent,
int _id,
const TQString &_text,
const TQString & _pix )
48 : TQListBoxItem( parent ),
55 setCustomHighlighting(
true );
59EntryItem::~EntryItem()
63void EntryItem::setNewText(
const TQString &_text)
68void EntryItem::reloadPixmap()
70 int size = (int)navigator()->viewMode();
72 mPixmap = TDEGlobal::iconLoader()->loadIcon( mPixmapName, TDEIcon::Desktop, size );
79 return static_cast<Navigator*
>( listBox() );
85 if( navigator()->showIcons() ) {
86 w = navigator()->viewMode();
87 if ( navigator()->viewMode() == SmallIcons )
90 if( navigator()->showText() ) {
91 if ( navigator()->viewMode() == SmallIcons )
92 w += listbox->fontMetrics().width( text() );
94 w = TQMAX( w, listbox->fontMetrics().width( text() ) );
96 return w + ( KDialog::marginHint() * 2 );
102 if ( navigator()->showIcons() )
103 h = (int)navigator()->viewMode() + 4;
104 if ( navigator()->showText() ) {
105 if ( navigator()->viewMode() == SmallIcons || !navigator()->showIcons() )
106 h = TQMAX( h, listbox->fontMetrics().lineSpacing() ) + KDialog::spacingHint() * 2;
108 h = (int)navigator()->viewMode() + listbox->fontMetrics().lineSpacing() + 4;
113void EntryItem::paint( TQPainter *p )
117 TQListBox *box = listBox();
118 bool iconAboveText = ( navigator()->viewMode() > SmallIcons )
119 && navigator()->showIcons();
120 int w = box->viewport()->width();
124 if ( isCurrent() || isSelected() || mHasHover || mPaintActive ) {
128 if ( isCurrent() || isSelected() || mPaintActive )
129 brush = box->colorGroup().brush( TQColorGroup::Highlight );
131 brush = TQBrush(box->colorGroup().highlight().light( 115 ));
132 p->fillRect( 1, 0, w - 2, h - 1, brush );
133 TQPen pen = p->pen();
135 pen.setColor( box->colorGroup().mid() );
138 p->drawPoint( 1, 0 );
139 p->drawPoint( 1, h - 2 );
140 p->drawPoint( w - 2, 0 );
141 p->drawPoint( w - 2, h - 2 );
146 if ( !mPixmap.isNull() && navigator()->showIcons() ) {
147 int x = iconAboveText ? ( ( w - mPixmap.width() ) / 2 ) :
148 KDialog::marginHint();
149 p->drawPixmap( x, y, mPixmap );
152 TQColor shadowColor = listBox()->colorGroup().background().dark(115);
153 if ( isCurrent() || isSelected() ) {
154 p->setPen( box->colorGroup().highlightedText() );
157 if ( !text().isEmpty() && navigator()->showText() ) {
158 TQFontMetrics fm = p->fontMetrics();
161 if ( iconAboveText ) {
162 x = ( w - fm.width( text() ) ) / 2;
163 y += fm.height() - fm.descent();
164 if ( navigator()->showIcons() )
165 y += mPixmap.height();
167 x = KDialog::marginHint() + 4;
168 if( navigator()->showIcons() ) {
169 x += mPixmap.width();
172 if ( !navigator()->showIcons() || mPixmap.height() < fm.height() )
173 y += fm.ascent() + fm.leading()/2;
175 y += mPixmap.height()/2 - fm.height()/2 + fm.ascent();
178 if ( isCurrent() || isSelected() || mHasHover ) {
179 p->setPen( box->colorGroup().highlight().dark(115) );
180 p->drawText( x + ( TQApplication::reverseLayout() ? -1 : 1),
182 p->setPen( box->colorGroup().highlightedText() );
185 p->setPen( box->colorGroup().text() );
187 p->drawText( x, y, text() );
191 if ( isCurrent() || isSelected() ) mHasHover =
false;
194void EntryItem::setHover(
bool hasHover )
196 mHasHover = hasHover;
199void EntryItem::setPaintActive(
bool paintActive )
201 mPaintActive = paintActive;
206Navigator::Navigator(
bool _selectable, TDEPopupMenu * menu, IconSidePane *_iconsidepane, TQWidget *parent,
const char *name )
207 : TDEListBox( parent, name ), mSidePane( _iconsidepane ), mPopupMenu( menu )
209 setSelectionMode( TDEListBox::Single );
210 viewport()->setBackgroundMode( PaletteBackground );
211 setFrameStyle( TQFrame::NoFrame );
212 setHScrollBarMode( TQScrollView::AlwaysOff );
215 mSelectable = _selectable;
219 setFocusPolicy( TQWidget::NoFocus );
221 connect(
this, TQ_SIGNAL( clicked( TQListBoxItem* ) ),
222 TQ_SLOT( slotExecuted( TQListBoxItem* ) ) );
223 connect(
this, TQ_SIGNAL( onItem( TQListBoxItem * ) ),
224 TQ_SLOT( slotMouseOn( TQListBoxItem * ) ) );
225 connect(
this, TQ_SIGNAL( onViewport() ), TQ_SLOT( slotMouseOff() ) );
227 TQToolTip::remove(
this );
228 if ( !mSidePane->showText() )
229 new EntryItemToolTip(
this );
232IconViewMode Navigator::viewMode()
234 return mSidePane->viewMode();
237bool Navigator::showText()
239 return mSidePane->showText();
242bool Navigator::showIcons()
244 return mSidePane->showIcons();
247void Navigator::mouseReleaseEvent(TQMouseEvent *e)
249 TDEListBox::mouseReleaseEvent(e);
250 if ( e->button() != TQt::LeftButton || !mLeftMouseButtonPressed )
252 if ( itemAt( e->pos() ) && executedItem == selectedItem() )
253 emit itemSelected( currentItem() );
258void Navigator::mousePressEvent(TQMouseEvent *e)
260 if ( e->button() != TQt::LeftButton || itemAt( e->pos() ) == 0 )
262 mLeftMouseButtonPressed =
false;
263 if (e->button() == TQt::RightButton)
264 slotShowRMBMenu( 0,mapToGlobal( e->pos() ) );
268 mLeftMouseButtonPressed =
true;
269 TDEListBox::mousePressEvent(e);
272void Navigator::enterEvent( TQEvent *event )
275 TDEListBox::enterEvent( event );
276 emit onItem( itemAt( mapFromGlobal( TQCursor::pos() ) ) );
279void Navigator::slotExecuted( TQListBoxItem *item )
286TQSize Navigator::sizeHint()
const
288 return TQSize( mMinWidth, 100 );
291void Navigator::calculateMinWidth()
293 mMinWidth = mSidePane->minWidth();
295 for (EntryItem *item =
static_cast<EntryItem *
>(firstItem()) ; item; item =
static_cast<EntryItem *
>(item->next()))
297 if (item->width(
this ) > mMinWidth)
298 mMinWidth = item->width(
this );
301 parentWidget()->setFixedWidth( mMinWidth );
305int Navigator::insertItem(
const TQString &_text,
const TQString & _pix)
307 EntryItem *item =
new EntryItem(
this, count(), _text, _pix );
308 if (item->
width(
this ) > mSidePane->minWidth() )
310 mMinWidth = item->
width(
this );
311 parentWidget()->setMinimumWidth( mMinWidth );
317void Navigator::setHoverItem( TQListBoxItem* item,
bool hover )
319 static_cast<EntryItem*
>( item )->setHover( hover );
323void Navigator::setPaintActiveItem( TQListBoxItem* item,
bool paintActive )
325 static_cast<EntryItem*
>( item )->setPaintActive( paintActive );
329void Navigator::slotMouseOn( TQListBoxItem* newItem )
331 TQListBoxItem* oldItem = mMouseOn;
332 if ( oldItem == newItem )
335 if ( oldItem && !oldItem->isCurrent() && !oldItem->isSelected() )
336 setHoverItem( oldItem,
false );
338 if ( newItem && !newItem->isCurrent() && !newItem->isSelected() )
339 setHoverItem( newItem,
true );
343void Navigator::slotMouseOff()
348void Navigator::resizeEvent( TQResizeEvent *event )
350 TQListBox::resizeEvent( event );
351 triggerUpdate(
true );
354void Navigator::slotShowRMBMenu( TQListBoxItem *,
const TQPoint &pos )
356 int choice = mPopupMenu->exec( pos );
361 mSidePane->resetWidth();
362 if ( choice >= SmallIcons ) {
363 mSidePane->setViewMode( mSidePane->sizeIntToEnum( choice ) );
364 mPopupMenu->setItemChecked( (
int)SmallIcons,
false);
365 mPopupMenu->setItemChecked( (
int)NormalIcons,
false);
366 mPopupMenu->setItemChecked( (
int)LargeIcons,
false);
367 mPopupMenu->setItemChecked( mSidePane->viewMode(),
true);
368 KoShellSettings::setSidePaneIconSize( choice );
373 if ( choice == ShowIcons ) {
374 mSidePane->toogleIcons();
375 mPopupMenu->setItemChecked( (
int)ShowIcons, mSidePane->showIcons() );
376 mPopupMenu->setItemEnabled( (
int)ShowText, mSidePane->showIcons() );
377 mPopupMenu->setItemEnabled( (
int)SmallIcons, mSidePane->showIcons());
378 mPopupMenu->setItemEnabled( (
int)NormalIcons, mSidePane->showIcons());
379 mPopupMenu->setItemEnabled( (
int)LargeIcons, mSidePane->showIcons());
380 KoShellSettings::setSidePaneShowIcons( mSidePane->showIcons() );
382 TQToolTip::remove(
this );
384 mSidePane->toogleText();
385 mSidePane->resetWidth();
386 mPopupMenu->setItemChecked( (
int)ShowText, mSidePane->showText() );
387 mPopupMenu->setItemEnabled( (
int)ShowIcons, mSidePane->showText() );
388 mPopupMenu->setItemEnabled( (
int)SmallIcons,
true);
389 mPopupMenu->setItemEnabled( (
int)NormalIcons,
true);
390 mPopupMenu->setItemEnabled( (
int)LargeIcons,
true);
391 KoShellSettings::setSidePaneShowText( mSidePane->showText() );
392 new EntryItemToolTip(
this );
400 emit updateAllWidgets();
405IconSidePane::IconSidePane(TQWidget *parent,
const char *name )
406 : TQVBox( parent, name )
408 m_buttongroup =
new TQButtonGroup(1, TQt::Horizontal,
this);
409 m_buttongroup->setExclusive(
true);
410 m_buttongroup->hide();
411 mWidgetstack =
new TQWidgetStack(
this);
412 mWidgetstack->setSizePolicy(TQSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding));
415 mShowIcons = KoShellSettings::sidePaneShowIcons();
416 mShowText = KoShellSettings::sidePaneShowText();
417 mViewMode = sizeIntToEnum( KoShellSettings::sidePaneIconSize() );
418 mPopupMenu =
new TDEPopupMenu(0);
419 mPopupMenu->insertTitle( i18n(
"Icon Size" ) );
420 mPopupMenu->insertItem( i18n(
"Large" ), (
int)LargeIcons );
421 mPopupMenu->setItemEnabled( (
int)LargeIcons, mShowIcons );
422 mPopupMenu->insertItem( i18n(
"Normal" ), (
int)NormalIcons );
423 mPopupMenu->setItemEnabled( (
int)NormalIcons, mShowIcons );
424 mPopupMenu->insertItem( i18n(
"Small" ), (
int)SmallIcons );
425 mPopupMenu->setItemEnabled( (
int)SmallIcons, mShowIcons );
426 mPopupMenu->setItemChecked( (
int)mViewMode,
true );
427 mPopupMenu->insertSeparator();
428 mPopupMenu->insertItem( i18n(
"Show Icons" ), (
int)ShowIcons );
429 mPopupMenu->setItemChecked( (
int)ShowIcons, mShowIcons );
430 mPopupMenu->setItemEnabled( (
int)ShowIcons, mShowText );
431 mPopupMenu->insertItem( i18n(
"Show Text" ), (
int)ShowText );
432 mPopupMenu->setItemChecked( (
int)ShowText, mShowText );
433 mPopupMenu->setItemEnabled( (
int)ShowText, mShowIcons );
435 m_buttongroup->hide();
438IconSidePane::~IconSidePane()
442int IconSidePane::insertItem(
int _grp,
const TQString & _pix,
const TQString &_text)
444 return static_cast<Navigator*
>( mWidgetstack->widget(_grp))->insertItem( _text, _pix );
447int IconSidePane::insertItem(
const TQString & _pix,
const TQString &_text)
449 return mCurrentNavigator->insertItem(_text, _pix);
452void IconSidePane::renameItem(
int _grp,
int _id,
const TQString & _text )
454 Navigator *navigator =
static_cast<Navigator*
>(mWidgetstack->widget(_grp));
458 for (uint i=0; i< navigator->count(); i++)
460 item =
static_cast<EntryItem *
>(navigator->item(i));
461 if (_id == item->id())
463 item->setNewText(_text);
464 navigator->triggerUpdate(
false);
470void IconSidePane::removeItem(
int _grp,
int _id )
472 Navigator *navigator =
static_cast<Navigator*
>(mWidgetstack->widget(_grp));
475 for (uint i=0; i< navigator->count(); i++)
477 if (_id ==
static_cast<EntryItem *
>(navigator->item(i))->id())
479 navigator->removeItem(i);
485int IconSidePane::insertGroup(
const TQString &_text,
bool _selectable, TQObject *_obj,
const char *_slot)
487 mCurrentNavigator =
new Navigator(_selectable, mPopupMenu,
this, mWidgetstack );
489 if ( _obj != 0L && _slot != 0L )
490 connect( mCurrentNavigator, TQ_SIGNAL( itemSelected(
int ) ), _obj, _slot );
491 connect( mCurrentNavigator, TQ_SIGNAL( updateAllWidgets() ),
this, TQ_SLOT(updateAllWidgets()) );
492 int const id = mWidgetstack->addWidget(mCurrentNavigator);
493 mWidgetStackIds.append(
id );
494 KPushButton *b =
new KPushButton( _text, m_buttongroup );
495 m_buttongroup->insert( b,
id );
496 connect( b, TQ_SIGNAL( clicked() ),
this, TQ_SLOT( buttonClicked() ) );
497 b->setToggleButton(
true );
498 b->setFocusPolicy( TQWidget::NoFocus );
499 if (m_buttongroup->count()==1)
501 mCurrentNavigator->calculateMinWidth();
502 m_buttongroup->setButton(m_buttongroup->id(b));
503 mWidgetstack->raiseWidget(
id);
505 if ( b->width() > minimumWidth() )
506 setMinimumWidth( b->width() );
510void IconSidePane::buttonClicked()
512 mWidgetstack->raiseWidget( m_buttongroup->selectedId() );
515void IconSidePane::selectGroup(
int group_id)
517 mWidgetstack->raiseWidget(group_id);
520void IconSidePane::itemSelected(
int item)
522 kdDebug() <<
"Item selected:" << item << endl;
527 return static_cast<Navigator*
>(mWidgetstack->widget(_grp));
530void IconSidePane::updateAllWidgets()
532 TQValueList<int>::iterator it;
533 for ( it = mWidgetStackIds.begin(); it != mWidgetStackIds.end(); ++it )
534 static_cast<Navigator*
>(mWidgetstack->widget(*it))->triggerUpdate(
true );
537int IconSidePane::minWidth()
540 TQValueList<int>::iterator it;
542 for ( it = mWidgetStackIds.begin(); it != mWidgetStackIds.end(); ++it )
544 n =
static_cast<Navigator*
>(mWidgetstack->widget(*it));
545 if ( n->minWidth() > width )
546 width = n->minWidth();
551void IconSidePane::resetWidth()
553 TQValueList<int>::iterator it;
555 for ( it = mWidgetStackIds.begin(); it != mWidgetStackIds.end(); ++it )
557 n =
static_cast<Navigator*
>(mWidgetstack->widget(*it));
559 n->triggerUpdate(
true);
563IconViewMode IconSidePane::sizeIntToEnum(
int size)
const
566 case int(LargeIcons):
569 case int(NormalIcons):
572 case int(SmallIcons):
578 kdDebug() <<
"View mode not implemented!" << endl;
583void IconSidePane::setActionCollection( TDEActionCollection *actionCollection )
585 mActionCollection = actionCollection;
588TDEActionCollection *IconSidePane::actionCollection()
const
590 return mActionCollection;
593#include "iconsidepane.moc"
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.