工具栏基本功能

This commit is contained in:
Barry 2019-01-26 15:46:51 +08:00
commit adc0641893
9 changed files with 291 additions and 31 deletions

View file

@ -6,10 +6,22 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>564</width> <width>560</width>
<height>486</height> <height>486</height>
</rect> </rect>
</property> </property>
<property name="minimumSize">
<size>
<width>560</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>560</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>QtScrcpy</string> <string>QtScrcpy</string>
</property> </property>

View file

@ -9,6 +9,7 @@
#include "input.h" #include "input.h"
#include "keycodes.h" #include "keycodes.h"
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
// ControlEvent // ControlEvent
class ControlEvent : public QScrcpyEvent class ControlEvent : public QScrcpyEvent
{ {

View file

@ -21,7 +21,6 @@ public:
virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize) = 0; virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize) = 0;
void setDeviceSocket(DeviceSocket* deviceSocket); void setDeviceSocket(DeviceSocket* deviceSocket);
protected:
void sendControlEvent(ControlEvent* event); void sendControlEvent(ControlEvent* event);
private: private:

View file

@ -2,6 +2,8 @@
#include "toolform.h" #include "toolform.h"
#include "ui_toolform.h" #include "ui_toolform.h"
#include "iconhelper.h"
#include "videoform.h"
ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos) ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos)
: MagneticWidget(adsorbWidget, adsorbPos) : MagneticWidget(adsorbWidget, adsorbPos)
@ -10,6 +12,10 @@ ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos)
ui->setupUi(this); ui->setupUi(this);
//setWindowFlags(windowFlags() | Qt::FramelessWindowHint); //setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
setWindowFlags(windowFlags() & ~Qt::WindowMinMaxButtonsHint); setWindowFlags(windowFlags() & ~Qt::WindowMinMaxButtonsHint);
m_videoForm = dynamic_cast<VideoForm*>(adsorbWidget);
initStyle();
} }
ToolForm::~ToolForm() ToolForm::~ToolForm()
@ -17,6 +23,20 @@ ToolForm::~ToolForm()
delete ui; delete ui;
} }
void ToolForm::initStyle()
{
IconHelper::Instance()->SetIcon(ui->fullScreenBtn, QChar(0xf0b2), 15);
IconHelper::Instance()->SetIcon(ui->menuBtn, QChar(0xf096), 15);
IconHelper::Instance()->SetIcon(ui->homeBtn, QChar(0xf1db), 15);
//IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15);
IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf053), 15);
IconHelper::Instance()->SetIcon(ui->appSwitchBtn, QChar(0xf24d), 15);
IconHelper::Instance()->SetIcon(ui->powerBtn, QChar(0xf023), 15);
IconHelper::Instance()->SetIcon(ui->volumeUpBtn, QChar(0xf028), 15);
IconHelper::Instance()->SetIcon(ui->volumeDownBtn, QChar(0xf027), 15);
IconHelper::Instance()->SetIcon(ui->turnOnBtn, QChar(0xf09c), 15);
}
void ToolForm::mousePressEvent(QMouseEvent *event) void ToolForm::mousePressEvent(QMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
@ -37,3 +57,66 @@ void ToolForm::mouseMoveEvent(QMouseEvent *event)
event->accept(); event->accept();
} }
} }
void ToolForm::on_fullScreenBtn_clicked()
{
if (m_videoForm) {
m_videoForm->switchFullScreen();
}
}
void ToolForm::on_returnBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postGoBack();
}
}
void ToolForm::on_homeBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postGoHome();
}
}
void ToolForm::on_menuBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postGoMenu();
}
}
void ToolForm::on_appSwitchBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postAppSwitch();
}
}
void ToolForm::on_powerBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postPower();
}
}
void ToolForm::on_volumeUpBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postVolumeUp();
}
}
void ToolForm::on_volumeDownBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postVolumeDown();
}
}
void ToolForm::on_turnOnBtn_clicked()
{
if (m_videoForm) {
m_videoForm->postTurnOn();
}
}

View file

@ -2,6 +2,7 @@
#define TOOLFORM_H #define TOOLFORM_H
#include <QWidget> #include <QWidget>
#include <QPointer>
#include "magneticwidget.h" #include "magneticwidget.h"
@ -9,6 +10,7 @@ namespace Ui {
class ToolForm; class ToolForm;
} }
class VideoForm;
class ToolForm : public MagneticWidget class ToolForm : public MagneticWidget
{ {
Q_OBJECT Q_OBJECT
@ -22,9 +24,32 @@ protected:
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
private slots:
void on_fullScreenBtn_clicked();
void on_returnBtn_clicked();
void on_homeBtn_clicked();
void on_menuBtn_clicked();
void on_appSwitchBtn_clicked();
void on_powerBtn_clicked();
void on_volumeUpBtn_clicked();
void on_volumeDownBtn_clicked();
void on_turnOnBtn_clicked();
private:
void initStyle();
private: private:
Ui::ToolForm *ui; Ui::ToolForm *ui;
QPoint m_dragPosition; QPoint m_dragPosition;
QPointer<VideoForm> m_videoForm;
}; };
#endif // TOOLFORM_H #endif // TOOLFORM_H

View file

@ -6,13 +6,91 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>80</width> <width>63</width>
<height>497</height> <height>497</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string>Tool</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="fullScreenBtn">
<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>
<widget class="QPushButton" name="powerBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="turnOnBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="volumeUpBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="volumeDownBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="appSwitchBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="menuBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="homeBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="returnBtn">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -13,6 +13,7 @@
#include "ui_videoform.h" #include "ui_videoform.h"
#include "iconhelper.h" #include "iconhelper.h"
#include "toolform.h" #include "toolform.h"
#include "controlevent.h"
VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWidget *parent) : VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWidget *parent) :
QWidget(parent), QWidget(parent),
@ -101,7 +102,6 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi
}); });
updateShowSize(size()); updateShowSize(size());
initStyle();
bool vertical = size().height() > size().width(); bool vertical = size().height() > size().width();
updateStyleSheet(vertical); updateStyleSheet(vertical);
@ -149,12 +149,6 @@ void VideoForm::showToolFrom(bool show)
m_toolForm->setVisible(show); m_toolForm->setVisible(show);
} }
void VideoForm::initStyle()
{
//IconHelper::Instance()->SetIcon(ui->fullScrcenbtn, QChar(0xf0b2), 13);
//IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15);
}
void VideoForm::updateStyleSheet(bool vertical) void VideoForm::updateStyleSheet(bool vertical)
{ {
if (vertical) { if (vertical) {
@ -216,13 +210,77 @@ void VideoForm::switchFullScreen()
{ {
if (isFullScreen()) { if (isFullScreen()) {
showNormal(); showNormal();
updateStyleSheet(height() > width());
showToolFrom(true); showToolFrom(true);
} else { } else {
showToolFrom(false); showToolFrom(false);
layout()->setContentsMargins(0, 0, 0, 0);
showFullScreen(); showFullScreen();
} }
} }
void VideoForm::postGoMenu()
{
postKeyCodeClick(AKEYCODE_MENU);
}
void VideoForm::postGoBack()
{
postKeyCodeClick(AKEYCODE_BACK);
}
void VideoForm::postAppSwitch()
{
postKeyCodeClick(AKEYCODE_APP_SWITCH);
}
void VideoForm::postPower()
{
postKeyCodeClick(AKEYCODE_POWER);
}
void VideoForm::postVolumeUp()
{
postKeyCodeClick(AKEYCODE_VOLUME_UP);
}
void VideoForm::postVolumeDown()
{
postKeyCodeClick(AKEYCODE_VOLUME_DOWN);
}
void VideoForm::postTurnOn()
{
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_COMMAND);
if (!controlEvent) {
return;
}
controlEvent->setCommandEventData(CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON);
m_inputConvert.sendControlEvent(controlEvent);
}
void VideoForm::postGoHome()
{
postKeyCodeClick(AKEYCODE_HOME);
}
void VideoForm::postKeyCodeClick(AndroidKeycode keycode)
{
ControlEvent* controlEventDown = new ControlEvent(ControlEvent::CET_KEYCODE);
if (!controlEventDown) {
return;
}
controlEventDown->setKeycodeEventData(AKEY_EVENT_ACTION_DOWN, keycode, AMETA_NONE);
m_inputConvert.sendControlEvent(controlEventDown);
ControlEvent* controlEventUp = new ControlEvent(ControlEvent::CET_KEYCODE);
if (!controlEventUp) {
return;
}
controlEventUp->setKeycodeEventData(AKEY_EVENT_ACTION_UP, keycode, AMETA_NONE);
m_inputConvert.sendControlEvent(controlEventUp);
}
void VideoForm::mousePressEvent(QMouseEvent *event) void VideoForm::mousePressEvent(QMouseEvent *event)
{ {
if (ui->videoWidget->geometry().contains(event->pos())) { if (ui->videoWidget->geometry().contains(event->pos())) {
@ -301,13 +359,3 @@ void VideoForm::showEvent(QShowEvent *event)
{ {
showToolFrom(); showToolFrom();
} }
void VideoForm::on_fullScrcenbtn_clicked()
{
switchFullScreen();
}
void VideoForm::on_returnBtn_clicked()
{
}

View file

@ -23,13 +23,23 @@ public:
explicit VideoForm(const QString& serial, quint16 maxSize = 720, quint32 bitRate = 8000000, QWidget *parent = 0); explicit VideoForm(const QString& serial, quint16 maxSize = 720, quint32 bitRate = 8000000, QWidget *parent = 0);
~VideoForm(); ~VideoForm();
void switchFullScreen();
void postGoMenu();
void postGoHome();
void postGoBack();
void postAppSwitch();
void postPower();
void postVolumeUp();
void postVolumeDown();
// turn the screen on if it was off, press BACK otherwise
void postTurnOn();
private: private:
void updateShowSize(const QSize &newSize); void updateShowSize(const QSize &newSize);
void switchFullScreen();
void initStyle();
void updateStyleSheet(bool vertical); void updateStyleSheet(bool vertical);
void initUI(); void initUI();
void showToolFrom(bool show = true); void showToolFrom(bool show = true);
void postKeyCodeClick(AndroidKeycode keycode);
protected: protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
@ -42,10 +52,6 @@ protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
private slots:
void on_fullScrcenbtn_clicked();
void on_returnBtn_clicked();
private: private:
Ui::videoForm *ui; Ui::videoForm *ui;
QSize frameSize; QSize frameSize;

View file

@ -1,2 +1,10 @@
手机窗口启动动画
工具窗口 模拟点击改用手指
中英文翻译
tool tips
工具栏基本功能
server移除
mp4录制
工具栏扩展(模拟点击指定次数等)
中文输入