Separate the view selector into a different file.

This commit is contained in:
Diego Prado Gesto 2018-11-25 18:24:21 +01:00
parent 9e92542eee
commit f3bf20ca1b
4 changed files with 86 additions and 73 deletions

View File

@ -29,80 +29,12 @@ Item
anchors.centerIn: parent
height: parent.height
Cura.ExpandableComponent
Cura.ViewsSelector
{
id: viewSelector
iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
id: viewsSelector
height: parent.height
width: UM.Theme.getSize("views_selector").width
headerCornerSide: Cura.RoundedRectangle.Direction.Left
property var viewModel: UM.ViewModel { }
property var activeView:
{
for (var i = 0; i < viewModel.rowCount(); i++)
{
if (viewModel.items[i].active)
{
return viewModel.items[i]
}
}
return null
}
Component.onCompleted:
{
// Nothing was active, so just return the first one (the list is sorted by priority, so the most
// important one should be returned)
if (activeView == null)
{
UM.Controller.setActiveView(viewModel.getItem(0).id)
}
}
headerItem: Label
{
text: viewSelector.activeView ? viewSelector.activeView.name : ""
verticalAlignment: Text.AlignVCenter
height: parent.height
elide: Text.ElideRight
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
popupItem: Column
{
id: viewSelectorPopup
width: viewSelector.width - 2 * UM.Theme.getSize("default_margin").width
// For some reason the height/width of the column gets set to 0 if this is not set...
Component.onCompleted:
{
height = implicitHeight
width = viewSelector.width - 2 * UM.Theme.getSize("default_margin").width
}
Repeater
{
id: viewsList
model: viewSelector.viewModel
RoundButton
{
text: name
radius: UM.Theme.getSize("default_radius").width
checkable: true
checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
onClicked:
{
viewSelector.togglePopup()
UM.Controller.setActiveView(id)
}
}
}
}
}
// Separator line

View File

@ -3,8 +3,6 @@
import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Controls.Styles 1.1
import QtQuick.Layouts 1.1
import UM 1.2 as UM
import Cura 1.0 as Cura

View File

@ -0,0 +1,82 @@
// Copyright (c) 2018 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7
import QtQuick.Controls 2.3
import UM 1.2 as UM
import Cura 1.0 as Cura
Cura.ExpandableComponent
{
id: viewSelector
iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
property var viewModel: UM.ViewModel { }
property var activeView:
{
for (var i = 0; i < viewModel.rowCount(); i++)
{
if (viewModel.items[i].active)
{
return viewModel.items[i]
}
}
return null
}
Component.onCompleted:
{
// Nothing was active, so just return the first one (the list is sorted by priority, so the most
// important one should be returned)
if (activeView == null)
{
UM.Controller.setActiveView(viewModel.getItem(0).id)
}
}
headerItem: Label
{
text: viewSelector.activeView ? viewSelector.activeView.name : ""
verticalAlignment: Text.AlignVCenter
height: parent.height
elide: Text.ElideRight
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")
renderType: Text.NativeRendering
}
popupItem: Column
{
id: viewSelectorPopup
width: viewSelector.width - 2 * UM.Theme.getSize("default_margin").width
// For some reason the height/width of the column gets set to 0 if this is not set...
Component.onCompleted:
{
height = implicitHeight
width = viewSelector.width - 2 * UM.Theme.getSize("default_margin").width
}
Repeater
{
id: viewsList
model: viewSelector.viewModel
RoundButton
{
text: name
radius: UM.Theme.getSize("default_radius").width
checkable: true
checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
onClicked:
{
viewSelector.togglePopup()
UM.Controller.setActiveView(id)
}
}
}
}
}

View File

@ -12,3 +12,4 @@ IconLabel 1.0 IconLabel.qml
OutputDevicesActionButton 1.0 OutputDevicesActionButton.qml
ExpandableComponent 1.0 ExpandableComponent.qml
PrinterTypeLabel 1.0 PrinterTypeLabel.qml
ViewsSelector 1.0 ViewsSelector.qml