diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-05-27 11:49:54 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-07 11:10:28 +0200 |
commit | cef1f2fab06ed9d01d525681f5a11db67bb8f262 (patch) | |
tree | eca3a46df630bdb770ee708a908fc4b38816c9af /tests | |
parent | 7bb27be8c5ce9a67a413022d627d9580cddbe64e (diff) |
Implement iconic live previews/iconic thumbnail icons.
[ChangeLog][QWinThumbnailToolBar] Added pixmap properties
and change notifications for thumbnail icons and live
preview.
Task-number: QTBUG-36730
Change-Id: I31ad0ff347235bc7933c1c14dece359ec0c36b39
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/manual/manual.pro | 3 | ||||
-rw-r--r-- | tests/manual/quickthumbnail/main.qml | 4 | ||||
-rw-r--r-- | tests/manual/thumbnail/main.cpp | 165 | ||||
-rw-r--r-- | tests/manual/thumbnail/thumbnail.pro | 4 |
4 files changed, 174 insertions, 2 deletions
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 14a08ef..4ff3a0b 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -2,5 +2,6 @@ TEMPLATE = subdirs qtHaveModule(widgets) { SUBDIRS += \ dwmfeatures \ - jumplist + jumplist \ + thumbnail } diff --git a/tests/manual/quickthumbnail/main.qml b/tests/manual/quickthumbnail/main.qml index b422564..a28744d 100644 --- a/tests/manual/quickthumbnail/main.qml +++ b/tests/manual/quickthumbnail/main.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -55,6 +55,8 @@ ApplicationWindow { ThumbnailToolBar { id: toolBar + iconicThumbnailSource : "qrc:/qt-project.org/qmessagebox/images/qtlogo-64.png" + iconicLivePreviewSource : "qrc:/qt-project.org/qmessagebox/images/qtlogo-64.png" ThumbnailToolButton { tooltip: "Button #1" diff --git a/tests/manual/thumbnail/main.cpp b/tests/manual/thumbnail/main.cpp new file mode 100644 index 0000000..bfce7bb --- /dev/null +++ b/tests/manual/thumbnail/main.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** + ** + ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). + ** Contact: http://www.qt-project.org/legal + ** + ** This file is part of the test suite 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 <QApplication> +#include <QMainWindow> +#include <QPlainTextEdit> +#include <QMenuBar> +#include <QMenu> +#include <QAction> +#include <QStyle> +#include <QScreen> +#include <QShortcut> +#include <QPixmap> +#include <QPainter> +#include <QFontMetrics> +#include <QtWinExtras> +#include <QDebug> + +static QPixmap drawColoredPixmap(const QSize &size, const QColor &color, + const QString &text = QString()) +{ + QPixmap result(size); + result.fill(color); + QPainter painter(&result); + painter.drawRect(QRect(QPoint(0, 0), size - QSize(1, 1))); + if (!text.isEmpty()) { + QFont font = painter.font(); + font.setPointSize(20); + painter.setFont(font); + const QFontMetrics fontMetrics(font); + QRect boundingRect(fontMetrics.boundingRect(text)); + const int x = (size.width() - boundingRect.width()) / 2; + const int y = size.height() - (size.height() - boundingRect.height()) / 2; + painter.drawText(x, y, text); + } + return result; +} + +class MainWindow : public QMainWindow { + Q_OBJECT +public: + MainWindow(); + void initThumbnailToolBar(); + +public slots: + void testButtonClicked(); + void updateIconicThumbnailPixmap(); + void updateIconicLivePreviewPixmap(); + void logText(const QString &text); + +private: + QWinThumbnailToolBar *m_thumbnailToolBar; + QPlainTextEdit *m_logEdit; +}; + +MainWindow::MainWindow() + : m_thumbnailToolBar(new QWinThumbnailToolBar(this)) + , m_logEdit(new QPlainTextEdit) +{ + setMinimumWidth(400); + setWindowTitle(QStringLiteral("QWinThumbnailToolBar ") + QLatin1String(QT_VERSION_STR)); + QMenu *fileMenu = menuBar()->addMenu("&File"); + QAction *quitAction = fileMenu->addAction("&Quit"); + quitAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q)); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + setCentralWidget(m_logEdit); +} + +void MainWindow::initThumbnailToolBar() +{ + m_thumbnailToolBar->setWindow(windowHandle()); + QWinThumbnailToolButton *testButton = new QWinThumbnailToolButton(m_thumbnailToolBar); + testButton->setToolTip("Test"); + testButton->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon)); + connect(testButton, SIGNAL(clicked()), this, SLOT(testButtonClicked())); + m_thumbnailToolBar->addButton(testButton); + m_thumbnailToolBar->setIconicPixmapNotificationsEnabled(true); + connect(m_thumbnailToolBar, SIGNAL(iconicLivePreviewPixmapRequested()), + this, SLOT(updateIconicLivePreviewPixmap())); + connect(m_thumbnailToolBar, SIGNAL(iconicThumbnailPixmapRequested()), + this, SLOT(updateIconicThumbnailPixmap())); +} + +void MainWindow::logText(const QString &text) +{ + m_logEdit->appendPlainText(text); + qDebug("%s", qPrintable(text)); +} + +void MainWindow::testButtonClicked() +{ + static int n = 1; + logText(QStringLiteral("Clicked #") + QString::number(n++)); +} + +void MainWindow::updateIconicThumbnailPixmap() +{ + static int n = 1; + const QString number = QString::number(n++); + logText(QLatin1String(__FUNCTION__) + QLatin1Char(' ') + number); + const QPixmap pixmap = + drawColoredPixmap(QSize(200, 50), Qt::yellow, QStringLiteral("ITP ") + number); + m_thumbnailToolBar->setIconicThumbnailPixmap(pixmap); +} + +void MainWindow::updateIconicLivePreviewPixmap() +{ + static int n = 1; + const QString number = QString::number(n++); + logText(QLatin1String(__FUNCTION__) + QLatin1Char(' ') + number); + const QPixmap pixmap = + drawColoredPixmap(QSize(200, 50), Qt::red, QStringLiteral("ILP ") + number); + m_thumbnailToolBar->setIconicLivePreviewPixmap(pixmap); +} + +int main(int argc, char* argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.move(QGuiApplication::primaryScreen()->availableGeometry().center() + - QPoint(w.width() / 2, w.height() / 2)); + w.show(); + w.initThumbnailToolBar(); + return a.exec(); +} + +#include "main.moc" diff --git a/tests/manual/thumbnail/thumbnail.pro b/tests/manual/thumbnail/thumbnail.pro new file mode 100644 index 0000000..2259b9b --- /dev/null +++ b/tests/manual/thumbnail/thumbnail.pro @@ -0,0 +1,4 @@ +TEMPLATE = app +QT += widgets winextras +CONFIG -= app_bundle +SOURCES += main.cpp |