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);
}
예제 #2
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);
    }
}
예제 #3
0
    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 );
        }
    }
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);
}
예제 #5
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);
    }
}
예제 #6
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);
}
}
예제 #7
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);
    }
}
예제 #8
0
void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget,
    const QRect &rect)
{
#if QT_VERSION < 0x040000
        widget->style().drawPrimitive(QStyle::PE_FocusRect, painter,
            rect, widget->colorGroup());
#else
        QStyleOptionFocusRect opt;
        opt.init(widget);
        opt.rect = rect;
        opt.state |= QStyle::State_HasFocus;

        widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect,
            &opt, painter, widget);
#endif

}
예제 #9
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);
    }
}
예제 #10
0
void VColorButton::drawButton(QPainter *p)
{
    QStyleOptionButton buttonOptions;
    buttonOptions.init(this);
    buttonOptions.features = QStyleOptionButton::None;
    buttonOptions.rect = rect();
    buttonOptions.palette = palette();
    buttonOptions.state = (isDown() ? QStyle::State_Sunken : QStyle::State_Raised);
    style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &buttonOptions, p, this);

    p->save();
    drawButtonLabel(p);
    p->restore();

    QStyleOptionFocusRect frectOptions;
    frectOptions.init(this);
    frectOptions.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &buttonOptions, this);
    if (hasFocus())
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frectOptions, p, this);
}
예제 #11
0
파일: plotter.cpp 프로젝트: 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);
    }
}
예제 #12
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);
    }
}
예제 #13
0
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);
    }

}
예제 #14
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);
	}
}
예제 #15
0
void ColorButton::paintEvent( QPaintEvent * )
{
  QPainter painter(this);

  //First, we need to draw the bevel.
  QStyleOptionButton butOpt;
  initStyleOption(&butOpt);
  style()->drawControl( QStyle::CE_PushButtonBevel, &butOpt, &painter, this );

  //OK, now we can muck around with drawing out pretty little color box
  //First, sort out where it goes
  QRect labelRect = style()->subElementRect( QStyle::SE_PushButtonContents,
      &butOpt, this );
  int shift = style()->pixelMetric( QStyle::PM_ButtonMargin );
  labelRect.adjust(shift, shift, -shift, -shift);
  int x, y, w, h;
  labelRect.getRect(&x, &y, &w, &h);

  if (isChecked() || isDown()) {
    x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal );
    y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical   );
  }

  QColor fillCol = isEnabled() ? btnColor : palette().color(backgroundRole());
  qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL);
  if ( fillCol.isValid() )
    painter.fillRect( x+1, y+1, w-2, h-2, fillCol );

  if ( hasFocus() ) {
    QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this );
    QStyleOptionFocusRect focusOpt;
    focusOpt.init(this);
    focusOpt.rect            = focusRect;
    focusOpt.backgroundColor = palette().background().color();
    style()->drawPrimitive( QStyle::PE_FrameFocusRect, &focusOpt, &painter, this );
  }
}
예제 #16
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);
    }
}
예제 #17
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);
    }
}
예제 #18
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 );
  }
}
예제 #19
0
/*!
  \brief Draw the button label
  \sa The Qt Manual on QPushButton
*/
void QwtArrowButton::drawButtonLabel(QPainter *p)
{
    const bool isVertical = d_data->arrowType == Qt::UpArrow ||
        d_data->arrowType == Qt::DownArrow;

    const QRect r = labelRect();
    QSize boundingSize = labelRect().size();
    if ( isVertical )
        boundingSize.transpose();
        
    const int w = 
        (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum;

    QSize arrow = arrowSize(Qt::RightArrow, 
        QSize(w, boundingSize.height()));

    if ( isVertical )
        arrow.transpose();

    QRect contentsSize; // aligned rect where to paint all arrows
    if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow )
    {
        contentsSize.setWidth(d_data->num * arrow.width() 
            + (d_data->num - 1) * Spacing);
        contentsSize.setHeight(arrow.height());
    }
    else
    {
        contentsSize.setWidth(arrow.width());
        contentsSize.setHeight(d_data->num * arrow.height() 
            + (d_data->num - 1) * Spacing);
    }

    QRect arrowRect(contentsSize);
    arrowRect.moveCenter(r.center());
    arrowRect.setSize(arrow);

    p->save();
    for (int i = 0; i < d_data->num; i++)
    {
        drawArrow(p, arrowRect, d_data->arrowType);

        int dx = 0;
        int dy = 0;

        if ( isVertical )
            dy = arrow.height() + Spacing;
        else
            dx = arrow.width() + Spacing;

#if QT_VERSION >= 0x040000
        arrowRect.translate(dx, dy);
#else
        arrowRect.moveBy(dx, dy);
#endif
    }
    p->restore();

    if ( hasFocus() )
    {
#if QT_VERSION >= 0x040000
        QStyleOptionFocusRect option;
        option.init(this);
        option.backgroundColor = palette().color(QPalette::Background);

        style()->drawPrimitive(QStyle::PE_FrameFocusRect, 
            &option, p, this);
#else
        const QRect focusRect =  
            style().subRect(QStyle::SR_PushButtonFocusRect, this);
        style().drawPrimitive(QStyle::PE_FocusRect, p,
            focusRect, colorGroup());
#endif
    }
}
예제 #20
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);
	}
}
예제 #21
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);
	}

	//-------------------------------------------------------------------------
}
예제 #22
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()*/);
        }
    }
}
예제 #23
0
파일: q3groupbox.cpp 프로젝트: Fale/qtmoko
void Q3GroupBox::drawFrame(QPainter *p)
{
    QPoint      p1, p2;
    QStyleOptionFrame opt;
    opt.init(this);

    int frameShape  = d->frameStyle & QFrame::Shape_Mask;
    int frameShadow = d->frameStyle & QFrame::Shadow_Mask;

    int lw = 0;
    int mlw = 0;
    opt.rect = frameRect();

    switch (frameShape) {
    case QFrame::Box:
    case QFrame::HLine:
    case QFrame::VLine:
    case QFrame::StyledPanel:
        lw = d->lineWidth;
        mlw = d->midLineWidth;
        break;
    default:
        // most frame styles do not handle customized line and midline widths
        // (see updateFrameWidth()).
        lw = d->frameWidth;
        break;
    }
    opt.lineWidth = lw;
    opt.midLineWidth = mlw;
    if (frameShadow == Sunken)
        opt.state |= QStyle::State_Sunken;
    else if (frameShadow == Raised)
        opt.state |= QStyle::State_Raised;

    switch (frameShape) {
    case Box:
        if (frameShadow == Plain)
            qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw);
        else
            qDrawShadeRect(p, opt.rect, opt.palette, frameShadow == Sunken, lw, mlw);
        break;

    case StyledPanel:
        style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this);
        break;

    case Panel:
        if (frameShadow == Plain)
            qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw);
        else
            qDrawShadePanel(p, opt.rect, opt.palette, frameShadow == Sunken, lw);
        break;

    case WinPanel:
        if (frameShadow == Plain)
            qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw);
        else
            qDrawWinPanel(p, opt.rect, opt.palette, frameShadow == Sunken);
        break;
    case HLine:
    case VLine:
        if (frameShape == HLine) {
            p1 = QPoint(opt.rect.x(), opt.rect.height() / 2);
            p2 = QPoint(opt.rect.x() + opt.rect.width(), p1.y());
        } else {
            p1 = QPoint(opt.rect.x()+opt.rect.width() / 2, 0);
            p2 = QPoint(p1.x(), opt.rect.height());
        }
        if (frameShadow == Plain) {
            QPen oldPen = p->pen();
            p->setPen(QPen(opt.palette.foreground().color(), lw));
            p->drawLine(p1, p2);
            p->setPen(oldPen);
        } else {
            qDrawShadeLine(p, p1, p2, opt.palette, frameShadow == Sunken, lw, mlw);
        }
        break;
    }

#ifdef QT_KEYPAD_NAVIGATION
    if (QApplication::keypadNavigationEnabled() && hasFocus()) {
        QStyleOptionFocusRect fopt;
        fopt.init(this);
        fopt.state |= QStyle::State_KeyboardFocusChange;
        fopt.rect = frameRect();
        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fopt, p, this);
    }
#endif
}
예제 #24
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);
        }

}