diff --git a/QtScrcpy/QtScrcpy.pro b/QtScrcpy/QtScrcpy.pro index 7c1364c..db01ddf 100644 --- a/QtScrcpy/QtScrcpy.pro +++ b/QtScrcpy/QtScrcpy.pro @@ -5,7 +5,7 @@ #------------------------------------------------- QT += core gui -QT += network quickwidgets +QT += network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -24,6 +24,11 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += SKIP_FRAMES +#DEFINES += USE_QTQUICK + +contains(DEFINES, USE_QTQUICK) { + QT += quickwidgets +} # 源码 SOURCES += \ diff --git a/QtScrcpy/qml/pinwheel.qml b/QtScrcpy/qml/pinwheel.qml index 61c328b..8893b99 100644 --- a/QtScrcpy/qml/pinwheel.qml +++ b/QtScrcpy/qml/pinwheel.qml @@ -9,11 +9,12 @@ Image { RotationAnimation { id:rotationAnimation target: wheel - to:360000 + to:360 direction: RotationAnimation.Clockwise - duration: 800000 + duration: 800 + loops:Animation.Infinite } onStatusChanged: if (wheel.status == Image.Ready) rotationAnimation.start() } -} \ No newline at end of file +} diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index 629224a..9fe3682 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -7,7 +7,10 @@ #ifdef Q_OS_WIN32 #include #endif +#ifdef USE_QTQUICK #include +#endif +#include #include #include #include @@ -76,12 +79,40 @@ VideoForm::~VideoForm() void VideoForm::initUI() { + setAttribute(Qt::WA_DeleteOnClose); QPixmap phone; if (phone.load(":/res/phone.png")) { m_widthHeightRatio = 1.0f * phone.width() / phone.height(); } - setAttribute(Qt::WA_DeleteOnClose); +#ifdef USE_QTQUICK + // qml animation + QWidget *loadingWidget; + QHBoxLayout *horizontalLayout; + QQuickWidget *quickWidget; + loadingWidget = new QWidget(this); + loadingWidget->setObjectName(QStringLiteral("loadingWidget")); + loadingWidget->setAutoFillBackground(false); + loadingWidget->setStyleSheet(QStringLiteral("")); + loadingWidget->setAttribute(Qt::WA_DeleteOnClose); + m_loadingWidget = loadingWidget; + horizontalLayout = new QHBoxLayout(loadingWidget); + horizontalLayout->setSpacing(0); + horizontalLayout->setObjectName(QStringLiteral("horizontalLayout")); + horizontalLayout->setContentsMargins(0, 0, 0, 0); + quickWidget = new QQuickWidget(loadingWidget); + quickWidget->setObjectName(QStringLiteral("quickWidget")); + quickWidget->setAutoFillBackground(false); + quickWidget->setStyleSheet(QStringLiteral("")); + quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); + quickWidget->setSource(QUrl(QStringLiteral("qrc:/qml/pinwheel.qml"))); + // 最后绘制,不设置最后绘制会影响父窗体异形异常(quickWidget的透明通道会形成穿透) + quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop); + // 背景透明 + quickWidget->setClearColor(QColor(Qt::transparent)); + horizontalLayout->addWidget(quickWidget); + ui->verticalLayout->addWidget(loadingWidget); +#endif // mac下去掉标题栏影响showfullscreen #ifndef Q_OS_OSX @@ -91,15 +122,9 @@ void VideoForm::initUI() setAttribute(Qt::WA_TranslucentBackground); #endif - setMouseTracking(true); - ui->loadingWidget->setAttribute(Qt::WA_DeleteOnClose); + setMouseTracking(true); ui->videoWidget->setMouseTracking(true); - ui->videoWidget->hide(); - - // 最后绘制,不设置最后绘制会影响父窗体异形异常(quickWidget的透明通道会形成穿透) - ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop); - // 背景透明 - ui->quickWidget->setClearColor(QColor(Qt::transparent)); + ui->videoWidget->hide(); } void VideoForm::initSignals() @@ -178,7 +203,9 @@ void VideoForm::initSignals() // must be Qt::QueuedConnection, ui update must be main thread connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ if (ui->videoWidget->isHidden()) { - ui->loadingWidget->close(); + if (m_loadingWidget) { + m_loadingWidget->close(); + } ui->videoWidget->show(); } m_frames.lock(); diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index 49b49ef..3cd7994 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -79,6 +79,7 @@ private: QPointer m_toolForm; Recorder* m_recorder = Q_NULLPTR; QTime m_startTimeCount; + QPointer m_loadingWidget; }; #endif // VIDEOFORM_H diff --git a/QtScrcpy/videoform.ui b/QtScrcpy/videoform.ui index 539e5b5..9c393cc 100644 --- a/QtScrcpy/videoform.ui +++ b/QtScrcpy/videoform.ui @@ -38,62 +38,12 @@ 62 - - - - false - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - - - - QQuickWidget::SizeRootObjectToView - - - - qrc:/qml/pinwheel.qml - - - - - - - - - QQuickWidget - QWidget -
QtQuickWidgets/QQuickWidget
-
QYUVOpenGLWidget QWidget