void SourceDirTreeNode::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
    QColorGroup myCg(cg);
    if (!m_sourceDir->found()) {
        myCg.setColor(QColorGroup::Text, cg.mid());
    }

    switch (column) {
        case SourceDirTree::COLUMN_TEXT: {
            KListViewItem::paintCell(p, myCg, column, width, alignment);
            break;
        }
        case SourceDirTree::COLUMN_SELECTED: {
            QFont oldFont = p->font();
            if  (m_selectedFilesCount > 0) {
                QFont font = QFont(oldFont);
                font.setBold(true);
                p->setFont(font);
            }
            KListViewItem::paintCell(p, myCg, column, width, alignment);
            p->setFont(oldFont);
            break;
        }
        case SourceDirTree::COLUMN_INCLUDED: {
            TreeHelper::drawCheckBox(p, cg, backgroundColor(SourceDirTree::COLUMN_INCLUDED), width, this->height(), true, m_sourceDir->include() ? TreeHelper::CHECKED : TreeHelper::NOT_CHECKED);
            break;
        }
    }
}
Пример #2
0
/*!\reimp
 */
void QPlatinumStyle::drawControl( ControlElement element,
				  QPainter *p,
				  const QWidget *widget,
				  const QRect &r,
				  const QColorGroup &cg,
				  SFlags how,
				  const QStyleOption& opt ) const
{
    switch( element ) {
    case CE_PushButton:
	{
#ifndef QT_NO_PUSHBUTTON
	    QColorGroup myCg( cg );
	    const QPushButton *btn;
	    int x1, y1, x2, y2;
	    bool useBevelButton;
	    SFlags flags;
	    flags = Style_Default;
	    btn = (const QPushButton*)widget;
	    p->setBrushOrigin( -widget->backgroundOffset().x(),
			       -widget->backgroundOffset().y() );

	    // take care of the flags based on what we know...
	    if ( btn->isDown() )
		flags |= Style_Down;
	    if ( btn->isOn() )
		flags |= Style_On;
	    if ( btn->isEnabled() )
		flags |= Style_Enabled;
	    if ( btn->isDefault() )
		flags |= Style_Default;
 	    if (! btn->isFlat() && !(flags & Style_Down))
 		flags |= Style_Raised;

	    r.coords( &x1, &y1, &x2, &y2 );

	    p->setPen( cg.foreground() );
	    p->setBrush( QBrush(cg.button(), NoBrush) );

	    QBrush fill;
	    if ( btn->isDown() ) {
		fill = cg.brush( QColorGroup::Dark );
		// this could be done differently, but this
		// makes a down Bezel drawn correctly...
		myCg.setBrush( QColorGroup::Mid, fill );
	    } else if ( btn->isOn() ) {
		fill = QBrush( cg.mid(), Dense4Pattern );
		myCg.setBrush( QColorGroup::Mid, fill );
	    }
	    // to quote the old QPlatinumStlye drawPushButton...
	    // small or square image buttons as well as toggle buttons are
	    // bevel buttons (what a heuristic....)
	    if ( btn->isToggleButton()
		 || ( btn->pixmap() &&
		      (btn->width() * btn->height() < 1600 ||
		       QABS( btn->width() - btn->height()) < 10 )) )
		useBevelButton = TRUE;
	    else
		useBevelButton = FALSE;

	    int diw = pixelMetric( PM_ButtonDefaultIndicator, widget );
	    if ( btn->isDefault() ) {
		x1 += 1;
		y1 += 1;
		x2 -= 1;
		y2 -= 1;
		QColorGroup cg2( myCg );
		SFlags myFlags = flags;
		// don't draw the default button sunken, unless it's necessary.
		if ( myFlags & Style_Down )
		    myFlags ^= Style_Down;
		if ( myFlags & Style_Sunken )
		    myFlags ^= Style_Sunken;

		cg2.setColor( QColorGroup::Button, cg.mid() );
		if ( useBevelButton ) {
		    drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1,
							     x2 - x1 + 1,
							     y2 - y1 + 1 ),
				   myCg, myFlags, opt );
		} else {
		    drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1,
							       x2 - x1 + 1,
							       y2 - y1 + 1 ),
				   cg2, myFlags, opt );
		}
	    }

	    if ( btn->isDefault() || btn->autoDefault() ) {
		x1 += diw;
		y1 += diw;
		x2 -= diw;
		y2 -= diw;
	    }

	    if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) {
		if ( useBevelButton ) {
		    // fix for toggle buttons...
		    if ( flags & (Style_Down | Style_On) )
			flags |= Style_Sunken;
		    drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1,
							     x2 - x1 + 1,
							     y2 - y1 + 1 ),
				   myCg, flags, opt );
		} else {

		    drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1,
							       x2 - x1 + 1,
							       y2 - y1 + 1 ),
				   myCg, flags, opt );
		}
	    }


	    if ( p->brush().style() != NoBrush )
		p->setBrush( NoBrush );
	    break;
#endif
	}
    case CE_PushButtonLabel:
	{
#ifndef QT_NO_PUSHBUTTON
	    const QPushButton *btn;
	    bool on;
	    int x, y, w, h;
	    SFlags flags;
	    flags = Style_Default;
	    btn = (const QPushButton*)widget;
	    on = btn->isDown() || btn->isOn();
	    r.rect( &x, &y, &w, &h );
	    if ( btn->isMenuButton() ) {
		int dx = pixelMetric( PM_MenuButtonIndicator, widget );

		QColorGroup g = cg;
		int xx = x + w - dx - 4;
		int yy = y - 3;
		int hh = h + 6;

		if ( !on ) {
		    p->setPen( g.mid() );
		    p->drawLine( xx, yy + 2, xx, yy + hh - 3 );
		    p->setPen( g.button() );
		    p->drawLine( xx + 1, yy + 1, xx + 1, yy + hh - 2 );
		    p->setPen( g.light() );
		    p->drawLine( xx + 2, yy + 2, xx + 2, yy + hh - 2 );
		}
		if ( btn->isEnabled() )
		    flags |= Style_Enabled;
		drawPrimitive( PE_ArrowDown, p, QRect(x + w - dx - 1, y + 2,
						      dx, h - 4),
			       g, flags, opt );
		w -= dx;
	    }
#ifndef QT_NO_ICONSET
	    if ( btn->iconSet() && !btn->iconSet()->isNull() ) {
		QIconSet::Mode mode = btn->isEnabled()
				      ? QIconSet::Normal : QIconSet::Disabled;
		if ( mode == QIconSet::Normal && btn->hasFocus() )
		    mode = QIconSet::Active;
		QIconSet::State state = QIconSet::Off;
		if ( btn->isToggleButton() && btn->isOn() )
		    state = QIconSet::On;
		QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small,
							 mode, state );
		int pixw = pixmap.width();
		int pixh = pixmap.height();
		p->drawPixmap( x + 2, y + h / 2 - pixh / 2, pixmap );
		x += pixw + 4;
		w -= pixw + 4;
	    }
#endif
	    drawItem( p, QRect( x, y, w, h ),
		      AlignCenter | ShowPrefix,
		      btn->colorGroup(), btn->isEnabled(),
		      btn->pixmap(), btn->text(), -1,
		      on ? &btn->colorGroup().brightText()
		      : &btn->colorGroup().buttonText() );
	    if ( btn->hasFocus() )
		drawPrimitive( PE_FocusRect, p,
			       subRect(SR_PushButtonFocusRect, widget),
			       cg, flags );
	    break;
#endif
	}
    default:
	QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
	break;
    }
}