Skip to content

Commit

Permalink
feat: Option to show/hide the toolbar when connecting a device. (#1042)
Browse files Browse the repository at this point in the history
* Option to show/hide the toolbar when connecting a device.

* Modify the code as required.
  • Loading branch information
fanxing782 authored Dec 6, 2024
1 parent 076f9ba commit 5354ae0
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 37 deletions.
Binary file modified QtScrcpy/res/i18n/en_US.qm
Binary file not shown.
12 changes: 8 additions & 4 deletions QtScrcpy/res/i18n/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@
<source>Start Config</source>
<translation>Start Config</translation>
</message>
<message>
<source>record save path:</source>
<translation>record save path:</translation>
</message>
<message>
<source>select path</source>
<translation>select path</translation>
Expand Down Expand Up @@ -297,5 +293,13 @@
<source>auto update</source>
<translation>auto update</translation>
</message>
<message>
<source>show toolbar</source>
<translation>show toolbar</translation>
</message>
<message>
<source>record save path:</source>
<translation>record save path:</translation>
</message>
</context>
</TS>
Binary file modified QtScrcpy/res/i18n/zh_CN.qm
Binary file not shown.
12 changes: 8 additions & 4 deletions QtScrcpy/res/i18n/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@
<source>Start Config</source>
<translation>启动配置</translation>
</message>
<message>
<source>record save path:</source>
<translation>录像保存路径:</translation>
</message>
<message>
<source>select path</source>
<translation>选择路径</translation>
Expand Down Expand Up @@ -297,5 +293,13 @@
<source>auto update</source>
<translation>自动刷新</translation>
</message>
<message>
<source>show toolbar</source>
<translation>显示工具栏</translation>
</message>
<message>
<source>record save path:</source>
<translation>录像保存路径</translation>
</message>
</context>
</TS>
8 changes: 6 additions & 2 deletions QtScrcpy/ui/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void Dialog::updateBootConfig(bool toView)
ui->stayAwakeCheck->setChecked(config.keepAlive);
ui->useSingleModeCheck->setChecked(config.simpleMode);
ui->autoUpdatecheckBox->setChecked(config.autoUpdateDevice);
ui->showToolbar->setChecked(config.showToolbar);
} else {
UserBootConfig config;

Expand All @@ -213,6 +214,8 @@ void Dialog::updateBootConfig(bool toView)
config.keepAlive = ui->stayAwakeCheck->isChecked();
config.simpleMode = ui->useSingleModeCheck->isChecked();
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
config.showToolbar = ui->showToolbar->isChecked();

Config::getInstance().setUserBootConfig(config);
}
}
Expand Down Expand Up @@ -447,14 +450,15 @@ void Dialog::onDeviceConnected(bool success, const QString &serial, const QStrin
if (!success) {
return;
}

auto videoForm = new VideoForm(ui->framelessCheck->isChecked(), Config::getInstance().getSkin());
auto videoForm = new VideoForm(ui->framelessCheck->isChecked(), Config::getInstance().getSkin(), ui->showToolbar->isChecked());
videoForm->setSerial(serial);

qsc::IDeviceManage::getInstance().getDevice(serial)->setUserData(static_cast<void*>(videoForm));
qsc::IDeviceManage::getInstance().getDevice(serial)->registerDeviceObserver(videoForm);


videoForm->showFPS(ui->fpsCheck->isChecked());

if (ui->alwaysTopCheck->isChecked()) {
videoForm->staysOnTop();
}
Expand Down
49 changes: 28 additions & 21 deletions QtScrcpy/ui/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1293</width>
<height>454</height>
<height>502</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -255,7 +255,7 @@
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
<enum>Qt::FocusPolicy::ClickFocus</enum>
</property>
<property name="documentTitle">
<string/>
Expand Down Expand Up @@ -626,29 +626,32 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="1">
<widget class="QCheckBox" name="closeScreenCheck">
<item row="0" column="4">
<widget class="QCheckBox" name="fpsCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>screen-off</string>
<string>show fps</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QCheckBox" name="framelessCheck">
<item row="0" column="1">
<widget class="QCheckBox" name="notDisplayCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>frameless</string>
<string>background record</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
Expand All @@ -668,19 +671,16 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="notDisplayCheck">
<item row="0" column="0">
<widget class="QCheckBox" name="recordScreenCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>background record</string>
</property>
<property name="checkable">
<bool>false</bool>
<string>record screen</string>
</property>
</widget>
</item>
Expand All @@ -700,29 +700,29 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="recordScreenCheck">
<item row="1" column="1">
<widget class="QCheckBox" name="closeScreenCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>record screen</string>
<string>screen-off</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QCheckBox" name="fpsCheck">
<item row="1" column="3">
<widget class="QCheckBox" name="framelessCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>show fps</string>
<string>frameless</string>
</property>
</widget>
</item>
Expand All @@ -739,6 +739,13 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="showToolbar">
<property name="text">
<string>show toolbar</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1146,7 +1153,7 @@
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down
9 changes: 5 additions & 4 deletions QtScrcpy/ui/videoform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
#include "ui_videoform.h"
#include "videoform.h"

VideoForm::VideoForm(bool framelessWindow, bool skin, QWidget *parent) : QWidget(parent), ui(new Ui::videoForm), m_skin(skin)
VideoForm::VideoForm(bool framelessWindow, bool skin, bool showToolbar, QWidget *parent) : QWidget(parent), ui(new Ui::videoForm), m_skin(skin)
{
ui->setupUi(this);
initUI();
installShortcut();
updateShowSize(size());
bool vertical = size().height() > size().width();
this->show_toolbar = showToolbar;
if (m_skin) {
updateStyleSheet(vertical);
}
Expand Down Expand Up @@ -479,7 +480,7 @@ void VideoForm::switchFullScreen()
if (m_skin) {
updateStyleSheet(m_frameSize.height() > m_frameSize.width());
}
showToolForm(true);
showToolForm(this->show_toolbar);
#ifdef Q_OS_WIN32
::SetThreadExecutionState(ES_CONTINUOUS);
#endif
Expand Down Expand Up @@ -721,9 +722,9 @@ void VideoForm::paintEvent(QPaintEvent *paint)
void VideoForm::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
if (!isFullScreen()) {
if (!isFullScreen() && this->show_toolbar) {
QTimer::singleShot(500, this, [this](){
showToolForm();
showToolForm(this->show_toolbar);
});
}
}
Expand Down
6 changes: 4 additions & 2 deletions QtScrcpy/ui/videoform.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class VideoForm : public QWidget, public qsc::DeviceObserver
{
Q_OBJECT
public:
explicit VideoForm(bool framelessWindow = false, bool skin = true, QWidget *parent = 0);
explicit VideoForm(bool framelessWindow = false, bool skin = true, bool showToolBar = true, QWidget *parent = 0);
~VideoForm();

void staysOnTop(bool top = true);
Expand All @@ -32,7 +32,6 @@ class VideoForm : public QWidget, public qsc::DeviceObserver
void removeBlackRect();
void showFPS(bool show);
void switchFullScreen();

bool isHost();

private:
Expand Down Expand Up @@ -85,6 +84,9 @@ class VideoForm : public QWidget, public qsc::DeviceObserver
bool m_skin = true;
QPoint m_fullScreenBeforePos;
QString m_serial;

//Whether to display the toolbar when connecting a device.
bool show_toolbar = true;
};

#endif // VIDEOFORM_H
5 changes: 5 additions & 0 deletions QtScrcpy/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
#define COMMON_TRAY_MESSAGE_SHOWN_KEY "TrayMessageShown"
#define COMMON_TRAY_MESSAGE_SHOWN_DEF false

#define COMMON_SHOW_TOOLBAR_KEY "showToolbar"
#define COMMON_SHOW_TOOLBAR_DEF true

// device config
#define SERIAL_WINDOW_RECT_KEY_X "WindowRectX"
#define SERIAL_WINDOW_RECT_KEY_Y "WindowRectY"
Expand Down Expand Up @@ -163,6 +166,7 @@ void Config::setUserBootConfig(const UserBootConfig &config)
m_userData->setValue(COMMON_KEEP_ALIVE_KEY, config.keepAlive);
m_userData->setValue(COMMON_SIMPLE_MODE_KEY, config.simpleMode);
m_userData->setValue(COMMON_AUTO_UPDATE_DEVICE_KEY, config.autoUpdateDevice);
m_userData->setValue(COMMON_SHOW_TOOLBAR_KEY, config.showToolbar);
m_userData->endGroup();
m_userData->sync();
}
Expand All @@ -186,6 +190,7 @@ UserBootConfig Config::getUserBootConfig()
config.keepAlive = m_userData->value(COMMON_KEEP_ALIVE_KEY, COMMON_KEEP_ALIVE_DEF).toBool();
config.simpleMode = m_userData->value(COMMON_SIMPLE_MODE_KEY, COMMON_SIMPLE_MODE_DEF).toBool();
config.autoUpdateDevice = m_userData->value(COMMON_AUTO_UPDATE_DEVICE_KEY, COMMON_AUTO_UPDATE_DEVICE_DEF).toBool();
config.showToolbar =m_userData->value(COMMON_SHOW_TOOLBAR_KEY,COMMON_SHOW_TOOLBAR_DEF).toBool();
m_userData->endGroup();
return config;
}
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct UserBootConfig
bool keepAlive = false;
bool simpleMode = false;
bool autoUpdateDevice = true;
bool showToolbar = true;
};

class QSettings;
Expand Down

0 comments on commit 5354ae0

Please sign in to comment.