Commit 42f2241d authored by Ivan Vizir's avatar Ivan Vizir Committed by The Qt Project
Browse files

Introduce QWinThumbnailToolBar and QWinThumbnailToolButton


Change-Id: I55d8f2e01c3647b49d117b2e7e8f7757fa843cba
Reviewed-by: default avatarJake Petroules <jake.petroules@petroules.com>
Reviewed-by: default avatarJan Arve Sæther <jan-arve.saether@digia.com>
Showing with 1031 additions and 3 deletions
src/winextras/doc/images/thumbbar.png

126 KB

/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtWinExtras>
void initializeThumbnailToolBar(QWidget *window)
{
Q_ASSERT(window->windowHandle()); // Note: this requires the window to be shown.
//! [thumbbar_cpp]
QWinThumbnailToolBar *thumbbar = QWinThumbnailToolBar(window);
thumbbar->setWindow(window->windowHandle());
QWinThumbnailToolButton *settings = new QWinThumbnailToolButton(thumbbar);
settings->setToolTip("Settings");
settings->setIcon(":/settings.png");
settings->setDismissOnClick(true);
connect(settings, SIGNAL(clicked()), settingsPage, SLOT(show()));
QWinThumbnailToolButton *playPause = new QWinThumbnailToolButton(thumbbar);
playPause->setToolTip("Play/Pause");
playPause->setIcon(":/play.png");
connect(playPause, SIGNAL(clicked()), mediaPlayer, SLOT(play()));
thumbbar->addButton(settings);
thumbbar->addButton(playPause);
//! [thumbbar_cpp]
}
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWinExtras in 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 "qwinthumbnailtoolbar.h"
#include "qwinthumbnailtoolbar_p.h"
#include "qwinthumbnailtoolbutton.h"
#include "qwinthumbnailtoolbutton_p.h"
#include <QWindow>
#include <QCoreApplication>
#include <QTimer>
#include <QDebug>
#include "qwintaskbarbuttoncreatedevent.h"
#include "qwinfunctions.h"
#include "qwineventfilter_p.h"
QT_BEGIN_NAMESPACE
static const int windowsLimitedThumbbarSize = 7;
/*!
\class QWinThumbnailToolBar
\inmodule QtWinExtras
\since 5.2
\brief The QWinThumbnailToolBar class allows manipulating the window's thumbnail toolbar.
This class allows an application to embed a toolbar in the thumbnail of a window,
which is shown when hovering over its taskbar icon. It provides quick access to
the window's commands without requiring the user to restore or activate the window.
\image thumbbar.png Media player thumbnail toolbar
\section3 Example
\snippet code/thumbbar.cpp thumbbar_cpp
*/
/*!
Constructs a QWinThumbnailToolBar with the parent object \a parent.
*/
QWinThumbnailToolBar::QWinThumbnailToolBar(QObject *parent) :
QObject(parent), d_ptr(new QWinThumbnailToolBarPrivate)
{
Q_D(QWinThumbnailToolBar);
d->q_ptr = this;
QWinEventFilter::setup();
setWindow(qobject_cast<QWindow *>(parent));
}
/*!
Destroys the QWinThumbnailToolBar and clears the toolbar.
*/
QWinThumbnailToolBar::~QWinThumbnailToolBar()
{
}
/*!
\property QWinThumbnailToolBar::window
\brief the window whose thumbnail toolbar is manipulated
*/
void QWinThumbnailToolBar::setWindow(QWindow *window)
{
Q_D(QWinThumbnailToolBar);
if (d->window != window) {
if (d->window) {
d->window->removeEventFilter(d);
d->clearToolbar();
}
d->window = window;
if (d->window) {
d->window->installEventFilter(d);
if (d->window->isVisible()) {
d->initToolbar();
d->_q_scheduleUpdate();
}
}
}
}
QWindow *QWinThumbnailToolBar::window() const
{
Q_D(const QWinThumbnailToolBar);
return d->window;
}
/*!
Appends a \a button to the right of the thumbnail toolbar.
\note The number of buttons is limited to 7.
*/
void QWinThumbnailToolBar::addButton(QWinThumbnailToolButton *button)
{
Q_D(QWinThumbnailToolBar);
if (d->buttonList.size() >= windowsLimitedThumbbarSize) {
qWarning() << "Cannot add " << button << " maximum number of buttons ("
<< windowsLimitedThumbbarSize << ") reached.";
return;
}
if (button && button->d_func()->toolbar != this) {
if (button->d_func()->toolbar) {
button->d_func()->toolbar->removeButton(button);
}
button->d_func()->toolbar = this;
connect(button, SIGNAL(changed()), this, SLOT(_q_scheduleUpdate()));
d->buttonList.append(button);
d->_q_scheduleUpdate();
}
}
/*!
Removes the \a button from this toolbar.
*/
void QWinThumbnailToolBar::removeButton(QWinThumbnailToolButton *button)
{
Q_D(QWinThumbnailToolBar);
if (button && d->buttonList.contains(button)) {
button->d_func()->toolbar = 0;
disconnect(button, SIGNAL(changed()), this, SLOT(_q_scheduleUpdate()));
d->buttonList.removeAll(button);
d->_q_scheduleUpdate();
}
}
/*!
Replaces the currently set toolbar with \a buttons.
*/
void QWinThumbnailToolBar::setButtons(const QList<QWinThumbnailToolButton *> &buttons)
{
Q_D(QWinThumbnailToolBar);
d->buttonList = buttons;
Q_FOREACH (QWinThumbnailToolButton *button, d->buttonList)
addButton(button);
d->_q_updateToolbar();
}
/*!
Returns the list of buttons which this toolbar consists of.
*/
QList<QWinThumbnailToolButton *> QWinThumbnailToolBar::buttons() const
{
Q_D(const QWinThumbnailToolBar);
return d->buttonList;
}
/*!
\property QWinThumbnailToolBar::count
\brief the current button count
*/
int QWinThumbnailToolBar::count() const
{
Q_D(const QWinThumbnailToolBar);
return d->buttonList.size();
}
/*!
Removes all buttons from the toolbar.
*/
void QWinThumbnailToolBar::clear()
{
setButtons(QList<QWinThumbnailToolButton *>());
}
static inline ITaskbarList4 *createTaskbarList()
{
ITaskbarList4 *result = 0;
HRESULT hresult = CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList4, reinterpret_cast<void **>(&result));
if (FAILED(hresult)) {
const QString err = QWinExtras::errorStringFromHresult(hresult);
qWarning("QWinThumbnailToolBar: IID_ITaskbarList4 was not created: %#010x, %s.",
(unsigned)hresult, qPrintable(err));
return 0;
}
hresult = result->HrInit();
if (FAILED(hresult)) {
result->Release();
const QString err = QWinExtras::errorStringFromHresult(hresult);
qWarning("QWinThumbnailToolBar: IID_ITaskbarList4 was not initialized: %#010x, %s.",
(unsigned)hresult, qPrintable(err));
return 0;
}
return result;
}
QWinThumbnailToolBarPrivate::QWinThumbnailToolBarPrivate() :
QObject(0), updateScheduled(false), window(0), pTbList(createTaskbarList()), q_ptr(0)
{
buttonList.reserve(windowsLimitedThumbbarSize);
QCoreApplication::instance()->installNativeEventFilter(this);
}
QWinThumbnailToolBarPrivate::~QWinThumbnailToolBarPrivate()
{
if (pTbList)
pTbList->Release();
QCoreApplication::instance()->removeNativeEventFilter(this);
}
void QWinThumbnailToolBarPrivate::initToolbar()
{
if (!pTbList || !window)
return;
THUMBBUTTON buttons[windowsLimitedThumbbarSize];
initButtons(buttons);
HRESULT hresult = pTbList->ThumbBarAddButtons(reinterpret_cast<HWND>(window->winId()), windowsLimitedThumbbarSize, buttons);
if (FAILED(hresult))
qWarning() << msgComFailed("ThumbBarAddButtons", hresult);
}
void QWinThumbnailToolBarPrivate::clearToolbar()
{
if (!pTbList || !window)
return;
THUMBBUTTON buttons[windowsLimitedThumbbarSize];
initButtons(buttons);
HRESULT hresult = pTbList->ThumbBarUpdateButtons(reinterpret_cast<HWND>(window->winId()), windowsLimitedThumbbarSize, buttons);
if (FAILED(hresult))
qWarning() << msgComFailed("ThumbBarUpdateButtons", hresult);
}
void QWinThumbnailToolBarPrivate::_q_updateToolbar()
{
updateScheduled = false;
if (!pTbList || !window)
return;
THUMBBUTTON buttons[windowsLimitedThumbbarSize];
initButtons(buttons);
const int thumbbarSize = qMin(buttonList.size(), windowsLimitedThumbbarSize);
// filling from the right fixes some strange bug which makes last button bg look like first btn bg
for (int i = (windowsLimitedThumbbarSize - thumbbarSize); i < windowsLimitedThumbbarSize; i++) {
QWinThumbnailToolButton *button = buttonList.at(i - (windowsLimitedThumbbarSize - thumbbarSize));
buttons[i].dwFlags = makeNativeButtonFlags(button);
buttons[i].dwMask = makeButtonMask(button);
if (!button->icon().isNull()) {;
buttons[i].hIcon = QWinExtras::toHICON(button->icon().pixmap(GetSystemMetrics(SM_CXSMICON)));
if (!buttons[i].hIcon)
buttons[i].hIcon = (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, SM_CXSMICON, SM_CYSMICON, LR_SHARED);
}
if (!button->toolTip().isEmpty()) {
buttons[i].szTip[button->toolTip().left(sizeof(buttons[i].szTip)/sizeof(buttons[i].szTip[0]) - 1).toWCharArray(buttons[i].szTip)] = 0;
}
}
HRESULT hresult = pTbList->ThumbBarUpdateButtons(reinterpret_cast<HWND>(window->winId()), windowsLimitedThumbbarSize, buttons);
if (FAILED(hresult))
qWarning() << msgComFailed("ThumbBarUpdateButtons", hresult);
freeButtonResources(buttons);
}
void QWinThumbnailToolBarPrivate::_q_scheduleUpdate()
{
if (updateScheduled)
return;
Q_Q(QWinThumbnailToolBar);
updateScheduled = true;
QTimer::singleShot(0, q, SLOT(_q_updateToolbar()));
}
bool QWinThumbnailToolBarPrivate::eventFilter(QObject *object, QEvent *event)
{
if (object == window && event->type() == QWinTaskbarButtonCreatedEvent::eventType()) {
initToolbar();
_q_scheduleUpdate();
}
return QObject::eventFilter(object, event);
}
bool QWinThumbnailToolBarPrivate::nativeEventFilter(const QByteArray &, void *message, long *result)
{
MSG *msg = static_cast<MSG *>(message);
if (window && msg->message == WM_COMMAND && HIWORD(msg->wParam) == THBN_CLICKED && msg->hwnd == reinterpret_cast<HWND>(window->winId())) {
int buttonId = LOWORD(msg->wParam);
buttonId = buttonId - (windowsLimitedThumbbarSize - qMin(windowsLimitedThumbbarSize, buttonList.size()));
buttonList.at(buttonId)->click();
if (result)
*result = 0;
return true;
}
return false;
}
void QWinThumbnailToolBarPrivate::initButtons(THUMBBUTTON *buttons)
{
for (int i = 0; i < windowsLimitedThumbbarSize; i++) {
memset(&buttons[i], 0, sizeof buttons[i]);
buttons[i].iId = i;
buttons[i].dwFlags = THBF_HIDDEN;
buttons[i].dwMask = THB_FLAGS;
}
}
THUMBBUTTONFLAGS QWinThumbnailToolBarPrivate::makeNativeButtonFlags(const QWinThumbnailToolButton *button)
{
THUMBBUTTONFLAGS nativeFlags = (THUMBBUTTONFLAGS)0;
if (button->isEnabled())
nativeFlags |= THBF_ENABLED;
else
nativeFlags |= THBF_DISABLED;
if (button->dismissOnClick())
nativeFlags |= THBF_DISMISSONCLICK;
if (button->isFlat())
nativeFlags |= THBF_NOBACKGROUND;
if (!button->isVisible())
nativeFlags |= THBF_HIDDEN;
if (!button->isInteractive())
nativeFlags |= THBF_NONINTERACTIVE;
return nativeFlags;
}
THUMBBUTTONMASK QWinThumbnailToolBarPrivate::makeButtonMask(const QWinThumbnailToolButton *button)
{
THUMBBUTTONMASK mask = (THUMBBUTTONMASK)0;
mask |= THB_FLAGS;
if (!button->icon().isNull())
mask |= THB_ICON;
if (!button->toolTip().isEmpty())
mask |= THB_TOOLTIP;
return mask;
}
void QWinThumbnailToolBarPrivate::freeButtonResources(THUMBBUTTON *buttons)
{
for (int i = 0; i < windowsLimitedThumbbarSize; i++) {
if (buttons[i].hIcon)
DeleteObject(buttons[i].hIcon);
}
}
QString QWinThumbnailToolBarPrivate::msgComFailed(const char *function, HRESULT hresult)
{
return QString::fromLatin1("QWinThumbnailToolBar: %1() failed: #%2: %3")
.arg(QLatin1String(function))
.arg((unsigned)hresult, 10, 16, QLatin1Char('0'))
.arg(QWinExtras::errorStringFromHresult(hresult));
}
QT_END_NAMESPACE
#include "moc_qwinthumbnailtoolbar.cpp"
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWinExtras in 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 QWINTHUMBNAILTOOLBAR_H
#define QWINTHUMBNAILTOOLBAR_H
#include <QtCore/qobject.h>
#include <QtCore/qscopedpointer.h>
#include <QtWinExtras/qwinextrasglobal.h>
QT_BEGIN_NAMESPACE
class QWindow;
class QWinThumbnailToolButton;
class QWinThumbnailToolBarPrivate;
class Q_WINEXTRAS_EXPORT QWinThumbnailToolBar : public QObject
{
Q_OBJECT
Q_PROPERTY(int count READ count STORED false)
Q_PROPERTY(QWindow *window READ window WRITE setWindow)
public:
explicit QWinThumbnailToolBar(QObject *parent = 0);
~QWinThumbnailToolBar();
void setWindow(QWindow *window);
QWindow *window() const;
void addButton(QWinThumbnailToolButton *button);
void removeButton(QWinThumbnailToolButton *button);
void setButtons(const QList<QWinThumbnailToolButton *> &buttons);
QList<QWinThumbnailToolButton *> buttons() const;
int count() const;
void clear();
private:
Q_DISABLE_COPY(QWinThumbnailToolBar)
Q_DECLARE_PRIVATE(QWinThumbnailToolBar)
QScopedPointer<QWinThumbnailToolBarPrivate> d_ptr;
friend class QWinThumbnailToolButton;
Q_PRIVATE_SLOT(d_func(), void _q_updateToolbar())
Q_PRIVATE_SLOT(d_func(), void _q_scheduleUpdate())
};
QT_END_NAMESPACE
#endif // QWINTHUMBNAILTOOLBAR_H
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWindowsExtras in 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 QWINTHUMBNAILTOOLBAR_P_H
#define QWINTHUMBNAILTOOLBAR_P_H
#include "qwinthumbnailtoolbar.h"
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtGui/QIcon>
#include <QtCore/QAbstractNativeEventFilter>
#include "winshobjidl_p.h"
QT_BEGIN_NAMESPACE
class QWinThumbnailToolBarPrivate : public QObject, QAbstractNativeEventFilter
{
public:
QWinThumbnailToolBarPrivate();
~QWinThumbnailToolBarPrivate();
void initToolbar();
void clearToolbar();
void _q_updateToolbar();
void _q_scheduleUpdate();
bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE;
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
static void initButtons(THUMBBUTTON *buttons);
static THUMBBUTTONFLAGS makeNativeButtonFlags(const QWinThumbnailToolButton *button);
static THUMBBUTTONMASK makeButtonMask(const QWinThumbnailToolButton *button);
static void freeButtonResources(THUMBBUTTON *buttons);
static QString msgComFailed(const char *function, HRESULT hresult);
bool updateScheduled;
QList<QWinThumbnailToolButton *> buttonList;
QWindow *window;
ITaskbarList4 * const pTbList;
private:
QWinThumbnailToolBar *q_ptr;
Q_DECLARE_PUBLIC(QWinThumbnailToolBar)
};
QT_END_NAMESPACE
#endif // QWINTHUMBNAILTOOLBAR_P_H
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWinExtras in 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 "qwinthumbnailtoolbutton.h"
#include "qwinthumbnailtoolbutton_p.h"
QT_BEGIN_NAMESPACE
/*!
\class QWinThumbnailToolButton
\inmodule QtWinExtras
\since 5.2
\brief The QWinThumbnailToolButton class represents a button in the window's thumbnail toolbar.
*/
/*!
\fn void QWinThumbnailToolButton::clicked()
This signal is emitted when the button is clicked.
*/
/*!
\internal
\fn void QWinThumbnailToolButton::changed()
*/
/*!
Constructs a QWinThumbnailToolButton with the specified \a parent.
*/
QWinThumbnailToolButton::QWinThumbnailToolButton(QObject *parent) :
QObject(parent), d_ptr(new QWinThumbnailToolButtonPrivate)
{
}
/*!
Destroys the QWinThumbnailToolButton.
*/
QWinThumbnailToolButton::~QWinThumbnailToolButton()
{
}
/*!
\property QWinThumbnailToolButton::toolTip
\brief the tooltip of the button
*/
void QWinThumbnailToolButton::setToolTip(const QString &toolTip)
{
Q_D(QWinThumbnailToolButton);
if (d->toolTip != toolTip) {
d->toolTip = toolTip;
emit changed();
}
}
QString QWinThumbnailToolButton::toolTip() const
{
Q_D(const QWinThumbnailToolButton);
return d->toolTip;
}
/*!
\property QWinThumbnailToolButton::icon
\brief the icon of the button
*/
void QWinThumbnailToolButton::setIcon(const QIcon &icon)
{
Q_D(QWinThumbnailToolButton);
if (d->icon.cacheKey() != icon.cacheKey()) {
d->icon = icon;
emit changed();
}
}
QIcon QWinThumbnailToolButton::icon() const
{
Q_D(const QWinThumbnailToolButton);
return d->icon;
}
/*!
\property QWinThumbnailToolButton::enabled
\brief whether the button is enabled
This property's default is true.
*/
void QWinThumbnailToolButton::setEnabled(bool enabled)
{
Q_D(QWinThumbnailToolButton);
if (d->enabled != enabled) {
d->enabled = enabled;
emit changed();
}
}
bool QWinThumbnailToolButton::isEnabled() const
{
Q_D(const QWinThumbnailToolButton);
return d->enabled;
}
/*!
\property QWinThumbnailToolButton::interactive
\brief whether the button is interactive
This property's default is true.
If not interactive, the button remains enabled, but no pressed or mouse-over
states are drawn. Set this property to false to use this button as a
notification icon.
*/
void QWinThumbnailToolButton::setInteractive(bool interactive)
{
Q_D(QWinThumbnailToolButton);
if (d->interactive != interactive) {
d->interactive = interactive;
emit changed();
}
}
bool QWinThumbnailToolButton::isInteractive() const
{
Q_D(const QWinThumbnailToolButton);
return d->interactive;
}
/*!
\property QWinThumbnailToolButton::visible
\brief whether the button is visible
This property's default is true.
*/
void QWinThumbnailToolButton::setVisible(bool visible)
{
Q_D(QWinThumbnailToolButton);
if (d->visible != visible) {
d->visible = visible;
emit changed();
}
}
bool QWinThumbnailToolButton::isVisible() const
{
Q_D(const QWinThumbnailToolButton);
return d->visible;
}
/*!
\property QWinThumbnailToolButton::dismissOnClick
\brief whether the window thumbnail is dismissed after a button click
This property's default is false.
*/
void QWinThumbnailToolButton::setDismissOnClick(bool dismiss)
{
Q_D(QWinThumbnailToolButton);
if (d->dismiss != dismiss) {
d->dismiss = dismiss;
emit changed();
}
}
bool QWinThumbnailToolButton::dismissOnClick() const
{
Q_D(const QWinThumbnailToolButton);
return d->dismiss;
}
/*!
\property QWinThumbnailToolButton::flat
\brief whether the button background and frame are not drawn
This property's default is false.
*/
void QWinThumbnailToolButton::setFlat(bool flat)
{
Q_D(QWinThumbnailToolButton);
if (d->flat != flat) {
d->flat = flat;
emit changed();
}
}
bool QWinThumbnailToolButton::isFlat() const
{
Q_D(const QWinThumbnailToolButton);
return d->flat;
}
/*!
Performs a click. The clicked() signal is emitted as appropriate.
Does nothing if the button is disabled or non-interactive.
*/
void QWinThumbnailToolButton::click()
{
Q_D(QWinThumbnailToolButton);
if (d->enabled && d->interactive)
emit clicked();
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWinExtras in 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 QWINTHUMBNAILTOOLBUTTON_H
#define QWINTHUMBNAILTOOLBUTTON_H
#include <QtGui/qicon.h>
#include <QtCore/qobject.h>
#include <QtCore/qscopedpointer.h>
#include <QtWinExtras/qwinextrasglobal.h>
QT_BEGIN_NAMESPACE
class QWinThumbnailToolButtonPrivate;
class Q_WINEXTRAS_EXPORT QWinThumbnailToolButton : public QObject
{
Q_OBJECT
Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
Q_PROPERTY(bool dismissOnClick READ dismissOnClick WRITE setDismissOnClick)
Q_PROPERTY(bool flat READ isFlat WRITE setFlat)
public:
explicit QWinThumbnailToolButton(QObject *parent = 0);
~QWinThumbnailToolButton();
void setToolTip(const QString &toolTip);
QString toolTip() const;
void setIcon(const QIcon &icon);
QIcon icon() const;
void setEnabled(bool enabled);
bool isEnabled() const;
void setInteractive(bool interactive);
bool isInteractive() const;
void setVisible(bool visible);
bool isVisible() const;
void setDismissOnClick(bool dismiss);
bool dismissOnClick() const;
void setFlat(bool flat);
bool isFlat() const;
public slots:
void click();
Q_SIGNALS:
void clicked();
void changed();
private:
Q_DISABLE_COPY(QWinThumbnailToolButton)
Q_DECLARE_PRIVATE(QWinThumbnailToolButton)
QScopedPointer<QWinThumbnailToolButtonPrivate> d_ptr;
friend class QWinThumbnailToolBar;
};
QT_END_NAMESPACE
#endif // QWINTHUMBNAILTOOLBUTTON_H
/****************************************************************************
**
** Copyright (C) 2013 Ivan Vizir <define-true-false@yandex.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of QtWindowsExtras in 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 QWINTHUMBNAILTOOLBUTTON_P_H
#define QWINTHUMBNAILTOOLBUTTON_P_H
#include <QtGui/qicon.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
class QWinThumbnailToolBar;
class QWinThumbnailToolButtonPrivate
{
public:
QWinThumbnailToolButtonPrivate() : enabled(true), interactive(true), dismiss(false), visible(true), flat(false), toolbar(0) {}
QString toolTip;
QIcon icon;
bool enabled;
bool interactive;
bool dismiss;
bool visible;
bool flat;
QWinThumbnailToolBar *toolbar;
};
QT_END_NAMESPACE
#endif // QWINTHUMBNAILTOOLBUTTON_P_H
...@@ -12,7 +12,9 @@ SOURCES += \ ...@@ -12,7 +12,9 @@ SOURCES += \
qwincompositionstatechangeevent.cpp \ qwincompositionstatechangeevent.cpp \
qwineventfilter.cpp \ qwineventfilter.cpp \
qwintaskbarbuttoncreatedevent.cpp \ qwintaskbarbuttoncreatedevent.cpp \
qwinthemechangeevent.cpp qwinthemechangeevent.cpp \
qwinthumbnailtoolbar.cpp \
qwinthumbnailtoolbutton.cpp
HEADERS += \ HEADERS += \
qwinfunctions.h \ qwinfunctions.h \
...@@ -31,7 +33,11 @@ HEADERS += \ ...@@ -31,7 +33,11 @@ HEADERS += \
winpropkey_p.h \ winpropkey_p.h \
qwineventfilter_p.h \ qwineventfilter_p.h \
qwinthemechangeevent.h \ qwinthemechangeevent.h \
qwinthemechangeevent_p.h qwinthemechangeevent_p.h \
qwinthumbnailtoolbar.h \
qwinthumbnailtoolbar_p.h \
qwinthumbnailtoolbutton.h \
qwinthumbnailtoolbutton_p.h
QMAKE_DOCS = $$PWD/doc/qtwinextras.qdocconf QMAKE_DOCS = $$PWD/doc/qtwinextras.qdocconf
...@@ -45,4 +51,5 @@ OTHER_FILES += \ ...@@ -45,4 +51,5 @@ OTHER_FILES += \
doc/src/qtwinextras-module-qml.qdoc \ doc/src/qtwinextras-module-qml.qdoc \
doc/snippets/code/use-qtwinextras.pro \ doc/snippets/code/use-qtwinextras.pro \
doc/snippets/code/jumplist.cpp \ doc/snippets/code/jumplist.cpp \
doc/snippets/code/use-qtwinextras.cpp doc/snippets/code/use-qtwinextras.cpp \
doc/snippets/code/thumbbar.cpp
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment