Esempio n. 1
0
void SpinMirror::setFrame()
{
    // Paint the left hand frame of the main spinbox.
    // Use the part to the left of the edit field, plus a slice at
    // the left of the edit field stretched for the rest of the width.
    // This avoids possibly grabbing text and displaying it in the
    // spin button area.
    QGraphicsScene* c = scene();
    QStyleOptionSpinBox option;
    option.initFrom(mMainSpinbox);
    QRect r = spinBoxEditFieldRect(mMainSpinbox, option);
    bool rtl = QApplication::isRightToLeft();
    QPixmap p;
    if (mMirrored)
    {
        int x = rtl ? 0 : mMainSpinbox->width() - width();
        p = grabWidget(mMainSpinbox, QRect(x, 0, width(), height()));
    }
    else
    {
        // Grab a single pixel wide vertical slice through the main spinbox, between the
        // frame and edit field.
        bool oxygen  = mMainSpinbox->style()->inherits("Oxygen::Style"); // KDE >= 4.4 Oxygen style
        bool oxygen1 = mMainSpinbox->style()->inherits("OxygenStyle");   // KDE <= 4.3 Oxygen style
        int editOffsetY = oxygen ? 5 : oxygen1 ? 6 : 2;   // offset to edit field
        int editOffsetX = (oxygen || oxygen1) ? 4 : 2;   // offset to edit field
        int x = rtl ? r.right() - editOffsetX : r.left() + editOffsetX;
        p = grabWidget(mMainSpinbox, QRect(x, 0, 1, height()));
        // Blot out edit field stuff from the middle of the slice
        QPixmap dot = grabWidget(mMainSpinbox, QRect(x, editOffsetY, 1, 1));
        QPainter painter(&p);
        painter.drawTiledPixmap(0, editOffsetY, 1, height() - 2*editOffsetY, dot, 0, 0);
        painter.end();
        // Horizontally fill the mirror widget with the vertical slice
        p = p.scaled(size());
        // Grab the left hand border of the main spinbox, and draw it into the mirror widget.
        QRect endr = rect();
        if (rtl)
        {
            int mr = mMainSpinbox->width() - 1;
            endr.setWidth(mr - r.right() + editOffsetX);
            endr.moveRight(mr);
        }
        else
            endr.setWidth(r.left() + editOffsetX);
        x = rtl ? width() - endr.width() : 0;
        mMainSpinbox->render(&p, QPoint(x, 0), endr, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);
    }
    c->setBackgroundBrush(p);
}
    //________________________________________________
    QPixmap TransitionWidget::grab( QWidget* widget, QRect rect )
    {

        // change rect
        if( !rect.isValid() ) rect = widget->rect();
        if( !rect.isValid() ) return QPixmap();

        // initialize pixmap
        QPixmap out( rect.size() );
        out.fill( Qt::transparent );
        _paintEnabled = false;

        if( testFlag( GrabFromWindow ) )
        {

            rect = rect.translated( widget->mapTo( widget->window(), widget->rect().topLeft() ) );
            widget = widget->window();
            #if QT_VERSION < 0x050000
            out = QPixmap::grabWidget( widget, rect );
            #else
            out = widget->grab( rect );
            #endif

        } else {

            if( !testFlag( Transparent ) ) { grabBackground( out, widget, rect ); }
            grabWidget( out, widget, rect );

        }

        _paintEnabled = true;

        return out;

    }
Esempio n. 3
0
void SpinMirror::setButtons()
{
    mSpinbox->inhibitPaintSignal(2);
    QStyleOptionSpinBox option;
    mSpinbox->initStyleOption(option);
    QStyle* st = mSpinbox->style();
    QRect r = st->subControlRect(QStyle::CC_SpinBox, &option, QStyle::SC_SpinBoxUp)
              | st->subControlRect(QStyle::CC_SpinBox, &option, QStyle::SC_SpinBoxDown);
    if (isOxygenStyle(mSpinbox))
    {
        // They don't use all their height, so shorten them to
        // allow frame highlighting to work properly.
        r.setTop(r.top() + 1);
        r.setHeight(r.height() - 2);
    }
    mSpinbox->inhibitPaintSignal(1);
    mButtons->setPixmap(grabWidget(mSpinbox, r));
    mSpinbox->inhibitPaintSignal(0);
}