aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qmlcompiler/qcoloroutput.cpp22
-rw-r--r--tests/manual/vectorimagetest/LottieAnimation.qml1
-rw-r--r--tests/manual/vectorimagetest/VectorImage.qml1
-rw-r--r--tests/manual/vectorimagetest/mainwindow.cpp13
-rw-r--r--tests/manual/vectorimagetest/mainwindow.h1
-rw-r--r--tests/manual/vectorimagetest/mainwindow.ui55
-rw-r--r--tests/manual/vectorimagetest/svgpainter.cpp3
-rw-r--r--tests/manual/vectorimagetest/svgpainter.h17
-rw-r--r--tests/manual/vectorimagetest/vectorimagemanager.h16
9 files changed, 103 insertions, 26 deletions
diff --git a/src/qmlcompiler/qcoloroutput.cpp b/src/qmlcompiler/qcoloroutput.cpp
index f3f5b86d7a..6a99a8007e 100644
--- a/src/qmlcompiler/qcoloroutput.cpp
+++ b/src/qmlcompiler/qcoloroutput.cpp
@@ -6,7 +6,9 @@
#include <QtCore/qfile.h>
#include <QtCore/qhash.h>
-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+#include <qt_windows.h>
+#else
#include <unistd.h>
#endif
@@ -75,17 +77,25 @@ private:
*/
inline bool isColoringPossible() const
{
+ static std::optional<bool> canColor;
+ if (canColor.has_value())
+ return canColor.value();
+
#if defined(Q_OS_WIN)
- /* Windows doesn't at all support ANSI escape codes, unless
- * the user install a "device driver". See the Wikipedia links in the
- * class documentation for details. */
- return false;
+ HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE);
+ DWORD mode = 0;
+
+ if (GetConsoleMode(hErr, &mode))
+ canColor = SetConsoleMode(hErr, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
+ else
+ canColor = false;
#else
/* We use QFile::handle() to get the file descriptor. It's a bit unsure
* whether it's 2 on all platforms and in all cases, so hopefully this layer
* of abstraction helps handle such cases. */
- return isatty(fileno(stderr));
+ canColor = isatty(fileno(stderr));
#endif
+ return canColor.value();
}
};
diff --git a/tests/manual/vectorimagetest/LottieAnimation.qml b/tests/manual/vectorimagetest/LottieAnimation.qml
index 8463234393..28c14706cc 100644
--- a/tests/manual/vectorimagetest/LottieAnimation.qml
+++ b/tests/manual/vectorimagetest/LottieAnimation.qml
@@ -12,5 +12,6 @@ Item {
id: lottieAnimation
textureSize: Qt.size(width * parent.scale, height * parent.scale)
source: VectorImageManager.currentSource.toString().endsWith("json") ? VectorImageManager.currentSource : ""
+ loops: VectorImageManager.looping ? LottieAnimation.Infinite : 1
}
}
diff --git a/tests/manual/vectorimagetest/VectorImage.qml b/tests/manual/vectorimagetest/VectorImage.qml
index dfd5473ed6..4a3fedf832 100644
--- a/tests/manual/vectorimagetest/VectorImage.qml
+++ b/tests/manual/vectorimagetest/VectorImage.qml
@@ -14,5 +14,6 @@ Item {
source: VectorImageManager.currentSource
preferredRendererType: VectorImage.CurveRenderer
assumeTrustedSource: true
+ animations.loops: VectorImageManager.looping ? Animation.Infinite : 1
}
}
diff --git a/tests/manual/vectorimagetest/mainwindow.cpp b/tests/manual/vectorimagetest/mainwindow.cpp
index a1580d7f8b..c3b11c04b8 100644
--- a/tests/manual/vectorimagetest/mainwindow.cpp
+++ b/tests/manual/vectorimagetest/mainwindow.cpp
@@ -12,6 +12,7 @@
#include <QQuickWidget>
#include <QQmlEngine>
#include <QSlider>
+#include <QCheckBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -58,9 +59,16 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->hsScale, &QAbstractSlider::valueChanged, m_manager, &VectorImageManager::setScale);
connect(ui->hsScale, &QAbstractSlider::valueChanged, m_svgPainter, &SvgPainter::setScale);
connect(ui->hsScale, &QAbstractSlider::valueChanged, this, &MainWindow::setScale);
+
+ connect(ui->cbLooping, &QCheckBox::toggled, m_manager, &VectorImageManager::setLooping);
+ connect(ui->cbLooping, &QCheckBox::toggled, this, &MainWindow::setLooping);
+ connect(ui->cbLooping, &QCheckBox::toggled, m_svgPainter, &SvgPainter::setLooping);
+
int scale = m_settings->value(QStringLiteral("scale"), 10).toInt();
ui->hsScale->setValue(scale);
+ ui->cbLooping->setChecked(m_settings->value(QStringLiteral("looping")).toBool());
+
ui->tbNext->setShortcut(QKeySequence(QKeySequence::MoveToNextChar));
ui->tbPrev->setShortcut(QKeySequence(QKeySequence::MoveToPreviousChar));
}
@@ -175,3 +183,8 @@ void MainWindow::previous()
m_manager->setCurrentIndex(m_manager->currentIndex() - 1);
}
+
+void MainWindow::setLooping(bool looping)
+{
+ m_settings->setValue(QStringLiteral("looping"), looping);
+}
diff --git a/tests/manual/vectorimagetest/mainwindow.h b/tests/manual/vectorimagetest/mainwindow.h
index cc0fe83ab5..865893b847 100644
--- a/tests/manual/vectorimagetest/mainwindow.h
+++ b/tests/manual/vectorimagetest/mainwindow.h
@@ -34,6 +34,7 @@ private slots:
void previous();
void loadDirectory(const QString &newDir);
void updateIndex(int newIndex);
+ void setLooping(bool looping);
private:
void updateCurrentDir(const QString &newDir);
diff --git a/tests/manual/vectorimagetest/mainwindow.ui b/tests/manual/vectorimagetest/mainwindow.ui
index dd5a32dc8d..f7e16d0585 100644
--- a/tests/manual/vectorimagetest/mainwindow.ui
+++ b/tests/manual/vectorimagetest/mainwindow.ui
@@ -55,7 +55,7 @@
<x>0</x>
<y>0</y>
<width>263</width>
- <height>790</height>
+ <height>788</height>
</rect>
</property>
</widget>
@@ -98,7 +98,7 @@
<x>0</x>
<y>0</y>
<width>264</width>
- <height>790</height>
+ <height>788</height>
</rect>
</property>
</widget>
@@ -141,7 +141,7 @@
<x>0</x>
<y>0</y>
<width>263</width>
- <height>790</height>
+ <height>788</height>
</rect>
</property>
</widget>
@@ -167,7 +167,7 @@
<item>
<widget class="QScrollArea" name="saVectorImage">
<property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -184,7 +184,7 @@
<x>0</x>
<y>0</y>
<width>263</width>
- <height>790</height>
+ <height>788</height>
</rect>
</property>
</widget>
@@ -254,20 +254,37 @@
</widget>
</item>
<item>
- <widget class="QSlider" name="hsScale">
- <property name="minimum">
- <number>1</number>
- </property>
- <property name="maximum">
- <number>100</number>
- </property>
- <property name="value">
- <number>10</number>
- </property>
- <property name="orientation">
- <enum>Qt::Orientation::Horizontal</enum>
- </property>
- </widget>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QSlider" name="hsScale">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>100</number>
+ </property>
+ <property name="value">
+ <number>10</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Orientation::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="cbLooping">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Looping animations</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</widget>
diff --git a/tests/manual/vectorimagetest/svgpainter.cpp b/tests/manual/vectorimagetest/svgpainter.cpp
index 7de39e5a4d..3deec5a2ee 100644
--- a/tests/manual/vectorimagetest/svgpainter.cpp
+++ b/tests/manual/vectorimagetest/svgpainter.cpp
@@ -73,6 +73,9 @@ void SvgPainter::paintEvent(QPaintEvent *event)
m_renderer.render(&p);
m_size = m_renderer.defaultSize();
setFixedSize(m_size * m_scale / 10.0);
+
+ if (m_looping && m_renderer.currentFrame() >= (m_renderer.animationDuration() / 1000 * m_renderer.framesPerSecond()))
+ m_renderer.setCurrentFrame(0);
}
#else
m_size = renderer()->defaultSize();
diff --git a/tests/manual/vectorimagetest/svgpainter.h b/tests/manual/vectorimagetest/svgpainter.h
index d362258661..d78af20aa1 100644
--- a/tests/manual/vectorimagetest/svgpainter.h
+++ b/tests/manual/vectorimagetest/svgpainter.h
@@ -20,6 +20,7 @@ class SvgPainter : public QWidget
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
+ Q_PROPERTY(bool looping READ looping WRITE setLooping NOTIFY loopingChanged)
public:
explicit SvgPainter(QWidget *parent = nullptr);
@@ -29,10 +30,23 @@ public:
qreal scale() const;
void setScale(const qreal scale);
+ bool looping() const
+ {
+ return m_looping;
+ }
+
+ void setLooping(bool looping)
+ {
+ if (m_looping == looping)
+ return;
+ m_looping = looping;
+ emit loopingChanged();
+ }
+
signals:
void sourceChanged();
void scaleChanged();
-
+ void loopingChanged();
protected:
#ifndef SVGWIDGET
@@ -45,6 +59,7 @@ private:
QUrl m_source;
QSize m_size;
qreal m_scale;
+ bool m_looping = false;
#ifndef SVGWIDGET
QSvgRenderer m_renderer;
#endif
diff --git a/tests/manual/vectorimagetest/vectorimagemanager.h b/tests/manual/vectorimagetest/vectorimagemanager.h
index e81cf4520a..67fa8989dc 100644
--- a/tests/manual/vectorimagetest/vectorimagemanager.h
+++ b/tests/manual/vectorimagetest/vectorimagemanager.h
@@ -20,6 +20,7 @@ class VectorImageManager : public QObject
Q_PROPERTY(QString currentDirectory READ currentDirectory WRITE setCurrentDirectory NOTIFY currentDirectoryChanged)
Q_PROPERTY(QList<QUrl> sources READ sources NOTIFY sourcesChanged)
Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
+ Q_PROPERTY(bool looping READ looping WRITE setLooping NOTIFY loopingChanged)
public:
VectorImageManager(QObject *parent);
~VectorImageManager() override;
@@ -57,8 +58,21 @@ public:
qreal scale() const;
+ bool looping() const
+ {
+ return m_looping;
+ }
+
public slots:
void setScale(int newScale);
+ void setLooping(bool looping)
+ {
+ if (m_looping == looping)
+ return;
+
+ m_looping = looping;
+ emit loopingChanged();
+ }
signals:
void currentSourceChanged();
@@ -69,6 +83,7 @@ signals:
void currentDirectoryChanged();
void scaleChanged();
+ void loopingChanged();
private:
static VectorImageManager *g_manager;
@@ -77,6 +92,7 @@ private:
QString m_currentDirectory;
QString m_qmlSource;
qreal m_scale = 10.0;
+ bool m_looping = false;
};
#endif // VECTORIMAGEMANAGER_H