Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
90c9cdde
Commit
90c9cdde
authored
Feb 11, 2021
by
Nate Graham
Browse files
[applets/batterymonitor] Modernize and refactor QML code a bit
Only uncontroversial changes, and no visual changes.
parent
009a5b4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
applets/batterymonitor/package/contents/ui/BadgeOverlay.qml
View file @
90c9cdde
...
...
@@ -23,26 +23,19 @@ import QtGraphicalEffects 1.0
import
org
.
kde
.
plasma
.
core
2.0
as
PlasmaCore
import
org
.
kde
.
plasma
.
components
3.0
as
PlasmaComponents3
Item
{
Rectangle
{
property
alias
text
:
label
.
text
property
Item
icon
Rectangle
{
id
:
badgeRect
anchors
{
right
:
parent
.
right
bottom
:
parent
.
bottom
}
color
:
PlasmaCore
.
ColorScope
.
backgroundColor
width
:
Math
.
max
(
units
.
gridUnit
,
label
.
width
+
units
.
devicePixelRatio
*
2
)
height
:
label
.
height
radius
:
units
.
devicePixelRatio
*
3
opacity
:
0.9
}
color
:
PlasmaCore
.
ColorScope
.
backgroundColor
width
:
Math
.
max
(
units
.
gridUnit
,
label
.
width
+
units
.
devicePixelRatio
*
2
)
height
:
label
.
height
radius
:
units
.
devicePixelRatio
*
3
opacity
:
0.9
PlasmaComponents3.Label
{
id
:
label
anchors.centerIn
:
badgeRec
t
anchors.centerIn
:
paren
t
font.pixelSize
:
Math
.
max
(
icon
.
height
/
4
,
theme
.
smallestFont
.
pixelSize
*
0.8
)
}
...
...
applets/batterymonitor/package/contents/ui/CompactRepresentation.qml
View file @
90c9cdde
...
...
@@ -20,19 +20,32 @@
*/
import
QtQuick
2.0
import
QtQuick
.
Layouts
1.1
import
org
.
kde
.
plasma
.
core
2.0
as
PlasmaCore
import
org
.
kde
.
plasma
.
workspace
.
components
2.0
import
org
.
kde
.
plasma
.
workspace
.
components
2.0
as
WorkspaceComponents
MouseArea
{
id
:
root
Layout.minimumWidth
:
units
.
iconSizes
.
small
*
view
.
count
Layout.minimumHeight
:
units
.
iconSizes
.
small
property
real
itemSize
:
Math
.
min
(
root
.
height
,
root
.
width
/
view
.
count
)
readonly
property
bool
isConstrained
:
plasmoid
.
formFactor
===
PlasmaCore
.
Types
.
Vertical
||
plasmoid
.
formFactor
===
PlasmaCore
.
Types
.
Horizontal
property
int
wheelDelta
:
0
onClicked
:
plasmoid
.
expanded
=
!
plasmoid
.
expanded
onEntered
:
wheelDelta
=
0
onExited
:
wheelDelta
=
0
onWheel
:
{
var
delta
=
wheel
.
angleDelta
.
y
||
wheel
.
angleDelta
.
x
var
maximumBrightness
=
batterymonitor
.
maximumScreenBrightness
// Don't allow the UI to turn off the screen
// Please see https://git.reviewboard.kde.org/r/122505/ for more information
var
minimumBrightness
=
(
maximumBrightness
>
100
?
1
:
0
)
var
steps
=
Math
.
max
(
1
,
Math
.
round
(
maximumBrightness
/
20
))
var
deltaSteps
=
delta
/
120
;
batterymonitor
.
screenBrightness
=
Math
.
max
(
minimumBrightness
,
Math
.
min
(
maximumBrightness
,
batterymonitor
.
screenBrightness
+
deltaSteps
*
steps
));
}
readonly
property
bool
isConstrained
:
plasmoid
.
formFactor
===
PlasmaCore
.
Types
.
Vertical
||
plasmoid
.
formFactor
===
PlasmaCore
.
Types
.
Horizontal
//Should we consider turning this into a Flow item?
Row
{
...
...
@@ -41,8 +54,7 @@ MouseArea {
id
:
view
property
bool
hasBattery
:
batterymonitor
.
pmSource
.
data
[
"
Battery
"
][
"
Has Cumulative
"
]
property
bool
singleBattery
:
isConstrained
||
!
hasBattery
property
bool
singleBattery
:
root
.
isConstrained
||
!
view
.
hasBattery
model
:
singleBattery
?
1
:
batterymonitor
.
batteries
...
...
@@ -58,21 +70,26 @@ MouseArea {
property
real
iconSize
:
Math
.
min
(
width
,
height
)
BatteryIcon
{
WorkspaceComponents.
BatteryIcon
{
id
:
batteryIcon
anchors.centerIn
:
parent
height
:
root
.
isConstrained
?
batteryContainer
.
iconSize
:
batteryContainer
.
iconSize
-
batteryLabel
.
height
width
:
height
hasBattery
:
batteryContainer
.
hasBattery
percent
:
batteryContainer
.
percent
pluggedIn
:
batteryContainer
.
pluggedIn
height
:
isConstrained
?
batteryContainer
.
iconSize
:
batteryContainer
.
iconSize
-
batteryLabel
.
height
width
:
height
}
BadgeOverlay
{
anchors.fill
:
batteryIcon
anchors.bottom
:
parent
.
bottom
anchors.right
:
parent
.
right
visible
:
plasmoid
.
configuration
.
showPercentage
text
:
batteryContainer
.
hasBattery
?
i18nc
(
"
battery percentage below battery icon
"
,
"
%1%
"
,
percent
)
:
i18nc
(
"
short symbol to signal there is no battery currently available
"
,
"
-
"
)
icon
:
batteryIcon
visible
:
plasmoid
.
configuration
.
showPercentage
}
}
}
...
...
applets/batterymonitor/package/contents/ui/batterymonitor.qml
View file @
90c9cdde
...
...
@@ -172,23 +172,6 @@ Item {
}
}
Plasmoid.compactRepresentation
:
CompactRepresentation
{
property
int
wheelDelta
:
0
onEntered
:
wheelDelta
=
0
onExited
:
wheelDelta
=
0
onWheel
:
{
var
delta
=
wheel
.
angleDelta
.
y
||
wheel
.
angleDelta
.
x
var
maximumBrightness
=
batterymonitor
.
maximumScreenBrightness
// Don't allow the UI to turn off the screen
// Please see https://git.reviewboard.kde.org/r/122505/ for more information
var
minimumBrightness
=
(
maximumBrightness
>
100
?
1
:
0
)
var
steps
=
Math
.
max
(
1
,
Math
.
round
(
maximumBrightness
/
20
))
var
deltaSteps
=
delta
/
120
;
batterymonitor
.
screenBrightness
=
Math
.
max
(
minimumBrightness
,
Math
.
min
(
maximumBrightness
,
batterymonitor
.
screenBrightness
+
deltaSteps
*
steps
));
}
}
property
QtObject
pmSource
:
PlasmaCore.DataSource
{
id
:
pmSource
...
...
@@ -222,6 +205,8 @@ Item {
}
}
Plasmoid.compactRepresentation
:
CompactRepresentation
{}
Plasmoid.fullRepresentation
:
PopupDialog
{
id
:
dialogItem
Layout.minimumWidth
:
units
.
iconSizes
.
medium
*
9
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment