VirtualBox

Changeset 71863 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 16, 2018 1:56:29 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for QIAdvancedSlider.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71791 r71863  
    440440VirtualBox_QT_MOCHDRS = \
    441441        src/UITakeSnapshotDialog.h \
    442         src/extensions/QIAdvancedSlider.h \
    443442        src/extensions/QIComboBox.h \
    444443        src/extensions/QIFlowLayout.h \
     
    651650        src/VBoxAboutDlg.h \
    652651        src/VBoxLicenseViewer.h \
     652        src/extensions/QIAdvancedSlider.h \
    653653        src/extensions/QIArrowButtonPress.h \
    654654        src/extensions/QIArrowButtonSwitch.h \
     
    723723        src/VBoxAboutDlg.h \
    724724        src/VBoxLicenseViewer.h \
     725        src/extensions/QIAdvancedSlider.h \
    725726        src/extensions/QIArrowButtonPress.h \
    726727        src/extensions/QIArrowButtonSwitch.h \
     
    826827ifndef VBOX_GUI_WITH_SHARED_LIBRARY
    827828 VirtualBox_QT_MOCSRCS += \
     829        src/extensions/QIAdvancedSlider.cpp \
     830        src/extensions/QIArrowSplitter.cpp \
    828831        src/extensions/QISplitter.cpp \
    829         src/extensions/QIArrowSplitter.cpp \
    830832        src/extradata/UIExtraDataManager.cpp \
    831833        src/globals/UIActionPool.cpp \
     
    863865#
    864866VBoxGlobal_QT_MOCSRCS = \
     867        src/extensions/QIAdvancedSlider.cpp \
     868        src/extensions/QIArrowSplitter.cpp \
    865869        src/extensions/QISplitter.cpp \
    866         src/extensions/QIArrowSplitter.cpp \
    867870        src/extradata/UIExtraDataManager.cpp \
    868871        src/globals/UIActionPool.cpp \
     
    901904        src/main.cpp \
    902905        src/UITakeSnapshotDialog.cpp \
    903         src/extensions/QIAdvancedSlider.cpp \
    904906        src/extensions/QIComboBox.cpp \
    905907        src/extensions/QIFlowLayout.cpp \
     
    11451147        src/VBoxAboutDlg.cpp \
    11461148        src/VBoxLicenseViewer.cpp \
     1149        src/extensions/QIAdvancedSlider.cpp \
    11471150        src/extensions/QIArrowButtonPress.cpp \
    11481151        src/extensions/QIArrowButtonSwitch.cpp \
     
    12441247        src/VBoxAboutDlg.cpp \
    12451248        src/VBoxLicenseViewer.cpp \
     1249        src/extensions/QIAdvancedSlider.cpp \
    12461250        src/extensions/QIArrowButtonPress.cpp \
    12471251        src/extensions/QIArrowButtonSwitch.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIAdvancedSlider.cpp

    r69500 r71863  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - VirtualBox Qt extensions: QIAdvancedSlider class implementation.
     3 * VBox Qt GUI - Qt extensions: QIAdvancedSlider class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
     22/* Qt includes: */
     23# include <QPainter>
     24# include <QSlider>
     25# include <QStyle>
     26# include <QVBoxLayout>
     27
     28/* GUI includes: */
    2229# include "QIAdvancedSlider.h"
    2330
    24 /* Qt includes */
    25 # include <QVBoxLayout>
    26 # include <QPainter>
    27 # include <QStyle>
    28 
    2931#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3032
     33/* Qt includes: */
    3134#include <QStyleOptionSlider>
    3235
    33 /* System includes */
     36/* External includes: */
    3437#include <math.h>
    3538
    3639
    37 
    38 class CPrivateSlider : public QSlider
    39 {
     40/** QSlider subclass for our private needs. */
     41class UIPrivateSlider : public QSlider
     42{
     43    Q_OBJECT;
     44
    4045public:
    41     CPrivateSlider(Qt::Orientation fOrientation, QWidget *pParent = 0)
    42       : QSlider(fOrientation, pParent)
    43       , m_optColor(0x0, 0xff, 0x0, 0x3c)
    44       , m_wrnColor(0xff, 0x54, 0x0, 0x3c)
    45       , m_errColor(0xff, 0x0, 0x0, 0x3c)
    46       , m_minOpt(-1)
    47       , m_maxOpt(-1)
    48       , m_minWrn(-1)
    49       , m_maxWrn(-1)
    50       , m_minErr(-1)
    51       , m_maxErr(-1)
    52     {
    53         /* Make sure ticks *always* positioned below: */
    54         setTickPosition(QSlider::TicksBelow);
    55     }
    56 
    57     int positionForValue(int val) const
    58     {
    59         QStyleOptionSlider opt;
    60         initStyleOption(&opt);
    61         opt.subControls = QStyle::SC_All;
    62         int available = opt.rect.width() - style()->pixelMetric(QStyle::PM_SliderLength, &opt, this);
    63         return QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, val, available);
    64     }
    65 
    66     virtual void paintEvent(QPaintEvent *pEvent)
    67     {
    68         QPainter p(this);
    69 
    70         QStyleOptionSlider opt;
    71         initStyleOption(&opt);
    72         opt.subControls = QStyle::SC_All;
    73 
    74         int available = opt.rect.width() - style()->pixelMetric(QStyle::PM_SliderLength, &opt, this);
    75         QSize s = size();
    76 
    77         /* We want to acquire SC_SliderTickmarks sub-control rectangle
    78          * and fill it with necessary background colors: */
     46
     47    /** Constructs private-slider passing @a pParent and @a enmOrientation to the base-class. */
     48    UIPrivateSlider(Qt::Orientation enmOrientation, QWidget *pParent = 0);
     49
     50    /** Returns suitable position for @a iValue. */
     51    int positionForValue(int iValue) const;
     52
     53    /** @todo encapsulate below stuff accordingly.. */
     54
     55    /** Holds the minimum optimal border. */
     56    int m_minOpt;
     57    /** Holds the maximum optimal border. */
     58    int m_maxOpt;
     59    /** Holds the minimum warning border. */
     60    int m_minWrn;
     61    /** Holds the maximum warning border. */
     62    int m_maxWrn;
     63    /** Holds the minimum error border. */
     64    int m_minErr;
     65    /** Holds the maximum error border. */
     66    int m_maxErr;
     67
     68protected:
     69
     70    /** Handles paint @a pEvent. */
     71    virtual void paintEvent(QPaintEvent *pEvent);
     72
     73private:
     74
     75    /** Holds the optimal color. */
     76    QColor m_optColor;
     77    /** Holds the warning color. */
     78    QColor m_wrnColor;
     79    /** Holds the error color. */
     80    QColor m_errColor;
     81};
     82
     83
     84/*********************************************************************************************************************************
     85*   Class UIPrivateSlider implementation.                                                                                        *
     86*********************************************************************************************************************************/
     87
     88UIPrivateSlider::UIPrivateSlider(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
     89    : QSlider(enmOrientation, pParent)
     90    , m_optColor(0x0, 0xff, 0x0, 0x3c)
     91    , m_wrnColor(0xff, 0x54, 0x0, 0x3c)
     92    , m_errColor(0xff, 0x0, 0x0, 0x3c)
     93    , m_minOpt(-1)
     94    , m_maxOpt(-1)
     95    , m_minWrn(-1)
     96    , m_maxWrn(-1)
     97    , m_minErr(-1)
     98    , m_maxErr(-1)
     99{
     100    /* Make sure ticks *always* positioned below: */
     101    setTickPosition(QSlider::TicksBelow);
     102}
     103
     104int UIPrivateSlider::positionForValue(int iValue) const
     105{
     106    QStyleOptionSlider opt;
     107    initStyleOption(&opt);
     108    opt.subControls = QStyle::SC_All;
     109    int iAvailable = opt.rect.width() - style()->pixelMetric(QStyle::PM_SliderLength, &opt, this);
     110    return QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, iValue, iAvailable);
     111}
     112
     113void UIPrivateSlider::paintEvent(QPaintEvent *pEvent)
     114{
     115    QPainter p(this);
     116
     117    QStyleOptionSlider opt;
     118    initStyleOption(&opt);
     119    opt.subControls = QStyle::SC_All;
     120
     121    int iAvailable = opt.rect.width() - style()->pixelMetric(QStyle::PM_SliderLength, &opt, this);
     122    QSize s = size();
     123
     124    /* We want to acquire SC_SliderTickmarks sub-control rectangle
     125     * and fill it with necessary background colors: */
    79126#ifdef VBOX_WS_MAC
    80         /* Under MacOS X SC_SliderTickmarks is not fully reliable
    81          * source of the information we need, providing us with incorrect width.
    82          * So we have to calculate tickmarks rectangle ourself: */
    83         QRect ticks = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderTickmarks, this);
    84         ticks.setRect((s.width() - available) / 2, s.height() - ticks.y(), available, ticks.height());
     127    // WORKAROUND:
     128    // Under MacOS X SC_SliderTickmarks is not fully reliable
     129    // source of the information we need, providing us with incorrect width.
     130    // So we have to calculate tickmarks rectangle ourself.
     131    QRect ticks = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderTickmarks, this);
     132    ticks.setRect((s.width() - iAvailable) / 2, s.height() - ticks.y(), iAvailable, ticks.height());
    85133#else /* VBOX_WS_MAC */
    86         /* Under Windows SC_SliderTickmarks is fully unreliable
    87          * source of the information we need, providing us with empty rectangle.
    88          * Under X11 SC_SliderTickmarks is not fully reliable
    89          * source of the information we need, providing us with different rectangles
    90          * (correct or incorrect) under different look&feel styles.
    91          * So we have to calculate tickmarks rectangle ourself: */
    92         QRect ticks = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this) |
    93                       style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
    94         ticks.setRect((s.width() - available) / 2, ticks.bottom() + 1, available, s.height() - ticks.bottom() - 1);
     134    // WORKAROUND:
     135    // Under Windows SC_SliderTickmarks is fully unreliable
     136    // source of the information we need, providing us with empty rectangle.
     137    // Under X11 SC_SliderTickmarks is not fully reliable
     138    // source of the information we need, providing us with different rectangles
     139    // (correct or incorrect) under different look&feel styles.
     140    // So we have to calculate tickmarks rectangle ourself.
     141    QRect ticks = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this) |
     142                  style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
     143    ticks.setRect((s.width() - iAvailable) / 2, ticks.bottom() + 1, iAvailable, s.height() - ticks.bottom() - 1);
    95144#endif /* VBOX_WS_MAC */
    96145
    97         if ((m_minOpt != -1 &&
    98              m_maxOpt != -1) &&
    99             m_minOpt != m_maxOpt)
    100         {
    101             int posMinOpt = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minOpt, available);
    102             int posMaxOpt = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxOpt, available);
    103             p.fillRect(ticks.x() + posMinOpt, ticks.y(), posMaxOpt - posMinOpt + 1, ticks.height(), m_optColor);
    104         }
    105         if ((m_minWrn != -1 &&
    106              m_maxWrn != -1) &&
    107             m_minWrn != m_maxWrn)
    108         {
    109             int posMinWrn = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minWrn, available);
    110             int posMaxWrn = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxWrn, available);
    111             p.fillRect(ticks.x() + posMinWrn, ticks.y(), posMaxWrn - posMinWrn + 1, ticks.height(), m_wrnColor);
    112         }
    113         if ((m_minErr != -1 &&
    114              m_maxErr != -1) &&
    115             m_minErr != m_maxErr)
    116         {
    117             int posMinErr = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minErr, available);
    118             int posMaxErr = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxErr, available);
    119             p.fillRect(ticks.x() + posMinErr, ticks.y(), posMaxErr - posMinErr + 1, ticks.height(), m_errColor);
    120         }
    121         p.end();
    122 
    123         QSlider::paintEvent(pEvent);
    124     }
    125 
    126     QColor m_optColor;
    127     QColor m_wrnColor;
    128     QColor m_errColor;
    129 
    130     int m_minOpt;
    131     int m_maxOpt;
    132     int m_minWrn;
    133     int m_maxWrn;
    134     int m_minErr;
    135     int m_maxErr;
    136 };
     146    if ((m_minOpt != -1 &&
     147         m_maxOpt != -1) &&
     148        m_minOpt != m_maxOpt)
     149    {
     150        int iPosMinOpt = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minOpt, iAvailable);
     151        int iPosMaxOpt = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxOpt, iAvailable);
     152        p.fillRect(ticks.x() + iPosMinOpt, ticks.y(), iPosMaxOpt - iPosMinOpt + 1, ticks.height(), m_optColor);
     153    }
     154    if ((m_minWrn != -1 &&
     155         m_maxWrn != -1) &&
     156        m_minWrn != m_maxWrn)
     157    {
     158        int iPosMinWrn = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minWrn, iAvailable);
     159        int iPosMaxWrn = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxWrn, iAvailable);
     160        p.fillRect(ticks.x() + iPosMinWrn, ticks.y(), iPosMaxWrn - iPosMinWrn + 1, ticks.height(), m_wrnColor);
     161    }
     162    if ((m_minErr != -1 &&
     163         m_maxErr != -1) &&
     164        m_minErr != m_maxErr)
     165    {
     166        int iPosMinErr = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_minErr, iAvailable);
     167        int iPosMaxErr = QStyle::sliderPositionFromValue(opt.minimum, opt.maximum, m_maxErr, iAvailable);
     168        p.fillRect(ticks.x() + iPosMinErr, ticks.y(), iPosMaxErr - iPosMinErr + 1, ticks.height(), m_errColor);
     169    }
     170    p.end();
     171
     172    /* Call to base-class: */
     173    QSlider::paintEvent(pEvent);
     174}
     175
     176
     177/*********************************************************************************************************************************
     178*   Class QIAdvancedSlider implementation.                                                                                       *
     179*********************************************************************************************************************************/
    137180
    138181QIAdvancedSlider::QIAdvancedSlider(QWidget *pParent /* = 0 */)
    139182  : QWidget(pParent)
    140183{
    141     init();
    142 }
    143 
    144 QIAdvancedSlider::QIAdvancedSlider(Qt::Orientation fOrientation, QWidget *pParent /* = 0 */)
     184    prepare();
     185}
     186
     187QIAdvancedSlider::QIAdvancedSlider(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
    145188  : QWidget(pParent)
    146189{
    147     init(fOrientation);
     190    prepare(enmOrientation);
    148191}
    149192
     
    153196}
    154197
    155 void QIAdvancedSlider::setRange(int minV, int maxV)
    156 {
    157     m_pSlider->setRange(minV, maxV);
    158 }
    159 
    160 void QIAdvancedSlider::setMaximum(int val)
    161 {
    162     m_pSlider->setMaximum(val);
     198void QIAdvancedSlider::setRange(int iMin, int iMax)
     199{
     200    m_pSlider->setRange(iMin, iMax);
     201}
     202
     203void QIAdvancedSlider::setMaximum(int iValue)
     204{
     205    m_pSlider->setMaximum(iValue);
    163206}
    164207
     
    168211}
    169212
    170 void QIAdvancedSlider::setMinimum(int val)
    171 {
    172     m_pSlider->setMinimum(val);
     213void QIAdvancedSlider::setMinimum(int iValue)
     214{
     215    m_pSlider->setMinimum(iValue);
    173216}
    174217
     
    178221}
    179222
    180 void QIAdvancedSlider::setPageStep(int val)
    181 {
    182     m_pSlider->setPageStep(val);
     223void QIAdvancedSlider::setPageStep(int iValue)
     224{
     225    m_pSlider->setPageStep(iValue);
    183226}
    184227
     
    188231}
    189232
    190 void QIAdvancedSlider::setSingleStep(int val)
    191 {
    192     m_pSlider->setSingleStep(val);
     233void QIAdvancedSlider::setSingleStep(int iValue)
     234{
     235    m_pSlider->setSingleStep(iValue);
    193236}
    194237
     
    198241}
    199242
    200 void QIAdvancedSlider::setTickInterval(int val)
    201 {
    202     m_pSlider->setTickInterval(val);
     243void QIAdvancedSlider::setTickInterval(int iValue)
     244{
     245    m_pSlider->setTickInterval(iValue);
    203246}
    204247
     
    223266}
    224267
    225 void QIAdvancedSlider::setOptimalHint(int min, int max)
    226 {
    227     m_pSlider->m_minOpt = min;
    228     m_pSlider->m_maxOpt = max;
     268void QIAdvancedSlider::setOptimalHint(int iMin, int iMax)
     269{
     270    m_pSlider->m_minOpt = iMin;
     271    m_pSlider->m_maxOpt = iMax;
    229272
    230273    update();
    231274}
    232275
    233 void QIAdvancedSlider::setWarningHint(int min, int max)
    234 {
    235     m_pSlider->m_minWrn = min;
    236     m_pSlider->m_maxWrn = max;
     276void QIAdvancedSlider::setWarningHint(int iMin, int iMax)
     277{
     278    m_pSlider->m_minWrn = iMin;
     279    m_pSlider->m_maxWrn = iMax;
    237280
    238281    update();
    239282}
    240283
    241 void QIAdvancedSlider::setErrorHint(int min, int max)
    242 {
    243     m_pSlider->m_minErr = min;
    244     m_pSlider->m_maxErr = max;
     284void QIAdvancedSlider::setErrorHint(int iMin, int iMax)
     285{
     286    m_pSlider->m_minErr = iMin;
     287    m_pSlider->m_maxErr = iMax;
    245288
    246289    update();
    247290}
    248291
    249 void QIAdvancedSlider::setOrientation(Qt::Orientation fOrientation)
    250 {
    251     m_pSlider->setOrientation(fOrientation);
    252 }
    253 
    254 void QIAdvancedSlider::setValue (int val)
    255 {
    256     m_pSlider->setValue(val);
    257 }
    258 
    259 void QIAdvancedSlider::sltSliderMoved(int val)
    260 {
    261     val = snapValue(val);
    262     m_pSlider->setValue(val);
    263     emit sliderMoved(val);
    264 }
    265 
    266 void QIAdvancedSlider::init(Qt::Orientation fOrientation /* = Qt::Horizontal */)
     292void QIAdvancedSlider::setOrientation(Qt::Orientation enmOrientation)
     293{
     294    m_pSlider->setOrientation(enmOrientation);
     295}
     296
     297void QIAdvancedSlider::setValue (int iValue)
     298{
     299    m_pSlider->setValue(iValue);
     300}
     301
     302void QIAdvancedSlider::sltSliderMoved(int iValue)
     303{
     304    iValue = snapValue(iValue);
     305    m_pSlider->setValue(iValue);
     306    emit sliderMoved(iValue);
     307}
     308
     309void QIAdvancedSlider::prepare(Qt::Orientation enmOrientation /* = Qt::Horizontal */)
    267310{
    268311    m_fSnappingEnabled = false;
    269312
     313    /* Create layout: */
    270314    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    271     pMainLayout->setContentsMargins(0, 0, 0, 0);
    272     m_pSlider = new CPrivateSlider(fOrientation, this);
    273     pMainLayout->addWidget(m_pSlider);
    274 
    275     connect(m_pSlider, &CPrivateSlider::sliderMoved,    this, &QIAdvancedSlider::sltSliderMoved);
    276     connect(m_pSlider, &CPrivateSlider::valueChanged,   this, &QIAdvancedSlider::valueChanged);
    277     connect(m_pSlider, &CPrivateSlider::sliderPressed,  this, &QIAdvancedSlider::sliderPressed);
    278     connect(m_pSlider, &CPrivateSlider::sliderReleased, this, &QIAdvancedSlider::sliderReleased);
    279 }
    280 
    281 int QIAdvancedSlider::snapValue(int val)
     315    if (pMainLayout)
     316    {
     317        /* Configure layout: */
     318        pMainLayout->setContentsMargins(0, 0, 0, 0);
     319
     320        /* Create private-slider: */
     321        m_pSlider = new UIPrivateSlider(enmOrientation, this);
     322        if (m_pSlider)
     323        {
     324            connect(m_pSlider, &UIPrivateSlider::sliderMoved,    this, &QIAdvancedSlider::sltSliderMoved);
     325            connect(m_pSlider, &UIPrivateSlider::valueChanged,   this, &QIAdvancedSlider::valueChanged);
     326            connect(m_pSlider, &UIPrivateSlider::sliderPressed,  this, &QIAdvancedSlider::sliderPressed);
     327            connect(m_pSlider, &UIPrivateSlider::sliderReleased, this, &QIAdvancedSlider::sliderReleased);
     328
     329            /* Add into layout: */
     330            pMainLayout->addWidget(m_pSlider);
     331        }
     332    }
     333}
     334
     335int QIAdvancedSlider::snapValue(int iValue)
    282336{
    283337    if (m_fSnappingEnabled &&
    284         val > 2)
    285     {
    286         float l2 = log((float)val)/log(2.0);
    287         int newVal = (int)pow((float)2, (int)qRound(l2)); /* The value to snap on */
    288         int pos = m_pSlider->positionForValue(val); /* Get the relative screen pos for the original value */
    289         int newPos = m_pSlider->positionForValue(newVal); /* Get the relative screen pos for the snap value */
    290         if (abs(newPos - pos) < 5) /* 10 pixel snapping range */
     338        iValue > 2)
     339    {
     340        float l2 = log((float)iValue)/log(2.0);
     341        int iNewVal = (int)pow((float)2, (int)qRound(l2)); /* The value to snap on */
     342        int iPos = m_pSlider->positionForValue(iValue); /* Get the relative screen pos for the original value */
     343        int iNewPos = m_pSlider->positionForValue(iNewVal); /* Get the relative screen pos for the snap value */
     344        if (abs(iNewPos - iPos) < 5) /* 10 pixel snapping range */
    291345        {
    292             val = newVal;
    293             if (val > m_pSlider->maximum())
    294                 val = m_pSlider->maximum();
    295             else if (val < m_pSlider->minimum())
    296                 val = m_pSlider->minimum();
     346            iValue = iNewVal;
     347            if (iValue > m_pSlider->maximum())
     348                iValue = m_pSlider->maximum();
     349            else if (iValue < m_pSlider->minimum())
     350                iValue = m_pSlider->minimum();
    297351        }
    298352    }
    299     return val;
    300 }
    301 
     353    return iValue;
     354}
     355
     356
     357#include "QIAdvancedSlider.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIAdvancedSlider.h

    r69500 r71863  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - Qt extensions: QIAdvancedSlider class implementation
     3 * VBox Qt GUI - Qt extensions: QIAdvancedSlider class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __QIAdvancedSlider_h__
    19 #define __QIAdvancedSlider_h__
     18#ifndef ___QIAdvancedSlider_h___
     19#define ___QIAdvancedSlider_h___
    2020
    21 /* Qt includes */
    22 #include <QSlider>
     21/* Qt includes: */
     22#include <QWidget>
    2323
    24 class CPrivateSlider;
     24/* GUI includes: */
     25#include "UILibraryDefs.h"
    2526
    26 class QIAdvancedSlider: public QWidget
     27/* Forward declarations: */
     28class UIPrivateSlider;
     29
     30/** QWidget extension providing GUI with advanced QSlider functionality. */
     31class SHARED_LIBRARY_STUFF QIAdvancedSlider : public QWidget
    2732{
    2833    Q_OBJECT;
    2934    Q_PROPERTY(int value READ value WRITE setValue);
    3035
     36signals:
     37
     38    /** Notifies about value changed to @a iValue. */
     39    void valueChanged(int iValue);
     40
     41    /** Notifies about slider moved to @a iValue. */
     42    void sliderMoved(int iValue);
     43
     44    /** Notifies about slider pressed. */
     45    void sliderPressed();
     46    /** Notifies about slider released. */
     47    void sliderReleased();
     48
    3149public:
     50
     51    /** Constructs advanced-slider passing @a pParent to the base-class. */
    3252    QIAdvancedSlider(QWidget *pParent = 0);
    33     QIAdvancedSlider(Qt::Orientation fOrientation, QWidget *pParent = 0);
     53    /** Constructs advanced-slider passing @a pParent to the base-class.
     54      * @param  enmOrientation  Brings the slider orientation. */
     55    QIAdvancedSlider(Qt::Orientation enmOrientation, QWidget *pParent = 0);
    3456
     57    /** Returns the slider value. */
    3558    int value() const;
    3659
    37     void setRange(int minV, int maxV);
     60    /** Defines the slider range to be from @a iMin to @a iMax. */
     61    void setRange(int iMin, int iMax);
    3862
    39     void setMaximum(int val);
     63    /** Defines the slider @a iMaximum. */
     64    void setMaximum(int iMaximum);
     65    /** Returns the slider maximum. */
    4066    int maximum() const;
    4167
    42     void setMinimum(int val);
     68    /** Defines the slider @a iMinimum. */
     69    void setMinimum(int iMinimum);
     70    /** Returns the slider minimum. */
    4371    int minimum() const;
    4472
    45     void setPageStep(int val);
     73    /** Defines the slider @a iPageStep. */
     74    void setPageStep(int iPageStep);
     75    /** Returns the slider page step. */
    4676    int pageStep() const;
    4777
     78    /** Defines the slider @a iSingleStep. */
    4879    void setSingleStep(int val);
     80    /** Returns the slider single step. */
    4981    int singelStep() const;
    5082
     83    /** Defines the slider @a iTickInterval. */
    5184    void setTickInterval(int val);
     85    /** Returns the slider tick interval. */
    5286    int tickInterval() const;
    5387
     88    /** Returns the slider orientation. */
    5489    Qt::Orientation orientation() const;
    5590
    56     void setSnappingEnabled(bool fOn);
     91    /** Defines whether snapping is @a fEnabled. */
     92    void setSnappingEnabled(bool fEnabled);
     93    /** Returns whether snapping is enabled. */
    5794    bool isSnappingEnabled() const;
    5895
    59     void setOptimalHint(int min, int max);
    60     void setWarningHint(int min, int max);
    61     void setErrorHint(int min, int max);
     96    /** Defines the optimal hint to be from @a iMin to @a iMax. */
     97    void setOptimalHint(int iMin, int iMax);
     98    /** Defines the warning hint to be from @a iMin to @a iMax. */
     99    void setWarningHint(int iMin, int iMax);
     100    /** Defines the error hint to be from @a iMin to @a iMax. */
     101    void setErrorHint(int iMin, int iMax);
    62102
    63103public slots:
    64104
    65     void setOrientation(Qt::Orientation fOrientation);
    66     void setValue(int val);
     105    /** Defines the slider @a enmOrientation. */
     106    void setOrientation(Qt::Orientation enmOrientation);
    67107
    68 signals:
    69     void valueChanged(int);
    70     void sliderMoved(int);
    71     void sliderPressed();
    72     void sliderReleased();
     108    /** Defines current slider @a iValue. */
     109    void setValue(int iValue);
    73110
    74111private slots:
    75112
    76     void sltSliderMoved(int val);
     113    /** Handles the slider move to @a iValue. */
     114    void sltSliderMoved(int iValue);
    77115
    78116private:
    79117
    80     void init(Qt::Orientation fOrientation = Qt::Horizontal);
    81     int snapValue(int val);
     118    /** Prepares all. */
     119    void prepare(Qt::Orientation fOrientation = Qt::Horizontal);
    82120
    83     /* Private member vars */
    84     CPrivateSlider *m_pSlider;
    85     bool m_fSnappingEnabled;
     121    /** Returns snapped value for passed @a iValue. */
     122    int snapValue(int iValue);
     123
     124    /** Holds the private QSlider instance. */
     125    UIPrivateSlider *m_pSlider;
     126    /** Holds the whether slider snapping is enabled. */
     127    bool             m_fSnappingEnabled;
    86128};
    87129
    88 #endif /* __QIAdvancedSlider__ */
    89 
     130#endif /* !___QIAdvancedSlider_h___ */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette