Esempio n. 1
0
/*!
    \internal

    Mostly for the sake of Q3Frame
 */
void QFrame::drawFrame(QPainter *p)
{
    Q_D(QFrame);
    QStyleOptionFrameV3 opt;
    opt.init(this);
    int frameShape  = d->frameStyle & QFrame::Shape_Mask;
    int frameShadow = d->frameStyle & QFrame::Shadow_Mask;
    opt.frameShape = Shape(int(opt.frameShape) | frameShape);
    opt.rect = frameRect();
    switch (frameShape) {
        case QFrame::Box:
        case QFrame::HLine:
        case QFrame::VLine:
        case QFrame::StyledPanel:
        case QFrame::Panel:
            opt.lineWidth = d->lineWidth;
            opt.midLineWidth = d->midLineWidth;
            break;
        default:
            // most frame styles do not handle customized line and midline widths
            // (see updateFrameWidth()).
            opt.lineWidth = d->frameWidth;
            break;
    }

    if (frameShadow == Sunken)
        opt.state |= QStyle::State_Sunken;
    else if (frameShadow == Raised)
        opt.state |= QStyle::State_Raised;

    style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);
}
Esempio n. 2
0
/*!
  Draw the border of the plot canvas

  \param painter Painter
  \sa setBorderRadius()
*/
void QwtPlotCanvas::drawBorder( QPainter *painter )
{
    if ( d_data->borderRadius > 0 )
    {
        if ( frameWidth() > 0 )
        {
            QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ), 
                d_data->borderRadius, d_data->borderRadius,
                palette(), frameWidth(), frameStyle() );
        }
    }
    else
    {
#if QT_VERSION >= 0x040500
#if QT_VERSION < 0x050000
        QStyleOptionFrameV3 opt;
#else
        QStyleOptionFrame opt;
#endif
        opt.init(this);

        int frameShape  = frameStyle() & QFrame::Shape_Mask;
        int frameShadow = frameStyle() & QFrame::Shadow_Mask;

        opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape );
#if 0
        opt.rect = frameRect();
#endif

        switch (frameShape) 
        {
            case QFrame::Box:
            case QFrame::HLine:
            case QFrame::VLine:
            case QFrame::StyledPanel:
            case QFrame::Panel:
            {
                opt.lineWidth = lineWidth();
                opt.midLineWidth = midLineWidth();
                break; 
            }
            default: 
            {
                opt.lineWidth = frameWidth();
                break;
            }
        }
    
        if ( frameShadow == Sunken )
            opt.state |= QStyle::State_Sunken;
        else if ( frameShadow == Raised )
            opt.state |= QStyle::State_Raised;

        style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this);
#else
        drawFrame( painter );
#endif
    }
}
Esempio n. 3
0
/*!
  Draw the border of the canvas
  \param painter Painter
*/
void QwtPlotAbstractCanvas::drawBorder( QPainter *painter )
{
    const QWidget *w = canvasWidget();

    if ( d_data->borderRadius > 0 )
    {
        const int frameWidth = w->property( "frameWidth" ).toInt();
        if ( frameWidth > 0 )
        {
            const int frameShape = w->property( "frameShape" ).toInt();
            const int frameShadow = w->property( "frameShadow" ).toInt();

            const QRectF frameRect = w->property( "frameRect" ).toRect();

            QwtPainter::drawRoundedFrame( painter, frameRect,
                d_data->borderRadius, d_data->borderRadius,
                w->palette(), frameWidth, frameShape | frameShadow );
        }
    }
    else
    {
#if QT_VERSION >= 0x040500
        const int frameShape = w->property( "frameShape" ).toInt();
        const int frameShadow = w->property( "frameShadow" ).toInt();

#if QT_VERSION < 0x050000
        QStyleOptionFrameV3 opt;
#else
        QStyleOptionFrame opt;
#endif
        opt.init( w );

        opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape );

        switch (frameShape)
        {
            case QFrame::Box:
            case QFrame::HLine:
            case QFrame::VLine:
            case QFrame::StyledPanel:
            case QFrame::Panel:
            {
                opt.lineWidth = w->property( "lineWidth" ).toInt();
                opt.midLineWidth = w->property( "midLineWidth" ).toInt();
                break;
            }
            default:
            {
                opt.lineWidth = w->property( "frameWidth" ).toInt();
                break;
            }
        }

        if ( frameShadow == QFrame::Sunken )
            opt.state |= QStyle::State_Sunken;
        else if ( frameShadow == QFrame::Raised )
            opt.state |= QStyle::State_Raised;

        w->style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, w );
#else
        // TODO: do we really need Qt 4.4 ?
#endif
    }
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
void ctkCollapsibleButton::paintEvent(QPaintEvent * _event)
{
  Q_D(ctkCollapsibleButton);

  QPainter p(this);
  // Draw Button
  QStyleOptionButton opt;
  this->initStyleOption(&opt);

  // We don't want to have the highlight effect on the button when mouse is
  // over a child. We want the highlight effect only when the mouse is just
  // over itself.
  // same as this->underMouse()
  bool exclusiveMouseOver = false;
  if (opt.state & QStyle::State_MouseOver)
    {
    QRect buttonRect = opt.rect;
    QList<QWidget*> _children = this->findChildren<QWidget*>();
    QList<QWidget*>::ConstIterator it;
    for (it = _children.constBegin(); it != _children.constEnd(); ++it ) 
      {
      if ((*it)->underMouse())
        {
        // the mouse has been moved from the collapsible button to one 
        // of its children. The paint event rect is the child rect, this
        // is why we have to request another paint event to redraw the 
        // button to remove the highlight effect.
        if (!_event->rect().contains(buttonRect))
          {// repaint the button rect.
          this->update(buttonRect);
          }
        opt.state &= ~QStyle::State_MouseOver;
        exclusiveMouseOver = true;
        break;
        }
      }
    if (d->ExclusiveMouseOver && !exclusiveMouseOver)
      {
      // the mouse is over the widget, but not over the children. As it 
      // has been de-highlighted in the past, we should refresh the button
      // rect to re-highlight the button.
      if (!_event->rect().contains(buttonRect))
        {// repaint the button rect.
        this->update(buttonRect);
        }
      }
    }
  d->ExclusiveMouseOver = exclusiveMouseOver;
  QSize indicatorSize = QSize(style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, this),
                              style()->pixelMetric(QStyle::PM_IndicatorHeight, &opt, this));
  opt.iconSize = indicatorSize;
  style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p, this);
  // TBD is PE_PanelButtonCommand better ?
  //style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &opt, &p, this);
  int buttonHeight = opt.rect.height();
  uint tf = d->TextAlignment;
  if (this->style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
    {
    tf |= Qt::TextShowMnemonic;
    }
  else
    {
    tf |= Qt::TextHideMnemonic;
    }
  int textWidth = opt.fontMetrics.boundingRect(opt.rect, tf, opt.text).width();
  int indicatorSpacing = this->style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &opt, this);
  int buttonMargin = this->style()->pixelMetric(QStyle::PM_ButtonMargin, &opt, this);
  // Draw Indicator
  QStyleOption indicatorOpt;
  indicatorOpt.init(this);
  if (d->IndicatorAlignment & Qt::AlignLeft)
    {
    indicatorOpt.rect = QRect((buttonHeight - indicatorSize.width()) / 2,
                              (buttonHeight - indicatorSize.height()) / 2,
                              indicatorSize.width(), indicatorSize.height());
    }
  else if (d->IndicatorAlignment & Qt::AlignHCenter)
    {
    int w = indicatorSize.width();
    if (!opt.text.isEmpty() && (d->TextAlignment & Qt::AlignHCenter))
      {
      w += textWidth + indicatorSpacing;
      }
    indicatorOpt.rect = QRect(opt.rect.x()+ opt.rect.width() /2 - w / 2,
                              (buttonHeight - indicatorSize.height()) / 2,
                              indicatorSize.width(), indicatorSize.height());
    if (d->TextAlignment & Qt::AlignLeft &&
        indicatorOpt.rect.left() < opt.rect.x() + buttonMargin + textWidth)
      {
      indicatorOpt.rect.moveLeft(opt.rect.x() + buttonMargin + textWidth);
      }
    else if (d->TextAlignment & Qt::AlignRight &&
             indicatorOpt.rect.right() > opt.rect.right() - buttonMargin - textWidth)
      {
      indicatorOpt.rect.moveRight(opt.rect.right() - buttonMargin - textWidth);
      }
    }
  else if (d->IndicatorAlignment & Qt::AlignRight)
    {
    indicatorOpt.rect = QRect(opt.rect.width() - (buttonHeight - indicatorSize.width()) / 2
                                - indicatorSize.width(),
                              (buttonHeight - indicatorSize.height()) / 2,
                              indicatorSize.width(), indicatorSize.height());
    }
  if (d->Collapsed)
    {
    style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &indicatorOpt, &p, this);
    }
  else
    {
    style()->drawPrimitive(QStyle::PE_IndicatorArrowUp, &indicatorOpt, &p, this);
    }

  // Draw Text
  if (d->TextAlignment & Qt::AlignLeft)
    {
    if (d->IndicatorAlignment & Qt::AlignLeft)
      {
      opt.rect.setLeft(indicatorOpt.rect.right() + indicatorSpacing);
      }
    else
      {
      opt.rect.setLeft(opt.rect.x() + buttonMargin);
      }
    }
  else if (d->TextAlignment & Qt::AlignHCenter)
    {
    if (d->IndicatorAlignment & Qt::AlignHCenter)
      {
      opt.rect.setLeft(indicatorOpt.rect.right() + indicatorSpacing);
      }
    else
      {
      opt.rect.setLeft(opt.rect.x() + opt.rect.width() / 2 - textWidth / 2);
      if (d->IndicatorAlignment & Qt::AlignLeft)
        {
        opt.rect.setLeft( qMax(indicatorOpt.rect.right() + indicatorSpacing, opt.rect.left()) );
        }
      }
    }
  else if (d->TextAlignment & Qt::AlignRight)
    {
    if (d->IndicatorAlignment & Qt::AlignRight)
      {
      opt.rect.setLeft(indicatorOpt.rect.left() - indicatorSpacing - textWidth);
      }
    else
      {
      opt.rect.setLeft(opt.rect.right() - buttonMargin - textWidth);
      }
    }
  // all the computations have been made infering the text would be left oriented
  tf &= ~Qt::AlignHCenter & ~Qt::AlignRight;
  tf |= Qt::AlignLeft;
  style()->drawItemText(&p, opt.rect, tf, opt.palette, (opt.state & QStyle::State_Enabled),
                        opt.text, QPalette::ButtonText);

  // Draw Frame around contents
  QStyleOptionFrameV3 fopt;
  fopt.init(this);
  // HACK: on some styles, the frame doesn't exactly touch the button.
  // this is because the button has some kind of extra border.
  if (qobject_cast<QCleanlooksStyle*>(this->style()) != 0)
    {
    fopt.rect.setTop(buttonHeight - 1);
    }
  else
    {
    fopt.rect.setTop(buttonHeight);
    }
  fopt.frameShape = d->ContentsFrameShape;
  switch (d->ContentsFrameShadow)
    {
    case QFrame::Sunken:
      fopt.state |= QStyle::State_Sunken;
      break;
    case QFrame::Raised:
      fopt.state |= QStyle::State_Raised;
      break;
    default:
    case QFrame::Plain:
      break;
    }
  fopt.lineWidth = d->ContentsLineWidth;
  fopt.midLineWidth = d->ContentsMidLineWidth;
  style()->drawControl(QStyle::CE_ShapedFrame, &fopt, &p, this);
}