ui: Fixed some state issues

This commit is contained in:
Michaël Lemaire 2015-08-28 11:40:35 +02:00
parent 45f10440ec
commit 1361c5c654
8 changed files with 51 additions and 51 deletions

View file

@ -13,7 +13,7 @@ WaterModeler::WaterModeler(MainModelerWindow *ui):
QObject *toggle_water = ui->findQmlObject("camera_toggle_water"); QObject *toggle_water = ui->findQmlObject("camera_toggle_water");
if (toggle_water) if (toggle_water)
{ {
connect(toggle_water, SIGNAL(changed(bool)), this, SLOT(enableRendering(bool))); connect(toggle_water, SIGNAL(toggled(bool)), this, SLOT(enableRendering(bool)));
} }
prop_water_height = new FloatPropertyBind(ui, "water_height", "value", ui->getScenery()->getTerrain()->propWaterHeight()); prop_water_height = new FloatPropertyBind(ui, "water_height", "value", ui->getScenery()->getTerrain()->propWaterHeight());

View file

@ -9,7 +9,7 @@ BaseSection {
ToolbarButton { ToolbarButton {
id: tool_daytime id: tool_daytime
selected: true checked: true
picture: "images/icon_atmosphere_daytime.png" picture: "images/icon_atmosphere_daytime.png"
hovertext: qsTr("Change the time of day") hovertext: qsTr("Change the time of day")
} }
@ -37,7 +37,7 @@ BaseSection {
states: [ states: [
State { State {
name: "DayTime" name: "DayTime"
when: tool_daytime.selected when: tool_daytime.checked
PropertyChanges { PropertyChanges {
target: panel_daytime target: panel_daytime
enabled: true enabled: true
@ -45,7 +45,7 @@ BaseSection {
}, },
State { State {
name: "Humidity" name: "Humidity"
when: tool_humidity.selected when: tool_humidity.checked
PropertyChanges { PropertyChanges {
target: panel_humidity target: panel_humidity
enabled: true enabled: true

View file

@ -5,10 +5,4 @@ BaseToolbar {
height: parent.height - primary_toolbar.height height: parent.height - primary_toolbar.height
anchors.left: primary_toolbar.left anchors.left: primary_toolbar.left
anchors.top: primary_toolbar.bottom anchors.top: primary_toolbar.bottom
onEnabledChanged: {
if (enabled) {
primary_toolbar.current = this;
}
}
} }

View file

@ -1,19 +1,37 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 1.2
BaseRectangle { BaseRectangle {
id: toolbar
default property alias children : inner_space.children default property alias children : inner_space.children
property bool horizontal: false property bool horizontal: false
property list<BasePanel> panels property list<BasePanel> panels
property var current
width: horizontal ? parent.width : 60 width: horizontal ? parent.width : 60
height: horizontal ? 60 : parent.height height: horizontal ? 60 : parent.height
color: "#50888888" color: "#50888888"
ExclusiveGroup {
id: exclusive_checked
}
Grid { Grid {
id: inner_space id: inner_space
columns: parent.horizontal ? children.length : 1 columns: parent.horizontal ? children.length : 1
rows: parent.horizontal ? 1 : children.length rows: parent.horizontal ? 1 : children.length
spacing: (parent.horizontal ? (parent.width - children.length * tool_terrain.width) : (parent.height - children.length * tool_terrain.height)) / (children.length + 1) spacing: (parent.horizontal ? (parent.width - children.length * tool_terrain.width) : (parent.height - children.length * tool_terrain.height)) / (children.length + 1)
anchors.centerIn: parent anchors.centerIn: parent
onChildrenChanged: {
for (var i = 0; i < children.length; ++i)
{
children[i].toolbar = toolbar;
if (!children[i].toggle)
{
children[i].exclusiveGroup = exclusive_checked;
}
}
}
} }
} }

View file

@ -10,7 +10,7 @@ BaseToolbar {
id: camera_choice_render id: camera_choice_render
picture: "images/tab_display.png" picture: "images/tab_display.png"
hovertext: qsTr("Final render camera") hovertext: qsTr("Final render camera")
selected: true checked: true
} }
ToolbarButton { ToolbarButton {
@ -23,7 +23,7 @@ BaseToolbar {
id: camera_toggle_water id: camera_toggle_water
objectName: "camera_toggle_water" objectName: "camera_toggle_water"
toggle: true toggle: true
selected: true checked: true
picture: "images/toggle_water.png" picture: "images/toggle_water.png"
hovertext: qsTr("Toggle water rendering") hovertext: qsTr("Toggle water rendering")
} }
@ -31,11 +31,11 @@ BaseToolbar {
states: [ states: [
State { State {
name: "Render camera" name: "Render camera"
when: camera_choice_render.selected when: camera_choice_render.checked
}, },
State { State {
name: "Top-down camera" name: "Top-down camera"
when: camera_choice_topdown.selected when: camera_choice_topdown.checked
} }
] ]
} }

View file

@ -1,23 +1,36 @@
import QtQuick 2.0 import QtQuick 2.0
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import QtQuick.Controls 1.2
Item { Item {
id: button id: button
property var toolbar: null
property string picture property string picture
property bool selected: false property bool checked: false
property bool hovered: false property bool hovered: false
property bool toggle: false property bool toggle: false
property ExclusiveGroup exclusiveGroup: null
property string helptext property string helptext
property string hovertext property string hovertext
property string shortcut property string shortcut
signal clicked signal clicked
signal changed(bool value) signal toggled(bool value)
width: image.width + 10 width: image.width + 10
height: image.height + 10 height: image.height + 10
opacity: enabled ? 1.0 : 0.1 opacity: enabled ? 1.0 : 0.1
onSelectedChanged: changed(selected) onExclusiveGroupChanged: {
if (exclusiveGroup)
exclusiveGroup.bindCheckable(button)
}
onCheckedChanged: {
toggled(checked);
if (toolbar && !toggle && checked) {
toolbar.current = button;
}
}
Behavior on opacity { Behavior on opacity {
PropertyAnimation { PropertyAnimation {
@ -31,7 +44,7 @@ Item {
color: parent.toggle ? "#bbccbb" : "#cccccc" color: parent.toggle ? "#bbccbb" : "#cccccc"
radius: 8 radius: 8
opacity: button.selected ? 1.0 : (button.hovered ? 0.5 : 0.0) opacity: button.checked ? 1.0 : (button.hovered ? 0.5 : 0.0)
Behavior on opacity { Behavior on opacity {
PropertyAnimation { PropertyAnimation {
duration: 200 duration: 200
@ -79,20 +92,11 @@ Item {
tooltip_widget.hovertext = ""; tooltip_widget.hovertext = "";
} }
onClicked: { onClicked: {
button.selected = !button.selected; button.checked = !button.checked;
if (!button.toggle) if (!button.toggle)
{ {
if (button.selected) if (button.checked)
{ {
var toolbar = button.parent;
for (var i = 0; i < toolbar.children.length; ++i)
{
var child = toolbar.children[i]
if (child !== button && !child.toggle)
{
child.selected = false;
}
}
tooltip_widget.helptext = helptext; tooltip_widget.helptext = helptext;
} }
else else

View file

@ -9,7 +9,7 @@ BaseSection {
ToolbarButton { ToolbarButton {
id: tool_water_level id: tool_water_level
selected: true checked: true
picture: "images/icon_water_level.png" picture: "images/icon_water_level.png"
hovertext: qsTr("Change the water altitude") hovertext: qsTr("Change the water altitude")
} }
@ -27,7 +27,7 @@ BaseSection {
states: [ states: [
State { State {
name: "WaterHeight" name: "WaterHeight"
when: tool_water_level.selected when: tool_water_level.checked
PropertyChanges { PropertyChanges {
target: panel_water_level target: panel_water_level
enabled: true enabled: true

View file

@ -159,55 +159,39 @@ OpenGLView {
states: [ states: [
State { State {
name: "Water Mode" name: "Water Mode"
when: tool_water.selected when: primary_toolbar.current === tool_water
PropertyChanges { PropertyChanges {
target: water_section target: water_section
enabled: true enabled: true
} }
PropertyChanges {
target: tool_water
selected: true
}
}, },
State { State {
name: "Atmosphere Mode" name: "Atmosphere Mode"
when: tool_atmosphere.selected when: primary_toolbar.current === tool_atmosphere
PropertyChanges { PropertyChanges {
target: atmosphere_section target: atmosphere_section
enabled: true enabled: true
} }
PropertyChanges {
target: tool_atmosphere
selected: true
}
}, },
State { State {
name: "Render Mode" name: "Render Mode"
when: tool_render.selected when: primary_toolbar.current === tool_render
PropertyChanges { PropertyChanges {
target: render_toolbar target: render_toolbar
enabled: true enabled: true
} }
PropertyChanges {
target: tool_render
selected: true
}
}, },
State { State {
name: "File Mode" name: "File Mode"
when: tool_file.selected when: primary_toolbar.current === tool_file
PropertyChanges { PropertyChanges {
target: file_toolbar target: file_toolbar
enabled: true enabled: true
} }
PropertyChanges {
target: tool_file
selected: true
}
}, },
State { State {
name: "Render Dialog" name: "Render Dialog"