diff --git a/example/qml-Qt6/window/MainWindow.qml b/example/qml-Qt6/window/MainWindow.qml index 2512bee9..298333f9 100644 --- a/example/qml-Qt6/window/MainWindow.qml +++ b/example/qml-Qt6/window/MainWindow.qml @@ -282,6 +282,21 @@ CustomWindow { id:http } + FpsItem{ + id:fps_item + } + + FluText{ + text:"fps %1".arg(fps_item.fps) + opacity: 0.3 + anchors{ + bottom: parent.bottom + right: parent.right + bottomMargin: 5 + rightMargin: 5 + } + } + FluContentDialog{ property string newVerson property string body diff --git a/example/qml/window/MainWindow.qml b/example/qml/window/MainWindow.qml index f0f8367a..6115301f 100644 --- a/example/qml/window/MainWindow.qml +++ b/example/qml/window/MainWindow.qml @@ -283,6 +283,21 @@ CustomWindow { id:http } + FpsItem{ + id:fps_item + } + + FluText{ + text:"fps %1".arg(fps_item.fps) + opacity: 0.3 + anchors{ + bottom: parent.bottom + right: parent.right + bottomMargin: 5 + rightMargin: 5 + } + } + FluContentDialog{ property string newVerson property string body diff --git a/example/src/component/FpsItem.cpp b/example/src/component/FpsItem.cpp new file mode 100644 index 00000000..23ceb37a --- /dev/null +++ b/example/src/component/FpsItem.cpp @@ -0,0 +1,19 @@ +#include "FpsItem.h" + +#include +#include + +FpsItem::FpsItem() +{ + QTimer *timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, [this]{ + fps(_frameCount); + _frameCount = 0; + }); + connect(this, &QQuickItem::windowChanged, this, [this]{ + if (window()){ + connect(window(), &QQuickWindow::afterRendering, this, [this]{ _frameCount++; }, Qt::DirectConnection); + } + }); + timer->start(1000); +} diff --git a/example/src/component/FpsItem.h b/example/src/component/FpsItem.h new file mode 100644 index 00000000..4b51cdaf --- /dev/null +++ b/example/src/component/FpsItem.h @@ -0,0 +1,19 @@ +#ifndef FPSITEM_H +#define FPSITEM_H + +#include +#include "src/stdafx.h" + +class FpsItem : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY_AUTO(int,fps) +public: + FpsItem(); + +private: + int _frameCount = 0; + +}; + +#endif // FPSITEM_H diff --git a/example/src/main.cpp b/example/src/main.cpp index d5df129e..1cbe1648 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -11,6 +11,7 @@ #include "AppInfo.h" #include "src/component/CircularReveal.h" #include "src/component/FileWatcher.h" +#include "src/component/FpsItem.h" FRAMELESSHELPER_USE_NAMESPACE @@ -49,6 +50,7 @@ int main(int argc, char *argv[]) #endif qmlRegisterType("example", 1, 0, "CircularReveal"); qmlRegisterType("example", 1, 0, "FileWatcher"); + qmlRegisterType("example", 1, 0, "FpsItem"); appInfo->init(&engine); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,