Beispiel #1
0
int ScrollBar::extent() const
{
    QStyleOptionSlider opt;
    opt.init(this);
    opt.subControls = QStyle::SC_None;
    opt.activeSubControls = QStyle::SC_None;
    opt.orientation = orientation();
    opt.minimum = minimum();
    opt.maximum = maximum();
    opt.sliderPosition = sliderPosition();
    opt.sliderValue = value();
    opt.singleStep = singleStep();
    opt.pageStep = pageStep();
    opt.upsideDown = invertedAppearance();
    if (orientation() == Qt::Horizontal)
        opt.state |= QStyle::State_Horizontal;
    return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this);
}
Beispiel #2
0
void VCSlider::slotMonitorDMXValueChanged(int value)
{
    if (value != sliderValue())
    {
        if (invertedAppearance())
            m_monitorValue = 255 - value;
        else
            m_monitorValue = value;
        m_levelValueMutex.lock();
        m_levelValue = m_monitorValue;
        m_levelValueMutex.unlock();
        if (m_slider)
            m_slider->blockSignals(true);
        setSliderValue(m_monitorValue, true);
        setTopLabelText(sliderValue());
        if (m_slider)
            m_slider->blockSignals(false);
        updateFeedback();
    }
}
Beispiel #3
0
/**
 * @brief TextBubbleSlider::paintEvent Reimplements QSlider::paintEvent.
 * @param bob
 */
void TextBubbleSlider::paintEvent(QPaintEvent *paintEvent)
{
    if (hidden)
    {
        return;
    }

    // Pass paint event on to QSlider
    QSlider::paintEvent(paintEvent);

    /* Add numbers on top of handler */

    // Calculate pixel position for text.
    int sliderWidth = width();
    int sliderHeight = height();
    double valuePos;

    if (!invertedAppearance()) {
        valuePos = (slideHandleWidth - maximumFontWidth)/2 + slideHandleMargin + // First part centers text in handle...
                (value()-minimum())/(double)(maximum()-minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); //... and second part moves text with handle
    } else {
        valuePos = (slideHandleWidth - maximumFontWidth)/2 + slideHandleMargin + // First part centers text in handle...
                (maximum()-value())/(double)(maximum()-minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); //... and second part moves text with handle
    }

    // Create painter and set font
    QPainter painter(this);
    painter.setFont(font);

    // Draw neutral value text. Verically center it in the handle
    QString neutralStringWidth = QString("%1").arg(value());
    QFontMetrics fontMetrics(font);
    int textWidth = fontMetrics.width(neutralStringWidth);
    painter.drawText(QRectF(valuePos + maximumFontWidth - textWidth, ceil((sliderHeight - maximumFontHeight)/2.0), textWidth, maximumFontHeight),
                     neutralStringWidth);
}
Beispiel #4
0
        void mousePressEvent ( QMouseEvent * event )
        {
            QStyleOptionSlider opt;
            initStyleOption(&opt);
            QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);

            if (event->button() == Qt::LeftButton &&
                    sr.contains(event->pos()) == false)
            {
                int newVal;
                if (orientation() == Qt::Vertical)
                    newVal = minimum() + ((maximum()-minimum()) * (height()-event->y())) / height();
                else
                    newVal = minimum() + ((maximum()-minimum()) * event->x()) / width();

                if (invertedAppearance() == true)
                    setValue( maximum() - newVal );
                else
                    setValue(newVal);

                event->accept();
            }
            QSlider::mousePressEvent(event);
        }
Beispiel #5
0
void
StatsGauge::paintEvent( QPaintEvent* event )
{
    QPainter p( this );
    p.setRenderHint( QPainter::Antialiasing );
    p.setClipRect( event->rect() );

    QSize gaugeSize = m_sizeHint - QSize( 0, 40 );

    QPen pen( TomahawkStyle::HEADER_GAUGE_HIGHLIGHT );
    pen.setWidth( 16 );
    p.setPen( pen );

    int fullCircle = 16 * 360;
    p.drawArc( QRect( 12, 12, gaugeSize.width() - 24, gaugeSize.height() - 24 ),
               4 * 360, (int)( -1.0 * (float)fullCircle * ( invertedAppearance() ? ( 1.0 - m_percentage ) : m_percentage ) ) );

    pen = QPen( TomahawkStyle::HEADER_GAUGE_HIGHLIGHT.darker() );
    pen.setWidth( 6 );
    p.setPen( pen );

    QBrush brush( TomahawkStyle::HEADER_GAUGE_BACKGROUND );
    p.setBrush( brush );
    p.drawEllipse( QRect( 28, 28, gaugeSize.width() - 56, gaugeSize.height() - 56 ) );

    pen = QPen( TomahawkStyle::HEADER_GAUGE_TEXT );
    p.setPen( pen );
    QFont font = p.font();
    font.setWeight( QFont::Black );

    if ( value() <= 999 )
        font.setPixelSize( 60 );
    else
        font.setPixelSize( 44 );

    p.setFont( font );
    QRect textRect( 0, gaugeSize.height() / 2 - 14, gaugeSize.width(), 62 );
    p.drawText( textRect, Qt::AlignCenter, value() > 0 ? QString::number( value() ) : "-" );

    pen = QPen( TomahawkStyle::HEADER_GAUGE_TEXT.darker() );
    p.setPen( pen );
    font = p.font();
    font.setWeight( QFont::Black );
    font.setPixelSize( 16 );
    p.setFont( font );

    textRect = QRect( 0, gaugeSize.height() / 2 - 32, gaugeSize.width(), 20 );
    p.drawText( textRect, Qt::AlignCenter, maximum() > 0 ? tr( "out of %1" ).arg( maximum() ) : "-" );

    if ( !m_text.isEmpty() )
    {
        pen = QPen( TomahawkStyle::HEADER_GAUGE_TEXT );
        p.setPen( pen );
        font = p.font();
        font.setWeight( QFont::DemiBold );
        font.setPixelSize( 16 );
        p.setFont( font );

        QColor figColor( TomahawkStyle::HEADER_GAUGE_LABEL_BACKGROUND );
        p.setBrush( figColor );

        QFontMetrics fm( font );
        int textWidth = fm.width( m_text );
        textRect = QRect( m_sizeHint.width() / 2 - ( textWidth / 2 + 12 ), m_sizeHint.height() - 32, textWidth + 24, 28 );

        TomahawkUtils::drawBackgroundAndNumbers( &p, m_text, textRect );
    }
}
int QAbstractSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: sliderPressed(); break;
        case 2: sliderMoved((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 3: sliderReleased(); break;
        case 4: rangeChanged((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 5: actionTriggered((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 6: setValue((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 7: setOrientation((*reinterpret_cast< Qt::Orientation(*)>(_a[1]))); break;
        }
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = minimum(); break;
        case 1: *reinterpret_cast< int*>(_v) = maximum(); break;
        case 2: *reinterpret_cast< int*>(_v) = singleStep(); break;
        case 3: *reinterpret_cast< int*>(_v) = pageStep(); break;
        case 4: *reinterpret_cast< int*>(_v) = value(); break;
        case 5: *reinterpret_cast< int*>(_v) = sliderPosition(); break;
        case 6: *reinterpret_cast< bool*>(_v) = hasTracking(); break;
        case 7: *reinterpret_cast< Qt::Orientation*>(_v) = orientation(); break;
        case 8: *reinterpret_cast< bool*>(_v) = invertedAppearance(); break;
        case 9: *reinterpret_cast< bool*>(_v) = invertedControls(); break;
        case 10: *reinterpret_cast< bool*>(_v) = isSliderDown(); break;
        }
        _id -= 11;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setMinimum(*reinterpret_cast< int*>(_v)); break;
        case 1: setMaximum(*reinterpret_cast< int*>(_v)); break;
        case 2: setSingleStep(*reinterpret_cast< int*>(_v)); break;
        case 3: setPageStep(*reinterpret_cast< int*>(_v)); break;
        case 4: setValue(*reinterpret_cast< int*>(_v)); break;
        case 5: setSliderPosition(*reinterpret_cast< int*>(_v)); break;
        case 6: setTracking(*reinterpret_cast< bool*>(_v)); break;
        case 7: setOrientation(*reinterpret_cast< Qt::Orientation*>(_v)); break;
        case 8: setInvertedAppearance(*reinterpret_cast< bool*>(_v)); break;
        case 9: setInvertedControls(*reinterpret_cast< bool*>(_v)); break;
        case 10: setSliderDown(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 11;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 11;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 11;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Beispiel #7
0
bool VCSlider::saveXML(QDomDocument* doc, QDomElement* vc_root)
{
    QDomElement root;
    QDomElement tag;
    QDomElement subtag;
    QDomText text;
    QString str;

    Q_ASSERT(doc != NULL);
    Q_ASSERT(vc_root != NULL);

    /* VC Slider entry */
    root = doc->createElement(KXMLQLCVCSlider);
    vc_root->appendChild(root);

    /* Caption */
    root.setAttribute(KXMLQLCVCCaption, caption());

    /* Inverted appearance */
    if (invertedAppearance() == true)
        root.setAttribute(KXMLQLCVCSliderInvertedAppearance, "true");
    else
        root.setAttribute(KXMLQLCVCSliderInvertedAppearance, "false");

    /* Window state */
    saveXMLWindowState(doc, &root);

    /* Appearance */
    saveXMLAppearance(doc, &root);

    /* External input */
    saveXMLInput(doc, &root);

    /* Mode */
    tag = doc->createElement(KXMLQLCVCSliderMode);
    root.appendChild(tag);
    text = doc->createTextNode(sliderModeToString(m_sliderMode));
    tag.appendChild(text);

    /* Value display style */
    str = valueDisplayStyleToString(valueDisplayStyle());
    tag.setAttribute(KXMLQLCVCSliderValueDisplayStyle, str);

    /* Level */
    tag = doc->createElement(KXMLQLCVCSliderLevel);
    root.appendChild(tag);

    /* Level low limit */
    str.setNum(levelLowLimit());
    tag.setAttribute(KXMLQLCVCSliderLevelLowLimit, str);

    /* Level high limit */
    str.setNum(levelHighLimit());
    tag.setAttribute(KXMLQLCVCSliderLevelHighLimit, str);

    /* Level value */
    str.setNum(levelValue());
    tag.setAttribute(KXMLQLCVCSliderLevelValue, str);

    /* Level channels */
    QListIterator <LevelChannel> it(m_levelChannels);
    while (it.hasNext() == true)
    {
        LevelChannel lch(it.next());
        lch.saveXML(doc, &tag);
    }

    /* Playback */
    tag = doc->createElement(KXMLQLCVCSliderPlayback);
    root.appendChild(tag);

    /* Playback function */
    subtag = doc->createElement(KXMLQLCVCSliderPlaybackFunction);
    text = doc->createTextNode(QString::number(playbackFunction()));
    subtag.appendChild(text);
    tag.appendChild(subtag);

    return true;
}