From d787c3a9d4bb11d3019fce8bee019c68c3116b03 Mon Sep 17 00:00:00 2001 From: Zhang Xiang Date: Mon, 5 Jul 2021 20:50:26 +0800 Subject: [PATCH 1/2] Modify the input method of bitrate. Bug fix --- QtScrcpy/CMakeLists.txt | 19 ++--- QtScrcpy/device/device.h | 4 +- QtScrcpy/dialog.cpp | 36 +++++---- QtScrcpy/dialog.h | 22 +----- QtScrcpy/dialog.ui | 146 +++++++++++++++++++++++++++---------- QtScrcpy/main.cpp | 11 ++- QtScrcpy/res/i18n/en_US.qm | Bin 4808 -> 4507 bytes QtScrcpy/res/i18n/en_US.ts | 14 ++-- QtScrcpy/res/i18n/zh_CN.qm | Bin 4095 -> 3828 bytes QtScrcpy/res/i18n/zh_CN.ts | 14 ++-- QtScrcpy/util/config.cpp | 8 +- QtScrcpy/util/config.h | 2 +- 12 files changed, 164 insertions(+), 112 deletions(-) diff --git a/QtScrcpy/CMakeLists.txt b/QtScrcpy/CMakeLists.txt index b70a7f882..049cf629c 100755 --- a/QtScrcpy/CMakeLists.txt +++ b/QtScrcpy/CMakeLists.txt @@ -5,19 +5,10 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# *********************************************************** -# Qt Package finding -# *********************************************************** - find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Network LinguistTools REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Network LinguistTools REQUIRED) -# *********************************************************** -# Cross-platform settings -# *********************************************************** - -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - +if(MSVC) # FFmpeg cannot be compiled natively by MSVC version < 12.0 (2013) if(MSVC_VERSION LESS 1800) message(FATAL_ERROR "[QtScrcpy] FATAL ERROR: MSVC version is older than 12.0 (2013).") @@ -25,7 +16,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") - endif() @@ -145,6 +135,7 @@ if(WIN32) endif() set(QS_DLL_PATH "${PROJECT_SOURCE_DIR}/third_party/ffmpeg/bin/x64") + elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) # Compiler is 32-bit message(STATUS "[QtScrcpy] 32-bit compiler detected.") @@ -173,17 +164,17 @@ if(WIN32) ) endforeach() - # If MinGW is used, it is not appropriate to link static MSVC libs. - # Instead, we link DLLs directly if(MSVC) message(STATUS "[QtScrcpy] Microsoft Visual C++ is used.") - link_directories(${QS_LIB_PATH}) + target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${QS_LIB_PATH}) set(QS_EXTERNAL_LIBS_FFMPEG avformat avcodec avutil swscale ) + # If MinGW is used, it is not appropriate to link static MSVC libs. + # Instead, we link DLLs directly elseif(MINGW) message(STATUS "[QtScrcpy] MinGW GCC is used.") target_link_options(${CMAKE_PROJECT_NAME} PRIVATE diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index e07ee7664..33e602c8b 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -1,4 +1,4 @@ -#ifndef DEVICE_H +#ifndef DEVICE_H #define DEVICE_H #include @@ -30,7 +30,7 @@ class Device : public QObject QString serial = ""; // 设备序列号 quint16 localPort = 27183; // reverse时本地监听端口 quint16 maxSize = 720; // 视频分辨率 - quint32 bitRate = 8000000; // 视频比特率 + quint32 bitRate = 2000000; // 视频比特率 quint32 maxFps = 60; // 视频最大帧率 bool closeScreen = false; // 启动时自动息屏 bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 08aa86b5a..e4fc95a10 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -98,6 +98,7 @@ Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) Dialog::~Dialog() { + qDebug() << "~Dialog()"; updateBootConfig(false); m_deviceManage.disconnectAllDevice(); delete ui; @@ -108,14 +109,9 @@ void Dialog::initUI() setAttribute(Qt::WA_DeleteOnClose); setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint); - ui->bitRateBox->addItem("2000000"); - ui->bitRateBox->addItem("6000000"); - ui->bitRateBox->addItem("8000000"); - ui->bitRateBox->addItem("10000000"); - ui->bitRateBox->addItem("20000000"); - ui->bitRateBox->addItem("50000000"); - ui->bitRateBox->addItem("100000000"); - ui->bitRateBox->addItem("200000000"); + setWindowTitle(Config::getInstance().getTitle()); + + ui->bitRateEdit->setValidator(new QIntValidator(1, 99999, this)); ui->maxSizeBox->addItem("640"); ui->maxSizeBox->addItem("720"); @@ -156,7 +152,16 @@ void Dialog::updateBootConfig(bool toView) if (toView) { UserBootConfig config = Config::getInstance().getUserBootConfig(); - ui->bitRateBox->setCurrentIndex(config.bitRateIndex); + if(config.bitRate == 0) { + ui->bitRateBox->setCurrentText("Mbps"); + } else if(config.bitRate % 1000000 == 0) { + ui->bitRateEdit->setText(QString::number(config.bitRate / 1000000)); + ui->bitRateBox->setCurrentText("Mbps"); + } else { + ui->bitRateEdit->setText(QString::number(config.bitRate / 1000)); + ui->bitRateBox->setCurrentText("Kbps"); + } + ui->maxSizeBox->setCurrentIndex(config.maxSizeIndex); ui->formatBox->setCurrentIndex(config.recordFormatIndex); ui->recordPathEdt->setText(config.recordPath); @@ -173,7 +178,7 @@ void Dialog::updateBootConfig(bool toView) } else { UserBootConfig config; - config.bitRateIndex = ui->bitRateBox->currentIndex(); + config.bitRate = getBitRate(); config.maxSizeIndex = ui->maxSizeBox->currentIndex(); config.recordFormatIndex = ui->formatBox->currentIndex(); config.recordPath = ui->recordPathEdt->text(); @@ -187,7 +192,6 @@ void Dialog::updateBootConfig(bool toView) config.framelessWindow = ui->framelessCheck->isChecked(); config.keepAlive = ui->stayAwakeCheck->isChecked(); config.simpleMode = ui->useSingleModeCheck->isChecked(); - Config::getInstance().setUserBootConfig(config); } } @@ -235,7 +239,6 @@ void Dialog::slotActivated(QSystemTrayIcon::ActivationReason reason) switch (reason) { case QSystemTrayIcon::Trigger: this->show(); - m_hideIcon->hide(); break; default: break; @@ -278,13 +281,12 @@ void Dialog::on_startServerBtn_clicked() } } - quint32 bitRate = ui->bitRateBox->currentText().trimmed().toUInt(); // this is ok that "native" toUshort is 0 quint16 videoSize = ui->maxSizeBox->currentText().trimmed().toUShort(); Device::DeviceParams params; params.serial = ui->serialBox->currentText().trimmed(); params.maxSize = videoSize; - params.bitRate = bitRate; + params.bitRate = getBitRate(); // on devices with Android >= 10, the capture frame rate can be limited params.maxFps = static_cast(Config::getInstance().getMaxFps()); params.recordFileName = absFilePath; @@ -621,3 +623,9 @@ void Dialog::on_serialBox_currentIndexChanged(const QString &arg1) { ui->userNameEdt->setText(Config::getInstance().getNickName(arg1)); } + +quint32 Dialog::getBitRate() +{ + return ui->bitRateEdit->text().trimmed().toUInt() * + (ui->bitRateBox->currentText() == QString("Mbps") ? 1000000 : 1000); +} diff --git a/QtScrcpy/dialog.h b/QtScrcpy/dialog.h index b29d123c3..8803e3ef2 100644 --- a/QtScrcpy/dialog.h +++ b/QtScrcpy/dialog.h @@ -32,47 +32,26 @@ class Dialog : public QDialog private slots: void on_updateDevice_clicked(); - void on_startServerBtn_clicked(); - void on_stopServerBtn_clicked(); - void on_wirelessConnectBtn_clicked(); - void on_startAdbdBtn_clicked(); - void on_getIPBtn_clicked(); - void on_wirelessDisConnectBtn_clicked(); - void on_selectRecordPathBtn_clicked(); - void on_recordPathEdt_textChanged(const QString &arg1); - void on_adbCommandBtn_clicked(); - void on_stopAdbBtn_clicked(); - void on_clearOut_clicked(); - void on_stopAllServerBtn_clicked(); - void on_refreshGameScriptBtn_clicked(); - void on_applyScriptBtn_clicked(); - void on_recordScreenCheck_clicked(bool checked); - void on_usbConnectBtn_clicked(); - void on_wifiConnectBtn_clicked(); - void on_connectedPhoneList_itemDoubleClicked(QListWidgetItem *item); - void on_updateNameBtn_clicked(); - void on_useSingleModeCheck_clicked(); - void on_serialBox_currentIndexChanged(const QString &arg1); private: @@ -85,6 +64,7 @@ private slots: void slotShow(); void slotActivated(QSystemTrayIcon::ActivationReason reason); int findDeviceFromeSerialBox(bool wifi); + quint32 getBitRate(); protected: void closeEvent(QCloseEvent *event); diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index 16daf249b..6968d5c21 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -7,7 +7,7 @@ 0 0 500 - 769 + 749 @@ -18,7 +18,7 @@ - 500 + 565 16777215 @@ -133,23 +133,115 @@ + + + 0 + 0 + + + + + 60 + 0 + + + + + 0 + 16777215 + + bit rate: + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 0 + 16777215 + + + + 2 + + + + + + 0 + 0 + + + + + 70 + 0 + + + + + 0 + 16777215 + + - - + Mbps + + + + + + + Mbps + + + + + Kbps + + + + + 0 + 0 + + + + + 70 + 0 + + + + + 0 + 16777215 + + max size: @@ -162,16 +254,6 @@ - - - - record format: - - - - - - @@ -191,27 +273,24 @@ 0 - + - lock orientation: + record format: - + - - - Qt::Horizontal - - - - 40 - 20 - + + + lock orientation: - + + + + @@ -792,19 +871,6 @@ - - - - Qt::Vertical - - - - 20 - 0 - - - - diff --git a/QtScrcpy/main.cpp b/QtScrcpy/main.cpp index 21e9dc289..929580548 100644 --- a/QtScrcpy/main.cpp +++ b/QtScrcpy/main.cpp @@ -12,7 +12,6 @@ #include "stream.h" static Dialog *g_mainDlg = Q_NULLPTR; - static QtMessageHandler g_oldMessageHandler = Q_NULLPTR; void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg); void installTranslator(); @@ -104,8 +103,7 @@ int main(int argc, char *argv[]) file.close(); } - g_mainDlg = new Dialog; - g_mainDlg->setWindowTitle(Config::getInstance().getTitle()); + g_mainDlg = new Dialog {}; g_mainDlg->show(); qInfo() << QObject::tr("This software is completely open source and free. Use it at your own risk. You can download it at the " @@ -113,6 +111,7 @@ int main(int argc, char *argv[]) qInfo() << QString("QtScrcpy %1 ").arg(QCoreApplication::applicationVersion()); int ret = a.exec(); + delete g_mainDlg; #if defined(Q_OS_WIN32) || defined(Q_OS_OSX) MouseTap::getInstance()->quitMouseEventTap(); @@ -173,12 +172,12 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS g_oldMessageHandler(type, context, msg); } - // qt log info big than warning? - float fLogLevel = 1.0f * g_msgType; + // Is Qt log level higher than warning? + float fLogLevel = g_msgType; if (QtInfoMsg == g_msgType) { fLogLevel = QtDebugMsg + 0.5f; } - float fLogLevel2 = 1.0f * type; + float fLogLevel2 = type; if (QtInfoMsg == type) { fLogLevel2 = QtDebugMsg + 0.5f; } diff --git a/QtScrcpy/res/i18n/en_US.qm b/QtScrcpy/res/i18n/en_US.qm index b0be36628bcb5a55c9d03fc0425479fa3e16737b..aeb1d2f7a16183ea1df3d517bfc422377baa274a 100644 GIT binary patch delta 548 zcmWNNe`t(x9LL|!J@-7{d%n-zJ;mh5t)q=U>@;`K{yGl}{@DMS;w zlygI$81ShK4?dvrgxr5nk~e7XY3gAAveoPhyruD^IrMNP1^V_)mVidjpAQ79Enc6^3(YC-wUHvgnr+R?U#H$@CF=9!y|EHk vShaXz9VkQ@FlhCTP%jQy?~h0(Rf-Z+?akFXGRmpH>Z@E*iyJxJ>R0~*xU-0` delta 803 zcmZ9IeMl2=7{|Zo-R*97+ir%Dnyi@yzJQTrW=QjmWJ08vS`^}vb)DD-bHfyKy{y8p zu*8ZC3`LN#B1TeT*$dX9kV*wBqR{e>_D2Pg;2+U5uo3<7yXWq?=ll77e@|~pXkC}Z zp9a2@17h01kL(4ERnYy)0ZeTW@~fy0LWukqH$v!B0qF#if|~(F#io`0fEZ@s*7ko_?UE)=u9sLxE>~NZj!k77@MU45M-uwgPZ&YnDU8>fS;{nMg!*w)Wyuc zOayevG3yIw05+ACXDnni#6FR(QeEJ77ri53h&#IPHUZ4sCHok_9N~ri8KkS@SLKAs z;5DChWsv4feD$p!n%lvj3aoS!9h7sMfuK{#(Osrp@EtF<{Ag>J87`hpx#fQ%lt63=T6fy(hcF^2?{c3__n2tmT<$^QJzaiCynRS z%d~{;#-&eW#8sPC=LLwzn66L70cMM0oxe$ezbjh9Jn@GWZ74CB8vV-Qa5*Iwl+h^y zhjXpTm=+C9Kd`$bg1 z2MylnAXnkjy#I_bEJ@b>9fK8ac<9+gbT3seeL2tqTNDr*0a)E0Ym?J!^?DpFw*P5n rR4%I%mgP~gSh*|;s+>n}HKB&+9=eT2M~#jN%?^)CbE(1S#y9LAbHcYq diff --git a/QtScrcpy/res/i18n/en_US.ts b/QtScrcpy/res/i18n/en_US.ts index c84b13272..432a4c3f3 100644 --- a/QtScrcpy/res/i18n/en_US.ts +++ b/QtScrcpy/res/i18n/en_US.ts @@ -234,27 +234,27 @@ warning Warning - Warning + Warning Quit or set tray? Quit or set tray? - Quit or set tray? + Quit or set tray? Quit Quit - Quit + Quit Set tray Set tray - Set tray + Set tray Cancel Cancel - Cancel + Cancel Notice @@ -266,6 +266,10 @@ Hidden here! Hidden here! + + 2 + + InputConvertGame diff --git a/QtScrcpy/res/i18n/zh_CN.qm b/QtScrcpy/res/i18n/zh_CN.qm index a4c59488f8a70537555d48758b1c1f8355eee349..3f1615160ad1a5e78e70e5a98807f7ea66584b4b 100644 GIT binary patch delta 538 zcmWlVT}V@L7{;Ho^YK4B=gdQ2CT3?rS2-{+EGGk}Nuu5C!mJ=h25B38KqQNz4aP|@YP7qMCQfPhzkbX)tz1IPKueAK89Ed7quI&v=Y&@3DB?qu}$aBx@ z0QYJ6rE!aShjOs-BMsb2&yfe5+pmhwN(#298*2&#>{P36-l1W)+CFuI{bBV=VJ(0& z+S&Xy?q#%rk|yf8hrCj0LW_xJ-*=9;isaLN@}|UO-y?FK7e6X<Tf(e+^gzQ_ z+KlVr>erMT*H`5V+V#7G)kiruR|CZvYe-RORxZP97p>u?53Q8s~DL-)c-`Aj#!o53?gh;$4 zWHH`r_*COG2zb7}rx6=9@*NE~v5Ad;8!-vP8~CqjHsqg#gv2li+XY+95a4aXPc{?= zHYqJJ1(+*Q+J|vLVV|-*cLu_lqAIcr_0yv6>T)lHeu#SW8*DrxS_XTOpBMKY7D4z~ z<*J5r;kl~c_!L6Dst0{3=nt!tY}ts#YRByrz**JRaicKUrS^9W0JmQKF+Lp|n>Do= zaS$5RoOGN+y-zdy3Oa02P>2Z&i~6AUk@zJz=}yTobq$1a$yq!F!OfEM3VsFmP}=X$ z0N|U{Jpux*MS4*S=QQdBsNJ_preh59tS6<%guvOjz+<(S?I warning 警告 - 警告 + 警告 Quit or set tray? 退出还是最小化到托盘? - 退出还是最小化到托盘? + 退出还是最小化到托盘? Quit 退出 - 退出 + 退出 Set tray 最小化到系统托盘 - 最小化到系统托盘 + 最小化到系统托盘 Cancel 取消 - 取消 + 取消 Notice @@ -266,6 +266,10 @@ 安卓录屏程序隐藏在这! 安卓录屏程序隐藏在这! + + 2 + + InputConvertGame diff --git a/QtScrcpy/util/config.cpp b/QtScrcpy/util/config.cpp index e5897ef7d..60f619191 100644 --- a/QtScrcpy/util/config.cpp +++ b/QtScrcpy/util/config.cpp @@ -48,8 +48,8 @@ #define COMMON_RECORD_KEY "RecordPath" #define COMMON_RECORD_DEF "" -#define COMMON_BITRATE_INDEX_KEY "BitRateIndex" -#define COMMON_BITRATE_INDEX_DEF 2 +#define COMMON_BITRATE_KEY "BitRate" +#define COMMON_BITRATE_DEF 2000000 #define COMMON_MAX_SIZE_INDEX_KEY "MaxSizeIndex" #define COMMON_MAX_SIZE_INDEX_DEF 2 @@ -132,7 +132,7 @@ void Config::setUserBootConfig(const UserBootConfig &config) { m_userData->beginGroup(GROUP_COMMON); m_userData->setValue(COMMON_RECORD_KEY, config.recordPath); - m_userData->setValue(COMMON_BITRATE_INDEX_KEY, config.bitRateIndex); + m_userData->setValue(COMMON_BITRATE_KEY, config.bitRate); m_userData->setValue(COMMON_MAX_SIZE_INDEX_KEY, config.maxSizeIndex); m_userData->setValue(COMMON_RECORD_FORMAT_INDEX_KEY, config.recordFormatIndex); m_userData->setValue(COMMON_FRAMELESS_WINDOW_KEY, config.framelessWindow); @@ -154,7 +154,7 @@ UserBootConfig Config::getUserBootConfig() UserBootConfig config; m_userData->beginGroup(GROUP_COMMON); config.recordPath = m_userData->value(COMMON_RECORD_KEY, COMMON_RECORD_DEF).toString(); - config.bitRateIndex = m_userData->value(COMMON_BITRATE_INDEX_KEY, COMMON_BITRATE_INDEX_DEF).toInt(); + config.bitRate = m_userData->value(COMMON_BITRATE_KEY, COMMON_BITRATE_DEF).toUInt(); config.maxSizeIndex = m_userData->value(COMMON_MAX_SIZE_INDEX_KEY, COMMON_MAX_SIZE_INDEX_DEF).toInt(); config.recordFormatIndex = m_userData->value(COMMON_RECORD_FORMAT_INDEX_KEY, COMMON_RECORD_FORMAT_INDEX_DEF).toInt(); config.lockOrientationIndex = m_userData->value(COMMON_LOCK_ORIENTATION_INDEX_KEY, COMMON_LOCK_ORIENTATION_INDEX_DEF).toInt(); diff --git a/QtScrcpy/util/config.h b/QtScrcpy/util/config.h index e978be435..0eeea83cf 100644 --- a/QtScrcpy/util/config.h +++ b/QtScrcpy/util/config.h @@ -8,7 +8,7 @@ struct UserBootConfig { QString recordPath = ""; - int bitRateIndex = 0; + quint32 bitRate = 2000000; int maxSizeIndex = 0; int recordFormatIndex = 0; int lockOrientationIndex = 0; From e0cb232133a2c7383c8e1c1e867dafde3440a3da Mon Sep 17 00:00:00 2001 From: leiyu Date: Sun, 8 Aug 2021 11:23:04 +0800 Subject: [PATCH 2/2] feat: right click map to return --- QtScrcpy/device/ui/videoform.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index e7527686e..adef61298 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -527,6 +527,14 @@ void VideoForm::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::MiddleButton) { if (m_device && !m_device->isCurrentCustomKeymap()) { emit m_device->postGoHome(); + return; + } + } + + if (event->button() == Qt::RightButton) { + if (m_device && !m_device->isCurrentCustomKeymap()) { + emit m_device->postGoBack(); + return; } }