[ui] fix Palette propagation

* bugfix: in latest PySide2 versions, application palette is not properly applied to all QtQuick Controls 2 components. Force this by exposing QApplication palette and bind it to the root ApplicationWindow.
* rename all "palette" ids to "activePalette" to avoid clashes with "palette" property on QtQuick Controls 2
* use parent component palette when it makes sense to propagate active/disabled style (instead of always using Active SystemPalette)
This commit is contained in:
Yann Lanthony 2018-05-28 15:28:47 +02:00
parent 571560a43a
commit 2f2390e465
16 changed files with 46 additions and 43 deletions

View file

@ -2,7 +2,7 @@ import os
import signal
import sys
from PySide2.QtCore import Qt, QObject, Slot
from PySide2.QtCore import Qt, QObject, Slot, Signal, Property
from PySide2.QtGui import QPalette, QColor, QIcon
from PySide2.QtWidgets import QApplication
@ -60,6 +60,10 @@ class PaletteManager(QObject):
app.setPalette(self.darkPalette)
if self.qmlEngine.rootObjects():
self.qmlEngine.reload()
self.paletteChanged.emit()
paletteChanged = Signal()
palette = Property(QPalette, lambda self: QApplication.instance().palette(), notify=paletteChanged)
if __name__ == "__main__":

View file

@ -9,12 +9,10 @@ import QtQuick.Layouts 1.3
Pane {
id: root
SystemPalette { id: palette }
property bool opaque: false
property int radius: 1
padding: 6
anchors.margins: 2
background: Rectangle { color: palette.base; opacity: opaque ? 1.0 : 0.7; radius: root.radius }
background: Rectangle { color: root.palette.base; opacity: opaque ? 1.0 : 0.7; radius: root.radius }
}

View file

@ -15,11 +15,9 @@ ColumnLayout {
spacing: 0
SystemPalette { id: palette }
Pane {
Layout.fillWidth: true
background: Rectangle { color: Qt.darker(palette.window, 1.15) }
background: Rectangle { color: Qt.darker(parent.palette.window, 1.15) }
padding: 2
RowLayout {
width: parent.width

View file

@ -43,7 +43,7 @@ RowLayout {
// make label italic if attribute is a link
font.italic: object.isLink
background: Rectangle { color: Qt.darker(palette.window, 1.2) }
background: Rectangle { color: Qt.darker(parent.palette.window, 1.2) }
MouseArea {
id: parameterMA

View file

@ -134,7 +134,7 @@ RowLayout {
rightPadding: root.layoutDirection == Qt.LeftToRight ? 1 : 0
text: attribute.name
background: Rectangle {
color: palette.window
color: parent.palette.window
}
}
}

View file

@ -29,7 +29,7 @@ Item {
clip: true
SystemPalette { id: palette }
SystemPalette { id: activePalette }
MouseArea {
id: mouseArea
@ -195,7 +195,7 @@ Item {
property var dstAnchor: dst.nodeItem.mapFromItem(dst, dst.edgeAnchorPos.x, dst.edgeAnchorPos.y)
edge: object
color: containsMouse && !readOnly ? palette.highlight : palette.text
color: containsMouse && !readOnly ? activePalette.highlight : activePalette.text
opacity: 0.7
point1x: src.nodeItem.x + srcAnchor.x
point1y: src.nodeItem.y + srcAnchor.y

View file

@ -23,6 +23,8 @@ Item {
implicitHeight: body.height
objectName: node.name
SystemPalette { id: activePalette }
MouseArea {
anchors.fill: parent
drag.target: parent
@ -91,7 +93,7 @@ Item {
Rectangle {
id: background
anchors.fill: parent
color: palette.base
color: activePalette.base
layer.enabled: true
layer.effect: DropShadow { radius: 2; color: shadowColor }
}

View file

@ -6,11 +6,12 @@ ListView {
id: root
interactive: false
SystemPalette { id: palette }
SystemPalette { id: activePalette }
property color defaultColor: Qt.darker(palette.window, 1.1)
property color defaultColor: Qt.darker(activePalette.window, 1.1)
property real chunkHeight: height
property real chunkWidth: model ? width / model.count : 0
orientation: ListView.Horizontal
implicitWidth: 100
spacing: 0

View file

@ -16,7 +16,7 @@ import "common.js" as Common
FocusScope {
property variant node
SystemPalette { id: palette }
SystemPalette { id: activePalette }
Controls1.SplitView {
anchors.fill: parent
@ -42,13 +42,13 @@ FocusScope {
text: "Chunks"
padding: 4
z: 10
background: Rectangle { color: palette.window }
background: Rectangle { color: parent.palette.window }
}
}
highlight: Component {
Rectangle {
color: palette.highlight
color: activePalette.highlight
opacity: 0.3
z: 2
}
@ -116,7 +116,7 @@ FocusScope {
Layout.alignment: Qt.AlignTop
Layout.fillHeight: true
padding: 0
background: Rectangle { color: Qt.darker(palette.window, 1.2) }
background: Rectangle { color: Qt.darker(activePalette.window, 1.2) }
Column {
height: parent.height
ToolButton {

View file

@ -18,8 +18,6 @@ Item {
signal pressed(var mouse)
signal removeRequest()
SystemPalette { id: palette }
// retrieve viewpoints inner data
QtObject {
id: _viewpoint
@ -62,10 +60,10 @@ Item {
// Image thumbnail and background
Rectangle {
id: imageBackground
color: Qt.darker(palette.base, 1.15)
color: Qt.darker(imageLabel.palette.base, 1.15)
Layout.fillHeight: true
Layout.fillWidth: true
border.color: isCurrentItem ? palette.highlight : Qt.darker(palette.highlight)
border.color: isCurrentItem ? imageLabel.palette.highlight : Qt.darker(imageLabel.palette.highlight)
border.width: imageMA.containsMouse || imageDelegate.isCurrentItem ? 2 : 0
Image {
anchors.fill: parent
@ -79,6 +77,7 @@ Item {
}
// Image basename
Label {
id: imageLabel
Layout.fillWidth: true
padding: 2
font.pointSize: 8
@ -86,7 +85,7 @@ Item {
horizontalAlignment: Text.AlignHCenter
text: Filepath.basename(imageDelegate.source)
background: Rectangle {
color: imageDelegate.isCurrentItem ? palette.highlight : "transparent"
color: imageDelegate.isCurrentItem ? parent.palette.highlight : "transparent"
}
}
}

View file

@ -157,7 +157,7 @@ Panel {
Rectangle {
visible: dropArea.containsDrag
anchors.fill: parent
color: palette.window
color: root.palette.window
opacity: 0.8
}
@ -175,9 +175,9 @@ Panel {
text: "Add Images"
font.bold: true
background: Rectangle {
color: parent.hovered ? palette.highlight : palette.window
color: parent.hovered ? parent.palette.highlight : parent.palette.window
opacity: 0.8
border.color: palette.highlight
border.color: parent.palette.highlight
}
}
@ -196,7 +196,7 @@ Panel {
background: Rectangle {
color: parent.hovered ? palette.highlight : palette.window
opacity: 0.8
border.color: palette.highlight
border.color: parent.palette.highlight
}
}
}

View file

@ -27,12 +27,11 @@ Page {
property int footerHeight: 22
property int hPadding: 6
property int vPadding: 2
readonly property color paneBackgroundColor: Qt.darker(palette.window, 1.15)
readonly property color paneBackgroundColor: Qt.darker(root.palette.window, 1.15)
}
padding: 2
SystemPalette { id: palette }
header: Pane {
id: headerPane

View file

@ -20,8 +20,6 @@ FloatingPane {
clip: true
padding: 4
SystemPalette { id: palette }
/**
* Convert GPS metadata to degree coordinates.
*
@ -173,7 +171,7 @@ FloatingPane {
id: sizeHandle
height: parent.contentHeight
width: 1
color: palette.mid
color: root.palette.mid
x: parent.width * 0.4
MouseArea {
anchors.fill: parent
@ -198,7 +196,7 @@ FloatingPane {
Label {
width: parent.width
padding: 2
background: Rectangle { color: palette.mid }
background: Rectangle { color: parent.palette.mid }
text: section
}
}
@ -240,7 +238,7 @@ FloatingPane {
anchorPoint.y: circle.paintedHeight
sourceItem: Text {
id: circle
color: palette.highlight
color: root.palette.highlight
font.pointSize: 18
font.family: MaterialIcons.fontFamily
text: MaterialIcons.location_on

View file

@ -142,6 +142,8 @@ FocusScope {
depthMapSource = ''
}
SystemPalette { id: activePalette }
Scene3D {
id: scene3D
anchors.fill: parent
@ -358,7 +360,7 @@ FocusScope {
CuboidMesh { xExtent: 0.2; yExtent: 0.2; zExtent: 0.2},
PhongMaterial{
id: mat
ambient: viewId == _reconstruction.selectedViewId ? palette.highlight : "#CCC"
ambient: viewId == _reconstruction.selectedViewId ? activePalette.highlight : "#CCC"
diffuse: ambient
},
ObjectPicker {

View file

@ -53,7 +53,7 @@ Item {
}
}
SystemPalette { id: palette }
SystemPalette { id: activePalette }
Controls1.SplitView {
anchors.fill: parent
@ -109,7 +109,7 @@ Item {
Rectangle {
z: -1
anchors.fill: parent
color: Qt.darker(palette.base, 1.1)
color: Qt.darker(activePalette.base, 1.1)
}
}
}
@ -135,7 +135,7 @@ Item {
text: "Loading..."
visible: viewer3D.loading
padding: 6
background: Rectangle { color: palette.base; opacity: 0.5 }
background: Rectangle { color: parent.palette.base; opacity: 0.5 }
}
// Load reconstructed model

View file

@ -30,10 +30,12 @@ ApplicationWindow {
ensureSaved(function(){ Qt.quit() })
}
SystemPalette { id: palette }
SystemPalette { id: disabledPalette; colorGroup: SystemPalette.Disabled}
// force Application palette assignation
// note: should be implicit (PySide bug)
palette: _PaletteManager.palette
palette.window: palette.window
SystemPalette { id: activePalette }
SystemPalette { id: disabledPalette; colorGroup: SystemPalette.Disabled }
Settings {
id: settings_UILayout
@ -222,7 +224,7 @@ ApplicationWindow {
}
header: MenuBar {
palette.window: Qt.darker(palette.window, 1.15)
palette.window: Qt.darker(activePalette.window, 1.15)
Menu {
title: "File"
Action {
@ -321,7 +323,7 @@ ApplicationWindow {
orientation: Qt.Vertical
// Setup global tooltip style
ToolTip.toolTip.background: Rectangle { color: palette.base; border.color: palette.mid }
ToolTip.toolTip.background: Rectangle { color: activePalette.base; border.color: activePalette.mid }
ColumnLayout {
Layout.fillWidth: true