diff options
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r-- | src/quickcontrols2/qquickanimatednode.cpp | 163 | ||||
-rw-r--r-- | src/quickcontrols2/qquickanimatednode_p.h | 112 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle.cpp | 55 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle.h | 1 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle_p.h | 1 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyleselector_p_p.h | 1 | ||||
-rw-r--r-- | src/quickcontrols2/qquicktumblerview.cpp | 2 | ||||
-rw-r--r-- | src/quickcontrols2/quickcontrols2.pri | 2 |
8 files changed, 330 insertions, 7 deletions
diff --git a/src/quickcontrols2/qquickanimatednode.cpp b/src/quickcontrols2/qquickanimatednode.cpp new file mode 100644 index 00000000..2c5cdc67 --- /dev/null +++ b/src/quickcontrols2/qquickanimatednode.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickanimatednode_p.h" + +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickwindow.h> + +// based on qtdeclarative/examples/quick/scenegraph/threadedanimation + +QT_BEGIN_NAMESPACE + +QQuickAnimatedNode::QQuickAnimatedNode(QQuickItem *target) + : m_running(false), + m_duration(0), + m_loopCount(1), + m_currentTime(0), + m_currentLoop(0), + m_window(target->window()) +{ +} + +bool QQuickAnimatedNode::isRunning() const +{ + return m_running; +} + +int QQuickAnimatedNode::currentTime() const +{ + int time = m_currentTime; + if (m_running) + time += m_timer.elapsed(); + return time; +} + +void QQuickAnimatedNode::setCurrentTime(int time) +{ + m_currentTime = time; + m_timer.restart(); +} + +int QQuickAnimatedNode::duration() const +{ + return m_duration; +} + +void QQuickAnimatedNode::setDuration(int duration) +{ + m_duration = duration; +} + +int QQuickAnimatedNode::loopCount() const +{ + return m_loopCount; +} + +void QQuickAnimatedNode::setLoopCount(int count) +{ + m_loopCount = count; +} + +void QQuickAnimatedNode::sync(QQuickItem *target) +{ + Q_UNUSED(target); +} + +QQuickWindow *QQuickAnimatedNode::window() const +{ + return m_window; +} + +void QQuickAnimatedNode::start(int duration) +{ + if (m_running) + return; + + m_running = true; + m_currentLoop = 0; + m_timer.restart(); + if (duration > 0) + m_duration = duration; + connect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance); + connect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update); + emit started(); +} + +void QQuickAnimatedNode::restart() +{ + stop(); + start(); +} + +void QQuickAnimatedNode::stop() +{ + if (!m_running) + return; + + m_running = false; + disconnect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance); + disconnect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update); + emit stopped(); +} + +void QQuickAnimatedNode::updateCurrentTime(int time) +{ + Q_UNUSED(time); +} + +void QQuickAnimatedNode::advance() +{ + int time = currentTime(); + if (time > m_duration) { + time = 0; + setCurrentTime(0); + + if (m_loopCount > 0 && ++m_currentLoop >= m_loopCount) { + time = m_duration; // complete + stop(); + } + } + updateCurrentTime(time); +} + +void QQuickAnimatedNode::update() +{ + if (m_running) + m_window->update(); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickanimatednode_p.h b/src/quickcontrols2/qquickanimatednode_p.h new file mode 100644 index 00000000..24b404c9 --- /dev/null +++ b/src/quickcontrols2/qquickanimatednode_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKANIMATEDNODE_P_H +#define QQUICKANIMATEDNODE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuick/qsgnode.h> +#include <QtCore/qelapsedtimer.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickWindow; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAnimatedNode : public QObject, public QSGTransformNode +{ + Q_OBJECT + +public: + explicit QQuickAnimatedNode(QQuickItem *target); + + bool isRunning() const; + + int currentTime() const; + void setCurrentTime(int time); + + int duration() const; + void setDuration(int duration); + + enum LoopCount { Infinite = -1 }; + + int loopCount() const; + void setLoopCount(int count); + + virtual void sync(QQuickItem *target); + + QQuickWindow *window() const; + + // must be called from sync() or updatePaintNode() + void start(int duration = 0); + void restart(); + void stop(); + +Q_SIGNALS: + void started(); + void stopped(); + +protected: + virtual void updateCurrentTime(int time); + +private Q_SLOTS: + void advance(); + void update(); + +private: + bool m_running; + int m_duration; + int m_loopCount; + int m_currentTime; + int m_currentLoop; + QElapsedTimer m_timer; + QQuickWindow *m_window; +}; + +QT_END_NAMESPACE + +#endif // QQUICKANIMATEDNODE_P_H diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 3ad7c074..cf4979c1 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -205,12 +205,11 @@ struct QQuickStyleSpec if (QGuiApplication::instance()) { if (!custom) { - const QString targetPath = QStringLiteral("QtQuick/Controls.2"); - const QStringList importPaths = defaultImportPathList(); - - for (const QString &importPath : importPaths) { - QString stylePath = findStyle(importPath + QLatin1Char('/') + targetPath, style); + const QStringList stylePaths = QQuickStylePrivate::stylePaths(); + for (const QString &path : stylePaths) { + QString stylePath = findStyle(path, style); if (!stylePath.isEmpty()) { + custom = !stylePath.startsWith(baseUrl.toLocalFile()); style = stylePath; resolved = true; break; @@ -254,6 +253,27 @@ struct QQuickStyleSpec Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) +QStringList QQuickStylePrivate::stylePaths() +{ + // system/custom style paths + QStringList paths; + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE_PATH"))) { + const QByteArray value = qgetenv("QT_QUICK_CONTROLS_STYLE_PATH"); + paths += QString::fromLatin1(value).split(QDir::listSeparator(), QString::SkipEmptyParts); + } + + // built-in import paths + const QString targetPath = QStringLiteral("QtQuick/Controls.2"); + const QStringList importPaths = defaultImportPathList(); + for (const QString &importPath : importPaths) { + QDir dir(importPath); + if (dir.cd(targetPath)) + paths += dir.absolutePath(); + } + + return paths; +} + QString QQuickStylePrivate::fallbackStyle() { return styleSpec()->fallbackStyle; @@ -354,4 +374,29 @@ void QQuickStyle::setFallbackStyle(const QString &style) styleSpec()->setFallbackStyle(style, "QQuickStyle::setFallbackStyle()"); } +/*! + \since 5.9 + Returns the names of the available built-in styles. + + \note The method must be called \b after creating an instance of QGuiApplication. +*/ +QStringList QQuickStyle::availableStyles() +{ + QStringList styles; + if (!QGuiApplication::instance()) { + qWarning() << "ERROR: QQuickStyle::availableStyles() must be called after creating an instance of QGuiApplication."; + return styles; + } + + const QStringList stylePaths = QQuickStylePrivate::stylePaths(); + for (const QString &path : stylePaths) { + QDir dir(path); + styles += dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot); + styles.removeAll(QStringLiteral("designer")); + } + styles.prepend(QStringLiteral("Default")); + styles.removeDuplicates(); + return styles; +} + QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle.h b/src/quickcontrols2/qquickstyle.h index d2e7faf1..4260411e 100644 --- a/src/quickcontrols2/qquickstyle.h +++ b/src/quickcontrols2/qquickstyle.h @@ -50,6 +50,7 @@ public: static QString path(); static void setStyle(const QString &style); static void setFallbackStyle(const QString &style); + static QStringList availableStyles(); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 65f48d95..1655f805 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate { public: + static QStringList stylePaths(); static QString fallbackStyle(); static bool isCustomStyle(); static void init(const QUrl &baseUrl); diff --git a/src/quickcontrols2/qquickstyleselector_p_p.h b/src/quickcontrols2/qquickstyleselector_p_p.h index 4ff28d5d..6423233f 100644 --- a/src/quickcontrols2/qquickstyleselector_p_p.h +++ b/src/quickcontrols2/qquickstyleselector_p_p.h @@ -65,4 +65,3 @@ public: QT_END_NAMESPACE #endif // QQUICKSTYLESELECTOR_P_P_H - diff --git a/src/quickcontrols2/qquicktumblerview.cpp b/src/quickcontrols2/qquicktumblerview.cpp index 540a8dd1..ef11a70f 100644 --- a/src/quickcontrols2/qquicktumblerview.cpp +++ b/src/quickcontrols2/qquicktumblerview.cpp @@ -189,7 +189,7 @@ void QQuickTumblerView::updateView() m_pathView->setDragMargin(width() / 2); } else { m_listView->setPreferredHighlightBegin(height() / 2 - (height() / m_tumbler->visibleItemCount() / 2)); - m_listView->setPreferredHighlightEnd(height() / 2 + (height() / m_tumbler->visibleItemCount() / 2)); + m_listView->setPreferredHighlightEnd(height() / 2 + (height() / m_tumbler->visibleItemCount() / 2)); } } diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri index 8e4e0046..eddd14d2 100644 --- a/src/quickcontrols2/quickcontrols2.pri +++ b/src/quickcontrols2/quickcontrols2.pri @@ -1,4 +1,5 @@ HEADERS += \ + $$PWD/qquickanimatednode_p.h \ $$PWD/qquickcolorimageprovider_p.h \ $$PWD/qquickproxytheme_p.h \ $$PWD/qquickstyle.h \ @@ -11,6 +12,7 @@ HEADERS += \ $$PWD/qquicktumblerview_p.h SOURCES += \ + $$PWD/qquickanimatednode.cpp \ $$PWD/qquickcolorimageprovider.cpp \ $$PWD/qquickproxytheme.cpp \ $$PWD/qquickstyle.cpp \ |