// WizardBar.cpp code snippet
QSGNode *WizardBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
QSGNode *root = static_cast<QSGNode *>(oldNode);
if(!root) root = new QSGNode;
QSGGeometry *geometry;
int height = WizardBar::height();
int width = WizardBar::width();
int arrow = height / 2;
int pos = 0;
QColor backgroundColor
= active_ ? activeBg_
: inactiveBg_;
switch (position_)
{
case FirstLabel:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos, 0);
geometry->vertexDataAsPoint2D()[1].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + arrow + width, arrow);
geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
geometry->vertexDataAsPoint2D()[4].set(pos, height);
break;
case LastLabel:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
geometry->vertexDataAsPoint2D()[1].set(pos, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
geometry->vertexDataAsPoint2D()[4].set(pos, height);
break;
default:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
geometry->vertexDataAsPoint2D()[1].set(pos, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[3].set(pos + arrow + width, arrow);
geometry->vertexDataAsPoint2D()[4].set(pos + width, height);
geometry->vertexDataAsPoint2D()[5].set(pos, height);
break;
}
root->appendChildNode(drawPolygon(geometry, backgroundColor));
return root;
}
QSGNode
*WizardBar
::drawPolygon(QSGGeometry
*geometry,
const QColor &color
){
QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
material->setColor(color);
QSGGeometryNode *node = new QSGGeometryNode;
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
return node;
}
// WizardBar.cpp code snippet
QSGNode *WizardBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
QSGNode *root = static_cast<QSGNode *>(oldNode);
if(!root) root = new QSGNode;
QSGGeometry *geometry;
int height = WizardBar::height();
int width = WizardBar::width();
int arrow = height / 2;
int pos = 0;
QColor backgroundColor = active_ ? activeBg_ : inactiveBg_;
switch (position_)
{
case FirstLabel:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos, 0);
geometry->vertexDataAsPoint2D()[1].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + arrow + width, arrow);
geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
geometry->vertexDataAsPoint2D()[4].set(pos, height);
break;
case LastLabel:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
geometry->vertexDataAsPoint2D()[1].set(pos, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
geometry->vertexDataAsPoint2D()[4].set(pos, height);
break;
default:
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
geometry->setDrawingMode(GL_TRIANGLE_FAN);
geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
geometry->vertexDataAsPoint2D()[1].set(pos, 0);
geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
geometry->vertexDataAsPoint2D()[3].set(pos + arrow + width, arrow);
geometry->vertexDataAsPoint2D()[4].set(pos + width, height);
geometry->vertexDataAsPoint2D()[5].set(pos, height);
break;
}
root->appendChildNode(drawPolygon(geometry, backgroundColor));
return root;
}
QSGNode *WizardBar::drawPolygon(QSGGeometry *geometry, const QColor &color)
{
QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
material->setColor(color);
QSGGeometryNode *node = new QSGGeometryNode;
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
return node;
}
To copy to clipboard, switch view to plain text mode
// qml page
Item {
id: container
property int conWidth: StaticData.screenWidth - header.anchors.leftMargin*2; // i can't get the implicit width of anchored items
property int missingWidth: 0
property int extraWidth: 0
function getWidth(rowWidth) {
if (rowWidth <= conWidth) {
missingWidth = 0;
extraWidth = conWidth - rowWidth;
} else {
extraWidth = 0;
missingWidth = rowWidth - conWidth
}
}
anchors {
right: parent.right
left: parent.left
bottom: parent.bottom
}
clip: true
height: 60
Row {
id: barRow
property int rowWidth
property int curIdx
spacing: 1
ListModel {
id: barModel
ListElement {
label: qsTr("Protocol")
group: "protocols"
}
ListElement {
label: qsTr("Host")
group: "host"
}
ListElement {
label: qsTr("Login")
group: "login"
}
ListElement {
label: qsTr("Proxy")
group: "proxy"
}
ListElement {
label: qsTr("Save")
group: "save"
}
}
Component.onCompleted: {
container.getWidth(rowWidth);
if (container.extraWidth > 0) {
var addtlWidth = Math.floor(container.extraWidth/barModel.count)
for (var i = 0; i <= barModel.count - 1; i++) {
barRepeater.itemAt(i).width += addtlWidth ;
}
}
}
Repeater {
id: barRepeater
model: barModel
onItemAdded: {
barRow.rowWidth += item.width;
}
WizardBar {
id: wizardBar
property bool mid: index != 0
property bool curGroup: model.group === newConnPagesModel.curGroup // to synch with the wizard pages
onCurGroupChanged: {
if (curGroup) barRow.curIdx = index;
}
height: 60
width: label.paintedWidth + 10
active: index <= barRow.curIdx
position: index === 0 ? WizardBar.FirstLabel : ((index === (barModel.count - 1)) ? WizardBar.LastLabel : WizardBar.MiddleLabel) // labels are enum in class which indicates the shape of the arrow to be drawn
Item { // created as text container so that the arrow part will be excluded
id: labelItem
x: index != 0 ? parent.height/2 : 0
width: index != 0 ? parent.width - parent.height/2 : parent.width
height: parent.height
Text
{
id: label
anchors.centerIn: parent
color: wizardBar.active ? Colors.text.title.normal : Colors.text.title.disabled
font { pixelSize: Fonts.fontSize; family: Fonts.fontFamily }
text: model.label
}
}
}
}
}
}
// qml page
Item {
id: container
property int conWidth: StaticData.screenWidth - header.anchors.leftMargin*2; // i can't get the implicit width of anchored items
property int missingWidth: 0
property int extraWidth: 0
function getWidth(rowWidth) {
if (rowWidth <= conWidth) {
missingWidth = 0;
extraWidth = conWidth - rowWidth;
} else {
extraWidth = 0;
missingWidth = rowWidth - conWidth
}
}
anchors {
right: parent.right
left: parent.left
bottom: parent.bottom
}
clip: true
height: 60
Row {
id: barRow
property int rowWidth
property int curIdx
spacing: 1
ListModel {
id: barModel
ListElement {
label: qsTr("Protocol")
group: "protocols"
}
ListElement {
label: qsTr("Host")
group: "host"
}
ListElement {
label: qsTr("Login")
group: "login"
}
ListElement {
label: qsTr("Proxy")
group: "proxy"
}
ListElement {
label: qsTr("Save")
group: "save"
}
}
Component.onCompleted: {
container.getWidth(rowWidth);
if (container.extraWidth > 0) {
var addtlWidth = Math.floor(container.extraWidth/barModel.count)
for (var i = 0; i <= barModel.count - 1; i++) {
barRepeater.itemAt(i).width += addtlWidth ;
}
}
}
Repeater {
id: barRepeater
model: barModel
onItemAdded: {
barRow.rowWidth += item.width;
}
WizardBar {
id: wizardBar
property bool mid: index != 0
property bool curGroup: model.group === newConnPagesModel.curGroup // to synch with the wizard pages
onCurGroupChanged: {
if (curGroup) barRow.curIdx = index;
}
height: 60
width: label.paintedWidth + 10
active: index <= barRow.curIdx
position: index === 0 ? WizardBar.FirstLabel : ((index === (barModel.count - 1)) ? WizardBar.LastLabel : WizardBar.MiddleLabel) // labels are enum in class which indicates the shape of the arrow to be drawn
Item { // created as text container so that the arrow part will be excluded
id: labelItem
x: index != 0 ? parent.height/2 : 0
width: index != 0 ? parent.width - parent.height/2 : parent.width
height: parent.height
Text
{
id: label
anchors.centerIn: parent
color: wizardBar.active ? Colors.text.title.normal : Colors.text.title.disabled
font { pixelSize: Fonts.fontSize; family: Fonts.fontFamily }
text: model.label
}
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks