Skip to content

Commit

Permalink
add hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
朱子楚\zhuzi committed May 15, 2024
1 parent 876b230 commit 354f7f2
Show file tree
Hide file tree
Showing 26 changed files with 2,083 additions and 114 deletions.
32 changes: 32 additions & 0 deletions THIRD_PARTY_COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,38 @@ providing powerful tools and support for this project.
For more information about the Qt project,
please visit the official Qt website (https://www.qt.io/).


************************************************************************************
QHotkey

Copyright (c) 2016, Felix Barz
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of QHotkey nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

************************************************************************************
framelesshelper

Expand Down
1 change: 1 addition & 0 deletions example/example.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<file>qml/window/FluentInitializrWindow.qml</file>
<file>qml/page/T_OpenGL.qml</file>
<file>qml/page/T_Icons.qml</file>
<file>qml/window/HotkeyWindow.qml</file>
</qresource>
<qresource prefix="/"/>
</RCC>
56 changes: 56 additions & 0 deletions example/example_en_US.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>App</name>
<message>
<location filename="qml/App.qml" line="61"/>
<source>Quit</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="68"/>
<source>Test1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="75"/>
<source>Test2</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="82"/>
<source>Test3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="89"/>
<source>Test4</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="96"/>
<source>Test5</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="103"/>
<source>Test6</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="110"/>
<source>Test7</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="qml/App.qml" line="117"/>
<source>Test8</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CodeExpander</name>
<message>
Expand Down Expand Up @@ -71,6 +119,14 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>HotkeyWindow</name>
<message>
<location filename="qml/window/HotkeyWindow.qml" line="11"/>
<source>Hotkey</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>HotloadWindow</name>
<message>
Expand Down
60 changes: 60 additions & 0 deletions example/example_zh_CN.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>App</name>
<message>
<location filename="qml/App.qml" line="61"/>
<source>Quit</source>
<translation type="unfinished">退出</translation>
</message>
<message>
<location filename="qml/App.qml" line="68"/>
<source>Test1</source>
<translation type="unfinished">测试1</translation>
</message>
<message>
<location filename="qml/App.qml" line="75"/>
<source>Test2</source>
<translation type="unfinished">测试2</translation>
</message>
<message>
<location filename="qml/App.qml" line="82"/>
<source>Test3</source>
<translation type="unfinished">测试3</translation>
</message>
<message>
<location filename="qml/App.qml" line="89"/>
<source>Test4</source>
<translation type="unfinished">测试4</translation>
</message>
<message>
<location filename="qml/App.qml" line="96"/>
<source>Test5</source>
<translation type="unfinished">测试5</translation>
</message>
<message>
<location filename="qml/App.qml" line="103"/>
<source>Test6</source>
<translation type="unfinished">测试6</translation>
</message>
<message>
<location filename="qml/App.qml" line="110"/>
<source>Test7</source>
<translation type="unfinished">测试7</translation>
</message>
<message>
<location filename="qml/App.qml" line="117"/>
<source>Test8</source>
<translation type="unfinished">测试8</translation>
</message>
</context>
<context>
<name>CodeExpander</name>
<message>
Expand Down Expand Up @@ -71,6 +119,14 @@
<translation type="unfinished">创建</translation>
</message>
</context>
<context>
<name>HotkeyWindow</name>
<message>
<location filename="qml/window/HotkeyWindow.qml" line="11"/>
<source>Hotkey</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>HotloadWindow</name>
<message>
Expand Down Expand Up @@ -2043,6 +2099,10 @@ Some contents...</source>
<source>ShortcutPicker</source>
<translation type="unfinished">快捷键选择器</translation>
</message>
<message>
<source>Quit</source>
<translation type="obsolete">退出</translation>
</message>
<message>
<source>Activate the Shortcut</source>
<translation type="obsolete">激活快捷键</translation>
Expand Down
72 changes: 71 additions & 1 deletion example/qml/App.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ FluLauncher {
"/singleTaskWindow":"qrc:/example/qml/window/SingleTaskWindow.qml",
"/standardWindow":"qrc:/example/qml/window/StandardWindow.qml",
"/singleInstanceWindow":"qrc:/example/qml/window/SingleInstanceWindow.qml",
"/pageWindow":"qrc:/example/qml/window/PageWindow.qml"
"/pageWindow":"qrc:/example/qml/window/PageWindow.qml",
"/hotkey":"qrc:/example/qml/window/HotkeyWindow.qml"
}
var args = Qt.application.arguments
if(args.length>=2 && args[1].startsWith("-crashed=")){
Expand All @@ -52,4 +53,73 @@ FluLauncher {
FluRouter.navigate("/")
}
}

property alias hotkeys: object_hotkey
FluObject{
id: object_hotkey
FluHotkey{
name: qsTr("Quit")
sequence: "Ctrl+Alt+Q"
onActivated: {
FluRouter.exit()
}
}
FluHotkey{
name: qsTr("Test1")
sequence: "Alt+A"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test2")
sequence: "Alt+B"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test3")
sequence: "Alt+C"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test4")
sequence: "Alt+D"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test5")
sequence: "Alt+E"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test6")
sequence: "Alt+F"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test7")
sequence: "Alt+G"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
FluHotkey{
name: qsTr("Test8")
sequence: "Alt+H"
onActivated: {
FluRouter.navigate("/hotkey",{sequence:sequence})
}
}
}

}
20 changes: 17 additions & 3 deletions example/qml/page/T_ShortcutPicker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@ FluScrollablePage{

FluFrame{
Layout.fillWidth: true
Layout.preferredHeight: 100
padding: 10
FluShortcutPicker{
Layout.preferredHeight: childrenRect.height
ColumnLayout{
anchors.verticalCenter: parent.verticalCenter
Item{
Layout.preferredHeight: 15
}
Repeater{
model: FluApp.launcher.hotkeys.children
delegate: FluShortcutPicker{
text: model.name
syncHotkey: FluApp.launcher.hotkeys.children[index]
Layout.leftMargin: 15
}
}
Item{
Layout.preferredHeight: 15
}
}
}

CodeExpander{
Layout.fillWidth: true
Layout.topMargin: -6
Expand Down
26 changes: 26 additions & 0 deletions example/qml/window/HotkeyWindow.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import FluentUI 1.0
import "../component"

FluWindow {

id: window
property string sequence: ""
title: qsTr("Hotkey")
width: 250
height: 250
fixSize: true
launchMode: FluWindowType.SingleInstance
onInitArgument:
(argument)=>{
window.sequence = argument.sequence
}
FluText{
anchors.centerIn: parent
color: FluTheme.primaryColor
font: FluTextStyle.Title
text: window.sequence
}
}
19 changes: 19 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,28 @@ file(COPY ${QM_FILE_PATHS} DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/Qt${QT_VERSI
file(GLOB_RECURSE CPP_FILES *.cpp *.h *.cxx)
foreach (filepath ${CPP_FILES})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
message(${filename})
list(APPEND sources_files ${filename})
endforeach (filepath)

list(REMOVE_ITEM sources_files qhotkey/qhotkey_mac.cpp qhotkey/qhotkey_win.cpp qhotkey/qhotkey_x11.cpp)

if (WIN32)
list(APPEND sources_files qhotkey/qhotkey_win.cpp)
elseif (APPLE)
list(APPEND sources_files qhotkey/qhotkey_mac.cpp)
elseif (UNIX)
list(APPEND sources_files qhotkey/qhotkey_x11.cpp)
endif()

if (WIN32)
set(FLUENTUI_VERSION_RC_PATH ${CMAKE_CURRENT_BINARY_DIR}/version_${PROJECT_NAME}.rc)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/.cmake/version_dll.rc.in
${FLUENTUI_VERSION_RC_PATH}
)
endif ()

if (QT_VERSION VERSION_GREATER_EQUAL "6.2")
#删除fluentuiplugin.cpp与fluentuiplugin.h,这些只要Qt5使用,Qt6不需要
list(REMOVE_ITEM sources_files fluentuiplugin.h fluentuiplugin.cpp)
Expand Down
5 changes: 3 additions & 2 deletions src/FluApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ FluApp::FluApp(QObject *parent) : QObject{parent} {

FluApp::~FluApp() = default;

void FluApp::init(QObject *target, QLocale locale) {
void FluApp::init(QObject *launcher, QLocale locale) {
this->launcher(launcher);
_locale = std::move(locale);
_engine = qmlEngine(target);
_engine = qmlEngine(launcher);
_translator = new QTranslator(this);
QGuiApplication::installTranslator(_translator);
const QStringList uiLanguages = _locale.uiLanguages();
Expand Down
3 changes: 2 additions & 1 deletion src/FluApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Q_OBJECT
Q_PROPERTY_AUTO(bool, useSystemAppBar)
Q_PROPERTY_AUTO(QString, windowIcon)
Q_PROPERTY_AUTO(QLocale, locale)
Q_PROPERTY_AUTO_P(QObject*,launcher)
QML_NAMED_ELEMENT(FluApp)
QML_SINGLETON

Expand All @@ -34,7 +35,7 @@ SINGLETON(FluApp)

static FluApp *create(QQmlEngine *, QJSEngine *) { return getInstance(); }

Q_INVOKABLE void init(QObject *target, QLocale locale = QLocale::system());
Q_INVOKABLE void init(QObject *launcher, QLocale locale = QLocale::system());

[[maybe_unused]] Q_INVOKABLE static QJsonArray iconData(const QString &keyword = "");

Expand Down
Loading

0 comments on commit 354f7f2

Please sign in to comment.