Skip to content

Commit

Permalink
feat: pullin Kirigami primitives module, add BusyIndicator.qml
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Nov 1, 2024
1 parent 205f8bc commit 4e67da8
Show file tree
Hide file tree
Showing 52 changed files with 5,070 additions and 44 deletions.
6 changes: 6 additions & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ static const QLatin1String liveCheckFile("live.check");
PixmapCache* PixmapCache::s_instance = nullptr;

// PREVENT LINKER FORM OPTIMIZING OUT QML MODULES
void qml_register_types_org_prismlauncher_platform();
void qml_register_types_org_prismlauncher_pqcstyle();
void qml_register_types_org_prismlauncher_primitives();
void qml_register_types_org_prismlauncher_desktop();
void qml_register_types_org_prismlauncher_data();
void qml_register_types_org_prismlauncher_ui();
Expand All @@ -187,8 +189,12 @@ void qml_register_types_org_prismlauncher_ui();
// TO PREVENT LINKER FORM OPTIMISING THEM OUT
void preventQmlLinkerOpt()
{
volatile auto org_prismlauncher_platform_registration = &qml_register_types_org_prismlauncher_platform;
Q_UNUSED(org_prismlauncher_platform_registration);
volatile auto org_prismlauncher_pqcstyle_registration = &qml_register_types_org_prismlauncher_pqcstyle;
Q_UNUSED(org_prismlauncher_pqcstyle_registration);
volatile auto org_prismlauncher_primitives_registration = &qml_register_types_org_prismlauncher_primitives;
Q_UNUSED(org_prismlauncher_primitives_registration);
volatile auto org_prismlauncher_desktop_registration = &qml_register_types_org_prismlauncher_desktop;
Q_UNUSED(org_prismlauncher_desktop_registration);
volatile auto org_prismlauncher_data_registration = &qml_register_types_org_prismlauncher_data;
Expand Down
4 changes: 4 additions & 0 deletions launcher/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@

qt_policy(SET QTP0001 NEW)

add_subdirectory(org/prismlauncher/platform)
add_subdirectory(org/prismlauncher/pqcstyle)
add_subdirectory(org/prismlauncher/primitives)
add_subdirectory(org/prismlauncher/desktop)
add_subdirectory(org/prismlauncher/data)
add_subdirectory(org/prismlauncher/ui)

target_link_libraries(Launcher_logic
PUBLIC
org_prismlauncher_platform
org_prismlauncher_pqcstyle
org_prismlauncher_primitives
org_prismlauncher_desktop
org_prismlauncher_data
org_prismlauncher_ui
Expand Down
129 changes: 129 additions & 0 deletions launcher/qml/org/prismlauncher/desktop/BusyIndicator.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: 2024 Rachel Powers <[email protected]>
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2024 Rachel Powers <[email protected]>
*
* 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, version 3.
*
* 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 <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright ©: 2018 Oleg Chernovskiy <[email protected]>
* Copyright ©: 2022 ivan tkachenko <[email protected]>
*
* Licensed under LGPL-3.0-only OR GPL-2.0-or-later
*
* https://community.kde.org/Policies/Licensing_Policy
*/
import QtQuick
import QtQuick.Templates as T
import org.prismlauncher.pqcstyle as PrismStyle
import org.prismlauncher.platform as Platform
import org.prismlauncher.primitives as Primitives

T.BusyIndicator {
id: control

implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding)
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding)

// BusyIndicator doesn't need padding since it has no background.
// A Control containing a BusyIndicator can have padding instead
// (e.g., a ToolBar, a Page or maybe a widget in a Plasma panel).
padding: 0

hoverEnabled: false

contentItem: Item {
/* Binding on `visible` implicitly takes care of `control.visible`,
* `control.running` and `opacity > 0` at once.
* Also, don't animate at all if the user has disabled animations,
* and don't animate when window is hidden (which somehow does not
* affect items' visibility).
*/
readonly property bool animationShouldBeRunning:
visible
&& Window.visibility !== Window.Hidden
&& PrismStyle.Units.longDuration > 1

/* implicitWidth and implicitHeight won't work unless they come
* from a child of the contentItem. No idea why.
*/
implicitWidth: Platform.Units.gridUnit * 2
implicitHeight: Platform.Units.gridUnit * 2

// We can't bind directly to opacity, as Animator won't update its value immediately.
visible: control.running || opacityAnimator.running
opacity: control.running ? 1 : 0
Behavior on opacity {
enabled: Platform.Units.shortDuration > 0
OpacityAnimator {
id: opacityAnimator
duration: Platform.Units.shortDuration
easing.type: Easing.OutCubic
}
}

// sync all busy animations such that they start at a common place in the rotation
onAnimationShouldBeRunningChanged: startOrStopAnimation();

function startOrStopAnimation() {
if (rotationAnimator.running === animationShouldBeRunning) {
return;
}
if (animationShouldBeRunning) {
const date = new Date;
const ms = date.valueOf();
const startAngle = ((ms % rotationAnimator.duration) / rotationAnimator.duration) * 360;
rotationAnimator.from = startAngle;
rotationAnimator.to = startAngle + 360
}
rotationAnimator.running = animationShouldBeRunning;
}

Primitives.Icon {
/* Do not use `anchors.fill: parent` in here or else
* the aspect ratio won't always be 1:1.
*/
anchors.centerIn: parent
width: Math.min(parent.width, parent.height)
height: width

source: "process-working-symbolic"
smooth: true

RotationAnimator on rotation {
id: rotationAnimator
from: 0
to: 360
// Not using a standard duration value because we don't want the
// animation to spin faster or slower based on the user's animation
// scaling preferences; it doesn't make sense in this context
duration: 2000
loops: Animation.Infinite
// Initially false, will be set as appropriate after
// initialization. Can't be bound declaratively due to the
// procedural nature of to/from adjustments: order of
// assignments is crucial, as animator won't use new to/from
// values while running.
running: false
}
}

Component.onCompleted: startOrStopAnimation();
}
}
9 changes: 5 additions & 4 deletions launcher/qml/org/prismlauncher/desktop/Button.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import QtQuick
import QtQuick.Templates as T
import org.prismlauncher.pqcstyle as PrismStyle
import org.prismlauncher.platform as Platform

T.Button {
id: controlRoot
Expand All @@ -45,13 +46,13 @@ T.Button {

hoverEnabled: Qt.styleHints.useHoverEffects

PrismStyle.MnemonicData.enabled: enabled && visible
PrismStyle.MnemonicData.controlType: PrismStyle.MnemonicData.ActionElement
PrismStyle.MnemonicData.label: display !== T.AbstractButton.IconOnly ? text : ""
Platform.MnemonicData.enabled: enabled && visible
Platform.MnemonicData.controlType: Platform.MnemonicData.ActionElement
Platform.MnemonicData.label: display !== T.AbstractButton.IconOnly ? text : ""
Shortcut {
//in case of explicit & the button manages it by itself
enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text))
sequence: controlRoot.PrismStyle.MnemonicData.sequence
sequence: controlRoot.Platform.MnemonicData.sequence
onActivated: controlRoot.clicked()
}
background: PrismStyle.PStyleButton {
Expand Down
2 changes: 2 additions & 0 deletions launcher/qml/org/prismlauncher/desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ qt_add_qml_module(org_prismlauncher_desktop
STATIC
IMPORTS
"org.prismlauncher.pqcstyle"
"org.prismlauncher.platform"
QML_FILES ${DESKTOP_QML_SOURCES}
)
set(DESKTOP_QML_SOURCES
Expand All @@ -35,4 +36,5 @@ target_link_libraries(org_prismlauncher_desktop
PUBLIC
Qt${QT_VERSION_MAJOR}::QuickControls2
org_prismlauncher_pqcstyle
org_prismlauncher_platform
)
39 changes: 39 additions & 0 deletions launcher/qml/org/prismlauncher/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# SPDX-FileCopyrightText: 2024 Rachel Powers <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-only
#
# Prism Launcher - Minecraft Launcher
# Copyright (C) 2024 Rachel Powers <[email protected]>
#
# 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, version 3.
#
# 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 <https://www.gnu.org/licenses/>.

qt_add_qml_module(org_prismlauncher_platform
URI "org.prismlauncher.platform"
VERSION 1.0
STATIC
)

set(PLATFORM_CPP_SOURCES
"Units.cpp"
"Units.h"
"MnemonicData.h"
"MnemonicData.cpp"

)

target_sources(org_prismlauncher_platform PRIVATE ${PLATFORM_CPP_SOURCES})
target_link_libraries(org_prismlauncher_platform
PUBLIC
Qt${QT_VERSION_MAJOR}::Quick
)
Loading

0 comments on commit 4e67da8

Please sign in to comment.