Editor Informations
Downloads
Sending datas to the qml
#define qmlMember(_type,_name) \
public: \
Q_PROPERTY(_type _name MEMBER m_##_name READ get_##_name WRITE set_##_name NOTIFY _name##Changed); \
_type get_##_name() const {return m_##_name;} \
void set_##_name(_type val) {m_##_name = val; emit _name##Changed(val);} \
private: \
_type m_##_name;
As you see, we need to call "Q_PROPERTY" with the following parameters:
The cursor position
qmlMember(QString,cursorInfo)
[...]
signals:
[...]
void cursorInfoChanged(QString);
In "MainForm.ui.qml" we simply display it inside a rectangle:
Rectangle {
id: rectangle
y: 446
height: cursorInfos.height + 8
color: "#00000000"
border.color: "#808080"
border.width: 1
[...]
Label {
id: cursorInfos
x: 0
text: bridge.cursorInfo
[...]
}
}
And in "rectangles.cpp", we modify the variable every time we draw the cursor:
void Rectangles::drawCursor(QImage* image, CVec2 mousePos, ETabIndex tabIndex)
{
if (mousePos.x != -1)
{
if (tabIndex == eTabTiles)
drawTileRect(image, mousePos, CURSOR_COLOR);
else if (tabIndex == eTabWalls)
drawWallRect(image, mousePos, CURSOR_COLOR);
else if (tabIndex == eTabObjects)
drawObjectRect(image, mousePos, CURSOR_COLOR);
QString text = editor.getPositionString(mousePos, tabIndex);
bridge.set_cursorInfo(text);
}
else
{
bridge.set_cursorInfo(QString());
}
}
The selection informations
GroupBox {
id: selectionBox
x: 403
width: tabView1.width
[...]
title: qsTr("Selection")
ScrollView {
id: tileSelScroll
visible: bridge.tileSelScrollVis
anchors.fill: parent
Grid {
id: tSelGrid
spacing: 4
rows: 3
columns: 2
anchors.fill: parent
[...]
}
}
ScrollView {
id: wallSelScroll
visible: bridge.wallSelScrollVis
anchors.fill: parent
Grid {
id: wSelGrid
spacing: 4
rows: 3
columns: 2
anchors.fill: parent
[...]
}
}
ScrollView {
id: objectSelScroll
visible: bridge.objectSelScrollVis
anchors.fill: parent
Grid {
id: oSelGrid
spacing: 4
rows: 3
columns: 2
anchors.fill: parent
[...]
}
}
ScrollView {
id: rectSelScroll
visible: bridge.rectSelScrollVis
anchors.fill: parent
Grid {
id: rSelGrid
spacing: 4
rows: 3
columns: 2
anchors.fill: parent
[...]
}
}
}
As you can see, each of the ScrollViews can be shown or hidden by modifying the corresponding variable tileSelScrollVis, wallSelScrollVis,
Label {
id: tPosLabel
height: 20
text: qsTr("Position:")
verticalAlignment: Text.AlignVCenter
renderType: Text.QtRendering
}
Label {
id: tPosValue
height: 20
text: bridge.selPosition
verticalAlignment: Text.AlignVCenter
}
This position is set using the same function getPositionString() that we used before.
The ComboBoxes
Label {
id: tTypeLabel
height: 20
text: qsTr("Type:")
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
}
ComboBox {
id: tTypeValue
model: tilesList
currentIndex: bridge.selTileType
}
The "model" represents all the values that will be displayed in the ComboBox. It is a list of strings that is defined by the function
// register our functions
ctxt = engine.rootContext();
editor.initLists();
ctxt->setContextProperty("bridge", &bridge);
ctxt->setContextProperty("tilesList", QVariant::fromValue(bridge.tilesList));
ctxt->setContextProperty("wallsList", QVariant::fromValue(bridge.wallsList));
The "currentIndex" is the variable we will use to set the type of the selected item from the C++ side.
tTypeValue.onCurrentIndexChanged: bridge.setSelTileType(tTypeValue.currentIndex);
wTypeValue.onCurrentIndexChanged: bridge.setSelWallType(wTypeValue.currentIndex);
You can see how those values are handled in the C++ code by searching for the corresponding variables and functions.