From 3dbd9c1e2501347b82eecc878c2daeae3e399b40 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Fri, 25 Jan 2019 23:28:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=A0=E8=BD=BD=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtScrcpy/videoform.cpp | 69 ++++++++++++++++++------------------------ QtScrcpy/videoform.h | 1 + QtScrcpy/videoform.ui | 6 ++-- 3 files changed, 33 insertions(+), 43 deletions(-) diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index cd36dde..96992b1 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -18,23 +18,10 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) : QWidget(parent), ui(new Ui::videoForm), m_serial(serial) -{ +{ ui->setupUi(this); - setAttribute(Qt::WA_DeleteOnClose); - - QPixmap phone; - if (phone.load(":/res/phone.png")) { - m_widthHeightRatio = 1.0f * phone.width() / phone.height(); - } - - // 去掉标题栏 - setWindowFlags(Qt::FramelessWindowHint); - // 根据图片构造异形窗口 - setAttribute(Qt::WA_TranslucentBackground); - - setMouseTracking(true); - ui->videoWidget->setMouseTracking(true); + initUI(); connect(&m_inputConvert, &InputConvertGame::grabCursor, this, [this](bool grab){ #ifdef Q_OS_WIN32 @@ -90,6 +77,10 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) : // must be Qt::QueuedConnection, ui update must be main thread QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ + if (ui->videoWidget->isHidden()) { + ui->loadingWidget->hide(); + ui->videoWidget->show(); + } m_frames.lock(); const AVFrame *frame = m_frames.consumeRenderedFrame(); //qDebug() << "widthxheight:" << frame->width << "x" << frame->height; @@ -116,31 +107,7 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) : initStyle(); bool vertical = size().height() > size().width(); - updateStyleSheet(vertical); - - ui->videoWidget->hide(); - //ui->loadingWidget->setAutoFillBackground(true); - //ui->quickWidget->setClearColor(QColor(Qt::transparent)); - - //ui->quickWidget->setSource(QUrl(QString::fromUtf8("qrc:/qml/pinwheel.qml"))); - //ui->quickWidget->show(); - /* - QWidget* test = new QWidget(this); - test->setGeometry(QRect(0, 200, 170, 370)); - test->setAutoFillBackground(false); - test->show(); - // qquickwidget - QQuickWidget* pinwheel = new QQuickWidget(this); - pinwheel->setObjectName(QString::fromUtf8("pinwheel")); - pinwheel->setAutoFillBackground(false); - pinwheel->setResizeMode(QQuickWidget::SizeRootObjectToView); - pinwheel->setSource(QUrl(QString::fromUtf8("qrc:/qml/pinwheel.qml"))); - pinwheel->setClearColor(QColor(Qt::transparent)); - pinwheel->setGeometry(QRect(0, 0, 170, 170)); - //pinwheel->setGeometry(ui->videoWidget->geometry()); - pinwheel->setAutoFillBackground(true); - pinwheel->show(); - */ + updateStyleSheet(vertical); ToolForm* mw = new ToolForm(this, ToolForm::AP_OUTSIDE_RIGHT); mw->move(pos().x() + geometry().width(), pos().y() + 30); @@ -156,6 +123,28 @@ VideoForm::~VideoForm() delete ui; } +void VideoForm::initUI() +{ + QPixmap phone; + if (phone.load(":/res/phone.png")) { + m_widthHeightRatio = 1.0f * phone.width() / phone.height(); + } + + // 去掉标题栏 + setWindowFlags(Qt::FramelessWindowHint); + // 根据图片构造异形窗口 + setAttribute(Qt::WA_TranslucentBackground); + + setMouseTracking(true); + ui->videoWidget->setMouseTracking(true); + ui->videoWidget->hide(); + + // 最后绘制,不设置最后绘制会影响父窗体异形异常(quickWidget的透明通道会形成穿透) + ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop); + // 背景透明 + ui->quickWidget->setClearColor(QColor(Qt::transparent)); +} + void VideoForm::initStyle() { //IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13); diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index b52f525..1c688fd 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -26,6 +26,7 @@ private: void switchFullScreen(); void initStyle(); void updateStyleSheet(bool vertical); + void initUI(); protected: void mousePressEvent(QMouseEvent *event); diff --git a/QtScrcpy/videoform.ui b/QtScrcpy/videoform.ui index 03457fe..79545d6 100644 --- a/QtScrcpy/videoform.ui +++ b/QtScrcpy/videoform.ui @@ -41,7 +41,7 @@ false - background-color: rgb(0, 0, 0); + @@ -77,14 +77,14 @@ false - background-color: rgb(0, 0, 0); + QQuickWidget::SizeRootObjectToView - file:///G:/mygitcode/QtScrcpy/QtScrcpy/qml/pinwheel.qml + qrc:/qml/pinwheel.qml