@ -11,9 +11,11 @@ import QtQuick.Layouts 1.15
import org . kde . plasma . components 3.0 as PlasmaComponents3
import org . kde . plasma . core 2.1 as PlasmaCore
RowLayout {
PlasmaComponents3 . ItemDelegate {
id: root
property alias slider: slider
property string activeProfile
property string inhibitionReason
@ -51,190 +53,204 @@ RowLayout {
signal activateProfileRequested ( string profile )
spacing: PlasmaCore . Units . gridUnit
background.visible: highlighted
highlighted: activeFocus
hoverEnabled: false
text: i18n ( "Power Profile" )
PlasmaCore . IconItem {
source: "speedometer"
Layout.alignment: Qt . AlignTop
Layout.preferredWidth: PlasmaCore . Units . iconSizes . medium
Layout.preferredHeight: PlasmaCore . Units . iconSizes . medium
}
Accessible.description: activeProfileLabel . text
Accessible.role: Accessible . Slider
Keys.forwardTo: [ slider ]
ColumnLayout {
Layout.fillWidth: true
Layout.alignment: Qt . AlignTop
spacing: 0
contentItem: RowLayout {
spacing: PlasmaCore . Units . gridUnit
PlasmaCore . IconItem {
source: "speedometer"
Layout.alignment: Qt . AlignTop
Layout.preferredWidth: PlasmaCore . Units . iconSizes . medium
Layout.preferredHeight: PlasmaCore . Units . iconSizes . medium
}
RowLayout {
Column Layout {
Layout.fillWidth: true
spacing: PlasmaCore . Units . smallSpacing
Layout.alignment: Qt . AlignTop
spacing: 0
PlasmaComponents3 . Label {
RowLayout {
Layout.fillWidth: true
elide: Text . ElideRight
text: i18n ( "Power Profile" )
}
spacing: PlasmaCore . Units . smallSpacing
PlasmaComponents3 . Label {
Layout.alignment: Qt . AlignRight
text: activeProfileData ? activeProfileData.label : ""
PlasmaComponents3 . Label {
Layout.fillWidth: true
elide: Text . ElideRight
text: root . text
}
PlasmaComponents3 . Label {
id: activeProfileLabel
Layout.alignment: Qt . AlignRight
text: activeProfileData ? activeProfileData.label : ""
}
}
}
PlasmaComponents3 . Slider {
Layout.fillWidth: true
PlasmaComponents3 . Slider {
id: slider
Layout.fillWidth: true
from: 0
to: 2
stepSize: 1
value: root . activeProfileIndex
snapMode: PlasmaComponents3 . Slider . SnapAlways
onMoved: {
const { canBeInhibited , profile } = root . profileData [ value ] ;
if ( ! ( canBeInhibited && root . inhibited ) ) {
activateProfileRequested ( profile ) ;
} else {
value = Qt . binding ( ( ) = > root . activeProfileIndex ) ;
activeFocusOnTab: false
from: 0
to: 2
stepSize: 1
value: root . activeProfileIndex
snapMode: PlasmaComponents3 . Slider . SnapAlways
onMoved: {
const { canBeInhibited , profile } = root . profileData [ value ] ;
if ( ! ( canBeInhibited && root . inhibited ) ) {
activateProfileRequested ( profile ) ;
} else {
value = Qt . binding ( ( ) = > root . activeProfileIndex ) ;
}
}
}
/ / f a k e h a v i n g a d i s a b l e d s e c o n d h a l f
Rectangle {
z: - 1
visible: root . inhibited
color: PlasmaCore . Theme . backgroundColor
anchors {
top: parent . background . top
left: parent . horizontalCenter
leftMargin: 1
right: parent . right
bottom: parent . background . bottom
/ / f a k e h a v i n g a d i s a b l e d s e c o n d h a l f
Rectangle {
z: - 1
visible: root . inhibited
color: PlasmaCore . Theme . backgroundColor
anchors {
top: parent . background . top
left: parent . horizontalCenter
leftMargin: 1
right: parent . right
bottom: parent . background . bottom
}
opacity: 0.4
}
opacity: 0.4
}
}
RowLayout {
spacing: 0
Layout.topMargin: PlasmaCore . Units . smallSpacing
Layout.bottomMargin: PlasmaCore . Units . smallSpacing
Layout.fillWidth: true
RowLayout {
spacing: 0
Layout.topMargin: PlasmaCore . Units . smallSpacing
Layout.bottomMargin: PlasmaCore . Units . smallSpacing
Layout.fillWidth: true
PlasmaCore . Svg {
id: svg
imagePath: "icons/battery"
}
PlasmaCore . Svg {
id: svg
imagePath: "icons/battery"
}
PlasmaCore . SvgItem {
Layout.preferredHeight: PlasmaCore . Units . iconSizes . smallMedium
Layout.preferredWidth: PlasmaCore . Units . iconSizes . smallMedium
svg: svg
elementId: "profile-powersave"
PlasmaCore . SvgItem {
Layout.preferredHeight: PlasmaCore . Units . iconSizes . smallMedium
Layout.preferredWidth: PlasmaCore . Units . iconSizes . smallMedium
svg: svg
elementId: "profile-powersave"
HoverHandler {
id: powersaveIconHover
}
HoverHandler {
id: powersaveIconHover
}
PlasmaComponents3 . ToolTip {
text: root . profileData . find ( profile = > profile . profile === "power-saver" ) . label
visible: powersaveIconHover . hovered
PlasmaComponents3 . ToolTip {
text: root . profileData . find ( profile = > profile . profile === "power-saver" ) . label
visible: powersaveIconHover . hovered
}
}
}
Item {
Layout.fillWidth: true
}
Item {
Layout.fillWidth: true
}
PlasmaCore . SvgItem {
Layout.preferredHeight: PlasmaCore . Units . iconSizes . smallMedium
Layout.preferredWidth: PlasmaCore . Units . iconSizes . smallMedium
svg: svg
elementId: "profile-performance"
PlasmaCore . SvgItem {
Layout.preferredHeight: PlasmaCore . Units . iconSizes . smallMedium
Layout.preferredWidth: PlasmaCore . Units . iconSizes . smallMedium
svg: svg
elementId: "profile-performance"
HoverHandler {
id: performanceIconHover
}
HoverHandler {
id: performanceIconHover
}
PlasmaComponents3 . ToolTip {
text: root . profileData . find ( profile = > profile . profile === "performance" ) . label
visible: performanceIconHover . hovered
PlasmaComponents3 . ToolTip {
text: root . profileData . find ( profile = > profile . profile === "performance" ) . label
visible: performanceIconHover . hovered
}
}
}
}
/ / N O T E O n l y o n e o f t h e s e w i l l b e v i s i b l e a t a t i m e s i n c e t h e d a e m o n w i l l o n l y s e t o n e d e p e n d i n g
/ / o n i t s v e r s i o n
InhibitionHint {
id: inhibitionReasonHint
/ / N O T E O n l y o n e o f t h e s e w i l l b e v i s i b l e a t a t i m e s i n c e t h e d a e m o n w i l l o n l y s e t o n e d e p e n d i n g
/ / o n i t s v e r s i o n
InhibitionHint {
id: inhibitionReasonHint
Layout.fillWidth: true
Layout.fillWidth: true
visible: root . inhibited
iconSource: "dialog-information"
text: switch ( root . inhibitionReason ) {
case "lap-detected" :
return i18n ( "Performance mode has been disabled to reduce heat generation because the computer has detected that it may be sitting on your lap." )
case "high-operating-temperature" :
return i18n ( "Performance mode is unavailable because the computer is running too hot." )
default:
return i18n ( "Performance mode is unavailable." )
visible: root . inhibited
iconSource: "dialog-information"
text: switch ( root . inhibitionReason ) {
case "lap-detected" :
return i18n ( "Performance mode has been disabled to reduce heat generation because the computer has detected that it may be sitting on your lap." )
case "high-operating-temperature" :
return i18n ( "Performance mode is unavailable because the computer is running too hot." )
default:
return i18n ( "Performance mode is unavailable." )
}
}
}
InhibitionHint {
id: inhibitionPerformanceHint
InhibitionHint {
id: inhibitionPerformanceHint
Layout.fillWidth: true
Layout.fillWidth: true
visible: root . activeProfile === "performance" && root . degradationReason !== ""
iconSource: "dialog-information"
text: switch ( root . degradationReason ) {
case "lap-detected" :
return i18n ( "Performance may be lowered to reduce heat generation because the computer has detected that it may be sitting on your lap." )
case "high-operating-temperature" :
return i18n ( "Performance may be reduced because the computer is running too hot." )
default:
return i18n ( "Performance may be reduced." )
visible: root . activeProfile === "performance" && root . degradationReason !== ""
iconSource: "dialog-information"
text: switch ( root . degradationReason ) {
case "lap-detected" :
return i18n ( "Performance may be lowered to reduce heat generation because the computer has detected that it may be sitting on your lap." )
case "high-operating-temperature" :
return i18n ( "Performance may be reduced because the computer is running too hot." )
default:
return i18n ( "Performance may be reduced." )
}
}
}
InhibitionHint {
id: inhibitionHoldersHint
InhibitionHint {
id: inhibitionHoldersHint
Layout.fillWidth: true
Layout.fillWidth: true
visible: root . activeHolds . length > 0 && root . activeProfileData !== undefined
text: root . activeProfileData !== undefined
? i18np ( "One application has requested activating %2:" ,
"%1 applications have requested activating %2:" ,
root . activeHolds . length ,
i18n ( root . activeProfileData . label ) )
: ""
}
visible: root . activeHolds . length > 0 && root . activeProfileData !== undefined
text: root . activeProfileData !== undefined
? i18np ( "One application has requested activating %2:" ,
"%1 applications have requested activating %2:" ,
root . activeHolds . length ,
i18n ( root . activeProfileData . label ) )
: ""
}
Repeater {
id: repeater
Repeater {
id: repeater
model: root . activeHolds
model: root . activeHolds
InhibitionHint {
Layout.fillWidth: true
InhibitionHint {
Layout.fillWidth: true
x: PlasmaCore . Units . smallSpacing
iconSource: modelData . Icon
text: i18nc ( "%1 is the name of the application, %2 is the reason provided by it for activating performance mode" ,
"%1: %2" , modelData . Name , modelData . Reason )
x: PlasmaCore . Units . smallSpacing
iconSource: modelData . Icon
text: i18nc ( "%1 is the name of the application, %2 is the reason provided by it for activating performance mode" ,
"%1: %2" , modelData . Name , modelData . Reason )
}
}
}
Item {
Layout.fillWidth: true
Layout.preferredHeight: PlasmaCore . Units . smallSpacing
Item {
Layout.fillWidth: true
Layout.preferredHeight: PlasmaCore . Units . smallSpacing
visible: repeater . visibleChildren > 0
|| inhibitionReasonHint . visible
|| inhibitionPerformanceHint . visible
|| inhibitionHoldersHint . visible
visible: repeater . visibleChildren > 0
|| inhibitionReasonHint . visible
|| inhibitionPerformanceHint . visible
|| inhibitionHoldersHint . visible
}
}
}
}