diff --git a/src/imports/winextras/qquickwinthumbnailtoolbar.cpp b/src/imports/winextras/qquickwinthumbnailtoolbar.cpp new file mode 100644 index 0000000000000000000000000000000000000000..714f42e82c4636dcfed6ef3e6b532818d5061a8a --- /dev/null +++ b/src/imports/winextras/qquickwinthumbnailtoolbar.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** + ** + ** 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 "qquickwinthumbnailtoolbar.h" +#include "qquickwinthumbnailtoolbutton.h" + +#include <QQuickWindow> +#include <QQmlEngine> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ThumbnailToolBar + \instantiates QQuickWinThumbnailToolBar + \inqmlmodule QtWinExtras + + \brief 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.qml thumbbar_qml + \since QtWinExtras 1.0 + */ + +QQuickWinThumbnailToolBar::QQuickWinThumbnailToolBar(QQuickItem *parent) : + QQuickItem(parent) +{ +} + +QQuickWinThumbnailToolBar::~QQuickWinThumbnailToolBar() +{ +} + +QQmlListProperty<QObject> QQuickWinThumbnailToolBar::data() +{ + return QQmlListProperty<QObject>(this, this, &QQuickWinThumbnailToolBar::addData, 0, 0, 0); +} + +void QQuickWinThumbnailToolBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + if (change == ItemSceneChange) + m_toolbar.setWindow(data.window); + QQuickItem::itemChange(change, data); +} + +void QQuickWinThumbnailToolBar::addData(QQmlListProperty<QObject> *property, QObject *object) +{ + if (const QQuickWinThumbnailToolButton *button = qobject_cast<QQuickWinThumbnailToolButton *>(object)) { + QQuickWinThumbnailToolBar *quickThumbbar = static_cast<QQuickWinThumbnailToolBar *>(property->data); + quickThumbbar->m_toolbar.addButton(button->m_button); + } +} + +QT_END_NAMESPACE diff --git a/src/imports/winextras/qquickwinthumbnailtoolbar.h b/src/imports/winextras/qquickwinthumbnailtoolbar.h new file mode 100644 index 0000000000000000000000000000000000000000..9f2a1465438c130e9481231d9316c13d88bc6f59 --- /dev/null +++ b/src/imports/winextras/qquickwinthumbnailtoolbar.h @@ -0,0 +1,72 @@ +/**************************************************************************** + ** + ** 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 QQUICKWINTHUMBNAILTOOLBAR_H +#define QQUICKWINTHUMBNAILTOOLBAR_H + +#include <QQuickItem> +#include <QWinThumbnailToolBar> + +QT_BEGIN_NAMESPACE + +class QQuickWinThumbnailToolBar : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<QObject> data READ data) + Q_CLASSINFO("DefaultProperty", "data") + +public: + explicit QQuickWinThumbnailToolBar(QQuickItem *parent = 0); + ~QQuickWinThumbnailToolBar(); + + QQmlListProperty<QObject> data(); + + void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data); + +private: + static void addData(QQmlListProperty<QObject> *property, QObject *button); + + QWinThumbnailToolBar m_toolbar; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWINTHUMBNAILTOOLBAR_H diff --git a/src/imports/winextras/qquickwinthumbnailtoolbutton.cpp b/src/imports/winextras/qquickwinthumbnailtoolbutton.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c736fbe51ed0c9dfd2f098c492d2ab8d9afdeaa --- /dev/null +++ b/src/imports/winextras/qquickwinthumbnailtoolbutton.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** + ** + ** 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 "qquickwinthumbnailtoolbutton.h" + +#include <QWinThumbnailToolButton> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ThumbnailToolButton + \instantiates QQuickWinThumbnailToolButton + \inqmlmodule QtWinExtras + + \brief Represents a button in a thumbnail toolbar. + + The ThumbnailToolButton represents a button in a thumbnail toolbar. + \since QtWinExtras 1.0 + */ + +/*! + \qmlsignal ThumbnailToolButton::clicked() + This signal is emitted when the user clicks the button. The corresponding handler is \c onClicked. +*/ + +QQuickWinThumbnailToolButton::QQuickWinThumbnailToolButton(QObject *parent) : + QObject(parent), m_button(new QWinThumbnailToolButton(this)) +{ + connect(m_button, SIGNAL(clicked()), SIGNAL(clicked())); + connect(&m_loader, SIGNAL(finished()), SLOT(iconLoaded())); +} + +QQuickWinThumbnailToolButton::~QQuickWinThumbnailToolButton() +{ +} + +/*! + \qmlproperty url ThumbnailToolButton::iconSource + + The button icon path. + */ +void QQuickWinThumbnailToolButton::setIconSource(const QUrl &iconSource) +{ + if (m_iconSource != iconSource) { + m_iconSource = iconSource; + emit iconSourceChanged(); + m_loader.load(m_iconSource, qmlEngine(this)); + } +} + +QUrl QQuickWinThumbnailToolButton::iconSource() +{ + return m_iconSource; +} + +/*! + \qmlproperty string ThumbnailToolButton::tooltip + + The tooltip of the button. + */ +void QQuickWinThumbnailToolButton::setTooltip(const QString &tooltip) +{ + if (m_button->toolTip() != tooltip) { + m_button->setToolTip(tooltip); + emit tooltipChanged(); + } +} + +QString QQuickWinThumbnailToolButton::tooltip() const +{ + return m_button->toolTip(); +} + +/*! + \qmlproperty bool ThumbnailToolButton::enabled + + This property holds whether the button is enabled. + + By default, this property is set to true. + */ +void QQuickWinThumbnailToolButton::setEnabled(bool enabled) +{ + if (m_button->isEnabled() != enabled) { + m_button->setEnabled(enabled); + emit enabledChanged(); + } +} + +bool QQuickWinThumbnailToolButton::isEnabled() const +{ + return m_button->isEnabled(); +} + +/*! + \qmlproperty bool ThumbnailToolButton::interactive + + This property holds whether the button is interactive. + 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. + + By default, this property is set to true. + */ +void QQuickWinThumbnailToolButton::setInteractive(bool interactive) +{ + if (m_button->isInteractive() != interactive) { + m_button->setInteractive(interactive); + emit interactiveChanged(); + } +} + +bool QQuickWinThumbnailToolButton::isInteractive() const +{ + return m_button->isInteractive(); +} + +/*! + \qmlproperty bool ThumbnailToolButton::visible + + This property holds whether the button is visible. + + By default, this property is set to true. + */ +void QQuickWinThumbnailToolButton::setVisible(bool visible) +{ + if (m_button->isVisible() != visible) { + m_button->setVisible(visible); + emit visibleChanged(); + } +} + +bool QQuickWinThumbnailToolButton::isVisible() const +{ + return m_button->isVisible(); +} + +/*! + \qmlproperty bool ThumbnailToolButton::dismissOnClick + + This property holds whether the window thumbnail is dismissed after a button click. + + By default, this property is set to false. + */ +void QQuickWinThumbnailToolButton::setDismissOnClick(bool dismiss) +{ + if (m_button->dismissOnClick() != dismiss) { + m_button->setDismissOnClick(dismiss); + emit dismissOnClickChanged(); + } +} + +bool QQuickWinThumbnailToolButton::dismissOnClick() const +{ + return m_button->dismissOnClick(); +} + +/*! + \qmlproperty bool ThumbnailToolButton::flat + + This property holds whether the button background and frame are not drawn. + + By default, this property is set to false. + */ +void QQuickWinThumbnailToolButton::setFlat(bool flat) +{ + if (m_button->isFlat() != flat) { + m_button->setFlat(flat); + emit flatChanged(); + } +} + +bool QQuickWinThumbnailToolButton::isFlat() const +{ + return m_button->isFlat(); +} + +void QQuickWinThumbnailToolButton::iconLoaded() +{ + QIcon icon = m_loader.icon(); + if (!icon.isNull()) + m_button->setIcon(icon); +} + +QT_END_NAMESPACE diff --git a/src/imports/winextras/qquickwinthumbnailtoolbutton.h b/src/imports/winextras/qquickwinthumbnailtoolbutton.h new file mode 100644 index 0000000000000000000000000000000000000000..084ab899b244b59d210f620d5da01f046fa9c55b --- /dev/null +++ b/src/imports/winextras/qquickwinthumbnailtoolbutton.h @@ -0,0 +1,106 @@ +/**************************************************************************** + ** + ** 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 QQUICKWINTHUMBNAILTOOLBUTTON_H +#define QQUICKWINTHUMBNAILTOOLBUTTON_H + +#include <QQuickItem> +#include <QWinThumbnailToolBar> +#include <QUrl> + +#include "qwiniconloader.h" + +QT_BEGIN_NAMESPACE + +class QQuickWinThumbnailToolButton : public QObject +{ + Q_OBJECT + Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged) + Q_PROPERTY(QString tooltip READ tooltip WRITE setTooltip NOTIFY tooltipChanged) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(bool dismissOnClick READ dismissOnClick WRITE setDismissOnClick NOTIFY dismissOnClickChanged) + Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged) + +public: + explicit QQuickWinThumbnailToolButton(QObject *parent = 0); + ~QQuickWinThumbnailToolButton(); + + void setIconSource(const QUrl &iconSource); + QUrl iconSource(); + void setTooltip(const QString &tooltip); + QString tooltip() const; + void setEnabled(bool isEnabled); + bool isEnabled() const; + void setInteractive(bool isInteractive); + bool isInteractive() const; + void setVisible(bool isVisible); + bool isVisible() const; + void setDismissOnClick(bool dismiss); + bool dismissOnClick() const; + void setFlat(bool flat); + bool isFlat() const; + +Q_SIGNALS: + void clicked(); + void iconSourceChanged(); + void tooltipChanged(); + void enabledChanged(); + void interactiveChanged(); + void visibleChanged(); + void dismissOnClickChanged(); + void flatChanged(); + +private Q_SLOTS: + void iconLoaded(); + +private: + QUrl m_iconSource; + QWinThumbnailToolButton *m_button; + QWinIconLoader m_loader; + + friend class QQuickWinThumbnailToolBar; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWINTHUMBNAILTOOLBUTTON_H diff --git a/src/imports/winextras/qwinextrasplugin.cpp b/src/imports/winextras/qwinextrasplugin.cpp index ad72ca79b4978eba1f5bec385266aa46f2129468..b9f5dd543378d9c990254048e72e1852ef1f0d48 100644 --- a/src/imports/winextras/qwinextrasplugin.cpp +++ b/src/imports/winextras/qwinextrasplugin.cpp @@ -43,6 +43,8 @@ #include "qquickwindwmfeatures.h" #include "qquickwintaskbarbutton.h" #include "qquickjumplist.h" +#include "qquickwinthumbnailtoolbar.h" +#include "qquickwinthumbnailtoolbutton.h" #include <QtQml/QtQml> @@ -61,7 +63,8 @@ void QWinExtrasQmlPlugin::registerTypes(const char *uri) qmlRegisterType<QQuickJumpList>(uri, 1, 0, "JumpList"); qmlRegisterType<QQuickJumpListItem>(uri, 1, 0, "JumpListItem"); qmlRegisterType<QQuickJumpListCategory>(uri, 1, 0, "JumpListCategory"); + qmlRegisterType<QQuickWinThumbnailToolBar>(uri, 1, 0, "ThumbnailToolBar"); + qmlRegisterType<QQuickWinThumbnailToolButton>(uri, 1, 0, "ThumbnailToolButton"); } - QT_END_NAMESPACE diff --git a/src/imports/winextras/qwiniconloader.cpp b/src/imports/winextras/qwiniconloader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f3cd0038df9a9aee8bbcf47a3bb3983922a77f2b --- /dev/null +++ b/src/imports/winextras/qwiniconloader.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** + ** + ** 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 "qwiniconloader.h" + +#include <QUrl> +#include <QQmlEngine> +#include <QNetworkAccessManager> +#include <QFileInfo> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QPixmap> +#include <QQuickImageProvider> +#include <QQmlFile> +#include <qt_windows.h> + +QT_BEGIN_NAMESPACE + +QWinIconLoader::QWinIconLoader(QObject *parent) : + QObject(parent) +{ +} + +void QWinIconLoader::load(const QUrl &url, QQmlEngine *engine) +{ + m_icon = QIcon(); + QString scheme = url.scheme(); + if (scheme == QLatin1String("qrc") || scheme == QLatin1String("file")) + loadFromFile(url); + else if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) + loadFromNetwork(url, engine); + else if (scheme == QLatin1String("image")) + loadFromImageProvider(url, engine); +} + +QIcon QWinIconLoader::icon() const +{ + return m_icon; +} + +void QWinIconLoader::onRequestFinished(QNetworkReply *reply) +{ + disconnect(reply->manager(), 0, this, 0); + if (reply->error() == QNetworkReply::NoError) { + QByteArray data = reply->readAll(); + QPixmap pixmap; + if (pixmap.loadFromData(data)) { + m_icon = QIcon(pixmap); + emit finished(); + } + } else { + qWarning().nospace() << "Cannot load " << reply->url().toString() << " (" << qPrintable(reply->errorString()) << ")"; + } + reply->deleteLater(); +} + +void QWinIconLoader::loadFromFile(const QUrl &url) +{ + QString path = QQmlFile::urlToLocalFileOrQrc(url); + if (QFileInfo(path).exists()) { + m_icon = QIcon(path); + emit finished(); + } +} + +void QWinIconLoader::loadFromNetwork(const QUrl &url, QQmlEngine *engine) +{ + QNetworkRequest request(url); + QNetworkAccessManager *manager = engine->networkAccessManager(); + connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(onRequestFinished(QNetworkReply*))); + manager->get(request); +} + +static inline QString imageProviderId(const QUrl &url) +{ + return url.host(); +} + +static inline QString imageId(const QUrl &url) +{ + return url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1); +} + +void QWinIconLoader::loadFromImageProvider(const QUrl &url, QQmlEngine *engine) +{ + const QString providerId = url.host(); + const QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1); + QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid; + QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(providerId)); + QSize size; + QSize requestSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); + if (provider) + imageType = provider->imageType(); + if (imageType == QQuickImageProvider::Image) { + QImage image = provider->requestImage(imageId, &size, requestSize); + if (!image.isNull()) + m_icon = QIcon(QPixmap::fromImage(image)); + } else if (imageType == QQuickImageProvider::Pixmap) { + QPixmap pixmap = provider->requestPixmap(imageId, &size, requestSize); + if (!pixmap.isNull()) + m_icon = QIcon(pixmap); + } + emit finished(); +} + +QT_END_NAMESPACE diff --git a/src/imports/winextras/qwiniconloader.h b/src/imports/winextras/qwiniconloader.h new file mode 100644 index 0000000000000000000000000000000000000000..423d29d9656228452013ffce4d9f0206af4bb405 --- /dev/null +++ b/src/imports/winextras/qwiniconloader.h @@ -0,0 +1,79 @@ +/**************************************************************************** + ** + ** 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 QWINICONLOADER_H +#define QWINICONLOADER_H + +#include <QObject> +#include <QIcon> + +QT_BEGIN_NAMESPACE + +class QIcon; +class QQmlEngine; +class QNetworkReply; + +class QWinIconLoader : public QObject +{ + Q_OBJECT + +public: + explicit QWinIconLoader(QObject *parent = 0); + void load(const QUrl &url, QQmlEngine *engine); + QIcon icon() const; + +Q_SIGNALS: + void finished(); + +private Q_SLOTS: + void onRequestFinished(QNetworkReply*); + +private: + void loadFromFile(const QUrl &url); + void loadFromNetwork(const QUrl &url, QQmlEngine *engine); + void loadFromImageProvider(const QUrl &url, QQmlEngine *engine); + + QIcon m_icon; +}; + +QT_END_NAMESPACE + +#endif // QWINICONLOADER_H diff --git a/src/imports/winextras/winextras.pro b/src/imports/winextras/winextras.pro index 97f1de601c59c525b33ff9cabceee759b854514a..dadc5cf7c0ca10d65f160aedbffb33797d295ddd 100644 --- a/src/imports/winextras/winextras.pro +++ b/src/imports/winextras/winextras.pro @@ -15,13 +15,19 @@ HEADERS += \ qquickwindwmfeatures.h \ qquickwindwmfeatures_p.h \ qquickwintaskbarbutton.h \ - qquickjumplist.h + qquickjumplist.h \ + qquickwinthumbnailtoolbar.h \ + qquickwinthumbnailtoolbutton.h \ + qwiniconloader.h SOURCES += \ qwinextrasplugin.cpp \ qquickwindwmfeatures.cpp \ qquickwintaskbarbutton.cpp \ - qquickjumplist.cpp + qquickjumplist.cpp \ + qquickwinthumbnailtoolbar.cpp \ + qquickwinthumbnailtoolbutton.cpp \ + qwiniconloader.cpp OTHER_FILES += \ qmldir \ diff --git a/src/winextras/doc/snippets/code/thumbbar.qml b/src/winextras/doc/snippets/code/thumbbar.qml new file mode 100644 index 0000000000000000000000000000000000000000..dfc5bebe847f305624ab631ddda2ef40ecdbb1e5 --- /dev/null +++ b/src/winextras/doc/snippets/code/thumbbar.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Window 2.0 +import QtWinExtras 1.0 + +//! [thumbbar_qml] +Window { + ThumbnailToolBar { + ThumbnailToolButton { iconSource: "qrc:///player_rew.png"; tooltip: "Rewind"; onClicked: player.rewind() } + ThumbnailToolButton { iconSource: "qrc:///player_pause.png"; tooltip: "Pause"; onClicked: player.togglePlay() } + ThumbnailToolButton { iconSource: "qrc:///player_fwd.png"; tooltip: "Forward"; onClicked: player.forward() } + ThumbnailToolButton { interactive: false; flat: true } + ThumbnailToolButton { iconSource: "qrc:///configure.png"; tooltip: "Settings"; onClicked: settingsWindow.show() } + ThumbnailToolButton { iconSource: "qrc:///document_open_folder.png"; tooltip: "Open"; onClicked: player.open() } + } +} +//! [thumbbar_qml] diff --git a/src/winextras/winextras.pro b/src/winextras/winextras.pro index 7e830aa15945814e2cc72b728f070a9e5b92be5b..210e8bbbdf69b4f205e487e5beccb94af691ba1c 100644 --- a/src/winextras/winextras.pro +++ b/src/winextras/winextras.pro @@ -42,4 +42,5 @@ OTHER_FILES += \ doc/snippets/code/use-qtwinextras.pro \ doc/snippets/code/jumplist.cpp \ doc/snippets/code/use-qtwinextras.cpp \ - doc/snippets/code/thumbbar.cpp + doc/snippets/code/thumbbar.cpp \ + doc/snippets/code/thumbbar.qml