Esempio n. 1
0
/*!
  Draw a needle looking like a ray
*/
void QwtDialSimpleNeedle::drawRayNeedle(QPainter *painter, 
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, int width, double direction, 
    bool hasKnob)
{
    if ( width <= 0 )
        width = 5;

    direction *= M_PI / 180.0;

    painter->save();

    const QPoint p1(center.x() + 1, center.y() + 2);
    const QPoint p2 = qwtPolar2Pos(p1, length, direction);

    if ( width == 1 )
    {
        const QColor midColor =
            palette.color(colorGroup, QwtPalette::Mid);

        painter->setPen(QPen(midColor, 1));
        painter->drawLine(p1, p2);
    }
    else
    {
        QwtPointArray pa(4);
        pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction + M_PI_2));
        pa.setPoint(1, qwtPolar2Pos(p2, width / 2, direction + M_PI_2));
        pa.setPoint(2, qwtPolar2Pos(p2, width / 2, direction - M_PI_2));
        pa.setPoint(3, qwtPolar2Pos(p1, width / 2, direction - M_PI_2));

        painter->setPen(Qt::NoPen);
        painter->setBrush(palette.brush(colorGroup, QwtPalette::Mid));
        painter->drawPolygon(pa);
    }
    if ( hasKnob )
    {
        int knobWidth = qwtMax(qRound(width * 0.7), 5);
        if ( knobWidth % 2 == 0 )
            knobWidth++;

        drawKnob(painter, center, knobWidth, 
            palette.brush(colorGroup, QwtPalette::Base), 
            false);
    }

    painter->restore();
}
Esempio n. 2
0
void TextEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
{
    QPainter painter(lineNumberArea);
    QPalette b;
    painter.fillRect(event->rect(), b.brush(QWidget::backgroundRole()));


    QTextBlock block = firstVisibleBlock();
    int blockNumber = block.blockNumber();
    int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
    int bottom = top + (int) blockBoundingRect(block).height();

    while (block.isValid() && top <= event->rect().bottom()) {
        if (block.isVisible() && bottom >= event->rect().top()) {
            QString number = QString::number(blockNumber + 1);
            painter.setPen(Qt::lightGray);
            painter.drawText(0, top, lineNumberArea->width() - 4, fontMetrics().height(),
                             Qt::AlignRight, number);
        }

        block = block.next();
        top = bottom;
        bottom = top + (int) blockBoundingRect(block).height();
        ++blockNumber;
    }
}
Esempio n. 3
0
    void drawItemText( QPainter *painter, const QRect &rect, int alignment, const QPalette &palette,
                       bool enabled, const QString& text, QPalette::ColorRole textRole ) const {
        Q_UNUSED( alignment );
        Q_UNUSED( enabled );

        if ( text.isEmpty() ) {
            return;
        }

        QPen savedPen;
        if ( textRole != QPalette::NoRole ) {
            savedPen = painter->pen();
            painter->setPen( QPen( palette.brush( textRole ), savedPen.widthF() ) );
        }

        QPainterPath path;
        QFontMetricsF metrics( painter->font() );
        QPointF point( rect.x() + 7.0, rect.y() + metrics.ascent() );
        path.addText( point, painter->font(), text );
        QPen pen( Qt::white );
        pen.setWidth( 3 );
        painter->setPen( pen );
        painter->setBrush( QBrush( Qt::black ) );
        painter->setRenderHint( QPainter::Antialiasing, true );
        painter->drawPath( path );

        painter->setPen( Qt::NoPen );
        painter->drawPath( path );

        if ( textRole != QPalette::NoRole ) {
            painter->setPen( savedPen );
        }
    }
Esempio n. 4
0
/*!
  Draw a compass needle

 \param painter Painter
 \param palette Palette
 \param colorGroup colorGroup
 \param center Center of the dial, start position for the needle
 \param length Length of the needle
 \param direction Direction of the needle, in degrees counter clockwise
*/
void QwtCompassWindArrow::drawStyle1Needle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, double direction )
{
    const QBrush lightBrush = palette.brush( colorGroup, QPalette::Light );

    const double AR1[] = {0, 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4};
    const double AW1[] = {0, -45, -20, -15, 0, 15, 20, 45};

    const QPoint arrowCenter( center.x() + 1, center.y() + 1 );

    QPolygon pa( 8 );
    pa.setPoint( 0, arrowCenter );
    for ( int i = 1; i < 8; i++ )
    {
        const QPoint p = qwtDegree2Pos( center,
            AR1[i] * length, direction + AW1[i] );
        pa.setPoint( i, p );
    }

    painter->save();
    painter->setPen( Qt::NoPen );
    painter->setBrush( lightBrush );
    painter->drawPolygon( pa );
    painter->restore();
}
QList<QStandardItem*> QDatabaseTableViewController::makeStandardItemListFromStringList(const QList<QString>& szStringList)
{
	QList<QStandardItem*> listStandardItemList;
	QStandardItem* pStandardItem;
	QFont font;

	QPalette palette = QApplication::palette(m_pDatabaseTableView);
	QBrush nullbrush = palette.brush(QPalette::Disabled, QPalette::Text);

	QList<QString>::const_iterator iter = szStringList.begin();
	while(iter != szStringList.end())
	{
		//Getting an item from QList<QString> to add it to a QList<QStandardItem>
		if((*iter).isNull()){
			pStandardItem = new QStandardItem(QString("NULL"));
			font = pStandardItem->font();
			font.setItalic(true);
			pStandardItem->setFont(font);
			pStandardItem->setForeground(nullbrush);
		} else {
			pStandardItem = new QStandardItem(*iter);
		}
		pStandardItem->setEditable(true);
		listStandardItemList.append(pStandardItem);
		iter++;
	}
	return listStandardItemList;
}
Esempio n. 6
0
void DJToolButton::paintEvent( QPaintEvent *event )
{	

	QWidget *parentWidget = qobject_cast<QWidget*>(parent());
	if ( parentWidget ) {
		QPalette::ColorRole parentRole	= parentWidget->backgroundRole();
			
		QPalette parentPalette = parentWidget->palette();
		//QRect rect = parentWidget->rect();
		QBrush parentBrush = parentPalette.brush( parentRole );
		//QPixmap parentPix(prect.width(),prect.height());
		//QPainter p(&pix);
		//p.fillRect(0,0,pix.width(),pix.height(),parentbrush);
		
		QPalette pal = palette();
		pal.setBrush(QPalette::Button,parentBrush);
		setPalette(pal);
	}
	
	//QRect qrect = tbw->geometry();
		//		QRect prect = parent->rect();
	
				
	/*
	QPalette pal = palette();
	//pal.setBrush(QPalette::Background,Qt::red);
	pal.setBrush(QPalette::Button,Qt::green);
	//pal.setBrush(QPalette::Base,Qt::blue);
	setPalette(pal);
	*/
	QToolButton::paintEvent( event );
}
void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role, const QPixmap &pixmap)
{
    for (int i = 0; i < QPalette::NColorGroups; ++i) {
        QColor color = palette.brush(QPalette::ColorGroup(i), role).color();
        palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap));
    }
}
void K3ActiveLabelPrivate::updatePalette()
{
    QPalette p = q->palette();
    p.setBrush(QPalette::Base, p.brush(QPalette::Normal, QPalette::Background));
    p.setColor(QPalette::Text, p.color(QPalette::Normal, QPalette::Foreground));
    q->setPalette(p);
}
Esempio n. 9
0
File: epg.cpp Progetto: mstorsjo/vlc
EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
{
    setWindowTitle( qtr( "Program Guide" ) );

    QVBoxLayout *layout = new QVBoxLayout( this );
    layout->setMargin( 0 );
    epg = new EPGWidget( this );

    QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );

    QVBoxLayout *boxLayout = new QVBoxLayout( descBox );

    description = new QTextEdit( this );
    description->setReadOnly( true );
    description->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
    description->setAutoFillBackground( true );
    description->setAlignment( Qt::AlignLeft | Qt::AlignTop );
    description->setFixedHeight( 100 );

    QPalette palette;
    palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
    description->setPalette( palette );

    title = new QLabel( qtr( "Title" ), this );
    title->setWordWrap( true );

    boxLayout->addWidget( title );
    boxLayout->addWidget( description );

    layout->addWidget( epg, 10 );
    layout->addWidget( descBox );

    CONNECT( epg, itemSelectionChanged( EPGItem *), this, displayEvent( EPGItem *) );
    CONNECT( epg, programActivated(int), THEMIM->getIM(), changeProgram(int) );
    CONNECT( THEMIM->getIM(), epgChanged(), this, scheduleUpdate() );
    CONNECT( THEMIM, inputChanged( bool ), this, inputChanged() );

    QDialogButtonBox *buttonsBox = new QDialogButtonBox( this );

#if 0
    QPushButton *update = new QPushButton( qtr( "Update" ) ); // Temporary to test
    buttonsBox->addButton( update, QDialogButtonBox::ActionRole );
    BUTTONACT( update, updateInfos() );
#endif

    buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
                           QDialogButtonBox::RejectRole );
    boxLayout->addWidget( buttonsBox );
    CONNECT( buttonsBox, rejected(), this, close() );

    timer = new QTimer( this );
    timer->setSingleShot( true );
    timer->setInterval( 5000 );
    CONNECT( timer, timeout(), this, timeout() );

    updateInfos();
    restoreWidgetPosition( "EPGDialog", QSize( 650, 450 ) );
}
Esempio n. 10
0
void QDecorationWindows::paintButton(QPainter *painter, const QWidget *widget, int buttonRegion,
                                     DecorationState state, const QPalette &pal)
{
    QBrush fromBrush, toBrush;
    QPen   titlePen;

    if (widget == qApp->activeWindow() || qApp->activeWindow() == qApp->activePopupWidget()) {
        fromBrush = pal.brush(QPalette::Highlight);
        titlePen  = pal.color(QPalette::HighlightedText);
    } else {
        fromBrush = pal.brush(QPalette::Window);
        titlePen  = pal.color(QPalette::Text);
    }
    toBrush = fromBrush.color().lighter(300);

    QRect brect(QDecoration::region(widget, buttonRegion).boundingRect());
    if (buttonRegion != Close && buttonRegion != Menu)
        painter->fillRect(brect, toBrush);
    else
        painter->fillRect(brect.x() - 2, brect.y(), brect.width() + 4, brect.height(),
                          buttonRegion == Menu ? fromBrush : toBrush);

    int xoff = 1;
    int yoff = 2;
    const QPixmap pm = pixmapFor(widget, buttonRegion, xoff, yoff);
    if (buttonRegion != Menu) {
        if (state & Normal) {
            qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(),
                          brect.height() - 4, pal, false, &pal.brush(QPalette::Window));
        } else if (state & Pressed) {
            qDrawWinPanel(painter, brect.x(), brect.y() + 2, brect.width(),
                          brect.height() - 4, pal, true, &pal.brush(QPalette::Window));
            ++xoff;
            ++yoff;
        }
    } else {
        xoff = 0;
        yoff = 2;
    }

    if (!pm.isNull())
        painter->drawPixmap(brect.x() + xoff, brect.y() + yoff, pm);
}
Esempio n. 11
0
static void qDrawWinArrow(QPainter *p, Qt::ArrowType type, bool down,
                           int x, int y, int w, int h,
                           const QPalette &pal, bool enabled)
{
    QPolygon a;                                // arrow polygon
    switch (type) {
    case Qt::UpArrow:
        a.setPoints(7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2);
        break;
    case Qt::DownArrow:
        a.setPoints(7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2);
        break;
    case Qt::LeftArrow:
        a.setPoints(7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0);
        break;
    case Qt::RightArrow:
        a.setPoints(7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0);
        break;
    default:
        break;
    }
    if (a.isEmpty())
        return;

    if (down) {
        x++;
        y++;
    }

    QPen savePen = p->pen();                        // save current pen
    if (down)
        p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));
    p->fillRect(x, y, w, h, pal.brush(QPalette::Button));
    if (down)
        p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
    if (enabled) {
        a.translate(x+w/2, y+h/2);
        p->setPen(pal.foreground().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    } else {
        a.translate(x+w/2+1, y+h/2+1);
        p->setPen(pal.light().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
        a.translate(-1, -1);
        p->setPen(pal.mid().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    }
    p->setPen(savePen);                        // restore pen
}
Esempio n. 12
0
/*!
  Draw a round frame

  \param painter Painter
  \param rect Frame rectangle
  \param palette QPalette::WindowText is used for plain borders
                 QPalette::Dark and QPalette::Light for raised
                 or sunken borders
  \param lineWidth Line width
  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
*/
void QwtPainter::drawRoundFrame( QPainter *painter,
    const QRectF &rect, const QPalette &palette,
    int lineWidth, int frameStyle )
{
    enum Style
    {
        Plain,
        Sunken,
        Raised
    };

    Style style = Plain;
    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
        style = Sunken;
    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
        style = Raised;

    const double lw2 = 0.5 * lineWidth;
    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );

    QBrush brush;

    if ( style != Plain )
    {
        QColor c1 = palette.color( QPalette::Light );
        QColor c2 = palette.color( QPalette::Dark );

        if ( style == Sunken )
            qSwap( c1, c2 );

        QLinearGradient gradient( r.topLeft(), r.bottomRight() );
        gradient.setColorAt( 0.0, c1 );
#if 0
        gradient.setColorAt( 0.3, c1 );
        gradient.setColorAt( 0.7, c2 );
#endif
        gradient.setColorAt( 1.0, c2 );

        brush = QBrush( gradient );
    }
    else // Plain
    {
        brush = palette.brush( QPalette::WindowText );
    }

    painter->save();

    painter->setPen( QPen( brush, lineWidth ) );
    painter->setBrush( Qt::NoBrush );

    painter->drawEllipse( r );

    painter->restore();
}
Esempio n. 13
0
void LocationBar::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    QPalette p = palette();
    QColor backgroundColor = m_defaultBaseColor;
    if (m_webView && m_webView->url().scheme() == QLatin1String("https")
        && p.brush(QPalette::Text) == Qt::black) {
        QColor lightYellow(248, 248, 210);
        backgroundColor = lightYellow;
    }

    // paint the text background
    QStyleOptionFrameV2 panel;
    initStyleOption(&panel);
    QRect backgroundRect = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
    int left = textMargin(LineEdit::LeftSide);
    int right = textMargin(LineEdit::RightSide);
    backgroundRect.adjust(-left, 0, right, 0);
    painter.setBrush(backgroundColor);
    painter.setPen(backgroundColor);
    painter.drawRect(backgroundRect);

    // paint the progressbar
    if (m_webView && !hasFocus()) {
        int progress = m_webView->progress();
        QColor loadingColor = QColor(116, 192, 250);
        if (p.brush(QPalette::Text) != Qt::black)
            loadingColor = m_defaultBaseColor.value() < 128 ? m_defaultBaseColor.lighter(200) : m_defaultBaseColor.darker(200);

        painter.setBrush(generateGradient(m_defaultBaseColor, loadingColor, height()));
        painter.setPen(Qt::transparent);

        int mid = backgroundRect.width() / 100 * progress;
        QRect progressRect = QRect(backgroundRect.x(), backgroundRect.y(), mid, backgroundRect.height());
        painter.drawRect(progressRect);
    }
    painter.end();

    LineEdit::paintEvent(event);
}
Esempio n. 14
0
void QBB10BrightStyle::polish(QWidget *widget)
{
    // Hide the text by default
    if (QProgressBar *pb = qobject_cast<QProgressBar*>(widget))
        pb->setTextVisible(false);

    if (QComboBox *cb = qobject_cast<QComboBox*>(widget)) {
        QAbstractItemView *list = cb->view();
        QPalette p = list->palette();
        p.setBrush(QPalette::HighlightedText, p.brush(QPalette::Text));
        list->setPalette(p);
    }

    if (qobject_cast<QAbstractItemView*>(widget)) {
        QPalette p = widget->palette();
        p.setBrush(QPalette::Disabled, QPalette::HighlightedText, p.brush(QPalette::Text));
        widget->setPalette(p);
    }

    QPixmapStyle::polish(widget);
}
Esempio n. 15
0
void LaptopClient::updateActiveBuffer( )
{
    QRect rTitle = titleRect();
    if( !bufferDirty && (lastBufferWidth == rTitle.width()))
        return;
    if ( rTitle.width() <= 0 || rTitle.height() <= 0 )
	return;
    lastBufferWidth = rTitle.width();
    bufferDirty = false;

    activeBuffer = QPixmap(rTitle.width(), rTitle.height());
    QPainter p;
    QRect r(0, 0, activeBuffer.width(), activeBuffer.height());
    p.begin(&activeBuffer);
    if(aUpperGradient){
        p.drawTiledPixmap(r, *aUpperGradient);
    }
    else{
        p.fillRect(r, options()->color(KDecoration::ColorTitleBar, true));
    }
    if(titlePix)
        p.drawTiledPixmap(r, *titlePix);

    p.setFont(options()->font(true, isToolWindow() ));
    QFontMetrics fm(options()->font(true));
    QPalette g = options()->palette(KDecoration::ColorTitleBar, true);
    g.setCurrentColorGroup( QPalette::Active );
    if(aUpperGradient)
        p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4,
                          r.y(), fm.width(caption())+8, r.height()-1,
                          *aUpperGradient);
    else
        p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, 0,
                   fm.width(caption())+8, r.height(),
                   g.brush(QPalette::Background));
    p.setPen(g.mid().color());
    p.drawLine(r.x(), r.y(), r.right(), r.y());
    p.drawLine(r.x(), r.y(), r.x(), r.bottom());
    p.setPen(g.color(QPalette::Button));
    p.drawLine(r.right(), r.y(), r.right(), r.bottom());
    p.drawLine(r.x(), r.bottom(), r.right(), r.bottom());
    p.setPen(options()->color(KDecoration::ColorFont, true));
    p.drawText(r.x(), r.y()+1, r.width(), r.height()-1,
               Qt::AlignCenter, caption() );
    g = options()->palette(KDecoration::ColorFrame, true);
    g.setCurrentColorGroup( QPalette::Active );
    p.setPen(g.background().color());
    p.drawPoint(r.x(), r.y());
    p.drawPoint(r.right(), r.y());
    p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom());
    p.end();
}
Esempio n. 16
0
static void qwtDrawStyle2Needle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup, double length )
{
    const double ratioX = 0.7;
    const double ratioY = 0.3;

    QPainterPath path1;
    path1.lineTo( ratioX * length, 0.0 );
    path1.lineTo( length, ratioY * length );

    QPainterPath path2;
    path2.lineTo( ratioX * length, 0.0 );
    path2.lineTo( length, -ratioY * length );

    painter->setPen( Qt::NoPen );

    painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
    painter->drawPath( path1 );

    painter->setBrush( palette.brush( colorGroup, QPalette::Dark ) );
    painter->drawPath( path2 );
}
Esempio n. 17
0
QPalette PaletteEditor::getPalette(QDesignerFormEditorInterface *core, QWidget* parent, const QPalette &init,
            const QPalette &parentPal, int *ok)
{
    PaletteEditor dlg(core, parent);
    QPalette parentPalette(parentPal);
    uint mask = init.resolve();
    for (int i = 0; i < (int)QPalette::NColorRoles; i++) {
        if (!(mask & (1 << i))) {
            parentPalette.setBrush(QPalette::Active, static_cast<QPalette::ColorRole>(i),
                        init.brush(QPalette::Active, static_cast<QPalette::ColorRole>(i)));
            parentPalette.setBrush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i),
                        init.brush(QPalette::Inactive, static_cast<QPalette::ColorRole>(i)));
            parentPalette.setBrush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i),
                        init.brush(QPalette::Disabled, static_cast<QPalette::ColorRole>(i)));
        }
    }
    dlg.setPalette(init, parentPalette);

    const int result = dlg.exec();
    if (ok) *ok = result;

    return result == QDialog::Accepted ? dlg.palette() : init;
}
Esempio n. 18
0
void ListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	QString title = index.data(ListItem::ItemTitle).toString();
	QString description = index.data(ListItem::ItemDescription).toString();
	QIcon icon = QIcon::fromTheme(index.data(ListItem::ItemIcon).toString());
// 	QVariant data = index.data(ListItem::ItemData);

	painter->save();
	QPalette p;
	painter->fillRect(option.rect, p.brush((index.row() % 2 ) ? QPalette::Base : QPalette::AlternateBase));
	QStyle *style = QApplication::style();
	style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
	
		QTextDocument doc;
		painter->translate(option.rect.topLeft());
		if (option.state & QStyle::State_Selected)
		{
		  painter->setPen(option.palette.color(QPalette::Normal, QPalette::HighlightedText));
		  doc.setDefaultStyleSheet("* { color: "+option.palette.color(QPalette::HighlightedText).name()+"; }");
		}
		else
		{
		  painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
		  doc.setDefaultStyleSheet("* { color: "+option.palette.color(QPalette::Text).name()+"; }");
		}
		
		if(!icon.isNull())
		{
		  painter->drawPixmap(5,5,64,64, icon.pixmap(QSize(64,64)));
		}
		
		QFont f = painter->font();
		f.setBold(true);
		painter->setFont(f);
		painter->drawText(74,20, title);
		f.setBold(false);
		
		doc.setUndoRedoEnabled(false);
		doc.setDocumentMargin(0);
		doc.setTextWidth(option.rect.width()-79);
		doc.setUseDesignMetrics(true);
		doc.setHtml("<p>"+description+"</p>");
		QRectF rect = QRectF(QPoint(0,0),doc.size());
		painter->translate(74,20+QFontMetrics(f).height());
		doc.drawContents(painter, rect);
		painter->translate(-74,-20-QFontMetrics(f).height());

	painter->restore();
}
Esempio n. 19
0
/*!
  Draw a compass needle

  \param painter Painter
  \param palette Palette
  \param colorGroup Color group
  \param center Center, where the needle starts
  \param length Length of the needle
  \param direction Direction
*/
void QwtCompassMagnetNeedle::drawThinNeedle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, double direction )
{
    const QBrush darkBrush = palette.brush( colorGroup, QPalette::Dark );
    const QBrush lightBrush = palette.brush( colorGroup, QPalette::Light );
    const QBrush baseBrush = palette.brush( colorGroup, QPalette::Base );

    const int colorOffset = 10;
    const int width = qMax( qRound( length / 6.0 ), 3 );

    painter->save();

    const QPoint arrowCenter( center.x() + 1, center.y() + 1 );

    drawPointer( painter, darkBrush, colorOffset,
        arrowCenter, length, width, direction );
    drawPointer( painter, lightBrush, -colorOffset,
        arrowCenter, length, width, direction + 180.0 );

    drawKnob( painter, arrowCenter, width, baseBrush, true );

    painter->restore();
}
Esempio n. 20
0
/* static */
void UIGSelectorItem::paintBackground(QPainter *pPainter, const QRect &rect,
                                      bool fHasParent, bool fIsSelected,
                                      int iGradientDarkness, DragToken dragTokenWhere)
{
    /* Fill rectangle with brush: */
    QPalette pal = QApplication::palette();
    QColor base = pal.color(QPalette::Active, fIsSelected ? QPalette::Highlight : QPalette::Window);
    pPainter->fillRect(rect, pal.brush(QPalette::Active, QPalette::Base));

    /* Add gradient: */
    QLinearGradient lg(rect.topLeft(), rect.topRight());
    /* For non-root item: */
    if (fHasParent)
    {
        /* Background is animated if drag token missed: */
        lg.setColorAt(0, base.darker(dragTokenWhere == DragToken_Off ? iGradientDarkness : 115));
        lg.setColorAt(1, base.darker(105));
    }
    else
    {
        /* Background is simple: */
        lg.setColorAt(0, base.darker(100));
        lg.setColorAt(1, base.darker(100));
    }
    pPainter->fillRect(rect, lg);

    /* Paint drag token UP? */
    if (dragTokenWhere != DragToken_Off)
    {
        QLinearGradient dragTokenGradient;
        QRect dragTokenRect = rect;
        if (dragTokenWhere == DragToken_Up)
        {
            dragTokenRect.setHeight(10);
            dragTokenGradient.setStart(dragTokenRect.bottomLeft());
            dragTokenGradient.setFinalStop(dragTokenRect.topLeft());
        }
        else if (dragTokenWhere == DragToken_Down)
        {
            dragTokenRect.setTopLeft(dragTokenRect.bottomLeft() - QPoint(0, 10));
            dragTokenGradient.setStart(dragTokenRect.topLeft());
            dragTokenGradient.setFinalStop(dragTokenRect.bottomLeft());
        }
        dragTokenGradient.setColorAt(0, base.darker(115));
        dragTokenGradient.setColorAt(1, base.darker(150));
        pPainter->fillRect(dragTokenRect, dragTokenGradient);
    }
}
bool RenderThemeQt::paintMediaVolumeSliderTrack(RenderObject *o, const PaintInfo &paintInfo, const IntRect &r)
{
    StylePainter p(this, paintInfo);
    if (!p.isValid())
        return true;

    p.painter->setRenderHint(QPainter::Antialiasing, true);

    paintMediaBackground(p.painter, r);

    if (!o->isSlider())
        return false;

    IntRect b = toRenderBox(o)->contentBoxRect();

    // Position the outer rectangle
    int top = r.y() + b.y();
    int left = r.x() + b.x();
    int width = b.width();
    int height = b.height();

    // Get the scale color from the page client
    QPalette pal = QApplication::palette();
    setPaletteFromPageClientIfExists(pal);
    const QColor highlightText = pal.brush(QPalette::Active, QPalette::HighlightedText).color();
    const QColor scaleColor(highlightText.red(), highlightText.green(), highlightText.blue(), mediaControlsBaselineOpacity() * 255);

    // Draw the outer rectangle
    p.painter->setBrush(scaleColor);
    p.painter->drawRect(left, top, width, height);

    if (!o->node() || !o->node()->hasTagName(inputTag))
        return false;

    HTMLInputElement* slider = static_cast<HTMLInputElement*>(o->node());

    // Position the inner rectangle
    height = height * slider->valueAsNumber();
    top += b.height() - height;

    // Draw the inner rectangle
    p.painter->setPen(Qt::NoPen);
    p.painter->setBrush(getMediaControlForegroundColor(o));
    p.painter->drawRect(left, top, width, height);

    return false;
}
QColor RenderThemeQt::getMediaControlForegroundColor(RenderObject* o) const
{
    QColor fgColor = platformActiveSelectionBackgroundColor();
    if (!o)
        return fgColor;

    if (o->node()->active())
        fgColor = fgColor.lighter();

    if (!mediaElementCanPlay(o)) {
        QPalette pal = QApplication::palette();
        setPaletteFromPageClientIfExists(pal);
        fgColor = pal.brush(QPalette::Disabled, QPalette::Text).color();
    }

    return fgColor;
}
Esempio n. 23
0
bool RenderThemeQt::paintMediaVolumeSliderTrack(RenderObject *o, const PaintInfo &paintInfo, const IntRect &r)
{
    QSharedPointer<StylePainter> p = getStylePainter(paintInfo);
    if (p.isNull() || !p->isValid())
        return true;

    p->painter->setRenderHint(QPainter::Antialiasing, true);

    paintMediaBackground(p->painter, r);

    if (!o->isSlider())
        return false;

    IntRect b = pixelSnappedIntRect(toRenderBox(o)->contentBoxRect());

    // Position the outer rectangle
    int top = r.y() + b.y();
    int left = r.x() + b.x();
    int width = b.width();
    int height = b.height();

    QPalette pal = colorPalette();
    const QColor highlightText = pal.brush(QPalette::Active, QPalette::HighlightedText).color();
    const QColor scaleColor(highlightText.red(), highlightText.green(), highlightText.blue(), mediaControlsBaselineOpacity() * 255);

    // Draw the outer rectangle
    p->painter->setBrush(scaleColor);
    p->painter->drawRect(left, top, width, height);

    if (!o->node() || !isHTMLInputElement(o->node()))
        return false;

    HTMLInputElement* slider = toHTMLInputElement(o->node());

    // Position the inner rectangle
    height = height * slider->valueAsNumber();
    top += b.height() - height;

    // Draw the inner rectangle
    p->painter->setPen(Qt::NoPen);
    p->painter->setBrush(getMediaControlForegroundColor(o));
    p->painter->drawRect(left, top, width, height);

    return false;
}
Esempio n. 24
0
/**
 * Constructs the window.
 */
LibraryWindow::LibraryWindow(Place p, QWidget* parent, const char* name,
                             WFlags f)
    : QDockWindow(p, parent, name, f)
{
    modified_ = false;

    setCloseMode(Never);
    setMovingEnabled(TRUE);
    setResizeEnabled(TRUE);

    splitter_ = new QSplitter(Qt::Vertical, this);
    setWidget(splitter_);

    modelListView_ = new LibraryListView(splitter_);
    modelListView_->addColumn(tr("Module"));
    modelListView_->setDefaultRenameAction(QListView::Accept);

    descriptionTextBrowser_ = new QTextBrowser(splitter_);
    QPalette palette = QApplication::palette();
    descriptionTextBrowser_->setFrameStyle(QFrame::NoFrame);
    descriptionTextBrowser_->setPaper
            (palette.brush(QPalette::Normal, QColorGroup::Background));

    popupMenu_ = new QPopupMenu();
    popupMenu_->insertItem(tr("Rename"), this, SLOT(renameSelected()));
    popupMenu_->insertItem(tr("Change Type"),
                           this, SLOT(changeTypeOfSelected()));
    popupMenu_->insertSeparator();
    popupMenu_->insertItem(QPixmap(Util::findIcon("editdelete.png")),
                           tr("Remove"), this, SLOT(removeSelected()));

    connect(modelListView_, SIGNAL(selectionChanged(QListViewItem *)),
            this, SLOT(setDescription(QListViewItem *)));
    connect(this, SIGNAL(orientationChanged(Orientation)),
            this, SLOT(setOrientation(Orientation)));
    connect(modelListView_,
            SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)),
            this, SLOT(showPopup(QListViewItem *, const QPoint &, int)));
    connect(modelListView_, SIGNAL(selectionChanged(QListViewItem *)),
            this, SLOT(selectionChanged(QListViewItem *)));

    // load items
    initialize();
}
Esempio n. 25
0
void UIPopupBox::paintEvent(QPaintEvent *pEvent)
{
    /* Create painter: */
    QPainter painter(this);
    painter.setClipRect(pEvent->rect());

    QPalette pal = palette();
    painter.setClipPath(*m_pLabelPath);
    QColor base = pal.color(QPalette::Active, QPalette::Window);
    QRect rect = QRect(QPoint(0, 0), size()).adjusted(0, 0, -1, -1);
    /* Base background */
    painter.fillRect(QRect(QPoint(0, 0), size()), pal.brush(QPalette::Active, QPalette::Base));
    /* Top header background */
    const int iMaxHeightHint = qMax(m_pTitleLabel->sizeHint().height(),
                                    m_pTitleIcon->sizeHint().height());
    QLinearGradient lg(rect.x(), rect.y(), rect.x(), rect.y() + 2 * 5 + iMaxHeightHint);
    lg.setColorAt(0, base.darker(95));
    lg.setColorAt(1, base.darker(110));
    int theight = rect.height();
    if (m_fOpen)
        theight = 2 * 5 + iMaxHeightHint;
    painter.fillRect(QRect(rect.x(), rect.y(), rect.width(), theight), lg);
    /* Outer round rectangle line */
    painter.setClipping(false);
    painter.strokePath(*m_pLabelPath, base.darker(110));
    /* Arrow */
    if (m_fHeaderHover)
    {
        painter.setBrush(base.darker(106));
        painter.setPen(QPen(base.darker(128), 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
        QSizeF s = m_arrowPath.boundingRect().size();
        if (m_fOpen)
        {
            painter.translate(rect.x() + rect.width() - s.width() - 10, rect.y() + theight / 2 + s.height() / 2);
            /* Flip */
            painter.scale(1, -1);
        }
        else
            painter.translate(rect.x() + rect.width() - s.width() - 10, rect.y() + theight / 2 - s.height() / 2 + 1);

        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawPath(m_arrowPath);
    }
}
Esempio n. 26
0
EXPORT void disableWidget(QWidget *w)
{
    QPalette pal = w->palette();
    pal.setColorGroup(
        QPalette::Disabled,
        pal.brush( QPalette::Active, QPalette::WindowText ),
        pal.brush( QPalette::Active, QPalette::Button ),
        pal.brush( QPalette::Active, QPalette::Light ),
        pal.brush( QPalette::Active, QPalette::Dark ),
        pal.brush( QPalette::Active, QPalette::Mid ),
        pal.brush( QPalette::Active, QPalette::Text ),
        pal.brush( QPalette::Active, QPalette::BrightText ),
        pal.brush( QPalette::Active, QPalette::Base ),
        pal.brush( QPalette::Active, QPalette::Window )
    );
    w->setPalette(pal);
    if (w->inherits("QLineEdit")){
        static_cast<QLineEdit*>(w)->setReadOnly(true);
    }else if (w->inherits("QTextEdit")){
        static_cast<QTextEdit*>(w)->setReadOnly(true);
    }else{
        w->setEnabled(false);
    }
}
Esempio n. 27
0
void PaletteEditor::updatePreviewPalette()
{
    const QPalette::ColorGroup g = currentColorGroup();
    // build the preview palette
    const QPalette currentPalette = palette();
    QPalette previewPalette;
    for (int i = QPalette::WindowText; i < QPalette::NColorRoles; i++) {
        const QPalette::ColorRole r = static_cast<QPalette::ColorRole>(i);
        const QBrush br = currentPalette.brush(g, r);
        previewPalette.setBrush(QPalette::Active, r, br);
        previewPalette.setBrush(QPalette::Inactive, r, br);
        previewPalette.setBrush(QPalette::Disabled, r, br);
    }
    ui.previewFrame->setPreviewPalette(previewPalette);

    const bool enabled = g != QPalette::Disabled;
    ui.previewFrame->setEnabled(enabled);
    ui.previewFrame->setSubWindowActive(g != QPalette::Inactive);
}
Esempio n. 28
0
bool KUrlLabel::event( QEvent *event )
{
  if ( event->type() == QEvent::PaletteChange ) {
    /**
     * Use parentWidget() unless you are a toplevel widget, then try qAapp
     */
    QPalette palette = parentWidget() ? parentWidget()->palette() : qApp->palette();

    palette.setBrush( QPalette::Base, palette.brush( QPalette::Normal, QPalette::Background ) );
    palette.setColor( QPalette::Foreground, this->palette().color( QPalette::Active, QPalette::Foreground ) );
    setPalette( palette );

    d->linkColor = KColorScheme(QPalette::Active, KColorScheme::Window).foreground(KColorScheme::LinkText).color();
    d->updateColor();

    return true;
  } else
    return QLabel::event( event );
}
Esempio n. 29
0
/*!
 *  Highlight background of the current line.
 */
void TextEdit::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    if (!isReadOnly()) {
        QTextEdit::ExtraSelection selection;
        QPalette a;

        selection.format.setBackground(a.brush(QPalette::Window));
        //selection.format.setProperty(QTextFormat::BlockNonBreakableLines, false);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        selection.cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
        selection.cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
        extraSelections.append(selection);
    }

    setExtraSelections(extraSelections);
}
Esempio n. 30
0
/*!
 *  \fn void TextEdit::highlight(const QString &findString, QTextDocument::FindFlags options)
 *  Highlight texts that match the find query in document.
 *
 *  \param &findString  text to be find in document.
 *  \param options      QTextDocument::FindFlags find options.
 */
void TextEdit::highlight(const QString &findString, QTextDocument::FindFlags options)
{
    clearFind();
    QTextDocument *document = this->document();
    QTextCursor highlightCursor(document);
    QTextCharFormat colorFormat(highlightCursor.charFormat());
    colorFormat.setForeground(Qt::white);
    QPalette a;

    QBrush back(a.brush(QPalette::Link).color());//.darker(120));
    colorFormat.setBackground(back);

    while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
        highlightCursor = document->find(findString, highlightCursor, options);

        if (!highlightCursor.isNull()) {
            highlightCursor.setCharFormat(colorFormat);
        }
    }
}