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");
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());

View file

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

View file

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

View file

@ -1,19 +1,37 @@
import QtQuick 2.0
import QtQuick.Controls 1.2
BaseRectangle {
id: toolbar
default property alias children : inner_space.children
property bool horizontal: false
property list<BasePanel> panels
property var current
width: horizontal ? parent.width : 60
height: horizontal ? 60 : parent.height
color: "#50888888"
ExclusiveGroup {
id: exclusive_checked
}
Grid {
id: inner_space
columns: parent.horizontal ? children.length : 1
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)
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
picture: "images/tab_display.png"
hovertext: qsTr("Final render camera")
selected: true
checked: true
}
ToolbarButton {
@ -23,7 +23,7 @@ BaseToolbar {
id: camera_toggle_water
objectName: "camera_toggle_water"
toggle: true
selected: true
checked: true
picture: "images/toggle_water.png"
hovertext: qsTr("Toggle water rendering")
}
@ -31,11 +31,11 @@ BaseToolbar {
states: [
State {
name: "Render camera"
when: camera_choice_render.selected
when: camera_choice_render.checked
},
State {
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 QtGraphicalEffects 1.0
import QtQuick.Controls 1.2
Item {
id: button
property var toolbar: null
property string picture
property bool selected: false
property bool checked: false
property bool hovered: false
property bool toggle: false
property ExclusiveGroup exclusiveGroup: null
property string helptext
property string hovertext
property string shortcut
signal clicked
signal changed(bool value)
signal toggled(bool value)
width: image.width + 10
height: image.height + 10
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 {
PropertyAnimation {
@ -31,7 +44,7 @@ Item {
color: parent.toggle ? "#bbccbb" : "#cccccc"
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 {
PropertyAnimation {
duration: 200
@ -79,20 +92,11 @@ Item {
tooltip_widget.hovertext = "";
}
onClicked: {
button.selected = !button.selected;
button.checked = !button.checked;
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;
}
else

View file

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

View file

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