Example #1
0
void Plotter::paintEvent(QPaintEvent * /* event */)
{
    QStylePainter painter(this);
    painter.drawPixmap(0, 0, pixmap);
    if (rubberBandIsShown)
    {
        painter.setPen(palette().light().color());
        /*
         * Using QRect::normalized() ensures that the rubber band rectangle has
         * positive width and height (swap-ping coordinates if necessary),
         * and adjusted() reduces the size of the rectangle by one pixel to
         * allow for its own 1-pixel-wide outline.
         */
        painter.drawRect(rubberBandRect.normalized()
                                       .adjusted(0, 0, -1, -1));
    }

    /*
     * If the Plotter has focus, a focus rectangle is drawn using the widget
     * style's draw-Primitive() function with QStyle::PE_FrameFocusRect as its
     * first argument and a QStyleOptionFocusRect object as its second argument.
     * The focus rectangle's drawing options are inherited from the Plotter widget
     * (by the initFrom() call). The background color must be specified explicitly.
     */
    if (hasFocus())
    {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.backgroundColor = palette().dark().color();
        painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
    }
}
void DetailsButton::paintEvent(QPaintEvent *e)
{
    QWidget::paintEvent(e);

    QPainter p(this);

    // draw hover animation
    if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0) {
		// draw hover animation
		if (!isDown() && m_fader > 0)
			p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180)));
    }

    if (isChecked()) {
        if (m_checkedPixmap.isNull() || m_checkedPixmap.size() / m_checkedPixmap.devicePixelRatio() != contentsRect().size())
            m_checkedPixmap = cacheRendering(contentsRect().size(), true);
        p.drawPixmap(contentsRect(), m_checkedPixmap);
    } else {
        if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() / m_uncheckedPixmap.devicePixelRatio() != contentsRect().size())
            m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
        p.drawPixmap(contentsRect(), m_uncheckedPixmap);
    }
    if (isDown()) {
        p.setPen(Qt::NoPen);
        p.setBrush(QColor(0, 0, 0, 20));
        p.drawRoundedRect(rect().adjusted(1, 1, -1, -1), 1, 1);
    }
    if (hasFocus()) {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
    }
}
Example #3
0
void DateWidget::paintEvent(QPaintEvent *event)
{
	static QPixmap pix = QPixmap(":/calendar").scaled(DATEWIDGETWIDTH, 64);

	QPainter painter(this);

	painter.drawPixmap(QPoint(0, 0), isEnabled() ? pix : QPixmap::fromImage(grayImage(pix.toImage())));

	QString month = mDate.toString("MMM");
	QString year = mDate.toString("yyyy");
	QString day = mDate.toString("dd");

	QFont font = QFont("monospace", 10);
	QFontMetrics metrics = QFontMetrics(font);
	painter.setFont(font);
	painter.setPen(QPen(QBrush(Qt::white), 0));
	painter.setBrush(QBrush(Qt::white));
	painter.drawText(QPoint(6, metrics.height() + 1), month);
	painter.drawText(QPoint(DATEWIDGETWIDTH - metrics.width(year) - 6, metrics.height() + 1), year);

	font.setPointSize(14);
	metrics = QFontMetrics(font);
	painter.setPen(QPen(QBrush(Qt::black), 0));
	painter.setBrush(Qt::black);
	painter.setFont(font);
	painter.drawText(QPoint(DATEWIDGETWIDTH / 2 - metrics.width(day) / 2, 45), day);

	if (hasFocus()) {
		QStyleOptionFocusRect option;
		option.initFrom(this);
		option.backgroundColor = palette().color(QPalette::Background);
		style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
	}
}
Example #4
0
void BcExpander::paintEvent(QPaintEvent * /*event*/)
{
    QPainter p(this);
    p.setRenderHint(QPainter::Antialiasing, true);
    p.setPen(QPen(Qt::lightGray, 2));
    if (m_count > 1) {
        if (QApplication::isRightToLeft()) {
            p.drawLine(5, 1, 1, 5);
            p.drawLine(1, 5, 5, 9);
            p.drawLine(5, 9, 9, 5);
        } else {
            p.drawLine(5, 1, 9, 5);
            p.drawLine(9, 5, 5, 9);
            p.drawLine(5, 9, 1, 5);
        }
    } else {
        if (QApplication::isRightToLeft()) {
            p.drawLine(7, 1, 3, 5);
            p.drawLine(3, 5, 7, 9);
        } else {
            p.drawLine(3, 1, 7, 5);
            p.drawLine(7, 5, 3, 9);
        }
    }

    // focus handling
    if (hasFocus()) {
        QStyleOptionFocusRect opt;
        opt.initFrom(this);
        opt.backgroundColor = Qt::white;
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &p, this);
    }
}
void QgsGradientStopEditor::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  QPainter painter( this );

  QRect frameRect( rect().x() + MARGIN_X, rect().y(),
                   rect().width() - 2 * MARGIN_X,
                   rect().height() - MARGIN_BOTTOM );

  //draw frame
  QStyleOptionFrame option;
  option.initFrom( this );
  option.state = hasFocus() ? QStyle::State_KeyboardFocusChange : QStyle::State_None;
  option.rect = frameRect;
  style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );

  if ( hasFocus() )
  {
    //draw focus rect
    QStyleOptionFocusRect option;
    option.initFrom( this );
    option.state = QStyle::State_KeyboardFocusChange;
    option.rect = frameRect;
    style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
  }

  //start with the checkboard pattern
  QBrush checkBrush = QBrush( transparentBackground() );
  painter.setBrush( checkBrush );
  painter.setPen( Qt::NoPen );

  QRect box( frameRect.x() + FRAME_MARGIN, frameRect.y() + FRAME_MARGIN,
             frameRect.width() - 2 * FRAME_MARGIN,
             frameRect.height() - 2 * FRAME_MARGIN );

  painter.drawRect( box );

  // draw gradient preview on top of checkerboard
  for ( int i = 0; i < box.width() + 1; ++i )
  {
    QPen pen( mGradient.color( static_cast< double >( i ) / box.width() ) );
    painter.setPen( pen );
    painter.drawLine( box.left() + i, box.top(), box.left() + i, box.height() + 1 );
  }

  // draw stop markers
  int markerTop = frameRect.bottom() + 1;
  drawStopMarker( painter, QPoint( box.left(), markerTop ), mGradient.color1(), mSelectedStop == 0 );
  drawStopMarker( painter, QPoint( box.right(), markerTop ), mGradient.color2(), mSelectedStop == mGradient.count() - 1 );
  int i = 1;
  Q_FOREACH ( const QgsGradientStop& stop, mStops )
  {
    int x = stop.offset * box.width() + box.left();
    drawStopMarker( painter, QPoint( x, markerTop ), stop.color, mSelectedStop == i );
    ++i;
  }
Example #6
0
void MotorLever::paintEvent(QPaintEvent *)
{
	QStylePainter painter(this);

	if (hasFocus()) {
		QStyleOptionFocusRect option;
		option.initFrom(this);
		option.backgroundColor = palette().color(QPalette::Background);

		painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
	}
}
void QIRichToolButton::paintEvent (QPaintEvent *aEvent)
{
    /* Draw focus around mLabel if focused */
    if (hasFocus())
    {
        QStylePainter painter (this);
        QStyleOptionFocusRect option;
        option.initFrom (this);
        option.rect = mLabel->frameGeometry();
        painter.drawPrimitive (QStyle::PE_FrameFocusRect, option);
    }
    QWidget::paintEvent (aEvent);
}
Example #8
0
void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option);

    if (m_alternateBackground) {
        const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
        const QRectF backgroundRect(0, 0, size().width(), size().height());
        painter->fillRect(backgroundRect, backgroundColor);
    }

    if (m_selected && m_editedRole.isEmpty()) {
        const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
        drawItemStyleOption(painter, widget, activeState |
                                             QStyle::State_Enabled |
                                             QStyle::State_Selected |
                                             QStyle::State_Item);
    }

    if (m_current && m_editedRole.isEmpty()) {
        QStyleOptionFocusRect focusRectOption;
        focusRectOption.initFrom(widget);
        focusRectOption.rect = textFocusRect().toRect();
        focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
        if (m_selected) {
            focusRectOption.state |= QStyle::State_Selected;
        }

        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
    }

    if (m_hoverOpacity > 0.0) {
        if (!m_hoverCache) {
            // Initialize the m_hoverCache pixmap to improve the drawing performance
            // when fading the hover background
            m_hoverCache = new QPixmap(size().toSize());
            m_hoverCache->fill(Qt::transparent);

            QPainter pixmapPainter(m_hoverCache);
            const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
            drawItemStyleOption(&pixmapPainter, widget, activeState |
                                                        QStyle::State_Enabled |
                                                        QStyle::State_MouseOver |
                                                        QStyle::State_Item);
        }

        const qreal opacity = painter->opacity();
        painter->setOpacity(m_hoverOpacity * opacity);
        painter->drawPixmap(0, 0, *m_hoverCache);
        painter->setOpacity(opacity);
    }
}
QRect KexiRelationsTableFieldList::drawItemHighlighter(QPainter *painter, Q3ListViewItem *item)
{
#ifdef __GNUC__
#warning TODO KexiRelationsTableFieldList::drawItemHighlighter() OK?
#endif
    if (painter) {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.rect = itemRect(item);
        option.state |= QStyle::State_FocusAtBorder;
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, painter, this);
    }
    return itemRect(item);
}
    void paintEvent( QPaintEvent* /*pPaintEvent*/ )
    {
        if( m_Selected )
        {
            QStyle* style = this->style();

            QStyleOptionFocusRect option;
            option.initFrom( this );
            option.rect.adjust( 2, 2, -2, -2 );

            QPainter painter( this );
            style->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter, this );
        }
    }
Example #11
0
/*!
    \reimp
 */
void QxtStars::paintEvent(QPaintEvent* event)
{
    QAbstractSlider::paintEvent(event);

    QPainter painter(this);
    painter.save();
    painter.setPen(palette().color(QPalette::Text));
    painter.setRenderHint(QPainter::Antialiasing);

    const bool invert = invertedAppearance();
    const QSize size = qxt_d().getStarSize();
    const QRectF star = qxt_d().star.boundingRect();
    painter.scale(size.width() / star.width(), size.height() / star.height());
    const int count = maximum() - minimum();
    if (orientation() == Qt::Horizontal)
    {
        painter.translate(-star.x(), -star.y());
        if (invert != isRightToLeft())
            painter.translate((count - 1) * star.width(), 0);
    }
    else
    {
        painter.translate(-star.x(), -star.y());
        if (!invert)
            painter.translate(0, (count - 1) * star.height());
    }
    for (int i = 0; i < count; ++i)
    {
        if (value() > minimum() + i)
            painter.setBrush(palette().highlight());
        else
            painter.setBrush(palette().base());
        painter.drawPath(qxt_d().star);

        if (orientation() == Qt::Horizontal)
            painter.translate(invert != isRightToLeft() ? -star.width() : star.width(), 0);
        else
            painter.translate(0, invert ? star.height() : -star.height());
    }

    painter.restore();
    if (hasFocus())
    {
        QStyleOptionFocusRect opt;
        opt.initFrom(this);
        opt.rect.setSize(sizeHint());
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &painter, this);
    }
}
Example #12
0
void Plotter::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap);
if (rubberBandIsShown) {
painter.setPen(palette().light().color());
painter.drawRect(rubberBandRect.normalized().adjusted(0, 0, -1, -1));
}
if (hasFocus()) {
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().dark().color();
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
Example #13
0
void
QvisOpacitySlider::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    int mid = thickness()/2 + sliderLength() / 8;

    // Draw the gradient pixmap.
    if(gradientImage == 0)
        createGradientImage();
    p.drawImage(0, tickOffset, *gradientImage);

    // Draw the groove on which the slider slides.    
    drawSliderGroove(&p, 0, tickOffset, imageWidth(), thickness(), mid);

    // Figure out the interval between the tick marks.
    int interval = tickInt;
    if(interval <= 0)
    {
        interval = singleStep();
        if(positionFromValue(interval) - positionFromValue(0) < 3)
            interval = pageStep();
    }

    // Draw the tick marks.
    p.fillRect(0, 0, imageWidth(), tickOffset,
               palette().brush(QPalette::Background));
    p.fillRect(0, tickOffset + thickness(), imageWidth(), height(),
               palette().brush(QPalette::Background));
    drawTicks(&p, palette(), 0, tickOffset - 2, interval);

    // Draw the slider
    paintSlider(&p, palette(), sliderRect());

    // Draw the value text.
    paintValueText(&p, palette(), imageWidth(), height());

    // If this widget has focus, draw the focus rectangle.
    if(hasFocus())
    {
        QStyleOptionFocusRect so;
        so.initFrom(this);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, 
                               &so,
                               &p);
    }
}
Example #14
0
void StarWidget::paintEvent(QPaintEvent *event)
{
    QPainter p(this);

    for (int i = 0; i < current; i++)
        p.drawPixmap(i * IMG_SIZE + SPACING, 0, starActive());

    for (int i = current; i < TOTALSTARS; i++)
        p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive());

    if (hasFocus()) {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.backgroundColor = palette().color(QPalette::Background);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
    }
}
Example #15
0
File: plotter.cpp Project: Qmax/PT6
void Plotter::paintEvent(QPaintEvent *pEvent)
{
    //Q_UNUSED(pEvent);
    QStylePainter painter(this);
    QColor l_objColor;
    painter.drawPixmap(0,0,pixmap);
    if(rubberBandIsShown)
    {
        painter.setPen(palette().light().color());
        painter.setBackgroundMode(Qt::TransparentMode);
        painter.fillRect(rubberBandRect,Qt::NoBrush);
        painter.drawRect(rubberBandRect.normalized());
    }
    if(hasFocus())
    {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.backgroundColor = palette().dark().color();
        painter.drawPrimitive(QStyle::PE_FrameFocusRect,option);
    }
}
Example #16
0
void BcLabel::paintEvent(QPaintEvent * event)
{
    // draw underlining if clickable
    if (!m_last && m_hover) {
        QPainter p(this);
        p.setPen(QPen(QPalette().highlight().color(), 1));
        p.drawLine(0, height() - 2, width(), height() - 2);
    }

    // unbreak painting
    QLabel::paintEvent(event);

    // focus handling
    if (hasFocus()) {
        QPainter p(this);
        QStyleOptionFocusRect opt;
        opt.initFrom(this);
        opt.backgroundColor = Qt::white;
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &p, this);
    }
}
void KisAbstractSliderSpinBox::paintEvent(QPaintEvent* e)
{
    Q_D(KisAbstractSliderSpinBox);
    Q_UNUSED(e)

    QPainter painter(this);

    //Create options to draw spin box parts
    QStyleOptionSpinBox spinOpts = spinBoxOptions();

    //Draw "SpinBox".Clip off the area of the lineEdit to avoid double
    //borders being drawn
    painter.save();
    painter.setClipping(true);
    QRect eraseRect(QPoint(rect().x(), rect().y()),
                    QPoint(progressRect(spinOpts).right(), rect().bottom()));
    painter.setClipRegion(QRegion(rect()).subtracted(eraseRect));
    style()->drawComplexControl(QStyle::CC_SpinBox, &spinOpts, &painter, d->dummySpinBox);
    painter.setClipping(false);
    painter.restore();


    //Create options to draw progress bar parts
    QStyleOptionProgressBar progressOpts = progressBarOptions();

    //Draw "ProgressBar" in SpinBox
    style()->drawControl(QStyle::CE_ProgressBar, &progressOpts, &painter, 0);

    //Draw focus if necessary
    if (hasFocus() &&
            d->edit->hasFocus()) {
        QStyleOptionFocusRect focusOpts;
        focusOpts.initFrom(this);
        focusOpts.rect = progressOpts.rect;
        focusOpts.backgroundColor = palette().color(QPalette::Window);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpts, &painter, this);
    }

}
Example #18
0
void StarWidget::paintEvent(QPaintEvent *event)
{
	QPainter p(this);
	QImage star = hasFocus() ? focusedImage(starActive()) : starActive();
	QPixmap selected = QPixmap::fromImage(star);
	QPixmap inactive = QPixmap::fromImage(starInactive());
	const IconMetrics& metrics = defaultIconMetrics();


	for (int i = 0; i < current; i++)
		p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, selected);

	for (int i = current; i < TOTALSTARS; i++)
		p.drawPixmap(i * metrics.sz_small + metrics.spacing, 0, inactive);

	if (hasFocus()) {
		QStyleOptionFocusRect option;
		option.initFrom(this);
		option.backgroundColor = palette().color(QPalette::Background);
		style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
	}
}
Example #19
0
void DetailsButton::paintEvent(QPaintEvent *e)
{
    QWidget::paintEvent(e);

    QPainter p(this);

    // draw hover animation
    if (!HostOsInfo::isMacHost() && !isDown() && m_fader > 0) {
        QColor c = creatorTheme()->color(Theme::DetailsButtonBackgroundColorHover);
        c.setAlpha (int(m_fader * c.alpha()));

        QRect r = rect();
        if (!creatorTheme()->flag(Theme::FlatProjectsMode))
            r.adjust(1, 1, -2, -2);
        p.fillRect(r, c);
    }

    if (isChecked()) {
        if (m_checkedPixmap.isNull() || m_checkedPixmap.size() / m_checkedPixmap.devicePixelRatio() != contentsRect().size())
            m_checkedPixmap = cacheRendering(contentsRect().size(), true);
        p.drawPixmap(contentsRect(), m_checkedPixmap);
    } else {
        if (m_uncheckedPixmap.isNull() || m_uncheckedPixmap.size() / m_uncheckedPixmap.devicePixelRatio() != contentsRect().size())
            m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
        p.drawPixmap(contentsRect(), m_uncheckedPixmap);
    }
    if (isDown()) {
        p.setPen(Qt::NoPen);
        p.setBrush(QColor(0, 0, 0, 20));
        p.drawRoundedRect(rect().adjusted(1, 1, -1, -1), 1, 1);
    }
    if (hasFocus()) {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this);
    }
}
Example #20
0
void QDebugView::paintEvent(QPaintEvent * /*event*/)
{
    if (g_pBoard == NULL) return;

    QPainter painter(this);
    painter.fillRect(0,0, this->width(), this->height(), Qt::white);

    QFont font = Common_GetMonospacedFont();
    painter.setFont(font);
    QFontMetrics fontmetrics(font);
    int cxChar = fontmetrics.averageCharWidth();
    int cyLine = fontmetrics.height();

    CProcessor* pDebugPU = g_pBoard->GetCPU();
    ASSERT(pDebugPU != NULL);
    WORD* arrR = m_wDebugCpuR;
    BOOL* arrRChanged = m_okDebugCpuRChanged;

    drawProcessor(painter, pDebugPU, cxChar * 2, 1 * cyLine, arrR, arrRChanged);

    // Draw stack
    drawMemoryForRegister(painter, 6, pDebugPU, 35 * cxChar, 1 * cyLine);

    drawPorts(painter, 57 * cxChar, 1 * cyLine);

    // Draw focus rect
    if (hasFocus())
    {
        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.state |= QStyle::State_KeyboardFocusChange;
        option.backgroundColor = QColor(Qt::gray);
        option.rect = this->rect();
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
    }
}
Example #21
0
void AmeGradientButton::paintEvent(QPaintEvent *)
{
        QPainter painter(this);

        QColor outlineColor1(0x7e, 0x7e, 0x7e);
        QColor outlineColor2(0x97, 0x97, 0x97);

        QColor topColor, bottomColor;
        if (isDown()) {
                topColor = QColor(0xa3, 0xa3, 0xa3);
                bottomColor = QColor(0x95, 0x95, 0x95);
        } else {
                topColor = QColor(0xfb, 0xfb, 0xfb);
                bottomColor = QColor(0xee, 0xee, 0xee);
        }

        QRect r = painter.window();

        int left, right, h, w, x1, x2;
        h = (height() - 2) / 2;
        x1 = 1; x2 = 0;

        switch (gPos) {
                case LeftButton : {
                        w = width() - 1;
                        left=r.left() + 1;
                        right=r.right();
                        x1 = 2;
                        break;
                }
                case MidButton: {
                        w = width();
                        left = r.left();
                        right = r.right();
                        break;
                }
                case RightButton : {
                        w = width() - 2;
                        left = r.left();
                        right = r.right();
                        x2 = -1;
                        break;
                }
        }

        painter.setPen(QPen(outlineColor1, 0));
        painter.drawLine(QPoint(left, r.top()), QPoint(right, r.top()));


        int y1 = r.top() + 1;
        painter.setPen(QPen(outlineColor2, 0));
        painter.drawLine(QPoint(left, y1), QPoint(left, r.bottom()));
        painter.drawLine(QPoint(left, r.bottom()), QPoint(right, r.bottom()));

        if (gPos == RightButton)
                painter.drawLine(QPoint(right, y1), QPoint(right, r.bottom()));

        left ++;
        painter.fillRect(left, 1, w, h, topColor);
        painter.fillRect(left, h + 1, w, h, bottomColor);

        QStyleOptionFocusRect option;
        option.initFrom(this);
        option.rect.adjust(x1, 1, x2, -1);

        QPixmap pix = icon().pixmap(iconSize(),
                isEnabled() ? QIcon::Normal : QIcon::Disabled,
                isDown() ? QIcon::On : QIcon::Off);

        int pw = pix.width();
        int ph = pix.height();

        QPoint point(option.rect.x() + option.rect.width() / 2 - pw / 2,
                     option.rect.y() + option.rect.height() / 2 - ph / 2);

        painter.drawPixmap(style()->visualPos(layoutDirection(), option.rect, point), pix);

        if (hasFocus()) {
                option.backgroundColor = palette().color(QPalette::Background);
                style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
        }

}
Example #22
0
void FingerList::paintCell(QPainter *p, int row, int col)
{
	int n = row * perRow + col;

	if (n < num) {
		int barre, eff;
		QColor back = palette().color(QPalette::Base);
		QColor fore = palette().color(QPalette::Text);

		// Selection painting

		if (curSel == n) {
			back = palette().color(QPalette::Highlight);
			fore = palette().color(QPalette::HighlightedText);

			p->setBrush(back);
			p->setPen(Qt::NoPen);
			p->drawRect(0, 0, ICONCHORD - 1, ICONCHORD - 1);

			if (hasFocus()) {
				p->setBrush(Qt::NoBrush);
				p->setPen(fore);
				QStyleOptionFocusRect option;
				option.initFrom(this);
				option.backgroundColor = palette().color(QPalette::Highlight);
				style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, p, this);
				// GREYTODO: port these rects?
// 				                       QRect(0, 0, ICONCHORD - 1, ICONCHORD - 1),
// 				                       colorGroup());
			}
		}

		p->setPen(fore);

		// Horizontal lines

		for (int i = 0; i <= NUMFRETS; i++)
			p->drawLine(SCALE/2+BORDER+FRETTEXT,BORDER+SCALE+2*SPACER+i*SCALE,
			            SCALE/2+BORDER+parm->string*SCALE-SCALE+FRETTEXT,
			            BORDER+SCALE+2*SPACER+i*SCALE);

		// Beginning fret number

		int firstFret = parm->frets;
		bool noff = TRUE;

		for (int i = 0; i < parm->string; i++) {
			if ((appl[n].f[i] < firstFret) && (appl[n].f[i] > 0))
				firstFret = appl[n].f[i];
			if (appl[n].f[i] > 5)
				noff = FALSE;
		}

		if (noff)
			firstFret = 1;

		if (firstFret > 1) {
			QString fs;
			fs.setNum(firstFret);
			p->setFont(*fretNumberFont);
			p->drawText(BORDER, BORDER + SCALE + 2 * SPACER, 50, 50,
			            Qt::AlignLeft | Qt::AlignTop, fs);
		}

		// Vertical lines and fingering

		for (int i = 0; i < parm->string; i++) {
			p->drawLine(i * SCALE + BORDER + SCALE / 2 + FRETTEXT,
			            BORDER + SCALE + 2 * SPACER,
			            i * SCALE + BORDER + SCALE / 2 + FRETTEXT,
			            BORDER + SCALE + 2 * SPACER + NUMFRETS * SCALE);
			if (appl[n].f[i] == -1) {
				p->drawLine(i*SCALE+BORDER+CIRCBORD+FRETTEXT,BORDER+CIRCBORD,
				            i*SCALE+BORDER+SCALE-CIRCBORD+FRETTEXT,
				            BORDER+SCALE-CIRCBORD);
				p->drawLine(i*SCALE+BORDER+SCALE-CIRCBORD+FRETTEXT,BORDER+CIRCBORD,
				            i*SCALE+BORDER+CIRCBORD+FRETTEXT,BORDER+SCALE-CIRCBORD);
			} else if (appl[n].f[i]==0) {
				p->setBrush(back);
				p->drawEllipse(i*SCALE+BORDER+CIRCBORD+FRETTEXT,BORDER+CIRCBORD,
				               CIRCLE,CIRCLE);
			} else {
				p->setBrush(fore);
				p->drawEllipse(i*SCALE+BORDER+CIRCBORD+FRETTEXT,
				               BORDER+SCALE+2*SPACER+(appl[n].f[i]-firstFret)*SCALE+
				               CIRCBORD,CIRCLE,CIRCLE);
			}
		}

		// Analyze & draw barre

		p->setBrush(fore);

		for (int i = 0; i < NUMFRETS; i++) {
			barre = 0;
			while ((appl[n].f[parm->string - barre - 1] >= (i + firstFret)) ||
			       (appl[n].f[parm->string - barre - 1] == -1)) {
				barre++;
				if (barre > parm->string - 1)
					break;
			}

			while ((appl[n].f[parm->string-barre]!=(i+firstFret)) && (barre>1))
				barre--;

			eff = 0;
			for (int j = parm->string-barre; j < parm->string; j++) {
				if (appl[n].f[j] != -1)
					eff++;
			}

			if (eff > 2) {
				p->drawRect((parm->string-barre) * SCALE + SCALE / 2 +
				            BORDER + FRETTEXT,
				            BORDER + SCALE + 2 * SPACER + i * SCALE + CIRCBORD,
				            (barre - 1) * SCALE, CIRCLE);
			}
		}

		p->setBrush(Qt::NoBrush);
		p->setPen(Qt::SolidLine);
	}
}
Example #23
0
void QgsColorRampWidget::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  QPainter painter( this );

  if ( mShowFrame )
  {
    //draw frame
    QStyleOptionFrameV3 option;
    option.initFrom( this );
    option.state = hasFocus() ? QStyle::State_KeyboardFocusChange : QStyle::State_None;
    style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );
  }

  if ( hasFocus() )
  {
    //draw focus rect
    QStyleOptionFocusRect option;
    option.initFrom( this );
    option.state = QStyle::State_KeyboardFocusChange;
    style()->drawPrimitive( QStyle::PE_FrameFocusRect, &option, &painter );
  }

  if ( mComponent != QgsColorWidget::Alpha )
  {
    int maxValue = ( mOrientation == QgsColorRampWidget::Horizontal ? width() : height() ) - 1 - 2 * mMargin;
    QColor color = QColor( mCurrentColor );
    color.setAlpha( 255 );
    QPen pen;
    pen.setWidth( 0 );
    painter.setPen( pen );
    painter.setBrush( Qt::NoBrush );

    //draw background ramp
    for ( int c = 0; c <= maxValue; ++c )
    {
      int colorVal = componentRange() * ( double )c / maxValue;
      //vertical sliders are reversed
      if ( mOrientation == QgsColorRampWidget::Vertical )
      {
        colorVal = componentRange() - colorVal;
      }
      alterColor( color, mComponent, colorVal );
      if ( color.hue() < 0 )
      {
        color.setHsv( hue(), color.saturation(), color.value() );
      }
      pen.setColor( color );
      painter.setPen( pen );
      if ( mOrientation == QgsColorRampWidget::Horizontal )
      {
        //horizontal
        painter.drawLine( c + mMargin, mMargin, c + mMargin, height() - mMargin - 1 );
      }
      else
      {
        //vertical
        painter.drawLine( mMargin, c + mMargin, width() - mMargin - 1, c + mMargin );
      }
    }
  }
  else if ( mComponent == QgsColorWidget::Alpha )
  {
    //alpha ramps are drawn differently
    //start with the checkboard pattern
    QBrush checkBrush = QBrush( transparentBackground() );
    painter.setBrush( checkBrush );
    painter.setPen( Qt::NoPen );
    painter.drawRect( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 );
    QLinearGradient colorGrad;
    if ( mOrientation == QgsColorRampWidget::Horizontal )
    {
      //horizontal
      colorGrad = QLinearGradient( mMargin, 0, width() - mMargin - 1, 0 );
    }
    else
    {
      //vertical
      colorGrad = QLinearGradient( 0, mMargin, 0, height() - mMargin - 1 );
    }
    QColor transparent = QColor( mCurrentColor );
    transparent.setAlpha( 0 );
    colorGrad.setColorAt( 0, transparent );
    QColor opaque = QColor( mCurrentColor );
    opaque.setAlpha( 255 );
    colorGrad.setColorAt( 1, opaque );
    QBrush colorBrush = QBrush( colorGrad );
    painter.setBrush( colorBrush );
    painter.drawRect( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 );
  }

  if ( mOrientation == QgsColorRampWidget::Horizontal )
  {
    //draw marker triangles for horizontal ramps
    painter.setRenderHint( QPainter::Antialiasing );
    painter.setBrush( QBrush( Qt::black ) );
    painter.setPen( Qt::NoPen );
    painter.translate( mMargin + ( width() - 2 * mMargin ) * ( double )componentValue() / componentRange(), mMargin - 1 );
    painter.drawPolygon( mTopTriangle );
    painter.translate( 0, height() - mMargin - 2 );
    painter.setBrush( QBrush( Qt::white ) );
    painter.drawPolygon( mBottomTriangle );
    painter.end();
  }
  else
  {
    //draw cross lines for vertical ramps
    int ypos = mMargin + ( height() - 2 * mMargin - 1 ) - ( height() - 2 * mMargin - 1 ) * ( double )componentValue() / componentRange();
    painter.setBrush( Qt::white );
    painter.setPen( Qt::NoPen );
    painter.drawRect( mMargin, ypos - 1, width() - 2 * mMargin - 1, 3 );
    painter.setPen( Qt::black );
    painter.drawLine( mMargin, ypos, width() - mMargin - 1, ypos );
  }
}
Example #24
0
void KexiDBImageBox::paintEvent(QPaintEvent *pe)
{
    if (!m_paintEventEnabled)
        return;
    QPainter p(this);
    p.setClipRect(pe->rect());
    const int _realLineWidth = realLineWidth();
    KexiUtils::WidgetMargins margins(this);
    margins += KexiUtils::WidgetMargins(_realLineWidth);
//Qt3 replaced with 'margins': const int m = realLineWidth() + margin();
    const QBrush bgBrush(palette().brush(backgroundRole()));
    if (designMode() && pixmap().isNull()) {
        QRect r(
            QPoint(margins.left, margins.top),
            size() - QSize(margins.left + margins.right, margins.top + margins.bottom));
//        p.fillRect(0, 0, width(), height(), bgBrush);

        updatePixmap();
        QPixmap *imagBoxPm = scaledImageBoxIcon(margins, size());
        if (imagBoxPm) {
//        QImage img(imagBoxPm->toImage());
//          QPixmap converted(QPixmap::fromImage(img));
            p.drawPixmap(2, height() - margins.top - margins.bottom - imagBoxPm->height() - 2, *imagBoxPm);
        }
        QFont f(qApp->font());
        p.setFont(f);
//        p.setPen(KexiUtils::contrastColor(bg));
        QString text;
        if (dataSource().isEmpty()) {
            text = objectName() + "\n" + i18nc("Unbound Image Box", "(unbound)");
        }
        else {
            text = dataSource();
            const QFontMetrics fm(fontMetrics());
            const QPixmap dataSourceTagIcon(KexiFormUtils::dataSourceTagIcon());
            if (width() >= (dataSourceTagIcon.width() + 2 + fm.boundingRect(r, Qt::AlignCenter, text).width())) {
                r.setLeft( r.left() + dataSourceTagIcon.width() + 2 ); // make some room for the [>] icon
                QRect bounding = fm.boundingRect(r, Qt::AlignCenter, text);
                p.drawPixmap(
                    bounding.left() - dataSourceTagIcon.width() - 2,
                    bounding.top() + bounding.height() / 2 - dataSourceTagIcon.height() / 2,
                    dataSourceTagIcon);
            }
        }
        p.drawText(r, Qt::AlignCenter, text);
    }
    else {
        QSize internalSize(size());
        if (m_chooser && m_dropDownButtonVisible && !dataSource().isEmpty())
            internalSize.setWidth(internalSize.width() - m_chooser->width());

        //clearing needed here because we may need to draw a pixmap with transparency
 //       p.fillRect(0, 0, width(), height(), bgBrush);

        const QRect internalRect(QPoint(0, 0), internalSize);
        if (m_currentScaledPixmap.isNull() || internalRect != m_currentRect) {
            m_currentRect = internalRect;
            m_currentPixmapPos = QPoint(0, 0);
            m_currentScaledPixmap = KexiUtils::scaledPixmap(
                margins, m_currentRect, pixmap(), m_currentPixmapPos, m_alignment,
                m_scaledContents, m_keepAspectRatio,
                m_smoothTransformation ? Qt::SmoothTransformation : Qt::FastTransformation);
        }
        p.drawPixmap(m_currentPixmapPos, m_currentScaledPixmap);
//        KexiUtils::drawPixmap(p, margins, QRect(QPoint(0, 0), internalSize), pixmap(), m_alignment,
//                              m_scaledContents, m_keepAspectRatio);
    }
    KexiFrame::drawFrame(&p);

    if (designMode()) {
        const bool hasFrame = frameWidth() >= 1 && frameShape() != QFrame::NoFrame;
        if (!hasFrame) {
            KFormDesigner::paintWidgetFrame(p, rect());
        }
    }
    else { // data mode
        // if the widget is focused, draw focus indicator rect _if_ there is no chooser button
        if (   !dataSource().isEmpty()
            && hasFocus()
            && (!m_chooser || !m_chooser->isVisible()))
        {
            QStyleOptionFocusRect option;
            option.initFrom(this);
            //option.rect = style().subRect(QStyle::SR_PushButtonContents);
            style()->drawPrimitive(
                QStyle::PE_FrameFocusRect, &option, &p, this
                /*Qt4 , palette().active()*/);
        }
    }
}
Example #25
0
void StyledButton::paintEvent(QPaintEvent *ev)
{
	QPainter p(this);

	// Initialize button style options
	QStyleOptionButton opt;
	initStyleOption(&opt);

	// Determine colour set to paint with
	QColor topCol(*(m_colorSet.topColor));
	QColor bottomCol(*(m_colorSet.bottomColor));
	QColor highlightCol(*(m_colorSet.highlightColor));
	QColor shadowCol(*(m_colorSet.shadowColor));
	StyleHelper::ColorSet set(&topCol, &bottomCol, &highlightCol, &shadowCol);
	if(m_hovered) {
		topCol = topCol.darker(BUTTON_HOVER_DARKEN_AMOUNT);
		bottomCol = bottomCol.darker(BUTTON_HOVER_DARKEN_AMOUNT);
		highlightCol = highlightCol.darker(BUTTON_HOVER_DARKEN_AMOUNT);
		shadowCol = shadowCol.darker(BUTTON_HOVER_DARKEN_AMOUNT);
	}
	opt.palette.setColor(QPalette::ButtonText, m_textColor);

	// Draw background
	StyleHelper::drawBackground(
		&p, QRect(0, 0, width(), height()), set,
		opt.state & QStyle::State_Sunken, 0.0f, m_joinLeft, m_joinRight);

	//-------------------------------------------------------------------------
	// This section duplicated in `DarkStyle` (CE_PushButtonLabel)
	// The only difference is that we hard-code the pressed button offset

	// Get contents rectangle
	QMargins margins = contentsMargins();
	QStyleOptionButton subopt = opt;
	subopt.rect = opt.rect.adjusted(
		margins.left(), margins.top(),
		-margins.right(), -margins.bottom());

	QRect textRect = subopt.rect;
	uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
	if(!style()->styleHint(QStyle::SH_UnderlineShortcut, &subopt, this))
		tf |= Qt::TextHideMnemonic;

	// Draw the icon if one exists. We need to modify the text rectangle as
	// well as we want both the icon and the text centered on the button
	QRect iconRect;
	if(!subopt.icon.isNull()) {
		// Determine icon state
		QIcon::Mode mode = (subopt.state & QStyle::State_Enabled) ?
			QIcon::Normal : QIcon::Disabled;
		if(mode == QIcon::Normal && subopt.state & QStyle::State_HasFocus)
			mode = QIcon::Active;
		QIcon::State state = QIcon::Off;
		if(subopt.state & QStyle::State_On)
			state = QIcon::On;

		// Determine metrics
		QPixmap pixmap = subopt.icon.pixmap(subopt.iconSize, mode, state);
		int labelWidth = pixmap.width();
		int labelHeight = pixmap.height();
		int iconSpacing = 4; // See `sizeHint()`
		int textWidth = subopt.fontMetrics.boundingRect(
			subopt.rect, tf, subopt.text).width();
		if(!subopt.text.isEmpty())
			labelWidth += textWidth + iconSpacing;

		// Determine icon rectangle
		iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
			textRect.y() + (textRect.height() - labelHeight) / 2,
			pixmap.width(), pixmap.height());
		iconRect = QStyle::visualRect(subopt.direction, textRect, iconRect);

		// Change where the text will be displayed
		tf |= Qt::AlignLeft; // Left align, we adjust the text rect instead
		if(subopt.direction == Qt::RightToLeft)
			textRect.setRight(iconRect.left() - iconSpacing);
		else
			textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing);

		// Translate the contents slightly when the button is pressed
		if(subopt.state & QStyle::State_Sunken)
			iconRect.translate(1, 1);

		// Draw pixmap
		p.drawPixmap(iconRect, pixmap);
	} else
		tf |= Qt::AlignHCenter;

	// HACK: Move the text up 1px so that it is vertically centered
	textRect.translate(0, -1);

	// Translate the contents slightly when the button is pressed
	if(subopt.state & QStyle::State_Sunken)
		textRect.translate(1, 1);

	// Draw text shadow only if the button is enabled
	if(subopt.state & QStyle::State_Enabled) {
		QPalette pal(subopt.palette);
		pal.setColor(QPalette::ButtonText, m_textShadowColor);
		style()->drawItemText(
			&p, textRect.translated(2, 1).adjusted(-1, -1, 1, 1), tf, pal,
			true, subopt.text, QPalette::ButtonText);
	}

	// Draw text. HACK: We offset the text by one pixel to the right as the
	// font metrics include the character spacing to the right of the last
	// character making the text appear slightly to the left. We also increase
	// the rectangle by 1px in every direction in order for the text to not get
	// clipped with some fonts.
	style()->drawItemText(
		&p, textRect.translated(1, 0).adjusted(-1, -1, 1, 1), tf,
		subopt.palette, (subopt.state & QStyle::State_Enabled), subopt.text,
		QPalette::ButtonText);

	//-------------------------------------------------------------------------
	// This section is based off QCommonStyle (CE_PushButton)
	// We change the way the focus rectangle is calculated as the original
	// algorithm has some bugs

	// Draw focus rectangle
	if(hasFocus()) {
		int pad =
			style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this) + 1;

		QStyleOptionFocusRect fropt;
		fropt.initFrom(this);
		fropt.QStyleOption::operator=(opt);

		// Determine bounding rectangle
		if(!subopt.icon.isNull()) {
			QRegion region(subopt.fontMetrics.boundingRect(
				textRect, tf, subopt.text));
			region += iconRect;
			fropt.rect = region.boundingRect();
			fropt.rect = fropt.rect.adjusted(-pad, -pad, pad, pad);
		} else if(!subopt.text.isEmpty()) {
			fropt.rect = subopt.fontMetrics.boundingRect(
				textRect, tf, subopt.text);
			fropt.rect = fropt.rect.adjusted(-pad, -pad, pad, pad);
		} else {
			fropt.rect = subopt.rect;

			// Translate the contents slightly when the button is pressed
			if(subopt.state & QStyle::State_Sunken)
				fropt.rect.translate(1, 1);
		}

		style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, &p, this);
		//p.drawRect(fropt.rect);
	}

	//-------------------------------------------------------------------------
}