add FpsItem

This commit is contained in:
zhuzichu 2023-08-28 17:14:21 +08:00
parent 82a3f85f10
commit 5fc7ae7e89
5 changed files with 70 additions and 0 deletions

View File

@ -282,6 +282,21 @@ CustomWindow {
id:http 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{ FluContentDialog{
property string newVerson property string newVerson
property string body property string body

View File

@ -283,6 +283,21 @@ CustomWindow {
id:http 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{ FluContentDialog{
property string newVerson property string newVerson
property string body property string body

View File

@ -0,0 +1,19 @@
#include "FpsItem.h"
#include <QTimer>
#include <QQuickWindow>
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);
}

View File

@ -0,0 +1,19 @@
#ifndef FPSITEM_H
#define FPSITEM_H
#include <QQuickItem>
#include "src/stdafx.h"
class FpsItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY_AUTO(int,fps)
public:
FpsItem();
private:
int _frameCount = 0;
};
#endif // FPSITEM_H

View File

@ -11,6 +11,7 @@
#include "AppInfo.h" #include "AppInfo.h"
#include "src/component/CircularReveal.h" #include "src/component/CircularReveal.h"
#include "src/component/FileWatcher.h" #include "src/component/FileWatcher.h"
#include "src/component/FpsItem.h"
FRAMELESSHELPER_USE_NAMESPACE FRAMELESSHELPER_USE_NAMESPACE
@ -49,6 +50,7 @@ int main(int argc, char *argv[])
#endif #endif
qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal"); qmlRegisterType<CircularReveal>("example", 1, 0, "CircularReveal");
qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher"); qmlRegisterType<FileWatcher>("example", 1, 0, "FileWatcher");
qmlRegisterType<FpsItem>("example", 1, 0, "FpsItem");
appInfo->init(&engine); appInfo->init(&engine);
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,