Skip to content

Commit

Permalink
Merge pull request #80 from barry-ran/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
barry-ran authored Feb 15, 2020
2 parents a6f3020 + 5f81089 commit 076deb6
Show file tree
Hide file tree
Showing 36 changed files with 826 additions and 118 deletions.
2 changes: 1 addition & 1 deletion QtScrcpy/QtScrcpy.pro
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ INCLUDEPATH += \

# 统一版本号入口,只修改这一个地方即可
VERSION_MAJOR = 1
VERSION_MINOR = 1
VERSION_MINOR = 2
VERSION_PATCH = 0

# qmake变量的方式定义版本号
Expand Down
5 changes: 5 additions & 0 deletions QtScrcpy/device/decoder/videobuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ const AVFrame *VideoBuffer::consumeRenderedFrame()
return m_renderingframe;
}

const AVFrame *VideoBuffer::peekRenderedFrame()
{
return m_renderingframe;
}

void VideoBuffer::interrupt()
{
if (m_renderExpiredFrames) {
Expand Down
2 changes: 2 additions & 0 deletions QtScrcpy/device/decoder/videobuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class VideoBuffer
// unlocking m_mutex
const AVFrame* consumeRenderedFrame();

const AVFrame* peekRenderedFrame();

// wake up and avoid any blocking call
void interrupt();

Expand Down
15 changes: 8 additions & 7 deletions QtScrcpy/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ void Device::updateScript(QString script)

void Device::onScreenshot()
{
m_screenshot = true;
if (!m_vb) {
return;
}

m_vb->lock();
// screenshot
saveFrame(m_vb->peekRenderedFrame());
m_vb->unLock();
}

void Device::initSignals()
Expand Down Expand Up @@ -201,12 +208,6 @@ void Device::initSignals()
if (m_videoForm) {
m_videoForm->updateRender(frame);
}

// screenshot
if (m_screenshot) {
saveFrame(frame);
m_screenshot = false;
}
m_vb->unLock();
},Qt::QueuedConnection);
}
Expand Down
2 changes: 0 additions & 2 deletions QtScrcpy/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public slots:

QTime m_startTimeCount;
DeviceParams m_params;

bool m_screenshot = false;
};

#endif // DEVICE_H
26 changes: 25 additions & 1 deletion QtScrcpy/device/ui/toolform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "iconhelper.h"
#include "videoform.h"
#include "controller.h"
#include "adbprocess.h"

ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos)
: MagneticWidget(adsorbWidget, adsorbPos)
Expand Down Expand Up @@ -40,7 +41,8 @@ void ToolForm::initStyle()
IconHelper::Instance()->SetIcon(ui->closeScreenBtn, QChar(0xf070), 15);
IconHelper::Instance()->SetIcon(ui->powerBtn, QChar(0xf011), 15);
IconHelper::Instance()->SetIcon(ui->expandNotifyBtn, QChar(0xf103), 15);
IconHelper::Instance()->SetIcon(ui->screenShotBtn, QChar(0xf05b), 15);
IconHelper::Instance()->SetIcon(ui->screenShotBtn, QChar(0xf0c4), 15);
IconHelper::Instance()->SetIcon(ui->touchBtn, QChar(0xf111), 15);
}

void ToolForm::mousePressEvent(QMouseEvent *event)
Expand Down Expand Up @@ -150,3 +152,25 @@ void ToolForm::on_expandNotifyBtn_clicked()
m_videoForm->getController()->expandNotificationPanel();
}
}

void ToolForm::on_touchBtn_clicked()
{
if (!m_videoForm) {
return;
}

m_showTouch = !m_showTouch;

AdbProcess* adb = new AdbProcess();
if (!adb) {
return;
}
connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){
if (AdbProcess::AER_SUCCESS_START != processResult) {
sender()->deleteLater();
}
});
adb->setShowTouchesEnabled(m_videoForm->getSerial(), m_showTouch);

qInfo() << "show touch " << (m_showTouch ? "enable" : "disable");
}
3 changes: 3 additions & 0 deletions QtScrcpy/device/ui/toolform.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ private slots:

void on_expandNotifyBtn_clicked();

void on_touchBtn_clicked();

private:
void initStyle();

private:
Ui::ToolForm *ui;
QPoint m_dragPosition;
QPointer<VideoForm> m_videoForm;
bool m_showTouch = false;
};

#endif // TOOLFORM_H
10 changes: 10 additions & 0 deletions QtScrcpy/device/ui/toolform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="touchBtn">
<property name="toolTip">
<string>touch switch</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeScreenBtn">
<property name="toolTip">
Expand Down
25 changes: 16 additions & 9 deletions QtScrcpy/device/ui/videoform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VideoForm::VideoForm(bool skin, QWidget *parent)
: QWidget(parent)
, ui(new Ui::videoForm)
, m_skin(skin)
{
{
ui->setupUi(this);
initUI();
updateShowSize(size());
Expand All @@ -37,7 +37,7 @@ VideoForm::VideoForm(bool skin, QWidget *parent)
}

VideoForm::~VideoForm()
{
{
delete ui;
}

Expand All @@ -59,9 +59,9 @@ void VideoForm::initUI()
#endif
}

setMouseTracking(true);
setMouseTracking(true);
ui->videoWidget->setMouseTracking(true);
ui->videoWidget->hide();
ui->videoWidget->hide();
}

void VideoForm::onGrabCursor(bool grab)
Expand Down Expand Up @@ -155,7 +155,7 @@ void VideoForm::updateShowSize(const QSize &newSize)
if (isFullScreen()) {
switchFullScreen();
}
if (layout()) {
if (m_skin) {
QMargins m = getMargins(vertical);
showSize.setWidth(showSize.width() + m.left() + m.right());
showSize.setHeight(showSize.height() + m.top() + m.bottom());
Expand All @@ -165,9 +165,11 @@ void VideoForm::updateShowSize(const QSize &newSize)
move(screenRect.center() - QRect(0, 0, showSize.width(), showSize.height()).center());
}

// 减去标题栏高度 (mark:已经没有标题栏了)
//int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
//showSize.setHeight(showSize.height() - titleBarHeight);
if (!m_skin) {
// 减去标题栏高度 (mark:已经没有标题栏了)
int titleBarHeight = style()->pixelMetric(QStyle::PM_TitleBarHeight);
showSize.setHeight(showSize.height() - titleBarHeight);
}

if (showSize != size()) {
#ifdef Q_OS_OSX
Expand Down Expand Up @@ -247,6 +249,11 @@ void VideoForm::setSerial(const QString &serial)
m_serial = serial;
}

const QString &VideoForm::getSerial()
{
return m_serial;
}

void VideoForm::setController(Controller *controller)
{
m_controller = controller;
Expand Down Expand Up @@ -297,7 +304,7 @@ void VideoForm::mouseReleaseEvent(QMouseEvent *event)
}

void VideoForm::mouseMoveEvent(QMouseEvent *event)
{
{
if (ui->videoWidget->geometry().contains(event->pos())) {
if (!m_controller) {
return;
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/device/ui/videoform.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class VideoForm : public QWidget
Controller* getController();
void setFileHandler(FileHandler *fileHandler);
void setSerial(const QString &serial);
const QString& getSerial();

signals:
void screenshot();
Expand Down
16 changes: 16 additions & 0 deletions QtScrcpy/devicemanage/devicemanage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "devicemanage.h"
#include "server.h"
#include "videoform.h"

#define DM_MAX_DEVICES_NUM 16

Expand Down Expand Up @@ -62,6 +63,21 @@ void DeviceManage::updateScript(QString script)
}
}

bool DeviceManage::staysOnTop(const QString &serial)
{
if (!serial.isEmpty() && m_devices.contains(serial)) {
auto it = m_devices.find(serial);
if (!it->data()) {
return false;
}
if (!it->data()->getVideoForm()) {
return false;
}
it->data()->getVideoForm()->staysOnTop();
}
return true;
}

bool DeviceManage::disconnectDevice(const QString &serial)
{
bool ret = false;
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/devicemanage/devicemanage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DeviceManage : public QObject

bool connectDevice(Device::DeviceParams params);
void updateScript(QString script);
bool staysOnTop(const QString &serial);

bool disconnectDevice(const QString &serial);
void disconnectAllDevice();
Expand Down
12 changes: 5 additions & 7 deletions QtScrcpy/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Dialog::initUI()
ui->maxSizeBox->addItem("1080");
ui->maxSizeBox->addItem("1280");
ui->maxSizeBox->addItem("1920");
ui->maxSizeBox->addItem("native");
ui->maxSizeBox->addItem(tr("original"));
ui->maxSizeBox->setCurrentIndex(2);

ui->formatBox->addItem("mp4");
Expand All @@ -106,7 +106,7 @@ void Dialog::execAdbCmd()
}
QString cmd = ui->adbCommandEdt->text().trimmed();
outLog("adb " + cmd, false);
m_adb.execute("", cmd.split(" ", QString::SkipEmptyParts));
m_adb.execute(ui->serialBox->currentText().trimmed(), cmd.split(" ", QString::SkipEmptyParts));
}

QString Dialog::getGameScript(const QString& fileName)
Expand Down Expand Up @@ -166,11 +166,9 @@ void Dialog::on_startServerBtn_clicked()

m_deviceManage.connectDevice(params);

/*
if (ui->alwaysTopCheck->isChecked() && m_device->getVideoForm()) {
m_device->getVideoForm()->staysOnTop();
}
*/
if (ui->alwaysTopCheck->isChecked()) {
m_deviceManage.staysOnTop(params.serial);
}
}

void Dialog::on_stopServerBtn_clicked()
Expand Down
Binary file modified QtScrcpy/res/i18n/QtScrcpy_en.qm
Binary file not shown.
Loading

0 comments on commit 076deb6

Please sign in to comment.