From 2a11286469bf28b348821f015d72f8cb06f54b95 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 26 Aug 2013 16:03:22 +0200 Subject: Refactor QWinTaskbarProgress out of QWinTaskbarButton Change-Id: I8b95d7804d9070c8e93993ad6acf5c22d964880d Reviewed-by: Ivan Vizir Reviewed-by: Friedemann Kleint --- src/imports/winextras/qquickwintaskbarbutton.cpp | 20 +- src/imports/winextras/qquickwintaskbarbutton.h | 7 +- src/winextras/qwintaskbarbutton.cpp | 379 ++++++++--------------- src/winextras/qwintaskbarbutton.h | 40 +-- src/winextras/qwintaskbarbutton_p.h | 21 +- src/winextras/qwintaskbarprogress.cpp | 226 ++++++++++++++ src/winextras/qwintaskbarprogress.h | 101 ++++++ src/winextras/winextras.pro | 2 + 8 files changed, 488 insertions(+), 308 deletions(-) create mode 100644 src/winextras/qwintaskbarprogress.cpp create mode 100644 src/winextras/qwintaskbarprogress.h (limited to 'src') diff --git a/src/imports/winextras/qquickwintaskbarbutton.cpp b/src/imports/winextras/qquickwintaskbarbutton.cpp index c1c16af..8a34f44 100644 --- a/src/imports/winextras/qquickwintaskbarbutton.cpp +++ b/src/imports/winextras/qquickwintaskbarbutton.cpp @@ -77,12 +77,12 @@ QQuickWinTaskbarButton::~QQuickWinTaskbarButton() int QQuickWinTaskbarButton::progressMinimum() const { - return button->progressMinimum(); + return button->progressBar()->minimum(); } void QQuickWinTaskbarButton::setProgressMinimum(int min) { - button->setProgressMinimum(min); + button->progressBar()->setMinimum(min); } /*! @@ -92,12 +92,12 @@ void QQuickWinTaskbarButton::setProgressMinimum(int min) */ int QQuickWinTaskbarButton::progressMaximum() const { - return button->progressMaximum(); + return button->progressBar()->maximum(); } void QQuickWinTaskbarButton::setProgressMaximum(int max) { - button->setProgressMaximum(max); + button->progressBar()->setMaximum(max); } /*! @@ -107,12 +107,12 @@ void QQuickWinTaskbarButton::setProgressMaximum(int max) */ int QQuickWinTaskbarButton::progressValue() const { - return button->progressValue(); + return button->progressBar()->value(); } void QQuickWinTaskbarButton::setProgressValue(int progress) { - button->setProgressValue(progress); + button->progressBar()->setValue(progress); } /*! @@ -169,14 +169,14 @@ void QQuickWinTaskbarButton::setIconDescription(const QString &descr) \li The progress indicator turns red. \endtable */ -QWinTaskbarButton::ProgressState QQuickWinTaskbarButton::progressState() const +QWinTaskbarProgress::ProgressState QQuickWinTaskbarButton::progressState() const { - return button->progressState(); + return button->progressBar()->state(); } -void QQuickWinTaskbarButton::setProgressState(QWinTaskbarButton::ProgressState state) +void QQuickWinTaskbarButton::setProgressState(QWinTaskbarProgress::ProgressState state) { - button->setProgressState(state); + button->progressBar()->setState(state); } void QQuickWinTaskbarButton::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) diff --git a/src/imports/winextras/qquickwintaskbarbutton.h b/src/imports/winextras/qquickwintaskbarbutton.h index 65185c8..c575077 100644 --- a/src/imports/winextras/qquickwintaskbarbutton.h +++ b/src/imports/winextras/qquickwintaskbarbutton.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -57,7 +58,7 @@ class QQuickWinTaskbarButton : public QQuickItem Q_PROPERTY(int progressValue READ progressValue WRITE setProgressValue) Q_PROPERTY(QString overlayIcon READ overlayIcon WRITE setOverlayIcon) Q_PROPERTY(QString iconDescription READ iconDescription WRITE setIconDescription) - Q_PROPERTY(QWinTaskbarButton::ProgressState progressState READ progressState WRITE setProgressState) + Q_PROPERTY(QWinTaskbarProgress::ProgressState progressState READ progressState WRITE setProgressState) public: Q_ENUMS(QWinTaskbarButton::ProgressState) @@ -75,8 +76,8 @@ public: QString iconDescription() const; void setIconDescription(const QString &descr); - QWinTaskbarButton::ProgressState progressState() const; - void setProgressState(QWinTaskbarButton::ProgressState state); + QWinTaskbarProgress::ProgressState progressState() const; + void setProgressState(QWinTaskbarProgress::ProgressState state); protected: void itemChange(ItemChange, const ItemChangeData &) Q_DECL_OVERRIDE; diff --git a/src/winextras/qwintaskbarbutton.cpp b/src/winextras/qwintaskbarbutton.cpp index a9d4804..9d2a46e 100644 --- a/src/winextras/qwintaskbarbutton.cpp +++ b/src/winextras/qwintaskbarbutton.cpp @@ -41,9 +41,11 @@ #include "qwintaskbarbutton.h" #include "qwintaskbarbutton_p.h" +#include "qwintaskbarprogress.h" #include "qwinfunctions.h" #include "qwineventfilter_p.h" #include "qwinevent.h" +#include "winshobjidl_p.h" #include #include @@ -66,23 +68,100 @@ QT_BEGIN_NAMESPACE window thumbnail popup. */ -/*! - \enum QWinTaskbarButton::ProgressState - - This enum type specifies the state of the progress indicator. - - \value NoProgressState - No progress indicator is displayed. - \value IndeterminateState - The progress indicator cycles repeatedly. - \value NormalState - The progress indicator is green. - \value PausedState - The progress indicator turns yellow. Use this state to show that the - operation has been paused, but it can be continued. - \value ErrorState - The progress indicator turns red. - */ +static TBPFLAG nativeProgressState(QWinTaskbarProgress::ProgressState state) +{ + TBPFLAG flag; + switch (state) { + default : + case QWinTaskbarProgress::NoProgressState: flag = TBPF_NOPROGRESS; break; + case QWinTaskbarProgress::IndeterminateState: flag = TBPF_INDETERMINATE; break; + case QWinTaskbarProgress::NormalState: flag = TBPF_NORMAL; break; + case QWinTaskbarProgress::PausedState: flag = TBPF_PAUSED; break; + case QWinTaskbarProgress::ErrorState: flag = TBPF_ERROR; break; + } + return flag; +} + +QWinTaskbarButtonPrivate::QWinTaskbarButtonPrivate() : progressBar(0), pTbList(0), window(0) +{ + HRESULT hresult = CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, reinterpret_cast(&pTbList)); + if (FAILED(hresult)) { + pTbList = 0; + const QString err = QWinExtras::errorStringFromHresult(hresult); + qWarning("QWinTaskbarButton: IID_ITaskbarList4 was not created: %#010x, %s.", (unsigned)hresult, qPrintable(err)); + } else if (FAILED(pTbList->HrInit())) { + pTbList->Release(); + pTbList = 0; + const QString err = QWinExtras::errorStringFromHresult(hresult); + qWarning("QWinTaskbarButton: IID_ITaskbarList4 was not initialized: %#010x, %s.", (unsigned)hresult, qPrintable(err)); + } +} + +QWinTaskbarButtonPrivate::~QWinTaskbarButtonPrivate() +{ + pTbList->Release(); +} + +HWND QWinTaskbarButtonPrivate::handle() +{ + return reinterpret_cast(window->winId()); +} + +int QWinTaskbarButtonPrivate::iconSize() const +{ + return GetSystemMetrics(SM_CXSMICON); +} + +void QWinTaskbarButtonPrivate::updateOverlayIcon() +{ + if (!pTbList || !window) + return; + + wchar_t *descrPtr = 0; + HICON hicon = 0; + if (!overlayIconDescription.isEmpty()) { + descrPtr = new wchar_t[overlayIconDescription.length() + 1]; + descrPtr[overlayIconDescription.toWCharArray(descrPtr)] = 0; + } + if (!overlayIcon.isNull()) + hicon = QWinExtras::toHICON(overlayIcon.pixmap(iconSize())); + + if (hicon) + pTbList->SetOverlayIcon(handle(), hicon, descrPtr); + else if (!hicon && !overlayIcon.isNull()) + pTbList->SetOverlayIcon(handle(), (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, SM_CXSMICON, SM_CYSMICON, LR_SHARED), descrPtr); + + if (hicon) + DeleteObject(hicon); + if (descrPtr) + delete[] descrPtr; +} + +void QWinTaskbarButtonPrivate::_q_updateProgressValue() +{ + const QWinTaskbarProgress::ProgressState state = progressBar ? progressBar->state() : QWinTaskbarProgress::NoProgressState; + if (!pTbList || !window || state == QWinTaskbarProgress::NoProgressState || state == QWinTaskbarProgress::IndeterminateState) + return; + + const int min = progressBar->minimum(); + const int max = progressBar->maximum(); + const int range = max - min; + if (range > 0) { + const int value = 100.0 * (progressBar->value() - min) / range; + pTbList->SetProgressValue(handle(), value, 100); + + if (state == QWinTaskbarProgress::IndeterminateState) + progressBar->setState(QWinTaskbarProgress::NormalState); + } +} + +void QWinTaskbarButtonPrivate::_q_updateProgressState() +{ + if (!pTbList || !window || !progressBar) + return; + + pTbList->SetProgressState(handle(), nativeProgressState(progressBar->state())); +} /*! Constructs a QWinTaskbarButton with the parent object \a parent. @@ -90,8 +169,6 @@ QT_BEGIN_NAMESPACE QWinTaskbarButton::QWinTaskbarButton(QObject *parent) : QObject(parent), d_ptr(new QWinTaskbarButtonPrivate) { - Q_D(QWinTaskbarButton); - d->q_ptr = this; QWinEventFilter::setup(); } @@ -115,7 +192,8 @@ void QWinTaskbarButton::setWindow(QWindow *window) if (d->window) { d->window->installEventFilter(this); if (d->window->isVisible()) { - d->updateProgressValue(); + d->_q_updateProgressValue(); + d->_q_updateProgressState(); d->updateOverlayIcon(); } } @@ -137,71 +215,6 @@ QIcon QWinTaskbarButton::overlayIcon() const return d->overlayIcon; } -/*! - \property QWinTaskbarButton::overlayIconAccessibilityDescription - \brief the overlay icon accessibility description text - */ -QString QWinTaskbarButton::overlayIconAccessibilityDescription() const -{ - Q_D(const QWinTaskbarButton); - return d->overlayIconDescription; -} - -/*! - \property QWinTaskbarButton::progressState - \brief the progress state of the progress indicator - */ -QWinTaskbarButton::ProgressState QWinTaskbarButton::progressState() const -{ - Q_D(const QWinTaskbarButton); - return d->progressState; -} - -/*! - \property QWinTaskbarButton::progressValue - \brief the current progress value of the progress indicator - */ -int QWinTaskbarButton::progressValue() const -{ - Q_D(const QWinTaskbarButton); - return d->progressValue; -} - -/*! - \property QWinTaskbarButton::progressMinimum - \brief the minimum value of the progress indicator - */ -int QWinTaskbarButton::progressMinimum() const -{ - Q_D(const QWinTaskbarButton); - return d->progressMinimum; -} - -/*! - \property QWinTaskbarButton::progressMaximum - \brief the maximum value of the progress indicator - */ -int QWinTaskbarButton::progressMaximum() const -{ - Q_D(const QWinTaskbarButton); - return d->progressMaximum; -} - -/*! - \internal - Intercepts TaskbarButtonCreated messages. - */ -bool QWinTaskbarButton::eventFilter(QObject *object, QEvent *event) -{ - Q_D(QWinTaskbarButton); - if (object == d->window && event->type() == QWinEvent::TaskbarButtonCreated) { - d->pTbList->SetProgressState(d->handle(), QWinTaskbarButtonPrivate::nativeProgressState(d->progressState)); - d->updateProgressValue(); - d->updateOverlayIcon(); - } - return false; -} - void QWinTaskbarButton::setOverlayIcon(const QIcon &icon) { Q_D(QWinTaskbarButton); @@ -210,14 +223,6 @@ void QWinTaskbarButton::setOverlayIcon(const QIcon &icon) d->updateOverlayIcon(); } -void QWinTaskbarButton::setOverlayIconAccessibilityDescription(const QString &description) -{ - Q_D(QWinTaskbarButton); - - d->overlayIconDescription = description; - d->updateOverlayIcon(); -} - /*! Clears the previously set overlay icon. \sa QWinTaskbarButton::setOverlayIcon() @@ -228,182 +233,58 @@ void QWinTaskbarButton::clearOverlayIcon() setOverlayIcon(QIcon()); } -void QWinTaskbarButton::setProgressState(const QWinTaskbarButton::ProgressState state) -{ - Q_D(QWinTaskbarButton); - - if (state == d->progressState) - return; - - d->progressState = state; - emit progressStateChanged(d->progressState); - - if (!d->pTbList || !d->window) - return; - - d->pTbList->SetProgressState(d->handle(), QWinTaskbarButtonPrivate::nativeProgressState(state)); - d->updateProgressValue(); -} - -void QWinTaskbarButton::setProgressValue(int value) +/*! + \property QWinTaskbarButton::overlayIconAccessibilityDescription + \brief the overlay icon accessibility description text + */ +QString QWinTaskbarButton::overlayIconAccessibilityDescription() const { - Q_D(QWinTaskbarButton); - - if ((value == d->progressValue && !d->updateNeeded) || value < d->progressMinimum || value > d->progressMaximum) - return; - - d->updateNeeded = false; - - d->progressValue = value; - emit progressValueChanged(d->progressValue); - d->updateProgressValue(); + Q_D(const QWinTaskbarButton); + return d->overlayIconDescription; } -void QWinTaskbarButton::setProgressMinimum(int min) +void QWinTaskbarButton::setOverlayIconAccessibilityDescription(const QString &description) { Q_D(QWinTaskbarButton); - setProgressRange(min, qMax(min, d->progressMaximum)); -} -void QWinTaskbarButton::setProgressMaximum(int max) -{ - Q_D(QWinTaskbarButton); - setProgressRange(qMin(d->progressMinimum, max), max); + d->overlayIconDescription = description; + d->updateOverlayIcon(); } /*! - Sets both the \a minimum and \a maximum values. + \property QWinTaskbarButton::progressBar + \brief the progress indicator of the taskbar button */ -void QWinTaskbarButton::setProgressRange(int minimum, int maximum) +QWinTaskbarProgress *QWinTaskbarButton::progressBar() const { - Q_D(QWinTaskbarButton); - if (minimum != d->progressMinimum || maximum != d->progressMaximum) { - d->progressMinimum = minimum; - d->progressMaximum = qMax(minimum, maximum); - - if (d->progressValue < d->progressMinimum || d->progressValue > d->progressMaximum) - resetProgress(); - else - d->updateProgressValue(); + Q_D(const QWinTaskbarButton); + if (!d->progressBar) { + QWinTaskbarButton *that = const_cast(this); + QWinTaskbarProgress *pbar = new QWinTaskbarProgress(that); + connect(pbar, SIGNAL(valueChanged(int)), this, SLOT(_q_updateProgressValue())); + connect(pbar, SIGNAL(stateChanged(QWinTaskbarProgress::ProgressState)), this, SLOT(_q_updateProgressState())); + that->d_func()->progressBar = pbar; + that->d_func()->_q_updateProgressValue(); + that->d_func()->_q_updateProgressState(); } + return d->progressBar; } /*! - Resets the progress indicator of this button. - - This function sets the progress state to \c NoProgressState and rewinds the - progress value to the minimum value. + \internal + Intercepts TaskbarButtonCreated messages. */ -void QWinTaskbarButton::resetProgress() -{ - setProgressValue(progressMinimum()); - setProgressState(NoProgressState); -} - - - -QWinTaskbarButtonPrivate::QWinTaskbarButtonPrivate() : - progressMinimum(0), progressMaximum(100), progressValue(0), progressState(QWinTaskbarButton::NoProgressState), - updateNeeded(false), pTbList(0), window(0), q_ptr(0) -{ - HRESULT hresult = CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, reinterpret_cast(&pTbList)); - if (FAILED(hresult)) { - pTbList = 0; - const QString err = QWinExtras::errorStringFromHresult(hresult); - qWarning("QWinTaskbarButton: IID_ITaskbarList4 was not created: %#010x, %s.", (unsigned)hresult, qPrintable(err)); - } else if (FAILED(pTbList->HrInit())) { - pTbList->Release(); - pTbList = 0; - const QString err = QWinExtras::errorStringFromHresult(hresult); - qWarning("QWinTaskbarButton: IID_ITaskbarList4 was not initialized: %#010x, %s.", (unsigned)hresult, qPrintable(err)); - } -} - -QWinTaskbarButtonPrivate::~QWinTaskbarButtonPrivate() -{ - pTbList->Release(); -} - -HWND QWinTaskbarButtonPrivate::handle() -{ - return reinterpret_cast(window->winId()); -} - -int QWinTaskbarButtonPrivate::iconSize() const -{ - return GetSystemMetrics(SM_CXSMICON); -} - -TBPFLAG QWinTaskbarButtonPrivate::nativeProgressState(QWinTaskbarButton::ProgressState state) -{ - TBPFLAG flag; - switch (state) { - default : - case QWinTaskbarButton::NoProgressState : flag = TBPF_NOPROGRESS; break; - case QWinTaskbarButton::IndeterminateState : flag = TBPF_INDETERMINATE; break; - case QWinTaskbarButton::NormalState : flag = TBPF_NORMAL; break; - case QWinTaskbarButton::PausedState : flag = TBPF_PAUSED; break; - case QWinTaskbarButton::ErrorState : flag = TBPF_ERROR; break; - } - return flag; -} - -void QWinTaskbarButtonPrivate::updateOverlayIcon() -{ - if (!pTbList || !window) - return; - - wchar_t *descrPtr = 0; - HICON hicon = 0; - if (!overlayIconDescription.isEmpty()) { - descrPtr = new wchar_t[overlayIconDescription.length() + 1]; - descrPtr[overlayIconDescription.toWCharArray(descrPtr)] = 0; - } - if (!overlayIcon.isNull()) - hicon = QWinExtras::toHICON(overlayIcon.pixmap(iconSize())); - - if (hicon) - pTbList->SetOverlayIcon(handle(), hicon, descrPtr); - else if (!hicon && !overlayIcon.isNull()) - pTbList->SetOverlayIcon(handle(), (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, SM_CXSMICON, SM_CYSMICON, LR_SHARED), descrPtr); - - if (hicon) - DeleteObject(hicon); - if (descrPtr) - delete[] descrPtr; -} - -void QWinTaskbarButtonPrivate::updateProgressValue() +bool QWinTaskbarButton::eventFilter(QObject *object, QEvent *event) { - if (!pTbList || !window || progressState == QWinTaskbarButton::NoProgressState || progressState == QWinTaskbarButton::IndeterminateState) - return; - - Q_Q(QWinTaskbarButton); - - const int range = progressMaximum - progressMinimum; - if (range > 0) { - int value = 100.0 * (progressValue - progressMinimum)/(progressMaximum - progressMinimum); - pTbList->SetProgressValue(handle(), value, 100); - if (progressState == QWinTaskbarButton::IndeterminateState) { - progressState = QWinTaskbarButton::NormalState; - emit q->progressStateChanged(progressState); - } + Q_D(QWinTaskbarButton); + if (object == d->window && event->type() == QWinEvent::TaskbarButtonCreated) { + d->_q_updateProgressState(); + d->_q_updateProgressValue(); + d->updateOverlayIcon(); } + return false; } -/*! - \fn void QWinTaskbarButton::progressStateChanged(const ProgressState state) - - This signal is emitted when the \c progressState property changes its value. - The \a state argument contains the new value. - */ - -/*! - \fn void QWinTaskbarButton::progressValueChanged(int value) - - This signal is emitted when the progress indicator \a value changes. - */ - QT_END_NAMESPACE #include "moc_qwintaskbarbutton.cpp" diff --git a/src/winextras/qwintaskbarbutton.h b/src/winextras/qwintaskbarbutton.h index 08c3085..c8b50ec 100644 --- a/src/winextras/qwintaskbarbutton.h +++ b/src/winextras/qwintaskbarbutton.h @@ -42,12 +42,14 @@ #ifndef QWINTASKBARBUTTON_H #define QWINTASKBARBUTTON_H +#include #include #include QT_BEGIN_NAMESPACE class QWindow; +class QWinTaskbarProgress; class QWinTaskbarButtonPrivate; class Q_WINEXTRAS_EXPORT QWinTaskbarButton : public QObject @@ -55,23 +57,10 @@ class Q_WINEXTRAS_EXPORT QWinTaskbarButton : public QObject Q_OBJECT Q_PROPERTY(QIcon overlayIcon READ overlayIcon WRITE setOverlayIcon) Q_PROPERTY(QString overlayIconAccessibilityDescription READ overlayIconAccessibilityDescription WRITE setOverlayIconAccessibilityDescription) - Q_PROPERTY(int progressValue READ progressValue WRITE setProgressValue) - Q_PROPERTY(int progressMaximum READ progressMaximum WRITE setProgressMaximum) - Q_PROPERTY(int progressMinimum READ progressMinimum WRITE setProgressMinimum) - Q_PROPERTY(ProgressState progressState READ progressState WRITE setProgressState) + Q_PROPERTY(QWinTaskbarProgress *progressBar READ progressBar) Q_PROPERTY(QWindow *window READ window WRITE setWindow) public: - enum ProgressState { - NoProgressState, - IndeterminateState, - NormalState, - PausedState, - ErrorState - }; - - Q_ENUMS(ProgressState) - explicit QWinTaskbarButton(QObject *parent = 0); ~QWinTaskbarButton(); @@ -81,10 +70,7 @@ public: QIcon overlayIcon() const; QString overlayIconAccessibilityDescription() const; - ProgressState progressState() const; - int progressValue() const; - int progressMinimum() const; - int progressMaximum() const; + QWinTaskbarProgress *progressBar() const; bool eventFilter(QObject *, QEvent *); @@ -94,23 +80,13 @@ public Q_SLOTS: void clearOverlayIcon(); - void setProgressState(ProgressState state); - void setProgressValue(int progress); - void setProgressMinimum(int min); - void setProgressMaximum(int max); - void setProgressRange(int mininum, int progressMaximum); - void resetProgress(); - -Q_SIGNALS: - void progressStateChanged(const ProgressState state); - void progressValueChanged(int value); - private: + Q_DISABLE_COPY(QWinTaskbarButton) + Q_DECLARE_PRIVATE(QWinTaskbarButton) QScopedPointer d_ptr; - friend class QQuickWinTaskbarButton; - - Q_DECLARE_PRIVATE(QWinTaskbarButton) + Q_PRIVATE_SLOT(d_func(), void _q_updateProgressValue()) + Q_PRIVATE_SLOT(d_func(), void _q_updateProgressState()) }; QT_END_NAMESPACE diff --git a/src/winextras/qwintaskbarbutton_p.h b/src/winextras/qwintaskbarbutton_p.h index 51dc657..dbb88ea 100644 --- a/src/winextras/qwintaskbarbutton_p.h +++ b/src/winextras/qwintaskbarbutton_p.h @@ -43,44 +43,37 @@ #define QWINTASKBARBUTTON_P_H #include "qwintaskbarbutton.h" -#include "winshobjidl_p.h" #include -#include +#include #include struct ITaskbarList4; QT_BEGIN_NAMESPACE +class QWinTaskbarProgress; + class QWinTaskbarButtonPrivate { public: QWinTaskbarButtonPrivate(); ~QWinTaskbarButtonPrivate(); - int progressMinimum; - int progressMaximum; - int progressValue; + QPointer progressBar; QIcon overlayIcon; QString overlayIconDescription; - QWinTaskbarButton::ProgressState progressState; - bool updateNeeded; HWND handle(); int iconSize() const; - static TBPFLAG nativeProgressState(QWinTaskbarButton::ProgressState); void updateOverlayIcon(); - void updateProgressValue(); + + void _q_updateProgressValue(); + void _q_updateProgressState(); ITaskbarList4 *pTbList; QWindow *window; - -private: - QWinTaskbarButton *q_ptr; - - Q_DECLARE_PUBLIC(QWinTaskbarButton) }; QT_END_NAMESPACE diff --git a/src/winextras/qwintaskbarprogress.cpp b/src/winextras/qwintaskbarprogress.cpp new file mode 100644 index 0000000..607798e --- /dev/null +++ b/src/winextras/qwintaskbarprogress.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** + ** + ** Copyright (C) 2013 Ivan Vizir + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of the QtWinExtras module of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and Digia. For licensing terms and + ** conditions see http://qt.digia.com/licensing. For further information + ** use the contact form at http://qt.digia.com/contact-us. + ** + ** GNU Lesser General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU Lesser + ** General Public License version 2.1 as published by the Free Software + ** Foundation and appearing in the file LICENSE.LGPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU Lesser General Public License version 2.1 requirements + ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + ** + ** In addition, as a special exception, Digia gives you certain additional + ** rights. These rights are described in the Digia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3.0 as published by the Free Software + ** Foundation and appearing in the file LICENSE.GPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU General Public License version 3.0 requirements will be + ** met: http://www.gnu.org/copyleft/gpl.html. + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include "qwintaskbarprogress.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWinTaskbarProgress + \inmodule QtWinExtras + \brief The QWinTaskbarProgress class represents the Windows taskbar progress indicator. + + \since 5.2 + + The QWinTaskbarProgress class enables you to to display a progress indicator + on a taskbar button. + */ + +/*! + \fn void QWinTaskbarProgress::stateChanged(ProgressState state) + + This signal is emitted when the \c state property changes its value. + The \a state argument contains the new value. + */ + +/*! + \fn void QWinTaskbarProgress::valueChanged(int value) + + This signal is emitted when the progress indicator \a value changes. + */ + +/*! + \enum QWinTaskbarProgress::ProgressState + + This enum type specifies the state of the progress indicator. + + \value NoProgressState + No progress indicator is displayed. + \value IndeterminateState + The progress indicator cycles repeatedly. + \value NormalState + The progress indicator is green. + \value PausedState + The progress indicator turns yellow. Use this state to show that the + operation has been paused, but it can be continued. + \value ErrorState + The progress indicator turns red. + */ + +class QWinTaskbarProgressPrivate +{ +public: + QWinTaskbarProgressPrivate(); + + int value; + int minimum; + int maximum; + QWinTaskbarProgress::ProgressState state; +}; + +QWinTaskbarProgressPrivate::QWinTaskbarProgressPrivate() : + value(0), minimum(0), maximum(100), state(QWinTaskbarProgress::NoProgressState) +{ +} + +/*! + Constructs a QWinTaskbarProgress with the parent object \a parent. + */ +QWinTaskbarProgress::QWinTaskbarProgress(QObject *parent) : + QObject(parent), d_ptr(new QWinTaskbarProgressPrivate) +{ +} + +/*! + Destroys the QWinTaskbarProgress. + */ +QWinTaskbarProgress::~QWinTaskbarProgress() +{ +} + +/*! + \property QWinTaskbarProgress::state + \brief the state of the progress indicator + + The default value is \c NoProgressState. + */ +QWinTaskbarProgress::ProgressState QWinTaskbarProgress::state() const +{ + Q_D(const QWinTaskbarProgress); + return d->state; +} + +void QWinTaskbarProgress::setState(QWinTaskbarProgress::ProgressState state) +{ + Q_D(QWinTaskbarProgress); + if (state == d->state) + return; + + d->state = state; + emit stateChanged(d->state); +} + +/*! + \property QWinTaskbarProgress::value + \brief the current value of the progress indicator + + The default value is \c 0. + */ +int QWinTaskbarProgress::value() const +{ + Q_D(const QWinTaskbarProgress); + return d->value; +} + +void QWinTaskbarProgress::setValue(int value) +{ + Q_D(QWinTaskbarProgress); + if ((value == d->value) || value < d->minimum || value > d->maximum) + return; + + d->value = value; + emit valueChanged(d->value); +} + +/*! + \property QWinTaskbarProgress::minimum + \brief the minimum value of the progress indicator + + The default value is \c 0. + */ +int QWinTaskbarProgress::minimum() const +{ + Q_D(const QWinTaskbarProgress); + return d->minimum; +} + +void QWinTaskbarProgress::setMinimum(int minimum) +{ + Q_D(QWinTaskbarProgress); + setRange(minimum, qMax(minimum, d->maximum)); +} + +/*! + \property QWinTaskbarProgress::maximum + \brief the maximum value of the progress indicator + + The default value is \c 100. + */ +int QWinTaskbarProgress::maximum() const +{ + Q_D(const QWinTaskbarProgress); + return d->maximum; +} + +void QWinTaskbarProgress::setMaximum(int maximum) +{ + Q_D(QWinTaskbarProgress); + setRange(qMin(d->minimum, maximum), maximum); +} + +/*! + Sets both the \a minimum and \a maximum values. + */ +void QWinTaskbarProgress::setRange(int minimum, int maximum) +{ + Q_D(QWinTaskbarProgress); + if (minimum != d->minimum || maximum != d->maximum) { + d->minimum = minimum; + d->maximum = qMax(minimum, maximum); + + if (d->value < d->minimum || d->value > d->maximum) + reset(); + } +} + +/*! + Resets the progress indicator. + + This function sets the state to \c NoProgressState and rewinds the + value to the minimum value. + */ +void QWinTaskbarProgress::reset() +{ + setValue(minimum()); + setState(NoProgressState); +} + +QT_END_NAMESPACE diff --git a/src/winextras/qwintaskbarprogress.h b/src/winextras/qwintaskbarprogress.h new file mode 100644 index 0000000..dec0401 --- /dev/null +++ b/src/winextras/qwintaskbarprogress.h @@ -0,0 +1,101 @@ +/**************************************************************************** + ** + ** Copyright (C) 2013 Ivan Vizir + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of the QtWinExtras module of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** Commercial License Usage + ** Licensees holding valid commercial Qt licenses may use this file in + ** accordance with the commercial license agreement provided with the + ** Software or, alternatively, in accordance with the terms contained in + ** a written agreement between you and Digia. For licensing terms and + ** conditions see http://qt.digia.com/licensing. For further information + ** use the contact form at http://qt.digia.com/contact-us. + ** + ** GNU Lesser General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU Lesser + ** General Public License version 2.1 as published by the Free Software + ** Foundation and appearing in the file LICENSE.LGPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU Lesser General Public License version 2.1 requirements + ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. + ** + ** In addition, as a special exception, Digia gives you certain additional + ** rights. These rights are described in the Digia Qt LGPL Exception + ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. + ** + ** GNU General Public License Usage + ** Alternatively, this file may be used under the terms of the GNU + ** General Public License version 3.0 as published by the Free Software + ** Foundation and appearing in the file LICENSE.GPL included in the + ** packaging of this file. Please review the following information to + ** ensure the GNU General Public License version 3.0 requirements will be + ** met: http://www.gnu.org/copyleft/gpl.html. + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#ifndef QWINTASKBARPROGRESS_H +#define QWINTASKBARPROGRESS_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QWinTaskbarProgressPrivate; + +class Q_WINEXTRAS_EXPORT QWinTaskbarProgress : public QObject +{ + Q_OBJECT + Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged) + Q_PROPERTY(int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged) + Q_PROPERTY(ProgressState state READ state WRITE setState NOTIFY stateChanged) + Q_ENUMS(ProgressState) + +public: + enum ProgressState { + NoProgressState, + IndeterminateState, + NormalState, + PausedState, + ErrorState + }; + + explicit QWinTaskbarProgress(QObject *parent = 0); + ~QWinTaskbarProgress(); + + ProgressState state() const; + int value() const; + int minimum() const; + int maximum() const; + +public Q_SLOTS: + void setState(ProgressState state); + void setValue(int value); + void setMinimum(int minimum); + void setMaximum(int minimum); + void setRange(int minimum, int maximum); + void reset(); + +Q_SIGNALS: + void valueChanged(int value); + void minimumChanged(int minimum); + void maximumChanged(int maximum); + void stateChanged(ProgressState state); + +private: + Q_DISABLE_COPY(QWinTaskbarProgress) + Q_DECLARE_PRIVATE(QWinTaskbarProgress) + QScopedPointer d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QWINTASKBARPROGRESS_H diff --git a/src/winextras/winextras.pro b/src/winextras/winextras.pro index e278fff..fdf96a9 100644 --- a/src/winextras/winextras.pro +++ b/src/winextras/winextras.pro @@ -6,6 +6,7 @@ SOURCES += \ qwinfunctions.cpp \ qwinfunctions_p.cpp \ qwintaskbarbutton.cpp \ + qwintaskbarprogress.cpp \ windowsguidsdefs.cpp \ qwinjumplist.cpp \ qwinjumplistitem.cpp \ @@ -20,6 +21,7 @@ HEADERS += \ qwinfunctions_p.h \ qwintaskbarbutton_p.h \ qwintaskbarbutton.h \ + qwintaskbarprogress.h \ qwinjumplist.h \ qwinjumplistitem.h \ winshobjidl_p.h \ -- cgit v1.2.3