feat: add shortcut

This commit is contained in:
rankun 2020-03-16 10:59:58 +08:00
parent 4f013e58b5
commit 9bcfed92db
9 changed files with 273 additions and 25 deletions

View file

@ -62,7 +62,7 @@ void Controller::updateScript(QString gameScript)
connect(m_inputConvert, &InputConvertBase::grabCursor, this, &Controller::grabCursor);
}
void Controller::onPostTurnOn()
void Controller::onPostBackOrScreenOn()
{
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON);
if (!controlMsg) {

View file

@ -40,7 +40,7 @@ public slots:
void onKeyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize);
// turn the screen on if it was off, press BACK otherwise
void onPostTurnOn();
void onPostBackOrScreenOn();
void onRequestDeviceClipboard();
void onSetDeviceClipboard();
void onClipboardPaste();

View file

@ -155,11 +155,12 @@ void Device::initSignals()
connect(this, &Device::postVolumeDown, m_controller, &Controller::onPostVolumeDown);
connect(this, &Device::setScreenPowerMode, m_controller, &Controller::onSetScreenPowerMode);
connect(this, &Device::expandNotificationPanel, m_controller, &Controller::onExpandNotificationPanel);
connect(this, &Device::collapseNotificationPanel, m_controller, &Controller::onCollapseNotificationPanel);
connect(this, &Device::mouseEvent, m_controller, &Controller::onMouseEvent);
connect(this, &Device::wheelEvent, m_controller, &Controller::onWheelEvent);
connect(this, &Device::keyEvent, m_controller, &Controller::onKeyEvent);
connect(this, &Device::postTurnOn, m_controller, &Controller::onPostTurnOn);
connect(this, &Device::postBackOrScreenOn, m_controller, &Controller::onPostBackOrScreenOn);
connect(this, &Device::requestDeviceClipboard, m_controller, &Controller::onRequestDeviceClipboard);
connect(this, &Device::setDeviceClipboard, m_controller, &Controller::onSetDeviceClipboard);
connect(this, &Device::clipboardPaste, m_controller, &Controller::onClipboardPaste);

View file

@ -65,7 +65,8 @@ signals:
void postVolumeDown();
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
void expandNotificationPanel();
void postTurnOn();
void collapseNotificationPanel();
void postBackOrScreenOn();
void postTextInput(QString& text);
void requestDeviceClipboard();
void setDeviceClipboard();

View file

@ -8,6 +8,9 @@
#include <QMimeData>
#include <QFileInfo>
#include <QMessageBox>
#include <QShortcut>
#include <QWindow>
#include <QScreen>
#include "videoform.h"
#include "qyuvopenglwidget.h"
@ -29,6 +32,7 @@ VideoForm::VideoForm(bool skin, QWidget *parent)
{
ui->setupUi(this);
initUI();
installShortcut();
updateShowSize(size());
bool vertical = size().height() > size().width();
if (m_skin) {
@ -97,6 +101,21 @@ const QSize &VideoForm::frameSize()
return m_frameSize;
}
void VideoForm::resizeSquare()
{
QRect screenRect = getScreenRect();
if (screenRect.isEmpty()) {
qWarning() << "getScreenRect is empty";
return;
}
resize(screenRect.height(), screenRect.height());
}
void VideoForm::removeBlackRect()
{
resize(ui->keepRadioWidget->goodSize());
}
void VideoForm::updateRender(const AVFrame *frame)
{
if (m_videoWidget->isHidden()) {
@ -124,16 +143,178 @@ void VideoForm::showToolForm(bool show)
void VideoForm::moveCenter()
{
QDesktopWidget* desktop = QApplication::desktop();
if (!desktop) {
qWarning() << "QApplication::desktop() is nullptr";
QRect screenRect = getScreenRect();
if (screenRect.isEmpty()) {
qWarning() << "getScreenRect is empty";
return;
}
QRect screenRect = desktop->availableGeometry();
// 窗口居中
move(screenRect.center() - QRect(0, 0, size().width(), size().height()).center());
}
void VideoForm::installShortcut()
{
QShortcut *shortcut = nullptr;
// switchFullScreen
shortcut = new QShortcut(QKeySequence("Ctrl+f"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->switchFullScreen();
});
// resizeSquare
shortcut = new QShortcut(QKeySequence("Ctrl+g"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
resizeSquare();
});
// removeBlackRect
shortcut = new QShortcut(QKeySequence("Ctrl+x"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
removeBlackRect();
});
// postGoHome
shortcut = new QShortcut(QKeySequence("Ctrl+h"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postGoHome();
});
// postGoBack
shortcut = new QShortcut(QKeySequence("Ctrl+b"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postGoBack();
});
// postAppSwitch
shortcut = new QShortcut(QKeySequence("Ctrl+s"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postAppSwitch();
});
// postGoMenu
shortcut = new QShortcut(QKeySequence("Ctrl+m"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postGoMenu();
});
// postVolumeUp
shortcut = new QShortcut(QKeySequence("Ctrl+up"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postVolumeUp();
});
// postVolumeDown
shortcut = new QShortcut(QKeySequence("Ctrl+down"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postVolumeDown();
});
// postPower
shortcut = new QShortcut(QKeySequence("Ctrl+p"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->postPower();
});
// setScreenPowerMode(ControlMsg::SPM_OFF)
shortcut = new QShortcut(QKeySequence("Ctrl+o"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->setScreenPowerMode(ControlMsg::SPM_OFF);
});
// expandNotificationPanel
shortcut = new QShortcut(QKeySequence("Ctrl+n"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->expandNotificationPanel();
});
// collapseNotificationPanel
shortcut = new QShortcut(QKeySequence("Ctrl+Shift+n"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->collapseNotificationPanel();
});
// requestDeviceClipboard
shortcut = new QShortcut(QKeySequence("Ctrl+c"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->requestDeviceClipboard();
});
// clipboardPaste
shortcut = new QShortcut(QKeySequence("Ctrl+v"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->clipboardPaste();
});
// setDeviceClipboard
shortcut = new QShortcut(QKeySequence("Ctrl+Shift+v"), this);
connect(shortcut, &QShortcut::activated, this, [this](){
if (!m_device) {
return;
}
emit m_device->setDeviceClipboard();
});
}
QRect VideoForm::getScreenRect()
{
QRect screenRect;
QWidget *win = window();
if (!win) {
return screenRect;
}
QWindow *winHandle = win->windowHandle();
if (!winHandle) {
return screenRect;
}
QScreen *screen = winHandle->screen();
if (!screen) {
return screenRect;
}
screenRect = screen->availableGeometry();
return screenRect;
}
void VideoForm::updateStyleSheet(bool vertical)
{
if (vertical) {
@ -175,12 +356,11 @@ void VideoForm::updateShowSize(const QSize &newSize)
bool vertical = m_widthHeightRatio < 1.0f ? true : false;
QSize showSize = newSize;
QDesktopWidget* desktop = QApplication::desktop();
if (!desktop) {
qWarning() << "QApplication::desktop() is nullptr";
QRect screenRect = getScreenRect();
if (screenRect.isEmpty()) {
qWarning() << "getScreenRect is empty";
return;
}
QRect screenRect = desktop->availableGeometry();
if (vertical) {
showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200));
showSize.setWidth(showSize.height() * m_widthHeightRatio);
@ -278,6 +458,12 @@ void VideoForm::setDevice(Device *device)
void VideoForm::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MiddleButton) {
if (m_device) {
emit m_device->postGoHome();
}
}
if (m_videoWidget->geometry().contains(event->pos())) {
if (!m_device) {
return;
@ -336,6 +522,18 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event)
}
}
void VideoForm::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton
&& !m_videoWidget->geometry().contains(event->pos())) {
removeBlackRect();
}
if (event->button() == Qt::RightButton && m_device) {
emit m_device->postBackOrScreenOn();
}
}
void VideoForm::wheelEvent(QWheelEvent *event)
{
if (m_videoWidget->geometry().contains(event->pos())) {
@ -364,17 +562,6 @@ void VideoForm::keyPressEvent(QKeyEvent *event)
&& isFullScreen()) {
emit m_device->switchFullScreen();
}
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) {
emit m_device->requestDeviceClipboard();
}
if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) {
if (event->modifiers() & Qt::ShiftModifier) {
emit m_device->setDeviceClipboard();
} else {
emit m_device->clipboardPaste();
}
return;
}
emit m_device->keyEvent(event, m_videoWidget->frameSize(), m_videoWidget->size());
}

View file

@ -26,6 +26,8 @@ public:
void setDevice(Device *device);
QRect getGrabCursorRect();
const QSize &frameSize();
void resizeSquare();
void removeBlackRect();
public slots:
void onSwitchFullScreen();
@ -37,11 +39,14 @@ private:
void showToolForm(bool show = true);
void moveCenter();
void installShortcut();
QRect getScreenRect();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);

View file

@ -121,7 +121,8 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins
connect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
connect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
connect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
connect(host, &Device::postTurnOn, client, &Device::postTurnOn);
connect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel);
connect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
connect(host, &Device::postTextInput, client, &Device::postTextInput);
connect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
connect(host, &Device::clipboardPaste, client, &Device::clipboardPaste);
@ -141,7 +142,8 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins
disconnect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
disconnect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
disconnect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
disconnect(host, &Device::postTurnOn, client, &Device::postTurnOn);
disconnect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel);
disconnect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn);
disconnect(host, &Device::postTextInput, client, &Device::postTextInput);
disconnect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
disconnect(host, &Device::clipboardPaste, client, &Device::clipboardPaste);

View file

@ -179,6 +179,32 @@ Note: it is not necessary to keep you Android device connected via USB after you
breaks non-ASCII characters).
- Group control
## Shortcuts
| Action | Shortcut (Windows) | Shortcut (macOS)
| -------------------------------------- |:----------------------------- |:-----------------------------
| Switch fullscreen mode | `Ctrl`+`f` | `Cmd`+`f`
| Resize window to 1:1 (pixel-perfect) | `Ctrl`+`g` | `Cmd`+`g`
| Resize window to remove black borders | `Ctrl`+`x` \| _Double-click¹_ | `Cmd`+`x` \| _Double-click¹_
| Click on `HOME` | `Ctrl`+`h` \| _Middle-click_ | `Ctrl`+`h` \| _Middle-click_
| Click on `BACK` | `Ctrl`+`b` \| _Right-click²_ | `Cmd`+`b` \| _Right-click²_
| Click on `APP_SWITCH` | `Ctrl`+`s` | `Cmd`+`s`
| Click on `MENU` | `Ctrl`+`m` | `Ctrl`+`m`
| Click on `VOLUME_UP` | `Ctrl`+`↑` _(up)_ | `Cmd`+`↑` _(up)_
| Click on `VOLUME_DOWN` | `Ctrl`+`↓` _(down)_ | `Cmd`+`↓` _(down)_
| Click on `POWER` | `Ctrl`+`p` | `Cmd`+`p`
| Power on | _Right-click²_ | _Right-click²_
| Turn device screen off (keep mirroring)| `Ctrl`+`o` | `Cmd`+`o`
| Expand notification panel | `Ctrl`+`n` | `Cmd`+`n`
| Collapse notification panel | `Ctrl`+`Shift`+`n` | `Cmd`+`Shift`+`n`
| Copy device clipboard to computer | `Ctrl`+`c` | `Cmd`+`c`
| Paste computer clipboard to device | `Ctrl`+`v` | `Cmd`+`v`
| Copy computer clipboard to device | `Ctrl`+`Shift`+`v` | `Cmd`+`Shift`+`v`
_¹Double-click on black borders to remove them._
_²Right-click turns the screen on if it was off, presses BACK otherwise._
## TODO
[TODO](docs/TODO.md)

View file

@ -179,6 +179,32 @@ Mac OS平台你可以直接使用我编译好的可执行程序:
- `Ctrl` +`v` 将计算机剪贴板作为一系列文本事件发送到设备不支持非ASCII字符
- 群控
## 快捷键
| 功能 | 快捷键(Windows) | 快捷键 (macOS)
| -------------------------------------- |:----------------------------- |:-----------------------------
| 切换全屏 | `Ctrl`+`f` | `Cmd`+`f`
| 调整窗口大小为 1:1 | `Ctrl`+`g` | `Cmd`+`g`
| 调整窗口大小去除黑边 | `Ctrl`+`x` \| _左键双击_ | `Cmd`+`x` \| _左键双击_
| 点击 `主页` | `Ctrl`+`h` \| _点击鼠标中键_ | `Ctrl`+`h` \| _点击鼠标中键_
| 点击 `BACK` | `Ctrl`+`b` \| _右键双击_ | `Cmd`+`b` \| _右键双击_
| 点击 `APP_SWITCH` | `Ctrl`+`s` | `Cmd`+`s`
| 点击 `MENU` | `Ctrl`+`m` | `Ctrl`+`m`
| 点击 `VOLUME_UP` | `Ctrl`+`↑` _(上)_ | `Cmd`+`↑` _(上)_
| 点击 `VOLUME_DOWN` | `Ctrl`+`↓` _(下)_ | `Cmd`+`↓` _(下)_
| 点击 `POWER` | `Ctrl`+`p` | `Cmd`+`p`
| 打开电源 | _右键双击_ | _右键双击_
| 关闭屏幕 (保持投屏) | `Ctrl`+`o` | `Cmd`+`o`
| 打开下拉菜单 | `Ctrl`+`n` | `Cmd`+`n`
| 关闭下拉菜单 | `Ctrl`+`Shift`+`n` | `Cmd`+`Shift`+`n`
| 复制设备剪切板到电脑 | `Ctrl`+`c` | `Cmd`+`c`
| 粘贴电脑剪切板到设备 | `Ctrl`+`v` | `Cmd`+`v`
| 复制电脑剪切板到设备 | `Ctrl`+`Shift`+`v` | `Cmd`+`Shift`+`v`
鼠标左键双击黑色区域可以去除黑色区域
如果电源关闭,鼠标右键双击打开电源;如果电源开启,鼠标右键双击相当于返回
## TODO
[后期计划](docs/TODO.md)