Пример #1
0
int KexiDBImageBox::realLineWidth() const
{
    switch (frameShape()) {
    case QFrame::NoFrame:
        // shadow, line, midline unused
        return 0;
    case QFrame::Box:
        switch (frameShadow()) {
        case QFrame::Plain:
            // midline unused
            return lineWidth();
        default: // sunken, raised:
            return 2 * lineWidth() + midLineWidth();
        }
        break;
    case QFrame::Panel:
        // shadow, midline unused
        return lineWidth();
    case QFrame::WinPanel:
        // shadow, line, midline unused
        return 2;
    case QFrame::StyledPanel: {
        // shadow, line, midline unused
        QStyleOptionFrameV3 option;
        option.initFrom(this);
        return style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this);
    }
    default:
        return lineWidth();
    }
}
Пример #2
0
    void paintFrame()
    {
        QPainter painter( editor );
        QStyleOptionFrameV3 option;
        
        option.initFrom( editor );
        option.palette = originalPalette;
        option.rect = editor->frameRect();
        option.frameShape = editor->frameShape();
        
        switch ( option.frameShape ) {
            case QFrame::Box:
            case QFrame::HLine:
            case QFrame::VLine:
            case QFrame::StyledPanel:
            case QFrame::Panel:
                option.lineWidth = editor->lineWidth();
                option.midLineWidth = editor->midLineWidth();
                break;
            default:
                // most frame styles do not handle customized line and midline widths
                // (see updateFrameWidth()).
                option.lineWidth = editor->frameWidth();
                break;
        }

        if ( editor->frameShadow() == QFrame::Sunken ) {
            option.state |= QStyle::State_Sunken;
        }
        else if ( editor->frameShadow() == QFrame::Raised ) {
            option.state |= QStyle::State_Raised;
        }

        editor->style()->drawControl( QStyle::CE_ShapedFrame, &option, &painter, editor );
    }
Пример #3
0
void QgsColorBox::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  QPainter painter( this );

  QStyleOptionFrameV3 option;
  option.initFrom( this );
  option.state = hasFocus() ? QStyle::State_Active :  QStyle::State_None;
  style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );

  if ( mDirty )
  {
    createBox();
  }

  //draw background image
  painter.drawImage( QPoint( mMargin, mMargin ), *mBoxImage );

  //draw cross lines
  double xPos = mMargin + ( width() - 2 * mMargin - 1 ) * ( double )xComponentValue() / ( double )valueRangeX();
  double yPos = mMargin + ( height() - 2 * mMargin - 1 ) - ( height() - 2 * mMargin - 1 ) * ( double )yComponentValue() / ( double )valueRangeY();

  painter.setBrush( Qt::white );
  painter.setPen( Qt::NoPen );

  painter.drawRect( xPos - 1, mMargin, 3, height() - 2 * mMargin - 1 );
  painter.drawRect( mMargin, yPos - 1, width() - 2 * mMargin - 1, 3 );
  painter.setPen( Qt::black );
  painter.drawLine( xPos, mMargin, xPos, height() - mMargin - 1 );
  painter.drawLine( mMargin, yPos, width() - mMargin - 1, yPos );

  painter.end();
}
Пример #4
0
	void CodeLineEdit::paintEvent(QPaintEvent *event)
	{
		if(!mMultiline)
			QLineEdit::paintEvent(event);

		if(mMultiline || mCode)
		{
			QPainter painter(this);

			if(mMultiline)
			{
				QStyleOptionFrameV3 panel;
				panel.initFrom(this);
				
				if(!mEmbedded)
				{
					panel.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &panel, this);
					panel.midLineWidth = 0;
					panel.state |= QStyle::State_Sunken;
	
					style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &painter, this);
				}

				painter.setBrush(panel.palette.text());
				QFont italicFont = font();
				italicFont.setStyle(QFont::StyleItalic);
				painter.setFont(italicFont);

				QPalette pal = palette();
				pal.setCurrentColorGroup(QPalette::Disabled);

                style()->drawItemText(&painter, rect(), Qt::AlignCenter, pal, false, tr("Multiline, double-click to edit"), QPalette::Text);
			}

			if(mCode)
			{
				QPolygon polygon;
				QColor color;
		
				if(isEnabled())
					color = QColor(255, 0, 0, 200);
				else
					color = QColor(100, 0, 0, 200);
		
				painter.setPen(Qt::NoPen);
				
				int offset = (mEmbedded ? 0 : 4);
		
				polygon << QPoint(offset, offset)
						<< QPoint(6 + offset, offset)
						<< QPoint(offset, 6 + offset);
		
				painter.setBrush(QBrush(color));
				painter.drawPolygon(polygon);
			}
        }
    }
Пример #5
0
QSize LineEdit::sizeHint () const
{
    QFontMetrics fm(font());
    int h = qMax(fm.height(), 14) + 4;
    int w = fm.width(QLatin1Char('x')) * 17 + 4;
    QStyleOptionFrameV3 opt;
    opt.initFrom(this);
    return (style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(w, h).
                                      expandedTo(QApplication::globalStrut()), this));
}
Пример #6
0
void PartResizerWidget::paintEvent(QPaintEvent*)
{
    // draw sunken frame
    QPainter painter(this);
    QStyleOptionFrameV3 opt;
    opt.initFrom(this);
    opt.frameShape = QFrame::StyledPanel;
    opt.rect = contentsRect();
    opt.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this);
    opt.midLineWidth = 0;
    opt.state |= QStyle::State_Sunken;

    style()->drawPrimitive(QStyle::PE_PanelLineEdit, &opt, &painter, this);
}
Пример #7
0
void RatingWidget::paintEvent(QPaintEvent* e) {
  QStylePainter p(this);

  // Draw the background
  QStyleOptionFrameV3 opt;
  opt.initFrom(this);
  opt.state |= QStyle::State_Sunken;
  opt.frameShape = QFrame::StyledPanel;
  opt.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, this);
  opt.midLineWidth = 0;

  p.drawPrimitive(QStyle::PE_PanelLineEdit, opt);

  // Draw the stars
  painter_.Paint(&p, rect(), hover_rating_ == -1.0 ? rating_ : hover_rating_);
}
Пример #8
0
//! Reimplements QListView::resizeEvent.
void TraceWidget::resizeEvent(QResizeEvent * event)
{
  QListWidget::resizeEvent(event);

  QStyleOptionFrameV3 option;
  option.initFrom(this);

  const QRect client = style()->subElementRect(
                        QStyle::SE_FrameContents, &option, this);

  const QRect view = viewport()->rect();
  const QRect visual = QStyle::visualRect(layoutDirection(), view, QRect(
    client.left(), client.top(), cycleBarWidth, view.height() - view.top()));

  cbar_->setGeometry(visual);
}
Пример #9
0
/*!
  \internal
  Updates the frame widths from the style.
*/
void QFramePrivate::updateStyledFrameWidths()
{
    Q_Q(const QFrame);
    QStyleOptionFrameV3 opt;
    opt.initFrom(q);
    opt.lineWidth = lineWidth;
    opt.midLineWidth = midLineWidth;
    opt.frameShape = QFrame::Shape(frameStyle & QFrame::Shape_Mask);

    QRect cr = q->style()->subElementRect(QStyle::SE_ShapedFrameContents, &opt, q);
    leftFrameWidth = cr.left() - opt.rect.left();
    topFrameWidth = cr.top() - opt.rect.top();
    rightFrameWidth = opt.rect.right() - cr.right(),
    bottomFrameWidth = opt.rect.bottom() - cr.bottom();
    frameWidth = qMax(qMax(leftFrameWidth, rightFrameWidth),
                      qMax(topFrameWidth, bottomFrameWidth));
}
Пример #10
0
void QgsColorWheel::paintEvent( QPaintEvent *event )
{
  Q_UNUSED( event );
  QPainter painter( this );

  //draw a frame
  QStyleOptionFrameV3 option = QStyleOptionFrameV3();
  option.initFrom( this );
  option.state = this->hasFocus() ? QStyle::State_Active : QStyle::State_None;
  style()->drawPrimitive( QStyle::PE_Frame, &option, &painter );

  if ( !mWidgetImage || !mWheelImage || !mTriangleImage )
  {
    createImages( size() );
  }

  //draw everything in an image
  mWidgetImage->fill( Qt::transparent );
  QPainter imagePainter( mWidgetImage );
  imagePainter.setRenderHint( QPainter::Antialiasing );

  if ( mWheelDirty )
  {
    //need to redraw the wheel image
    createWheel();
  }

  //draw wheel centered on widget
  QPointF center = QPointF( width() / 2.0, height() / 2.0 );
  imagePainter.drawImage( QPointF( center.x() - ( mWheelImage->width() / 2.0 ), center.y() - ( mWheelImage->height() / 2.0 ) ), *mWheelImage );

  //draw hue marker
  int h = hue();
  double length = mWheelImage->width() / 2.0;
  QLineF hueMarkerLine = QLineF( center.x(), center.y(), center.x() + length, center.y() );
  hueMarkerLine.setAngle( h );
  imagePainter.save();
  //use sourceIn mode for nicer antialiasing
  imagePainter.setCompositionMode( QPainter::CompositionMode_SourceIn );
  QPen pen;
  pen.setWidth( 2 );
  //adapt pen color for hue
  pen.setColor( h > 20 && h < 200 ? Qt::black : Qt::white );
  imagePainter.setPen( pen );
  imagePainter.drawLine( hueMarkerLine );
  imagePainter.restore();

  //draw triangle
  if ( mTriangleDirty )
  {
    createTriangle();
  }
  imagePainter.drawImage( QPointF( center.x() - ( mWheelImage->width() / 2.0 ), center.y() - ( mWheelImage->height() / 2.0 ) ), *mTriangleImage );

  //draw current color marker
  double triangleRadius = length - mWheelThickness - 1;

  //adapted from equations at https://github.com/timjb/colortriangle/blob/master/colortriangle.js by Tim Baumann
  double lightness = mCurrentColor.lightnessF();
  double hueRadians = ( h * M_PI / 180.0 );
  double hx = cos( hueRadians ) * triangleRadius;
  double hy = -sin( hueRadians ) * triangleRadius;
  double sx = -cos( -hueRadians + ( M_PI / 3.0 ) ) * triangleRadius;
  double sy = -sin( -hueRadians + ( M_PI / 3.0 ) ) * triangleRadius;
  double vx = -cos( hueRadians + ( M_PI / 3.0 ) ) * triangleRadius;
  double vy = sin( hueRadians + ( M_PI / 3.0 ) ) * triangleRadius;
  double mx = ( sx + vx ) / 2.0;
  double  my = ( sy + vy ) / 2.0;

  double a = ( 1 - 2.0 * fabs( lightness - 0.5 ) ) * mCurrentColor.hslSaturationF();
  double x = sx + ( vx - sx ) * lightness + ( hx - mx ) * a;
  double y = sy + ( vy - sy ) * lightness + ( hy - my ) * a;

  //adapt pen color for lightness
  pen.setColor( lightness > 0.7 ? Qt::black : Qt::white );
  imagePainter.setPen( pen );
  imagePainter.setBrush( Qt::NoBrush );
  imagePainter.drawEllipse( QPointF( x + center.x(), y + center.y() ), 4.0, 4.0 );
  imagePainter.end();

  //draw image onto widget
  painter.drawImage( QPoint( 0, 0 ), *mWidgetImage );
  painter.end();
}
Пример #11
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 );
  }
}