diff --git a/QtScrcpy/QtScrcpy.pro b/QtScrcpy/QtScrcpy.pro index d0a273d..5bc3cef 100644 --- a/QtScrcpy/QtScrcpy.pro +++ b/QtScrcpy/QtScrcpy.pro @@ -142,3 +142,5 @@ linux { RESOURCES += \ res.qrc +DISTFILES += + diff --git a/QtScrcpy/res.qrc b/QtScrcpy/res.qrc index 8b1a966..b0ce25b 100644 --- a/QtScrcpy/res.qrc +++ b/QtScrcpy/res.qrc @@ -2,5 +2,7 @@ res/psblack.css res/fontawesome-webfont.ttf + res/phone-h.png + res/phone-v.png diff --git a/QtScrcpy/res/phone-h.png b/QtScrcpy/res/phone-h.png new file mode 100644 index 0000000..0734a9b Binary files /dev/null and b/QtScrcpy/res/phone-h.png differ diff --git a/QtScrcpy/res/phone-v.png b/QtScrcpy/res/phone-v.png new file mode 100644 index 0000000..09724cb Binary files /dev/null and b/QtScrcpy/res/phone-v.png differ diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index 663af48..e4ac962 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #ifdef Q_OS_WIN32 #include #endif @@ -17,6 +20,16 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) : 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); @@ -98,6 +111,9 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) : updateShowSize(size()); initStyle(); + + bool vertical = size().height() > size().width(); + updateStyleSheet(vertical); } VideoForm::~VideoForm() @@ -111,8 +127,29 @@ VideoForm::~VideoForm() void VideoForm::initStyle() { - IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13); - IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15); + //IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13); + //IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15); +} + +void VideoForm::updateStyleSheet(bool vertical) +{ + if (vertical) { + setStyleSheet(R"( + #videoForm { + border-image: url(:/res/phone-v.png) 150px 142px 85px 142px; + border-width: 150px 142px 85px 142px; + } + )"); + layout()->setContentsMargins(10, 68, 12, 62); + } else { + setStyleSheet(R"( + #videoForm { + border-image: url(:/res/phone-h.png) 142px 85px 142px 150px; + border-width: 142px 85px 142px 150px; + } + )"); + layout()->setContentsMargins(68, 12, 62, 10); + } } void VideoForm::updateShowSize(const QSize &newSize) @@ -126,11 +163,11 @@ void VideoForm::updateShowSize(const QSize &newSize) if (desktop) { QRect screenRect = desktop->availableGeometry(); if (vertical) { - showSize.setHeight(qMin(newSize.height(), screenRect.height())); - showSize.setWidth(showSize.height()/2); + showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200)); + showSize.setWidth(showSize.height() * m_widthHeightRatio); } else { showSize.setWidth(qMin(newSize.width(), screenRect.width())); - showSize.setHeight(showSize.width()/2); + showSize.setHeight(showSize.width() * m_widthHeightRatio); } if (isFullScreen()) { @@ -140,11 +177,13 @@ void VideoForm::updateShowSize(const QSize &newSize) move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center()); } - int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight); - // 减去标题栏高度 - showSize.setHeight(showSize.height() - titleBarHeight); + // 减去标题栏高度 (mark:已经没有标题栏了) + //int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight); + //showSize.setHeight(showSize.height() - titleBarHeight); + if (showSize != size()) { - resize(showSize); + resize(showSize); + updateStyleSheet(vertical); } } } @@ -153,32 +192,54 @@ void VideoForm::switchFullScreen() { if (isFullScreen()) { showNormal(); - ui->rightToolWidget->show(); } else { - ui->rightToolWidget->hide(); showFullScreen(); } } void VideoForm::mousePressEvent(QMouseEvent *event) { - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + if (ui->videoWidget->geometry().contains(event->pos())) { + event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); + m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + } else { + if (event->button() == Qt::LeftButton) { + m_dragPosition = event->globalPos() - frameGeometry().topLeft(); + event->accept(); + } + } } void VideoForm::mouseReleaseEvent(QMouseEvent *event) { - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + if (ui->videoWidget->geometry().contains(event->pos())) { + event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); + m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + } } void VideoForm::mouseMoveEvent(QMouseEvent *event) -{ - m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); +{ + if (ui->videoWidget->geometry().contains(event->pos())) { + event->setLocalPos(ui->videoWidget->mapFrom(this, event->localPos().toPoint())); + m_inputConvert.mouseEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); + } else { + if (event->buttons() & Qt::LeftButton) { + move(event->globalPos() - m_dragPosition); + event->accept(); + } + } } void VideoForm::wheelEvent(QWheelEvent *event) { - m_inputConvert.wheelEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); - + if (ui->videoWidget->geometry().contains(event->pos())) { + QPoint pos = ui->videoWidget->mapFrom(this, event->pos()); + QWheelEvent wheelEvent(pos, event->globalPosF(), event->pixelDelta(), + event->angleDelta(), event->buttons(), event->modifiers(), + event->phase(), event->inverted(), event->source()); + m_inputConvert.wheelEvent(&wheelEvent, ui->videoWidget->frameSize(), ui->videoWidget->size()); + } } void VideoForm::keyPressEvent(QKeyEvent *event) @@ -198,9 +259,16 @@ void VideoForm::keyReleaseEvent(QKeyEvent *event) m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size()); } +void VideoForm::paintEvent(QPaintEvent *paint) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + void VideoForm::on_fullScrcenbtn_clicked() { - QKeySequence s =ui->fullScrcenbtn->shortcut(); switchFullScreen(); } diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index a17145b..b52f525 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -25,6 +25,7 @@ private: void updateShowSize(const QSize &newSize); void switchFullScreen(); void initStyle(); + void updateStyleSheet(bool vertical); protected: void mousePressEvent(QMouseEvent *event); @@ -34,9 +35,10 @@ protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); + void paintEvent(QPaintEvent *); + private slots: void on_fullScrcenbtn_clicked(); - void on_returnBtn_clicked(); private: @@ -48,6 +50,9 @@ private: //InputConvertNormal m_inputConvert; InputConvertGame m_inputConvert; QString m_serial = ""; + + QPoint m_dragPosition; + float m_widthHeightRatio = 0.5f; }; #endif // VIDEOFORM_H diff --git a/QtScrcpy/videoform.ui b/QtScrcpy/videoform.ui index e4bf7e1..7b3546d 100644 --- a/QtScrcpy/videoform.ui +++ b/QtScrcpy/videoform.ui @@ -6,113 +6,38 @@ 0 0 - 454 - 908 + 400 + 800 + + #videoForm { + border-image: url(:/res/phone-v.png) 150px 142px 85px 142px; + border-width: 150px 142px 85px 142px; +} + 0 - 0 + 10 - 0 + 68 - 0 + 12 - 0 + 62 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - - 0 - - - 0 - - - - - - 40 - 40 - - - - - 40 - 40 - - - - Qt::NoFocus - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 40 - 40 - - - - - 40 - 40 - - - - Qt::NoFocus - - - - - - - - -