Improve sizing of Plasmoid

This commit is contained in:
Martchus 2019-11-30 18:43:24 +01:00
parent 4b5a8efa3e
commit 32996b8894
2 changed files with 22 additions and 30 deletions

View File

@ -15,7 +15,7 @@
<item row="0" column="0">
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>Size of full representation</string>
<string>Size of directory/device/download list</string>
</property>
</widget>
</item>
@ -43,7 +43,7 @@
<item>
<widget class="QSpinBox" name="widthSpinBox">
<property name="minimum">
<number>20</number>
<number>0</number>
</property>
<property name="maximum">
<number>1000</number>
@ -75,7 +75,7 @@
<item>
<widget class="QSpinBox" name="heightSpinBox">
<property name="minimum">
<number>15</number>
<number>0</number>
</property>
<property name="maximum">
<number>1000</number>
@ -109,7 +109,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Note that the size is ignored when the Plasmoid is displayed on the desktop, in full screen mode or as entry of the system tray Plasmoid.</string>
<string>Note that the size is ignored when the Plasmoid is displayed on the desktop or in full screen mode. When displayed as entry of the system tray Plasmoid the size can not be changed (setting a high value just leads to the contents being clipped).</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -11,38 +11,28 @@ import martchus.syncthingplasmoid 0.6 as SyncthingPlasmoid
ColumnLayout {
id: root
// define minimum size
Layout.minimumWidth: units.gridUnit * 20
Layout.minimumHeight: units.gridUnit * 15
// ensure keyboard events can be received after initialization
Component.onCompleted: forceActiveFocus()
// define function to update the size according to the settings
// when "floating" (shown as popup) or tied to an edge
function updateSize() {
switch (plasmoid.location) {
case PlasmaCore.Types.Floating:
case PlasmaCore.Types.TopEdge:
case PlasmaCore.Types.BottomEdge:
case PlasmaCore.Types.LeftEdge:
case PlasmaCore.Types.RightEdge:
var size = plasmoid.nativeInterface.size
parent.width = tabWidget.Layout.minimumWidth = units.gridUnit * size.width
parent.height = tabWidget.Layout.minimumHeight = units.gridUnit * size.height
// note: Setting the tabWidget's layout properties here as well because setting the parent's
// height ceased to work with Plasma 5.17.0 or later. (It somehow doesn't work to set root's layout
// properties so I'm using tabWidget here.)
break
default:
;
}
}
// update the size when settings changed
Connections {
target: plasmoid.nativeInterface
onSizeChanged: updateSize()
onSizeChanged: {
switch (plasmoid.location) {
case PlasmaCore.Types.Floating:
case PlasmaCore.Types.TopEdge:
case PlasmaCore.Types.BottomEdge:
case PlasmaCore.Types.LeftEdge:
case PlasmaCore.Types.RightEdge:
// set the parent's width and height so it will shrink again when decreasing the size
var size = plasmoid.nativeInterface.size
parent.width = units.gridUnit * size.width
parent.height = units.gridUnit * size.height
break
default:
;
}
}
}
// define shortcuts to trigger actions for currently selected item
@ -503,6 +493,8 @@ ColumnLayout {
RowLayout {
id: tabWidget
spacing: 0
Layout.minimumWidth: units.gridUnit * plasmoid.nativeInterface.size.width
Layout.minimumHeight: units.gridUnit * plasmoid.nativeInterface.size.height
ColumnLayout {
spacing: 0