diff --git a/BiometricAuth/CMakeLists.txt b/BiometricAuth/CMakeLists.txt index 18c3215..e1b52a5 100644 --- a/BiometricAuth/CMakeLists.txt +++ b/BiometricAuth/CMakeLists.txt @@ -1,8 +1,6 @@ qt5_wrap_cpp(BiometricAuth_SRC biometricdeviceinfo.h - biometricproxy.h - biometricauthwidget.h - biometricdeviceswidget.h + biometricproxy.h giodbus.h uniauthservice.h ) @@ -10,9 +8,7 @@ qt5_wrap_cpp(BiometricAuth_SRC set(BiometricAuth_SRC ${BiometricAuth_SRC} biometricdeviceinfo.cpp - biometricproxy.cpp - biometricauthwidget.cpp - biometricdeviceswidget.cpp + biometricproxy.cpp giodbus.cpp uniauthservice.cpp ) @@ -20,11 +16,12 @@ set(BiometricAuth_SRC include_directories( ${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} - ${Qt5DBus_INCLUDE_DIRS} - ${OpenCV_INCLUDE_DIRS} + ${Qt5DBus_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} + ${GIOUNIX2_INCLUDE_DIRS} ) add_library(BiometricAuth STATIC ${BiometricAuth_SRC}) -target_link_libraries(BiometricAuth Qt5::Core Qt5::DBus Qt5::Widgets ${OpenCV_LIBS} ${GIOUNIX2_LIBRARIES}) +target_link_libraries(BiometricAuth Qt5::Core Qt5::DBus Qt5::Widgets + ${GIOUNIX2_LIBRARIES}) diff --git a/BiometricAuth/biometricdeviceinfo.cpp b/BiometricAuth/biometricdeviceinfo.cpp index ad0da07..83f97f0 100644 --- a/BiometricAuth/biometricdeviceinfo.cpp +++ b/BiometricAuth/biometricdeviceinfo.cpp @@ -66,6 +66,8 @@ QString DeviceType::getDeviceType_tr(int deviceType) return tr("Face"); case VoicePrint: return tr("VoicePrint"); + case LOGINOPT_TYPE_GENERAL_UKEY: + return tr("ukey"); case REMOTE_QRCODE_TYPE: return tr("QRCode"); default: @@ -125,10 +127,33 @@ const QDBusArgument &operator >>(const QDBusArgument &arg, DeviceInfo &deviceInf return arg; } +/* For the type FeatureInfo */ +QDBusArgument &operator<<(QDBusArgument &argument, const FeatureInfo &featureInfo) +{ + argument.beginStructure(); + argument << featureInfo.uid << featureInfo.biotype + << featureInfo.device_shortname << featureInfo.index + << featureInfo.index_name; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, FeatureInfo &featureInfo) +{ + argument.beginStructure(); + argument >> featureInfo.uid >> featureInfo.biotype + >> featureInfo.device_shortname >> featureInfo.index + >> featureInfo.index_name; + argument.endStructure(); + return argument; +} + void registerMetaType() { qRegisterMetaType("DeviceInfo"); qDBusRegisterMetaType(); + qRegisterMetaType("FeatureInfo"); + qDBusRegisterMetaType(); } diff --git a/BiometricAuth/biometricdeviceinfo.h b/BiometricAuth/biometricdeviceinfo.h index 31cf9ac..e5a4e64 100644 --- a/BiometricAuth/biometricdeviceinfo.h +++ b/BiometricAuth/biometricdeviceinfo.h @@ -211,20 +211,35 @@ struct DeviceInfo int OpsStatus; }; + +struct FeatureInfo { + int uid; + int biotype; + QString device_shortname; + int index; + QString index_name; +}; + class QDBusArgument; QDBusArgument &operator <<(QDBusArgument &arg, const DeviceInfo &deviceInfo); const QDBusArgument &operator >>(const QDBusArgument &arg, DeviceInfo &deviceInfo); +QDBusArgument &operator<<(QDBusArgument &argument, const FeatureInfo &featureInfo); +const QDBusArgument &operator>>(const QDBusArgument &argument, FeatureInfo &featureInfo); void registerMetaType(); typedef std::shared_ptr DeviceInfoPtr; typedef QList DeviceList; typedef QMap DeviceMap; +typedef std::shared_ptr FeatureInfoPtr; +typedef QList FeatureList; +typedef QMap FeatureMap; QDebug operator <<(QDebug stream, const DeviceInfo &deviceInfo); Q_DECLARE_METATYPE(DeviceInfo) +Q_DECLARE_METATYPE(FeatureInfo) /** * @brief 获取默认设备 @@ -265,6 +280,8 @@ enum LOGINOPT_TYPE { LOGINOPT_TYPE_IRIS, // 虹膜 LOGINOPT_TYPE_VOICEPRINT, // 声纹 LOGINOPT_TYPE_FINGERVEIN, // 指静脉 + LOGINOPT_TYPE_GENERAL_UKEY, // 普通的ukey + LOGINOPT_TYPE_ADVANCED_UKEY, // 高阶的ukey LOGINOPT_TYPE_QRCODE, // 二维码 LOGINOPT_TYPE_OTHERS, // 其他 LOGINOPT_TYPE_COUNT diff --git a/BiometricAuth/biometricproxy.cpp b/BiometricAuth/biometricproxy.cpp index 644d9f7..9f2513e 100644 --- a/BiometricAuth/biometricproxy.cpp +++ b/BiometricAuth/biometricproxy.cpp @@ -17,6 +17,7 @@ **/ #include "biometricproxy.h" #include +#include BiometricProxy::BiometricProxy(QObject *parent) : QDBusAbstractInterface(BIOMETRIC_DBUS_SERVICE, @@ -36,6 +37,41 @@ QDBusPendingCall BiometricProxy::Identify(int drvid, int uid, int indexStart, in return asyncCallWithArgumentList(QStringLiteral("Identify"), argList); } +QDBusPendingCall BiometricProxy::UkeyIdentify(int drvid, int type, int uid) +{ + QList argList; + argList << drvid << type << uid; + return asyncCallWithArgumentList(QStringLiteral("UkeyIdentify"), argList); +} + +bool BiometricProxy::GetHasUkeyFeature(int uid, int indexStart, int indexEnd) +{ + QList qlist; + FeatureInfo *featureInfo; + int listsize; + QDBusMessage result = call(QStringLiteral("GetAllFeatureList"),uid,indexStart,indexEnd); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "GetDevList error:" << result.errorMessage(); + return false; + } + QList variantList = result.arguments(); + listsize = variantList[0].value(); + variantList[1].value() >> qlist; + for (int i = 0; i < listsize; i++) { + featureInfo = new FeatureInfo; + qlist[i].variant().value() >> *featureInfo; + if(featureInfo->biotype == LOGINOPT_TYPE_GENERAL_UKEY){ + delete featureInfo; + return true; + } + delete featureInfo; + } + + return false; + +} + int BiometricProxy::GetFeatureCount(int uid, int indexStart, int indexEnd) { QDBusMessage result = call(QStringLiteral("GetDevList")); @@ -67,6 +103,17 @@ int BiometricProxy::GetFeatureCount(int uid, int indexStart, int indexEnd) return res; } +int BiometricProxy::SetExtraInfo(QString info_type,QString extra_info) +{ + QDBusReply reply = call(QStringLiteral("SetExtraInfo"), info_type, extra_info); + if(!reply.isValid()) + { + qWarning() << "SetExtraInfo error:" << reply.error(); + return -1; + } + return reply.value(); +} + int BiometricProxy::StopOps(int drvid, int waiting) { QDBusReply reply = call(QStringLiteral("StopOps"), drvid, waiting); @@ -144,6 +191,28 @@ DeviceList BiometricProxy::GetDevList() return deviceList; } +FeatureMap BiometricProxy::GetUserFeatures(int uid) +{ + FeatureMap featureMap; + QList qlist; + int listsize; + QDBusMessage result = call(QStringLiteral("GetAllFeatureList"), uid, 0, -1); + if(result.type() == QDBusMessage::ErrorMessage) + { + qWarning() << "GetDevList error:" << result.errorMessage(); + return featureMap; + } + QList variantList = result.arguments(); + listsize = variantList[0].value(); + variantList[1].value() >> qlist; + for (int i = 0; i < listsize; i++) { + FeatureInfoPtr pFeatureInfo = std::make_shared(); + qlist[i].variant().value() >> *pFeatureInfo; + featureMap[pFeatureInfo->device_shortname].append(pFeatureInfo); + } + return featureMap; +} + int BiometricProxy::GetDevCount() { QDBusMessage result = call(QStringLiteral("GetDevList")); diff --git a/BiometricAuth/biometricproxy.h b/BiometricAuth/biometricproxy.h index 4452a7e..5395ed7 100644 --- a/BiometricAuth/biometricproxy.h +++ b/BiometricAuth/biometricproxy.h @@ -64,6 +64,21 @@ public Q_SLOTS: * @return 结果: (结果,用户id) */ QDBusPendingCall Identify(int drvid, int uid, int indexStart = 0, int indexEnd = -1); + /** + * @brief 使用指定id的设备进行用户认证 + * @param drvid 驱动(设备)id + * @param type ukey的认证类型,2表示pin认证(需通过setExtraInfo设置pin码,3表示指纹认证) + * @param uid 用户id + * @return 结果: (结果,用户id) + */ + QDBusPendingCall UkeyIdentify(int drvid, int type, int uid); + /** + * @brief 设置一些认证时所需的额外的信息 + * @param info_type 额外的信息类型,ukey pincode认证时传 "pincode" + * @param extra_info 额外的信息内容,ukey pincode认证时传PIN码内容 + * @return 结果: (设置额外信息的结果) + */ + int SetExtraInfo(QString info_type, QString extra_info); /** * @brief 终止设备上正在进行的操作 * @param drvid 设备id @@ -79,6 +94,14 @@ public Q_SLOTS: * @return */ int GetFeatureCount(int uid, int indexStart = 0, int indexEnd = -1); + /** + * @brief 获取当前用户已连接设备对应特征数目 + * @param uid 用户id + * @param indexStart 用于认证的特征索引范围 + * @param indexEnd + * @return 返回是否存在ukey特征 + */ + bool GetHasUkeyFeature(int uid, int indexStart = 0, int indexEnd = -1); /** * @brief 获取已连接的设备列表 * @return @@ -116,7 +139,12 @@ public Q_SLOTS: StatusReslut UpdateStatus(int drvid); int GetUserDevCount(int uid); int GetUserDevFeatureCount(int uid,int drvid); - + /** + * @brief GetUserFeatures 获取用户所有特征 + * @param uid 用户id + * @return 特征信息列表 + */ + FeatureMap GetUserFeatures(int uid); Q_SIGNALS: /** diff --git a/BiometricAuth/giodbus.cpp b/BiometricAuth/giodbus.cpp index 399aa0e..02a362b 100644 --- a/BiometricAuth/giodbus.cpp +++ b/BiometricAuth/giodbus.cpp @@ -17,7 +17,7 @@ **/ #include "giodbus.h" #include -#include +#include #include int get_server_gvariant_stdout (int drvid) diff --git a/Common/CMakeLists.txt b/Common/CMakeLists.txt index 5390d95..a53f577 100644 --- a/Common/CMakeLists.txt +++ b/Common/CMakeLists.txt @@ -1,7 +1,21 @@ +pkg_check_modules(GLIB REQUIRED glib-2.0) +find_package(X11 REQUIRED) +find_package(KF5WindowSystem) + +include_directories( + ${Qt5Core_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS} + ${Qt5DBus_INCLUDE_DIRS} + ${GLIB2_INCLUDE_DIRS} + ${KF5Wayland_LIBRARIES} + ) + qt5_wrap_cpp(Common_SRC autoresize.h checkbutton.h commonfunc.h + glibinterface.h + plasma-shell-manager.h ) set(Common_SRC @@ -9,14 +23,9 @@ set(Common_SRC autoresize.cpp checkbutton.cpp commonfunc.cpp + glibinterface.cpp + plasma-shell-manager.cpp ) -include_directories( - ${Qt5Core_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} - ${Qt5DBus_INCLUDE_DIRS} - ) - - add_library(Common STATIC ${Common_SRC}) -target_link_libraries(Common Qt5::Core Qt5::DBus Qt5::Widgets) +target_link_libraries(Common Qt5::Core Qt5::DBus Qt5::Widgets ${GIOUNIX2_LIBRARIES} ${KF5Wayland_LIBRARIES} -lKF5WaylandClient -lKF5WaylandServer KF5::WindowSystem) diff --git a/Common/commonfunc.h b/Common/commonfunc.h index d8f0d02..d028bdd 100644 --- a/Common/commonfunc.h +++ b/Common/commonfunc.h @@ -23,6 +23,8 @@ #include #include +#define G_FONT_SIZE (11.0) + bool ispicture(QString filepath); QString getSystemVersion(); QString getSystemDistrib(); diff --git a/Common/glibinterface.cpp b/Common/glibinterface.cpp new file mode 100644 index 0000000..66c26bc --- /dev/null +++ b/Common/glibinterface.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "glibinterface.h" +#include +#include + +#define STYLE_TYPE_SCHEMA "org.ukui.style" +#define KEY_SYSTEM_FONT_SIZE "system-font-size" +#define DEFAULT_FONT_SIZE (10.0) + +double getDefaultFontSize() +{ + GSettingsSchemaSource *schema_source = NULL; + GSettingsSchema *schema = NULL; + + schema_source = g_settings_schema_source_get_default(); + if(schema_source){ + schema = g_settings_schema_source_lookup (schema_source,KEY_SYSTEM_FONT_SIZE,TRUE); + if(schema){ + GVariant *size; + unsigned long length; + GSettings *gs; + + gs = g_settings_new(STYLE_TYPE_SCHEMA); + size = g_settings_get_default_value(gs, KEY_SYSTEM_FONT_SIZE); + QString fontsize(g_variant_get_string(size,&length)); + g_object_unref(gs); + + return fontsize.toDouble(); + } + } + return DEFAULT_FONT_SIZE; +} diff --git a/Common/glibinterface.h b/Common/glibinterface.h new file mode 100644 index 0000000..3b3c018 --- /dev/null +++ b/Common/glibinterface.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef GLIBINTERFACE_H +#define GLIBINTERFACE_H + +double getDefaultFontSize(); + +#endif // LOCKWIDGET_H + diff --git a/src/plasma-shell-manager.cpp b/Common/plasma-shell-manager.cpp similarity index 67% rename from src/plasma-shell-manager.cpp rename to Common/plasma-shell-manager.cpp index 98659f0..eeea7e4 100644 --- a/src/plasma-shell-manager.cpp +++ b/Common/plasma-shell-manager.cpp @@ -15,6 +15,7 @@ * along with this program; if not, see . * **/ + #include "plasma-shell-manager.h" #include @@ -129,8 +130,40 @@ bool PlasmaShellManager::supportPlasmaWindowManagement() return m_windowManager && m_appWindow; } +bool PlasmaShellManager::supportFakeInput() +{ + return m_fakeInput; +} + +bool PlasmaShellManager::supportKeyState() +{ + return m_keyState; +} + +KWayland::Client::Keystate::State PlasmaShellManager::getKeyState(KWayland::Client::Keystate::Key key) +{ + if(!supportKeyState()){ + return KWayland::Client::Keystate::Unlocked; + } + + return m_keyStateMap[key]; +} + +void PlasmaShellManager::setKeyPressed(quint32 key) +{ + if(!supportFakeInput()) + return ; + + m_fakeInput->requestKeyboardKeyPress(key); + m_fakeInput->requestKeyboardKeyRelease(key); +} + PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent) { + m_keyStateMap.insert(KWayland::Client::Keystate::Key::CapsLock,KWayland::Client::Keystate::Unlocked); + m_keyStateMap.insert(KWayland::Client::Keystate::Key::NumLock,KWayland::Client::Keystate::Unlocked); + m_keyStateMap.insert(KWayland::Client::Keystate::Key::ScrollLock,KWayland::Client::Keystate::Unlocked); + auto connection = KWayland::Client::ConnectionThread::fromApplication(qApp); auto registry = new KWayland::Client::Registry(this); registry->create(connection->display()); @@ -161,15 +194,15 @@ PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent) m_appWindow = window; connect(m_appWindow, &KWayland::Client::PlasmaWindow::activeChanged, - [this]() { - this->setAppWindowKeepAbove(true); - this->setAppWindowActive(); - }); + [this]() { + this->setAppWindowKeepAbove(true); + this->setAppWindowActive(); + }); connect(m_appWindow, &KWayland::Client::PlasmaWindow::keepAboveChanged, - [this]() { - this->setAppWindowKeepAbove(true); - this->setAppWindowActive(); - }); + [this]() { + this->setAppWindowKeepAbove(true); + this->setAppWindowActive(); + }); } } }); @@ -183,6 +216,34 @@ PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent) } }); + connect(registry, &KWayland::Client::Registry::fakeInputAnnounced, this, [=](){ + qDebug()<<"fakeInputAnnounced"; + const auto interface = registry->interface(KWayland::Client::Registry::Interface::FakeInput); + if (interface.name != 0) { + qDebug()<<"createFakeInput"; + m_fakeInput = registry->createFakeInput(interface.name, interface.version); + m_fakeInput->authenticate("ukui-screensaver-dialog","virual keyboard"); + } + }); + + connect(registry, &KWayland::Client::Registry::keystateAnnounced, this, [=](){ + qDebug()<<"keystateAnnounced"; + const auto interface = registry->interface(KWayland::Client::Registry::Interface::Keystate); + if (interface.name != 0) { + qDebug()<<"createKeyState"; + m_keyState = registry->createKeystate(interface.name, interface.version); + if(m_keyState){ + connect(m_keyState, &KWayland::Client::Keystate::stateChanged, + [this](KWayland::Client::Keystate::Key key,KWayland::Client::Keystate::State state) { + qDebug()<<"key = "<fetchStates(); + } + } + }); + registry->setup(); connection->roundtrip(); } diff --git a/src/plasma-shell-manager.h b/Common/plasma-shell-manager.h similarity index 77% rename from src/plasma-shell-manager.h rename to Common/plasma-shell-manager.h index 35516aa..e5e0230 100644 --- a/src/plasma-shell-manager.h +++ b/Common/plasma-shell-manager.h @@ -15,14 +15,18 @@ * along with this program; if not, see . * **/ + #ifndef PLASMASHELLMANAGER_H #define PLASMASHELLMANAGER_H #include #include +#include #include #include #include +#include +#include class PlasmaShellManager : public QObject { @@ -35,9 +39,16 @@ public: bool setMaximized(QWindow *window); bool setRole(QWindow *window, KWayland::Client::PlasmaShellSurface::Role role); bool setPos(QWindow *window, const QPoint &pos); + void setKeyPressed(quint32 key); + bool supportPlasmaShell(); bool supportShell(); bool supportPlasmaWindowManagement(); + bool supportFakeInput(); + bool supportKeyState(); + KWayland::Client::Keystate::State getKeyState(KWayland::Client::Keystate::Key key); +Q_SIGNALS: + void keyStateChanged(); private: explicit PlasmaShellManager(QObject *parent = nullptr); @@ -46,8 +57,13 @@ private: KWayland::Client::Shell *m_shell = nullptr; KWayland::Client::PlasmaWindowManagement *m_windowManager = nullptr; KWayland::Client::PlasmaWindow *m_appWindow = nullptr; + KWayland::Client::FakeInput *m_fakeInput = nullptr; + KWayland::Client::Keystate *m_keyState = nullptr; bool isFirstCreate = true; + + QMap m_keyStateMap; + }; diff --git a/VirtualKeyboard/CMakeLists.txt b/VirtualKeyboard/CMakeLists.txt index 9f5355d..aa1ddf2 100644 --- a/VirtualKeyboard/CMakeLists.txt +++ b/VirtualKeyboard/CMakeLists.txt @@ -4,28 +4,33 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) +include_directories(${PROJECT_SOURCE_DIR}/Common) + qt5_add_resources(VirtualKeyboard_SRC src/keyboard.qrc) qt5_wrap_cpp(VirtualKeyboard_SRC - src/vkstackedwidget.h src/fakekeyboard.h ) set(VirtualKeyboard_SRC ${VirtualKeyboard_SRC} - src/cursormonitor.cpp - src/keyboardwidget.cpp - src/virtualkeyboard.cpp - src/x11keyboard.cpp - src/qtkeyboard.cpp - src/vkstackedwidget.cpp - src/keyboard.qrc) + src/charsmorewidget.cpp + src/charswidget.cpp + src/dragwidget.cpp + src/kbbutton.cpp + src/kbtitle.cpp + src/letterswidget.cpp + src/numberswidget.cpp + src/virtualkeyboardwidget.cpp + src/x11keyboard.cpp + src/qtkeyboard.cpp + ) include_directories( ${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} - ) + ) add_library(VirtualKeyboard STATIC ${VirtualKeyboard_SRC}) -target_link_libraries(VirtualKeyboard Qt5::Core Qt5::Widgets Qt5::X11Extras) +target_link_libraries(VirtualKeyboard Qt5::Core Qt5::Widgets Qt5::X11Extras Common) diff --git a/VirtualKeyboard/VirtualKeyboard.pri b/VirtualKeyboard/VirtualKeyboard.pri index e8029dc..79c43c4 100644 --- a/VirtualKeyboard/VirtualKeyboard.pri +++ b/VirtualKeyboard/VirtualKeyboard.pri @@ -1,18 +1,26 @@ SOURCES += \ - $$PWD/src/keyboardwidget.cpp \ - $$PWD/src/x11keyboard.cpp \ - $$PWD/src/cursormonitor.cpp \ - $$PWD/src/virtualkeyboard.cpp + $$PWD/src/charsmorewidget.cpp \ + $$PWD/src/charswidget.cpp \ + $$PWD/src/dragwidget.cpp \ + $$PWD/src/kbbutton.cpp \ + $$PWD/src/kbtitle.cpp \ + $$PWD/src/letterswidget.cpp \ + $$PWD/src/numberswidget.cpp \ + $$PWD/src/virtualkeyboardwidget.cpp \ + $$PWD/src/x11keyboard.cpp HEADERS += \ - $$PWD/src/keyboardwidget.h \ - $$PWD/src/x11keyboard.h \ - $$PWD/src/cursormonitor.h \ - $$PWD/src/virtualkeyboard.h - -FORMS += \ - $$PWD/src/keyboardwidget.ui + $$PWD/src/charsmorewidget.h \ + $$PWD/src/charswidget.h \ + $$PWD/src/commondef.h \ + $$PWD/src/dragwidget.h \ + $$PWD/src/kbbutton.h \ + $$PWD/src/kbtitle.h \ + $$PWD/src/letterswidget.h \ + $$PWD/src/numberswidget.h \ + $$PWD/src/virtualkeyboardwidget.h \ + $$PWD/src/x11keyboard.h RESOURCES += \ diff --git a/VirtualKeyboard/src/charsmorewidget.cpp b/VirtualKeyboard/src/charsmorewidget.cpp new file mode 100644 index 0000000..01cc10f --- /dev/null +++ b/VirtualKeyboard/src/charsmorewidget.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "charsmorewidget.h" +#include "commondef.h" + +#include +#include +#include +#include +#include +#include + +CharsMoreWidget::CharsMoreWidget(QWidget *parent/* = nullptr*/) + : QWidget(parent) +{ + this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 + setWindowFlags(Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint | + Qt::WindowDoesNotAcceptFocus); + initUI(); +} + +CharsMoreWidget::~CharsMoreWidget() +{ + +} + +void CharsMoreWidget::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + QMap::iterator itGeometry = m_mapBtnGeometrys.begin(); + for (; itGeometry != m_mapBtnGeometrys.end(); itGeometry ++) { + QWidget *widget = itGeometry.key(); + if (widget) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + widget->setGeometry(newGeometry); + } + } + + QChar chChars[] = {',', '.', '?', '!', '\'', ':', '~', '@', ';', '"', + '/', '(', ')', '_', '+', '=', '`', '^', '#', '*', + '%', '&', '\\', '[', ']', '<', '>', '{', '}', '|', + '$', '-'}; + for (int n = 0; n < sizeof(chChars)/sizeof(QChar); n++) { //单独更新符号btn的高度 + QString objName = QString("btn_%1").arg(QString(chChars[n])); + KBButton *btn = findChild(objName); + btn->setFixedHeight(KEYBOARD_FIXED_DEFAULT_NORMAL_CHARSMORE_BTN_HEIGHT *lfHeightScale); + } + //更新listfarame的高度 + listFrame->setFixedHeight(KEYBOARD_FIXED_DEFAULT_NORMAL_CHARSMORE_BTN_HEIGHT *m_vlayoutBtnList->count() *lfHeightScale); +} + +void CharsMoreWidget::onBtnClicked(QChar charId) +{ + QObject *obj = sender(); + KBButton *btn = static_cast(obj); + QString objName = btn->objectName(); + int lastUnderline = objName.lastIndexOf('_'); + int start = strlen("btn_"); + int keyLength = lastUnderline - start; + QString keyName = objName.mid(start, keyLength); + if (keyName == BTN_RETURN) { + Q_EMIT specialBtnClicked(PAGE_CHAR); + } else if (charId != QChar::Null) { + Q_EMIT normalBtnClicked(charId); + } else { + Q_EMIT specialBtnClicked(keyName); + } +} + +void CharsMoreWidget::initUI() +{ + // all chars + m_vlayoutBtnList = new QVBoxLayout(); + m_vlayoutBtnList->setContentsMargins(8,0,0,0); + m_vlayoutBtnList->setSpacing(1); + listFrame = new QFrame(); + listFrame->setLayout(m_vlayoutBtnList); + listFrame->setStyleSheet("QFrame{border-radius: 8px}"); + m_scrollFrame = new QScrollArea(this); + m_scrollFrame->setContentsMargins(0, 0, 0, 0); + m_scrollFrame->setFocusPolicy(Qt::NoFocus); + m_scrollFrame->setStyleSheet("QScrollArea {background-color: #C0FFFFFF; border-radius:8px;}"); + m_scrollFrame->viewport()->setStyleSheet("background-color:transparent;"); + m_scrollFrame->verticalScrollBar()->setProperty("drawScrollBarGroove", false); + m_scrollFrame->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_scrollFrame->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); + m_scrollFrame->setWidgetResizable(true); + m_scrollFrame->setWidget(listFrame); + m_scrollFrame->setGeometry(KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1, 0, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH, KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_HEIGHT); + listFrame->setGeometry(KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1, 0, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH, KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_HEIGHT); + m_mapBtnGeometrys[m_scrollFrame] = m_scrollFrame->geometry(); + m_mapBtnGeometrys[listFrame] = listFrame->geometry(); + QChar chChars[] = {',', '.', '?', '!', '\'', ':', '~', '@', ';', '"', + '/', '(', ')', '_', '+', '=', '`', '^', '#', '*', + '%', '&', '\\', '[', ']', '<', '>', '{', '}', '|', + '$', '-', ' ', ' ', ' ', ' '}; + QHBoxLayout *lastLayout = nullptr; + for (int n = 0; n < sizeof(chChars)/sizeof(QChar); n++) { + KBButton *charBtn = new KBButton(listFrame); + charBtn->setCharId(chChars[n]); + charBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_NORMAL, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_FONT_COLOR_PRESS, + KBButton::BORDER_RADIUS_NONE); + if ((n%KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_COLS) == 0) { + lastLayout = new QHBoxLayout(); + lastLayout->setContentsMargins(0,0,0,0); + lastLayout->setSpacing(1); + m_vlayoutBtnList->addLayout(lastLayout); + } + if (chChars[n] == ' ') { + charBtn->setDisabled(true); + } else { + charBtn->setObjectName(QString("btn_%1").arg(QString(chChars[n]))); + } + charBtn->setFixedHeight(KEYBOARD_FIXED_DEFAULT_NORMAL_CHARSMORE_BTN_HEIGHT); + lastLayout->addWidget(charBtn); + m_mapSubWidgetListRects[charBtn] = charBtn->geometry(); + connect(charBtn, &KBButton::clicked, this, &CharsMoreWidget::onBtnClicked); + } + // backspace + KBButton *backspaceBtn = new KBButton(this); + backspaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1+(KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH+KEYBOARD_FIXED_DEFAULT_CHARSMORE_HSPACING), + 0, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT); + backspaceBtn->setObjectName("btn_backspace"); + backspaceBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + backspaceBtn->setIcon(QIcon(":/images/images/delet.svg")); + m_mapBtnGeometrys[backspaceBtn] = backspaceBtn->geometry(); + connect(backspaceBtn, &KBButton::clicked, this, &CharsMoreWidget::onBtnClicked); + // enter + KBButton *enterBtn = new KBButton(this); + enterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1+(KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH+KEYBOARD_FIXED_DEFAULT_CHARSMORE_HSPACING), + (KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT+KEYBOARD_FIXED_DEFAULT_CHARSMORE_VSPACING)*1, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT); + enterBtn->setObjectName("btn_enter"); + enterBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + enterBtn->setIcon(QIcon(":/images/images/enter.svg")); + connect(enterBtn, &KBButton::clicked, this, &CharsMoreWidget::onBtnClicked); + m_mapBtnGeometrys[enterBtn] = enterBtn->geometry(); + // return + KBButton *returnBtn = new KBButton(this); + returnBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1+(KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH+KEYBOARD_FIXED_DEFAULT_CHARSMORE_HSPACING), + (KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT+KEYBOARD_FIXED_DEFAULT_CHARSMORE_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT); + returnBtn->setObjectName("btn_return"); + returnBtn->setText(tr("&&?!")); + returnBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(returnBtn, &KBButton::clicked, this, &CharsMoreWidget::onBtnClicked); + m_mapBtnGeometrys[returnBtn] = returnBtn->geometry(); +} diff --git a/VirtualKeyboard/src/charsmorewidget.h b/VirtualKeyboard/src/charsmorewidget.h new file mode 100644 index 0000000..9971ed3 --- /dev/null +++ b/VirtualKeyboard/src/charsmorewidget.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef CHARSMOREWIDGETS_H +#define CHARSMOREWIDGETS_H + +#include +#include "kbbutton.h" +#include + +class QVBoxLayout; +class QHBoxLayout; +class QScrollArea; +class QFrame; +class CharsMoreWidget : public QWidget +{ + Q_OBJECT +public: + explicit CharsMoreWidget(QWidget *parent = nullptr); + ~CharsMoreWidget(); + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); + +public Q_SLOTS: + void onBtnClicked(QChar charId); + +Q_SIGNALS: + void clicked(int nKeyId); + void specialBtnClicked(QString keyName); + void normalBtnClicked(QChar charId); + +private: + void initUI(); + +private: + QMap m_mapBtnGeometrys; + QMap m_mapSubWidgetListRects; + QVBoxLayout *m_vlayoutBtnList = nullptr; + QScrollArea *m_scrollFrame = nullptr; + QFrame *listFrame = nullptr; +}; + +#endif // CHARSMOREWIDGETS_H diff --git a/VirtualKeyboard/src/charswidget.cpp b/VirtualKeyboard/src/charswidget.cpp new file mode 100644 index 0000000..c66597f --- /dev/null +++ b/VirtualKeyboard/src/charswidget.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "charswidget.h" + +#include "commondef.h" +#include + +CharsWidget::CharsWidget(QWidget *parent/* = nullptr*/) + : QWidget(parent) +{ + this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 + initUI(); +} + +CharsWidget::~CharsWidget() +{ + +} + +void CharsWidget::initUI() +{ + // line 1 + QChar chLine1[] = {'1','2','3','4','5','6','7','8','9','0'}; + for (int n = 0; n < sizeof(chLine1)/sizeof(QChar); n++) { + KBButton *charBtn = new KBButton(this); + charBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L1+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*n, + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + charBtn->setCharId(chLine1[n]); + charBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(charBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[charBtn] = charBtn->geometry(); + } + // backspace + KBButton *backspaceBtn = new KBButton(this); + backspaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L1+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*10, + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + backspaceBtn->setObjectName("btn_backspace"); + backspaceBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(backspaceBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + backspaceBtn->setIcon(QIcon(":/images/images/delet.svg")); + m_mapBtnGeometrys[backspaceBtn] = backspaceBtn->geometry(); + + // line 2 + QChar chLine2[] = {'~','/',':',';','(',')','@','"','\''}; + for (int n = 0; n < sizeof(chLine2)/sizeof(QChar); n++) { + KBButton *charBtn = new KBButton(this); + charBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L2+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*n, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING), + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + charBtn->setCharId(chLine2[n]); + charBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(charBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[charBtn] = charBtn->geometry(); + } + // enter + KBButton *enterBtn = new KBButton(this); + enterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L2+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*9, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING), + KEYBOARD_FIXED_DEFAULT_ENTERBTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + enterBtn->setObjectName("btn_enter"); + enterBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(enterBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + enterBtn->setIcon(QIcon(":/images/images/enter.svg")); + m_mapBtnGeometrys[enterBtn] = enterBtn->geometry(); + + // line 3 + QChar chLine3[] = {'-','_','#','%','$','+','^',',','.','!'}; + for (int n = 0; n < sizeof(chLine3)/sizeof(QChar); n++) { + KBButton *charBtn = new KBButton(this); + charBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L3+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*(n+1), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + charBtn->setCharId(chLine3[n]); + charBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(charBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[charBtn] = charBtn->geometry(); + } + // more + KBButton *moreBtn = new KBButton(this); + moreBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L3, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + moreBtn->setObjectName("btn_more"); + moreBtn->setText(tr("More")); + moreBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(moreBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[moreBtn] = moreBtn->geometry(); + + // line 4 + KBButton *returnBtn = new KBButton(this); + returnBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + returnBtn->setObjectName("btn_return"); + returnBtn->setText(tr("ABC")); + returnBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(returnBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[returnBtn] = returnBtn->geometry(); + + KBButton *numBtn = new KBButton(this); + numBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + numBtn->setObjectName("btn_number"); + numBtn->setText(tr("123")); + numBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(numBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[numBtn] = numBtn->geometry(); + + KBButton *threedBtn = new KBButton(this); + threedBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*2, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + threedBtn->setObjectName("btn_threed"); + threedBtn->setCharId(('&')); + threedBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(threedBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[threedBtn] = threedBtn->geometry(); + + KBButton *spaceBtn = new KBButton(this); + spaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*3, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_SPACEBTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + spaceBtn->setObjectName("btn_space"); + spaceBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_BORDER_NORMAL, + KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + spaceBtn->setIcon(QIcon(":/images/images/space.svg")); + connect(spaceBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[spaceBtn] = spaceBtn->geometry(); + + KBButton *whBtn = new KBButton(this); + whBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*8, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + whBtn->setCharId('?'); + whBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(whBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[whBtn] = whBtn->geometry(); + + KBButton *leftBtn = new KBButton(this); + leftBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*9, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + leftBtn->setObjectName("btn_left"); + leftBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + leftBtn->setIcon(QIcon(":/images/images/left.svg")); + connect(leftBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[leftBtn] = leftBtn->geometry(); + + KBButton *rightBtn = new KBButton(this); + rightBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*10, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + rightBtn->setObjectName("btn_right"); + rightBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + rightBtn->setIcon(QIcon(":/images/images/right.svg")); + connect(rightBtn, &KBButton::clicked, this, &CharsWidget::onBtnClicked); + m_mapBtnGeometrys[rightBtn] = rightBtn->geometry(); +} + +void CharsWidget::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + QMap::iterator itGeometry = m_mapBtnGeometrys.begin(); + for (; itGeometry != m_mapBtnGeometrys.end(); itGeometry ++) { + KBButton *button = itGeometry.key(); + if (button) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + button->setGeometry(newGeometry); + } + } +} + +void CharsWidget::onBtnClicked(QChar charId) +{ + QObject *obj = sender(); + KBButton *btn = static_cast(obj); + QString objName = btn->objectName(); + int lastUnderline = objName.lastIndexOf('_'); + int start = strlen("btn_"); + int keyLength = lastUnderline - start; + QString keyName = objName.mid(start, keyLength); + if (keyName == BTN_RETURN) { + Q_EMIT specialBtnClicked(PAGE_LETTER); + } else if (keyName == "more") { + Q_EMIT specialBtnClicked(PAGE_CHARSMORE); + } else if (keyName == "number") { + Q_EMIT specialBtnClicked(PAGE_NUMBER); + } else if (charId != QChar::Null) { + Q_EMIT normalBtnClicked(charId); + } else { + Q_EMIT specialBtnClicked(keyName); + } +} diff --git a/VirtualKeyboard/src/charswidget.h b/VirtualKeyboard/src/charswidget.h new file mode 100644 index 0000000..1076201 --- /dev/null +++ b/VirtualKeyboard/src/charswidget.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef CHARSWIDGET_H +#define CHARSWIDGET_H + +#include +#include "kbbutton.h" +#include + +class CharsWidget : public QWidget +{ + Q_OBJECT +public: + explicit CharsWidget(QWidget *parent = nullptr); + virtual ~CharsWidget(); + + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); + +public Q_SLOTS: + void onBtnClicked(QChar charId); + +Q_SIGNALS: + void clicked(int nKeyId); + void specialBtnClicked(QString keyName); + void normalBtnClicked(QChar c); + +private: + void initUI(); + +private: + QMap m_mapBtnGeometrys; + +}; + +#endif // CHARSWIDGET_H diff --git a/VirtualKeyboard/src/commondef.h b/VirtualKeyboard/src/commondef.h new file mode 100644 index 0000000..629bd2d --- /dev/null +++ b/VirtualKeyboard/src/commondef.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef COMMONDEF_H +#define COMMONDEF_H + +#define KEYBOARD_PARENT_DEFAULT_WIDTH 1620 +#define KEYBOARD_PARENT_DEFAULT_HEIGHT 1080 + +#define KEYBOARD_FIXED_DEFAULT_WIDTH 1620 +#define KEYBOARD_DRAGSHOW_FIXED_DEFAULT_HEIGHT 428 + +#define KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH 1458 +#define KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT 404 + +#define KEYBOARD_TITLEBTN_DEFAULT_WIDTH 56 +#define KEYBOARD_TITLEBTN_DEFAULT_HEIGHT 56 +#define KEYBOARD_TITLE_DEFAULT_HEIGHT 68 + +#define KEYBOARD_DRAGBTN_DEFAULT_WIDTH 56 +#define KEYBOARD_DRAGBTN_DEFAULT_HEIGHT 4 +#define KEYBOARD_DRAG_DEFAULT_HEIGHT 26 + +#define KEYBOARD_FLOAT_PERCENTAGE 0.9 + +#define KEYBOARD_FIXED_DEFAULT_LMARGIN 22 // 左边距 +#define KEYBOARD_FIXED_DEFAULT_RMARGIN 22 // 右边距 +#define KEYBOARD_FIXED_DEFAULT_TMARGIN 8 // 上边距 +#define KEYBOARD_FIXED_DEFAULT_BMARGIN 16 // 下边距 + +#define KEYBOAED_FIXED_DEFAULT_VSPACING 8 // 垂直间隔 +#define KEYBOAED_FIXED_DEFAULT_HSPACING 8 // 水平间隔 +// letters +#define KEYBOARD_FIXED_DEFAULT_LETTER_L1 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) // 字符页面左起点 +#define KEYBOARD_FIXED_DEFAULT_LETTER_L2 (KEYBOARD_FIXED_DEFAULT_LMARGIN+72) // 字符页面左起点 +#define KEYBOARD_FIXED_DEFAULT_LETTER_L3 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) // 字符页面左起点 +#define KEYBOARD_FIXED_DEFAULT_LETTER_L4 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) // 字符页面左起点 +#define KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH 136 // 字符按钮宽度 +#define KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT 72 // 字符按钮高度 +#define KEYBOARD_FIXED_DEFAULT_LETTER_ENTWIDTH 208 +#define KEYBOARD_FIXED_DEFAULT_LETTER_SPCWIDTH 712 +#define KEYBOARD_FIXED_DEFAULT_TITLEBTN_WIDTH 56 +#define KEYBOARD_FIXED_DEFAULT_TITLEBTN_HEIGHT 56 + +#define KEYBOARD_FIXED_DEFAULT_ENTERBTN_WIDTH 208 +#define KEYBOARD_FIXED_DEFAULT_SPACEBTN_WIDTH 712 + +#define KEYBOARD_LETTER_COLOR_NORMAL "#FFFFFF" +#define KEYBOARD_LETTER_COLOR_PRESSED "#DDE0E4" +#define KEYBOARD_LETTER_COLOR_BORDER_NORMAL "#95A0AD" +#define KEYBOARD_LETTER_COLOR_BORDER_PRESSED "#95A0AD" + +#define KEYBOARD_OTHER_COLOR_NORMAL "#CED3D9" +#define KEYBOARD_OTHER_COLOR_PRESSED "#3790FA" +#define KEYBOARD_OTHER_COLOR_BORDER_NORMAL "#95A0AD" +#define KEYBOARD_OTHER_COLOR_BORDER_PRESSED "#1174E5" + +#define KEYBOARD_FONT_COLOR_PRESS "#262626" +#define KEYBOARD_OTHER_FONT_COLOR_PRESS "#FFFFFF" + +//numbers +#define KEYBOARD_FIXED_DEFAULT_NUMBER_L1 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) +#define KEYBOARD_FIXED_DEFAULT_NUMBER_L2 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) +#define KEYBOARD_FIXED_DEFAULT_NUMBER_L3 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) +#define KEYBOARD_FIXED_DEFAULT_NUMBER_L4 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) + +#define KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH 306 // 数字按钮宽度 +#define KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT 72 // 数字按钮高度 +#define KEYBOARD_FIXED_DEFAULT_NUMBER_CHARS_HEIGHT 230 // 数字字符按钮高度 + +// chars more + +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_L1 (KEYBOARD_FIXED_DEFAULT_LMARGIN+0) +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_HSPACING 16 +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_VSPACING 16 + +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_COLS 6 +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_WIDTH 1350 // 字符列表宽度 +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_LIST_HEIGHT 315 // 字符列表高度 +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_WIDTH 214 // 按钮宽度 +#define KEYBOARD_FIXED_DEFAULT_CHARSMORE_BTN_HEIGHT 94 // 功能按钮高度 +#define KEYBOARD_FIXED_DEFAULT_NORMAL_CHARSMORE_BTN_HEIGHT 80 // 符号按钮高度 + +//iconsize +#define KEYBOARD_FIXED_DEFAULT_ICONSIZE QSize(25, 25) + +//keyName +#define PAGE_CHAR "page_char" +#define PAGE_NUMBER "page_number" +#define PAGE_CHARSMORE "page_charmore" +#define PAGE_LETTER "page_letter" +#define BTN_FLOAT "float" +#define BTN_CLOSE "close" +#define BTN_RETURN "return" +#define BTN_BACK "backspace" +#define BTN_ENTER "enter" +#define BTN_SHIFT "shift" +#define BTN_CTRL "ctrl" +#define BTN_ALT "alt" +#define BTN_SPACE "space" +#define BTN_RIGHT "right" +#define BTN_LEFT "left" +#define BTN_CAPSLOCK "capslock" + + + +#endif // COMMONDEF_H diff --git a/VirtualKeyboard/src/dragwidget.cpp b/VirtualKeyboard/src/dragwidget.cpp new file mode 100644 index 0000000..db8a332 --- /dev/null +++ b/VirtualKeyboard/src/dragwidget.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "dragwidget.h" +#include +#include +#include +#include "commondef.h" + +DragWidget::DragWidget(QWidget *parent/* = nullptr*/) + : QWidget(parent) +{ + setAttribute(Qt::WA_TranslucentBackground);//背景透明 + initUI(); +} + +DragWidget::~DragWidget() +{ + +} + +void DragWidget::initUI() +{ + setFixedHeight(KEYBOARD_DRAG_DEFAULT_HEIGHT); + + m_labelDrag = new QLabel(this); + m_labelDrag->setPixmap(QPixmap(":/images/images/drag.svg")); + m_labelDrag->setGeometry((KEYBOARD_PARENT_DEFAULT_WIDTH - KEYBOARD_TITLEBTN_DEFAULT_WIDTH)/2, + (this->height() - KEYBOARD_TITLEBTN_DEFAULT_HEIGHT)/2, + KEYBOARD_TITLEBTN_DEFAULT_WIDTH, KEYBOARD_TITLEBTN_DEFAULT_HEIGHT); + m_mapSubGeometrys[m_labelDrag] = m_labelDrag->geometry(); +} + +void DragWidget::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + setFixedHeight(KEYBOARD_DRAG_DEFAULT_HEIGHT*lfHeightScale); + QMap::iterator itGeometry = m_mapSubGeometrys.begin(); + for (; itGeometry != m_mapSubGeometrys.end(); itGeometry ++) { + QLabel *label = itGeometry.key(); + if (label) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + label->setGeometry(newGeometry); + } + } +} diff --git a/VirtualKeyboard/src/virtualkeyboard.h b/VirtualKeyboard/src/dragwidget.h similarity index 58% rename from VirtualKeyboard/src/virtualkeyboard.h rename to VirtualKeyboard/src/dragwidget.h index 8bdbc52..e8b1527 100644 --- a/VirtualKeyboard/src/virtualkeyboard.h +++ b/VirtualKeyboard/src/dragwidget.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * Copyright (C) 2023 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 @@ -15,32 +15,29 @@ * along with this program; if not, see . * **/ -#ifndef VIRTUALKEYBOARD_H -#define VIRTUALKEYBOARD_H +#ifndef DRAGWIDGET_H +#define DRAGWIDGET_H #include -#include +#include +#include -#include "keyboardwidget.h" -#include "cursormonitor.h" - -class VirtualKeyboard : public QWidget +class DragWidget : public QWidget { Q_OBJECT public: - explicit VirtualKeyboard(QWidget *parent = 0); + DragWidget(QWidget *parent = nullptr); + virtual ~DragWidget(); + +public: + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); private: - void adjustGeometry(int screen); - -Q_SIGNALS: - void aboutToClose(); + void initUI(); private: - KeyboardWidget *keyboardWidget; - CursorMonitor *cursorMonitor; - bool isApplication; + QLabel *m_labelDrag = nullptr; + QMap m_mapSubGeometrys; }; - -#endif // VIRTUALKEYBOARD_H +#endif // DRAGWIDGET_H diff --git a/VirtualKeyboard/src/fakekeyboard.h b/VirtualKeyboard/src/fakekeyboard.h index 7c29ce5..65a22ce 100644 --- a/VirtualKeyboard/src/fakekeyboard.h +++ b/VirtualKeyboard/src/fakekeyboard.h @@ -71,7 +71,8 @@ public: UP, DOWN, LEFT, - RIGHT + RIGHT, + CAPSLOCK }; Q_ENUM(FUNCKEY) static QString getKeyName(int key) diff --git a/VirtualKeyboard/src/images/backspace.svg b/VirtualKeyboard/src/images/backspace.svg deleted file mode 100644 index 092d72d..0000000 --- a/VirtualKeyboard/src/images/backspace.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/VirtualKeyboard/src/images/backspace_click.svg b/VirtualKeyboard/src/images/backspace_click.svg deleted file mode 100644 index 4a9d7fa..0000000 --- a/VirtualKeyboard/src/images/backspace_click.svg +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - diff --git a/VirtualKeyboard/src/images/capslock.svg b/VirtualKeyboard/src/images/capslock.svg deleted file mode 100644 index a5a367c..0000000 --- a/VirtualKeyboard/src/images/capslock.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/VirtualKeyboard/src/images/capslock_click.svg b/VirtualKeyboard/src/images/capslock_click.svg deleted file mode 100644 index 36ae8f8..0000000 --- a/VirtualKeyboard/src/images/capslock_click.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/VirtualKeyboard/src/images/capslock_hl.svg b/VirtualKeyboard/src/images/capslock_hl.svg deleted file mode 100644 index 4f8870a..0000000 --- a/VirtualKeyboard/src/images/capslock_hl.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/VirtualKeyboard/src/images/capslock_hl_click.svg b/VirtualKeyboard/src/images/capslock_hl_click.svg deleted file mode 100644 index 65b0a21..0000000 --- a/VirtualKeyboard/src/images/capslock_hl_click.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/VirtualKeyboard/src/images/close.svg b/VirtualKeyboard/src/images/close.svg index c509415..ba56780 100644 --- a/VirtualKeyboard/src/images/close.svg +++ b/VirtualKeyboard/src/images/close.svg @@ -1,22 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/VirtualKeyboard/src/images/close_click.svg b/VirtualKeyboard/src/images/close_click.svg deleted file mode 100644 index d143065..0000000 --- a/VirtualKeyboard/src/images/close_click.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/VirtualKeyboard/src/images/delet.svg b/VirtualKeyboard/src/images/delet.svg new file mode 100644 index 0000000..b290563 --- /dev/null +++ b/VirtualKeyboard/src/images/delet.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/VirtualKeyboard/src/images/down.svg b/VirtualKeyboard/src/images/down.svg deleted file mode 100644 index 73361dd..0000000 --- a/VirtualKeyboard/src/images/down.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - -画板 15 - - - - diff --git a/VirtualKeyboard/src/images/down_click.svg b/VirtualKeyboard/src/images/down_click.svg deleted file mode 100644 index 9140b38..0000000 --- a/VirtualKeyboard/src/images/down_click.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/VirtualKeyboard/src/images/drag.svg b/VirtualKeyboard/src/images/drag.svg new file mode 100644 index 0000000..9bc4dac --- /dev/null +++ b/VirtualKeyboard/src/images/drag.svg @@ -0,0 +1,3 @@ + + + diff --git a/VirtualKeyboard/src/images/enter.svg b/VirtualKeyboard/src/images/enter.svg index 5cbc51d..9c09d11 100644 --- a/VirtualKeyboard/src/images/enter.svg +++ b/VirtualKeyboard/src/images/enter.svg @@ -1,11 +1,4 @@ - - - - - - - + + + + diff --git a/VirtualKeyboard/src/images/enter_click.svg b/VirtualKeyboard/src/images/enter_click.svg deleted file mode 100644 index 106cc7b..0000000 --- a/VirtualKeyboard/src/images/enter_click.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/VirtualKeyboard/src/images/float-restore.svg b/VirtualKeyboard/src/images/float-restore.svg new file mode 100644 index 0000000..3349d01 --- /dev/null +++ b/VirtualKeyboard/src/images/float-restore.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/VirtualKeyboard/src/images/float.svg b/VirtualKeyboard/src/images/float.svg new file mode 100644 index 0000000..a24e50f --- /dev/null +++ b/VirtualKeyboard/src/images/float.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/VirtualKeyboard/src/images/left.svg b/VirtualKeyboard/src/images/left.svg index 6ac0fa8..f614a70 100644 --- a/VirtualKeyboard/src/images/left.svg +++ b/VirtualKeyboard/src/images/left.svg @@ -1,7 +1,3 @@ - - - -画板 19 - - + + + diff --git a/VirtualKeyboard/src/images/left_click.svg b/VirtualKeyboard/src/images/left_click.svg deleted file mode 100644 index edfd291..0000000 --- a/VirtualKeyboard/src/images/left_click.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - -画板 20 - - diff --git a/VirtualKeyboard/src/images/rectangle.svg b/VirtualKeyboard/src/images/rectangle.svg new file mode 100644 index 0000000..7ffef85 --- /dev/null +++ b/VirtualKeyboard/src/images/rectangle.svg @@ -0,0 +1,3 @@ + + + diff --git a/VirtualKeyboard/src/images/right.svg b/VirtualKeyboard/src/images/right.svg index 62c301c..9922eb7 100644 --- a/VirtualKeyboard/src/images/right.svg +++ b/VirtualKeyboard/src/images/right.svg @@ -1,6 +1,3 @@ - - - - - + + + diff --git a/VirtualKeyboard/src/images/right_click.svg b/VirtualKeyboard/src/images/right_click.svg deleted file mode 100644 index 5ba0ec6..0000000 --- a/VirtualKeyboard/src/images/right_click.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/VirtualKeyboard/src/images/shift.svg b/VirtualKeyboard/src/images/shift.svg new file mode 100644 index 0000000..6a3b438 --- /dev/null +++ b/VirtualKeyboard/src/images/shift.svg @@ -0,0 +1,3 @@ + + + diff --git a/VirtualKeyboard/src/images/shift_lock.svg b/VirtualKeyboard/src/images/shift_lock.svg new file mode 100644 index 0000000..09d5c99 --- /dev/null +++ b/VirtualKeyboard/src/images/shift_lock.svg @@ -0,0 +1,4 @@ + + + + diff --git a/VirtualKeyboard/src/images/space.svg b/VirtualKeyboard/src/images/space.svg new file mode 100644 index 0000000..b5b9769 --- /dev/null +++ b/VirtualKeyboard/src/images/space.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/VirtualKeyboard/src/images/super.svg b/VirtualKeyboard/src/images/super.svg deleted file mode 100644 index c847e44..0000000 --- a/VirtualKeyboard/src/images/super.svg +++ /dev/null @@ -1 +0,0 @@ -画板 11 \ No newline at end of file diff --git a/VirtualKeyboard/src/images/super_click.svg b/VirtualKeyboard/src/images/super_click.svg deleted file mode 100644 index 7fcc495..0000000 --- a/VirtualKeyboard/src/images/super_click.svg +++ /dev/null @@ -1 +0,0 @@ -画板 12 \ No newline at end of file diff --git a/VirtualKeyboard/src/images/unlock.svg b/VirtualKeyboard/src/images/unlock.svg new file mode 100644 index 0000000..17271fd --- /dev/null +++ b/VirtualKeyboard/src/images/unlock.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/VirtualKeyboard/src/images/up.svg b/VirtualKeyboard/src/images/up.svg deleted file mode 100644 index d5613b2..0000000 --- a/VirtualKeyboard/src/images/up.svg +++ /dev/null @@ -1,9 +0,0 @@ - - - -画板 13 - - - - diff --git a/VirtualKeyboard/src/images/up_click.svg b/VirtualKeyboard/src/images/up_click.svg deleted file mode 100644 index 225e401..0000000 --- a/VirtualKeyboard/src/images/up_click.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/VirtualKeyboard/src/kbbutton.cpp b/VirtualKeyboard/src/kbbutton.cpp new file mode 100644 index 0000000..d593793 --- /dev/null +++ b/VirtualKeyboard/src/kbbutton.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "kbbutton.h" +#include "commondef.h" +#include +#include + +KBButton::KBButton(QWidget *parent/* = nullptr*/) + : QPushButton(parent) +{ + this->installEventFilter(this); + this->setIconSize(KEYBOARD_FIXED_DEFAULT_ICONSIZE); + this->setFocusPolicy(Qt::NoFocus); + connect(this, &QPushButton::clicked, this, [&,this]() { + if (m_charId.isLetter()) { + if (m_isShift) { + if (m_isCaps) { + m_charId = m_charId.toLower(); + } else { + m_charId = m_charId.toUpper(); + } + } else { + if (m_isCaps) { + m_charId = m_charId.toUpper(); + } else { + m_charId = m_charId.toLower(); + } + } + } + Q_EMIT clicked(m_charId); + }); +} + +KBButton::~KBButton() +{ + +} + +bool KBButton::eventFilter(QObject *watched, QEvent *event) +{ + if (m_clrNormal == KEYBOARD_LETTER_COLOR_NORMAL) + return QPushButton::eventFilter(watched, event); + if (event->type() == QEvent::MouseButtonPress) { + QPixmap pressIcon = this->icon().pixmap(QSize(24, 24)); + pressIcon = drawSymbolicColoredPixmap(pressIcon, "white"); + this->setIcon(pressIcon); + } else if (event->type() == QEvent::MouseButtonRelease) { + QPixmap releaseIcon = this->icon().pixmap(QSize(24, 24)); + releaseIcon = drawSymbolicColoredPixmap(releaseIcon, "black"); + this->setIcon(releaseIcon); + } + return QPushButton::eventFilter(watched, event); +} + +void KBButton::setCharId(QChar charId) +{ + m_charId = charId; + if (charId == '&') { + setText("&&"); + } else { + setText(m_charId); + } +} + +void KBButton::updateStyleSheet(QString clrNormal, QString clrHover, QString clrChecked, QString clrBoard, QString clrBoardPress, QString clrFontPress, int radius, bool is_lock) +{ + QString strBorderRadius = QString("border-top-left-radius: %1px; border-top-right-radius: %2px; border-bottom-right-radius: %3px;border-bottom-left-radius: %4px;") + .arg((radius&BORDER_RADIUS_LT)?8:0) + .arg((radius&BORDER_RADIUS_TR)?8:0) + .arg((radius&BORDER_RADIUS_RB)?8:0) + .arg((radius&BORDER_RADIUS_LB)?8:0); + if (!is_lock) { + setStyleSheet(QString("QPushButton{%1 border: 2px solid %2; border-width: 0px 0px 2px 0px; background: %3; color: #262626}" + // "QPushButton:hover{border: 2px solid %4; border-width: 2px 0px 0px 0px; background: %5;}" + "QPushButton:pressed{border: 2px solid %4; border-width: 2px 0px 0px 0px; background: %5; color: %6}" + "QPushButton:checked{border: 2px solid %7; border-width: 2px 0px 0px 0px; background: %8; color: %9}") + .arg(strBorderRadius).arg(clrBoard).arg(clrNormal).arg(clrBoardPress).arg(clrHover).arg(clrFontPress).arg(clrBoardPress).arg(clrChecked).arg(clrFontPress) + ); + } else { + setStyleSheet(QString("QPushButton{%1 border: 2px solid %2; border-width: 0px 0px 2px 0px; background: %3; color: #FFFFFF}" + // "QPushButton:hover{border: 2px solid %4; border-width: 2px 0px 0px 0px; background: %5;}" + "QPushButton:pressed{border: 2px solid %4; border-width: 2px 0px 0px 0px; background: %5; color: %6}" + "QPushButton:checked{border: 2px solid %7; border-width: 2px 0px 0px 0px; background: %8; color: %9}") + .arg(strBorderRadius).arg(clrBoard).arg(clrNormal).arg(clrBoardPress).arg(clrHover).arg(clrFontPress).arg(clrBoardPress).arg(clrChecked).arg(clrFontPress) + ); + } + m_clrBoard = clrBoard; + m_clrNormal = clrNormal; + m_clrBoardPress = clrBoardPress; + m_clrHover = clrHover; + m_clrChecked = clrChecked; + if (m_clrNormal == KEYBOARD_LETTER_COLOR_NORMAL) { + sysFont.setPixelSize(32); + this->setFont(sysFont); + this->setIconSize(QSize(32, 32)); + } else { + sysFont.setPixelSize(24); + this->setFont(sysFont); + this->setIconSize(QSize(24, 24)); + } +} + +QPixmap KBButton::drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor) +{ + QImage img = source.toImage(); + for (int x = 0; x < img.width(); x++) { + for (int y = 0; y < img.height(); y++) { + auto color = img.pixelColor(x, y); + if (color.alpha() > 0) { + if ( "white" == cgColor) { + color.setRed(255); + color.setGreen(255); + color.setBlue(255); + img.setPixelColor(x, y, color); + } else if( "black" == cgColor) { + color.setRed(0); + color.setGreen(0); + color.setBlue(0); + img.setPixelColor(x, y, color); + } else if ("gray"== cgColor) { + color.setRed(152); + color.setGreen(163); + color.setBlue(164); + img.setPixelColor(x, y, color); + } else if ("blue" == cgColor){ + color.setRed(61); + color.setGreen(107); + color.setBlue(229); + img.setPixelColor(x, y, color); + } else { + return source; + } + } + } + } + return QPixmap::fromImage(img); +} + +void KBButton::setShiftState(bool isShift) +{ + if (m_isShift != isShift) { + if (m_charId.isLetter()) { + if (isShift) { + setText(m_charId.toUpper()); + } else { + setText(m_charId.toLower()); + } + } + m_isShift = isShift; + } +} + +void KBButton::setCapsStatus(bool isCaps) +{ + m_isCaps = isCaps; + setShiftState(m_isCaps); +} + +void KBButton::setCtrlState(bool isCtrl) +{ + +} + +void KBButton::setAltState(bool isAlt) +{ + +} diff --git a/VirtualKeyboard/src/kbbutton.h b/VirtualKeyboard/src/kbbutton.h new file mode 100644 index 0000000..923fa2e --- /dev/null +++ b/VirtualKeyboard/src/kbbutton.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef KBBUTTON_H +#define KBBUTTON_H + +#include + +class KBButton : public QPushButton +{ + Q_OBJECT +public: + enum BORDER_RADIUS{ + BORDER_RADIUS_NONE, + BORDER_RADIUS_LT = 1, + BORDER_RADIUS_TR = 2, + BORDER_RADIUS_RB = 4, + BORDER_RADIUS_LB = 8, + BORDER_RADIUS_ALL = 0xF, + }; + KBButton(QWidget *parent = nullptr); + virtual ~KBButton(); + + void setCharId(QChar charId); + void updateStyleSheet(QString clrNormal, QString clrHover, QString clrChecked, QString clrBoard, QString clrBoardPress, QString clrFontPress, int radius = BORDER_RADIUS_ALL, bool is_lock = false); + void setShiftState(bool isShift); + void setCapsStatus(bool isCaps); + void setCtrlState(bool isCtrl); + void setAltState(bool isAlt); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +Q_SIGNALS: + void clicked(QChar charId); + +private: + QPixmap drawSymbolicColoredPixmap(const QPixmap &source, QString cgColor); + +private: + int m_nKeyId = -1; + bool m_isShift = false; + bool m_isCtrl = false; + bool m_isAlt = false; + bool m_isCaps = false; + QChar m_charId = QChar::Null; + QString m_clrBoard; + QString m_clrNormal; + QString m_clrBoardPress; + QString m_clrHover; + QString m_clrChecked; + QFont sysFont; +}; + +#endif // KBBUTTON_H diff --git a/VirtualKeyboard/src/kbtitle.cpp b/VirtualKeyboard/src/kbtitle.cpp new file mode 100644 index 0000000..1d270cc --- /dev/null +++ b/VirtualKeyboard/src/kbtitle.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "kbtitle.h" +#include +#include +#include "commondef.h" +#include + +KBTitle::KBTitle(QWidget *parent/* = nullptr*/) + : QWidget(parent) +{ + setAttribute(Qt::WA_TranslucentBackground);//背景透明 + initUI(); + initConnections(); +} + +KBTitle::~KBTitle() +{ + +} + +void KBTitle::initUI() +{ + setFixedHeight(KEYBOARD_TITLE_DEFAULT_HEIGHT); + QString strBtnStyle = "QPushButton{ text-align:center; color: rgb(255, 255, 255, 255); border: none; border-radius: 4px; outline: none;}" + "QPushButton:hover{ background-color: rgb(255,255,255,15%); }" + "QPushButton::pressed { background-color: rgba(255,255,255,40%); }" + "QPushButton::checked { background-color: rgba(255,255,255,40%); }"; + + m_btnFloat = new QPushButton(this); + m_btnFloat->setFlat(true); + m_btnFloat->setIcon(QIcon(":/images/images/float.svg")); + m_btnFloat->setObjectName("btn_float"); + m_btnFloat->setIconSize(KEYBOARD_FIXED_DEFAULT_ICONSIZE); + m_btnFloat->setGeometry(1484, 8, KEYBOARD_TITLEBTN_DEFAULT_WIDTH, KEYBOARD_TITLEBTN_DEFAULT_HEIGHT); + m_btnFloat->setStyleSheet(strBtnStyle); + m_mapSubGeometrys[m_btnFloat] = m_btnFloat->geometry(); + + m_btnClose = new QPushButton(this); + m_btnClose->setFlat(true); + m_btnClose->setIcon(QIcon(":/images/images/close.svg")); + m_btnClose->setIconSize(KEYBOARD_FIXED_DEFAULT_ICONSIZE); + m_btnClose->setObjectName("btn_close"); + m_btnClose->setGeometry(1548, 8, KEYBOARD_TITLEBTN_DEFAULT_WIDTH, KEYBOARD_TITLEBTN_DEFAULT_HEIGHT); + m_btnClose->setStyleSheet(strBtnStyle); + m_mapSubGeometrys[m_btnClose] = m_btnClose->geometry(); +} + +void KBTitle::initConnections() +{ + connect(m_btnFloat, &QPushButton::clicked, this, &KBTitle::onBtnClicked); + connect(m_btnClose, &QPushButton::clicked, this, &KBTitle::onBtnClicked); +} + +void KBTitle::onBtnClicked() +{ + QObject *obj = sender(); + QPushButton *btn = static_cast(obj); + QString objName = btn->objectName(); + int lastUnderline = objName.lastIndexOf('_'); + int start = strlen("btn_"); + int keyLength = lastUnderline - start; + QString keyName = objName.mid(start, keyLength); + if (keyName == BTN_FLOAT) { + if (floatStatus) { + btn->setIcon(QIcon(":/images/images/float.svg")); + } else { + btn->setIcon(QIcon(":/images/images/float-restore.svg")); + } + floatStatus = !floatStatus; + } + + Q_EMIT btnClicked(keyName); +} + +void KBTitle::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + setFixedHeight(KEYBOARD_TITLE_DEFAULT_HEIGHT*lfHeightScale); + QMap::iterator itGeometry = m_mapSubGeometrys.begin(); + for (; itGeometry != m_mapSubGeometrys.end(); itGeometry ++) { + QPushButton *button = itGeometry.key(); + if (button) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + button->setGeometry(newGeometry); + } + } +} diff --git a/VirtualKeyboard/src/kbtitle.h b/VirtualKeyboard/src/kbtitle.h new file mode 100644 index 0000000..cda3263 --- /dev/null +++ b/VirtualKeyboard/src/kbtitle.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef KBTITLE_H +#define KBTITLE_H + +#include +#include +#include + +class KBTitle : public QWidget +{ + Q_OBJECT +public: + KBTitle(QWidget *parent = nullptr); + virtual ~KBTitle(); + +public: + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); + +public Q_SLOTS: + void onBtnClicked(); + +Q_SIGNALS: + void btnClicked(QString keyName); + +private: + void initUI(); + void initConnections(); + +private: + QPushButton *m_btnFloat = nullptr; + QPushButton *m_btnClose = nullptr; + QMap m_mapSubGeometrys; + bool floatStatus = false; +}; + +#endif // KBTITLE_H diff --git a/VirtualKeyboard/src/keyboard.qrc b/VirtualKeyboard/src/keyboard.qrc index 4e38067..a5e482e 100644 --- a/VirtualKeyboard/src/keyboard.qrc +++ b/VirtualKeyboard/src/keyboard.qrc @@ -1,27 +1,17 @@ - - keyboard.qss - - images/backspace_click.svg - images/backspace.svg - images/capslock_click.svg - images/capslock_hl.svg - images/capslock.svg - images/down_click.svg - images/down.svg - images/enter_click.svg images/enter.svg - images/left_click.svg images/left.svg - images/right_click.svg images/right.svg - images/super_click.svg - images/super.svg - images/up.svg - images/close_click.svg images/close.svg - images/capslock_hl_click.svg - images/up_click.svg + images/unlock.svg + images/space.svg + images/shift.svg + images/float.svg + images/float-restore.svg + images/drag.svg + images/delet.svg + images/shift_lock.svg + images/rectangle.svg diff --git a/VirtualKeyboard/src/keyboard.qss b/VirtualKeyboard/src/keyboard.qss deleted file mode 100644 index e91e23c..0000000 --- a/VirtualKeyboard/src/keyboard.qss +++ /dev/null @@ -1,37 +0,0 @@ -QPushButton -{ - border: none; - font: 24px; - color: white; - background: #35322f; - border-radius: 5px; -} - -QPushButton::pressed -{ - color: gray; - background: #2a2826; -} - -#btn_backspace, #btn_enter, #btn_shift_l, -#btn_shift_r, #btn_ctrl_l, #btn_ctrl_r, -#btn_alt_l, #btn_alt_r, #btn_super -{ - font: 16px; - background: #1e1b18 -} - -#btn_backspace::pressed, #btn_enter::pressed, #btn_shift_l::pressed, -#btn_shift_r::pressed, #btn_ctrl_l::pressed, #btn_ctrl_r::pressed, -#btn_alt_l::pressed, #btn_alt_r::pressed, #btn_super::pressed -{ - background: #181613; - color: gray; -} - -#btn_letter, #btn_symbol, #btn_number, -#btn_insert, #btn_delete, #btn_home, -#btn_end, #btn_pgup, #btn_pgdn, #btn_close -{ - font: 16px; -} diff --git a/VirtualKeyboard/src/keyboardwidget.cpp b/VirtualKeyboard/src/keyboardwidget.cpp deleted file mode 100644 index a13adec..0000000 --- a/VirtualKeyboard/src/keyboardwidget.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright (C) 2018 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 3, 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, see . - * -**/ -#include "keyboardwidget.h" -#include "ui_keyboardwidget.h" -#include -#include -#include -#include -#include "x11keyboard.h" -#include "qtkeyboard.h" - -#define SYMBOL_KEY_COUNT 29 -#define SYMBOL_PAGE_COUNT 2 - -#define BUTTON_BG "QPushButton{background:#1E1B18}" -#define BUTTON_BG_PRESSED "QPushButton{background: #181613;}" -#define BUTTON_BG_HL "QPushButton{background:#80c342}" -#define BUTTON_BG_HL_PRESSED "QPushButton{background:#486E25}" - - -QChar symbols[SYMBOL_PAGE_COUNT][SYMBOL_KEY_COUNT] = - { {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', - 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', - 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'}, - {'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', - '`', '-', '=', '[', ']', '\\', '|', '{', '}', - '~','<', '>', ':', ';', '\'', '"', '_', '+', '?'}}; - - -KeyboardWidget::KeyboardWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::KeyboardWidget), - capsLock(false), - isShift(false), - page(0) -{ - if(QX11Info::isPlatformX11()){ - vKeyboard = new X11Keyboard(this); - }else{ - vKeyboard = new QtKeyboard(this); - } - connect(this, SIGNAL(keyPressed(QChar)), - vKeyboard, SLOT(onKeyPressed(QChar))); - connect(this, SIGNAL(keyPressed(FuncKey::FUNCKEY)), - vKeyboard, SLOT(onKeyPressed(FuncKey::FUNCKEY))); - - ui->setupUi(this); - bindSingal(); - setDefaultIcon(); -} - -KeyboardWidget::~KeyboardWidget() -{ - delete ui; -} - -void KeyboardWidget::resizeEvent(QResizeEvent */*event*/) -{ - int w = width(); - int h = height(); - int mainLeftMargin = ui->hl_main->contentsMargins().left(); - int mainRightMargin = ui->hl_main->contentsMargins().right(); - int mainTopMargin = ui->hl_main->contentsMargins().left(); - int mainBottomMargin = ui->hl_main->contentsMargins().right(); - int mainSpacing = ui->hl_main->spacing(); - int itemSpacing = ui->hl_1->spacing(); - - int btnWidthCount = w - 11 * itemSpacing - mainSpacing- mainLeftMargin - mainRightMargin; - int btnHeightCount = h - 3 * itemSpacing - mainTopMargin - mainBottomMargin; - double btnWidth = btnWidthCount / 12; - double btnHeight = btnHeightCount / 4; - for(int i = 0; i <= 28; i++) { - QString btnObjName = "btn_" + QString::number(i); - QPushButton *btn = ui->page_letter->findChild(btnObjName); - btn->setFixedSize(btnWidth, btnHeight); - } - ui->btn_ctrl_l->setFixedSize(btnWidth * 1.3, btnHeight); - ui->btn_ctrl_r->setFixedSize(btnWidth * 1.3, btnHeight); - ui->btn_alt_l->setFixedSize(btnWidth, btnHeight); - ui->btn_alt_r->setFixedSize(btnWidth, btnHeight); - ui->btn_super->setFixedSize(btnWidth, btnHeight); - ui->btn_shift_l->setFixedSize(btnWidth, btnHeight); - ui->btn_shift_r->setFixedHeight(btnHeight); - ui->spacer_2->changeSize(btnWidth / 2, 20); - - - for(int i = 1; i <= 9; i++) { - QString btnObjName = "btn_num_" + QString::number(i); - QPushButton *btn = ui->page_number->findChild(btnObjName); - btn->setFixedWidth(btnWidth); - } - ui->btn_backspace_num->setFixedSize(btnWidth,btnHeight); - ui->btn_insert->setFixedWidth(btnWidth); - ui->btn_delete->setFixedWidth(btnWidth); - ui->btn_home->setFixedWidth(btnWidth); - ui->btn_end->setFixedWidth(btnWidth); - ui->btn_pgup->setFixedWidth(btnWidth); - ui->btn_pgdn->setFixedWidth(btnWidth); - ui->btn_up->setFixedSize(btnWidth,btnHeight); - ui->btn_down->setFixedSize(btnWidth,btnHeight); - ui->btn_left->setFixedSize(btnWidth,btnHeight); - ui->btn_right->setFixedSize(btnWidth,btnHeight); - - ui->btn_close->setFixedHeight(btnHeight); - ui->btn_letter->setFixedHeight(btnHeight); - ui->btn_symbol->setFixedHeight(btnHeight); - ui->btn_number->setFixedHeight(btnHeight); - - setIconSize(); -} - -float hScale = 0.6; -float wScale = hScale; -#define SET_ICON_SIZE_SCALE(btn) \ - ui->btn_##btn->setIconSize(QSize(ui->btn_##btn->width() * hScale, ui->btn_##btn->height() * wScale)); - -#define SET_ICON_SIZE(btn) \ - ui->btn_##btn->setIconSize(QSize(ui->btn_##btn->width(), ui->btn_##btn->height())); - -#define SET_SHIFT_ICON_SIZE_SCALE(btn) \ - ui->btn_##btn->setIconSize(QSize(ui->btn_##btn->height() * 0.4, ui->btn_##btn->height() * 0.4)); - -#define SET_ENTER_ICON_SIZE_SCALE(btn) \ - ui->btn_##btn->setIconSize(QSize(ui->btn_##btn->width() * 0.4, ui->btn_##btn->height() * 0.4)); - -void KeyboardWidget::setIconSize() -{ - SET_ICON_SIZE_SCALE(backspace); - SET_ICON_SIZE_SCALE(backspace_num); - SET_ENTER_ICON_SIZE_SCALE(enter); - SET_ICON_SIZE_SCALE(enter_num); - SET_ICON_SIZE_SCALE(close); - SET_ICON_SIZE_SCALE(super); - - SET_SHIFT_ICON_SIZE_SCALE(shift_l); - SET_SHIFT_ICON_SIZE_SCALE(shift_r); - SET_ICON_SIZE(up); - SET_ICON_SIZE(down); - SET_ICON_SIZE(left); - SET_ICON_SIZE(right); -} - -void KeyboardWidget::bindSingal() -{ - for(auto obj : ui->page_letter->children()) { - if(obj->metaObject()->className() == QString("QPushButton")) { - QPushButton *btn = static_cast(obj); - btn->setFocusPolicy(Qt::NoFocus); - connect(btn, &QPushButton::clicked, this, &KeyboardWidget::onButtonClicked); - connect(btn, &QPushButton::pressed, this, &KeyboardWidget::onButtonPressed); - connect(btn, &QPushButton::released, this, &KeyboardWidget::onButtonReleased); - } - } - for(auto obj : ui->page_number->children()) { - if(obj->metaObject()->className() == QString("QPushButton")) { - QPushButton *btn = static_cast(obj); - btn->setFocusPolicy(Qt::NoFocus); - connect(btn, &QPushButton::clicked, this, &KeyboardWidget::onButtonClicked); - connect(btn, &QPushButton::pressed, this, &KeyboardWidget::onButtonPressed); - connect(btn, &QPushButton::released, this, &KeyboardWidget::onButtonReleased); - } - } - ui->btn_close->setFocusPolicy(Qt::NoFocus); - ui->btn_letter->setFocusPolicy(Qt::NoFocus); - ui->btn_symbol->setFocusPolicy(Qt::NoFocus); - ui->btn_number->setFocusPolicy(Qt::NoFocus); - - connect(ui->btn_letter, &QPushButton::clicked, this, [&] { - ui->stackedWidget->setCurrentWidget(ui->page_letter); - page = 0; - switchPage(); - }); - connect(ui->btn_symbol, &QPushButton::clicked, this, [&] { - ui->stackedWidget->setCurrentWidget(ui->page_letter); - page = 1; - switchPage(); - }); - connect(ui->btn_number, &QPushButton::clicked, this, [&] { - ui->stackedWidget->setCurrentWidget(ui->page_number); - }); - connect(ui->btn_close, &QPushButton::clicked, - this, &KeyboardWidget::aboutToClose); - - connect(ui->btn_close, &QPushButton::pressed, - this, &KeyboardWidget::onButtonPressed); - connect(ui->btn_close, &QPushButton::released, - this, &KeyboardWidget::onButtonReleased); -} - -void KeyboardWidget::setDefaultIcon() -{ - ui->btn_backspace->setIcon(QIcon(":/images/images/backspace.svg")); - ui->btn_backspace_num->setIcon(QIcon(":/images/images/backspace.svg")); - ui->btn_enter->setIcon(QIcon(":/images/images/enter.svg")); - ui->btn_enter_num->setIcon(QIcon(":/images/images/enter.svg")); - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_close->setIcon(QIcon(":/images/images/close.svg")); - //ui->btn_super->setIcon(QIcon(":/images/images/super.svg")); - ui->btn_super->setText("Super"); - ui->btn_up->setIcon(QIcon(":/images/images/up.svg")); - ui->btn_down->setIcon(QIcon(":/images/images/down.svg")); - ui->btn_left->setIcon(QIcon(":/images/images/left.svg")); - ui->btn_right->setIcon(QIcon(":/images/images/right.svg")); -} - -QString KeyboardWidget::getKeyName(QPushButton *btn) -{ - QString objName = btn->objectName(); - int lastUnderline = objName.lastIndexOf('_'); - int start = strlen("btn_"); - int keyLength = lastUnderline - start; - QString keyName = objName.mid(start, keyLength); - return keyName; -} - -void KeyboardWidget::changeFuncKeyStyle(QPushButton *btn, bool isPressed) -{ - QString modName = getKeyName(btn); - Modifier::MOD mod = Modifier::getModifier(modName); - - if(vKeyboard->hasModifier(mod)) { - if(isPressed) - btn->setStyleSheet(BUTTON_BG_HL_PRESSED); - else - btn->setStyleSheet(BUTTON_BG_HL); - } else { - if(isPressed) - btn->setStyleSheet(BUTTON_BG_PRESSED); - else - btn->setStyleSheet(BUTTON_BG); - } -} - -void KeyboardWidget::changeShitKeyStyle(QPushButton *btn, bool isPressed) -{ - if(page == 0){ - if(isShift) { - if(capsLock){ - if(isPressed) { - btn->setStyleSheet(BUTTON_BG_HL_PRESSED); - btn->setIcon(QIcon(":/images/images/capslock_click.svg")); - } else { - btn->setStyleSheet(BUTTON_BG_HL); - btn->setIcon(QIcon(":/images/images/capslock.svg")); - } - } - else { - if(isPressed) - btn->setIcon(QIcon(":/images/images/capslock_hl_click.svg")); - else - btn->setIcon(QIcon(":/images/images/capslock_hl.svg")); - } - } else { - if(isPressed) - btn->setIcon(QIcon(":/images/images/capslock_click.svg")); - else - btn->setIcon(QIcon(":/images/images/capslock.svg")); - } - } -} - - -void KeyboardWidget::changeDirectKeyStyle(QPushButton *btn, bool isPressed) -{ - QString keyName = getKeyName(btn); - FuncKey::FUNCKEY key = FuncKey::getKey(keyName); - if(key == FuncKey::UNKNOWN) - return; - - QString iconName = QString(":/images/images/%1.svg").arg(keyName); - QString iconNamePressed = QString(":/images/images/%1_click.svg").arg(keyName); - - if(isPressed) - btn->setIcon(QIcon(iconNamePressed)); - else - btn->setIcon(QIcon(iconName)); -} - -/** - * @brief 修改按键样式 - * @param obj 按键 - * @param isPressed 按下或者松开 - */ -void KeyboardWidget::changeKeyStyle(QPushButton *btn, bool isPressed) -{ - if(btn == ui->btn_ctrl_l || btn == ui->btn_ctrl_r || - btn == ui->btn_alt_l || btn == ui->btn_alt_r || - btn == ui->btn_super) { - changeFuncKeyStyle(btn, isPressed); - } - - if(btn == ui->btn_shift_l) - changeShitKeyStyle(ui->btn_shift_l, isPressed); - if(btn == ui->btn_shift_r) - changeShitKeyStyle(ui->btn_shift_r, isPressed); - - changeDirectKeyStyle(btn, isPressed); -} - -void KeyboardWidget::onButtonPressed() -{ - QPushButton *btn = static_cast(sender()); - changeKeyStyle(btn, true); -} - -void KeyboardWidget::onButtonReleased() -{ - QPushButton *btn = static_cast(sender()); - changeKeyStyle(btn, false); -} - -void KeyboardWidget::onButtonClicked() -{ - QObject *obj = sender(); - if(obj->metaObject()->className() != QString("QPushButton")) - return; - - QPushButton *btn = static_cast(obj); - QString keyName = getKeyName(btn); - qDebug() << "keyName: " << keyName; - - Modifier::MOD mod = Modifier::getModifier(keyName); - FuncKey::FUNCKEY funcKey = FuncKey::getKey(keyName); - - if(keyName == "shift") { - if(page == 0) { - isShift = !isShift; - if(isShift) { //第一次被按下 - capsLock = false; - shiftLastClicked = QTime::currentTime(); - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock_hl.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock_hl.svg")); - } - else { - int doubleClickInterval = QApplication::doubleClickInterval(); - if(shiftLastClicked.msecsTo(QTime::currentTime()) <= doubleClickInterval) { - //shift键双击,锁定大写 - capsLock = true; - isShift = true; - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_l->setStyleSheet("QPushButton{background:#80c342}"); - ui->btn_shift_r->setStyleSheet("QPushButton{background:#80c342}"); - } else { - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_l->setStyleSheet("QPushButton{background:#1e1b18}"); - ui->btn_shift_r->setStyleSheet("QPushButton{background:#1e1b18}"); - } - } - toggleCase(); - } else { - page = page % (SYMBOL_PAGE_COUNT - 1) + 1; - switchPage(); - } - } else if(mod != Modifier::UNKNOWN) { - if(vKeyboard->hasModifier(mod)) { - vKeyboard->removeModifier(mod); - btn->setStyleSheet(BUTTON_BG); - btn->setStyleSheet(BUTTON_BG); - } else { - vKeyboard->addModifier(mod); - btn->setStyleSheet(BUTTON_BG_HL); - btn->setStyleSheet(BUTTON_BG_HL); - } - } else if(funcKey != FuncKey::UNKNOWN) { - Q_EMIT keyPressed(funcKey); - } else { //字符键 - QChar c; - QString text = btn->text(); - qDebug() << "clicked button text: " << text; - if(text == "&&") - c = '&'; - else if(text.length() == 1) - c = text.at(0); - - Q_EMIT keyPressed(c); - - //如果shift键被单击,按一个键后就恢复为小写 - if(isShift && !capsLock) { - isShift = false; - toggleCase(); - changeShitKeyStyle(ui->btn_shift_l, false); - changeShitKeyStyle(ui->btn_shift_r, false); - } - clearModifier(); - } -} - -void KeyboardWidget::clearModifier() -{ - for(auto mod : vKeyboard->getAllModifier()) { - QString modName = Modifier::getModifierName(mod); - if(mod == Modifier::SUPER) { - QString objName = QString("btn_%1").arg(modName); - QPushButton *btn = ui->page_letter->findChild(objName); - btn->setStyleSheet(BUTTON_BG); - } else { - QString objName = QString("btn_%1_l").arg(modName); - QPushButton *btn = ui->page_letter->findChild(objName); - btn->setStyleSheet(BUTTON_BG); - objName = QString("btn_%1_r").arg(modName); - btn = ui->page_letter->findChild(objName); - btn->setStyleSheet(BUTTON_BG); - } - } - vKeyboard->clearModifier(); -} - -void KeyboardWidget::toggleCase() -{ - for(int i = 0; i < 26; i++) { - QString objName = "btn_" + QString::number(i); - QPushButton *btn = findChild(objName); - QChar ch; - if(isShift) { //切换到大写 - ch = symbols[0][i].toUpper(); - } else { - ch = symbols[0][i]; - } - btn->setText(ch); - } -} - -void KeyboardWidget::switchPage() -{ - if(page == 0) { - ui->btn_shift_l->setText(""); - ui->btn_shift_r->setText(""); - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock.svg")); - } else { - ui->btn_shift_l->setText(""); - ui->btn_shift_r->setText(""); - ui->btn_shift_l->setIcon(QIcon(":/images/images/capslock.svg")); - ui->btn_shift_r->setIcon(QIcon(":/images/images/capslock.svg")); - } - - for(int i = 0; i < SYMBOL_KEY_COUNT; i++) { - QString btnObjName = "btn_" + QString::number(i); - QPushButton *btn = ui->page_letter->findChild(btnObjName); - QChar c = symbols[page][i]; - if(c == '&') - btn->setText("&&"); - else - btn->setText(c); - } -} - diff --git a/VirtualKeyboard/src/keyboardwidget.h b/VirtualKeyboard/src/keyboardwidget.h deleted file mode 100644 index c2f7a37..0000000 --- a/VirtualKeyboard/src/keyboardwidget.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2018 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 3, 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, see . - * -**/ -#ifndef KEYBOARDWIDGET_H -#define KEYBOARDWIDGET_H - -#include -#include -#include -#include "fakekeyboard.h" - -namespace Ui { -class KeyboardWidget; -} - -class QPushButton; - -class KeyboardWidget : public QWidget -{ - Q_OBJECT - -public: - explicit KeyboardWidget(QWidget *parent = 0); - ~KeyboardWidget(); - -protected: - void resizeEvent(QResizeEvent *event); - -private: - void bindSingal(); - void toggleCase(); - void switchPage(); - void setDefaultIcon(); - void setIconSize(); - void changeKeyStyle(QPushButton *btn, bool isPressed); - void changeFuncKeyStyle(QPushButton *btn, bool isPressed); - void changeShitKeyStyle(QPushButton *btn, bool isPressed); - void changeDirectKeyStyle(QPushButton *btn, bool isPressed); - void clearModifier(); - QString getKeyName(QPushButton *btn); - - -private Q_SLOTS: - void onButtonClicked(); - void onButtonPressed(); - void onButtonReleased(); - -Q_SIGNALS: - void aboutToClose(); - void keyPressed(QChar c); - void keyPressed(FuncKey::FUNCKEY key); - -private: - Ui::KeyboardWidget *ui; - bool capsLock; //是否大写锁定 - bool isShift; - QTime shiftLastClicked; //shift键上次被点击的时间 - int page; //当前是第几页的键盘 - FakeKeyboard *vKeyboard; -}; - -#endif // KEYBOARDWIDGET_H diff --git a/VirtualKeyboard/src/keyboardwidget.ui b/VirtualKeyboard/src/keyboardwidget.ui deleted file mode 100644 index 2f6b5f1..0000000 --- a/VirtualKeyboard/src/keyboardwidget.ui +++ /dev/null @@ -1,1226 +0,0 @@ - - - KeyboardWidget - - - Qt::NonModal - - - - 0 - 0 - 1132 - 293 - - - - - 0 - 0 - - - - - 0 - 0 - - - - KeyboardWidget - - - - 0 - - - QLayout::SetMinAndMaxSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 8 - - - QLayout::SetNoConstraint - - - 8 - - - 8 - - - 8 - - - 8 - - - - - 1 - - - - - 0 - - - QLayout::SetNoConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 5 - - - QLayout::SetNoConstraint - - - - - Qt::Vertical - - - - 10 - 20 - - - - - - - - 10 - - - QLayout::SetNoConstraint - - - - - - 0 - 0 - - - - q - - - - - - - - 0 - 0 - - - - w - - - - - - - - 0 - 0 - - - - e - - - - - - - - 0 - 0 - - - - r - - - - - - - - 0 - 0 - - - - t - - - - - - - - 0 - 0 - - - - y - - - - - - - - 0 - 0 - - - - u - - - - - - - - 0 - 0 - - - - i - - - - - - - - 0 - 0 - - - - o - - - - - - - - 0 - 0 - - - - p - - - - - - - - 0 - 0 - - - - - - - - - - - - - 10 - - - QLayout::SetNoConstraint - - - - - Qt::Horizontal - - - QSizePolicy::Maximum - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - a - - - - - - - - 0 - 0 - - - - s - - - - - - - - 0 - 0 - - - - d - - - - - - - - 0 - 0 - - - - f - - - - - - - - 0 - 0 - - - - g - - - - - - - - 0 - 0 - - - - h - - - - - - - - 0 - 0 - - - - j - - - - - - - - 0 - 0 - - - - k - - - - - - - - 0 - 0 - - - - l - - - - - - - - 0 - 0 - - - - - - - - - - - - - - - - 10 - - - QLayout::SetNoConstraint - - - - - - 0 - 0 - - - - - - - - - - - - - - - 0 - 0 - - - - z - - - - - - - - 0 - 0 - - - - x - - - - - - - - 0 - 0 - - - - c - - - - - - - - 0 - 0 - - - - v - - - - - - - - 0 - 0 - - - - b - - - - - - - - 0 - 0 - - - - n - - - - - - - - 0 - 0 - - - - m - - - - - - - - 0 - 0 - - - - , - - - - - - - - 0 - 0 - - - - . - - - - - - - - 0 - 0 - - - - - - - - - - - - - - - - 10 - - - QLayout::SetNoConstraint - - - - - - 0 - 0 - - - - - - - Ctrl - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - Alt - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - Alt - - - - - - - - 0 - 0 - - - - / - - - - - - - - 0 - 0 - - - - Ctrl - - - - - - - - - Qt::Vertical - - - - 10 - 20 - - - - - - - - - - - - 4 - - - QLayout::SetNoConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 10 - - - QLayout::SetNoConstraint - - - - - QLayout::SetNoConstraint - - - 10 - - - - - - 0 - 0 - - - - 9 - - - - - - - - 0 - 0 - - - - 5 - - - - - - - - 0 - 0 - - - - 8 - - - - - - - - 0 - 0 - - - - 4 - - - - - - - - 0 - 0 - - - - 2 - - - - - - - - 0 - 0 - - - - 7 - - - - - - - - 0 - 0 - - - - 1 - - - - - - - - 0 - 0 - - - - 6 - - - - - - - - 0 - 0 - - - - 3 - - - - - - - - 0 - 0 - - - - 0 - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QLayout::SetNoConstraint - - - 10 - - - - - - 0 - 0 - - - - Delete - - - - - - - - 0 - 0 - - - - End - - - - - - - - 0 - 0 - - - - Insert - - - - - - - - 0 - 0 - - - - PgUp - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - Home - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - - - - - - - - - 0 - 0 - - - - PgDn - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 5 - - - QLayout::SetNoConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - 10 - 20 - - - - - - - - - 0 - 0 - - - - - 100 - 16777215 - - - - - - - - - - - - 0 - 0 - - - - - 100 - 16777215 - - - - Abc - - - - - - - - 0 - 0 - - - - - 100 - 16777215 - - - - @ - - - - - - - - 0 - 0 - - - - - 100 - 16777215 - - - - 123 - - - - - - - Qt::Vertical - - - - 10 - 20 - - - - - - - - - - - - - - VKStackedWidget - QStackedWidget -
src/vkstackedwidget.h
- 1 -
-
- - -
diff --git a/VirtualKeyboard/src/letterswidget.cpp b/VirtualKeyboard/src/letterswidget.cpp new file mode 100644 index 0000000..102d64b --- /dev/null +++ b/VirtualKeyboard/src/letterswidget.cpp @@ -0,0 +1,383 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "letterswidget.h" +#include "commondef.h" +#include "plasma-shell-manager.h" +#include +#include +#include + +LettersWidget::LettersWidget(QWidget *parent/* = nullptr*/) + : QWidget(parent) +{ + this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 + initUI(); + + if(QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") { + isWayland = true; + } + + if(isWayland){ + connect(PlasmaShellManager::getInstance(), &PlasmaShellManager::keyStateChanged, + this, &LettersWidget::onCapsChanged); + }else{ + settings = new QGSettings("org.ukui.peripherals-keyboard", "", this); + connect(settings, &QGSettings::changed, + this, &LettersWidget::onCapsChanged); + } + onCapsChanged(); +} + +LettersWidget::~LettersWidget() +{ + +} + +void LettersWidget::initUI() +{ + // line 1 + QChar chLine1[] = {'q','w','e','r','t','y','u','i','o','p'}; + for (int n = 0; n < sizeof(chLine1)/sizeof(QChar); n++) { + KBButton *letterBtn = new KBButton(this); + QString objName = "btn_" + QString::number(chLine1[n].toLatin1()); + letterBtn->setObjectName(objName); + letterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L1+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*n, + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + letterBtn->setCharId(chLine1[n]); + letterBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(letterBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[letterBtn] = letterBtn->geometry(); + } + // backspace + KBButton *backspaceBtn = new KBButton(this); + backspaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L1+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*10, + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + backspaceBtn->setObjectName("btn_backspace"); + backspaceBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + backspaceBtn->setIcon(QIcon(":/images/images/delet.svg")); + connect(backspaceBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[backspaceBtn] = backspaceBtn->geometry(); + qDebug()<<"backspaceBtn geometry:"<geometry(); + + // line 2 + QChar chLine2[] = {'a','s','d','f','g','h','j','k','l'}; + for (int n = 0; n < sizeof(chLine2)/sizeof(QChar); n++) { + KBButton *letterBtn = new KBButton(this); + QString objName = "btn_" + QString::number(chLine2[n].toLatin1()); + letterBtn->setObjectName(objName); + letterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L2+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*n, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING), + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + letterBtn->setCharId(chLine2[n]); + letterBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(letterBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[letterBtn] = letterBtn->geometry(); + } + // enter + KBButton *enterBtn = new KBButton(this); + enterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L2+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*9, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING), + KEYBOARD_FIXED_DEFAULT_ENTERBTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + enterBtn->setObjectName("btn_enter"); + enterBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + enterBtn->setIcon(QIcon(":/images/images/enter.svg")); + connect(enterBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[enterBtn] = enterBtn->geometry(); + + // line 3 + QChar chLine3[] = {'z','x','c','v','b','n','m',',','.'}; + for (int n = 0; n < sizeof(chLine3)/sizeof(QChar); n++) { + KBButton *letterBtn = new KBButton(this); + QString objName = "btn_" + QString::number(chLine3[n].toLatin1()); + letterBtn->setObjectName(objName); + letterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L3+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*(n+1), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + letterBtn->setCharId(chLine3[n]); + letterBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED, + KEYBOARD_FONT_COLOR_PRESS); + connect(letterBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[letterBtn] = letterBtn->geometry(); + } + // shift l + KBButton *shiftLBtn = new KBButton(this); + shiftLBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L3, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + shiftLBtn->setObjectName("btn_shift_l"); + shiftLBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + shiftLBtn->setIcon(QIcon(":/images/images/shift.svg")); + connect(shiftLBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[shiftLBtn] = shiftLBtn->geometry(); + // shift r + KBButton *shiftRBtn = new KBButton(this); + shiftRBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L3+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*10, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + shiftRBtn->setObjectName("btn_shift_r"); + shiftRBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + shiftRBtn->setIcon(QIcon(":/images/images/shift.svg")); + connect(shiftRBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[shiftRBtn] = shiftRBtn->geometry(); + + // line 4 + KBButton *symbolBtn = new KBButton(this); + symbolBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + symbolBtn->setObjectName("btn_symbol"); + symbolBtn->setText(tr("&&?!")); + symbolBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(symbolBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[symbolBtn] = symbolBtn->geometry(); + + KBButton *numBtn = new KBButton(this); + numBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + numBtn->setObjectName("btn_num"); + numBtn->setText(tr("123")); + numBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(numBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[numBtn] = numBtn->geometry(); + + KBButton *ctrlBtn = new KBButton(this); + ctrlBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*2, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + ctrlBtn->setObjectName("btn_ctrl"); + ctrlBtn->setText(tr("Ctrl")); + ctrlBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(ctrlBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[ctrlBtn] = ctrlBtn->geometry(); + + KBButton *spaceBtn = new KBButton(this); + spaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*3, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_SPACEBTN_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + spaceBtn->setObjectName("btn_space"); + spaceBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_BORDER_NORMAL, + KEYBOARD_LETTER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + spaceBtn->setIcon(QIcon(":/images/images/space.svg")); + connect(spaceBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[spaceBtn] = spaceBtn->geometry(); + + KBButton *altBtn = new KBButton(this); + altBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*8, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + altBtn->setObjectName("btn_alt"); + altBtn->setText(tr("Alt")); + altBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(altBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[altBtn] = altBtn->geometry(); + + KBButton *leftBtn = new KBButton(this); + leftBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*9, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + leftBtn->setObjectName("btn_left"); + leftBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + leftBtn->setIcon(QIcon(":/images/images/left.svg")); + connect(leftBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[leftBtn] = leftBtn->geometry(); + + KBButton *rightBtn = new KBButton(this); + rightBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_LETTER_L4+(KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*10, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_LETTER_WIDTH, + KEYBOARD_FIXED_DEFAULT_LETTER_HEIGHT); + rightBtn->setObjectName("btn_right"); + rightBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED, + KEYBOARD_OTHER_FONT_COLOR_PRESS); + rightBtn->setIcon(QIcon(":/images/images/right.svg")); + connect(rightBtn, &KBButton::clicked, this, &LettersWidget::onBtnClicked); + m_mapBtnGeometrys[rightBtn] = rightBtn->geometry(); +} + +void LettersWidget::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + QMap::iterator itGeometry = m_mapBtnGeometrys.begin(); + for (; itGeometry != m_mapBtnGeometrys.end(); itGeometry ++) { + KBButton *button = itGeometry.key(); + if (button) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + button->setGeometry(newGeometry); + } + } +} + +void LettersWidget::onBtnClicked(QChar charId) +{ + QObject *obj = sender(); + KBButton *btn = static_cast(obj); + QString objName = btn->objectName(); + int lastUnderline = objName.lastIndexOf('_'); + int start = strlen("btn_"); + int keyLength = lastUnderline - start; + QString keyName = objName.mid(start, keyLength); + + if (charId != QChar::Null && isShift && !capsState) { //第一次按shift,按后取消shift状态 + isShift = false; + changeFuncKeyStyle("shift_l", false); + changeFuncKeyStyle("shift_r", false); + toggleCase(); + } + + if (keyName == "num") { //数字页面 + Q_EMIT specialBtnClicked(PAGE_NUMBER); + } else if (keyName == "symbol") { //符号页面 + Q_EMIT specialBtnClicked(PAGE_CHAR); + } else if (keyName == BTN_SHIFT) { //shift + if (capsState) { + capsState = false; + isShift = false; + changeFuncKeyStyle("shift_l", false); + changeFuncKeyStyle("shift_r", false); + Q_EMIT specialBtnClicked(BTN_CAPSLOCK); + } else if (isShift) { //shift键锁定 + capsState = true; + isShift = true; + changeFuncKeyStyle("shift_l", true); + changeFuncKeyStyle("shift_r", true); + Q_EMIT specialBtnClicked(BTN_CAPSLOCK); + } else { + isShift = true; + changeFuncKeyStyle("shift_l", true); + changeFuncKeyStyle("shift_r", true); + } + toggleCase(); + } else if (charId != QChar::Null) { //字符 + Q_EMIT normalBtnClicked(charId); + } else { //ctrl或者alt + Q_EMIT specialBtnClicked(keyName); + + } +} + +void LettersWidget::onCapsChanged() +{ + if(isWayland){ + capsState = PlasmaShellManager::getInstance()->getKeyState(KWayland::Client::Keystate::Key::CapsLock); + }else{ + capsState = settings->get("capslock-state").toBool(); + } + + isShift = capsState; + for (int i = 97; i < 123; i++) { //大小写切换 + QString objName = QString("btn_%1").arg(QString::number(i)); + KBButton *btn = findChild(objName); + btn->setCapsStatus(capsState); + changeFuncKeyStyle("shift_l", capsState); + changeFuncKeyStyle("shift_r", capsState); + } +} + +void LettersWidget::toggleCase() +{ + for (int i = 97; i < 123; i++) { //大小写切换 + QString objName = QString("btn_%1").arg(QString::number(i)); + KBButton *btn = findChild(objName); + btn->setShiftState(isShift); + } +} + +void LettersWidget::changeFuncKeyStyle(QString obj, bool isLock) +{ + if(obj == BTN_CAPSLOCK) + return; + QString objName = QString("btn_%1").arg(obj); + KBButton *btn = findChild(objName); + if (isLock) { + btn->updateStyleSheet(KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS, + KBButton::BORDER_RADIUS_ALL,true); + if (capsState && obj.contains(BTN_SHIFT)) { + btn->setIcon(QIcon(":/images/images/shift_lock.svg")); + } else if (obj.contains(BTN_SHIFT)) { + btn->setIcon(QIcon(":/images/images/rectangle.svg")); + } + } else { + btn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + if (obj.contains(BTN_SHIFT)) { + btn->setIcon(QIcon(":/images/images/shift.svg")); + } + } +} diff --git a/VirtualKeyboard/src/letterswidget.h b/VirtualKeyboard/src/letterswidget.h new file mode 100644 index 0000000..31ee168 --- /dev/null +++ b/VirtualKeyboard/src/letterswidget.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef LETTERSWIDGET_H +#define LETTERSWIDGET_H + +#include +#include +#include "kbbutton.h" +#include + +class LettersWidget : public QWidget +{ + Q_OBJECT +public: + explicit LettersWidget(QWidget *parent = nullptr); + virtual ~LettersWidget(); + + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); + void changeFuncKeyStyle(QString obj, bool isLock); + +public Q_SLOTS: + void onBtnClicked(QChar charId); + void onCapsChanged(); + +Q_SIGNALS: + void clicked(int nKeyId); + void specialBtnClicked(QString keyName); + void normalBtnClicked(QChar c); + +private: + void initUI(); + void toggleCase(); + +private: + QMap m_mapBtnGeometrys; + + bool isShift = false; + + QGSettings *settings; + bool capsState = false; + bool isWayland = false; +}; + +#endif // LETTERSWIDGET_H diff --git a/VirtualKeyboard/src/numberswidget.cpp b/VirtualKeyboard/src/numberswidget.cpp new file mode 100644 index 0000000..a09de13 --- /dev/null +++ b/VirtualKeyboard/src/numberswidget.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "numberswidget.h" +#include "kbbutton.h" +#include "commondef.h" + +#include +#include +#include +#include +#include +#include + +NumbersWidget::NumbersWidget(QWidget *parent) + : QWidget(parent) +{ + this->setAttribute(Qt::WA_TranslucentBackground);//背景透明 + initUI(); +} + +NumbersWidget::~NumbersWidget() +{ + +} + +void NumbersWidget::initUI() +{ + // all chars + m_layoutBtnList = new QVBoxLayout(); + m_layoutBtnList->setContentsMargins(8,0,0,0); + m_layoutBtnList->setSpacing(1); + listFrame = new QFrame(); + listFrame->setObjectName("listFrame"); + listFrame->setLayout(m_layoutBtnList); + listFrame->setStyleSheet("QFrame{border-radius: 8px}"); + listFrame->setFrameStyle(QFrame::Plain); + m_scrollFrame = new QScrollArea(this); + m_scrollFrame->setObjectName("scrollFrame"); + m_scrollFrame->setFocusPolicy(Qt::NoFocus); + m_scrollFrame->setContentsMargins(0, 0, 0, 0); + m_scrollFrame->setStyleSheet("QScrollArea {background-color: #C0CED3D9; border-radius:8px;}"); + m_scrollFrame->viewport()->setStyleSheet("background-color:transparent;"); + m_scrollFrame->verticalScrollBar()->setProperty("drawScrollBarGroove", false); + m_scrollFrame->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_scrollFrame->verticalScrollBar()->setContextMenuPolicy(Qt::NoContextMenu); + m_scrollFrame->setWidgetResizable(true); + m_scrollFrame->setWidget(listFrame); + m_scrollFrame->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L1, KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, KEYBOARD_FIXED_DEFAULT_NUMBER_CHARS_HEIGHT); + listFrame->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L1, KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, KEYBOARD_FIXED_DEFAULT_NUMBER_CHARS_HEIGHT); + m_mapBtnGeometrys[m_scrollFrame] = m_scrollFrame->geometry(); + //m_mapBtnGeometrys[listFrame] = listFrame->geometry(); + QChar chChars[] = {',', '.', '?', '!', '\'', ':', '~', '@', ';', '"', + '/', '(', ')', '_', '+', '=', '`', '^', '#', '*', + '%', '&', '\\', '[', ']', '<', '>', '{', '}', '|', + '$', '-'}; + for (int n = 0; n < sizeof(chChars)/sizeof(QChar); n++) { + KBButton *charBtn = new KBButton(listFrame); + charBtn->setCharId(chChars[n]); + charBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_NORMAL, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS, + KBButton::BORDER_RADIUS_NONE); + charBtn->setObjectName(QString("btn_%1").arg(QString(chChars[n]))); + connect(charBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + charBtn->setFixedHeight(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + m_layoutBtnList->addWidget(charBtn); + } + // line 1 + QChar chLine1[] = {'1','2','3'}; + for (int n = 0; n < sizeof(chLine1)/sizeof(QChar); n++) { + KBButton *numberBtn = new KBButton(this); + numberBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L1+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*(n+1), + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + numberBtn->setCharId(chLine1[n]); + numberBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(numberBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[numberBtn] = numberBtn->geometry(); + } + // backspace + KBButton *backspaceBtn = new KBButton(this); + backspaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L1+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*4, + KEYBOARD_FIXED_DEFAULT_TMARGIN, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + backspaceBtn->setObjectName("btn_backspace"); + backspaceBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + backspaceBtn->setIcon(QIcon(":/images/images/delet.svg")); + connect(backspaceBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[backspaceBtn] = backspaceBtn->geometry(); + + // line 2 + QChar chLine2[] = {'4','5','6'}; + for (int n = 0; n < sizeof(chLine2)/sizeof(QChar); n++) { + KBButton *numberBtn = new KBButton(this); + numberBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L2+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*(n+1), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*1, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + numberBtn->setCharId(chLine2[n]); + numberBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(numberBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[numberBtn] = numberBtn->geometry(); + } + // @ + KBButton *atBtn = new KBButton(this); + atBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L2+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*1, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + atBtn->setCharId('@'); + atBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(atBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[atBtn] = atBtn->geometry(); + // line 3 + QChar chLine3[] = {'7','8','9'}; + for (int n = 0; n < sizeof(chLine3)/sizeof(QChar); n++) { + KBButton *numberBtn = new KBButton(this); + numberBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L3+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*(n+1), + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + numberBtn->setCharId(chLine3[n]); + numberBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_BORDER_NORMAL,KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(numberBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[numberBtn] = numberBtn->geometry(); + } + // symbol + KBButton *symbolBtn = new KBButton(this); + symbolBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L3+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*2, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + symbolBtn->setObjectName("btn_symbol"); + symbolBtn->setText(tr("&&?!")); + symbolBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(symbolBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[symbolBtn] = symbolBtn->geometry(); + + // line 4 + KBButton *returnBtn = new KBButton(this); + returnBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + returnBtn->setObjectName("btn_return"); + returnBtn->setText(tr("Return")); + returnBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + connect(returnBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[returnBtn] = returnBtn->geometry(); + + // space + KBButton *spaceBtn = new KBButton(this); + spaceBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L4+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*1, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + spaceBtn->setObjectName("btn_space"); + spaceBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_BORDER_NORMAL, + KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + spaceBtn->setIcon(QIcon(":/images/images/space.svg")); + connect(spaceBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[spaceBtn] = spaceBtn->geometry(); + + // . + KBButton *dianBtn = new KBButton(this); + dianBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L4+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*3, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + dianBtn->setCharId('.'); + dianBtn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_BORDER_NORMAL, + KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(dianBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[dianBtn] = dianBtn->geometry(); + + // 9 + KBButton *num0Btn = new KBButton(this); + num0Btn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L4+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*2, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + num0Btn->setCharId('0'); + num0Btn->updateStyleSheet(KEYBOARD_LETTER_COLOR_NORMAL,KEYBOARD_LETTER_COLOR_PRESSED, + KEYBOARD_LETTER_COLOR_PRESSED,KEYBOARD_LETTER_COLOR_BORDER_NORMAL, + KEYBOARD_LETTER_COLOR_BORDER_PRESSED,KEYBOARD_FONT_COLOR_PRESS); + connect(num0Btn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[num0Btn] = num0Btn->geometry(); + + // enter + KBButton *enterBtn = new KBButton(this); + enterBtn->setGeometry(KEYBOARD_FIXED_DEFAULT_NUMBER_L3+(KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH+KEYBOAED_FIXED_DEFAULT_HSPACING)*4, + KEYBOARD_FIXED_DEFAULT_TMARGIN+(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT+KEYBOAED_FIXED_DEFAULT_VSPACING)*3, + KEYBOARD_FIXED_DEFAULT_NUMBER_WIDTH, + KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT); + enterBtn->setObjectName("btn_enter"); + enterBtn->updateStyleSheet(KEYBOARD_OTHER_COLOR_NORMAL,KEYBOARD_OTHER_COLOR_PRESSED, + KEYBOARD_OTHER_COLOR_PRESSED,KEYBOARD_OTHER_COLOR_BORDER_NORMAL, + KEYBOARD_OTHER_COLOR_BORDER_PRESSED,KEYBOARD_OTHER_FONT_COLOR_PRESS); + enterBtn->setIcon(QIcon(":/images/images/enter.svg")); + connect(enterBtn, &KBButton::clicked, this, &NumbersWidget::onBtnClicked); + m_mapBtnGeometrys[enterBtn] = enterBtn->geometry(); +} + +void NumbersWidget::adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical/* = false*/, bool floatStatus) +{ + QMap::iterator itGeometry = m_mapBtnGeometrys.begin(); + for (; itGeometry != m_mapBtnGeometrys.end(); itGeometry ++) { + QWidget *widget = itGeometry.key(); + if (widget) { + QRect oldGeometry = itGeometry.value(); + QRect newGeometry = oldGeometry; + if (floatStatus) { + newGeometry.setX(oldGeometry.x()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale*KEYBOARD_FLOAT_PERCENTAGE); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } else { + newGeometry.setX(oldGeometry.x()*lfWidthScale); + newGeometry.setY(oldGeometry.y()*lfHeightScale); + newGeometry.setWidth(oldGeometry.width()*lfWidthScale); + newGeometry.setHeight(oldGeometry.height()*lfHeightScale); + } + widget->setGeometry(newGeometry); + } + } + + QChar chChars[] = {',', '.', '?', '!', '\'', ':', '~', '@', ';', '"', + '/', '(', ')', '_', '+', '=', '`', '^', '#', '*', + '%', '&', '\\', '[', ']', '<', '>', '{', '}', '|', + '$', '-'}; + for (int n = 0; n < sizeof(chChars)/sizeof(QChar); n++) { //单独更新符号btn的高度 + QString objName = QString("btn_%1").arg(QString(chChars[n])); + KBButton *btn = findChild(objName); + btn->setFixedHeight(KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT *lfHeightScale); + } + //更新listfarame的高度 + listFrame->setFixedHeight((KEYBOARD_FIXED_DEFAULT_NUMBER_HEIGHT *lfHeightScale +1) * (m_layoutBtnList->count())); +} + +void NumbersWidget::onBtnClicked(QChar charId) +{ + QObject *obj = sender(); + KBButton *btn = static_cast(obj); + QString objName = btn->objectName(); + int lastUnderline = objName.lastIndexOf('_'); + int start = strlen("btn_"); + int keyLength = lastUnderline - start; + QString keyName = objName.mid(start, keyLength); + qDebug() << "keyName: " << keyName; + if (keyName == BTN_RETURN) { + Q_EMIT specialBtnClicked(PAGE_LETTER); + } else if (keyName == "symbol") { + Q_EMIT specialBtnClicked(PAGE_CHAR); + } else if (charId != QChar::Null) { + Q_EMIT narmalBtnClicked(charId); + } else if (keyName == BTN_BACK) { + Q_EMIT specialBtnClicked(BTN_BACK); + } else { + Q_EMIT specialBtnClicked(keyName); + } +} diff --git a/VirtualKeyboard/src/numberswidget.h b/VirtualKeyboard/src/numberswidget.h new file mode 100644 index 0000000..bea0f28 --- /dev/null +++ b/VirtualKeyboard/src/numberswidget.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef NUMBERSWIDGET_H +#define NUMBERSWIDGET_H + +#include +#include + +class KBButton; +class QVBoxLayout; +class QScrollArea; +class QFrame; +class NumbersWidget : public QWidget +{ + Q_OBJECT +public: + explicit NumbersWidget(QWidget *parent = nullptr); + virtual ~NumbersWidget(); + + void adjustGeometry(double lfWidthScale, double lfHeightScale, bool isVertical = false, bool floatStatus = false); + +public Q_SLOTS: + void onBtnClicked(QChar charId); + +Q_SIGNALS: + void clicked(int nKeyId); + void specialBtnClicked(QString keyName); + void narmalBtnClicked(QChar charId); + +private: + void initUI(); + +private: + QMap m_mapBtnGeometrys; + QVBoxLayout *m_layoutBtnList = nullptr; + QScrollArea *m_scrollFrame = nullptr; + QFrame *listFrame = nullptr; +}; + +#endif // NUMBERSWIDGET_H diff --git a/VirtualKeyboard/src/qtkeyboard.cpp b/VirtualKeyboard/src/qtkeyboard.cpp index 731b70e..a87495b 100644 --- a/VirtualKeyboard/src/qtkeyboard.cpp +++ b/VirtualKeyboard/src/qtkeyboard.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "plasma-shell-manager.h" QMap m_specialSymbolMap = { {' ', Qt::Key_Space}, @@ -94,7 +95,7 @@ QVector m_shiftKeyVec = {'~', '!', '@', '#', '$', '%', '^', '&', '*', * @brief 判断大写键状态 * @return true: 大写锁定 */ -bool checkCapsLockState() +bool QtKeyboard::checkCapsLockState() { QDir ledDir(DRM_DIR); QStringList leds = ledDir.entryList(QDir::Dirs); @@ -193,8 +194,10 @@ void QtKeyboard::onKeyPressed(FuncKey::FUNCKEY key) sendKey(keysym,"\r"); }else if(key == FuncKey::INSERT){ sendKey(keysym,"\u007F"); + }else if(key == FuncKey::CAPSLOCK){ + PlasmaShellManager::getInstance()->setKeyPressed(58); }else{ - sendKey(keysym,""); + sendKey(keysym,""); } } @@ -214,6 +217,7 @@ void QtKeyboard::sendKey(const unsigned int keysym,const QString text) QKeyEvent event2(QEvent::KeyRelease, keysym , modifier, text , true, 1); + QCoreApplication::sendEvent(objfous, &event1); QCoreApplication::sendEvent(objfous, &event2); } diff --git a/VirtualKeyboard/src/qtkeyboard.h b/VirtualKeyboard/src/qtkeyboard.h index fed4508..a9c9690 100644 --- a/VirtualKeyboard/src/qtkeyboard.h +++ b/VirtualKeyboard/src/qtkeyboard.h @@ -40,6 +40,7 @@ public Q_SLOTS: private: void sendKey(const unsigned int keyCode,const QString text); + bool checkCapsLockState(); private: QList modList; diff --git a/VirtualKeyboard/src/virtualkeyboard.cpp b/VirtualKeyboard/src/virtualkeyboard.cpp deleted file mode 100644 index 0ad995f..0000000 --- a/VirtualKeyboard/src/virtualkeyboard.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2018 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 3, 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, see . - * -**/ -#include "virtualkeyboard.h" -#include -#include -#include -#include - -VirtualKeyboard::VirtualKeyboard(QWidget *parent) - : QWidget(parent) -{ - Q_INIT_RESOURCE(keyboard); - - setAutoFillBackground(true); - QPalette plt; - plt.setBrush(QPalette::Background, Qt::black); - setPalette(plt); - - setWindowFlags(Qt::FramelessWindowHint | - Qt::WindowStaysOnTopHint | - Qt::WindowDoesNotAcceptFocus); - - - keyboardWidget = new KeyboardWidget(this); - QHBoxLayout *hl_keyboard = new QHBoxLayout(this); - hl_keyboard->setContentsMargins(0,0,0,0); - hl_keyboard->setSpacing(0); - QSpacerItem *spacer = new QSpacerItem(10, 5); - hl_keyboard->addSpacerItem(spacer); - hl_keyboard->addWidget(keyboardWidget); - QSpacerItem *spacer2 = new QSpacerItem(10, 5); - hl_keyboard->addSpacerItem(spacer2); - - QFile qssFile(":/qss/keyboard.qss"); - qssFile.open(QIODevice::ReadOnly); - setStyleSheet(qssFile.readAll()); - qssFile.close(); - - QDesktopWidget *desktop = QApplication::desktop(); - cursorMonitor = new CursorMonitor(this); - - //在多显示器情况下,监视鼠标指针的位置和主显示器变化信号 - connect(cursorMonitor, &CursorMonitor::cursorPosChanged, - this, [&](const QPoint &pos){ - adjustGeometry(desktop->screenNumber(pos)); - }); - - connect(desktop, &QDesktopWidget::primaryScreenChanged, - this, [&]{ - adjustGeometry(desktop->primaryScreen()); - }); - - connect(keyboardWidget, &KeyboardWidget::aboutToClose, - this, &VirtualKeyboard::aboutToClose); - - adjustGeometry(desktop->primaryScreen()); -} - -void VirtualKeyboard::adjustGeometry(int screen) -{ - QDesktopWidget *desktop = QApplication::desktop(); - QWidget *activateScreen = desktop->screen(screen); - setGeometry(0, activateScreen->height() - activateScreen->height() / 3, - activateScreen->width(), activateScreen->height() / 3); -} diff --git a/VirtualKeyboard/src/virtualkeyboardwidget.cpp b/VirtualKeyboard/src/virtualkeyboardwidget.cpp new file mode 100644 index 0000000..4318702 --- /dev/null +++ b/VirtualKeyboard/src/virtualkeyboardwidget.cpp @@ -0,0 +1,310 @@ +/* + * Copyright (C) 2018 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 3, 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, see . + * +**/ +#include "virtualkeyboardwidget.h" + +#include +#include +#include +#include +#include "commondef.h" +#include +#include +#include "dragwidget.h" +#include "kbtitle.h" +#include "letterswidget.h" +#include "numberswidget.h" +#include "charswidget.h" +#include "charsmorewidget.h" +#include "x11keyboard.h" +#include "qtkeyboard.h" + +VirtualKeyboardWidget::VirtualKeyboardWidget(QWidget *parent) + : QWidget(parent) + , m_lfWidthScale(1.0) + , m_lfHeightScale(1.0) + , m_isVertical(false) +{ + Q_INIT_RESOURCE(keyboard); + setAttribute(Qt::WA_TranslucentBackground);//背景透明 + //setAutoFillBackground(true); + setWindowFlags(Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint | + Qt::WindowDoesNotAcceptFocus); + + if(QX11Info::isPlatformX11()){ + vKeyboard = new X11Keyboard(this); + }else{ + vKeyboard = new QtKeyboard(this); + } + + connect(this, SIGNAL(keyPressed(QChar)), + vKeyboard, SLOT(onKeyPressed(QChar))); + connect(this, SIGNAL(keyPressed(FuncKey::FUNCKEY)), + vKeyboard, SLOT(onKeyPressed(FuncKey::FUNCKEY))); + initUI(); + initConnections(); +} + +VirtualKeyboardWidget::~VirtualKeyboardWidget() +{ + +} + +void VirtualKeyboardWidget::initUI() +{ + QVBoxLayout *layoutMain = new QVBoxLayout(this); + layoutMain->setContentsMargins(0,0,0,0); + layoutMain->setSpacing(0); + + m_dragWidget = new DragWidget(); + layoutMain->addWidget(m_dragWidget); + m_dragWidget->installEventFilter(this); + + m_kbTitle = new KBTitle(); + layoutMain->addWidget(m_kbTitle); + + m_stackedWidget = new QStackedWidget(); + + m_lettersWidget = new LettersWidget(); + m_stackedWidget->addWidget(m_lettersWidget); + + m_numbersWidget = new NumbersWidget(this); + m_stackedWidget->addWidget(m_numbersWidget); + + m_charsWidget = new CharsWidget(); + m_stackedWidget->addWidget(m_charsWidget); + + m_charsMoreWidget = new CharsMoreWidget(); + m_stackedWidget->addWidget(m_charsMoreWidget); + + m_stackedWidget->setCurrentIndex(VKB_PAGE_LETTERS); + m_nCurPage = VKB_PAGE_CHARSMORE; + layoutMain->addWidget(m_stackedWidget); +} + +void VirtualKeyboardWidget::initConnections() +{ + connect(m_kbTitle, &KBTitle::btnClicked, this, &VirtualKeyboardWidget::onSpecialBtnClicked); + connect(m_lettersWidget, &LettersWidget::specialBtnClicked, this, &VirtualKeyboardWidget::onSpecialBtnClicked); + connect(m_lettersWidget, &LettersWidget::normalBtnClicked, this, &VirtualKeyboardWidget::onNormalBtnClicked); + connect(m_numbersWidget, &NumbersWidget::specialBtnClicked, this, &VirtualKeyboardWidget::onSpecialBtnClicked); + connect(m_numbersWidget, &NumbersWidget::narmalBtnClicked, this, &VirtualKeyboardWidget::onNormalBtnClicked); + connect(m_charsWidget, &CharsWidget::specialBtnClicked, this, &VirtualKeyboardWidget::onSpecialBtnClicked); + connect(m_charsWidget, &CharsWidget::normalBtnClicked, this, &VirtualKeyboardWidget::onNormalBtnClicked); + connect(m_charsMoreWidget, &CharsMoreWidget::specialBtnClicked, this, &VirtualKeyboardWidget::onSpecialBtnClicked); + connect(m_charsMoreWidget, &CharsMoreWidget::normalBtnClicked, this, &VirtualKeyboardWidget::onNormalBtnClicked); +} + +void VirtualKeyboardWidget::adjustGeometry() +{ + QWidget *parentWidget = qobject_cast(parent()); + if (parentWidget) { + //qDebug()<< "parent: " << parentWidget <<"Parent gemotry:"<geometry(); + double lfWidth = parentWidget->geometry().width(); + double lfHeight = parentWidget->geometry().height(); + m_isVertical = lfHeight > lfWidth; + m_lfWidthScale = lfWidth/KEYBOARD_PARENT_DEFAULT_WIDTH; + if (m_isVertical) + m_lfHeightScale = lfHeight / KEYBOARD_PARENT_DEFAULT_WIDTH; + else + m_lfHeightScale = lfHeight / KEYBOARD_PARENT_DEFAULT_HEIGHT; + if (m_isdragState) { + lfWidth = m_lfWidthScale * KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH; + lfHeight = m_lfHeightScale * KEYBOARD_DRAGSHOW_FIXED_DEFAULT_HEIGHT; + setGeometry(QRect(m_lfWidthScale * (KEYBOARD_PARENT_DEFAULT_WIDTH - KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH) / 2, + parentWidget->geometry().height() - lfHeight, + lfWidth, lfHeight)); + m_dragWidget->show(); + } else { + lfWidth = m_lfWidthScale * KEYBOARD_FIXED_DEFAULT_WIDTH; + lfHeight = m_lfHeightScale * KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT; + m_dragWidget->hide(); + setGeometry(QRect(0, parentWidget->geometry().height()-lfHeight, lfWidth, lfHeight)); + } + + //qDebug()<<"Widget geometry:"<show(); + } else { + setGeometry(QRect(0, 0, + KEYBOARD_FIXED_DEFAULT_WIDTH, KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT)); + m_dragWidget->hide(); + } + m_lfWidthScale = 1.0; + m_lfHeightScale = 1.0; + m_isVertical = false; + } + if (m_dragWidget) { + m_dragWidget->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } + if (m_kbTitle) { + m_kbTitle->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } + if (m_lettersWidget) { + m_lettersWidget->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } + if (m_numbersWidget) { + m_numbersWidget->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } + if (m_charsWidget) { + m_charsWidget->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } + if (m_charsMoreWidget) { + m_charsMoreWidget->adjustGeometry(m_lfWidthScale, m_lfHeightScale, m_isVertical, m_isdragState); + } +} + +bool VirtualKeyboardWidget::eventFilter(QObject *watched, QEvent *event) +{ + if(watched != m_dragWidget && !isMove) return QWidget::eventFilter(watched, event); + switch(event->type()) + { + case QEvent::MouseButtonPress: + onMouseEvents(1); + return true; + case QEvent::MouseMove: + onMouseEvents(2); + return true; + case QEvent::MouseButtonRelease: + onMouseEvents(3); + return true; + default: + break; + } + return QWidget::eventFilter(watched, event); +} + +void VirtualKeyboardWidget::resizeEvent(QResizeEvent *event) +{ + adjustGeometry(); +} + +void VirtualKeyboardWidget::paintEvent(QPaintEvent *event) +{ + QPainterPath path; + QPainter painter(this); + painter.setOpacity(1.0); + painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; + painter.setClipping(true); + painter.setPen(Qt::transparent); + if (m_isdragState) { + path.addRoundedRect(this->rect(), 16, 16); + } else { + path.addRoundedRect(this->rect(), 0, 0); + } + path.setFillRule(Qt::WindingFill); + painter.setBrush(QColor("#EBEDEF")); + painter.setPen(Qt::transparent); + painter.drawPath(path); + QWidget::paintEvent(event); +} + +void VirtualKeyboardWidget::onSpecialBtnClicked(QString keyName) +{ + Modifier::MOD mod = Modifier::getModifier(keyName); + FuncKey::FUNCKEY funcKey = FuncKey::getKey(keyName); + if (mod != Modifier::UNKNOWN) { + if(vKeyboard->hasModifier(mod)) { + vKeyboard->removeModifier(mod); + m_lettersWidget->changeFuncKeyStyle(keyName, false); + } else { + vKeyboard->addModifier(mod); + m_lettersWidget->changeFuncKeyStyle(keyName, true); + } + if (keyName == BTN_CAPSLOCK) { + Q_EMIT keyPressed(FuncKey::CAPSLOCK); + clearModifier(); + } + } else if(funcKey != FuncKey::UNKNOWN) { + Q_EMIT keyPressed(funcKey); + } else if (keyName == PAGE_CHARSMORE) { + m_stackedWidget->setCurrentIndex(VKB_PAGE_CHARSMORE); + update(); + } else if (keyName == PAGE_CHAR) { + m_stackedWidget->setCurrentIndex(VKB_PAGE_CHARS); + update(); + } else if (keyName == PAGE_NUMBER) { + m_stackedWidget->setCurrentIndex(VKB_PAGE_NUMBERS); + update(); + } else if (keyName == PAGE_LETTER) { + m_stackedWidget->setCurrentIndex(VKB_PAGE_LETTERS); + update(); + } else if (keyName == BTN_FLOAT) { + m_isdragState = !m_isdragState; + adjustGeometry(); + Q_EMIT aboutToFloat(); + } else if (keyName == BTN_CLOSE) { + Q_EMIT aboutToClose(); + } +} + +void VirtualKeyboardWidget::onNormalBtnClicked(QChar c) +{ + Q_EMIT keyPressed(c); + clearModifier(); +} + +void VirtualKeyboardWidget::clearModifier() +{ + for(auto mod : vKeyboard->getAllModifier()) { + QString modName = Modifier::getModifierName(mod); + m_lettersWidget->changeFuncKeyStyle(modName, false); + } + vKeyboard->clearModifier(); +} + +void VirtualKeyboardWidget::onMouseEvents(int type) +{ + switch (type) { + case 1: + { + isMove = true; + lastPoint = QCursor::pos(); + break; + } + case 2: + { + if(isMove) + { + QPoint cPoint = QCursor::pos(); + QPoint p = pos(); + p.setX(p.x() - lastPoint.x() + cPoint.x()); + p.setY(p.y() - lastPoint.y() + cPoint.y()); + lastPoint = cPoint; + move(p); + } + break; + } + case 3: + { + isMove = false; + break; + } + default: + break; + } +} + + +bool VirtualKeyboardWidget::getFloatStatus() +{ + return m_isdragState; +} diff --git a/VirtualKeyboard/src/virtualkeyboardwidget.h b/VirtualKeyboard/src/virtualkeyboardwidget.h new file mode 100644 index 0000000..3238662 --- /dev/null +++ b/VirtualKeyboard/src/virtualkeyboardwidget.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 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 3, 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, see . + * +**/ +#ifndef VIRTUALKEYBOARDWIDGET_H +#define VIRTUALKEYBOARDWIDGET_H + +#include +#include +#include +#include +#include "fakekeyboard.h" +#include "plasma-shell-manager.h" + +class DragWidget; +class KBTitle; +class LettersWidget; +class NumbersWidget; +class CharsWidget; +class CharsMoreWidget; +class VirtualKeyboardWidget : public QWidget +{ + Q_OBJECT +public: + enum { + VKB_PAGE_LETTERS, + VKB_PAGE_NUMBERS, + VKB_PAGE_CHARS, + VKB_PAGE_CHARSMORE, + }; + VirtualKeyboardWidget(QWidget *parent = nullptr); + virtual ~VirtualKeyboardWidget(); + bool getFloatStatus(); + +public Q_SLOTS: + void onNormalBtnClicked(QChar c); + void onSpecialBtnClicked(QString keyName); + +Q_SIGNALS: + void aboutToClose(); + void aboutToFloat(); + void keyPressed(QChar c); + void keyPressed(FuncKey::FUNCKEY key); + +protected: + void paintEvent(QPaintEvent *) override; + void resizeEvent(QResizeEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; + +private: + void initUI(); + void initConnections(); + void adjustGeometry(); + void onMouseEvents(int type); + void clearModifier(); + +private: + double m_lfWidthScale; + double m_lfHeightScale; + bool m_isVertical; + QStackedWidget *m_stackedWidget = nullptr; + LettersWidget *m_lettersWidget = nullptr; + NumbersWidget *m_numbersWidget = nullptr; + CharsWidget *m_charsWidget = nullptr; + CharsMoreWidget *m_charsMoreWidget = nullptr; + KBTitle *m_kbTitle = nullptr; + DragWidget *m_dragWidget = nullptr; + int m_nCurPage; + QList m_listPageHis; + bool m_isdragState = false;//是否为悬浮状态 + bool isMove;// 是否可移动 + QPoint lastPoint;// 拖拽控件时 记录当前控件的位置 + FakeKeyboard *vKeyboard; +}; + +#endif // VIRTUALKEYBOARDWIDGET_H diff --git a/VirtualKeyboard/src/x11keyboard.cpp b/VirtualKeyboard/src/x11keyboard.cpp index 25b36d8..c7cd2c8 100644 --- a/VirtualKeyboard/src/x11keyboard.cpp +++ b/VirtualKeyboard/src/x11keyboard.cpp @@ -33,7 +33,7 @@ struct CharMap XSpecialSymbolMap[] { {'\'', XK_quoteright}, {'@', XK_at}, {'#', XK_numbersign}, - {'$', XK_dollar}, + {'$', XK_dollar}, {'%', XK_percent}, {'&', XK_ampersand}, {'*', XK_asterisk}, @@ -76,14 +76,15 @@ QMap funckeyMap = { {FuncKey::UP, XK_Up}, {FuncKey::DOWN, XK_Down}, {FuncKey::LEFT, XK_Left}, - {FuncKey::RIGHT, XK_Right} + {FuncKey::RIGHT, XK_Right}, + {FuncKey::CAPSLOCK, XK_Caps_Lock} }; QMap modifierMap = { {Modifier::CTRL, XK_Control_L}, {Modifier::ALT, XK_Alt_L}, {Modifier::SUPER, XK_Super_L}, - {Modifier::SHIFT, XK_Shift_L} + {Modifier::SHIFT, XK_Shift_L}, }; QVector shiftKeyVec = {'~', '!', '@', '#', '$', '%', '^', '&', '*', @@ -165,6 +166,7 @@ void X11Keyboard::onKeyPressed(QChar c) void X11Keyboard::onKeyPressed(FuncKey::FUNCKEY key) { KeyCode keyCode; + KeySym keysym = funckeyMap[key]; if(keysym != NoSymbol) @@ -200,6 +202,9 @@ void X11Keyboard::sendKey(unsigned int keyCode) KeyCode keyCode = XKeysymToKeycode(display, modifierMap[mod]); XTestFakeKeyEvent(display, keyCode, False, 2); } + + //输入结束清除shift状态 + isShift = false; XFlush(display); } diff --git a/data/screensaver-startup.sh b/data/screensaver-startup.sh index c110d2e..822388a 100755 --- a/data/screensaver-startup.sh +++ b/data/screensaver-startup.sh @@ -1,5 +1,4 @@ #!/bin/bash -/usr/lib/ukui-screensaver/set4kScale >/dev/null 2>&1 ukui-screensaver-dialog --lock-startup & >/dev/null 2>&1 /usr/lib/ukui-screensaver/screensaver-focus-helper & >/dev/null 2>&1 diff --git a/debian/changelog b/debian/changelog index 745320d..f4ea900 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ukui-screensaver (4.0.0.0-ok1~0426) yangtze; urgency=medium + + * BUG号: 137546 【RISC-V】【控制面板】无法更改屏幕缩放 + * 需求号:无 + * 其他修改说明:无 + + -- Yang Min Wed, 26 Apr 2023 19:49:20 +0800 + ukui-screensaver (3.22.1.3-ok11~0412) yangtze; urgency=medium * BUG号:I5XFFQ 锁屏登入界面无键盘图标,无实体键盘时无法输入 diff --git a/debian/control b/debian/control index dd14820..ad39a66 100644 --- a/debian/control +++ b/debian/control @@ -25,6 +25,7 @@ Build-Depends: debhelper-compat (= 12), libgsettings-qt-dev, libkf5windowsystem-dev, libmatemixer-dev, + libimlib2-dev, libukui-log4qt-dev, libkysdk-sysinfo-dev (>> 1.1.0kylin1), ukui-input-gather (>=1.0.0.2), diff --git a/i18n_ts/bo.ts b/i18n_ts/bo.ts index c88658a..f0f3219 100644 --- a/i18n_ts/bo.ts +++ b/i18n_ts/bo.ts @@ -4,107 +4,119 @@ AuthDialog - + Authentication failure, Please try again - - - - + + + + Please try again in %1 minutes. - - - - + + Enter the ukey password + + + + + Insert the ukey into the USB port + + + + + + + Please try again in %1 seconds. - - - - + + + + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock - - + + Password cannot be empty - + Password - + Input Password - + Login - + Retry - + Failed to verify %1, please enter password to unlock - + + Unable to verify %1, please enter password to unlock - + + Failed to verify %1, you still have %2 verification opportunities - + Abnormal network @@ -168,6 +180,32 @@ + + CharsMoreWidget + + + &&?! + + + + + CharsWidget + + + More + + + + + ABC + + + + + 123 + + + ConfForm @@ -302,6 +340,11 @@ + ukey + + + + QRCode @@ -1599,14 +1642,6 @@ - - KeyboardWidget - - - KeyboardWidget - - - KylinNM @@ -1741,6 +1776,29 @@ + + LettersWidget + + + &&?! + + + + + 123 + + + + + Ctrl + + + + + Alt + + + LockWidget @@ -1759,17 +1817,17 @@ - + Multiple users are logged in at the same time.Are you sure you want to reboot this system? - + LAN - + WLAN @@ -1777,12 +1835,17 @@ LoginOptionsWidget - + Login Options - + + Password + + + + Identify device removed! @@ -1797,6 +1860,19 @@ + + NumbersWidget + + + &&?! + + + + + Return + + + OneConnForm @@ -1973,8 +2049,8 @@ - - Reboot + + Restart @@ -1983,17 +2059,17 @@ - + Shut Down - + Hibernate - + Suspend @@ -2001,12 +2077,12 @@ QObject - + The screensaver is active. - + The screensaver is inactive. @@ -2016,72 +2092,6 @@ - this is only shown for laptops with multiple batteries - - - - - - this is only shown for laptops with multiple batteries - - - - - - laptop primary battery - - - - - - battery-backed AC power source - - - - - - a monitor is a device to measure voltage and current - - - - - - wireless mice with internal batteries - - - - - - wireless keyboard with internal battery - - - - - - portable device - - - - - - cell phone (mobile...) - - - - - - media player, mp3 etc - - - - - - tablet device - - - - - tablet device @@ -2089,17 +2099,17 @@ Screensaver - + Picture does not exist - + View - + You have new notification @@ -2107,7 +2117,7 @@ SleepTime - + You have rested @@ -2135,22 +2145,22 @@ - + The following program is running to prevent the system from reboot! - + The following program is running to prevent the system from shutting down! - + The following program is running to prevent the system from suspend! - + The following program is running to prevent the system from hibernate! @@ -2287,57 +2297,78 @@ + + delay + + + how long to show lock + + + + + has-lock + + + if show lock + + + main - + Screensaver for ukui-screensaver - + show on root window - + show on window. - + window id - + Start command for the ukui ScreenSaver. - + lock the screen immediately - + query the status of the screen saver - + unlock the screen saver - + show the screensaver - + + show blank and delay to lock,param:idle/lid/lowpower + + + + Dialog for the ukui ScreenSaver. @@ -2357,5 +2388,15 @@ show screensaver immediately + + + show blank screensaver immediately and delay time to show lock + + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/bo_CN.ts b/i18n_ts/bo_CN.ts index e4e93b5..2774fdb 100644 --- a/i18n_ts/bo_CN.ts +++ b/i18n_ts/bo_CN.ts @@ -107,6 +107,14 @@ Abnormal network + + Enter the ukey password + གསང་བའི་ཨང་གྲངས་ནང་འཇུག་བྱེད་པ། + + + Insert the ukey into the USB port + བདེ་འཇགས་ཀྱི་གསང་བའི་ལྡེ་མིག་དེ་USBཡི་སྣེ་འདྲེན་དུ་འཇུག་རོགས། + BatteryWidget @@ -157,6 +165,28 @@ སྒྲིག་ཆས་ཀྱི་མིང་། + + CharsMoreWidget + + &&?! + + + + + CharsWidget + + More + + + + ABC + + + + 123 + + + ConfForm @@ -266,6 +296,10 @@ QRCode + + ukey + + DigitalAuthDialog @@ -1301,13 +1335,6 @@ - - KeyboardWidget - - KeyboardWidget - - - KylinNM @@ -1403,6 +1430,25 @@ + + LettersWidget + + &&?! + + + + 123 + + + + Ctrl + + + + Alt + + + LockWidget @@ -1448,6 +1494,10 @@ Identify device removed! + + Password + + MyLineEdit @@ -1456,6 +1506,17 @@ + + NumbersWidget + + &&?! + + + + Return + + + OneConnForm @@ -1597,7 +1658,7 @@ Restart - བསྐྱར་སློང་། + བསྐྱར་སློང་། Switch User @@ -1615,10 +1676,6 @@ lock - - Reboot - - Shut Down @@ -1641,61 +1698,6 @@ S: - - - this is only shown for laptops with multiple batteries - - - - - this is only shown for laptops with multiple batteries - - - - - laptop primary battery - - - - - battery-backed AC power source - - - - - a monitor is a device to measure voltage and current - - - - - wireless mice with internal batteries - - - - - wireless keyboard with internal battery - - - - - portable device - - - - - cell phone (mobile...) - - - - - media player, mp3 etc - - - - - tablet device - - tablet device @@ -1872,6 +1874,20 @@ + + delay + + how long to show lock + + + + + has-lock + + if show lock + + + main @@ -1926,5 +1942,17 @@ show screensaver immediately + + show blank and delay to lock,param:idle/lid/lowpower + + + + show blank screensaver immediately and delay time to show lock + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/es.ts b/i18n_ts/es.ts index d117fe0..fc24bdf 100644 --- a/i18n_ts/es.ts +++ b/i18n_ts/es.ts @@ -107,6 +107,14 @@ Abnormal network + + Enter the ukey password + + + + Insert the ukey into the USB port + + BatteryWidget @@ -222,6 +230,28 @@ + + CharsMoreWidget + + &&?! + + + + + CharsWidget + + More + Más + + + ABC + + + + 123 + + + ConfForm @@ -331,6 +361,10 @@ QRCode + + ukey + + DigitalAuthDialog @@ -1370,7 +1404,7 @@ KeyboardWidget KeyboardWidget - TecladoWidget + TecladoWidget @@ -1468,6 +1502,25 @@ + + LettersWidget + + &&?! + + + + 123 + + + + Ctrl + + + + Alt + + + LockWidget @@ -1511,7 +1564,7 @@ Password - Contraseña + Contraseña Identify device removed! @@ -1525,6 +1578,17 @@ + + NumbersWidget + + &&?! + + + + Return + + + OneConnForm @@ -1672,10 +1736,6 @@ lock - - Reboot - - Shut Down @@ -1684,6 +1744,10 @@ Hibernate + + Restart + + QObject @@ -1698,61 +1762,6 @@ S: - - - this is only shown for laptops with multiple batteries - - - - - this is only shown for laptops with multiple batteries - - - - - laptop primary battery - - - - - battery-backed AC power source - - - - - a monitor is a device to measure voltage and current - - - - - wireless mice with internal batteries - - - - - wireless keyboard with internal battery - - - - - portable device - - - - - cell phone (mobile...) - - - - - media player, mp3 etc - - - - - tablet device - - tablet device @@ -1917,6 +1926,20 @@ + + delay + + how long to show lock + + + + + has-lock + + if show lock + + + main @@ -1971,5 +1994,17 @@ show screensaver immediately + + show blank and delay to lock,param:idle/lid/lowpower + + + + show blank screensaver immediately and delay time to show lock + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/fr.ts b/i18n_ts/fr.ts index 679e732..8a0b976 100644 --- a/i18n_ts/fr.ts +++ b/i18n_ts/fr.ts @@ -107,6 +107,14 @@ Abnormal network + + Enter the ukey password + + + + Insert the ukey into the USB port + + BatteryWidget @@ -222,6 +230,28 @@ + + CharsMoreWidget + + &&?! + + + + + CharsWidget + + More + Plus + + + ABC + + + + 123 + + + ConfForm @@ -331,6 +361,10 @@ QRCode + + ukey + + DigitalAuthDialog @@ -1370,7 +1404,7 @@ KeyboardWidget KeyboardWidget - KeyboardWidget + KeyboardWidget @@ -1468,6 +1502,25 @@ + + LettersWidget + + &&?! + + + + 123 + + + + Ctrl + + + + Alt + + + LockWidget @@ -1511,7 +1564,7 @@ Password - Mot de passe + Mot de passe Identify device removed! @@ -1525,6 +1578,17 @@ + + NumbersWidget + + &&?! + + + + Return + + + OneConnForm @@ -1672,10 +1736,6 @@ lock - - Reboot - - Shut Down @@ -1684,6 +1744,10 @@ Hibernate + + Restart + + QObject @@ -1698,61 +1762,6 @@ S: - - - this is only shown for laptops with multiple batteries - - - - - this is only shown for laptops with multiple batteries - - - - - laptop primary battery - - - - - battery-backed AC power source - - - - - a monitor is a device to measure voltage and current - - - - - wireless mice with internal batteries - - - - - wireless keyboard with internal battery - - - - - portable device - - - - - cell phone (mobile...) - - - - - media player, mp3 etc - - - - - tablet device - - tablet device @@ -1917,6 +1926,20 @@ + + delay + + how long to show lock + + + + + has-lock + + if show lock + + + main @@ -1971,5 +1994,17 @@ show screensaver immediately + + show blank and delay to lock,param:idle/lid/lowpower + + + + show blank screensaver immediately and delay time to show lock + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/pt.ts b/i18n_ts/pt.ts index c9077d7..ed89cdf 100644 --- a/i18n_ts/pt.ts +++ b/i18n_ts/pt.ts @@ -107,6 +107,14 @@ Abnormal network + + Enter the ukey password + + + + Insert the ukey into the USB port + + BatteryWidget @@ -222,6 +230,28 @@ + + CharsMoreWidget + + &&?! + + + + + CharsWidget + + More + Mais + + + ABC + + + + 123 + + + ConfForm @@ -331,6 +361,10 @@ QRCode + + ukey + + DigitalAuthDialog @@ -1370,7 +1404,7 @@ KeyboardWidget KeyboardWidget - KeyboardWidget + KeyboardWidget @@ -1468,6 +1502,25 @@ + + LettersWidget + + &&?! + + + + 123 + + + + Ctrl + + + + Alt + + + LockWidget @@ -1511,7 +1564,7 @@ Password - Senha + Senha Identify device removed! @@ -1525,6 +1578,17 @@ + + NumbersWidget + + &&?! + + + + Return + + + OneConnForm @@ -1672,10 +1736,6 @@ lock - - Reboot - - Shut Down @@ -1684,6 +1744,10 @@ Hibernate + + Restart + + QObject @@ -1698,61 +1762,6 @@ S: - - - this is only shown for laptops with multiple batteries - - - - - this is only shown for laptops with multiple batteries - - - - - laptop primary battery - - - - - battery-backed AC power source - - - - - a monitor is a device to measure voltage and current - - - - - wireless mice with internal batteries - - - - - wireless keyboard with internal battery - - - - - portable device - - - - - cell phone (mobile...) - - - - - media player, mp3 etc - - - - - tablet device - - tablet device @@ -1917,6 +1926,20 @@ + + delay + + how long to show lock + + + + + has-lock + + if show lock + + + main @@ -1971,5 +1994,17 @@ show screensaver immediately + + show blank and delay to lock,param:idle/lid/lowpower + + + + show blank screensaver immediately and delay time to show lock + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/ru.ts b/i18n_ts/ru.ts index 82e351f..cf16e7f 100644 --- a/i18n_ts/ru.ts +++ b/i18n_ts/ru.ts @@ -107,6 +107,14 @@ Abnormal network + + Enter the ukey password + + + + Insert the ukey into the USB port + + BatteryWidget @@ -222,6 +230,28 @@ + + CharsMoreWidget + + &&?! + + + + + CharsWidget + + More + Больше + + + ABC + + + + 123 + + + ConfForm @@ -331,6 +361,10 @@ QRCode + + ukey + + DigitalAuthDialog @@ -1370,7 +1404,7 @@ KeyboardWidget KeyboardWidget - KeyboardWidget + KeyboardWidget @@ -1468,6 +1502,25 @@ + + LettersWidget + + &&?! + + + + 123 + + + + Ctrl + + + + Alt + + + LockWidget @@ -1511,7 +1564,7 @@ Password - пароль + пароль Identify device removed! @@ -1525,6 +1578,17 @@ + + NumbersWidget + + &&?! + + + + Return + + + OneConnForm @@ -1672,10 +1736,6 @@ lock - - Reboot - - Shut Down @@ -1684,6 +1744,10 @@ Hibernate + + Restart + + QObject @@ -1698,61 +1762,6 @@ S: - - - this is only shown for laptops with multiple batteries - - - - - this is only shown for laptops with multiple batteries - - - - - laptop primary battery - - - - - battery-backed AC power source - - - - - a monitor is a device to measure voltage and current - - - - - wireless mice with internal batteries - - - - - wireless keyboard with internal battery - - - - - portable device - - - - - cell phone (mobile...) - - - - - media player, mp3 etc - - - - - tablet device - - tablet device @@ -1917,6 +1926,20 @@ + + delay + + how long to show lock + + + + + has-lock + + if show lock + + + main @@ -1971,5 +1994,17 @@ show screensaver immediately + + show blank and delay to lock,param:idle/lid/lowpower + + + + show blank screensaver immediately and delay time to show lock + + + + show blank screensaver immediately and if lock + + diff --git a/i18n_ts/tr.ts b/i18n_ts/tr.ts index f08d2ff..2fecce2 100644 --- a/i18n_ts/tr.ts +++ b/i18n_ts/tr.ts @@ -16,7 +16,7 @@ Parola - + Retry Yeniden Dene @@ -41,102 +41,114 @@ Kimlik doğrulama hatası, hala %1 kalan denemen var - + Authentication failure, Please try again - - - - + + + + Please try again in %1 minutes. - - - - + + Enter the ukey password + + + + + Insert the ukey into the USB port + + + + + + + Please try again in %1 seconds. - - - - + + + + Account locked permanently. - + Verify face recognition or enter password to unlock - + Press fingerprint or enter password to unlock - + Verify voiceprint or enter password to unlock - + Verify finger vein or enter password to unlock - + Verify iris or enter password to unlock - + Use the bound wechat scanning code or enter the password to unlock - - + + Password cannot be empty - + Password - + Input Password - + Login - + Failed to verify %1, please enter password to unlock - + + Unable to verify %1, please enter password to unlock - + + Failed to verify %1, you still have %2 verification opportunities - + Abnormal network @@ -250,6 +262,32 @@ Tamam + + CharsMoreWidget + + + &&?! + + + + + CharsWidget + + + More + + + + + ABC + + + + + 123 + + + ConfForm @@ -384,6 +422,11 @@ + ukey + + + + QRCode @@ -1681,14 +1724,6 @@ - - KeyboardWidget - - - KeyboardWidget - - - KylinNM @@ -1823,6 +1858,29 @@ + + LettersWidget + + + &&?! + + + + + 123 + + + + + Ctrl + + + + + Alt + + + LockWidget @@ -1849,17 +1907,17 @@ Kullanıcı Değiştir - + Multiple users are logged in at the same time.Are you sure you want to reboot this system? - + LAN - + WLAN @@ -1867,16 +1925,17 @@ LoginOptionsWidget - + Login Options + Password - Parola + Parola - + Identify device removed! @@ -1891,6 +1950,19 @@ + + NumbersWidget + + + &&?! + + + + + Return + + + OneConnForm @@ -2089,15 +2161,11 @@ Log Out Çıkış - - Restart - Yeniden Başlat - - - Reboot - + + Restart + Yeniden Başlat @@ -2105,17 +2173,17 @@ Bilgisayarı Kapat - + Shut Down - + Hibernate - + Suspend @@ -2123,12 +2191,12 @@ QObject - + The screensaver is active. - + The screensaver is inactive. @@ -2138,72 +2206,6 @@ - this is only shown for laptops with multiple batteries - - - - - - this is only shown for laptops with multiple batteries - - - - - - laptop primary battery - - - - - - battery-backed AC power source - - - - - - a monitor is a device to measure voltage and current - - - - - - wireless mice with internal batteries - - - - - - wireless keyboard with internal battery - - - - - - portable device - - - - - - cell phone (mobile...) - - - - - - media player, mp3 etc - - - - - - tablet device - - - - - tablet device @@ -2219,17 +2221,17 @@ çıkış - + Picture does not exist - + View - + You have new notification @@ -2245,7 +2247,7 @@ SleepTime - + You have rested @@ -2273,22 +2275,22 @@ - + The following program is running to prevent the system from reboot! - + The following program is running to prevent the system from shutting down! - + The following program is running to prevent the system from suspend! - + The following program is running to prevent the system from hibernate! @@ -2425,37 +2427,58 @@ + + delay + + + how long to show lock + + + + + has-lock + + + if show lock + + + main - + Start command for the ukui ScreenSaver. Ukui Ekran Koruyucu için başlatma komutu. - + lock the screen immediately Ekranı hemen kilitle - + query the status of the screen saver - + unlock the screen saver - + show the screensaver - + + show blank and delay to lock,param:idle/lid/lowpower + + + + Dialog for the ukui ScreenSaver. @@ -2476,22 +2499,32 @@ - + + show blank screensaver immediately and delay time to show lock + + + + + show blank screensaver immediately and if lock + + + + Screensaver for ukui-screensaver - + show on root window - + show on window. - + window id diff --git a/i18n_ts/zh_CN.ts b/i18n_ts/zh_CN.ts index a159196..ac55ca7 100644 --- a/i18n_ts/zh_CN.ts +++ b/i18n_ts/zh_CN.ts @@ -16,7 +16,7 @@ 使用密码认证 - + Retry 重试 @@ -45,71 +45,72 @@ 账户锁定%1分钟由于%2次错误尝试 - - - - + + + + Please try again in %1 minutes. 请%1分钟后再试 - - - - + + + + Please try again in %1 seconds. 请%1秒后再试 - - - - + + + + Account locked permanently. 账号已被永久锁定 - + Verify face recognition or enter password to unlock 验证人脸识别或输入密码解锁 - + Press fingerprint or enter password to unlock 按压指纹或输入密码解锁 - + Verify voiceprint or enter password to unlock 验证声纹或输入密码解锁 - + Verify finger vein or enter password to unlock 验证指静脉或输入密码解锁 - + Verify iris or enter password to unlock 验证虹膜或输入密码解锁 - + Input Password 输入密码 - + Failed to verify %1, please enter password to unlock 验证%1失败,请输入密码解锁 - + + Unable to verify %1, please enter password to unlock 无法验证%1,请输入密码解锁 - + Abnormal network 网络异常 @@ -118,8 +119,8 @@ 使用绑定的微信扫码或输入密码登录 - - + + Password cannot be empty 密码不能为空 @@ -132,7 +133,8 @@ 无法验证%1,请输入密码. - + + Failed to verify %1, you still have %2 verification opportunities 验证%1失败,您还有%2次尝试机会 @@ -161,22 +163,32 @@ 请输入密码或者录入指纹 - + Authentication failure, Please try again 认证失败,请重试 - + Use the bound wechat scanning code or enter the password to unlock 使用绑定的微信扫码或输入密码解锁 - + + Enter the ukey password + 输入安全密钥密码 + + + + Insert the ukey into the USB port + 请将安全密钥插入USB端口 + + + Password 密码 - + Login 登录 @@ -298,6 +310,44 @@ 确定 + + CharsMoreWidget + + Return + 返回 + + + + &&?! + + + + + CharsWidget + + + More + 更多 + + + + ABC + + + + + 123 + + + + Return + 返回 + + + Number + 数字 + + ConfForm @@ -444,6 +494,11 @@ + ukey + + + + QRCode 二维码 @@ -1781,14 +1836,6 @@ 获取验证码 - - KeyboardWidget - - - KeyboardWidget - - - KylinDBus @@ -2034,6 +2081,37 @@ 连接无线网络成功 + + LettersWidget + + Symbol + 符号 + + + Num + 数字 + + + + &&?! + + + + + 123 + + + + + Ctrl + + + + + Alt + + + LockWidget @@ -2060,17 +2138,17 @@ 切换用户 - + Multiple users are logged in at the same time.Are you sure you want to reboot this system? 同时有多个用户登录系统,您确定要退出系统吗? - + LAN 有线网络 - + WLAN 无线局域网 @@ -2078,20 +2156,21 @@ LoginOptionsWidget - + Login Options 登录选项 + Password - 密码 + 密码 Wechat 微信 - + Identify device removed! 校验设备已移除! @@ -2106,6 +2185,23 @@ 短信验证码 + + NumbersWidget + + Symbol + 符号 + + + + &&?! + + + + + Return + 返回 + + OneConnForm @@ -2333,14 +2429,14 @@ 注销 + + Restart - 重启 + 重启 - - Reboot - 重启 + 重启 @@ -2348,17 +2444,17 @@ 关机 - + Shut Down 关机 - + Hibernate 休眠 - + Suspend 睡眠 @@ -2370,12 +2466,12 @@ QObject - + The screensaver is active. 屏幕保护程序已激活 - + The screensaver is inactive. 屏幕保护程序未激活 @@ -2400,7 +2496,7 @@ 退出 - + Picture does not exist 图片不存在 @@ -2417,12 +2513,12 @@ 您有%1条未读消息 - + You have new notification 您有新的消息 - + View 预览 @@ -2434,7 +2530,7 @@ 您已休息: - + You have rested 您已休息 @@ -2466,22 +2562,22 @@ 同时有多个用户登录系统,您确定要退出系统吗? - + The following program is running to prevent the system from suspend! 以下程序正在运行,阻止系统进入睡眠! - + The following program is running to prevent the system from hibernate! 以下程序正在运行,阻止系统进入休眠! - + The following program is running to prevent the system from shutting down! 以下程序正在运行,阻止系统关机! - + The following program is running to prevent the system from reboot! 以下程序正在运行,阻止系统重启! @@ -2641,37 +2737,58 @@ + + delay + + + how long to show lock + + + + + has-lock + + + if show lock + + + main - + Start command for the ukui ScreenSaver. 启动锁屏到命令 - + lock the screen immediately 马上锁定屏幕 - + query the status of the screen saver 获取锁屏状态 - + unlock the screen saver 解锁屏幕 - + show the screensaver - + + show blank and delay to lock,param:idle/lid/lowpower + + + + Dialog for the ukui ScreenSaver. @@ -2692,22 +2809,32 @@ - + + show blank screensaver immediately and delay time to show lock + + + + + show blank screensaver immediately and if lock + + + + Screensaver for ukui-screensaver - + show on root window - + show on window. - + window id diff --git a/screensaver/CMakeLists.txt b/screensaver/CMakeLists.txt index 834e258..ce810ff 100644 --- a/screensaver/CMakeLists.txt +++ b/screensaver/CMakeLists.txt @@ -1,6 +1,7 @@ pkg_check_modules(X11 REQUIRED x11) pkg_check_modules(XTST REQUIRED xtst) pkg_check_modules(QGS REQUIRED gsettings-qt) +pkg_check_modules(KDKINFO REQUIRED kysdk-sysinfo) include_directories(${PROJECT_BINARY_DIR}) include_directories(${PROJECT_SOURCE_DIR}/Common) @@ -9,14 +10,20 @@ include_directories( ${X11_INCLUDE_DIRS} ${XTST_INCLUDE_DIRS} ${QGS_INCLUDE_DIRS} + ${KDKINFO_INCLUDE_DIRS} ) +link_directories( + ${KDKINFO_LIBRARY_DIRS} + ) + set(EXTRA_LIBS ${EXTRA_LIBS} ${X11_LIBRARIES} ${XTST_LIBRARIES} - ${QGS_LIBRARIES} - Common + ${QGS_LIBRARIES} + ${KDKINFO_LIBRARIES} + Common ) qt5_add_resources(screensaver_SRC default.qrc diff --git a/screensaver/assets/default.qss b/screensaver/assets/default.qss index 868e216..7985c01 100644 --- a/screensaver/assets/default.qss +++ b/screensaver/assets/default.qss @@ -1,13 +1,10 @@ QLabel#dateOfWeek { - font-size:16px; color: #ffffff; } QLabel#dateOfLocaltime { - font-size:50px; color: #ffffff; } QLabel#dateOfDay { - font-size:16px; color: #ffffff; } QLabel#dateOfLunar { @@ -17,28 +14,22 @@ QLabel#dateOfLunar { QLabel#clockTime { background:rgba(255,255,255,0.15); border-radius: 6px; - font-size:20px; color: #ffffff; } QLabel#colon { - font-size:20px; color: #ffffff; } QLabel#restTime { - font-size:20px; color: #ffffff; opacity:0.6; } QLabel#centerLabel { - font-size:36px; color: #ffffff; } QLabel#authorLabel { - font-size:28px; color: #ffffff; } QLabel#myText{ - font-size:24px; border-radius: 6px; background: rgba(255, 255, 255, 82%); padding: 24px 24px 24px 24px; diff --git a/screensaver/main.cpp b/screensaver/main.cpp index c7d725f..28f3dd3 100644 --- a/screensaver/main.cpp +++ b/screensaver/main.cpp @@ -34,6 +34,7 @@ #include "config.h" +#define WORKING_DIRECTORY "/usr/share/ukui-screensaver" bool bControlFlg = false;//是否控制面板窗口 int main(int argc, char *argv[]) @@ -43,7 +44,15 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #endif QApplication a(argc, argv); - prctl(PR_SET_PDEATHSIG, SIGHUP); + prctl(PR_SET_PDEATHSIG, SIGHUP); + //加载翻译文件 + QString locale = QLocale::system().name(); + QTranslator translator; + QString qmFile = QString(WORKING_DIRECTORY"/i18n_qm/%1.qm").arg(locale); + translator.load(qmFile); + a.installTranslator(&translator); + qDebug() << "load translation file " << qmFile; + QCommandLineParser parser; QString windowId; @@ -72,14 +81,24 @@ int main(int argc, char *argv[]) scale = screen->devicePixelRatio(); if(onWindow){ - windowId = parser.value("window-id"); + windowId = parser.value("window-id"); WId wid = windowId.toULong(); + + /*获取窗口属性失败时程序退出,这是为了避免应用调用屏保的一瞬间崩溃,导致 + 屏保获取到一个不存在的winid,从而产生一个屏保窗口*/ + + if(!XGetWindowAttributes (QX11Info::display(), wid, &xwa)) + { + qDebug()<<"XGetWindowAttributes failed"; + exit(0); + } + QWindow* window = QWindow::fromWinId(wid); - window->setProperty("_q_embedded_native_parent_handle",QVariant(wid)); + s.setProperty("_q_embedded_native_parent_handle",QVariant(wid)); + /*设置焦点穿透*/ + s.setWindowFlag(Qt::WindowTransparentForInput, true); s.winId(); - s.windowHandle()->setParent(window); - XGetWindowAttributes (QX11Info::display(), wid, &xwa); -/* + s.windowHandle()->setParent(window); #ifndef USE_INTEL XClassHint ch; ch.res_name = NULL; @@ -87,9 +106,10 @@ int main(int argc, char *argv[]) XGetClassHint (QX11Info::display(), wid, &ch); if(ch.res_name && strcmp(ch.res_name,"ukui-control-center")==0){ bControlFlg = true; + s.addClickedEvent(); } #endif -*/ + //获取屏保所在屏幕对应的缩放比例。 for(auto screen : QGuiApplication::screens()) { diff --git a/screensaver/scconfiguration.cpp b/screensaver/scconfiguration.cpp index 09af22d..7342b76 100644 --- a/screensaver/scconfiguration.cpp +++ b/screensaver/scconfiguration.cpp @@ -21,6 +21,10 @@ #include #include #include +#include +#include +#include +#include "glibinterface.h" #define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver" #define GSETTINGS_SCHEMA_MATE_BACKGROUND "org.mate.background" @@ -119,9 +123,13 @@ void SCConfiguration::onConfigurationChanged(QString key) }else if(key == "menuTransparency"){ int blur_Num = stygsettings->get("menuTransparency").toInt(); Q_EMIT blurChanged(blur_Num); - }else if(key == "styleName"){ + }else if(key == "styleName"){ QString m_curStyle = stygsettings->get("styleName").toString(); Q_EMIT styleChanged(m_curStyle); + } else if (key == "systemFontSize") { + double m_curFontSize = stygsettings->get("systemFontSize").toDouble(); + qDebug() << "curFontSize = " << m_curFontSize ; + Q_EMIT fontSizeChanged(m_curFontSize); } } @@ -132,10 +140,19 @@ QString SCConfiguration::getDefaultBackground() backgroundFile = ukgsettings->get("background").toString(); } - if(ispicture(backgroundFile)) + if(ispicture(backgroundFile)) { return backgroundFile; - else - return "/usr/share/backgrounds/1-openkylin.jpg"; + } else { + char *systemName = kdk_system_get_systemName(); + if (systemName) { + if (QString(systemName) == "openKylin") { + free(systemName); + return "/usr/share/backgrounds/1-openkylin.jpg"; + } + free(systemName); + } + return "/usr/share/backgrounds/1-warty-final-ubuntukylin.jpg"; + } } int SCConfiguration::getTimeType() @@ -162,6 +179,30 @@ QString SCConfiguration::getDateType() return dateType; } +int SCConfiguration::getFontSize() +{ + double fontSize = 0; + if(stygsettings){ + QStringList keys = stygsettings->keys(); + if (keys.contains("systemFontSize")) { + fontSize = stygsettings->get("systemFontSize").toDouble(); + } + } + + double defaultFontSize = getDefaultFontSize(); + qDebug()<<"defaultFontSize = "<logicalDotsPerInch() > 0) + m_ptTopx = 72/(QApplication::primaryScreen()->logicalDotsPerInch()); + return m_ptTopx; +} + bool SCConfiguration::getAutoSwitch() { bool ret = false; diff --git a/screensaver/scconfiguration.h b/screensaver/scconfiguration.h index e41ba78..83322fe 100644 --- a/screensaver/scconfiguration.h +++ b/screensaver/scconfiguration.h @@ -38,6 +38,8 @@ public: QString getDefaultBackground(); //获取屏保默认背景 int getTimeType(); //获取显示时间格式 QString getDateType(); //获取日期格式 + int getFontSize(); //获取当前字体大小 + double getPtToPx(); bool getAutoSwitch(); //获取是否自动切换 bool getCShowRestTime(); //自定义是否显示休息时间 bool getUShowRestTime(); //UKUI是否显示休息时间 @@ -69,6 +71,7 @@ Q_SIGNALS: QString dateTypeChanged(QString type); int blurChanged(int num); QString styleChanged(QString type); + int fontSizeChanged(int fontSize); private: void initGsettings(); diff --git a/screensaver/screensaver.cpp b/screensaver/screensaver.cpp index fb5acd0..dfb1b31 100644 --- a/screensaver/screensaver.cpp +++ b/screensaver/screensaver.cpp @@ -68,7 +68,6 @@ #define KEY_MESSAGE_SHOW_ENABLED "show-message-enabled" #define KEY_HOURSYSTEM "hoursystem" #define KEY_DATE_FORMAT "date" -#define WORKING_DIRECTORY "/usr/share/ukui-screensaver" QTime Screensaver::m_currentTime = QTime::currentTime(); extern bool bControlFlg; @@ -99,14 +98,6 @@ Screensaver::Screensaver(bool isscreensaver,QWidget *parent): screenLabel(nullptr), respondClick(false) { - //加载翻译文件 - QString locale = QLocale::system().name(); - QTranslator translator; - QString qmFile = QString(WORKING_DIRECTORY"/i18n_qm/%1.qm").arg(locale); - translator.load(qmFile); - qApp->installTranslator(&translator); - qDebug() << "load translation file " << qmFile; - installEventFilter(this); // setWindowFlags(Qt::X11BypassWindowManagerHint); setUpdateCenterWidget(); @@ -123,7 +114,8 @@ Screensaver::Screensaver(bool isscreensaver,QWidget *parent): myText = configuration->getMyText(); }else isUShowRestTime = configuration->getUShowRestTime(); - + curFontSize = configuration->getFontSize(); + m_ptToPx = configuration->getPtToPx(); initUI(); m_background = new MBackground(); @@ -251,6 +243,11 @@ void Screensaver::onDateFormatChanged(QString type){ dateType = type; } +void Screensaver::onFontSizeChanged(int fontSize) +{ + curFontSize = fontSize; +} + void Screensaver::onMessageNumberChanged(int num) { int number = configuration->getMessageNumber(); @@ -513,12 +510,23 @@ void Screensaver::resizeEvent(QResizeEvent */*event*/) for(int i = 0;ifont().pixelSize(); + int fontpt = labelList.at(i)->font().pointSize(); + if (fontsize > 0) { #ifdef USE_INTEL - const QString SheetStyle = QString("font-size:%1px;").arg(fontsize/3); + const QString SheetStyle = QString("font-size:%1px;").arg(fontsize/3); #else - const QString SheetStyle = QString("font-size:%1px;").arg(fontsize/4); + const QString SheetStyle = QString("font-size:%1px;").arg(fontsize/4); #endif - labelList.at(i)->setStyleSheet(SheetStyle); + labelList.at(i)->setStyleSheet(SheetStyle); + } else { + QFont font = labelList.at(i)->font(); +#ifdef USE_INTEL + font.setPointSize(fontpt/3); +#else + font.setPointSize(fontpt/4); +#endif + labelList.at(i)->setFont(font); + } } QList childList = timeLayout->findChildren(); for (int i = 0; i < childList.count(); ++i) { @@ -637,10 +645,6 @@ void Screensaver::setUpdateCenterWidget() QString languageDirPath=cwdPath+"language/"; QString defaultLanguageFilePath=languageDirPath+"screensaver-en_US.ini"; qDebug()<<"homePath="<childGroups(); @@ -966,6 +970,9 @@ void Screensaver::setDatelayout() QVBoxLayout *vtimeLayout = new QVBoxLayout(timeLayout); this->dateOfLocaltime = new QLabel(this); + sysFont= qApp->font(); + sysFont.setPointSize((58 + curFontSize) *m_ptToPx); + this->dateOfLocaltime->setFont(sysFont); if(timeType == 12) this->dateOfLocaltime->setText(QDateTime::currentDateTime().toString("A hh:mm")); else @@ -977,10 +984,12 @@ void Screensaver::setDatelayout() vtimeLayout->addWidget(dateOfLocaltime); this->dateOfDay = new QLabel(this); + sysFont.setPointSize((16 + curFontSize) *m_ptToPx); + this->dateOfDay->setFont(sysFont); if(dateType == "cn") - this->dateOfDay->setText(QDate::currentDate().toString("yyyy/MM/dd ddd")); + this->dateOfDay->setText(QDate::currentDate().toString("yyyy/MM/dd ddd").replace("周","星期")); else - this->dateOfDay->setText(QDate::currentDate().toString("yyyy-MM-dd ddd")); + this->dateOfDay->setText(QDate::currentDate().toString("yyyy-MM-dd ddd").replace("周","星期")); this->dateOfDay->setObjectName("dateOfDay"); this->dateOfDay->setAlignment(Qt::AlignCenter); this->dateOfDay->adjustSize(); @@ -1094,9 +1103,9 @@ void Screensaver::updateTime() this->dateOfLocaltime->setText(curDateTime.toString("hh:mm")); if(dateType == "cn") - this->dateOfDay->setText(curDateTime.date().toString("yyyy/MM/dd ddd")); + this->dateOfDay->setText(curDateTime.date().toString("yyyy/MM/dd ddd").replace("周","星期")); else - this->dateOfDay->setText(curDateTime.date().toString("yyyy-MM-dd ddd")); + this->dateOfDay->setText(curDateTime.date().toString("yyyy-MM-dd ddd").replace("周","星期")); m_lastDateTime = curDateTime; } @@ -1169,7 +1178,8 @@ void Screensaver::setRandomText() } layout->addWidget(myTextLabel); } - + sysFont.setPointSize((18 + curFontSize) *m_ptToPx); + myTextLabel->setFont(sysFont); myTextLabel->setText(myText); myTextWidget->adjustSize(); if(myText != "") @@ -1201,8 +1211,6 @@ void Screensaver::setPreviewText(bool bVisible) void Screensaver::setCenterWidget() { - if (!qsettings) - return ; QStringList qlist = qsettings->childGroups(); if(qlist.count()<1) return; @@ -1266,10 +1274,14 @@ void Screensaver::setCenterWidget() authorlabel->hide(); } #endif - centerlabel1->setObjectName("centerLabel"); centerlabel2->setObjectName("centerLabel"); authorlabel->setObjectName("authorLabel"); + sysFont.setPointSize((36 + curFontSize) *m_ptToPx); + centerlabel1->setFont(sysFont); + centerlabel2->setFont(sysFont); + sysFont.setPointSize((28 + curFontSize) *m_ptToPx); + authorlabel->setFont(sysFont); qsettings->endGroup(); diff --git a/screensaver/screensaver.h b/screensaver/screensaver.h index e010fe1..84ee2e7 100644 --- a/screensaver/screensaver.h +++ b/screensaver/screensaver.h @@ -111,7 +111,7 @@ private: QPushButton *settingsButton; QPushButton *WallpaperButton; QWidget *buttonWidget; - QSettings *qsettings = nullptr; + QSettings *qsettings; MBackground *m_background; @@ -136,6 +136,9 @@ private: static QTime m_currentTime; int blur_Num; QString curStyle; + double curFontSize; + double m_ptToPx = 1.0; + QFont sysFont; WeatherManager *m_weatherManager=nullptr; QWidget *m_weatherLaout; @@ -181,6 +184,7 @@ private Q_SLOTS: void onDateFormatChanged(QString type); void onBlurNumChanged(int num); void onStyleChanged(QString style); + void onFontSizeChanged(int fontSize); QPixmap getPaddingPixmap(); }; diff --git a/screensaver/sleeptime.cpp b/screensaver/sleeptime.cpp index 7367a35..bd06b4d 100644 --- a/screensaver/sleeptime.cpp +++ b/screensaver/sleeptime.cpp @@ -20,11 +20,13 @@ #include #include #include +#include SleepTime::SleepTime(QWidget *parent) : QWidget(parent), sleepTime(0), m_nLastSleepLeave(0), - m_nLastSleepTimeSecs(0) + m_nLastSleepTimeSecs(0), + configuration(SCConfiguration::instance()) { init(); } @@ -39,18 +41,22 @@ void SleepTime::init() layout = new QHBoxLayout(this); layout->setDirection(QBoxLayout::RightToLeft); layout->setSpacing(8); - + curFontSize = configuration->getFontSize(); + sysFont = qApp->font(); + sysFont.setPointSize((20 + curFontSize) *m_ptToPx); for(int i=0;i<3;i++) { QLabel *label = new QLabel(this); label->setText("0"); label->setFixedSize(40,40); label->setObjectName("clockTime"); + label->setFont(sysFont); list.append(label); if (i < 2) { QLabel *colon = new QLabel(this); colon->setText(":"); colon->setObjectName("colon"); + colon->setFont(sysFont); list.append(colon); } } @@ -61,6 +67,8 @@ void SleepTime::init() } restTime = new QLabel(this); + sysFont.setPointSize((20 + curFontSize) *m_ptToPx); + restTime->setFont(sysFont); restTime->setText(tr("You have rested")); restTime->setObjectName("restTime"); restTime->setAlignment(Qt::AlignBottom); diff --git a/screensaver/sleeptime.h b/screensaver/sleeptime.h index e5e4186..2174ac5 100644 --- a/screensaver/sleeptime.h +++ b/screensaver/sleeptime.h @@ -19,6 +19,7 @@ #ifndef SLEEPTIME_H #define SLEEPTIME_H +#include "scconfiguration.h" #include #include #include @@ -36,6 +37,7 @@ public: void setSmallMode(); private: + SCConfiguration *configuration; QLabel *restTime; QList list; QHBoxLayout *layout; @@ -44,6 +46,9 @@ private: long long m_nLastSleepTimeSecs; QDateTime initTime; QDateTime m_lastTime; + double curFontSize; + double m_ptToPx = 1.0; + QFont sysFont; void init(); void setHour(int hour); diff --git a/set4kScale/CMakeLists.txt b/set4kScale/CMakeLists.txt index 09b8eef..9429dfa 100644 --- a/set4kScale/CMakeLists.txt +++ b/set4kScale/CMakeLists.txt @@ -3,13 +3,18 @@ project(set4kScale) pkg_check_modules(X11 REQUIRED x11) pkg_check_modules(XCB REQUIRED xcb) pkg_check_modules(QGS REQUIRED gsettings-qt) +pkg_check_modules(KDKINFO REQUIRED kysdk-sysinfo) include_directories( ${X11_INCLUDE_DIRS} ${XCB_INCLUDE_DIRS} ${QGS_INCLUDE_DIRS} + ${KDKINFO_INCLUDE_DIRS} ) +link_directories( + ${KDKINFO_LIBRARY_DIRS}) + set(CMAKE_AUTOMOC ON) set(bin_SRCS @@ -18,7 +23,7 @@ set(bin_SRCS ) add_executable(set4kScale ${bin_SRCS}) -target_link_libraries(set4kScale Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_LIBRARIES} ${XCB_LIBRARIES} ${QGS_LIBRARIES}) +target_link_libraries(set4kScale Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_LIBRARIES} ${XCB_LIBRARIES} ${QGS_LIBRARIES} ${KDKINFO_LIBRARIES}) install(TARGETS set4kScale diff --git a/set4kScale/main.cpp b/set4kScale/main.cpp index 5042642..80b6c1e 100644 --- a/set4kScale/main.cpp +++ b/set4kScale/main.cpp @@ -28,6 +28,8 @@ #include #include #include +#include + extern "C" { #include #include @@ -41,6 +43,26 @@ extern "C" { #define CURSOR_THEME "cursor-theme" +/* 设置DPI环境变量 */ +void setXresources(double scale) +{ + Display *dpy; + QGSettings *mouse_settings = new QGSettings(MOUSE_SCHEMA); + QString str = QString("Xft.dpi:\t%1\nXcursor.size:\t%2\nXcursor.theme:\t%3\n") + .arg(scale * 96) + .arg(mouse_settings->get(CURSOR_SIZE).toInt() * scale) + .arg(mouse_settings->get(CURSOR_THEME).toString()); + + dpy = XOpenDisplay(NULL); + XChangeProperty(dpy, RootWindow(dpy, 0), XA_RESOURCE_MANAGER, XA_STRING, 8, + PropModeReplace, (unsigned char *) str.toLatin1().data(), str.length()); + XCloseDisplay(dpy); + + qDebug() << "setXresources:" << str; + + delete mouse_settings; +} + /* 过滤低分辨率高缩放比情况 */ void screenScaleJudgement(QGSettings *settings) { @@ -57,40 +79,24 @@ void screenScaleJudgement(QGSettings *settings) if (width < 1920 && height < 1080) { state = true; - } else if (width == 1920 && height == 1080 && scale > 1.5) { + } + else if (width == 1920 && height == 1080 && scale > 1.5) { state = true; - } else if (width > 2560 && height > 1440) { + } + /* + else if (width > 2560 && height > 1440) { mScale = true; } + */ } - if (state && !mScale) { - QGSettings *mGsettings = new QGSettings(MOUSE_SCHEMA); - mGsettings->set(CURSOR_SIZE, 24); +// if (state && !mScale) { + if (state) { settings->set(SCALING_KEY, 1.0); - delete mGsettings; + scale = 1.0; } } -} - -/* 设置DPI环境变量 */ -void setXresources(int dpi) -{ - Display *dpy; - QGSettings *mouse_settings = new QGSettings(MOUSE_SCHEMA); - QString str = QString("Xft.dpi:\t%1\nXcursor.size:\t%2\nXcursor.theme:\t%3\n") - .arg(dpi) - .arg(mouse_settings->get(CURSOR_SIZE).toInt()) - .arg(mouse_settings->get(CURSOR_THEME).toString()); - - dpy = XOpenDisplay(NULL); - XChangeProperty(dpy, RootWindow(dpy, 0), XA_RESOURCE_MANAGER, XA_STRING, 8, - PropModeReplace, (unsigned char *) str.toLatin1().data(), str.length()); - XCloseDisplay(dpy); - - qDebug() << "setXresources:" << str; - - delete mouse_settings; + setXresources(scale); } /* 判断文件是否存在 */ @@ -119,21 +125,16 @@ void writeXresourcesFile(QString XresourcesFile, QGSettings *settings, double sc file.close(); QGSettings *Font = new QGSettings("org.ukui.font-rendering"); - QGSettings *mouse_settings = new QGSettings(MOUSE_SCHEMA); Font->set("dpi", 96.0); settings->set(SCALING_KEY, scaling); - mouse_settings->set(CURSOR_SIZE, scaling * 24.0); qDebug() << " writeXresourcesFile: content = " << content - << " scalings = " << settings->get(SCALING_KEY).toDouble() - << "cursor size = " << mouse_settings->get(CURSOR_SIZE).toInt(); + << " scalings = " << settings->get(SCALING_KEY).toDouble(); delete Font; - delete mouse_settings; } /* 判断是否为首次登陆 */ - bool isTheFirstLogin(QGSettings *settings) { QString homePath = getenv("HOME"); @@ -173,22 +174,23 @@ bool isTheFirstLogin(QGSettings *settings) if (zoom1) { mScaling = 1.0; } else if (!zoom1 && zoom2) { - mScaling = 1.5; + mScaling = 1.5; //考虑新版缩放,设置默认150%暂时停止设置; } else if (!zoom1 && !zoom2 && zoom3) { mScaling = 2.0; } writeXresourcesFile(XresourcesFile, settings, mScaling); + setXresources(mScaling); + return true; } - /* 配置新装系统、新建用户第一次登陆时,4K缩放功能*/ -void setHightResolutionScreenZoom() +void setHightResolutionScreenZoom(bool platForm) { QGSettings *settings; - double dpi; + double scale; int ScreenNum = QApplication::screens().length(); if (!QGSettings::isSchemaInstalled(XSETTINGS_SCHEMA) || !QGSettings::isSchemaInstalled("org.ukui.font-rendering") || !QGSettings::isSchemaInstalled(MOUSE_SCHEMA)) { @@ -198,28 +200,41 @@ void setHightResolutionScreenZoom() } settings = new QGSettings(XSETTINGS_SCHEMA); + scale = settings->get(SCALING_KEY).toDouble(); + + if (platForm) { + setXresources(scale); + goto end; + } + if (isTheFirstLogin(settings)) { qDebug() << "Set the default zoom value when logging in for the first time."; goto end; } /* 过滤单双屏下小分辨率大缩放值 */ + if (ScreenNum > 1) { + setXresources(scale); goto end; } screenScaleJudgement(settings); end: - dpi = 0.0; - dpi = settings->get(SCALING_KEY).toDouble() * 96.0; - setXresources(dpi); delete settings; } int main(int argc, char *argv[]) { QApplication a(argc, argv); - setHightResolutionScreenZoom(); + QString platForm = kdk_system_get_hostCloudPlatform(); + if (platForm == "none") { + qDebug() << "platForm=" << platForm << ", 系统环境为实体机"; + setHightResolutionScreenZoom(false); + } else { + qDebug() << "platForm=" << platForm << ", 系统环境为云环境"; + setHightResolutionScreenZoom(true); + } return 0; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 684f2ec..d22a516 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,8 @@ pkg_check_modules(QGS REQUIRED gsettings-qt) pkg_check_modules(GLIB REQUIRED glib-2.0) pkg_check_modules(MMIX REQUIRED libmatemixer) pkg_check_modules(kylin-nm-base REQUIRED kylin-nm-base) +pkg_check_modules(KDKINFO REQUIRED kysdk-sysinfo) +pkg_check_modules(IMLIB2 REQUIRED imlib2) find_library(PAM_LIBRARIES pam) @@ -29,6 +31,13 @@ include_directories( ${MMIX_INCLUDE_DIRS} ${kylin-nm-base_INCLUDE_DIRS} ${KF5Wayland_LIBRARIES} + ${KDKINFO_INCLUDE_DIRS} + ${IMLIB2_INCLUDE_DIRS} + ${OpenCV_INCLUDE_DIRS} + ) + +link_directories( + ${KDKINFO_LIBRARY_DIRS} ) set(EXTRA_LIBS @@ -41,6 +50,8 @@ set(EXTRA_LIBS ${GLIB_LIBRARIES} ${MMIX_LIBRARIES} ${KF5Wayland_LIBRARIES} + ${KDKINFO_LIBRARIES} + ${IMLIB2_LIBRARIES} -lrt -lpthread -lKF5WaylandServer @@ -101,7 +112,8 @@ qt5_wrap_cpp(dialog_SRC lockchecker.h servicemanager.h mytabwidget.h - plasma-shell-manager.h + modebutton.h + klabel.h PhysicalDeviceSet/brightnessdeviceset.h PhysicalDeviceSet/flightmodeset.h PhysicalDeviceSet/sounddeviceset.h @@ -110,6 +122,7 @@ qt5_wrap_cpp(dialog_SRC enginedevice.h batterywidget.h libinputswitchevent.h + machinemodel.h ) set(dialog_SRC @@ -153,7 +166,9 @@ set(dialog_SRC lockchecker.cpp servicemanager.cpp mytabwidget.cpp - plasma-shell-manager.cpp + modebutton.cpp + klabel.cpp + rootWindowBackground.cpp PhysicalDeviceSet/brightnessdeviceset.cpp PhysicalDeviceSet/flightmodeset.cpp PhysicalDeviceSet/sounddeviceset.cpp @@ -162,6 +177,7 @@ set(dialog_SRC enginedevice.cpp batterywidget.cpp libinputswitchevent.cpp + machinemodel.cpp ) add_executable(ukui-screensaver-dialog ${dialog_SRC}) add_definitions(-DAPP_API_MAJOR=0 -DAPP_API_MINOR=11 -DAPP_API_FUNC=0) @@ -180,6 +196,9 @@ target_link_libraries(ukui-screensaver-dialog Kylin-nm ukui-log4qt Screensaver + opencv_imgcodecs + opencv_imgproc + opencv_core ) link_libraries(libmatemixer.so glib-2.0.so) @@ -202,7 +221,7 @@ set(backend_SRC logind.cpp ) add_executable(ukui-screensaver-backend ${backend_SRC}) -target_link_libraries(ukui-screensaver-backend Qt5::Core Qt5::DBus ${QGS_LIBRARIES} ukui-log4qt) +target_link_libraries(ukui-screensaver-backend Qt5::Core Qt5::DBus ${QGS_LIBRARIES} ukui-log4qt Common) set(command_SRC ukui-screensaver-command.cpp @@ -216,6 +235,14 @@ set(checkpass_SRC add_executable(ukui-screensaver-checkpass ${checkpass_SRC}) target_link_libraries(ukui-screensaver-checkpass ${PAM_LIBRARIES}) +set(ukss_SRCS + ukss_interface.cpp + ) + +add_definitions(-DUKSSSO_LIBRARY) +add_library(ukss SHARED ${ukss_SRCS}) +target_link_libraries(ukss Qt5::Core Qt5::DBus ${QGS_LIBRARIES}) + install(TARGETS ukui-screensaver-dialog ukui-screensaver-backend @@ -223,6 +250,8 @@ install(TARGETS ukui-screensaver-checkpass DESTINATION bin) +install(TARGETS ukss DESTINATION ${QT_INSTALL_LIBS}) + #set(test-act_SRC # users.cpp # test-accounts.cpp diff --git a/src/assets.qrc b/src/assets.qrc index 870f62f..cb0a657 100644 --- a/src/assets.qrc +++ b/src/assets.qrc @@ -112,6 +112,7 @@ assets/ukui-loginopt-finger.svg assets/ukui-loginopt-face.svg assets/ukui-loginopt-password.svg + assets/ukui-loginopt-ukey.svg assets/selected.svg assets/keyboard.svg assets/ukui-loginopt-smile.svg @@ -124,4 +125,7 @@ assets/hibernate.svg assets/switchuser.svg + + assets/data/conf.ini + diff --git a/src/assets/authdialog.qss b/src/assets/authdialog.qss index fd14444..a45e1c3 100644 --- a/src/assets/authdialog.qss +++ b/src/assets/authdialog.qss @@ -34,14 +34,12 @@ QToolButton::checked { QLabel { color: white; - font-size: 16px; } QToolTip{ border-radius:4px; background-color:#FFFFFF; color:black; - font-size:16px } #userWidget{ @@ -57,7 +55,6 @@ QToolTip{ /* 用户名 */ #login_nameLabel{ - font-size: 24px; } /* 密码输入框 */ @@ -66,7 +63,6 @@ QLineEdit { border: 2px solid #FFFFFF; border-radius: 6px; color:black; - font-size: 14px; lineedit-password-character:9679; } @@ -112,13 +108,11 @@ QLineEdit::focus{ /* PAM message提示*/ #messageLabel { - font-size: 16px; color: white; } #messageButton{ text-align:center; - font-size: 16px; color: white; } @@ -129,7 +123,6 @@ QMenu{ color: white; border-radius: 4px; width:250px; - font-size: 16px; padding: 5px 5px 5px 5px; } @@ -141,7 +134,6 @@ QMenu::item width:225px; border-radius: 4px; height:36px; - font-size:16px; padding: 2px 10px 2px 10px; } diff --git a/src/assets/data/conf.ini b/src/assets/data/conf.ini new file mode 100644 index 0000000..41ae2bd --- /dev/null +++ b/src/assets/data/conf.ini @@ -0,0 +1,15 @@ +[MachineType] +PANDING LTDtablet = SLATE +#Phytium12345 = SLATE + + +#key 值机器的sys_vendor + product_family +#cat /sys/class/dmi/id/product_family +#cat /sys/class/dmi/id/product_name +#cat /sys/class/dmi/id/sys_vendor + +#value 有以下四类 +#[SLATE]平板 +#[LAPTOP]计算机(有永久附加键盘) +#[CONVERTIBLE]平板/计算机(键盘可以分离、翻转或旋转) +#[ALLINONE]台式机 diff --git a/src/assets/ukui-loginopt-ukey.svg b/src/assets/ukui-loginopt-ukey.svg new file mode 100644 index 0000000..0239a86 --- /dev/null +++ b/src/assets/ukui-loginopt-ukey.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/authdialog.cpp b/src/authdialog.cpp index fae337d..e179b46 100644 --- a/src/authdialog.cpp +++ b/src/authdialog.cpp @@ -30,20 +30,21 @@ #include "users.h" #include "iconedit.h" +#include "configuration.h" #include "biometricproxy.h" -#include "biometricauthwidget.h" -#include "biometricdeviceswidget.h" #include "pam-tally.h" #include "commonfunc.h" #include "loginoptionswidget.h" #include "servicemanager.h" #include "uniauthservice.h" #include "imageutil.h" +#include "klabel.h" AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : QWidget(parent), user(user), auth(new AuthPAM(this)), + configuration(Configuration::instance()), authMode(UNKNOWN), m_biometricProxy(nullptr), m_widgetLoginOpts(nullptr), @@ -63,6 +64,8 @@ AuthDialog::AuthDialog(const UserItem &user, QWidget *parent) : if(qssFile.open(QIODevice::ReadOnly)) { this->setStyleSheet(qssFile.readAll()); } + curFontSize = configuration->getFontSize(); + m_ptToPx = configuration->getPtToPx(); initUI(); pam_tally_init(); //这里写函数声明 @@ -120,7 +123,7 @@ void AuthDialog::initUI() m_userWidget->setObjectName(QStringLiteral("userWidget")); /* 头像 */ - const QString SheetStyle = QString("border-radius: %1px; border:0px solid white;").arg(77*scale); + const QString SheetStyle = QString("border-radius: %1px; border:0px solid white;").arg((int)(77*scale)); m_labelHeadImg = new QLabel(m_userWidget); m_labelHeadImg->setObjectName(QStringLiteral("faceLabel")); m_labelHeadImg->setFocusPolicy(Qt::NoFocus); @@ -128,10 +131,7 @@ void AuthDialog::initUI() m_labelHeadImg->setAlignment(Qt::AlignCenter); m_labelHeadImg->hide(); - QPixmap facePixmap(user.icon); - facePixmap = scaledPixmap(facePixmap); - facePixmap = facePixmap.scaled(154*scale,154*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - facePixmap = PixmapToRound(facePixmap, 77*scale); + QPixmap facePixmap = makeRoundLogo(user.icon, 154*scale, 154*scale, 77*scale); m_labelHeadImg->setAlignment(Qt::AlignCenter); m_labelHeadImg->setPixmap(facePixmap); @@ -142,13 +142,10 @@ void AuthDialog::initUI() m_labelFace->hide(); // 二维码窗口 - m_labelLoginTypeTip = new QLabel(m_userWidget); - //m_labelLoginTypeTip->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); + m_labelLoginTypeTip = new KLabel(m_userWidget); + m_labelLoginTypeTip->setFontSize(14); m_labelLoginTypeTip->setObjectName("loginTypeTipLabel"); m_labelLoginTypeTip->setAlignment(Qt::AlignCenter); - QFont font = m_labelLoginTypeTip->font(); - font.setPixelSize(14); - m_labelLoginTypeTip->setFont(font); m_labelQRCode = new QLabel(m_userWidget); m_labelQRCode->setObjectName("qrCodeLabel"); m_labelQRCode->setAlignment(Qt::AlignCenter); @@ -160,31 +157,21 @@ void AuthDialog::initUI() m_labelQRCodeTip = new QLabel(); m_labelQRCodeTip->setFixedSize(22,22); layoutQRCode->addWidget(m_labelQRCodeTip, 0, Qt::AlignHCenter); - m_labelQRCodeMsg = new QLabel(); - m_labelQRCodeMsg->setFixedHeight(24); - font = m_labelQRCodeMsg->font(); - font.setPixelSize(16); + m_labelQRCodeMsg = new KLabel(); + m_labelQRCodeMsg->setFixedHeight(30); + m_labelQRCodeMsg->setFontSize(14); m_labelQRCodeMsg->setStyleSheet("QLabel{background-color:rgba(255,255,255,0);color:rgb(255,0,0)}"); - m_labelQRCodeMsg->setFont(font); layoutQRCode->addWidget(m_labelQRCodeMsg, 0, Qt::AlignHCenter); /* 用户名 */ - m_nameLabel = new QLabel(m_userWidget); + m_nameLabel = new KLabel(m_userWidget); m_nameLabel->setObjectName(QStringLiteral("login_nameLabel")); m_nameLabel->setFocusPolicy(Qt::NoFocus); m_nameLabel->setAlignment(Qt::AlignCenter); - m_nameLabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); + m_nameLabel->setFontSize(24); //m_nameLabel->setText(user.realName.isEmpty() ? user.name : user.realName); QString text = user.realName.isEmpty() ? user.name : user.realName; - font = m_nameLabel->font(); - font.setPixelSize(24); - QString str = ElideText(font,500,text); - if(text != str) - m_nameLabel->setToolTip(text); - if(text == str) - m_nameLabel->setToolTip(""); - m_nameLabel->setText(str); - + m_nameLabel->setElideText(text, 380); /* 密码框所在窗口 */ m_passwdWidget = new QWidget(this); @@ -200,7 +187,7 @@ void AuthDialog::initUI() QPixmap iconLogin = QIcon::fromTheme("system-lock-screen-symbolic").pixmap(16,16); iconLogin = ImageUtil::drawSymbolicColoredPixmap(iconLogin, "white"); m_passwordEdit->setIcon(iconLogin); - m_passwordEdit->setFocusPolicy(Qt::StrongFocus); + //m_passwordEdit->setFocusPolicy(Qt::StrongFocus); m_passwordEdit->installEventFilter(this); m_passwordEdit->readOnly(true); /*免密登录时,会出现闪一下密码框的问题,因此初始化时隐藏,收到pam发来的prompt类型的消息后再显示*/ @@ -213,19 +200,106 @@ void AuthDialog::initUI() //m_passwdWidget->hide(); /* 密码认证信息显示列表 */ - m_messageLabel = new QLabel(m_passwdWidget); + m_messageLabel = new KLabel(m_passwdWidget); m_messageLabel->setObjectName(QStringLiteral("messageLabel")); m_messageLabel->setAlignment(Qt::AlignLeft); - font = m_messageLabel->font(); - font.setPixelSize(14); - m_messageLabel->setFont(font); - m_messageLabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); + m_messageLabel->setFontSize(14); + + /* ukey密码框所在窗口 */ + m_ukeyPasswdWidget = new QWidget(this); + m_ukeyPasswdWidget->setObjectName(QStringLiteral("passwordWidget")); + + /* 密码框 */ + m_ukeyPasswordEdit = new IconEdit(m_ukeyPasswdWidget); + connect(m_ukeyPasswordEdit,&IconEdit::clickedPassword, + this,&AuthDialog::onM_passwordEditClicked); + + m_ukeyPasswdWidget->setInputMethodHints(Qt::ImhNone); + m_ukeyPasswordEdit->setObjectName(QStringLiteral("passwordEdit")); + m_ukeyPasswordEdit->setIcon(QIcon::fromTheme("system-lock-screen-symbolic")); + //m_ukeyPasswordEdit->setFocusPolicy(Qt::StrongFocus); + m_ukeyPasswordEdit->installEventFilter(this); + m_ukeyPasswordEdit->setType(QLineEdit::Password); + m_ukeyPasswordEdit->setPrompt(tr("Enter the ukey password")); + m_ukeyPasswordEdit->setModeBtnVisible(false); + connect(m_ukeyPasswordEdit, SIGNAL(clicked(const QString&)), + this, SLOT(onRespondUkey(const QString&))); + + /* 密码认证信息显示列表 */ + m_ukeyMessageLabel = new KLabel(m_ukeyPasswdWidget); + m_ukeyMessageLabel->setObjectName(QStringLiteral("messageLabel")); + m_ukeyMessageLabel->setAlignment(Qt::AlignLeft); + m_ukeyMessageLabel->setFontSize(14); + m_ukeyMessageLabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); + + m_ukeyPasswdWidget->hide(); + + m_loadingWidget = new QWidget(m_ukeyPasswdWidget); + m_loadingText = new KLabel(m_loadingWidget); + m_loadingText->setFontSize(18); + m_loadingText->setText(tr("Insert the ukey into the USB port")); + m_loadingButton = new QPushButton(m_loadingWidget); + m_loadingButton->setAttribute(Qt::WA_TransparentForMouseEvents, true); + m_loadingButton->setFlat(true); + m_loadingButton->installEventFilter(this); + m_loadingButton->setStyleSheet("QPushButton{text-align:center;color: rgb(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;}"); + + m_loadingWidget->adjustSize(); + + QVBoxLayout *loadingLayout= new QVBoxLayout(m_loadingWidget); + loadingLayout->addWidget(m_loadingButton); + loadingLayout->addWidget(m_loadingText); + startLoadingUkey(); m_messageButton = new QPushButton(m_passwdWidget); m_messageButton->setObjectName(QStringLiteral("messageButton")); + QFont font; + font = m_messageButton->font(); + font.setPointSize((14 + curFontSize) *m_ptToPx); + m_messageButton->setFont(font); m_messageButton->hide(); } + +void AuthDialog::startLoadingUkey() +{ + //isLoadingUkey = true; + m_loadingWidget->show(); + m_ukeyPasswordEdit->hide(); + m_ukeyMessageLabel->hide(); + if(!m_loadingTimer) + { + m_loadingTimer = new QTimer(this); + m_loadingTimer->setInterval(150); + connect(m_loadingTimer, &QTimer::timeout, this, &AuthDialog::updateLoadingPixmap); + } + + QPixmap icon = QIcon::fromTheme("ukui-loading-0-symbolic").pixmap(27,27); + m_loadingPixmap = ImageUtil::drawSymbolicColoredPixmap(icon, "white"); + m_loadingButton->setIcon(m_loadingPixmap); + m_loadingButton->setIconSize(QSize(27, 27)); + m_loadingTimer->start(); +} + +void AuthDialog::stopLoadingUkey() +{ + isLoadingUkey = false; + m_loadingWidget->hide(); + m_ukeyPasswordEdit->show(); + m_ukeyMessageLabel->show(); + if(m_loadingTimer){ + m_loadingTimer->stop(); + } +} + +void AuthDialog::updateLoadingPixmap() +{ + QMatrix matrix; + matrix.rotate(90.0); + m_loadingPixmap = m_loadingPixmap.transformed(matrix, Qt::FastTransformation); + m_loadingButton->setIcon(QIcon(m_loadingPixmap)); +} + void AuthDialog::unlock_countdown() { int failed_count = 0; @@ -281,7 +355,9 @@ void AuthDialog::unlock_countdown() { if(m_passwordEdit){ m_passwordEdit->readOnly(false); - m_passwordEdit->setFocus(); + if (m_passwordEdit->isVisible()) { + m_passwordEdit->setFocus(); + } } if (isLockingFlg) { @@ -346,7 +422,9 @@ void AuthDialog::root_unlock_countdown() { if(m_passwordEdit){ m_passwordEdit->readOnly(false); - m_passwordEdit->setFocus(); + if (m_passwordEdit->isVisible()) { + m_passwordEdit->setFocus(); + } } if (isLockingFlg) { @@ -366,32 +444,30 @@ void AuthDialog::resizeEvent(QResizeEvent *) void AuthDialog::setChildrenGeometry() { -// if(scale < 0.5) -// setFixedWidth(500); + if(scale < 0.5) + setFixedWidth(500); // 用户信息显示位置 m_userWidget->setGeometry(0, 0, width(), 376*scale); - m_labelLoginTypeTip->setGeometry(0,0,m_userWidget->width(), 24); + m_labelLoginTypeTip->setGeometry(0,0,m_userWidget->width(), 30); m_labelLoginTypeTip->setAlignment(Qt::AlignCenter); - m_labelHeadImg->setStyleSheet(QString("border-radius: %1px; border:0px solid white;").arg(77*scale)); + m_labelHeadImg->setStyleSheet(QString("border-radius: %1px; border:0px solid white;").arg((int)(77*scale))); m_labelHeadImg->setGeometry((width() - 154*scale) / 2 , m_labelLoginTypeTip->geometry().bottom()+24*scale, 154*scale, 154*scale); - QPixmap facePixmap(user.icon); - facePixmap = scaledPixmap(facePixmap); - facePixmap = facePixmap.scaled(154*scale,154*scale, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - facePixmap = PixmapToRound(facePixmap, 77*scale); + + QPixmap facePixmap = makeRoundLogo(user.icon, 154*scale, 154*scale, 77*scale); m_labelHeadImg->setPixmap(facePixmap); - m_labelQRCode->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,100%);").arg(6*scale)); + m_labelQRCode->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,100%);").arg((int)(6*scale))); m_labelQRCode->setGeometry((width() - 154*scale) / 2 , m_labelLoginTypeTip->geometry().bottom()+24*scale, 154*scale, 154*scale); setQRCode(m_imgQRCode); - m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,10%);").arg(77*scale)); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,10%);").arg((int)(77*scale))); m_labelFace->setGeometry((width() - 154*scale) / 2 , m_labelLoginTypeTip->geometry().bottom()+24*scale, 154*scale, 154*scale); QImage faceImg; setFaceImg(faceImg); m_nameLabel->setGeometry(0, m_labelHeadImg->geometry().bottom() + 16*scale, - width(), 34); + width(), 40); m_passwdWidget->setGeometry(0, m_nameLabel->geometry().bottom() + 24*scale, width(), 100); m_passwordEdit->setGeometry((m_passwdWidget->width() - 240)/2, 0, 240, 40); @@ -399,6 +475,16 @@ void AuthDialog::setChildrenGeometry() m_passwordEdit->geometry().bottom() + 4, width()-(m_passwdWidget->width() - 240)/2, 36); m_messageLabel->setMinimumHeight(36); + + m_ukeyPasswdWidget->setGeometry(0, m_nameLabel->geometry().bottom() + 24*scale, width(), 100); + m_ukeyPasswordEdit->setGeometry((m_ukeyPasswdWidget->width() - 240)/2, 0, 240, 40); + m_ukeyMessageLabel->setGeometry((m_ukeyPasswdWidget->width() - 240)/2, + m_ukeyPasswordEdit->geometry().bottom() + 4, + width()-(m_ukeyPasswdWidget->width() - 240)/2, 36); + m_loadingWidget->adjustSize(); + m_loadingWidget->setGeometry((m_ukeyPasswdWidget->width() - m_loadingWidget->width())/2, 0, m_loadingWidget->width(), m_loadingWidget->height()); + m_messageLabel->setMinimumHeight(36); + m_messageButton->setGeometry((m_passwdWidget->width() - 200)/2, 0, 200, 40); // m_messageButton->setStyleSheet("QPushButton:!checked:!pressed:!hover{background-color: rgba(255,255,255,40)}" // "QPushButton:!checked:!pressed:hover{background-color: rgba(255,255,255,100)}" @@ -410,12 +496,15 @@ void AuthDialog::setChildrenGeometry() void AuthDialog::switchLoginOptType(unsigned uLoginOptType) { + qDebug()<<"switchLoginOptType"<show(); m_labelQRCode->hide(); m_labelFace->hide(); + m_passwdWidget->show(); + m_ukeyPasswdWidget->hide(); } break; case LOGINOPT_TYPE_FACE: @@ -423,6 +512,8 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType) m_labelHeadImg->hide(); m_labelQRCode->hide(); m_labelFace->show(); + m_passwdWidget->show(); + m_ukeyPasswdWidget->hide(); } break; case LOGINOPT_TYPE_FINGERPRINT: @@ -433,6 +524,8 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType) m_labelHeadImg->show(); m_labelQRCode->hide(); m_labelFace->hide(); + m_passwdWidget->show(); + m_ukeyPasswdWidget->hide(); } break; case LOGINOPT_TYPE_QRCODE: @@ -441,6 +534,20 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType) setQRCodeMsg(""); m_labelQRCode->show(); m_labelFace->hide(); + m_passwdWidget->show(); + m_ukeyPasswdWidget->hide(); + } + break; + case LOGINOPT_TYPE_GENERAL_UKEY: + { + m_labelHeadImg->show(); + m_labelQRCode->hide(); + m_labelFace->hide(); + m_passwdWidget->hide(); + m_ukeyPasswdWidget->show(); +// setFocusProxy(m_ukeyPasswordEdit); +// m_ukeyPasswordEdit->setFocusPolicy(Qt::StrongFocus); +// m_ukeyPasswordEdit->setFocus(); } break; default: @@ -484,6 +591,11 @@ void AuthDialog::switchLoginOptType(unsigned uLoginOptType) setLoginTypeTip(tr("Use the bound wechat scanning code or enter the password to unlock")); } break; + case LOGINOPT_TYPE_GENERAL_UKEY: + { + setLoginTypeTip(""); + } + break; default: return; } @@ -559,7 +671,13 @@ void AuthDialog::pamBioSuccess() switchLoginOptType(LOGINOPT_TYPE_PASSWORD); return ; } - m_widgetLoginOpts->startAuth(m_deviceInfo, user.uid); + + if(m_deviceInfo && m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + //ukey时不调用ukey认证 + }else{ + m_widgetLoginOpts->startAuth(m_deviceInfo, user.uid); + } + if (m_deviceInfo) { switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); } else { @@ -571,6 +689,13 @@ void AuthDialog::startBioAuth(unsigned uTimeout) { if (m_widgetLoginOpts) m_widgetLoginOpts->stopAuth(); + + if(m_deviceInfo && m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + //ukey时不调用ukey认证 + switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); + return; + } + if(!m_bioTimer){ m_bioTimer = new QTimer(this); connect(m_bioTimer, SIGNAL(timeout()), this, SLOT(pamBioSuccess())); @@ -588,7 +713,10 @@ void AuthDialog::setX11Focus() void AuthDialog::setFocusin(int target) { - if(m_passwordEdit) { + if(m_passwordEdit && m_passwordEdit->isVisible()) { + if (m_ukeyPasswordEdit) { + m_ukeyPasswordEdit->setFocusin(2); + } switch (target) { case REMOVE: //焦点清除 if(m_widgetLoginOpts) @@ -637,6 +765,58 @@ void AuthDialog::setFocusin(int target) m_widgetLoginOpts->tabOptionSelected(2); break; } + } else { + if (m_passwordEdit) { + m_passwordEdit->setFocusin(2); + } + switch (target) { + case REMOVE: //焦点清除 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(2); + m_ukeyPasswordEdit->setFocusin(2); + if(is_showMessageBtn) { + m_messageButton->clearFocus(); + m_messageButton->setStyleSheet("QPushButton:!checked:!pressed:!hover{background-color: rgba(255,255,255,40)}" + "QPushButton:!checked:!pressed:hover{background-color: rgba(255,255,255,100)}" + "QPushButton:pressed{background-color: rgba(255,255,255,40)}"); + } + m_nameLabel->setFocus(); + break; + case IN_LIGIN: //焦点在登录按钮 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(2); + m_ukeyPasswordEdit->setFocusin(1); + break; + case BIO_RIGHT: //登录选项焦点右移 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(0); + m_ukeyPasswordEdit->setFocusin(2); + m_nameLabel->setFocus(); + break; + case BIO_LEFT: //登录选项焦点左移 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(1); + m_ukeyPasswordEdit->setFocusin(target); + m_nameLabel->setFocus(); + break; + case IN_LINEEDIT: //焦点在密码输入框 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(2); + m_ukeyPasswordEdit->setFocusin(0); + break; + case ON_MESSAGEBTN: //免密登录按钮 + if(m_widgetLoginOpts) + m_widgetLoginOpts->tabOptionSelected(2); + m_ukeyPasswordEdit->setFocusin(2); + m_messageButton->setFocus(); + m_messageButton->setStyleSheet("QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: 2px solid #2C73C8;}"); + break; + default: + if(m_ukeyPasswordEdit) + m_ukeyPasswordEdit->setFocusin(target); + m_widgetLoginOpts->tabOptionSelected(2); + break; + } } } @@ -647,13 +827,17 @@ void AuthDialog::setClick() void AuthDialog::checkPassword() { - m_passwordEdit->clicked_cb(); + if (m_passwordEdit && m_passwordEdit->isVisible()) { + m_passwordEdit->clicked_cb(); + } else if (m_ukeyPasswordEdit && m_ukeyPasswordEdit->isVisible()) { + m_ukeyPasswordEdit->clicked_cb(); + } setFocusin(REMOVE); } void AuthDialog::onShowPrompt(const QString &prompt, Auth::PromptType type) { - qDebug() << "-------prompt: " << prompt; + qDebug() << "-------prompt: " << prompt<show(); } - m_passwordEdit->setFocus(); + if (m_passwordEdit->isVisible()) + m_passwordEdit->setFocus(); prompted = true; unacknowledged_messages = false; @@ -691,7 +876,8 @@ void AuthDialog::onShowPrompt(const QString &prompt, Auth::PromptType type) m_passwordEdit->clear(); m_passwordEdit->setPrompt(text); m_passwordEdit->show(); - m_passwordEdit->setFocus(); + if (m_passwordEdit->isVisible()) + m_passwordEdit->setFocus(); if(!m_timer){ m_timer = new QTimer(this); m_timer->setInterval(200); @@ -752,7 +938,12 @@ void AuthDialog::show_authenticated(bool successful) { isretry = false; m_messageButton->setText(tr("Login")); + QString strMsgTip = m_messageLabel->text(); switchLoginOptType(LOGINOPT_TYPE_PASSWORD); + if (!strMsgTip.isEmpty()) { + m_messageLabel->setText(strMsgTip); + m_messageLabel->move(m_messageButton->x(), m_messageLabel->y()); + } // QTimer::singleShot(100, this, [=](){ // qDebug()<<"Delay to focus msgBtn!!"; // m_messageButton->show(); @@ -786,6 +977,14 @@ void AuthDialog::onMessageButtonClicked() } } +void AuthDialog::onRespondUkey(const QString &text) +{ + if (m_widgetLoginOpts){ + m_widgetLoginOpts->SetExtraInfo(text,"pincode"); + m_widgetLoginOpts->startAuth(m_deviceInfo, user.uid); + } +} + bool AuthDialog::getLineeditStatus() { return is_showMessageBtn; @@ -840,6 +1039,7 @@ void AuthDialog::clearMessage() void AuthDialog::performBiometricAuth() { + qDebug()<<"performBiometricAuth"; if(!m_biometricProxy) { m_biometricProxy = new BiometricProxy(this); @@ -874,6 +1074,12 @@ void AuthDialog::performBiometricAuth() { qWarning() << "No available devices"; skipBiometricAuth(); + if (m_deviceInfo) { + if (!m_widgetLoginOpts || !m_widgetLoginOpts->findDeviceById(m_deviceInfo->id) + || m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) { + m_deviceInfo = DeviceInfoPtr(); + } + } return; } @@ -907,8 +1113,21 @@ void AuthDialog::performBiometricAuth() return; } } + + if(m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + switchLoginOptType(LOGINOPT_TYPE_PASSWORD); + m_widgetLoginOpts->setSelectedPassword(); + skipBiometricAuth(); + return ; + } + switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); - startBioAuth(); + if(!m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) + startBioAuth(); + else { + QImage imgFailed; + setFaceImg(imgFailed, 1); + } skipBiometricAuth(); } @@ -942,6 +1161,12 @@ void AuthDialog::initBiometricWidget() m_widgetLoginOpts->hide(); else m_widgetLoginOpts->show(); + + if(m_widgetLoginOpts->getHasUkeyOptions() && m_widgetLoginOpts->getLoginOptCount() < 1){ + m_widgetLoginOpts->show(); + m_widgetLoginOpts->setSelectedPassword(); + } + m_widgetLoginOpts->setEnabled(true); setBiometricWidgetGeometry(); @@ -953,7 +1178,7 @@ void AuthDialog::setBiometricWidgetGeometry() if(m_widgetLoginOpts) { m_widgetLoginOpts->setGeometry(0, m_passwdWidget->geometry().bottom(), - width(), 84*scale); + width(), 92*scale); qDebug()<<"LoginOptGeometry:"<geometry()<<","<geometry() <<","<isHidden(); } @@ -961,33 +1186,63 @@ void AuthDialog::setBiometricWidgetGeometry() int AuthDialog::getBioNum() { - return m_widgetLoginOpts->getLoginOptCount(); + return m_widgetLoginOpts->getVisibleLoginOptCount(); } void AuthDialog::onDeviceChanged(unsigned uCurLoginOptType, const DeviceInfoPtr &deviceInfo, bool keyNavigation) { - if (!deviceInfo) - return; if(!keyNavigation) Q_EMIT loginOptionClicked(); - qDebug() << "device changed: " << *deviceInfo; - if(m_failedTimes.contains(deviceInfo->id) && + isLoadingUkey = false; + if(uCurLoginOptType == LOGINOPT_TYPE_PASSWORD){ + switchLoginOptType(uCurLoginOptType); + if(m_widgetLoginOpts){ + m_widgetLoginOpts->stopAuth(); + } + m_deviceInfo = nullptr; + authMode = PASSWORD; + startAuth(); + return; + } + if (uCurLoginOptType != LOGINOPT_TYPE_GENERAL_UKEY && !deviceInfo) + return; + if(deviceInfo) + qDebug() << "device changed: " << *deviceInfo; + if(deviceInfo && m_failedTimes.contains(deviceInfo->id) && m_failedTimes[deviceInfo->id] >= maxFailedTimes){ qDebug() << "Failed MAX:"<id; return ; } - if (deviceInfo == m_deviceInfo) { + + if (uCurLoginOptType == LOGINOPT_TYPE_GENERAL_UKEY && !deviceInfo){ + isLoadingUkey = true; + startLoadingUkey(); + }else if(uCurLoginOptType == LOGINOPT_TYPE_GENERAL_UKEY && deviceInfo){ + stopLoadingUkey(); + } + + if (uCurLoginOptType != LOGINOPT_TYPE_GENERAL_UKEY && deviceInfo == m_deviceInfo) { return ; } + + if(m_bioTimer && m_bioTimer->isActive()) + m_bioTimer->stop(); + m_deviceInfo = deviceInfo; switchLoginOptType(uCurLoginOptType); - if(!isBioPassed) + if(!isBioPassed && deviceInfo) startBioAuth(); } void AuthDialog::onBiometricAuthComplete(bool result, int nStatus) { if(!result) { + + if(m_deviceInfo && m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY && m_ukeyPasswdWidget->isVisible()){ + m_ukeyPasswordEdit->stopWaiting(); + m_ukeyPasswordEdit->clearText(); + } + if (nStatus == 5 && m_deviceInfo) { if(w_timer && w_timer->isActive()) w_timer->stop(); @@ -1011,16 +1266,31 @@ void AuthDialog::onBiometricAuthComplete(bool result, int nStatus) setLoginTypeTip(tr("Failed to verify %1, please enter password to unlock").arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType))); QImage nullImage; setQRCode(nullImage); + }else if(m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + setUkeyTypeTip(tr("Unable to verify %1, please enter password to unlock").arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType))); } else { setLoginTypeTip(tr("Unable to verify %1, please enter password to unlock").arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType))); } if (m_widgetLoginOpts) m_widgetLoginOpts->setDeviceDisable(m_deviceInfo->id, true); + + if(m_ukeyPasswdWidget && m_ukeyPasswdWidget->isVisible()){ + m_ukeyPasswordEdit->readOnly(true); + } return ; } - setLoginTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities") - .arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType)) - .arg(maxFailedTimes-m_failedTimes[m_deviceInfo->id])); + + qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + if(m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + setUkeyTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities") + .arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType)) + .arg(maxFailedTimes-m_failedTimes[m_deviceInfo->id])); + }else { + setLoginTypeTip(tr("Failed to verify %1, you still have %2 verification opportunities") + .arg(DeviceType::getDeviceType_tr(m_deviceInfo->deviceType)) + .arg(maxFailedTimes-m_failedTimes[m_deviceInfo->id])); + } + qDebug()<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; } } @@ -1101,7 +1371,7 @@ void AuthDialog::setQRCodeMsg(QString strMsg) { w_timer->stop(); } - m_labelQRCodeMsg->setText(strMsg); + m_labelQRCodeMsg->setElideText(strMsg, m_labelQRCode->width() - 20* scale, 14); m_labelQRCodeMsg->show(); m_labelQRCodeTip->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(QSize(22,22))); m_labelQRCodeTip->show(); @@ -1122,7 +1392,7 @@ void AuthDialog::setFaceImg(QImage& imgFace, int nStatus) break; case 2: faceImage = m_widgetLoginOpts->loadSvg(":/image/assets/ukui-loginopt-smile.svg", "gray", 48); - m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,20%);").arg(77*scale)); + m_labelFace->setStyleSheet(QString("border-radius: %1px; border:0px solid white;background-color: rgba(255,255,255,10%);").arg((int)(77*scale))); break; default: faceImage = QPixmap(":/image/assets/ukui-loginopt-smile.svg"); @@ -1146,6 +1416,19 @@ void AuthDialog::updatePixmap() } } +void AuthDialog::setUkeyTypeTip(QString text) +{ + QString textTip = text; + if (!textTip.isEmpty()) { +// QFontMetrics font(m_ukeyMessageLabel->font()); +// QString textTip = font.elidedText(textTip, Qt::ElideRight, m_messageLabel->width()-8); + m_ukeyMessageLabel->setText(textTip); + m_ukeyMessageLabel->setToolTip(text); + m_ukeyMessageLabel->show(); + } else { + m_ukeyMessageLabel->hide(); + } +} void AuthDialog::setLoginTypeTip(QString strLoginTypeTip) { @@ -1190,12 +1473,20 @@ void AuthDialog::onLoginOptsCount(unsigned uCount, bool is_bioBtn) if(m_widgetLoginOpts->getLoginOptCount() < 1) { qWarning() << "No available devices"; + if (m_deviceInfo) { + m_deviceInfo = DeviceInfoPtr(); + } return; } //获取默认设备 if (m_widgetLoginOpts) { - m_deviceName = m_widgetLoginOpts->getDefaultDevice(user.name); + qDebug()<<"isLoadingUkey:"<getDefaultDevice(user.name,UniT_General_Ukey); + } else { + m_deviceName = m_widgetLoginOpts->getDefaultDevice(user.name); + } } qDebug() << m_deviceName; if (m_deviceInfo) { @@ -1219,6 +1510,16 @@ void AuthDialog::onLoginOptsCount(unsigned uCount, bool is_bioBtn) return; } } + + if (m_deviceInfo->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + stopLoadingUkey(); + } + + if(m_deviceInfo){ + m_widgetLoginOpts->setCurrentDevice(m_deviceInfo); + m_widgetLoginOpts->updateUIStatus(); + } + switchLoginOptType(m_widgetLoginOpts->convertDeviceType(m_deviceInfo->deviceType)); startBioAuth(); } @@ -1300,6 +1601,12 @@ void AuthDialog::onBiometricDbusChanged(bool bActive) if(m_widgetLoginOpts->getLoginOptCount() < 1) { qWarning() << "No available devices"; + if (m_deviceInfo) { + if (!m_widgetLoginOpts || !m_widgetLoginOpts->findDeviceById(m_deviceInfo->id) + || m_widgetLoginOpts->isDeviceDisable(m_deviceInfo->id)) { + m_deviceInfo = DeviceInfoPtr(); + } + } return; } @@ -1331,3 +1638,38 @@ void AuthDialog::onBiometricDbusChanged(bool bActive) }); } } + +QPixmap AuthDialog::makeRoundLogo(QString logo, int wsize, int hsize, int radius) +{ + QPixmap rectPixmap; + QPixmap iconcop = QPixmap(logo); + qreal dpi = m_labelHeadImg->devicePixelRatioF(); + if (dpi > 1.0) { + wsize = wsize * dpi; + hsize = hsize * dpi; + } + if (iconcop.width() > iconcop.height()) { + QPixmap iconPixmap = iconcop.copy((iconcop.width() - iconcop.height())/2, 0, iconcop.height(), iconcop.height()); + // 根据label高度等比例缩放图片 + rectPixmap = iconPixmap.scaledToHeight(hsize, Qt::SmoothTransformation); + } else { + QPixmap iconPixmap = iconcop.copy(0, (iconcop.height() - iconcop.width())/2, iconcop.width(), iconcop.width()); + // 根据label宽度等比例缩放图片 + rectPixmap = iconPixmap.scaledToWidth(wsize, Qt::SmoothTransformation); + } + + if (rectPixmap.isNull()) { + return QPixmap(); + } + QPixmap pixmapa(rectPixmap); + QPixmap pixmap(radius * 2 * dpi, radius * 2 * dpi); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + QPainterPath path; + path.addEllipse(0, 0, radius * 2 * dpi, radius * 2 * dpi); + painter.setClipPath(path); + painter.drawPixmap(0, 0, radius * 2 * dpi, radius * 2 * dpi, pixmapa); + pixmap.setDevicePixelRatio(dpi); + return pixmap; +} diff --git a/src/authdialog.h b/src/authdialog.h index 6225de0..b3602e3 100644 --- a/src/authdialog.h +++ b/src/authdialog.h @@ -30,21 +30,21 @@ #include "users.h" #include "biometricdeviceinfo.h" #include "pam-tally.h" +#include "uniauthservice.h" namespace Ui { class AuthDialog; } class QLabel; +class KLabel; class QPushButton; +class Configuration; class IconEdit; class Auth; class BiometricProxy; -class BiometricAuthWidget; -class BiometricDevicesWidget; class PamTally; class LoginOptionsWidget; -class UniAuthService; enum FOCUS { REMOVE = 0, @@ -84,13 +84,19 @@ private: void startBioAuth(unsigned uTimeout = 1000); void show_authenticated (bool successful = true); void setLoginTypeTip(QString strLoginTypeTip); + void setUkeyTypeTip(QString text); void updatePixmap(); + void startLoadingUkey(); + void stopLoadingUkey(); + void updateLoadingPixmap(); + QPixmap makeRoundLogo(QString logo, int wsize, int hsize, int radius); private Q_SLOTS: void onShowMessage(const QString &message, Auth::MessageType type); void onShowPrompt(const QString &prompt, Auth::PromptType type); void onAuthComplete(); void onRespond(const QString &text); + void onRespondUkey(const QString &text); // void onBioAuthStart(); // void onBioAuthStop(); // void setBioMovieImage(); @@ -134,12 +140,12 @@ private: enum AuthMode { PASSWORD, BIOMETRIC, UNKNOWN }; AuthMode authMode; + Configuration *configuration; // biometric auth QString m_deviceName; DeviceInfoPtr m_deviceInfo = nullptr; BiometricProxy *m_biometricProxy; - BiometricAuthWidget *m_biometricAuthWidget; QWidget *m_buttonsWidget; QPushButton *m_biometricButton; QPushButton *m_passwordButton; @@ -152,19 +158,29 @@ private: // QPushButton *m_backButton; //返回用户列表 QWidget *m_userWidget; //放置用户信息Label QLabel *m_labelHeadImg = nullptr; //头像 - QLabel *m_nameLabel; //用户名 + KLabel *m_nameLabel; //用户名 // QLabel *m_isLoginLabel; //提示是否已登录 QWidget *m_passwdWidget; //放置密码输入框和信息列表 IconEdit *m_passwordEdit; //密码输入框 - QLabel *m_messageLabel; //PAM消息显示 + KLabel *m_messageLabel; //PAM消息显示 QPushButton *m_messageButton; bool is_showMessageBtn = false; + QWidget *m_ukeyPasswdWidget = nullptr; //放置密码输入框和信息列表 + IconEdit *m_ukeyPasswordEdit = nullptr; //密码输入框 + KLabel *m_ukeyMessageLabel = nullptr; //PAM消息显示 + + QWidget *m_loadingWidget = nullptr; + QPushButton *m_loadingButton = nullptr; + KLabel *m_loadingText = nullptr; + QTimer *m_loadingTimer = nullptr; + QPixmap m_loadingPixmap; + QLabel *m_labelFace = nullptr; - QLabel *m_labelLoginTypeTip = nullptr; // 登录类型提示 + KLabel *m_labelLoginTypeTip = nullptr; // 登录类型提示 QLabel *m_labelQRCode = nullptr; // 二维码图标 - QLabel *m_labelQRCodeMsg = nullptr; // 二维码状态消息提示 + KLabel *m_labelQRCodeMsg = nullptr; // 二维码状态消息提示 QLabel *m_labelQRCodeTip = nullptr; bool isBioPassed; // 生物认证是否成功 @@ -193,6 +209,9 @@ private: QPixmap m_waitingPixmap; QTimer *w_timer; UniAuthService *m_uniauthService = nullptr; + double curFontSize = 0; + double m_ptToPx = 1.0; + bool isLoadingUkey = false; }; #endif // AUTHDIALOG_H diff --git a/src/configuration.cpp b/src/configuration.cpp index 264cdd9..0e9198c 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -26,11 +26,17 @@ #include #include #include +#include +#include +#include +#include "glibinterface.h" #include "commonfunc.h" #define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver" +#define GSETTINGS_SCHEMA_STYLE "org.ukui.style" #define KEY_MODE "mode" #define KEY_THEMES "themes" +#define KEY_FONT_SIZE "systemFontSize" #define KEY_IDLE_ACTIVATION_ENABLED "idle-activation-enabled" #define KEY_LOCK_ENABLED "lock-enabled" #define KEY_IMAGE_TRANSITION_EFFECT "image-transition-effect" @@ -59,7 +65,10 @@ Configuration::Configuration(QObject *parent) : QObject(parent) imageSwitchInterval = gsettings->get(KEY_IMAGE_SWITCH_INTERVAL).toInt(); imageTSEffect = gsettings->get(KEY_IMAGE_TRANSITION_EFFECT).toInt(); background = gsettings->get(KEY_BACKGROUND).toString(); - m_nLockTimeout = gsettings->get(KEY_LOCK_TIMEOUT).toInt(); + QStringList keysScreenSaver = gsettings->keys(); + if (keysScreenSaver.contains(KEY_LOCK_TIMEOUT)) { + m_nLockTimeout = gsettings->get(KEY_LOCK_TIMEOUT).toInt(); + } qDebug() << mode << themes; qDebug() << imageSwitchInterval << imageTSEffect; @@ -95,6 +104,13 @@ Configuration::Configuration(QObject *parent) : QObject(parent) if(themes.count() == 1 && themes[0] == "kyccss-personal-slideshow") mode ="image"; + + fsGsettings = new QGSettings(GSETTINGS_SCHEMA_STYLE); + + double defaultFontSize = getDefaultFontSize(); + + qDebug()<<"defaultFontSize = "<get(KEY_FONT_SIZE).toDouble() - defaultFontSize; } Configuration* Configuration::instance(QObject *parent) @@ -206,7 +222,20 @@ QString Configuration::getBackground() if(ispicture(background)) return background; - return "/usr/share/backgrounds/1-openkylin.jpg"; + char *systemName = kdk_system_get_systemName(); + if (systemName) { + if (QString(systemName) == "openKylin") { + free(systemName); + return "/usr/share/backgrounds/1-openkylin.jpg"; + } + free(systemName); + } + return "/usr/share/backgrounds/1-warty-final-ubuntukylin.jpg"; +} + +QString Configuration::getDefaultBackgroundName() +{ + return "/usr/share/backgrounds/1-warty-final-ubuntukylin.jpg"; } bool Configuration::lockWhenXScreensaverActivated() @@ -228,3 +257,15 @@ int Configuration::locktimeout() { return m_nLockTimeout; } + +double Configuration::getFontSize() +{ + return curFontSize; +} + +double Configuration::getPtToPx() +{ + if (QApplication::primaryScreen()->logicalDotsPerInch() > 0) + m_pxToPt = 72/(QApplication::primaryScreen()->logicalDotsPerInch()); + return m_pxToPt; +} diff --git a/src/configuration.h b/src/configuration.h index a74fada..8bd81e8 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -32,17 +32,20 @@ class QGSettings; class Configuration : public QObject { Q_OBJECT -public: +private: explicit Configuration(QObject *parent = nullptr); public: ScreenSaver *getScreensaver(); static Configuration *instance(QObject *parent = nullptr); QString getBackground(); + QString getDefaultBackgroundName(); bool lockWhenXScreensaverActivated(); int idlelock(); int idledelay(); int locktimeout(); + double getFontSize(); + double getPtToPx(); public Q_SLOTS: void onConfigurationChanged(QString key); @@ -53,7 +56,10 @@ private: private: QGSettings *gsettings; QGSettings *bgGsettings; + QGSettings *fsGsettings; QString mode; + double curFontSize; + double m_pxToPt = 1.0; QList themes; QString background; bool idleActivationEnabled; diff --git a/src/fullbackgroundwidget.cpp b/src/fullbackgroundwidget.cpp index 4486055..adbcf01 100644 --- a/src/fullbackgroundwidget.cpp +++ b/src/fullbackgroundwidget.cpp @@ -302,6 +302,12 @@ void FullBackgroundWidget::switchToLinux() void FullBackgroundWidget::laterActivate() { + if (QX11Info::isPlatformX11()) { + /*在不调用XSetInputFocus接口的情况下,在窗口失去焦点后,activateWindow概率性无法 + * 激活窗口,导致锁屏输入不了密码。 + * 复现方法:锁屏,然后切换到tty,启动终端,文管等窗口抢占锁屏窗口焦点,数次以后必现*/ + XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); + } activateWindow(); raise(); raiseOtherWnd(); @@ -330,14 +336,21 @@ void FullBackgroundWidget::setLockState() return ; lockState = true; - - QDBusInterface *interface = new QDBusInterface(SS_DBUS_SERVICE, + QString displayNum = QString(qgetenv("DISPLAY")).replace(":", "").replace(".", "_"); + QString sessionDbus = QString("%1%2").arg(QString(SS_DBUS_SERVICE)).arg(displayNum); + QDBusInterface *interface = new QDBusInterface(sessionDbus, SS_DBUS_PATH, SS_DBUS_INTERFACE); + if (!interface->isValid()) { + delete interface; + interface = new QDBusInterface(SS_DBUS_SERVICE, + SS_DBUS_PATH, + SS_DBUS_INTERFACE); + } QDBusMessage msg = interface->call("SetLockState"); if(msg.type() == QDBusMessage::ErrorMessage) qDebug() << msg.errorMessage(); - + HideMultiview(); } bool FullBackgroundWidget::eventFilter(QObject *obj, QEvent *event) @@ -489,12 +502,7 @@ bool FullBackgroundWidget::nativeEventFilter(const QByteArray &eventType, void * XClassHint ch; ch.res_name = NULL; ch.res_class = NULL; - Display* display = XOpenDisplay(0); - if (!display) { - return false; - } - XGetClassHint (display, xc->window, &ch); - XCloseDisplay(display); + XGetClassHint (QX11Info::display(), xc->window, &ch); if(QString(ch.res_name) == "ukui-screensaver-dialog") { if (ch.res_name) XFree(ch.res_name); @@ -523,12 +531,7 @@ bool FullBackgroundWidget::nativeEventFilter(const QByteArray &eventType, void * XClassHint ch; ch.res_name = NULL; ch.res_class = NULL; - Display* display = XOpenDisplay(0); - if (!display) { - return false; - } - XGetClassHint (display, xm->window, &ch); - XCloseDisplay(display); + XGetClassHint (QX11Info::display(), xm->window, &ch); if(QString(ch.res_name) == "ukui-screensaver-dialog") { if (ch.res_name) XFree(ch.res_name); @@ -579,12 +582,14 @@ bool FullBackgroundWidget::nativeEventFilter(const QByteArray &eventType, void * int x = xc->root_x; int y = xc->root_y; onGlobalButtonPressed(x, y); + qDebug()<<"---------------------XCB_BUTTON_PRESS:"<(event); int x = xc->root_x; int y = xc->root_y; onGlobalButtonDrag(x, y); + qDebug()<<"---------------------XCB_MOTION_NOTIFY:"<primaryScreen()){ - lockWidget->setGeometry(screen->geometry()); - chkInOneScreen = true; - break; - } -#else - if(screen->geometry().contains(pos)) - { - if(lockWidget->geometry() == screen->geometry()) - return ; - /*避免切换时闪烁*/ - qDebug()<geometry()<geometry(); + qInfo()<<"LockWidget:"<geometry()<geometry(); lockWidget->hide(); lockWidget->setGeometry(screen->geometry()); lockWidget->show(); chkInOneScreen = true; break; } -#endif } if (!chkInOneScreen) { for(auto screen : QGuiApplication::screens()) { - if(screen == qApp->primaryScreen()){ + if(!screen){ /*避免切换时闪烁*/ - qInfo()<<"LockWidget:"<geometry()<geometry(); + qInfo()<<"LockWidget:"<geometry()<geometry()<<","<hide(); lockWidget->setGeometry(screen->geometry()); lockWidget->show(); @@ -846,6 +843,7 @@ void FullBackgroundWidget::showScreensaver(bool isPreview/* = false*/) } else { saverWidget->setGeometry(screen->geometry()); } + } setCursor(Qt::BlankCursor); @@ -961,39 +959,60 @@ void FullBackgroundWidget::onLockScreenTimeout() m_timerLock->stop(); } -void FullBackgroundWidget::onBlankScreensaver() +void FullBackgroundWidget::onBlankScreensaver(int nDelay/* = 0*/, bool hasLock/* = true*/) { - showLockWidget(); - screenStatus = (ScreenStatus)(screenStatus | SCREEN_SAVER | SCREEN_LOCK); - qDebug() << "showScreensaver - screenStatus: " << screenStatus; + if (hasLock) { + showLockWidget(); + screenStatus = (ScreenStatus)(screenStatus | SCREEN_SAVER | SCREEN_LOCK); + } else { + screenStatus = (ScreenStatus)(screenStatus | SCREEN_SAVER); + } + qDebug() << "showScreensaver - screenStatus: " << screenStatus << nDelay; - for(auto screen : QGuiApplication::screens()) - { - ScreenSaver *saver = configuration->getScreensaver(); - saver->mode = SaverMode(SAVER_BLANK_ONLY); - ScreenSaverWidget *saverWidget = new ScreenSaverWidget(saver, this); - widgetXScreensaverList.push_back(saverWidget); - saverWidget->setGeometry(screen->geometry()); - } - setCursor(Qt::BlankCursor); - isBlank = true; + for(auto screen : QGuiApplication::screens()) + { + ScreenSaver *saver = configuration->getScreensaver(); + saver->mode = SaverMode(SAVER_BLANK_ONLY); + ScreenSaverWidget *saverWidget = new ScreenSaverWidget(saver, this); + widgetXScreensaverList.push_back(saverWidget); + saverWidget->setGeometry(screen->geometry()); + } + setCursor(Qt::BlankCursor); + isBlank = true; - /*在进行压力测试时,可能会出现锁屏界面启动极慢,导致在睡眠之前调用了锁屏,但 - * 锁屏没来得及绑定睡眠唤醒信号,导致唤醒后,锁屏界面没有收到信号从而一直显示黑屏的问题。 - * 因此这里在进入黑色屏保时,通过后台接口,获取一次当前是否应该显示黑色屏保状态*/ - QDBusInterface *interface = new QDBusInterface(SS_DBUS_SERVICE, - SS_DBUS_PATH, - SS_DBUS_INTERFACE); + if (0 == nDelay) { + /*在进行压力测试时,可能会出现锁屏界面启动极慢,导致在睡眠之前调用了锁屏,但 + * 锁屏没来得及绑定睡眠唤醒信号,导致唤醒后,锁屏界面没有收到信号从而一直显示黑屏的问题。 + * 因此这里在进入黑色屏保时,通过后台接口,获取一次当前是否应该显示黑色屏保状态*/ + QString displayNum = QString(qgetenv("DISPLAY")).replace(":", "").replace(".", "_"); + QString sessionDbus = QString("%1%2").arg(QString(SS_DBUS_SERVICE)).arg(displayNum); + QDBusInterface *interface = new QDBusInterface(sessionDbus, + SS_DBUS_PATH, + SS_DBUS_INTERFACE); + if (!interface->isValid()) { + delete interface; + interface = new QDBusInterface(SS_DBUS_SERVICE, + SS_DBUS_PATH, + SS_DBUS_INTERFACE); + } - QDBusReply stateReply = interface->call("GetBlankState"); - if(!stateReply.isValid()){ - return ; - } + QDBusReply stateReply = interface->call("GetBlankState"); + if(!stateReply.isValid()){ + return ; + } - if(!stateReply){ - isBlank = false; - clearScreensavers(); - } + if(!stateReply){ + isBlank = false; + clearScreensavers(); + } + } else { + QTimer::singleShot(nDelay, this, [=](){ + if (isBlank) { + isBlank = false; + clearScreensavers(); + } + }); + } } void FullBackgroundWidget::onScreensaver() @@ -1388,3 +1407,54 @@ void FullBackgroundWidget::onShowBlackBackGround() setCursor(Qt::BlankCursor); } #endif + +bool FullBackgroundWidget::initMultiviewDbus() +{ + if (m_dbusIfMultiview) { + return true; + } + m_dbusIfMultiview = new QDBusInterface("org.ukui.KWin", + "/MultitaskView", + "org.ukui.KWin.MultitaskView", + QDBusConnection::sessionBus(), + this); + + if (!m_dbusIfMultiview || !m_dbusIfMultiview->isValid()){ + qWarning()<<"org.ukui.KWin.MultitaskView interface error!"; + return false; + } + return true; +} + +bool FullBackgroundWidget::isMultiviewHidden() +{ + if (initMultiviewDbus()) { + QDBusReply reply = m_dbusIfMultiview->call("isHidden"); + if(!reply.isValid()) { + qWarning() << "isHidden error:" << reply.error(); + return true; + } + return reply.value(); + } + return true; +} + +void FullBackgroundWidget::HideMultiview() +{ + if (initMultiviewDbus()) { + QDBusMessage result = m_dbusIfMultiview->call("hide"); + if(result.type() == QDBusMessage::ErrorMessage) { + qWarning() << "HideMultiview error:" << result.errorMessage(); + } + } +} + +void FullBackgroundWidget::ShowMultiview() +{ + if (initMultiviewDbus()) { + QDBusMessage result = m_dbusIfMultiview->call("show"); + if(result.type() == QDBusMessage::ErrorMessage) { + qWarning() << "HideMultiview error:" << result.errorMessage(); + } + } +} diff --git a/src/fullbackgroundwidget.h b/src/fullbackgroundwidget.h index 193e94e..92f1e06 100644 --- a/src/fullbackgroundwidget.h +++ b/src/fullbackgroundwidget.h @@ -52,7 +52,7 @@ public: void mouseMoveEvent(QMouseEvent *e); void mousePressEvent(QMouseEvent *e); void onScreensaver(); - void onBlankScreensaver(); + void onBlankScreensaver(int nDelay = 0, bool hasLock = true); void closeScreensaver(); void setIsStartup(bool val); @@ -91,6 +91,10 @@ private: bool isOtherWnd(int wndId); void delayLockScreen(); void stopDelayLockScreen(); + bool initMultiviewDbus(); + bool isMultiviewHidden(); + void HideMultiview(); + void ShowMultiview(); private Q_SLOTS: void onScreenCountChanged(int); @@ -139,6 +143,9 @@ private: QList m_listWndIds; QTimer *m_timerLock = nullptr; bool m_isAlreadyShowSaver = false; + + // 多任务视图接口 + QDBusInterface *m_dbusIfMultiview = nullptr; }; #endif // FULLBACKGROUNDWIDGET_H diff --git a/src/grab-x11.cpp b/src/grab-x11.cpp index 03806d2..9182cab 100644 --- a/src/grab-x11.cpp +++ b/src/grab-x11.cpp @@ -17,8 +17,19 @@ **/ #include "grab-x11.h" #include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include + +#define MAX_PROPERTY_VALUE_LEN 4096 class XServerGraber{ public: @@ -59,8 +70,8 @@ bool establishGrab() if(!grabKeyboard()) return false; - -/*抓取鼠标会导致触摸无效,因此这里先注释掉*/ + +/*抓取鼠标会导致触摸无效,这里暂时取消掉*/ /* if(!grabMouse()) { XUngrabKeyboard(QX11Info::display(), CurrentTime); @@ -79,7 +90,159 @@ bool closeGrab() Q_UNUSED(xserverGraber); XUngrabKeyboard(QX11Info::display(), CurrentTime); - // XUngrabPointer(QX11Info::display(), CurrentTime); +// XUngrabPointer(QX11Info::display(), CurrentTime); XFlush(QX11Info::display()); return true; } + +static Bool +Window_Has_Property(Display * dpy, Window win, Atom atom) +{ + Atom type_ret; + int format_ret; + unsigned char *prop_ret; + unsigned long bytes_after, num_ret; + + type_ret = None; + prop_ret = NULL; + XGetWindowProperty(dpy, win, atom, 0, 0, False, AnyPropertyType, + &type_ret, &format_ret, &num_ret, + &bytes_after, &prop_ret); + if (prop_ret) + XFree(prop_ret); + + return (type_ret != None) ? True : False; +} + +int getWindowByPid(Window win){ + int ret = -1; + + Atom xa_ret_type; + int ret_format; + unsigned long ret_nitems; + unsigned long ret_bytes_after; + unsigned long tmp_size; + unsigned char *ret_prop; + int id = 0; + + + Atom xa_prop_name = XInternAtom(QX11Info::display(), "_NET_WM_PID", False); // 取对应字串的AtomID + + if (XGetWindowProperty(QX11Info::display(), win, xa_prop_name, 0, // 获取窗口属性 + MAX_PROPERTY_VALUE_LEN / 4, + False, XA_CARDINAL, &xa_ret_type, // XA_CARDINAL为数值类型 + &ret_format, &ret_nitems, &ret_bytes_after, + &ret_prop) != Success) // 后五个参数是返回值 + { + printf("Cannot get %s property.\n", "_NET_WM_PID"); + return -1; + } + else + { + if(ret_prop) + memcpy(&id, ret_prop, 4);// 类型传换 + qDebug()<<"window pid: "< #include #include @@ -25,10 +26,12 @@ #include #include #include +#include #include #include #include +#define DRM_DIR "/sys/class/leds/" #define GSETTINGS_SCHEMA_PERIPHERALS_KEYBOARD "org.ukui.peripherals-keyboard" #define CAPSLOCK_STATUS "capslock_state" @@ -36,33 +39,65 @@ * @brief 判断大写键状态 * @return true: 大写锁定 */ -//bool checkCapsLockState() -//{ -// bool capsState = false; -// unsigned int n; -// XkbGetIndicatorState(QX11Info::display(), XkbUseCoreKbd, &n); -// capsState = (n & 0x01) == 1; +bool checkCapsLockState() +{ + QDir ledDir(DRM_DIR); + QStringList leds = ledDir.entryList(QDir::Dirs); + QString capsFile; -// return capsState; -//} + for(int i = 0;igetFontSize(); + m_ptToPx = configuration->getPtToPx(); m_edit = new QLineEdit(this); m_edit->setObjectName(QStringLiteral("passwdEdit")); m_edit->setAttribute(Qt::WA_InputMethodEnabled, false); //禁用输入法 m_edit->setContextMenuPolicy(Qt::NoContextMenu); //禁用右键菜单 m_edit->installEventFilter(this); + QFont sysFont; + sysFont.setPointSize((16 + curFontSize) *m_ptToPx); + m_edit->setFont(sysFont); m_capsIcon = new QSvgWidget(this); m_capsIcon->setObjectName(QStringLiteral("capsIconLabel")); - settings = new QGSettings(GSETTINGS_SCHEMA_PERIPHERALS_KEYBOARD, "", this); - connect(settings, &QGSettings::changed, + + if (QString(qgetenv("XDG_SESSION_TYPE")) == "wayland"){ + capsState = checkCapsLockState(); + }else{ + settings = new QGSettings(GSETTINGS_SCHEMA_PERIPHERALS_KEYBOARD, "", this); + connect(settings, &QGSettings::changed, this, &IconEdit::onCapsChanged); - capsState = settings->get("capslock-state").toBool(); + capsState = settings->get("capslock-state").toBool(); + } + m_capsIcon->setVisible(capsState); m_capsIcon->load(QString(":/image/assets/capslock.svg")); @@ -73,21 +108,28 @@ IconEdit::IconEdit(QWidget *parent) m_iconButton->setCursor(QCursor(Qt::PointingHandCursor)); m_iconButton->installEventFilter(this); m_iconButton->setFocusPolicy(Qt::FocusPolicy::NoFocus); + m_iconButton->setStyleSheet("border-radius:12px; border:2px solid #3D6BE5;"); - m_modeButton = new QPushButton(this); + m_modeButton = new ModeButton(this); m_modeButton->setObjectName(QStringLiteral("echoModeButton")); - m_modeButton->setCheckable(true); m_modeButton->setIcon(QIcon::fromTheme("ukui-eye-display-symbolic")); m_modeButton->setFocusPolicy(Qt::FocusPolicy::NoFocus); m_modeButton->setCursor(Qt::PointingHandCursor); m_modeButton->installEventFilter(this); - connect(m_modeButton, &QPushButton::clicked, this, [&](bool checked){ - setType(checked ? QLineEdit::Normal : QLineEdit::Password); + m_modeButton->setFixedSize(24, 14); + m_modeButton->setIconSize(QSize(16, 16)); + m_modeButton->setFlat(true); + connect(m_modeButton, &QPushButton::clicked, this, [=](){ + if (m_edit->echoMode() == QLineEdit::Password) { + setType(QLineEdit::Normal); + } else { + setType(QLineEdit::Password); + } }); QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(1, 1, 8, 1); - layout->setSpacing(0); + layout->setSpacing(2); layout->addStretch(); layout->addWidget(m_capsIcon); layout->addWidget(m_modeButton); @@ -129,6 +171,12 @@ bool IconEdit::eventFilter(QObject *obj, QEvent *event) //XSetInputFocus(QX11Info::display(),this->winId(),RevertToParent,CurrentTime); } update(); + } else if(event->type() == QEvent::MouseButtonRelease) { //禁用鼠标中键 + QMouseEvent *mouseevent = static_cast(event); + if(mouseevent->button() == Qt::MidButton){ + event->ignore(); + return true; + } } } if(obj == m_iconButton){ @@ -155,21 +203,23 @@ bool IconEdit::eventFilter(QObject *obj, QEvent *event) void IconEdit::setType(QLineEdit::EchoMode type) { m_edit->setEchoMode(type); - if(type == 0){ - m_modeButton->setChecked(true); + if (type == 0) { m_modeButton->setIcon(QIcon::fromTheme("ukui-eye-display-symbolic")); - } - else{ - m_modeButton->setChecked(false); + } else { m_modeButton->setIcon(QIcon::fromTheme("ukui-eye-hidden-symbolic")); } } +void IconEdit::setModeBtnVisible(bool visible) +{ + m_modeButton->setVisible(visible); +} + void IconEdit::resizeEvent(QResizeEvent *) { // 设置输入框中文件输入区,不让输入的文字在被隐藏在按钮下 int w = m_iconButton->width() + m_modeButton->width(); - m_edit->setTextMargins(1, 1, capsState ? w + m_capsIcon->width() + 8 : w, 1); + m_edit->setTextMargins(1, 1, capsState ? w + m_capsIcon->width() + 10 : w + 6, 1); m_edit->setFixedSize(size()); } @@ -209,17 +259,23 @@ void IconEdit::clicked_cb() void IconEdit::onCapsChanged() { - capsState = settings->get("capslock-state").toBool(); + if(settings){ + capsState = settings->get("capslock-state").toBool(); + }else{ + capsState = checkCapsLockState(); + } m_capsIcon->setVisible(capsState); int w = m_iconButton->width() + m_modeButton->width(); - m_edit->setTextMargins(1, 1, capsState ? w + m_capsIcon->width() + 8 : w, 1); + m_edit->setTextMargins(1, 1, capsState ? w + m_capsIcon->width() + 10 : w + 6, 1); } -//void IconEdit::onCapsStateChanged() -//{ -// bool capsState = m_capsIcon->isHidden(); - -//} +void IconEdit::onCapsStateChanged() +{ + capsState = checkCapsLockState(); + m_capsIcon->setVisible(capsState); + int w = m_iconButton->width() + m_modeButton->width(); + m_edit->setTextMargins(1, 1, capsState ? w + m_capsIcon->width() + 10 : w + 6, 1); +} void IconEdit::setIcon(const QString &text) { diff --git a/src/iconedit.h b/src/iconedit.h index 587f425..f067a3e 100644 --- a/src/iconedit.h +++ b/src/iconedit.h @@ -26,6 +26,9 @@ #include #include #include +#include "modebutton.h" + +class Configuration; class IconEdit : public QWidget { @@ -46,6 +49,7 @@ public: void setFocusin(int target); void readOnly(bool enabled); void setLocked(bool lock); + void setModeBtnVisible(bool visible); //void setEnabled(bool enabled); protected: @@ -62,19 +66,22 @@ Q_SIGNALS: public Q_SLOTS: void clicked_cb(); void onCapsChanged(); -// void onCapsStateChanged(); + void onCapsStateChanged(); private: QLineEdit *m_edit; QSvgWidget *m_capsIcon; QPushButton *m_iconButton; - QPushButton *m_modeButton; + ModeButton *m_modeButton; QTimer *m_timer; QPixmap m_waitingPixmap; QString m_iconText; //文字作为图标 QIcon m_icon; - QGSettings *settings; - bool capsState = false; + QGSettings *settings; + bool capsState = false; + Configuration *configuration; + double curFontSize = 0; + double m_ptToPx = 1.0; }; #endif // ICONEDIT_H diff --git a/src/interface.cpp b/src/interface.cpp index 9e1309f..d188ebf 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -54,6 +54,10 @@ Interface::Interface(QObject *parent) connect(&process, static_cast(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus){ + qInfo()<<"ukui-screensaver-dialog is exited,exitCode is "<isLidCloseWithBlank()) { m_nStatus &= ~SESSION_STATUS_SCREENCLOSE; } + stopDelayLockScreen(); } } @@ -456,8 +466,8 @@ bool Interface::checkStatus(int nStatus) return false; } if (((m_sessionWatcher->idledelay()*60 == m_sessionWatcher->closeActivationDelay()) - && m_sessionWatcher->closeActivationDelay() != -1) && !m_sessionWatcher->isCloseActivationEnable()) { - qDebug()<<"Close same with idle and Close disable!"; + && m_sessionWatcher->closeActivationDelay() != -1)/* && !m_sessionWatcher->isCloseActivationEnable()*/) { + qDebug()<<"Close same with idle do nothing!"; return false; } } @@ -467,3 +477,84 @@ bool Interface::checkStatus(int nStatus) } return true; } + +bool Interface::LockByBlank(int nType) // 0:idle delay close;1:lid close;2:lowpower close +{ + qDebug()<<"LockByBlank:"<closeActivationDelay(); + int nIdleDelay = m_sessionWatcher->idledelay(); + bool isCloseActive = m_sessionWatcher->isCloseActivationEnable(); + qDebug()<<"DelayState:"<isLockEnable()) { // 仅启动屏保 + isNeedLock = false; + } + } else { + return false; + } + } else { + qDebug()<<"Don't need blank lock:"<locktimeout() != -1 && isNeedLock) { + delayLockScreen(); + return false; + } else { + QString cmd = QString("/usr/bin/ukui-screensaver-dialog --blank --delay %1 --has-lock %2").arg(2000).arg(isNeedLock?1:0); + qDebug() << cmd; + process.start(cmd); + emitLockState(true); + } + return true; + } +} + +void Interface::delayLockScreen() +{ + if (!m_timerLock) { + m_timerLock = new QTimer(this); + connect(m_timerLock, &QTimer::timeout, this, &Interface::onLockScreenTimeout); + } + qDebug()<<"LockTimeout:"<locktimeout(); + if (m_sessionWatcher->locktimeout() != -1) { + stopDelayLockScreen(); + m_timerLock->start(m_sessionWatcher->locktimeout()*1000); + } +} + +void Interface::stopDelayLockScreen() +{ + if (m_timerLock && m_timerLock->isActive()) { + m_timerLock->stop(); + } +} + +void Interface::onLockScreenTimeout() +{ + Lock(); + m_timerLock->stop(); +} diff --git a/src/interface.h b/src/interface.h index 97e9b44..8b228ae 100644 --- a/src/interface.h +++ b/src/interface.h @@ -62,13 +62,27 @@ public Q_SLOTS: void onSessionIdleExit(); void onScreenClosed(bool state); void onLidStateChaned(bool isClosed); - bool GetBlankState(); + bool GetBlankState(); + bool LockByBlank(int nType); + private: bool checkExistChild(); void inhibit(); void uninhibit(); void emitLockState(bool); bool checkStatus(int nStatus); + /** + * @brief delayLockScreen 延迟锁屏 + */ + void delayLockScreen(); + /** + * @brief stopDelayLockScreen 停止延迟锁屏 + */ + void stopDelayLockScreen(); + /** + * @brief onLockScreenTimeout 延迟锁屏处理过程 + */ + void onLockScreenTimeout(); private: bool lockState; @@ -79,6 +93,8 @@ private: QDBusUnixFileDescriptor m_inhibitFileDescriptor; int m_nStatus = 0; // 当前状态 bool blankState = false; + bool m_isNewBlankInterface = false; + QTimer *m_timerLock = nullptr; private: QProcess process; }; diff --git a/src/klabel.cpp b/src/klabel.cpp new file mode 100644 index 0000000..ad19dd3 --- /dev/null +++ b/src/klabel.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "klabel.h" +#include "configuration.h" +#include "commonfunc.h" +#include +#include +#include + +KLabel::KLabel(QWidget *parent) + : QLabel(parent), + configuration(Configuration::instance()) +{ + curFontSize = configuration->getFontSize(); + m_ptToPx = configuration->getPtToPx(); + this->setStyleSheet("QLabel{color: white;}" + "QToolTip{border-radius:4px; background-color:#FFFFFF; color:black;}"); +} + +void KLabel::setFontSize(int fontSize) +{ + sysFont.setPointSize((fontSize +curFontSize) *m_ptToPx); + this->setFont(sysFont); + QToolTip::setFont(sysFont); +} + +void KLabel::setElideText(const QString text, int width, int size) +{ + sysFont.setPointSize((size + curFontSize) *m_ptToPx); + QString str = ElideText(sysFont,width,text); + if(text != str) + this->setToolTip(text); + if(text == str) + this->setToolTip(""); + this->setText(str); +} diff --git a/src/klabel.h b/src/klabel.h new file mode 100644 index 0000000..c96b00b --- /dev/null +++ b/src/klabel.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef KLABEL_H +#define KLABEL_H + +#include + +class Configuration; + +class KLabel : public QLabel +{ + Q_OBJECT +public: + KLabel(QWidget *parent = nullptr); + void setFontSize(int fontSize); + void setElideText(const QString text, int width, int size = 16); + +private: + Configuration *configuration; + double curFontSize; + double m_ptToPx = 1.0; + QFont sysFont; +}; + +#endif // KLABEL_H diff --git a/src/libinputswitchevent.cpp b/src/libinputswitchevent.cpp index 0f30800..de3886f 100644 --- a/src/libinputswitchevent.cpp +++ b/src/libinputswitchevent.cpp @@ -19,31 +19,44 @@ #include "libinputswitchevent.h" typedef std::function sendEvent; -LibinputSwitchEvent::LibinputSwitchEvent(QObject *parent) : QObject(parent) +LibinputSwitchEvent::LibinputSwitchEvent(QObject *parent) + : QObject(parent) + , m_machineModel(MachineModel::getMachineModelInstance()) { - + m_machineType = m_machineModel->getTheMachineType(); sendEvent se = std::bind(&LibinputSwitchEvent::dealEvent, this, std::placeholders::_1); m_inputGatherClient = new UKUIInputGatherClient; m_inputGatherClient->setEventCallBack(se); m_inputGatherClient->startToReceiveEvent(); - } + LibinputSwitchEvent::~LibinputSwitchEvent() { delete m_inputGatherClient; } + bool LibinputSwitchEvent::geInitDevicesStatus() { - //0 非平板 - //1 平板 - //-1 不支持 - int status = m_inputGatherClient->libinputTabletSwitchState(); - qInfo() << __FILE__ << __LINE__<< "当前设备的状态:" << status; - if(status == 1) + //其他处理 + if (m_machineType == QStringLiteral("SLATE")) { return true; - else + }else if (m_machineType == "LAPTOP" ) {//永久附加键盘笔记本 + //return true; + }else if (m_machineType == "ALLINONE") {//台式 return false; + }else { + //0 非平板 + //1 平板 + //-1 不支持 + int status = m_inputGatherClient->libinputTabletSwitchState(); + qInfo() << __FILE__ << __LINE__<< "当前设备的状态:" << status; + if(status == 1) + return true; + else + return false; + } } + void LibinputSwitchEvent::dealEvent(Event* e) { switch (e->type) { diff --git a/src/libinputswitchevent.h b/src/libinputswitchevent.h index 424bafd..95ecbe3 100644 --- a/src/libinputswitchevent.h +++ b/src/libinputswitchevent.h @@ -21,6 +21,7 @@ #include #include #include +#include "machinemodel.h" //头文件以及顺序不可改,不可删 class LibinputSwitchEvent : public QObject { @@ -35,6 +36,10 @@ signals: void tabletModeStatusChanged(int tabletmode); private: void dealEvent(Event* e); + +private: + QString m_machineType; + std::shared_ptr m_machineModel = nullptr; }; #endif // LIBINPUTSWITCHEVENT_H diff --git a/src/lockwidget.cpp b/src/lockwidget.cpp index bbb0ff7..daef32c 100644 --- a/src/lockwidget.cpp +++ b/src/lockwidget.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -33,12 +34,11 @@ #include #include #include -#include #include -#include #include #include "authdialog.h" -#include "virtualkeyboard.h" +#include "virtualkeyboardwidget.h" +#include "configuration.h" #include "users.h" #include "displaymanager.h" #include "config.h" @@ -46,16 +46,23 @@ #include "hoverwidget.h" #include "kylinnm.h" #include "mytabwidget.h" +#include "klabel.h" +#include "rootWindowBackground.h" +#include "configuration.h" #include #include #include +#define GSETTINGS_SCHEMA_MATE_BG "org.mate.background" +#define KEY_PICTURE_FILENAME "pictureFilename" +#define KEY_PICTURE_OPTIONS "pictureOptions" +#define KEY_PRIMARY_COLOR "primaryColor" #define TIME_TYPE_SCHEMA "org.ukui.control-center.panel.plugins" #define CONFIG_FILE "/etc/lightdm/ukui-greeter.conf" #define ON_TAB_SHEET "QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: 2px solid #2C73C8;}" -#define ON_NORMAL_SHEET "QPushButton{text-align:center;color: rgb(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ - QPushButton::hover{background-color: rgb(255,255,255,15%);} \ +#define ON_NORMAL_SHEET "QPushButton{text-align:center;color: rgba(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ + QPushButton::hover{background-color: rgba(255,255,255,15%);} \ QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}" float scale; @@ -64,6 +71,7 @@ LockWidget::LockWidget(QWidget *parent) ui(new Ui::LockWidget), usersMenu(nullptr), scrollArea(nullptr), + configuration(Configuration::instance()), users(new Users(this)), displayManager(new DisplayManager(this)), timeType(24), @@ -80,7 +88,7 @@ LockWidget::LockWidget(QWidget *parent) authDialog = new AuthDialog(user, this); authDialog->installEventFilter(this); connect(authDialog, &AuthDialog::authenticateCompete, - this, &LockWidget::closed); + this, &LockWidget::onAuthenticateCompete); connect(authDialog,&AuthDialog::clickPassword, this,&LockWidget::onClickPassword); connect(authDialog,&AuthDialog::loginOptionClicked, @@ -93,7 +101,7 @@ LockWidget::LockWidget(QWidget *parent) // connect(m_kylinNM, &KylinNM::onConnectChanged, this,[=](){ // updateNetIcon(m_kylinNM->getConnectStatus()); // }); - + curFontSize = configuration->getFontSize(); this->installEventFilter(this); initUI(); @@ -134,6 +142,10 @@ bool LockWidget::eventFilter(QObject *obj, QEvent *event) if(vKeyboard && obj == vKeyboard) return true; + if (vKeyboard && obj != vKeyboard && obj != ui->btnKeyboard && obj != btnNetworkManager && obj != ui->btnPowerManager && vKeyboard->isVisible()) { + hideBottomPlugins(); + } + if(obj == ui->btnPowerManager || obj == ui->btnSwitchUser || obj == btnNetworkManager || obj == ui->btnBatteryStatus || obj == ui->btnKeyboard) { authDialog->setFocusin(REMOVE); return false; @@ -169,21 +181,7 @@ bool LockWidget::eventFilter(QObject *obj, QEvent *event) } if(powermanager && powermanager->isVisible()){ - authDialog->show(); - powermanager->hide(); - if(!authDialog->getLineeditStatus()) { - tabAt = LINEEDIT; - authDialog->setFocusin(IN_LINEEDIT); - if(isTableMode && !(vKeyboard && vKeyboard->isVisible())) { - showVirtualKeyboard(); - } - } else { - tabAt = MESSAGEBTN; - authDialog->setFocusin(ON_MESSAGEBTN); - } - setBottomBtnSheet(); - powermanager->clearStatus(); - at_power = false; + showPowerManager(); } } @@ -221,6 +219,11 @@ void LockWidget::setStartupMode(bool mode) if (powermanager) { powermanager->setStartupMode(m_isStartupMode); } + if (m_isStartupMode) { + m_futureLoadDeskBg = QtConcurrent::run([=](){ + setRootWindow(); + }); + } } void LockWidget::key_enter_release(int key) @@ -659,6 +662,9 @@ void LockWidget::startAuth() if(authDialog) { authDialog->startAuth(); + if (isTableMode && !(vKeyboard && vKeyboard->isVisible())) { + showVirtualKeyboard(); + } } } @@ -701,9 +707,9 @@ void LockWidget::initUI() ui->lblTime->setText(QDateTime::currentDateTime().toString("hh:mm")); if(dateType == "cn") - ui->lblDate->setText(QDate::currentDate().toString("yyyy/MM/dd ddd")); + ui->lblDate->setText(QDate::currentDate().toString("yyyy/MM/dd ddd").replace("周","星期")); else - ui->lblDate->setText(QDate::currentDate().toString("yyyy-MM-dd ddd")); + ui->lblDate->setText(QDate::currentDate().toString("yyyy-MM-dd ddd").replace("周","星期")); }); if(timeType == 12) @@ -711,7 +717,7 @@ void LockWidget::initUI() else ui->lblTime->setText(QDateTime::currentDateTime().toString("hh:mm")); - ui->lblTime->setStyleSheet("QLabel{color:white; font-size: 36px;}"); + ui->lblTime->setFontSize(36); ui->lblTime->setAlignment(Qt::AlignCenter); ui->lblTime->adjustSize(); timer->start(1000); @@ -720,11 +726,11 @@ void LockWidget::initUI() // qDebug() << "current date: " << date; // ui->lblDate->setText(date); if(dateType == "cn") - ui->lblDate->setText(QDate::currentDate().toString("yyyy/MM/dd ddd")); + ui->lblDate->setText(QDate::currentDate().toString("yyyy/MM/dd ddd").replace("周","星期")); else - ui->lblDate->setText(QDate::currentDate().toString("yyyy-MM-dd ddd")); + ui->lblDate->setText(QDate::currentDate().toString("yyyy-MM-dd ddd").replace("周","星期")); - ui->lblDate->setStyleSheet("QLabel{color:white; font-size: 18px;}"); + ui->lblDate->setFontSize(18); ui->lblDate->setAlignment(Qt::AlignCenter); ui->lblDate->adjustSize(); ui->widgetTime->adjustSize(); @@ -795,8 +801,8 @@ void LockWidget::initUI() // }); btnNetworkManager = new KyNetworkIcon(this); - btnNetworkManager->setStyleSheet("QPushButton{text-align:center;color: rgb(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ - QPushButton::hover{background-color: rgb(255,255,255,15%);} \ + btnNetworkManager->setStyleSheet("QPushButton{text-align:center;color: rgba(255, 255, 255, 255);border: none;border-radius: 4px;outline: none;} \ + QPushButton::hover{background-color: rgba(255,255,255,15%);} \ QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}"); btnNetworkManager->setCheckable(true); @@ -814,29 +820,15 @@ void LockWidget::initUI() this->setCursor(Qt::ArrowCursor); }); -// if(QX11Info::isPlatformX11()){ - //虚拟键盘 - ui->btnKeyboard->setIcon(QIcon(":/image/assets/keyboard.svg")); - ui->btnKeyboard->setFixedSize(48, 48); - ui->btnKeyboard->setIconSize(QSize(24, 24)); - ui->btnKeyboard->setFocusPolicy(Qt::NoFocus); - ui->btnKeyboard->installEventFilter(this); + ui->btnKeyboard->setIcon(QIcon(":/image/assets/keyboard.svg")); + ui->btnKeyboard->setFixedSize(48, 48); + ui->btnKeyboard->setIconSize(QSize(24, 24)); + ui->btnKeyboard->setFocusPolicy(Qt::NoFocus); + ui->btnKeyboard->installEventFilter(this); -/* connect(ui->btnKeyboard, &QPushButton::clicked, - this, [&]{ - qDebug() << vKeyboard->isHidden(); - vKeyboard->setVisible(vKeyboard->isHidden()); - }); -*/ + connect(ui->btnKeyboard, &QPushButton::clicked, + this, &LockWidget::showVirtualKeyboard); - - connect(ui->btnKeyboard, &QPushButton::clicked, - this, &LockWidget::showVirtualKeyboard); -/* - } else { - ui->btnKeyboard->hide(); - } -*/ //用户切换 if(displayManager->canSwitch()) { @@ -859,10 +851,21 @@ void LockWidget::initUI() } connect(libswitch , &LibinputSwitchEvent::tabletModeStatusChanged, this, [ = ](int tablet_mode) { isTableMode = tablet_mode; + qInfo()<<"TableMode:"<isVisible())) { - showVirtualKeyboard(); - QTimer::singleShot(500, this, [&, this](){ - authDialog->setFocusin(IN_LINEEDIT); +// QTimer::singleShot(1000, this, [=]{ +// if (this->isTableMode) { +// showVirtualKeyboard(); +// QTimer::singleShot(500, this, [&, this](){ +// authDialog->setFocusin(IN_LINEEDIT); +// }); +// } +// }); + } else if (!isTableMode && (tabAt == BOTTMBTN && horAT == KEYBOARDBTN) && (vKeyboard && vKeyboard->isVisible())) { + QTimer::singleShot(100, this, [=]{ + if (!this->isTableMode) { + hideBottomPlugins(); + } }); } }); @@ -881,12 +884,14 @@ void LockWidget::showVirtualKeyboard() tabAt = BOTTMBTN; horAT = KEYBOARDBTN; if(!vKeyboard){ - vKeyboard = new VirtualKeyboard(this); + vKeyboard = new VirtualKeyboardWidget(this); vKeyboard->installEventFilter(this); vKeyboard->hide(); - connect(vKeyboard, &VirtualKeyboard::aboutToClose, + connect(vKeyboard, &VirtualKeyboardWidget::aboutToClose, this, &LockWidget::hideBottomPlugins); + connect(vKeyboard, &VirtualKeyboardWidget::aboutToFloat, + this, &LockWidget::netResetLocation); } vKeyboard->setVisible(vKeyboard->isHidden()); @@ -895,7 +900,7 @@ void LockWidget::showVirtualKeyboard() vKeyboard->raise(); //authDialog->setFocusin(IN_LINEEDIT); at_plugins = true; - if(m_kylinNM && m_kylinNM->isVisible()) { + if(m_kylinNM && m_kylinNM->isVisible() && !vKeyboard->getFloatStatus()) { m_kylinNM->move(this->width() - m_kylinNM->width() - 20, this->height() - m_kylinNM->height() - vKeyboard->height()); m_kylinNM->raise(); @@ -906,7 +911,25 @@ void LockWidget::showVirtualKeyboard() if(mBatteryWidget && mBatteryWidget->isVisible()) setCheckedSheet(BATTERYBTN, false); } - setVirkeyboardPos(); + vKeyboard->raise(); + //setVirkeyboardPos(); +} + +void LockWidget::netResetLocation() +{ + if (m_kylinNM && m_kylinNM->isVisible()) { + if (vKeyboard->getFloatStatus()) { + m_kylinNM->move(this->width() - m_kylinNM->width() - 20, + this->height() - m_kylinNM->height() - 72 - 8) ; + } else { + m_kylinNM->move(this->width() - m_kylinNM->width() - 20, + this->height() - m_kylinNM->height() - vKeyboard->height()); + } + m_kylinNM->raise(); + } + if (vKeyboard && vKeyboard->isVisible()) { + vKeyboard->raise(); + } } void LockWidget::showUserMenu() @@ -969,26 +992,30 @@ void LockWidget::showPowerManager(bool keynavigation) setCheckedSheet(BATTERYBTN, false); if(sureWidget && sureWidget->isVisible()) sureWidget->hide(); - if(vKeyboard && vKeyboard->isVisible()) - vKeyboard->hide(); + if (!at_power && (vKeyboard && vKeyboard->isVisible())) { + m_isShowKeyboard = true; + hideBottomPlugins(); + } else if (!at_power && (vKeyboard && !vKeyboard->isVisible())) { + m_isShowKeyboard = false; + } if(powermanager->isVisible()){ authDialog->show(); powermanager->hide(); if(!authDialog->getLineeditStatus()) { tabAt = LINEEDIT; authDialog->setFocusin(IN_LINEEDIT); - if(isTableMode && !(vKeyboard && vKeyboard->isVisible())) { + if (m_isShowKeyboard && isTableMode && !(vKeyboard && vKeyboard->isVisible())) { showVirtualKeyboard(); } } else { tabAt = MESSAGEBTN; authDialog->setFocusin(ON_MESSAGEBTN); } - setBottomBtnSheet(); + //setBottomBtnSheet(); powermanager->clearStatus(); at_power = false; } - else{ + else{ authDialog->hide(); powermanager->show(); if(keynavigation){ @@ -1152,6 +1179,9 @@ void LockWidget::showNetManager(bool keynavigation) m_kylinNM->width(), m_kylinNM->height()); m_kylinNM->raise(); + if (vKeyboard && vKeyboard->isVisible()) { + vKeyboard->raise(); + } m_kylinNM->setFocus(); /*在150%缩放下,点击网络弹窗左上角有线连接部分,authDialog会收到点击事件导致网络弹窗隐藏, * 这里只调用m_kylinNM->raise()仍会有问题,需要再调用一次authDialog->lower()才行,原因未知*/ @@ -1189,7 +1219,6 @@ void LockWidget::onClickPassword() setCheckedSheet(SWITCHBTN, false); at_plugins = false; } - if(isTableMode) { if(!(vKeyboard && vKeyboard->isVisible())) showVirtualKeyboard(); @@ -1458,12 +1487,11 @@ void LockWidget::initUserMenu() usersMenu = new QMenu(scrollContents); usersMenu->setObjectName("usersMenu"); usersMenu->setToolTipsVisible(true); - usersMenu->setStyleSheet("QMenu{background-color: rgb(255,255,255,15%);color: white;border-radius: 4px;width:250px;font-size: 16px;padding: 5px 5px 5px 5px;} \ + usersMenu->setStyleSheet("QMenu{background-color: rgb(255,255,255,15%);color: white;border-radius: 8px;width:250px;padding: 5px 5px 5px 5px;} \ QMenu::icon{padding: 2px 5px 2px 5px;}\ - QMenu::item{width:225px;border-radius: 4px;height:36px;font-size:16px;padding: 2px 10px 2px 10px;} \ + QMenu::item{width:225px;border-radius: 4px;height:36px;padding: 2px 10px 2px 10px;} \ QMenu::item:selected {border-radius: 4px;background-color:rgb(255,255,255,40%);} \ - QMenu::item:pressed {border-radius: 4px;background-color: rgb(255,255,255,40%);} \ - QLabel {color: white;font-size: 16px;}"); + QMenu::item:pressed {border-radius: 4px;background-color: rgb(255,255,255,40%);}"); // usersMenu->setStyleSheet("QMenu{background-color:transparent;color:white;padding:5px 5px 5px 8px}"); //QToolTip{border-radius:4px;background-color:rgb(255,255,255,40%);color:white;} @@ -1490,9 +1518,9 @@ void LockWidget::initUserMenu() p = PixmapToRound(p, 16*scale); iconlabel->setPixmap(p); iconlabel->setGeometry(8,4,32,32); - QLabel *textlabel =new QLabel(widget); - textlabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); - textlabel->setGeometry(48,8,190,24); + KLabel *textlabel =new KLabel(widget); + textlabel->setFontSize(16); + textlabel->setGeometry(48,4,190,30); action->setToolTip("SwitchUser"); action->setData("SwitchUser"); usersMenu->addAction(action); @@ -1525,9 +1553,9 @@ void LockWidget::initUserMenu() p = PixmapToRound(p, 16*scale); iconlabel->setPixmap(p); iconlabel->setGeometry(8,4,32,32); - QLabel *textlabel =new QLabel(widget); - textlabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); - textlabel->setGeometry(48,8,190,24); + KLabel *textlabel =new KLabel(widget); + textlabel->setFontSize(16); + textlabel->setGeometry(48,4,190,30); action->setData("Guest"); action->setToolTip("Guest"); usersMenu->addAction(action); @@ -1550,8 +1578,22 @@ void LockWidget::initUserMenu() if(scrollArea){ if(scrollContents->height() < height()/2){ scrollArea->setFixedSize(usersMenu->width(), scrollContents->height()+1); - }else{ + + scrollArea->clearMask(); + }else{ scrollArea->setFixedSize(usersMenu->width() + 16, height()/2); + + /*当scrollArea区域小于scrollContent大小时,使用样式表绘制的圆角外部透明部分,会显示出scrollContent的内容 + * 导致圆角外部有阴影,因此使用另一种方式再次绘制圆角,该方式绘制出来的圆角存在一定锯齿,所以只在会有阴影 + * 的情况下执行。*/ + QBitmap bitMap(scrollArea->width(),scrollArea->height()); // 定义一个窗口大小的位图 + bitMap.fill(); // 填充整个位图 + QPainter painter(&bitMap); // 定义绘图设备 + painter.setBrush(Qt::black); // 必须定义为黑色 + painter.setPen(Qt::NoPen); // 只能为黑色或者不设置画笔 + painter.setRenderHint(QPainter::Antialiasing);// 反走样 + painter.drawRoundedRect(bitMap.rect(),8,8); // 绘制圆角矩形 + scrollArea->setMask(bitMap); } scrollArea->move(ui->btnSwitchUser->geometry().x()- scrollArea->width()/2 + 24, \ height() - 72 - scrollArea->height() - 8); @@ -1647,9 +1689,20 @@ void LockWidget::resizeEvent(QResizeEvent *event) if(scrollArea){ if(scrollContents->height() < height()/2){ scrollArea->setFixedSize(usersMenu->width(),scrollContents->height()+1); - }else{ + + scrollArea->clearMask(); + }else{ scrollArea->setFixedSize(usersMenu->width() + 16, height()/2); - } + + QBitmap bitMap(scrollArea->width(),scrollArea->height()); // 定义一个窗口大小的位图 + bitMap.fill(); // 填充整个位图 + QPainter painter(&bitMap); // 定义绘图设备 + painter.setBrush(Qt::black); // 必须定义为黑色 + painter.setPen(Qt::NoPen); // 只能为黑色或者不设置画笔 + painter.setRenderHint(QPainter::Antialiasing);// 反走样 + painter.drawRoundedRect(bitMap.rect(),8,8); // 绘制圆角矩形 + scrollArea->setMask(bitMap); + } scrollArea->move(ui->btnSwitchUser->geometry().x()- scrollArea->width()/2 + 24, \ height() - y - scrollArea->height() - 8); } @@ -1698,9 +1751,9 @@ void LockWidget::onUserAdded(const UserItem &user) iconlabel->setPixmap(p); //iconlabel->setStyleSheet("background-color:transparent;"); iconlabel->setGeometry(8,4,32,32); - QLabel *textlabel =new QLabel(widget); - textlabel->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); - textlabel->setGeometry(48,8,190,24); + KLabel *textlabel =new KLabel(widget); + textlabel->setFontSize(16); + textlabel->setGeometry(48,4,190,30); if(getLoadStatus(user.name)){ QLabel *statusIcon = new QLabel(widget); QPixmap status(":/image/assets/selected.svg"); @@ -1712,15 +1765,7 @@ void LockWidget::onUserAdded(const UserItem &user) } action->setDefaultWidget(widget); - QFont font; - font.setPixelSize(16); - QString str = ElideText(font,189,user.realName); - if(user.realName != str){ - textlabel->setToolTip(user.realName); - textlabel->setText(str); - } else { - textlabel->setText(user.realName); - } + textlabel->setElideText(user.realName, textlabel->width()); action->setData(user.name); usersMenu->addAction(action); usersMenu->adjustSize(); @@ -1874,8 +1919,8 @@ void LockWidget::onActiveLineedit() if(authDialog && authDialog->isVisible()) { if(!authDialog->getLineeditStatus()) { authDialog->setFocusin(IN_LINEEDIT); - if(isTableMode && !(vKeyboard && vKeyboard->isVisible())) - showVirtualKeyboard(); +// if(isTableMode && !(vKeyboard && vKeyboard->isVisible())) +// showVirtualKeyboard(); } else { tabAt = MESSAGEBTN; authDialog->setFocusin(ON_MESSAGEBTN); @@ -1939,5 +1984,98 @@ const QDBusArgument &operator >>(const QDBusArgument &arg, userInfo &usersInfo) return arg; } +bool LockWidget::IsDesktopStarted() +{ + QDBusInterface *iface = new QDBusInterface(DESKTOP_DBUS_SERVICE, + DESKTOP_DBUS_PATH, + DESKTOP_DBUS_INTERFACE, + QDBusConnection::sessionBus(), + this); + if (iface) { + if (iface->isValid()) { + delete iface; + return true; + } + delete iface; + } + return false; +} +void LockWidget::setRootWindow() +{ + QStringList keysMateBg; + QString strUserBgFile = ""; + QString strUserBgColor = ""; + QString strUserBgOptions = ""; + if(QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_MATE_BG)){ + QGSettings *mateBgSettings = new QGSettings(GSETTINGS_SCHEMA_MATE_BG, "", this); + keysMateBg = mateBgSettings->keys(); + if (keysMateBg.contains(KEY_PICTURE_FILENAME)) { + strUserBgFile = mateBgSettings->get(KEY_PICTURE_FILENAME).toString(); + } + if (keysMateBg.contains(KEY_PRIMARY_COLOR)) { + strUserBgColor = mateBgSettings->get(KEY_PRIMARY_COLOR).toString(); + } + if (keysMateBg.contains(KEY_PICTURE_OPTIONS)) { + strUserBgOptions = mateBgSettings->get(KEY_PICTURE_OPTIONS).toString(); + } + qDebug()<<"User bg info:"<getDefaultBackgroundName(); + } + if(nDrawBgType == 0) { + qDebug()<<"DrawBgFile:"< #include #include +#include +#include #include #include "kylin-nm/kylin-nm-interface.h" #include "surewindow.h" @@ -48,9 +50,10 @@ struct userInfo { QDBusArgument &operator <<(QDBusArgument &arg, const userInfo &usersInfo); const QDBusArgument &operator >>(const QDBusArgument &arg, userInfo &usersInfo); -class VirtualKeyboard; +class VirtualKeyboardWidget; class PowerManager; class AuthDialog; +class Configuration; class Users; class UserItem; class DisplayManager; @@ -110,9 +113,22 @@ private: void key_shiftTab_release(); void key_LR_release(int key); int getLoginedNum(); - void loadNetPlugin(); - void setBottomBtnSheet(); - void setCheckedSheet(int type, bool show); + void loadNetPlugin(); + void setBottomBtnSheet(); + void setCheckedSheet(int type, bool show); + void netResetLocation(); + + /** + * @brief IsDesktopStarted 桌面是否已启动 + * @return + */ + bool IsDesktopStarted(); + + /** + * @brief setRootWindow 设置X背景 + */ + void setRootWindow(); + private Q_SLOTS: void onUserAdded(const UserItem &user); void onUserDeleted(const UserItem &user); @@ -134,6 +150,10 @@ private Q_SLOTS: void setBatteryIcon(QString str); void dealMessage(QDBusMessage); void onShowMessageBtn(bool is_show); + /** + * @brief onAuthenticateCompete 认证完成 + */ + void onAuthenticateCompete(); protected: bool eventFilter(QObject *obj, QEvent *event); @@ -143,7 +163,8 @@ protected: private: Ui::LockWidget *ui; AuthDialog *authDialog; - VirtualKeyboard *vKeyboard = nullptr; + Configuration *configuration; + VirtualKeyboardWidget *vKeyboard = nullptr; PowerManager *powermanager = nullptr; SureWindow *sureWidget = nullptr; QTimer *timer; @@ -172,7 +193,7 @@ private: bool is_keynavigation =false; int tabAt = LINEEDIT; int horAT = BATTERYBTN; - int at_power = false; + bool at_power = false; bool at_plugins = false; QDBusInterface *batInterface = nullptr; @@ -183,6 +204,10 @@ private: // 监听键盘插拔 LibinputSwitchEvent *libswitch = nullptr; bool isTableMode = false; + bool m_isShowKeyboard = false; // 打开电源管理界面前虚拟键盘是否已打开 + + double curFontSize = 0; + QFuture m_futureLoadDeskBg; }; #endif // LOCKWIDGET_H diff --git a/src/lockwidget.ui b/src/lockwidget.ui index b6c8c42..9ca0558 100644 --- a/src/lockwidget.ui +++ b/src/lockwidget.ui @@ -60,14 +60,14 @@ QPushButton::pressed { - + Time - + Date @@ -179,6 +179,13 @@ QPushButton::pressed { + + + KLabel + QLabel +
klabel.h
+
+
diff --git a/src/loginoptionswidget.cpp b/src/loginoptionswidget.cpp index cab7a65..f2f1b95 100644 --- a/src/loginoptionswidget.cpp +++ b/src/loginoptionswidget.cpp @@ -23,6 +23,9 @@ #include #include "giodbus.h" #include "biometricdeviceinfo.h" +#include "configuration.h" +#include "klabel.h" +#include #include #include @@ -35,10 +38,11 @@ #include #include #include +#include #define ON_TAB_SHEET "QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: 2px solid #2C73C8;}" -#define ON_NORMAL_SHEET "QPushButton{background-color: rgba(255,255,255,0); border-radius: 4px; border: none;}\ - QPushButton::hover{ background-color: rgb(255,255,255,15%);}\ +#define ON_NORMAL_SHEET "QPushButton{background-color: rgba(255,255,255,15%); border-radius: 4px; border: none;}\ + QPushButton::hover{ background-color: rgba(255,255,255,40%);}\ QPushButton::pressed {background-color: rgba(255,255,255,40%);}\ QPushButton::checked {background-color: rgba(255, 255, 255, 40%);}" @@ -47,6 +51,7 @@ LoginOptionsWidget::LoginOptionsWidget(BiometricProxy* proxy, int uid, UniAuthSe , m_biomericProxy(proxy) , m_uid(uid) , m_uniauthService(uniauthService) + , configuration(Configuration::instance()) { m_listPriority.clear(); m_listPriority.push_back(BioT_Face); @@ -55,6 +60,9 @@ LoginOptionsWidget::LoginOptionsWidget(BiometricProxy* proxy, int uid, UniAuthSe m_listPriority.push_back(BioT_VoicePrint); m_listPriority.push_back(BioT_FingerVein); m_listPriority.push_back(REMOTE_QRCODE_TYPE); + m_listPriority.push_back(UniT_General_Ukey); + curFontSize = configuration->getFontSize(); + m_ptToPx = configuration->getPtToPx(); initUI(); initConnections(); m_mapDisableDev.clear(); @@ -67,7 +75,7 @@ LoginOptionsWidget::~LoginOptionsWidget() void LoginOptionsWidget::initUI() { - this->setFixedHeight(86); + this->setFixedHeight(94); // 初始化UI m_layoutMain = new QVBoxLayout(); m_layoutMain->setContentsMargins(0,0,0,0); @@ -76,10 +84,11 @@ void LoginOptionsWidget::initUI() m_layoutOptBtns->setContentsMargins(0,0,0,0); m_layoutOptBtns->setSpacing(16); - m_labelOptTitle = new QLabel(); + m_labelOptTitle = new KLabel(); m_labelOptTitle->setAlignment(Qt::AlignCenter); + m_labelOptTitle->setFontSize(16); m_labelOptTitle->setText(tr("Login Options")); - m_labelOptTitle->setFixedHeight(22); + m_labelOptTitle->setFixedHeight(30); m_layoutMain->addWidget(m_labelOptTitle); m_btnGroup = new QButtonGroup(this); @@ -123,6 +132,18 @@ unsigned LoginOptionsWidget::getLoginOptCount() return m_mapDevices.size(); } +int LoginOptionsWidget::getVisibleLoginOptCount() +{ + int nCount = 0; + QMap::iterator itMapBtn = m_mapOptBtns.begin(); + for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { + if (itMapBtn.value() && itMapBtn.value()->isVisible()) { + nCount ++; + } + } + return nCount; +} + DeviceInfoPtr LoginOptionsWidget::getFirstDevInfo() { DeviceInfoPtr devInfo = nullptr; @@ -187,29 +208,32 @@ void LoginOptionsWidget::addOptionButton(unsigned uLoginOptType, int nDrvId, QSt return ; } QPushButton *newButton = new QPushButton(); - QVBoxLayout *layoutBtn = new QVBoxLayout(); - newButton->setLayout(layoutBtn); - //QLabel *newLabel = new QLabel(); - layoutBtn->setAlignment(Qt::AlignCenter); - //layoutBtn->addWidget(newLabel); +// QVBoxLayout *layoutBtn = new QVBoxLayout(); +// newButton->setLayout(layoutBtn); +// QLabel *newLabel = new QLabel(); +// layoutBtn->setAlignment(Qt::AlignCenter); +// layoutBtn->addWidget(newLabel); newButton->setCheckable(true); newButton->setChecked(false); newButton->setFocusPolicy(Qt::NoFocus); - if (nDrvId == -1) { - //newButton->setEnabled(false); - newButton->setChecked(true); - //屏蔽鼠标事件 - newButton->setAttribute(Qt::WA_TransparentForMouseEvents, true); - } else { +// if (nDrvId == -1) { +// //newButton->setEnabled(false); +// newButton->setChecked(true); +// //屏蔽鼠标事件 +// newButton->setAttribute(Qt::WA_TransparentForMouseEvents, true); +// } else { int nLength = m_btnGroup->buttons().length(); m_btnGroup->addButton(newButton, nLength); m_listDriveId.append(nDrvId); - } + // } QPixmap iconPixmap; switch (uLoginOptType) { case LOGINOPT_TYPE_PASSWORD: iconPixmap = loadSvg(":/image/assets/ukui-loginopt-password.svg", "white", 16); break; + case LOGINOPT_TYPE_GENERAL_UKEY: + iconPixmap = loadSvg(":/image/assets/ukui-loginopt-ukey.svg", "white", 16); + break; case LOGINOPT_TYPE_FACE: iconPixmap = loadSvg(":/image/assets/ukui-loginopt-face.svg", "white", 16); break; @@ -232,7 +256,12 @@ void LoginOptionsWidget::addOptionButton(unsigned uLoginOptType, int nDrvId, QSt newButton->setIcon(iconPixmap); //newLabel->setPixmap(iconPixmap); newButton->setToolTip(strDrvName); - newButton->setStyleSheet("QToolTip{border-radius:4px;background-color:#FFFFFF;color:black;font-size:16px}"); + sysFont.setPointSize((14 + curFontSize) *m_ptToPx); + QToolTip::setFont(sysFont); + newButton->setStyleSheet("QPushButton{text-align:center;background-color: rgb(255,255,255,15%);border: none;border-radius: 4px;outline: none;}" + "QPushButton::hover{background-color: rgb(255,255,255,40%);}" + "QPushButton::pressed {background-color: rgba(255,255,255,40%);}" + "QPushButton::checked {background-color: rgba(255,255,255,40%);}"); newButton->setFixedSize(48, 48); if (isDeviceDisable(nDrvId)) { newButton->setDisabled(true); @@ -258,20 +287,51 @@ void LoginOptionsWidget::clearOptionButtons() m_mapOptBtns.clear(); } +bool LoginOptionsWidget::getHasUkeyOptions() +{ + return isShowUkey; +} + void LoginOptionsWidget::updateOptionButtons() { + isShowUkey = false; clearOptionButtons(); - //addOptionButton(LOGINOPT_TYPE_PASSWORD, -1, tr("Password")); + addOptionButton(LOGINOPT_TYPE_PASSWORD, -1, tr("Password")); DeviceMap::iterator itMapDev = m_mapDevices.begin(); for ( ; itMapDev != m_mapDevices.end(); itMapDev++) { for (DeviceInfoPtr devPtr : itMapDev.value()) { if (devPtr) { + if(devPtr->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + //ukey 设备类型排在二维码前,但实际上应该显示在二维码之后,因此暂时不添加 + isShowUkey = true; + continue; + } addOptionButton(itMapDev.key(), devPtr->id, DeviceType::getDeviceType_tr(devPtr->deviceType)); } } } + + itMapDev = m_mapDevices.begin(); + if(isShowUkey){ + for ( ; itMapDev != m_mapDevices.end(); itMapDev++) { + for (DeviceInfoPtr devPtr : itMapDev.value()) { + if(devPtr && devPtr->deviceType == LOGINOPT_TYPE_GENERAL_UKEY){ + //此处才添加ukey + addOptionButton(itMapDev.key(), devPtr->id, DeviceType::getDeviceType_tr(devPtr->deviceType)); + } + } + } + } + + //存在特征但没有插入ukey + if(!isShowUkey && m_biomericProxy->GetHasUkeyFeature(m_uid) ){ + addOptionButton(LOGINOPT_TYPE_GENERAL_UKEY,-2,DeviceType::getDeviceType_tr(LOGINOPT_TYPE_GENERAL_UKEY)); + isShowUkey = true; + } + qDebug()<<"m_mapOptBtns.size():"<hide(); QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { @@ -279,7 +339,7 @@ void LoginOptionsWidget::updateOptionButtons() itMapBtn.value()->hide(); } } - } else { + }else { m_labelOptTitle->show(); QMap::iterator itMapBtn = m_mapOptBtns.begin(); for ( ; itMapBtn != m_mapOptBtns.end(); itMapBtn++) { @@ -288,6 +348,10 @@ void LoginOptionsWidget::updateOptionButtons() } } } + m_mapOptBtns[-1]->hide(); + if(m_mapOptBtns.size() == 2 && isShowUkey) { + m_mapOptBtns[-1]->show(); + } } void LoginOptionsWidget::setUser(int uid) @@ -303,16 +367,21 @@ void LoginOptionsWidget::readDevicesInfo() bool isQRCodeEnable = getQRCodeEnable(); DeviceList deviceList = m_biomericProxy->GetDevList(); QStringList listDefDevices = getAllDefDevices(); - for(auto pDeviceInfo : deviceList) - { - qDebug()<<"BeginGetFeature------!"; - int nDevFeatureCount = m_biomericProxy->GetUserDevFeatureCount(m_uid,pDeviceInfo->id); - qDebug() << *pDeviceInfo << ",feautres:"< 0) { - if (!isAuthEnable && pDeviceInfo->deviceType <= DeviceType::VoicePrint) - continue; - if (!isQRCodeEnable && pDeviceInfo->deviceType == REMOTE_QRCODE_TYPE) - continue; + qDebug()<<"BeginGetFeature------!"; + FeatureMap mapFeatures = m_biomericProxy->GetUserFeatures(m_uid); + qDebug() << m_uid <<",count:"<deviceType <= DeviceType::VoicePrint) + continue; + if (!isQRCodeEnable && pDeviceInfo->deviceType == REMOTE_QRCODE_TYPE) + continue; + int nFeatureCount = 0; + if (mapFeatures.contains(pDeviceInfo->shortName)) { + nFeatureCount = mapFeatures[pDeviceInfo->shortName].size(); + } + qDebug() << *pDeviceInfo <<",count:"< 0) { int nDevType = LOGINOPT_TYPE_OTHERS; nDevType = convertDeviceType(pDeviceInfo->deviceType); if (listDefDevices.contains(pDeviceInfo->shortName) && @@ -321,9 +390,20 @@ void LoginOptionsWidget::readDevicesInfo() } } } + updateOptionButtons(); } +void LoginOptionsWidget::SetExtraInfo(QString extra_info, QString info_type) +{ + if(!m_biomericProxy) + { + qWarning() << "BiometricProxy doesn't exist."; + return; + } + m_biomericProxy->SetExtraInfo(info_type,extra_info); +} + void LoginOptionsWidget::startAuth(DeviceInfoPtr device, int uid) { if(!m_biomericProxy) @@ -349,7 +429,27 @@ void LoginOptionsWidget::startAuth(DeviceInfoPtr device, int uid) this->m_curLoginOptType = convertDeviceType(this->m_curDevInfo->deviceType); updateUIStatus(); SetLastDevice(this->m_strUserName, this->m_curDevInfo->id); - startAuth_(); + if(this->m_curLoginOptType == LOGINOPT_TYPE_GENERAL_UKEY) + startUkeyAuth(); + else + startAuth_(); +} + +void LoginOptionsWidget::startUkeyAuth() +{ + if (!m_curDevInfo) + return ; + qDebug().noquote() << QString("Identify:[drvid: %1, uid: %2]").arg(m_curDevInfo->id).arg(m_uid); + + m_isInAuth = true; + m_dupFD = -1; + + Q_EMIT setLoadingImage(); + m_biomericProxy->StopOps(m_curDevInfo->id); + QDBusPendingCall call = m_biomericProxy->UkeyIdentify(m_curDevInfo->id, 2,m_uid); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &LoginOptionsWidget::onIdentifyComplete); } void LoginOptionsWidget::startAuth_() @@ -362,7 +462,7 @@ void LoginOptionsWidget::startAuth_() m_dupFD = -1; Q_EMIT setLoadingImage(); - + m_biomericProxy->StopOps(m_curDevInfo->id); QDBusPendingCall call = m_biomericProxy->Identify(m_curDevInfo->id, m_uid); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, @@ -386,7 +486,7 @@ void LoginOptionsWidget::stopAuth() Q_EMIT updateImage(QImage()); } -void LoginOptionsWidget::onIdentifyComplete(QDBusPendingCallWatcher *watcher) +void LoginOptionsWidget::onUkeyIdentifyComplete(QDBusPendingCallWatcher *watcher) { if(m_isStopped == true) return ; @@ -398,12 +498,37 @@ void LoginOptionsWidget::onIdentifyComplete(QDBusPendingCallWatcher *watcher) Q_EMIT authComplete(false, -1); return; } + int result = reply.argumentAt(0).toInt(); + int authUid = reply.argumentAt(1).toInt(); + qDebug() << result << authUid << m_uid; + if(result == DBUS_RESULT_SUCCESS) { + qDebug() << "Identify success"; + Q_EMIT authComplete(true, 0); + } else { + qDebug() << "Identify failed"; + Q_EMIT authComplete(false, 2); + } +} + +void LoginOptionsWidget::onIdentifyComplete(QDBusPendingCallWatcher *watcher) +{ + if(m_isStopped == true) + return ; + + QDBusPendingReply reply = *watcher; + if(reply.isError()) + { + qWarning() << "Identify error: " << reply.error().message(); + Q_EMIT authComplete(false, -1); + return; + } + int result = reply.argumentAt(0).toInt(); int authUid = reply.argumentAt(1).toInt(); qDebug() << result << authUid << m_uid; // 特征识别成功,而且用户id匹配 - if(result == DBUS_RESULT_SUCCESS && authUid == m_uid) { + if(result == DBUS_RESULT_SUCCESS && authUid == m_uid) { qDebug() << "Identify success"; Q_EMIT authComplete(true, 0); } else if(result == DBUS_RESULT_NOTMATCH) { // 特征识别不匹配 @@ -597,14 +722,26 @@ bool LoginOptionsWidget::getAuthDouble() return distribId; } -void LoginOptionsWidget::updateUIStatus() +void LoginOptionsWidget::setSelectedPassword() { if (m_mapOptBtns.contains(-1)) { QPushButton* btn = m_mapOptBtns[-1]; - if (btn) { + if (btn && btn->isVisible()) { + btn->setChecked(true); + } + m_curDevInfo = nullptr; + } +} + +void LoginOptionsWidget::updateUIStatus() +{ + if (!m_curDevInfo && m_mapOptBtns.contains(-1)) { + QPushButton* btn = m_mapOptBtns[-1]; + if (btn && btn->isVisible()) { btn->setChecked(true); } } + if (m_curDevInfo) { if (m_mapOptBtns.contains(m_curDevInfo->id)) { QPushButton* btn = m_mapOptBtns[m_curDevInfo->id]; @@ -624,7 +761,16 @@ void LoginOptionsWidget::onOptionSelected(int nIndex, bool keyNavigation) if (nIndex < m_listDriveId.size()) { DeviceInfoPtr info = findDeviceById(m_listDriveId[nIndex]); if (info && !isDeviceDisable(info->id)) { - Q_EMIT optionSelected(convertDeviceType(info->deviceType), info ,keyNavigation); + Q_EMIT optionSelected(convertDeviceType(info->deviceType), info, keyNavigation); + }else if(nIndex == 0 && m_listDriveId[nIndex] == -1){ + stopAuth(); + m_curDevInfo = nullptr; + Q_EMIT optionSelected(LOGINOPT_TYPE_PASSWORD, nullptr, keyNavigation); + }else if(m_listDriveId[nIndex] == -2){ + //存在ukey特征,但未插入ukey + stopAuth(); + m_curDevInfo = nullptr; + Q_EMIT optionSelected(LOGINOPT_TYPE_GENERAL_UKEY, nullptr, keyNavigation); } } } @@ -633,86 +779,65 @@ void LoginOptionsWidget::tabOptionSelected(int option) { switch(option) { case RIGHT: + { at_bioBtn = true; - if(nowAt+1 < m_listDriveId.count()) { - DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[nowAt+1]); - if (infoNow) { - QPushButton* btn = m_mapOptBtns[infoNow->id]; - if (btn) { - btn->setStyleSheet(ON_TAB_SHEET); - } - } - if(nowAt >= 0) { - DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); - if (infoOld) { - QPushButton* btn = m_mapOptBtns[infoOld->id]; - if (btn) { - btn->setStyleSheet(ON_NORMAL_SHEET); - } - } - } - nowAt += 1; - } else if (nowAt+1 == m_listDriveId.count()) { - DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[0]); - if (infoNow) { - QPushButton* btn = m_mapOptBtns[infoNow->id]; - if (btn) { - btn->setStyleSheet(ON_TAB_SHEET); - } - } - DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); - if (infoOld) { - QPushButton* btn = m_mapOptBtns[infoOld->id]; + int nCur = nowAt; + if(nCur >= 0 && nCur < m_listDriveId.count()) { + if (m_mapOptBtns.contains(m_listDriveId[nCur])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nCur]]; if (btn) { btn->setStyleSheet(ON_NORMAL_SHEET); } } - nowAt = 0; } + for (int n = 0; n < m_listDriveId.count(); n ++) { + nCur = nCur + 1; + if (nCur >= m_listDriveId.count()) + nCur = 0; + if (m_mapOptBtns.contains(m_listDriveId[nCur])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nCur]]; + if (btn && btn->isVisible()) { + btn->setStyleSheet(ON_TAB_SHEET); + nowAt = nCur; + break; + } + } + } + } break; case LEFT: + { at_bioBtn = true; - if(nowAt-1 >= 0) { - DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[nowAt-1]); - if (infoNow) { - QPushButton* btn = m_mapOptBtns[infoNow->id]; - if (btn) { - btn->setStyleSheet(ON_TAB_SHEET); - } - } - DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[nowAt]); - if (infoOld) { - QPushButton* btn = m_mapOptBtns[infoOld->id]; + int nCur = nowAt; + if(nCur >= 0 && nCur < m_listDriveId.count()) { + if (m_mapOptBtns.contains(m_listDriveId[nCur])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nCur]]; if (btn) { btn->setStyleSheet(ON_NORMAL_SHEET); } } - nowAt -= 1; - } else if (nowAt-1 < 0) { - DeviceInfoPtr infoNow = findDeviceById(m_listDriveId[m_listDriveId.count() - 1]); - if (infoNow) { - QPushButton* btn = m_mapOptBtns[infoNow->id]; - if (btn) { - btn->setStyleSheet(ON_TAB_SHEET); - } - } - DeviceInfoPtr infoOld = findDeviceById(m_listDriveId[0]); - if (infoOld) { - QPushButton* btn = m_mapOptBtns[infoOld->id]; - if (btn) { - btn->setStyleSheet(ON_NORMAL_SHEET); - } - } - nowAt = m_listDriveId.count() - 1; } + for (int n = 0; n < m_listDriveId.count(); n ++) { + nCur = nCur - 1; + if (nCur < 0) + nCur = m_listDriveId.count() - 1; + if (m_mapOptBtns.contains(m_listDriveId[nCur])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nCur]]; + if (btn && btn->isVisible()) { + btn->setStyleSheet(ON_TAB_SHEET); + nowAt = nCur; + break; + } + } + } + } break; case CLEAR: at_bioBtn = false; if(nowAt >= 0) { - for(int i = 0; i < getLoginOptCount(); i++) { - DeviceInfoPtr infoClear = findDeviceById(m_listDriveId[i]); - if (infoClear) { - QPushButton* btn = m_mapOptBtns[infoClear->id]; + for (int n = 0; n < m_listDriveId.count(); n ++) { + if (m_mapOptBtns.contains(m_listDriveId[n])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[n]]; if (btn) { btn->setStyleSheet(ON_NORMAL_SHEET); } @@ -724,20 +849,26 @@ void LoginOptionsWidget::tabOptionSelected(int option) case FirstDevice: at_bioBtn = true; if(nowAt >= 0) { - for(int i = 0; i < getLoginOptCount(); i++) { - DeviceInfoPtr infoClear = findDeviceById(m_listDriveId[i]); - if (infoClear) { - QPushButton* btn = m_mapOptBtns[infoClear->id]; + for (int n = 0; n < m_listDriveId.count(); n ++) { + if (m_mapOptBtns.contains(m_listDriveId[n])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[n]]; if (btn) { btn->setStyleSheet(ON_NORMAL_SHEET); } } } - DeviceInfoPtr infoFirst = findDeviceById(m_listDriveId[0]); - if (infoFirst) { - QPushButton* btn = m_mapOptBtns[infoFirst->id]; - if (btn) { - btn->setStyleSheet(ON_TAB_SHEET); + int nCur = 0; + for (int n = 0; n < m_listDriveId.count(); n ++) { + nCur = nCur + 1; + if (nCur >= m_listDriveId.count()) + nCur = 0; + if (m_mapOptBtns.contains(m_listDriveId[nCur])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nCur]]; + if (btn && btn->isVisible()) { + btn->setStyleSheet(ON_TAB_SHEET); + nowAt = nCur; + break; + } } } nowAt = 0; @@ -745,15 +876,13 @@ void LoginOptionsWidget::tabOptionSelected(int option) break; case CLICK: at_bioBtn = false; - DeviceInfoPtr infoClick = findDeviceById(m_listDriveId[nowAt]); - if (infoClick) { - QPushButton* btn = m_mapOptBtns[infoClick->id]; + if (nowAt >= 0 && nowAt < m_listDriveId.count() && m_mapOptBtns.contains(m_listDriveId[nowAt])) { + QPushButton* btn = m_mapOptBtns[m_listDriveId[nowAt]]; if (btn) { onOptionSelected(nowAt, true); } } break; - } } @@ -776,6 +905,12 @@ int LoginOptionsWidget::convertDeviceType(int nDevType) case BioT_VoicePrint: nLoginOptType = LOGINOPT_TYPE_VOICEPRINT; break; + case UniT_General_Ukey: + nLoginOptType = LOGINOPT_TYPE_GENERAL_UKEY; + break; + case UniT_Advanced_Ukey: + nLoginOptType = LOGINOPT_TYPE_ADVANCED_UKEY; + break; case UniT_Remote: nLoginOptType = LOGINOPT_TYPE_QRCODE; break; @@ -903,6 +1038,23 @@ bool LoginOptionsWidget::getQRCodeEnable() } } +QString LoginOptionsWidget::getDefaultDevice(QString strUserName,int bioType) +{ + if (m_uniauthService && m_uniauthService->isActivatable()) { + QString defaultDeviceName = ""; + QString strDeviceName = m_uniauthService->getDefaultDevice(strUserName, bioType); + if(!strDeviceName.isEmpty()) { + DeviceInfoPtr pDeviceInfo = findDeviceByName(strDeviceName); + if (pDeviceInfo) { + defaultDeviceName = strDeviceName; + } + } + return defaultDeviceName; + } else { + return GetDefaultDevice(strUserName); + } +} + QString LoginOptionsWidget::getDefaultDevice(QString strUserName) { if (m_uniauthService && m_uniauthService->isActivatable()) { diff --git a/src/loginoptionswidget.h b/src/loginoptionswidget.h index 256ab5c..8c197fa 100644 --- a/src/loginoptionswidget.h +++ b/src/loginoptionswidget.h @@ -24,12 +24,14 @@ #include "uniauthservice.h" class QLabel; +class KLabel; class QButtonGroup; class QHBoxLayout; class QVBoxLayout; class QPushButton; class QTimer; class QPixmap; +class Configuration; typedef enum { BioT_FingerPrint, /** 指纹 **/ @@ -76,7 +78,13 @@ public: bool getBioAuthEnable(int nType); bool getQRCodeEnable(); QString getDefaultDevice(QString strUserName); + QString getDefaultDevice(QString strUserName,int biotype); QStringList getAllDefDevices(); + void SetExtraInfo(QString extra_info,QString info_type); + bool getHasUkeyOptions(); + void setSelectedPassword(); + void updateUIStatus(); + int getVisibleLoginOptCount(); /** * @brief 进行生物识别认证 @@ -102,6 +110,7 @@ public: public Q_SLOTS: void readDevicesInfo(); void onIdentifyComplete(QDBusPendingCallWatcher *watcher); + void onUkeyIdentifyComplete(QDBusPendingCallWatcher *watcher); void onStatusChanged(int drvid, int status); void onFrameWritten(int drvid); void onUSBDeviceHotPlug(int drvid, int action, int devNum); @@ -123,8 +132,8 @@ private: void clearOptionButtons(); void updateOptionButtons(); void startAuth_(); + void startUkeyAuth(); bool getAuthDouble(); - void updateUIStatus(); QPixmap drawSymbolicColoredPixmap(QPixmap &source, QString cgColor); private: @@ -143,7 +152,7 @@ private: QVBoxLayout *m_layoutMain = nullptr; QHBoxLayout *m_layoutOptBtns = nullptr; - QLabel *m_labelOptTitle = nullptr; + KLabel *m_labelOptTitle = nullptr; QButtonGroup *m_btnGroup = nullptr; QList m_listDriveId; QMap m_mapOptBtns; @@ -152,6 +161,11 @@ private: bool at_bioBtn = false; UniAuthService *m_uniauthService = nullptr; QList m_listPriority; + Configuration *configuration; + double curFontSize = 0; + double m_ptToPx = 1.0; + QFont sysFont; + bool isShowUkey = false; }; #endif // LOGINOPTIONSWIDGET_H diff --git a/src/machinemodel.cpp b/src/machinemodel.cpp new file mode 100644 index 0000000..957da65 --- /dev/null +++ b/src/machinemodel.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "machinemodel.h" +#include +#include +#include + +std::shared_ptr MachineModel::m_machineModel = nullptr; +std::mutex MachineModel::m_mutex; + +MachineModel::MachineModel(QObject *parent) : QObject(parent) +{ + initMachineType(); +} + +QString MachineModel::getTheMachineType() +{ + return m_machineType; +} + +std::shared_ptr MachineModel::getMachineModelInstance() +{ + if(m_machineModel == nullptr) + { + std::unique_lock lock(m_mutex); + if(m_machineModel == nullptr) + { + m_machineModel = std::shared_ptr(new MachineModel); + } + } + return m_machineModel; +} + +void MachineModel::initMachineType() +{ + QSettings setting(":/assets/data/conf.ini", QSettings::IniFormat); + setting.beginGroup("MachineType");//节点开始 + + QString type = getSysVendor() + getProductFamily(); + qInfo() << __FILE__ << __LINE__ << type; + if (setting.contains(type)) { + m_machineType = setting.value(type).toString(); + } else { + m_machineType = QString(); + } + qInfo() << __FILE__ << __LINE__ << m_machineType; + setting.endGroup();//节点结束 + +} + +const QString MachineModel::getSysVendor() const +{ + QProcess process; + QStringList options; + options << "-c"; + options << "cat /sys/class/dmi/id/sys_vendor"; + process.start("/bin/bash", options); + process.waitForFinished(); + QString result = process.readAllStandardOutput(); + + QStringList list = result.split("\n"); + result = list.at(0); + qInfo() << __FILE__ << __LINE__ << "获取设备厂商为:" << result; + return result; +} + +const QString MachineModel::getProductName() const +{ + QProcess process; + QStringList options; + options << "-c"; + options << "cat /sys/class/dmi/id/product_name"; + process.start("/bin/bash", options); + process.waitForFinished(); + QString result = process.readAllStandardOutput(); + + QStringList list = result.split("\n"); + result = list.at(0); + qInfo() << __FILE__ << __LINE__ << "获取产品名为:" << result; + return result; +} + +const QString MachineModel::getProductFamily() const +{ + QProcess process; + QStringList options; + options << "-c"; + options << "cat /sys/class/dmi/id/product_family"; + process.start("/bin/bash", options); + process.waitForFinished(); + QString result = process.readAllStandardOutput(); + + QStringList list = result.split("\n"); + result = list.at(0); + qInfo() << __FILE__ << __LINE__ << "获取设备Family为:" << result; + return result; +} diff --git a/src/machinemodel.h b/src/machinemodel.h new file mode 100644 index 0000000..7b49b64 --- /dev/null +++ b/src/machinemodel.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#ifndef MACHINEMODEL_H +#define MACHINNEMODEL_H + +#include +#include +#include + +class MachineModel : public QObject +{ + Q_OBJECT +public: + QString getTheMachineType(); + static std::shared_ptr getMachineModelInstance(); + +private: + MachineModel(QObject *parent = nullptr); + MachineModel(const MachineModel &); + const MachineModel &operator =(const MachineModel &) = delete; + +private: + void initMachineType(); + const QString getSysVendor() const; + const QString getProductName() const; + const QString getProductFamily() const; + QString m_machineType; + static std::shared_ptr m_machineModel; + static std::mutex m_mutex; + +signals: + +}; + +#endif // MACHINEMODEL_H diff --git a/src/modebutton.cpp b/src/modebutton.cpp new file mode 100644 index 0000000..3b8bb26 --- /dev/null +++ b/src/modebutton.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2023 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 3, 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, see . + * +**/ +#include "modebutton.h" +#include +#include + +ModeButton::ModeButton(QWidget *parent) + : QPushButton(parent) +{ + +} + +void ModeButton::paintEvent(QPaintEvent *event) +{ + QStylePainter p(this); + QStyleOptionButton option; + initStyleOption(&option); + option.state = QStyle::State_Enabled; + p.drawControl(QStyle::CE_PushButton, option); +} + diff --git a/VirtualKeyboard/src/cursormonitor.h b/src/modebutton.h similarity index 66% rename from VirtualKeyboard/src/cursormonitor.h rename to src/modebutton.h index bacf21f..dc7944c 100644 --- a/VirtualKeyboard/src/cursormonitor.h +++ b/src/modebutton.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd. + * Copyright (C) 2023 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 @@ -15,21 +15,18 @@ * along with this program; if not, see . * **/ -#ifndef CURSORMONITOR_H -#define CURSORMONITOR_H +#ifndef MODEBUTTON_H +#define MODEBUTTON_H +#include -#include -#include - -class CursorMonitor : public QThread +class ModeButton : public QPushButton { Q_OBJECT public: - explicit CursorMonitor(QObject *parent = nullptr); - void run(); + ModeButton(QWidget *parent = nullptr); -Q_SIGNALS: - void cursorPosChanged(const QPoint& pos); +protected: + void paintEvent(QPaintEvent *event); }; -#endif // CURSORMONITOR_H +#endif // MODEBUTTON_H diff --git a/src/org.ukui.ScreenSaver.xml b/src/org.ukui.ScreenSaver.xml index 3e47687..e0d3a42 100644 --- a/src/org.ukui.ScreenSaver.xml +++ b/src/org.ukui.ScreenSaver.xml @@ -26,5 +26,9 @@ + + + + diff --git a/src/powermanager.cpp b/src/powermanager.cpp index faf67f8..5b9ba34 100644 --- a/src/powermanager.cpp +++ b/src/powermanager.cpp @@ -28,6 +28,7 @@ #include #include "powermanager.h" #include "lockchecker.h" +#include "klabel.h" const static QString login1Service = QStringLiteral("org.freedesktop.login1"); const static QString login1Path = QStringLiteral("/org/freedesktop/login1"); @@ -330,7 +331,7 @@ void PowerManager::initUI() QLabel *rebootLabel = new QLabel(this); rebootPB->setProperty("class", "PowerManagerPB"); rebootPB->setIcon(QIcon(QPixmap(":/image/assets/intel/reboot.png").scaled(40,40))); - rebootLabel->setText(tr("Reboot")); + rebootLabel->setText(tr("Restart")); rebootLabel->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); QVBoxLayout *rebootlayout = new QVBoxLayout(rebootWidget); @@ -662,13 +663,14 @@ void PowerManager::initUI() rbLabelWidget->setFixedSize(130, 130); rebootFace = new QPushButton(rbLabelWidget); rebootFace->setObjectName("rebootFace"); - QLabel *rebootLabel = new QLabel(this); + KLabel *rebootLabel = new KLabel(this); //rebootFace->setAlignment(Qt::AlignCenter); rebootFace->installEventFilter(this); rebootLabel->setAlignment(Qt::AlignCenter); rebootFace->setIcon(QIcon(":/image/assets/reboot.svg")); rebootFace->setIconSize(QSize(48, 48)); - rebootLabel->setText(tr("Reboot")); + rebootLabel->setFontSize(16); + rebootLabel->setText(tr("Restart")); rebootWidget->setFixedSize(ITEM_WIDTH,ITEM_HEIGHT); QVBoxLayout *rebootlayout = new QVBoxLayout(rebootWidget); rebootlayout->addWidget(rbLabelWidget); @@ -681,12 +683,14 @@ void PowerManager::initUI() shLabelWidget->setFixedSize(130, 130); shutdownFace = new QPushButton(shLabelWidget); shutdownFace->setObjectName("shutdownFace"); - QLabel *shutdownLabel = new QLabel(this); + KLabel *shutdownLabel = new KLabel(this); shutdownLabel->setAlignment(Qt::AlignCenter); //shutdownFace->setAlignment(Qt::AlignCenter); shutdownFace->installEventFilter(this); shutdownFace->setIcon(QIcon(":/image/assets/shutdown.svg")); shutdownFace->setIconSize(QSize(48, 48)); + //sysFont.setPointSize(20); + shutdownLabel->setFontSize(16); shutdownLabel->setText(tr("Shut Down")); shutdownWidget->setFixedSize(ITEM_WIDTH, ITEM_HEIGHT); QVBoxLayout *shutdownlayout = new QVBoxLayout(shutdownWidget); @@ -708,12 +712,13 @@ void PowerManager::initUI() hbLabelWidget->setFixedSize(130, 130); hibernateFace = new QPushButton(hbLabelWidget); hibernateFace->setObjectName("hibernateFace"); - QLabel *hibernateLabel = new QLabel(this); + KLabel *hibernateLabel = new KLabel(this); hibernateLabel->setAlignment(Qt::AlignCenter); //hibernateFace->setAlignment(Qt::AlignCenter); hibernateFace->installEventFilter(this); hibernateFace->setIcon(QIcon(":/image/assets/hibernate.svg")); hibernateFace->setIconSize(QSize(48, 48)); + hibernateLabel->setFontSize(16); hibernateLabel->setText(tr("Hibernate")); hibernateWidget->setFixedSize(ITEM_WIDTH,ITEM_HEIGHT); QVBoxLayout *hibernatelayout = new QVBoxLayout(hibernateWidget); @@ -736,12 +741,13 @@ void PowerManager::initUI() spLabelWidget->setFixedSize(130, 130); suspendFace = new QPushButton(spLabelWidget); suspendFace->setObjectName("suspendFace"); - QLabel *suspendLabel = new QLabel(this); + KLabel *suspendLabel = new KLabel(this); suspendLabel->setAlignment(Qt::AlignCenter); //suspendFace->setAlignment(Qt::AlignCenter); suspendFace->installEventFilter(this); suspendFace->setIcon(QIcon(":/image/assets/suspend.svg")); suspendFace->setIconSize(QSize(48, 48)); + suspendLabel->setFontSize(16); suspendLabel->setText(tr("Suspend")); suspendWidget->setFixedSize(ITEM_WIDTH,ITEM_HEIGHT); QVBoxLayout *suspendlayout = new QVBoxLayout(suspendWidget); diff --git a/src/rootWindowBackground.cpp b/src/rootWindowBackground.cpp new file mode 100644 index 0000000..eb3d534 --- /dev/null +++ b/src/rootWindowBackground.cpp @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2018 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 3, 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, see . + * +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rootWindowBackground.h" + +static const XID INVAL_ID = ~0UL; +Pixmap pix = INVAL_ID; +Display *dpy = NULL; +Window root = 0; +Screen *scn = NULL; + +struct RootWindowBGInfo { + bool isValid = false; + int nType; + int nColor; + QString strFileName; + int nOption; + QList listScreen; +}; + +static RootWindowBGInfo g_lastRootWndInfo; + +static QRect getSourceRect(const QRect &destination, const QRect &source) +{ + qreal screenScale = qreal(destination.width()) / qreal(destination.height()); + qreal width = source.width(); + qreal height = source.height(); + + if ((width / height) == screenScale) { + return source; + } + + bool isShortX = (width <= height); + if (isShortX) { + screenScale = qreal(destination.height()) / qreal(destination.width()); + } + + qreal shortEdge = isShortX ? width : height; + qreal longEdge = isShortX ? height : width; + + while (shortEdge > 1) { + qint32 temp = qFloor(shortEdge * screenScale); + if (temp <= longEdge) { + longEdge = temp; + break; + } + + qint32 spacing = qRound(shortEdge / 20); + if (spacing <= 0) { + spacing = 1; + } + shortEdge -= spacing; + } + + QSize sourceSize = source.size(); + if (shortEdge > 1 && longEdge > 1) { + sourceSize.setWidth(isShortX ? shortEdge : longEdge); + sourceSize.setHeight(isShortX ? longEdge : shortEdge); + } + + qint32 offsetX = 0; + qint32 offsetY = 0; + if (source.width() > sourceSize.width()) { + offsetX = (source.width() - sourceSize.width()) / 2; + } + + if (source.height() > sourceSize.height()) { + offsetY = (source.height() - sourceSize.height()) / 2; + } + + QPoint offsetPoint = source.topLeft(); + offsetPoint += QPoint(offsetX, offsetY); + + return QRect(offsetPoint, sourceSize); +} + +static QRect getDestRect(const QRect &destination, const QRect &source) +{ + qreal screenScale = qreal(destination.width()) / qreal(destination.height()); + qreal pixmapScale = qreal(source.width() / source.height()); + qreal width = source.width(); + qreal height = source.height(); + + if (pixmapScale == screenScale) { + return destination; + } + + qreal scaleWidth = destination.width() / width; + qreal scaleHeight = destination.height() / height; + qreal realPixmapWidth = 0; + qreal realPixmapHeight = 0; + + if(pixmapScale < screenScale){ + //图片比例小于屏幕比例时,按照图片和屏幕高度比进行缩放 + realPixmapWidth = width * scaleHeight; + realPixmapHeight = destination.height(); + }else{ + //图片比例大于屏幕比例时,按照图片与屏幕宽度比进行缩放 + realPixmapWidth = destination.width(); + realPixmapHeight = height * scaleWidth; + } + + QSize sourceSize = destination.size(); + qint32 offsetX = 0; + qint32 offsetY = 0; + if (destination.width() == realPixmapWidth) { + offsetY = (destination.height() - realPixmapHeight) / 2; + sourceSize.setHeight(realPixmapHeight); + } else if (destination.height() == realPixmapHeight) { + offsetX = (destination.width() - realPixmapWidth) / 2; + sourceSize.setWidth(realPixmapWidth); + } + + qDebug() << "=========getDestRect sourceSize:" << sourceSize; + QPoint offsetPoint = destination.topLeft(); + offsetPoint += QPoint(offsetX, offsetY); + + return QRect(offsetPoint, sourceSize); +} + +static QRect getSourceRect(const QRect &source, const QRect &screenGeometry, const QRect &screenVirtualGeometry) +{ + qreal pixWidth = source.width(); + qreal pixHeight = source.height(); + + QSize sourceSize = source.size(); + sourceSize.setWidth(screenGeometry.width() / screenVirtualGeometry.width() * pixWidth); + sourceSize.setHeight(screenGeometry.height() / screenVirtualGeometry.height() * pixHeight); + + qint32 offsetX = 0; + qint32 offsetY = 0; + if (screenGeometry.x() > 0) { + offsetX = (screenGeometry.x() / screenVirtualGeometry.width() * pixWidth); + } + + if (screenGeometry.y() > 0) { + offsetY = (screenGeometry.y() / screenVirtualGeometry.height() * pixHeight); + } + + QPoint offsetPoint = source.topLeft(); + offsetPoint += QPoint(offsetX, offsetY); + + return QRect(offsetPoint, sourceSize); +} + +void setRootWindowBackground(bool type,unsigned int color,char *filename, int nOption) +{ + Imlib_Image img; + + if (!dpy){ + dpy = XOpenDisplay(NULL); + if(!dpy) + return; + } + + int width = 0,height = 0; + + width = QApplication::desktop()->geometry().width()*qApp->devicePixelRatio(); + height = QApplication::desktop()->geometry().height()*qApp->devicePixelRatio(); + + if(!scn) + scn = DefaultScreenOfDisplay(dpy); + if(!root) + root = DefaultRootWindow(dpy); + + if (pix != INVAL_ID) { + XFreePixmap(dpy, pix); + pix = INVAL_ID; + } + pix = XCreatePixmap(dpy, root, width, height, + DefaultDepthOfScreen(scn)); + + imlib_context_set_display(dpy); + imlib_context_set_visual(DefaultVisualOfScreen(scn)); + imlib_context_set_colormap(DefaultColormapOfScreen(scn)); + imlib_context_set_drawable(pix); + + if(type == 0){ + img = imlib_load_image(filename); + if (!img) { + fprintf(stderr, "%s:Unable to load image\n", filename); + return ; + } + imlib_context_set_image(img); + + }else if(type == 1){ + img = imlib_create_image(width, height); + imlib_context_set_image(img); + int blue = color & 0xFF; + int green = color >> 8 & 0xFF; + int red = color >> 16 & 0xFF; + + qDebug()<<"red = "<= rect.width()) { + break; + } + } + drawedHeight += newSrcRect.height(); + if (drawedHeight >= rect.height()) { + break; + } + } + } + break; + case WNDBG_OPTION_ZOOM: // 适应 + { + rect = getDestRect(rect, newSrcRect); + qDebug()<<"Zoom:"<screens()){ + if (screen->name() == sscreen->name()) { + QRect srcRect = getSourceRect(newSrcRect, sscreen->geometry(), screen->virtualGeometry()); + imlib_render_image_part_on_drawable_at_size(srcRect.x(), srcRect.y(), + srcRect.width(), srcRect.height(), + rect.x(), rect.y(), + rect.width(),rect.height()); + break; + } + } + } + break; + default: + { + imlib_render_image_part_on_drawable_at_size(newSrcRect.x(), newSrcRect.y(), + newSrcRect.width(), newSrcRect.height(), + rect.x(), rect.y(), + rect.width(),rect.height()); + } + break; + } + } + + imlib_free_image(); +} + +void updateRootWindowBackground() +{ + // 对比新的屏幕尺寸是否有变化 + if (g_lastRootWndInfo.isValid) { + bool isSame = true; + QList listScreen; + for(QScreen *screen : QApplication::screens()){ + //在每个屏幕上绘制背景 + QRect rect = screen->geometry(); + rect.setX(rect.x()*screen->devicePixelRatio()); + rect.setY(rect.y()*screen->devicePixelRatio()); + rect.setWidth(rect.width()*screen->devicePixelRatio()); + rect.setHeight(rect.height()*screen->devicePixelRatio()); + listScreen.append(rect); + } + qDebug()<<"ScreenRects:"< g_lastRootWndInfo.listScreen.size()) { + isSame = false; + } else { + for (int n = 0; n < listScreen.size(); n++) { + if (n < g_lastRootWndInfo.listScreen.size()) { + if (g_lastRootWndInfo.listScreen[n] != listScreen[n]) { + isSame = false; + break; + } + } + } + } + if (!isSame) { + setRootWindowBackground(g_lastRootWndInfo.nType, g_lastRootWndInfo.nColor, + g_lastRootWndInfo.strFileName.toLatin1().data(), g_lastRootWndInfo.nOption); + } + } +} + +void drawBackground(bool isDraw) +{ + if (!dpy) { + return ; + } + if (isDraw) { + if (pix != INVAL_ID) + XSetWindowBackgroundPixmap(dpy, root, pix); + XClearWindow(dpy, root); + } + + while (XPending(dpy)) { + XEvent ev; + XNextEvent(dpy, &ev); + } + if (pix != INVAL_ID) { + XFreePixmap(dpy, pix); + pix = INVAL_ID; + } + XCloseDisplay(dpy); + dpy = NULL; +} + + diff --git a/src/rootWindowBackground.h b/src/rootWindowBackground.h new file mode 100644 index 0000000..5cd0860 --- /dev/null +++ b/src/rootWindowBackground.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 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 3, 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, see . + * +**/ + +typedef enum WNDBG_OPTION_e{ + WNDBG_OPTION_SCALED, // 填充 + WNDBG_OPTION_STRETCHED, // 拉伸 + WNDBG_OPTION_CENTERED, // 居中 + WNDBG_OPTION_WALLPAPER, // 平铺 + WNDBG_OPTION_ZOOM, // 适应 + WNDBG_OPTION_SPANNED // 跨区 +}WNDBG_OPTION; + +void setRootWindowBackground(bool type,unsigned int color,char *filename, int nOption = 0); +void updateRootWindowBackground(); +void drawBackground(bool isDraw); diff --git a/src/sessionwatcher.cpp b/src/sessionwatcher.cpp index 1f4d7a5..be05ab5 100644 --- a/src/sessionwatcher.cpp +++ b/src/sessionwatcher.cpp @@ -21,6 +21,7 @@ #include #include #include "types.h" +#include "glibinterface.h" #define GSETTINGS_SCHEMA_SCREENSAVER "org.ukui.screensaver" #define KEY_IDLE_DELAY "idleDelay" @@ -28,6 +29,8 @@ #define KEY_IDLE_ACTIVATION_ENABLED "idleActivationEnabled" #define KEY_IDLE_LOCK_ENABLED "idleLockEnabled" #define TIME_TYPE_SCHEMA "org.ukui.control-center.panel.plugins" +#define KEY_LOCK_TIMEOUT "lockTimeout" +#define STYLE_TYPE_SCHEMA "org.ukui.style" #define GSETTINGS_SCHEMA_SCREENSAVER_DEFAULT "org.ukui.screensaver-default" #define KEY_SHOW_REST_TIME "showRestTime" // old @@ -39,11 +42,14 @@ #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_DISPLAY_PATH "/org/freedesktop/UPower/devices/DisplayDevice" +#define G_FONT_SIZE (11.0) SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) { sessionPath = qgetenv("XDG_SESSION_PATH"); + defaultFontSize = getDefaultFontSize(); + QDBusInterface *interface = new QDBusInterface( SM_DBUS_SERVICE, SM_DBUS_PATH, @@ -83,6 +89,10 @@ SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) } idleDelay = m_ssSettings->get("idle-delay").toInt(); idleLock = m_ssSettings->get("idle-lock").toInt(); + + if (keysScreenSaver.contains(KEY_LOCK_TIMEOUT)) { + m_nLockTimeout = m_ssSettings->get("lock-timeout").toInt(); + } } if(QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA_SCREENSAVER_DEFAULT)){ @@ -142,14 +152,23 @@ SessionWatcher::SessionWatcher(QObject *parent) : QObject(parent) file.setPermissions(QFile::WriteUser | QFile::ReadUser | QFile::WriteOther | QFile::ReadOther); } configSettings = new QSettings(configPath, QSettings::IniFormat, this); - if(QGSettings::isSchemaInstalled(TIME_TYPE_SCHEMA)) + if (QGSettings::isSchemaInstalled(TIME_TYPE_SCHEMA)) { timegsettings = new QGSettings(TIME_TYPE_SCHEMA,"",this); - int timeType = timegsettings->get("hoursystem").toInt(); - setValue("timeType",timeType); - QString dateType = timegsettings->get("date").toString(); - setValue("dateType",dateType); - connect(timegsettings, &QGSettings::changed, - this, &SessionWatcher::onConfigurationTimeTpChanged); + int timeType = timegsettings->get("hoursystem").toInt(); + setValue("timeType",timeType); + QString dateType = timegsettings->get("date").toString(); + setValue("dateType",dateType); + connect(timegsettings, &QGSettings::changed, + this, &SessionWatcher::onConfigurationTimeTpChanged); + } + + if (QGSettings::isSchemaInstalled(STYLE_TYPE_SCHEMA)) { + stylesettings = new QGSettings(STYLE_TYPE_SCHEMA,"",this); + double fontSize = stylesettings->get("systemFontSize").toDouble(); + setValue("fontSize",fontSize - defaultFontSize); + connect(stylesettings, &QGSettings::changed, + this, &SessionWatcher::onConfigurationTimeTpChanged); + } // 监听合盖信号 QDBusConnection::systemBus().connect( @@ -162,20 +181,22 @@ void SessionWatcher::onSSConfigChanged(QString strKey) idleDelay = m_ssSettings->get("idle-delay").toInt(); } else if (strKey == KEY_IDLE_LOCK){ idleLock = m_ssSettings->get("idle-lock").toInt(); + } else if (strKey == KEY_LOCK_TIMEOUT) { + m_nLockTimeout = m_ssSettings->get("lock-timeout").toInt(); } } void SessionWatcher::onConfigurationTimeTpChanged(QString key) { - if(key == "hoursystem"){ + if (key == "hoursystem") { int timeType = timegsettings->get("hoursystem").toInt(); setValue("timeType",timeType); - } - if(key == "date"){ - qDebug()<<"jinlaile~~~~~~~~~~~~~~key="<get("date").toString(); - qDebug()<<"lsadjfldsa"<get("systemFontSize").toDouble() - defaultFontSize; + setValue("fontSize", fontSize); } } @@ -305,6 +326,11 @@ int SessionWatcher::idledelay() return idleDelay; } +int SessionWatcher::locktimeout() +{ + return m_nLockTimeout; +} + bool SessionWatcher::isLidCloseWithBlank() { if (!m_pmSettings) diff --git a/src/sessionwatcher.h b/src/sessionwatcher.h index 0d5419d..2c4a56d 100644 --- a/src/sessionwatcher.h +++ b/src/sessionwatcher.h @@ -38,6 +38,7 @@ public: int closeActivationDelay(); int idledelay(); bool isLidCloseWithBlank(); // 合盖关屏 + int locktimeout(); Q_SIGNALS: void sessionIdle(); @@ -59,11 +60,14 @@ private: QGSettings *m_ssSettings = nullptr; QGSettings *m_pmSettings = nullptr; QGSettings *m_sdSettings = nullptr; + QGSettings *stylesettings = nullptr; int idleDelay = -1; int idleLock = -1; + int m_nLockTimeout = -1; QTimer *m_timer = nullptr; QTimer *m_timer2 = nullptr; bool m_lidState = false; + double defaultFontSize; }; #endif // SESSIONWATCHER_H diff --git a/src/surewindow.cpp b/src/surewindow.cpp index d8f07ea..ee7e4eb 100644 --- a/src/surewindow.cpp +++ b/src/surewindow.cpp @@ -17,14 +17,19 @@ **/ #include "surewindow.h" #include "ui_surewindow.h" +#include "configuration.h" #include #include + SureWindow::SureWindow(QWidget *parent) : QWidget(parent), - ui(new Ui::SureWindow) + ui(new Ui::SureWindow), + configuration(Configuration::instance()) { ui->setupUi(this); - ui->tipLabel->setStyleSheet("color:white;font:14pt;"); + curFontSize = configuration->getFontSize(); + m_ptToPx = configuration->getPtToPx(); + ui->tipLabel->setFontSize(14 + curFontSize); //ui->tipLabel->setWordWrap(true); connect(ui->cancelBtn, &QPushButton::clicked, this, [&]() { emit cantelButtonclicked(); }); connect(ui->confirmBtn, &QPushButton::clicked, this, [&]() { emit confirmButtonclicked(); }); @@ -37,13 +42,15 @@ SureWindow::~SureWindow() void SureWindow::setTips(const QString tips) { - ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" - "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" - "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); - - ui->confirmBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;}" + ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;color: white;}" "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + ui->confirmBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;color: white;}" + "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" + "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + sysFont.setPointSize((16 + curFontSize) *m_ptToPx); + ui->confirmBtn->setFont(sysFont); + ui->cancelBtn->setFont(sysFont); ui->confirmBtn->show(); ui->tipLabel->show(); ui->listView->hide(); @@ -87,7 +94,9 @@ void SureWindow::setWarning(QVector &list, int type) } ui->listView->verticalScrollMode(); - ui->listView->setStyleSheet("font:10pt;color:white; background-color: rgba(255,255,255,30%); border-radius: 12px;"); + ui->listView->setStyleSheet("color:white; background-color: rgba(255,255,255,30%); border-radius: 12px;"); + sysFont.setPointSize((10 + curFontSize) *m_ptToPx); + ui->listView->setFont(sysFont); ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->listView->setIconSize(QSize(32,32)); ui->listView->setModel(model); @@ -96,8 +105,9 @@ void SureWindow::setWarning(QVector &list, int type) ui->cancelBtn->setFixedSize(120, 48); ui->confirmBtn->hide(); - ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 24px;}" - "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 24px;}" - "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 24px;}"); - + ui->cancelBtn->setStyleSheet("QPushButton{background: rgba(255, 255, 255, 0.2);border-radius: 8px;color: white;}" + "QPushButton:hover{background: rgba(255, 255, 255, 0.4);border-radius: 8px;}" + "QPushButton:pressed {background: rgba(255, 255, 255, 0.3);border-radius: 8px;}"); + sysFont.setPointSize((16 + curFontSize) *m_ptToPx); + ui->cancelBtn->setFont(sysFont); } diff --git a/src/surewindow.h b/src/surewindow.h index 62bc402..7d49b31 100644 --- a/src/surewindow.h +++ b/src/surewindow.h @@ -25,6 +25,8 @@ namespace Ui { class SureWindow; } +class Configuration; + class SureWindow : public QWidget { Q_OBJECT @@ -42,6 +44,12 @@ private: Q_SIGNALS: void cantelButtonclicked(); void confirmButtonclicked(); + +private: + Configuration *configuration; + double curFontSize = 0; + double m_ptToPx = 1.0; + QFont sysFont; }; #endif // SUREWINDOW_H diff --git a/src/surewindow.ui b/src/surewindow.ui index 278cab5..e2aea7a 100644 --- a/src/surewindow.ui +++ b/src/surewindow.ui @@ -46,7 +46,7 @@
- + Noto Sans CJK SC @@ -207,6 +207,13 @@
+ + + KLabel + QLabel +
klabel.h
+
+
diff --git a/src/tabletlockwidget.cpp b/src/tabletlockwidget.cpp index ff972bc..9a18136 100644 --- a/src/tabletlockwidget.cpp +++ b/src/tabletlockwidget.cpp @@ -35,7 +35,7 @@ #include "tabletlockwidget.h" #include "authdialog.h" -#include "virtualkeyboard.h" +#include "virtualkeyboardwidget.h" #include "users.h" #include "displaymanager.h" #include "weathermanager.h" @@ -62,7 +62,7 @@ TabletLockWidget::TabletLockWidget(QWidget *parent) : m_pb_powerManager(new QPushButton(this)), m_pb_networkManager(new QPushButton(this)), m_vKeyboardPB(new QPushButton(this)), - m_vKeyboard(new VirtualKeyboard(this)), + m_vKeyboard(new VirtualKeyboardWidget(this)), m_cancelOrBack(new QPushButton(this)), m_pb_skip(new QPushButton(this)), m_verificationWidget(new VerificationWidget(this)), @@ -166,8 +166,8 @@ void TabletLockWidget::initUI() //虚拟键盘 m_vKeyboard->hide(); - connect(m_vKeyboard, &VirtualKeyboard::aboutToClose, - m_vKeyboard, &VirtualKeyboard::hide); + connect(m_vKeyboard, &VirtualKeyboardWidget::aboutToClose, + m_vKeyboard, &VirtualKeyboardWidget::hide); m_vKeyboardPB->setIcon(QIcon(":/image/assets/intel/keyboard.png")); m_vKeyboardPB->setFixedSize(48,48); @@ -234,9 +234,9 @@ void TabletLockWidget::initUI() //Todo 1、锁屏 -》息屏 m_digitalAuthDialog->reset(); Q_EMIT blackSaver(); -#ifdef USE_INTEL +#ifdef USE_INTEL powermanager->hibernate(); -#endif +#endif } else { m_digitalAuthDialog->reset(); m_cancelOrBack->setIcon(QIcon(":/image/assets/intel/cancel.png")); @@ -348,7 +348,7 @@ void TabletLockWidget::initConnect() updateNetIcon(m_kylinNM->getConnectStatus()); }); - connect(m_vKeyboard, &VirtualKeyboard::aboutToClose, m_vKeyboard, [=](){ + connect(m_vKeyboard, &VirtualKeyboardWidget::aboutToClose, m_vKeyboard, [=](){ if(m_vKeyboard->isHidden() && m_kylinNM->isVisible()) { m_kylinNM->setGeometry(this->width() - m_kylinNM->width() - 20, this->height() - m_kylinNM->height() - 100, diff --git a/src/tabletlockwidget.h b/src/tabletlockwidget.h index dba18d7..8acf3b7 100644 --- a/src/tabletlockwidget.h +++ b/src/tabletlockwidget.h @@ -30,7 +30,7 @@ #include #include -class VirtualKeyboard; +class VirtualKeyboardWidget; class PowerManager; class AuthDialog; class Users; @@ -104,7 +104,7 @@ protected: private: AuthDialog *authDialog; - VirtualKeyboard *m_vKeyboard; + VirtualKeyboardWidget *m_vKeyboard; PowerManager *powermanager; QTimer *timer; QMenu *usersMenu; diff --git a/src/types.h b/src/types.h index 76b1fd1..7153a28 100644 --- a/src/types.h +++ b/src/types.h @@ -60,6 +60,10 @@ enum ScreenStatus #define SSWND_DBUS_PATH "/" #define SSWND_DBUS_INTERFACE "org.ukui.ScreenSaverWnd" +#define DESKTOP_DBUS_SERVICE "org.ukui.peony" +#define DESKTOP_DBUS_PATH "/org/ukui/peony" +#define DESKTOP_DBUS_INTERFACE "org.ukui.peony" + #define BIO_ERROR -1 #define BIO_FAILED 0 #define BIO_SUCCESS 1 diff --git a/VirtualKeyboard/src/vkstackedwidget.h b/src/ukss_interface.cpp similarity index 60% rename from VirtualKeyboard/src/vkstackedwidget.h rename to src/ukss_interface.cpp index fb737ff..11ea9bd 100644 --- a/VirtualKeyboard/src/vkstackedwidget.h +++ b/src/ukss_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Tianjin KYLIN Information Technology Co., Ltd. + * Copyright (C) 2023 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 @@ -15,21 +15,18 @@ * along with this program; if not, see . * **/ -#ifndef VKSTACKEDWIDGET_H -#define VKSTACKEDWIDGET_H -#include +#include "ukss_interface.h" +#include +#include -class VKStackedWidget : public QStackedWidget +int LockByBlank(QString strReason) { - Q_OBJECT -public: - explicit VKStackedWidget(QWidget *parent = nullptr); - virtual ~VKStackedWidget(); - -protected: - QSize sizeHint() const override; - QSize minimumSizeHint() const override; -}; - -#endif // VKSTACKEDWIDGET_H + QProcess procCmd; + QString strCmd = QString("ukui-screensaver-command -b %1").arg(strReason); + qDebug()<<"LockByBlank,CMD:"<. * **/ -#include "vkstackedwidget.h" +#ifndef __UKSS_INTERFACE_H__ +#define __UKSS_INTERFACE_H__ -VKStackedWidget::VKStackedWidget(QWidget *parent/* = nullptr*/) - : QStackedWidget(parent) -{ +#include -} +#if defined(UKSSSO_LIBRARY) +# define UKSSSO_EXPORT Q_DECL_EXPORT +#else +# define UKSSSO_EXPORT Q_DECL_IMPORT +#endif -VKStackedWidget::~VKStackedWidget() -{ +extern "C" UKSSSO_EXPORT int LockByBlank(QString strReason); -} - -QSize VKStackedWidget::sizeHint() const -{ - return currentWidget()->sizeHint(); -} - -QSize VKStackedWidget::minimumSizeHint() const -{ - return currentWidget()->minimumSizeHint(); -} +#endif // __UKSS_INTERFACE_H__ diff --git a/src/ukui-screensaver-backend.cpp b/src/ukui-screensaver-backend.cpp index 31783b0..87ca85d 100644 --- a/src/ukui-screensaver-backend.cpp +++ b/src/ukui-screensaver-backend.cpp @@ -63,9 +63,14 @@ int main(int argc, char *argv[]) ScreenSaverAdaptor adaptor(interface); QDBusConnection service = QDBusConnection::sessionBus(); - if(!service.registerService(SS_DBUS_SERVICE)) { - qDebug() << service.lastError().message(); - exit(EXIT_FAILURE); + QString sessionDbus = SS_DBUS_SERVICE; + if(!service.registerService(sessionDbus)) { + QString displayNum = QString(qgetenv("DISPLAY")).replace(":", "").replace(".", "_");; + sessionDbus = QString("%1%2").arg(QString(SS_DBUS_SERVICE)).arg(displayNum); + if(!service.registerService(sessionDbus)) { + qDebug() << service.lastError().message(); + exit(EXIT_FAILURE); + } } if(!service.registerObject(SS_DBUS_PATH, SS_DBUS_SERVICE, &adaptor, QDBusConnection::ExportAllSlots | diff --git a/src/ukui-screensaver-command.cpp b/src/ukui-screensaver-command.cpp index 1ce2d54..c18808c 100644 --- a/src/ukui-screensaver-command.cpp +++ b/src/ukui-screensaver-command.cpp @@ -24,6 +24,7 @@ #include #include "types.h" #include +#include #define WORKING_DIRECTORY "/usr/share/ukui-screensaver" @@ -53,20 +54,31 @@ int main(int argc, char **argv) QCoreApplication::translate("main", "unlock the screen saver")); QCommandLineOption screensaverOption({"s", QStringLiteral("screensaver")}, QCoreApplication::translate("main", "show the screensaver")); + QCommandLineOption blankOption({"b", QStringLiteral("blank")}, + QCoreApplication::translate("main", "show blank and delay to lock,param:idle/lid/lowpower"), "lid"); parser.addOption(lockOption); parser.addOption(queryOption); parser.addOption(unlockOption); parser.addOption(screensaverOption); + parser.addOption(blankOption); parser.process(a); - if(!parser.isSet(lockOption) && !parser.isSet(queryOption) && !parser.isSet(unlockOption) && !parser.isSet(screensaverOption)) + if(!parser.isSet(lockOption) && !parser.isSet(queryOption) && !parser.isSet(unlockOption) + && !parser.isSet(screensaverOption) && !parser.isSet(blankOption)) return -1; - QDBusInterface *interface = new QDBusInterface(SS_DBUS_SERVICE, + QString displayNum = QString(qgetenv("DISPLAY")).replace(":", "").replace(".", "_"); + QString sessionDbus = QString("%1%2").arg(QString(SS_DBUS_SERVICE)).arg(displayNum); + QDBusInterface *interface = new QDBusInterface(sessionDbus, SS_DBUS_PATH, SS_DBUS_INTERFACE); - + if (!interface->isValid()) { + delete interface; + interface = new QDBusInterface(SS_DBUS_SERVICE, + SS_DBUS_PATH, + SS_DBUS_INTERFACE); + } QDBusReply stateReply = interface->call("GetLockState"); if(!stateReply.isValid()){ qWarning()<< "Get state error:" << stateReply.error(); @@ -90,6 +102,36 @@ int main(int argc, char **argv) QDBusMessage msg = interface->call("ShowScreensaver"); if(msg.type() == QDBusMessage::ErrorMessage) qDebug() << msg.errorMessage(); + } else if (parser.isSet(blankOption) && !stateReply) { + int nLockType = 0; + qDebug()<<"Param:"< bLockSuccess = interface->call("LockByBlank", nLockType); + if(bLockSuccess.isValid() && bLockSuccess.value()) { + bool isLocked = false; + for (int n = 0; n < 20; n++) { + QDBusReply reply = interface->call("GetLockState"); + if (reply.isValid()) { + isLocked = reply.value(); + } + if (isLocked) { + qDebug()<<"LockState:"<onBlankScreensaver(); + int nDelay = 0; + bool isHasLock = true; + if (parser.isSet(delayOption)){ + int nDelayValue = parser.value(delayOption).toInt(); + if (nDelayValue > 0) { + nDelay = nDelayValue; + } + } + if (parser.isSet(hasLockOption)){ + int nHasLockValue = parser.value(hasLockOption).toInt(); + if (nHasLockValue == 0) { + isHasLock = false; + } + } + qDebug()<<"-------------:"<onBlankScreensaver(nDelay, isHasLock); } #ifndef USE_INTEL diff --git a/src/users.cpp b/src/users.cpp index 03c87e6..1e4a305 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -40,8 +40,15 @@ Users::Users(QObject *parent) : QObject(parent) if (Utils::isCommunity()) { defaultIcon = ":/image/assets/01-default-community.png"; } else { - defaultIcon = ":/image/assets/01-default-commercial.png"; + //优先读取控制面板的默认头像文件,保持登录锁屏默认头像和控制面板一致 + QFile faceFile("/usr/share/ukui/faces/default.png"); + if(faceFile.exists()){ + defaultIcon = "/usr/share/ukui/faces/default.png"; + }else{ + defaultIcon = ":/image/assets/01-default-commercial.png"; + } } + loadUsers(); }