summaryrefslogtreecommitdiffstats
path: root/kdeui/kjanuswidget.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-02 21:21:15 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-02 21:21:15 +0000
commit96900dbce3aaa1fcac74a07a71482c5c6fcd3cab (patch)
treebf3fc68d0dcc660fce0e21171373a2d4e2395707 /kdeui/kjanuswidget.cpp
parent5f99bff82d3413803bcc652999f4f631058179d6 (diff)
downloadtdelibs-96900dbce3aaa1fcac74a07a71482c5c6fcd3cab.tar.gz
tdelibs-96900dbce3aaa1fcac74a07a71482c5c6fcd3cab.zip
* Large set of SuSE patches to fix bugs and add functionality
* kdemm is included but not used by knotify as it does not work out of the box git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1171141 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeui/kjanuswidget.cpp')
-rw-r--r--kdeui/kjanuswidget.cpp121
1 files changed, 112 insertions, 9 deletions
diff --git a/kdeui/kjanuswidget.cpp b/kdeui/kjanuswidget.cpp
index f8647fb26..7f34dc5c1 100644
--- a/kdeui/kjanuswidget.cpp
+++ b/kdeui/kjanuswidget.cpp
@@ -49,16 +49,19 @@ class KJanusWidget::IconListItem : public QListBoxItem
{
public:
IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
- const TQString &text );
+ const TQString &text );
virtual int height( const TQListBox *lb ) const;
virtual int width( const TQListBox *lb ) const;
int expandMinimumWidth( int width );
+ void highlight( bool erase );
protected:
const TQPixmap &defaultPixmap();
void paint( TQPainter *painter );
-
+
private:
+ void paintContents( TQPainter *painter );
+
TQPixmap mPixmap;
int mMinimumWidth;
};
@@ -141,6 +144,8 @@ KJanusWidget::KJanusWidget( TQWidget *parent, const char *name, int face )
mIconList->verticalScrollBar()->installEventFilter( this );
connect( mIconList, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotShowPage()));
+ connect( mIconList, TQT_SIGNAL(onItem(TQListBoxItem *)), TQT_SLOT(slotOnItem(TQListBoxItem *)));
+
hbox->addSpacing( KDialog::marginHint() );
page = new TQFrame( this );
hbox->addWidget( page, 10 );
@@ -259,7 +264,7 @@ void KJanusWidget::slotReopen( TQListViewItem * item )
}
TQFrame *KJanusWidget::addPage( const TQString &itemName, const TQString &header,
- const TQPixmap &pixmap )
+ const TQPixmap &pixmap )
{
TQStringList items;
items << itemName;
@@ -269,8 +274,8 @@ TQFrame *KJanusWidget::addPage( const TQString &itemName, const TQString &header
TQVBox *KJanusWidget::addVBoxPage( const TQStringList &items,
- const TQString &header,
- const TQPixmap &pixmap )
+ const TQString &header,
+ const TQPixmap &pixmap )
{
if( !mValid )
{
@@ -721,6 +726,12 @@ void KJanusWidget::slotItemClicked(TQListViewItem *it)
it->setOpen(!it->isOpen());
}
+// hack because qt does not support Q_OBJECT in nested classes
+void KJanusWidget::slotOnItem(TQListBoxItem *qitem)
+{
+ mIconList->slotOnItem( qitem );
+}
+
void KJanusWidget::setFocus()
{
if( !mValid ) { return; }
@@ -929,11 +940,11 @@ bool KJanusWidget::eventFilter( TQObject *o, TQEvent *e )
KJanusWidget::IconListBox::IconListBox( TQWidget *parent, const char *name,
WFlags f )
:KListBox( parent, name, f ), mShowAll(false), mHeightValid(false),
- mWidthValid(false)
+ mWidthValid(false),
+ mOldItem(0)
{
}
-
void KJanusWidget::IconListBox::updateMinimumHeight()
{
if( mShowAll && !mHeightValid )
@@ -995,6 +1006,45 @@ void KJanusWidget::IconListBox::setShowAll( bool showAll )
}
+void KJanusWidget::IconListBox::leaveEvent( TQEvent *ev )
+{
+ KListBox::leaveEvent( ev );
+
+ if ( mOldItem && !mOldItem->isSelected() )
+ {
+ ((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
+ mOldItem = 0;
+ }
+}
+
+// hack because qt does not support Q_OBJECT in nested classes
+void KJanusWidget::IconListBox::slotOnItem(TQListBoxItem *qitem)
+{
+ KListBox::slotOnItem( qitem );
+
+ if ( qitem == mOldItem )
+ {
+ return;
+ }
+
+ if ( mOldItem && !mOldItem->isSelected() )
+ {
+ ((KJanusWidget::IconListItem *) mOldItem)->highlight( true );
+ }
+
+ KJanusWidget::IconListItem *item = dynamic_cast< KJanusWidget::IconListItem * >( qitem );
+ if ( item && !item->isSelected() )
+ {
+ item->highlight( false );
+ mOldItem = item;
+ }
+ else
+ {
+ mOldItem = 0;
+ }
+}
+
+
KJanusWidget::IconListItem::IconListItem( TQListBox *listbox, const TQPixmap &pixmap,
const TQString &text )
@@ -1006,6 +1056,7 @@ KJanusWidget::IconListItem::IconListItem( TQListBox *listbox, const TQPixmap &pi
mPixmap = defaultPixmap();
}
setText( text );
+ setCustomHighlighting( true );
mMinimumWidth = 0;
}
@@ -1017,6 +1068,36 @@ int KJanusWidget::IconListItem::expandMinimumWidth( int width )
}
+void KJanusWidget::IconListItem::highlight( bool erase )
+{
+ TQRect r = listBox()->itemRect( this );
+ r.addCoords( 1, 1, -1, -1 );
+
+ TQPainter p( listBox()->viewport() );
+ p.setClipRegion( r );
+
+ const TQColorGroup &cg = listBox()->colorGroup();
+ if ( erase )
+ {
+ p.setPen( cg.base() );
+ p.setBrush( cg.base() );
+ p.drawRect( r );
+ }
+ else
+ {
+ p.setBrush( cg.highlight().light( 120 ) );
+ p.drawRect( r );
+
+ p.setPen( cg.highlight().dark( 140 ) );
+ p.drawRect( r );
+ }
+
+ p.setPen( cg.foreground() );
+ p.translate( r.x() - 1, r.y() - 1 );
+ paintContents( &p );
+}
+
+
const TQPixmap &KJanusWidget::IconListItem::defaultPixmap()
{
static TQPixmap *pix=0;
@@ -1044,15 +1125,34 @@ const TQPixmap &KJanusWidget::IconListItem::defaultPixmap()
void KJanusWidget::IconListItem::paint( TQPainter *painter )
{
+ TQRect itemPaintRegion( listBox()->itemRect( this ) );
+ TQRect r( 1, 1, itemPaintRegion.width() - 2, itemPaintRegion.height() - 2);
+
+ if ( isSelected() )
+ {
+ painter->eraseRect( r );
+
+ painter->save();
+ painter->setPen( listBox()->colorGroup().highlight().dark( 160 ) );
+ painter->drawRect( r );
+ painter->restore();
+ }
+
+ paintContents( painter );
+}
+
+
+void KJanusWidget::IconListItem::paintContents( TQPainter *painter )
+{
TQFontMetrics fm = painter->fontMetrics();
int ht = fm.boundingRect( 0, 0, 0, 0, Qt::AlignCenter, text() ).height();
int wp = mPixmap.width();
int hp = mPixmap.height();
+ painter->drawPixmap( (mMinimumWidth - wp) / 2, 5, mPixmap );
- painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap );
if( !text().isEmpty() )
{
- painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() );
+ painter->drawText( 1, hp + 7, mMinimumWidth - 2, ht, Qt::AlignCenter, text() );
}
}
@@ -1082,6 +1182,7 @@ int KJanusWidget::IconListItem::width( const TQListBox *lb ) const
void KJanusWidget::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
+
// TODO: In TreeList, if the last child of a node is removed, and there is no corrsponding widget for that node, allow the caller to
// delete the node.
void KJanusWidget::removePage( TQWidget *page )
@@ -1129,6 +1230,7 @@ void KJanusWidget::removePage( TQWidget *page )
}
}
+
TQString KJanusWidget::pageTitle(int index) const
{
if (!d || !d->mIntToTitle.contains(index))
@@ -1137,6 +1239,7 @@ TQString KJanusWidget::pageTitle(int index) const
return d->mIntToTitle[index];
}
+
TQWidget *KJanusWidget::pageWidget(int index) const
{
if (!d || !d->mIntToPage.contains(index))