summaryrefslogtreecommitdiffstats
path: root/tests/manual/examples/widgets/wiggly
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/examples/widgets/wiggly')
-rw-r--r--tests/manual/examples/widgets/wiggly/CMakeLists.txt38
-rw-r--r--tests/manual/examples/widgets/wiggly/dialog.cpp27
-rw-r--r--tests/manual/examples/widgets/wiggly/dialog.h19
-rw-r--r--tests/manual/examples/widgets/wiggly/main.cpp16
-rw-r--r--tests/manual/examples/widgets/wiggly/wiggly.pro11
-rw-r--r--tests/manual/examples/widgets/wiggly/wigglywidget.cpp65
-rw-r--r--tests/manual/examples/widgets/wiggly/wigglywidget.h32
7 files changed, 208 insertions, 0 deletions
diff --git a/tests/manual/examples/widgets/wiggly/CMakeLists.txt b/tests/manual/examples/widgets/wiggly/CMakeLists.txt
new file mode 100644
index 0000000000..fe68396f92
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/CMakeLists.txt
@@ -0,0 +1,38 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(wiggly LANGUAGES CXX)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/widgets/wiggly")
+
+find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
+
+qt_standard_project_setup()
+
+qt_add_executable(wiggly
+ dialog.cpp dialog.h
+ main.cpp
+ wigglywidget.cpp wigglywidget.h
+)
+
+set_target_properties(wiggly PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(wiggly PRIVATE
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
+)
+
+install(TARGETS wiggly
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/tests/manual/examples/widgets/wiggly/dialog.cpp b/tests/manual/examples/widgets/wiggly/dialog.cpp
new file mode 100644
index 0000000000..0f3aa84fd8
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/dialog.cpp
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "dialog.h"
+#include "wigglywidget.h"
+
+#include <QLineEdit>
+#include <QVBoxLayout>
+
+//! [0]
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent)
+{
+ WigglyWidget *wigglyWidget = new WigglyWidget;
+ QLineEdit *lineEdit = new QLineEdit;
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(wigglyWidget);
+ layout->addWidget(lineEdit);
+
+ connect(lineEdit, &QLineEdit::textChanged, wigglyWidget, &WigglyWidget::setText);
+ lineEdit->setText(u8"🖖 " + tr("Hello world!"));
+
+ setWindowTitle(tr("Wiggly"));
+ resize(360, 145);
+}
+//! [0]
diff --git a/tests/manual/examples/widgets/wiggly/dialog.h b/tests/manual/examples/widgets/wiggly/dialog.h
new file mode 100644
index 0000000000..1f27668f4a
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/dialog.h
@@ -0,0 +1,19 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+
+//! [0]
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit Dialog(QWidget *parent = nullptr);
+};
+//! [0]
+
+#endif
diff --git a/tests/manual/examples/widgets/wiggly/main.cpp b/tests/manual/examples/widgets/wiggly/main.cpp
new file mode 100644
index 0000000000..e7df19b6a0
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/main.cpp
@@ -0,0 +1,16 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "dialog.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ Dialog dialog;
+ dialog.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/examples/widgets/wiggly/wiggly.pro b/tests/manual/examples/widgets/wiggly/wiggly.pro
new file mode 100644
index 0000000000..0e39f18add
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/wiggly.pro
@@ -0,0 +1,11 @@
+QT += widgets
+
+HEADERS = wigglywidget.h \
+ dialog.h
+SOURCES = wigglywidget.cpp \
+ dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/wiggly
+INSTALLS += target
diff --git a/tests/manual/examples/widgets/wiggly/wigglywidget.cpp b/tests/manual/examples/widgets/wiggly/wigglywidget.cpp
new file mode 100644
index 0000000000..3e686a67cf
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/wigglywidget.cpp
@@ -0,0 +1,65 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "wigglywidget.h"
+
+#include <QFontMetrics>
+#include <QPainter>
+#include <QTimerEvent>
+
+//! [0]
+WigglyWidget::WigglyWidget(QWidget *parent)
+ : QWidget(parent), step(0)
+{
+ setBackgroundRole(QPalette::Midlight);
+ setAutoFillBackground(true);
+
+ QFont newFont = font();
+ newFont.setPointSize(newFont.pointSize() + 20);
+ setFont(newFont);
+
+ timer.start(60, this);
+}
+//! [0]
+
+//! [1]
+void WigglyWidget::paintEvent(QPaintEvent * /* event */)
+//! [1] //! [2]
+{
+ static constexpr int sineTable[16] = {
+ 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38
+ };
+
+ QFontMetrics metrics(font());
+ int x = (width() - metrics.horizontalAdvance(text)) / 2;
+ int y = (height() + metrics.ascent() - metrics.descent()) / 2;
+ QColor color;
+//! [2]
+
+//! [3]
+ QPainter painter(this);
+//! [3] //! [4]
+ int offset = 0;
+ for (char32_t codePoint : text.toUcs4()) {
+ int index = (step + offset++) % 16;
+ color.setHsv((15 - index) * 16, 255, 191);
+ painter.setPen(color);
+ QString symbol = QString::fromUcs4(&codePoint, 1);
+ painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), symbol);
+ x += metrics.horizontalAdvance(symbol);
+ }
+}
+//! [4]
+
+//! [5]
+void WigglyWidget::timerEvent(QTimerEvent *event)
+//! [5] //! [6]
+{
+ if (event->timerId() == timer.timerId()) {
+ ++step;
+ update();
+ } else {
+ QWidget::timerEvent(event);
+ }
+//! [6]
+}
diff --git a/tests/manual/examples/widgets/wiggly/wigglywidget.h b/tests/manual/examples/widgets/wiggly/wigglywidget.h
new file mode 100644
index 0000000000..1c21e52234
--- /dev/null
+++ b/tests/manual/examples/widgets/wiggly/wigglywidget.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#ifndef WIGGLYWIDGET_H
+#define WIGGLYWIDGET_H
+
+#include <QBasicTimer>
+#include <QWidget>
+
+//! [0]
+class WigglyWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ WigglyWidget(QWidget *parent = nullptr);
+
+public slots:
+ void setText(const QString &newText) { text = newText; }
+
+protected:
+ void paintEvent(QPaintEvent *event) override;
+ void timerEvent(QTimerEvent *event) override;
+
+private:
+ QBasicTimer timer;
+ QString text;
+ int step;
+};
+//! [0]
+
+#endif