mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
美化手机窗口界面
This commit is contained in:
parent
a6fc4e5200
commit
04d29f2e9c
7 changed files with 108 additions and 106 deletions
|
@ -142,3 +142,5 @@ linux {
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
res.qrc
|
res.qrc
|
||||||
|
|
||||||
|
DISTFILES +=
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,7 @@
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>res/psblack.css</file>
|
<file>res/psblack.css</file>
|
||||||
<file>res/fontawesome-webfont.ttf</file>
|
<file>res/fontawesome-webfont.ttf</file>
|
||||||
|
<file>res/phone-h.png</file>
|
||||||
|
<file>res/phone-v.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
BIN
QtScrcpy/res/phone-h.png
Normal file
BIN
QtScrcpy/res/phone-h.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 301 KiB |
BIN
QtScrcpy/res/phone-v.png
Normal file
BIN
QtScrcpy/res/phone-v.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 293 KiB |
|
@ -1,6 +1,9 @@
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QPainter>
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,6 +20,16 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) :
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
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);
|
setMouseTracking(true);
|
||||||
ui->videoWidget->setMouseTracking(true);
|
ui->videoWidget->setMouseTracking(true);
|
||||||
|
|
||||||
|
@ -98,6 +111,9 @@ VideoForm::VideoForm(const QString& serial, QWidget *parent) :
|
||||||
|
|
||||||
updateShowSize(size());
|
updateShowSize(size());
|
||||||
initStyle();
|
initStyle();
|
||||||
|
|
||||||
|
bool vertical = size().height() > size().width();
|
||||||
|
updateStyleSheet(vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoForm::~VideoForm()
|
VideoForm::~VideoForm()
|
||||||
|
@ -111,8 +127,29 @@ VideoForm::~VideoForm()
|
||||||
|
|
||||||
void VideoForm::initStyle()
|
void VideoForm::initStyle()
|
||||||
{
|
{
|
||||||
IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13);
|
//IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13);
|
||||||
IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15);
|
//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)
|
void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
|
@ -126,11 +163,11 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
if (desktop) {
|
if (desktop) {
|
||||||
QRect screenRect = desktop->availableGeometry();
|
QRect screenRect = desktop->availableGeometry();
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
showSize.setHeight(qMin(newSize.height(), screenRect.height()));
|
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
|
||||||
showSize.setWidth(showSize.height()/2);
|
showSize.setWidth(showSize.height() * m_widthHeightRatio);
|
||||||
} else {
|
} else {
|
||||||
showSize.setWidth(qMin(newSize.width(), screenRect.width()));
|
showSize.setWidth(qMin(newSize.width(), screenRect.width()));
|
||||||
showSize.setHeight(showSize.width()/2);
|
showSize.setHeight(showSize.width() * m_widthHeightRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
|
@ -140,11 +177,13 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
|
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
|
||||||
}
|
}
|
||||||
|
|
||||||
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
// 减去标题栏高度 (mark:已经没有标题栏了)
|
||||||
// 减去标题栏高度
|
//int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
|
||||||
showSize.setHeight(showSize.height() - titleBarHeight);
|
//showSize.setHeight(showSize.height() - titleBarHeight);
|
||||||
|
|
||||||
if (showSize != size()) {
|
if (showSize != size()) {
|
||||||
resize(showSize);
|
resize(showSize);
|
||||||
|
updateStyleSheet(vertical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,32 +192,54 @@ void VideoForm::switchFullScreen()
|
||||||
{
|
{
|
||||||
if (isFullScreen()) {
|
if (isFullScreen()) {
|
||||||
showNormal();
|
showNormal();
|
||||||
ui->rightToolWidget->show();
|
|
||||||
} else {
|
} else {
|
||||||
ui->rightToolWidget->hide();
|
|
||||||
showFullScreen();
|
showFullScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::mousePressEvent(QMouseEvent *event)
|
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)
|
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)
|
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)
|
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)
|
void VideoForm::keyPressEvent(QKeyEvent *event)
|
||||||
|
@ -198,9 +259,16 @@ void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
||||||
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), ui->videoWidget->size());
|
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()
|
void VideoForm::on_fullScrcenbtn_clicked()
|
||||||
{
|
{
|
||||||
QKeySequence s =ui->fullScrcenbtn->shortcut();
|
|
||||||
switchFullScreen();
|
switchFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ private:
|
||||||
void updateShowSize(const QSize &newSize);
|
void updateShowSize(const QSize &newSize);
|
||||||
void switchFullScreen();
|
void switchFullScreen();
|
||||||
void initStyle();
|
void initStyle();
|
||||||
|
void updateStyleSheet(bool vertical);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
@ -34,9 +35,10 @@ protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void keyReleaseEvent(QKeyEvent *event);
|
void keyReleaseEvent(QKeyEvent *event);
|
||||||
|
|
||||||
|
void paintEvent(QPaintEvent *);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_fullScrcenbtn_clicked();
|
void on_fullScrcenbtn_clicked();
|
||||||
|
|
||||||
void on_returnBtn_clicked();
|
void on_returnBtn_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,6 +50,9 @@ private:
|
||||||
//InputConvertNormal m_inputConvert;
|
//InputConvertNormal m_inputConvert;
|
||||||
InputConvertGame m_inputConvert;
|
InputConvertGame m_inputConvert;
|
||||||
QString m_serial = "";
|
QString m_serial = "";
|
||||||
|
|
||||||
|
QPoint m_dragPosition;
|
||||||
|
float m_widthHeightRatio = 0.5f;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VIDEOFORM_H
|
#endif // VIDEOFORM_H
|
||||||
|
|
|
@ -6,113 +6,38 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>454</width>
|
<width>400</width>
|
||||||
<height>908</height>
|
<height>800</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">#videoForm {
|
||||||
|
border-image: url(:/res/phone-v.png) 150px 142px 85px 142px;
|
||||||
|
border-width: 150px 142px 85px 142px;
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>10</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>68</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>12</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>62</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QYUVOpenGLWidget" name="videoWidget" native="true"/>
|
<widget class="QYUVOpenGLWidget" name="videoWidget" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QWidget" name="rightToolWidget" native="true">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>60</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>60</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item alignment="Qt::AlignHCenter">
|
|
||||||
<widget class="QPushButton" name="fullScrcenbtn">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="focusPolicy">
|
|
||||||
<enum>Qt::NoFocus</enum>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item alignment="Qt::AlignHCenter">
|
|
||||||
<widget class="QPushButton" name="returnBtn">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="focusPolicy">
|
|
||||||
<enum>Qt::NoFocus</enum>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue