diff --git a/WidgetMovement.qbs b/WidgetMovement.qbs new file mode 100644 index 0000000..b97534c --- /dev/null +++ b/WidgetMovement.qbs @@ -0,0 +1,20 @@ +import qbs.FileInfo + +QtApplication { + Depends { name: "Qt.widgets" } + + cpp.defines: [ + // You can make your code fail to compile if it uses deprecated APIs. + // In order to do so, uncomment the following line. + //"QT_DISABLE_DEPRECATED_BEFORE=0x060000" // disables all the APIs deprecated before Qt 6.0.0 + ] + + files: [ + "main.cpp", + "mainwindow.cpp", + "mainwindow.h", + ] + + install: true + installDir: qbs.targetOS.contains("qnx") ? FileInfo.joinPaths("/tmp", name, "bin") : base +} diff --git a/WidgetMovement.qbs.user b/WidgetMovement.qbs.user new file mode 100644 index 0000000..cc7fb0a --- /dev/null +++ b/WidgetMovement.qbs.user @@ -0,0 +1,339 @@ + + + + + + EnvironmentId + {6e0f1a15-0091-43fd-86e2-976cc30150d1} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 6 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 5.12.12 MinGW 64-bit + Desktop Qt 5.12.12 MinGW 64-bit + qt.qt5.51212.win64_mingw73_kit + 0 + 0 + 0 + + D:\C++\Other\build-WidgetMovement-Desktop_Qt_5_12_12_MinGW_64_bit-Debug + + + true + Qbs (сборка) + Qbs.BuildStep + + debug + qtc_Desktop__034a3d58 + false + + true + 12 + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qbs (очистка) + Qbs.CleanStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qbs.QbsBuildConfiguration + Debug_Desktop__3974988abbc7268e + + + D:\C++\Other\build-WidgetMovement-Desktop_Qt_5_12_12_MinGW_64_bit-Release + + + true + Qbs (сборка) + Qbs.BuildStep + + release + qtc_Desktop__034a3d58 + + true + 12 + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qbs (очистка) + Qbs.CleanStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qbs.QbsBuildConfiguration + Release_Desktop__4aa00cbb42fc094d + + 2 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qbs.RunConfiguration:WidgetMovement. + WidgetMovement. + false + true + true + false + true + D:/C++/Other/build-WidgetMovement-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/Debug_Desktop__3974988abbc7268e/install-root/bin + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop + Desktop Qt 5.12.12 MinGW 32-bit + Desktop Qt 5.12.12 MinGW 32-bit + qt.qt5.51212.win32_mingw73_kit + 0 + 0 + 0 + + D:\C++\Other\build-WidgetMovement-Desktop_Qt_5_12_12_MinGW_32_bit-Debug + + + true + Qbs (сборка) + Qbs.BuildStep + + debug + qtc_Desktop__50d5c625 + + true + 12 + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qbs (очистка) + Qbs.CleanStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qbs.QbsBuildConfiguration + Debug_Desktop__497064d93505f293 + + + D:\C++\Other\build-WidgetMovement-Desktop_Qt_5_12_12_MinGW_32_bit-Release + + + true + Qbs (сборка) + Qbs.BuildStep + + release + qtc_Desktop__50d5c625 + + true + 12 + + 1 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qbs (очистка) + Qbs.CleanStep + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qbs.QbsBuildConfiguration + Release_Desktop__076eac804a3a9cc0 + + 2 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..78577f2 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + resize(300, 600); + + m_timer = new QTimer(this); + + m_timer->setInterval(m_randomizer.bounded(100,1000)); + m_timer->start(); + + connect(m_timer, &QTimer::timeout, [this] + { + m_timer->setInterval(m_randomizer.bounded(100,1000)); + m_timer->start(); + + auto pb = new QPushButton("*", this); + pb->setMouseTracking(true); + + const qint32 startPositionX = m_randomizer.bounded(30, this->width() - 30); + const qint32 startPositionY = 10; + + pb->setGeometry(startPositionX, startPositionY, 25, 25); + pb->show(); + + const auto speed = m_randomizer.bounded(1,10); + + auto moveTimer = new QTimer(pb); + moveTimer->setInterval(100); + moveTimer->start(); + + connect(moveTimer, &QTimer::timeout, [pb, speed, this] + { + pb->move(pb->pos() + QPoint(0, speed * (pb->underMouse() ? 2 : 1))); + + if (pb->pos().y() > height()) + { + pb->deleteLater(); + setPalette(QPalette(QPalette::Background, Qt::red)); + setWindowTitle("You LOOSE!"); + } + }); + + connect(pb, &QPushButton::clicked, + pb, &QPushButton::deleteLater); + }); + + m_timer->start(); +} + +MainWindow::~MainWindow() +{ +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..e95bd8f --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,23 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include + +class QTimer; + + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + + QRandomGenerator m_randomizer; + +private: + QTimer* m_timer = nullptr; +}; +#endif // MAINWINDOW_H