Feat:实现平板模式禁用时,插拔键盘自动切换平板模式功能隐藏
This commit is contained in:
parent
3d69eef18a
commit
7be36d3305
|
@ -0,0 +1,136 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "autotabletmodewidget.h"
|
||||
|
||||
#include <ukcc/interface/ukcccommon.h>
|
||||
#include <kysdk/applications/kswitchbutton.h>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
|
||||
AutoTabletModeWidget::AutoTabletModeWidget(const QString& autoSwitchTabletText, QWidget* parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
setContentsMargins(16, 10, 16, 10);
|
||||
setFrameShape(QFrame::Shape::Box);
|
||||
|
||||
initLayout();
|
||||
initAutoTabletModeWidget(autoSwitchTabletText);
|
||||
}
|
||||
|
||||
void AutoTabletModeWidget::initLayout()
|
||||
{
|
||||
QVBoxLayout* tabletModeVLayout = new QVBoxLayout;
|
||||
tabletModeVLayout->setMargin(0);
|
||||
setLayout(tabletModeVLayout);
|
||||
}
|
||||
|
||||
void AutoTabletModeWidget::initAutoTabletModeWidget(const QString& autoSwitchTabletText)
|
||||
{
|
||||
QWidget* autoSwitchTabletWidget = createAutoTabletModeWidget(autoSwitchTabletText);
|
||||
autoSwitchTabletWidget->setMinimumHeight(40);
|
||||
layout()->addWidget(autoSwitchTabletWidget);
|
||||
}
|
||||
|
||||
QWidget* AutoTabletModeWidget::createAutoTabletModeWidget(const QString& autoSwitchTabletText)
|
||||
{
|
||||
QWidget* autoTabletModeWidget = new QWidget;
|
||||
QLabel* tabletModeText = new QLabel(autoSwitchTabletText);
|
||||
initTabletModeButton(autoTabletModeWidget);
|
||||
|
||||
QHBoxLayout* autoTabletModeLayout = new QHBoxLayout(autoTabletModeWidget);
|
||||
autoTabletModeLayout->setContentsMargins(0, 0, 0, 0);
|
||||
autoTabletModeLayout->addWidget(tabletModeText);
|
||||
autoTabletModeLayout->addStretch();
|
||||
autoTabletModeLayout->addWidget(m_autoTabletModeButton);
|
||||
autoTabletModeWidget->setLayout(autoTabletModeLayout);
|
||||
|
||||
return autoTabletModeWidget;
|
||||
}
|
||||
|
||||
void AutoTabletModeWidget::initTabletModeButton(QWidget* widget)
|
||||
{
|
||||
m_autoTabletModeButton = new kdk::KSwitchButton(widget);
|
||||
m_autoTabletModeButton->setChecked(getAutoSwitchTablet());
|
||||
connect(m_autoTabletModeButton, &kdk::KSwitchButton::clicked, this, [this](bool state) {
|
||||
setAutoSwitchTablet(state);
|
||||
ukcc::UkccCommon::buriedSettings("AutoSwitchTabletModeButton", "settings", state ? "true":"false");
|
||||
});
|
||||
|
||||
QDBusConnection::sessionBus().connect("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface",
|
||||
"modemonitor_change_signal",
|
||||
this,
|
||||
SLOT(setAutoSwitchTabletBtn(bool)));
|
||||
}
|
||||
|
||||
bool AutoTabletModeWidget::getAutoSwitchTablet() const
|
||||
{
|
||||
QDBusInterface statusManager("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface");
|
||||
|
||||
if(!statusManager.isValid()) {
|
||||
qWarning() << "com.kylin.statusmanager.interface is invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
QDBusReply<bool> reply = statusManager.call("get_modemonitor");
|
||||
if (!reply.isValid()) {
|
||||
qWarning() << reply.error();
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.value();
|
||||
}
|
||||
|
||||
void AutoTabletModeWidget::setAutoSwitchTablet(bool state)
|
||||
{
|
||||
QDBusInterface statusManager("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface");
|
||||
|
||||
if(!statusManager.isValid()) {
|
||||
qWarning() << "com.kylin.statusmanager.interface is invalid";
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusMessage res = statusManager.call("set_modemonitor",
|
||||
QVariant(state),
|
||||
QVariant("Touch Screen Plugin"),
|
||||
QVariant("Auto Switch Tablet Mode Button"));
|
||||
|
||||
if (res.type() == QDBusMessage::ErrorMessage) {
|
||||
qWarning() << res.errorName() << res.errorMessage();
|
||||
}
|
||||
}
|
||||
|
||||
void AutoTabletModeWidget::setAutoSwitchTabletBtn(bool checked)
|
||||
{
|
||||
if (!m_autoTabletModeButton)
|
||||
return;
|
||||
if (m_autoTabletModeButton->isChecked() == checked)
|
||||
return;
|
||||
m_autoTabletModeButton->setChecked(checked);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AUTOTABLETMODEWIDGET_H
|
||||
#define AUTOTABLETMODEWIDGET_H
|
||||
|
||||
#include <QFrame>
|
||||
|
||||
namespace kdk {
|
||||
class KSwitchButton;
|
||||
}
|
||||
class AutoTabletModeWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AutoTabletModeWidget(const QString& autoSwitchTabletText, QWidget* parent = nullptr);
|
||||
~AutoTabletModeWidget() = default;
|
||||
|
||||
private:
|
||||
void initLayout();
|
||||
void initAutoTabletModeWidget(const QString& autoSwitchTabletText);
|
||||
QWidget* createAutoTabletModeWidget(const QString& autoSwitchTabletText);
|
||||
void initTabletModeButton(QWidget* widget);
|
||||
|
||||
bool getAutoSwitchTablet() const;
|
||||
void setAutoSwitchTablet(bool state);
|
||||
void setAutoSwitchTabletBtn(bool checked);
|
||||
|
||||
kdk::KSwitchButton* m_autoTabletModeButton;
|
||||
};
|
||||
|
||||
#endif // AUTOTABLETMODEWIDGET_H
|
|
@ -81,9 +81,9 @@ QWidget* TabletModeWidget::createTabletModeWidget()
|
|||
m_tabletModeButton = new kdk::KSwitchButton(tabletModeWidget);
|
||||
m_tabletModeButton->setChecked(getTabletModeEnabled());
|
||||
m_tabletModeButton->setEnabled(!getCurrentTabletMode());
|
||||
connect(m_tabletModeButton, &kdk::KSwitchButton::clicked, this, [this](bool checked) {
|
||||
setTabletModeEnabled(checked);
|
||||
ukcc::UkccCommon::buriedSettings("TouchScreen", "setTabletModeEnabled", "settings", checked ? "true":"false");
|
||||
connect(m_tabletModeButton, &kdk::KSwitchButton::clicked, this, [this](bool enabled) {
|
||||
setTabletModeEnabled(enabled);
|
||||
ukcc::UkccCommon::buriedSettings("TouchScreen", "setTabletModeEnabled", "settings", enabled ? "true":"false");
|
||||
});
|
||||
|
||||
QHBoxLayout* tabletModeLayout = new QHBoxLayout(tabletModeWidget);
|
||||
|
|
|
@ -36,12 +36,14 @@ include(../settings-common/settings-common.pri)
|
|||
#include(video-widget/video-widget.pri)
|
||||
|
||||
SOURCES += \
|
||||
autotabletmodewidget.cpp \
|
||||
gestureguidance.cpp \
|
||||
tabletmodewidget.cpp \
|
||||
touchscreen-settings.cpp \
|
||||
touchscreen.cpp
|
||||
|
||||
HEADERS += \
|
||||
autotabletmodewidget.h \
|
||||
gestureguidance.h \
|
||||
tabletmodewidget.h \
|
||||
touchscreen-settings.h \
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "touchscreen-settings.h"
|
||||
#include "settingscommon.h"
|
||||
#include "tabletmodewidget.h"
|
||||
#include "autotabletmodewidget.h"
|
||||
|
||||
#define KYLIN_USER_GUIDE_PATH "/"
|
||||
#define KYLIN_USER_GUIDE_SERVICE "com.kylinUserGuide.hotel"
|
||||
|
@ -58,6 +59,7 @@ TouchScreen::TouchScreen(QList<TouchGestureInfo> gestureInfos,
|
|||
{
|
||||
ui->setupUi(this);
|
||||
initUI();
|
||||
initConnection();
|
||||
loadGif();
|
||||
}
|
||||
|
||||
|
@ -111,13 +113,16 @@ void TouchScreen::initUI()
|
|||
TabletModeWidget* tabletModeWidget = new TabletModeWidget;
|
||||
ui->verticalLayout->insertWidget(2, tabletModeWidget);
|
||||
|
||||
initAutoTabletModeWidget();
|
||||
if (getTabletModeEnabled()) {
|
||||
m_autoTabletModeWidget = new AutoTabletModeWidget(m_autoSwitchText);
|
||||
ui->verticalLayout->insertWidget(3, m_autoTabletModeWidget);
|
||||
}
|
||||
|
||||
//! \note Do not show tablet mode if os without tablet mode
|
||||
if (!SettingsCommon::isTabletProductFeat()) {
|
||||
tabletModeWidget->deleteLater();
|
||||
m_autoTabletModeWidget->deleteLater();
|
||||
ui->switchTablet_label->hide();
|
||||
ui->switchTablet_frame->hide();
|
||||
ui->horizontalLayout_4->deleteLater();
|
||||
}
|
||||
|
||||
|
@ -145,29 +150,39 @@ void TouchScreen::initUI()
|
|||
});
|
||||
}
|
||||
|
||||
void TouchScreen::initAutoTabletModeWidget()
|
||||
void TouchScreen::initConnection()
|
||||
{
|
||||
QHBoxLayout* switchTabletLayout = new QHBoxLayout();
|
||||
ui->switchTablet_frame->setFrameShape(QFrame::Shape::Box);
|
||||
ui->switchTablet_frame->setLayout(switchTabletLayout);
|
||||
QLabel* autoSwtich = new QLabel(m_autoSwitchText);
|
||||
switchTabletLayout->addWidget(autoSwtich);
|
||||
switchTabletLayout->addStretch();
|
||||
switchTabletLayout->setContentsMargins(16, 0, 16, 0);
|
||||
m_autoSwitchTablet = new kdk::KSwitchButton();
|
||||
m_autoSwitchTablet->setChecked(this->autoSwitchTablet());
|
||||
switchTabletLayout->addWidget(m_autoSwitchTablet);
|
||||
connect(m_autoSwitchTablet, &kdk::KSwitchButton::clicked, this, [this](bool checked) {
|
||||
setAutoSwitchTablet(checked);
|
||||
buriedSettings("AutoSwitchTabletModeButton", "settings", checked ? "true":"false");
|
||||
});
|
||||
|
||||
QDBusConnection::sessionBus().connect("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface",
|
||||
"modemonitor_change_signal",
|
||||
"isTabletModeEnabledChanged",
|
||||
this,
|
||||
SLOT(setAutoSwitchTabletBtn(bool)));
|
||||
SLOT(onTabletModeEnabledChanged(bool)));
|
||||
}
|
||||
|
||||
void TouchScreen::onTabletModeEnabledChanged(bool enabled)
|
||||
{
|
||||
if (enabled && nullptr == m_autoTabletModeWidget) {
|
||||
m_autoTabletModeWidget = new AutoTabletModeWidget(m_autoSwitchText);
|
||||
ui->verticalLayout->insertWidget(3, m_autoTabletModeWidget);
|
||||
} else if (!enabled && m_autoTabletModeWidget != nullptr) {
|
||||
delete m_autoTabletModeWidget;
|
||||
m_autoTabletModeWidget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchScreen::getTabletModeEnabled() const
|
||||
{
|
||||
QDBusInterface statusManager("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface");
|
||||
QDBusReply<bool> reply = statusManager.call("isTabletModeEnabled");
|
||||
if (!reply.isValid()) {
|
||||
qWarning() << reply.error();
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.value();
|
||||
}
|
||||
|
||||
void TouchScreen::buriedSettings(QString settingsName, QString action, QString value) const
|
||||
|
@ -205,54 +220,6 @@ void TouchScreen::stopGif()
|
|||
m_movie->jumpToFrame(0);
|
||||
}
|
||||
|
||||
bool TouchScreen::autoSwitchTablet()
|
||||
{
|
||||
QDBusInterface statusManager("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface");
|
||||
QDBusMessage res = statusManager.call("get_modemonitor");
|
||||
if (res.type() == QDBusMessage::ErrorMessage) {
|
||||
qWarning() << res.errorName() << res.errorMessage();
|
||||
}
|
||||
else if(res.type() == QDBusMessage::ReplyMessage) {
|
||||
QDBusReply<bool> reply = res;
|
||||
return reply.value();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TouchScreen::setAutoSwitchTablet(bool state)
|
||||
{
|
||||
QDBusInterface statusManager("com.kylin.statusmanager.interface",
|
||||
"/",
|
||||
"com.kylin.statusmanager.interface");
|
||||
QDBusMessage res = statusManager.call("set_modemonitor",
|
||||
QVariant(state),
|
||||
QVariant("Touch Screen Plugin"),
|
||||
QVariant("Auto Switch Tablet Mode Button"));
|
||||
|
||||
if (res.type() == QDBusMessage::ErrorMessage) {
|
||||
qWarning() << res.errorName() << res.errorMessage();
|
||||
}
|
||||
else if (res.type() == QDBusMessage::ReplyMessage) {
|
||||
QDBusReply<bool> reply = res;
|
||||
if (!reply) {
|
||||
qWarning() << "Set auto switch tablet mode error."
|
||||
<< "Function set_modemonitor of dbus servies com.kylin.statusmanager.interface"
|
||||
<< "return" << reply;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TouchScreen::setAutoSwitchTabletBtn(bool checked)
|
||||
{
|
||||
if (!m_autoSwitchTablet)
|
||||
return;
|
||||
if (m_autoSwitchTablet->isChecked() == checked)
|
||||
return;
|
||||
m_autoSwitchTablet->setChecked(checked);
|
||||
}
|
||||
|
||||
// // 下面这种方式可以加载 mp4 文件,但是控制面板加载会报 QXcbConnection 的错误
|
||||
// // 用 demo 加载插件不会出现此问题,暂时没有思路
|
||||
//void TouchScreen::loadVideo()
|
||||
|
|
|
@ -65,6 +65,7 @@ class QMovie;
|
|||
class QGSettings;
|
||||
class GestureWidget;
|
||||
class TouchGestureInfo;
|
||||
class AutoTabletModeWidget;
|
||||
class TouchScreen : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -82,27 +83,26 @@ signals:
|
|||
void iconThemeChangedSignal();
|
||||
|
||||
private slots:
|
||||
void setAutoSwitchTabletBtn(bool checked);
|
||||
void onTabletModeEnabledChanged(bool enabled);
|
||||
private:
|
||||
GestureWidget * createGestureWidget(const TouchGestureInfo& gestureInfo);
|
||||
QList<GestureWidget*> createGestureWidgets();
|
||||
void initUI();
|
||||
void initAutoTabletModeWidget();
|
||||
void initConnection();
|
||||
void loadGif();
|
||||
void playGif(const QString& gifPath);
|
||||
bool autoSwitchTablet();
|
||||
void setAutoSwitchTablet(bool state);
|
||||
bool getTabletModeEnabled() const;
|
||||
void buriedSettings(QString settingsName, QString action, QString value) const;
|
||||
|
||||
Ui::TouchScreen *ui;
|
||||
quint32 m_cycleNum;
|
||||
QMovie *m_movie;
|
||||
QGSettings *m_iconThemeGSettings;
|
||||
kdk::KSwitchButton* m_autoSwitchTablet;
|
||||
QList<TouchGestureInfo> m_gestureInfos;
|
||||
|
||||
const QString m_modeTypeText;
|
||||
const QString m_autoSwitchText;
|
||||
AutoTabletModeWidget* m_autoTabletModeWidget;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0,0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
|
@ -75,34 +75,6 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="switchTablet_frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
|
|
Loading…
Reference in New Issue