- Timestamp:
- Apr 16, 2018 1:56:29 PM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r71791 r71863 440 440 VirtualBox_QT_MOCHDRS = \ 441 441 src/UITakeSnapshotDialog.h \ 442 src/extensions/QIAdvancedSlider.h \443 442 src/extensions/QIComboBox.h \ 444 443 src/extensions/QIFlowLayout.h \ … … 651 650 src/VBoxAboutDlg.h \ 652 651 src/VBoxLicenseViewer.h \ 652 src/extensions/QIAdvancedSlider.h \ 653 653 src/extensions/QIArrowButtonPress.h \ 654 654 src/extensions/QIArrowButtonSwitch.h \ … … 723 723 src/VBoxAboutDlg.h \ 724 724 src/VBoxLicenseViewer.h \ 725 src/extensions/QIAdvancedSlider.h \ 725 726 src/extensions/QIArrowButtonPress.h \ 726 727 src/extensions/QIArrowButtonSwitch.h \ … … 826 827 ifndef VBOX_GUI_WITH_SHARED_LIBRARY 827 828 VirtualBox_QT_MOCSRCS += \ 829 src/extensions/QIAdvancedSlider.cpp \ 830 src/extensions/QIArrowSplitter.cpp \ 828 831 src/extensions/QISplitter.cpp \ 829 src/extensions/QIArrowSplitter.cpp \830 832 src/extradata/UIExtraDataManager.cpp \ 831 833 src/globals/UIActionPool.cpp \ … … 863 865 # 864 866 VBoxGlobal_QT_MOCSRCS = \ 867 src/extensions/QIAdvancedSlider.cpp \ 868 src/extensions/QIArrowSplitter.cpp \ 865 869 src/extensions/QISplitter.cpp \ 866 src/extensions/QIArrowSplitter.cpp \867 870 src/extradata/UIExtraDataManager.cpp \ 868 871 src/globals/UIActionPool.cpp \ … … 901 904 src/main.cpp \ 902 905 src/UITakeSnapshotDialog.cpp \ 903 src/extensions/QIAdvancedSlider.cpp \904 906 src/extensions/QIComboBox.cpp \ 905 907 src/extensions/QIFlowLayout.cpp \ … … 1145 1147 src/VBoxAboutDlg.cpp \ 1146 1148 src/VBoxLicenseViewer.cpp \ 1149 src/extensions/QIAdvancedSlider.cpp \ 1147 1150 src/extensions/QIArrowButtonPress.cpp \ 1148 1151 src/extensions/QIArrowButtonSwitch.cpp \ … … 1244 1247 src/VBoxAboutDlg.cpp \ 1245 1248 src/VBoxLicenseViewer.cpp \ 1249 src/extensions/QIAdvancedSlider.cpp \ 1246 1250 src/extensions/QIArrowButtonPress.cpp \ 1247 1251 src/extensions/QIArrowButtonSwitch.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIAdvancedSlider.cpp
r69500 r71863 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - VirtualBoxQt extensions: QIAdvancedSlider class implementation.3 * VBox Qt GUI - Qt extensions: QIAdvancedSlider class implementation. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Qt includes: */ 23 # include <QPainter> 24 # include <QSlider> 25 # include <QStyle> 26 # include <QVBoxLayout> 27 28 /* GUI includes: */ 22 29 # include "QIAdvancedSlider.h" 23 30 24 /* Qt includes */25 # include <QVBoxLayout>26 # include <QPainter>27 # include <QStyle>28 29 31 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 30 32 33 /* Qt includes: */ 31 34 #include <QStyleOptionSlider> 32 35 33 /* System includes*/36 /* External includes: */ 34 37 #include <math.h> 35 38 36 39 37 38 class CPrivateSlider : public QSlider 39 { 40 /** QSlider subclass for our private needs. */ 41 class UIPrivateSlider : public QSlider 42 { 43 Q_OBJECT; 44 40 45 public: 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 68 protected: 69 70 /** Handles paint @a pEvent. */ 71 virtual void paintEvent(QPaintEvent *pEvent); 72 73 private: 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 88 UIPrivateSlider::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 104 int 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 113 void 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: */ 79 126 #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()); 85 133 #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); 95 144 #endif /* VBOX_WS_MAC */ 96 145 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 *********************************************************************************************************************************/ 137 180 138 181 QIAdvancedSlider::QIAdvancedSlider(QWidget *pParent /* = 0 */) 139 182 : QWidget(pParent) 140 183 { 141 init();142 } 143 144 QIAdvancedSlider::QIAdvancedSlider(Qt::Orientation fOrientation, QWidget *pParent /* = 0 */)184 prepare(); 185 } 186 187 QIAdvancedSlider::QIAdvancedSlider(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */) 145 188 : QWidget(pParent) 146 189 { 147 init(fOrientation);190 prepare(enmOrientation); 148 191 } 149 192 … … 153 196 } 154 197 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);198 void QIAdvancedSlider::setRange(int iMin, int iMax) 199 { 200 m_pSlider->setRange(iMin, iMax); 201 } 202 203 void QIAdvancedSlider::setMaximum(int iValue) 204 { 205 m_pSlider->setMaximum(iValue); 163 206 } 164 207 … … 168 211 } 169 212 170 void QIAdvancedSlider::setMinimum(int val)171 { 172 m_pSlider->setMinimum( val);213 void QIAdvancedSlider::setMinimum(int iValue) 214 { 215 m_pSlider->setMinimum(iValue); 173 216 } 174 217 … … 178 221 } 179 222 180 void QIAdvancedSlider::setPageStep(int val)181 { 182 m_pSlider->setPageStep( val);223 void QIAdvancedSlider::setPageStep(int iValue) 224 { 225 m_pSlider->setPageStep(iValue); 183 226 } 184 227 … … 188 231 } 189 232 190 void QIAdvancedSlider::setSingleStep(int val)191 { 192 m_pSlider->setSingleStep( val);233 void QIAdvancedSlider::setSingleStep(int iValue) 234 { 235 m_pSlider->setSingleStep(iValue); 193 236 } 194 237 … … 198 241 } 199 242 200 void QIAdvancedSlider::setTickInterval(int val)201 { 202 m_pSlider->setTickInterval( val);243 void QIAdvancedSlider::setTickInterval(int iValue) 244 { 245 m_pSlider->setTickInterval(iValue); 203 246 } 204 247 … … 223 266 } 224 267 225 void QIAdvancedSlider::setOptimalHint(int min, int max)226 { 227 m_pSlider->m_minOpt = min;228 m_pSlider->m_maxOpt = max;268 void QIAdvancedSlider::setOptimalHint(int iMin, int iMax) 269 { 270 m_pSlider->m_minOpt = iMin; 271 m_pSlider->m_maxOpt = iMax; 229 272 230 273 update(); 231 274 } 232 275 233 void QIAdvancedSlider::setWarningHint(int min, int max)234 { 235 m_pSlider->m_minWrn = min;236 m_pSlider->m_maxWrn = max;276 void QIAdvancedSlider::setWarningHint(int iMin, int iMax) 277 { 278 m_pSlider->m_minWrn = iMin; 279 m_pSlider->m_maxWrn = iMax; 237 280 238 281 update(); 239 282 } 240 283 241 void QIAdvancedSlider::setErrorHint(int min, int max)242 { 243 m_pSlider->m_minErr = min;244 m_pSlider->m_maxErr = max;284 void QIAdvancedSlider::setErrorHint(int iMin, int iMax) 285 { 286 m_pSlider->m_minErr = iMin; 287 m_pSlider->m_maxErr = iMax; 245 288 246 289 update(); 247 290 } 248 291 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 */)292 void QIAdvancedSlider::setOrientation(Qt::Orientation enmOrientation) 293 { 294 m_pSlider->setOrientation(enmOrientation); 295 } 296 297 void QIAdvancedSlider::setValue (int iValue) 298 { 299 m_pSlider->setValue(iValue); 300 } 301 302 void QIAdvancedSlider::sltSliderMoved(int iValue) 303 { 304 iValue = snapValue(iValue); 305 m_pSlider->setValue(iValue); 306 emit sliderMoved(iValue); 307 } 308 309 void QIAdvancedSlider::prepare(Qt::Orientation enmOrientation /* = Qt::Horizontal */) 267 310 { 268 311 m_fSnappingEnabled = false; 269 312 313 /* Create layout: */ 270 314 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 335 int QIAdvancedSlider::snapValue(int iValue) 282 336 { 283 337 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 */ 291 345 { 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(); 297 351 } 298 352 } 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 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - Qt extensions: QIAdvancedSlider class implementation3 * VBox Qt GUI - Qt extensions: QIAdvancedSlider class declaration. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2009-201 7Oracle Corporation7 * Copyright (C) 2009-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ QIAdvancedSlider_h__19 #define __ QIAdvancedSlider_h__18 #ifndef ___QIAdvancedSlider_h___ 19 #define ___QIAdvancedSlider_h___ 20 20 21 /* Qt includes */22 #include <Q Slider>21 /* Qt includes: */ 22 #include <QWidget> 23 23 24 class CPrivateSlider; 24 /* GUI includes: */ 25 #include "UILibraryDefs.h" 25 26 26 class QIAdvancedSlider: public QWidget 27 /* Forward declarations: */ 28 class UIPrivateSlider; 29 30 /** QWidget extension providing GUI with advanced QSlider functionality. */ 31 class SHARED_LIBRARY_STUFF QIAdvancedSlider : public QWidget 27 32 { 28 33 Q_OBJECT; 29 34 Q_PROPERTY(int value READ value WRITE setValue); 30 35 36 signals: 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 31 49 public: 50 51 /** Constructs advanced-slider passing @a pParent to the base-class. */ 32 52 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); 34 56 57 /** Returns the slider value. */ 35 58 int value() const; 36 59 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); 38 62 39 void setMaximum(int val); 63 /** Defines the slider @a iMaximum. */ 64 void setMaximum(int iMaximum); 65 /** Returns the slider maximum. */ 40 66 int maximum() const; 41 67 42 void setMinimum(int val); 68 /** Defines the slider @a iMinimum. */ 69 void setMinimum(int iMinimum); 70 /** Returns the slider minimum. */ 43 71 int minimum() const; 44 72 45 void setPageStep(int val); 73 /** Defines the slider @a iPageStep. */ 74 void setPageStep(int iPageStep); 75 /** Returns the slider page step. */ 46 76 int pageStep() const; 47 77 78 /** Defines the slider @a iSingleStep. */ 48 79 void setSingleStep(int val); 80 /** Returns the slider single step. */ 49 81 int singelStep() const; 50 82 83 /** Defines the slider @a iTickInterval. */ 51 84 void setTickInterval(int val); 85 /** Returns the slider tick interval. */ 52 86 int tickInterval() const; 53 87 88 /** Returns the slider orientation. */ 54 89 Qt::Orientation orientation() const; 55 90 56 void setSnappingEnabled(bool fOn); 91 /** Defines whether snapping is @a fEnabled. */ 92 void setSnappingEnabled(bool fEnabled); 93 /** Returns whether snapping is enabled. */ 57 94 bool isSnappingEnabled() const; 58 95 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); 62 102 63 103 public slots: 64 104 65 void setOrientation(Qt::Orientation fOrientation);66 void set Value(int val);105 /** Defines the slider @a enmOrientation. */ 106 void setOrientation(Qt::Orientation enmOrientation); 67 107 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); 73 110 74 111 private slots: 75 112 76 void sltSliderMoved(int val); 113 /** Handles the slider move to @a iValue. */ 114 void sltSliderMoved(int iValue); 77 115 78 116 private: 79 117 80 void init(Qt::Orientation fOrientation = Qt::Horizontal);81 int snapValue(int val);118 /** Prepares all. */ 119 void prepare(Qt::Orientation fOrientation = Qt::Horizontal); 82 120 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; 86 128 }; 87 129 88 #endif /* __QIAdvancedSlider__ */ 89 130 #endif /* !___QIAdvancedSlider_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.