diff --git a/src/block_data/BlockBase.h b/src/block_data/BlockBase.h index f6e3faa..fad1da1 100644 --- a/src/block_data/BlockBase.h +++ b/src/block_data/BlockBase.h @@ -49,6 +49,7 @@ class BlockBase : public BlockInterface Q_OBJECT Q_PROPERTY(bool focused MEMBER m_focused NOTIFY focusedChanged) + Q_PROPERTY(QString label READ getLabel WRITE setLabel NOTIFY labelChanged) public: // constructor etc: @@ -112,6 +113,11 @@ class BlockBase : public BlockInterface */ void focusedChanged(); + /** + * @brief labelChanged is emitted when the user changed the label text + */ + void labelChanged(); + public slots: QString getUid() const override { return m_uid; } void setUid(QString id) override { m_uid = id; } @@ -131,6 +137,8 @@ public slots: void deletedByUser() override; void onDeleteAnimationEnd() override; void makeBlocksConnectedToInputsVisible() override; + virtual QString getLabel() const override { return m_label; } + virtual void setLabel(QString value) override { m_label = value; emit labelChanged(); } protected: /** @@ -169,6 +177,11 @@ public slots: */ bool m_guiItemCompleted; + /** + * @brief m_label the user-chosen label text + */ + QString m_label; + }; #endif // BLOCKBASE_H diff --git a/src/block_data/BlockInterface.h b/src/block_data/BlockInterface.h index 549e2a6..f4bd815 100644 --- a/src/block_data/BlockInterface.h +++ b/src/block_data/BlockInterface.h @@ -207,7 +207,7 @@ class BlockInterface : public QObject { * @brief positionChangedExternal is emitted when the position was changed but not by the DragArea. * This is used by the DragArea to update the values in the kineticEffect. */ - void positionChangedExternal(); + void positionChangedExternal(); public slots: /** @@ -287,6 +287,17 @@ public slots: */ virtual void makeBlocksConnectedToInputsVisible() = 0; + /** + * @brief getLabel returns the user-chosen label text + * @return label text to show in DragArea + */ + virtual QString getLabel() const = 0; + /** + * @brief setLabel sets the label text + * @param value the new label text + */ + virtual void setLabel(QString value) = 0; + }; diff --git a/src/block_data/BlockManager.cpp b/src/block_data/BlockManager.cpp index 8b7c1d0..146abe6 100644 --- a/src/block_data/BlockManager.cpp +++ b/src/block_data/BlockManager.cpp @@ -108,6 +108,7 @@ BlockInterface* BlockManager::restoreBlock(const QJsonObject& blockState, bool a qWarning() << "Could not create block instance of type: " << blockType; return nullptr; } + block->setLabel(blockState["label"].toString()); block->setState(blockState["internalState"].toObject()); QQuickItem* guiItem = createGuiItem(block); if (!guiItem) { @@ -320,6 +321,7 @@ QJsonObject BlockManager::getBlockState(BlockInterface* block) const { blockState["posY"] = block->getGuiItem()->y() / dp; blockState["focused"] = getFocusedBlock() == block; blockState["nodeMergeModes"] = block->getNodeMergeModes(); + blockState["label"] = block->getLabel(); blockState["internalState"] = block->getState(); return blockState; } diff --git a/src/qml/BlockSettingsDrawerContent.qml b/src/qml/BlockSettingsDrawerContent.qml index 7328c83..f3ff8d3 100644 --- a/src/qml/BlockSettingsDrawerContent.qml +++ b/src/qml/BlockSettingsDrawerContent.qml @@ -1,14 +1,16 @@ import QtQuick 2.5 +import CustomElements 1.0 import "CustomControls" import "CustomBasics" VerticalScrollView { contentItem: root - Column { + StretchColumn { id: root width: parent.width height: implicitHeight + defaultSize: 30*dp Text { width: parent.width height: 30*dp @@ -43,11 +45,13 @@ VerticalScrollView { if (focusedBlock) { blockSettings.sourceComponent = focusedBlock.getSettingsComponent() blockTypeLabel.text = focusedBlock.getBlockName() + labelRow.visible = true + labelInput.text = focusedBlock.label } else { blockSettings.sourceComponent = noFocusedBlockDummy; blockTypeLabel.text = "" - } - //gc() + labelRow.visible = false + } } Connections { @@ -81,6 +85,32 @@ VerticalScrollView { } } } + BlockRow { + id: labelRow + implicitHeight: 0 // do not stretch + height: 30*dp + leftMargin: 15*dp + rightMargin: 15*dp + + Text { + text: "Label:" + width: 90*dp + } + TextInput { + id: labelInput + text: "" + width: parent.width - 120*dp + inputMethodHints: Qt.ImhPreferLatin + onDisplayTextChanged: { + var focusedBlock = controller.blockManager().getFocusedBlock() + if (focusedBlock) { + if (focusedBlock.label !== displayText) { + focusedBlock.label = displayText + } + } + } + } + } HorizontalDivider { // ------------------------------------------------------ } diff --git a/src/qml/Blocks/DimmerBlock.qml b/src/qml/Blocks/DimmerBlock.qml index d539f97..a18a60d 100644 --- a/src/qml/Blocks/DimmerBlock.qml +++ b/src/qml/Blocks/DimmerBlock.qml @@ -79,22 +79,8 @@ BlockBase { StretchColumn { leftMargin: 15*dp rightMargin: 15*dp - defaultSize: 30*dp + defaultSize: 30*dp - BlockRow { - Text { - text: "Name:" - width: parent.width / 2 - } - TextInput { - text: block.getName() - width: parent.width / 2 - inputMethodHints: Qt.ImhPreferLatin - onDisplayTextChanged: { - block.setName(displayText) - } - } - } BlockRow { StretchText { text: "Channel:" diff --git a/src/qml/CustomBasics/BlockBase.qml b/src/qml/CustomBasics/BlockBase.qml index a4700af..fa9c267 100644 --- a/src/qml/CustomBasics/BlockBase.qml +++ b/src/qml/CustomBasics/BlockBase.qml @@ -53,7 +53,7 @@ Rectangle { Component { id: noSettings Item { - height: 60*dp + implicitHeight: 60*dp Text { anchors.centerIn: parent diff --git a/src/qml/CustomBasics/DragArea.qml b/src/qml/CustomBasics/DragArea.qml index 8a8ff4e..f561f52 100644 --- a/src/qml/CustomBasics/DragArea.qml +++ b/src/qml/CustomBasics/DragArea.qml @@ -10,7 +10,7 @@ Item { z: -1 // public - property alias text: text.text + property string text: "" default property alias content: contentItem.data // -------------------------- Visuals ----------------------------------- @@ -29,7 +29,6 @@ Item { } Text { - id: text color: block.focused ? Qt.rgba(0.9, 0.8, 0.0, 0.5) : "#999" font.family: "Quicksand" font.weight: Font.Bold @@ -38,6 +37,7 @@ Item { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter fontSizeMode: Text.Fit + text: block.label || root.text } Item { diff --git a/src/qml/CustomControls/SvgButton.qml b/src/qml/CustomControls/SvgButton.qml index 462b108..0f026ff 100644 --- a/src/qml/CustomControls/SvgButton.qml +++ b/src/qml/CustomControls/SvgButton.qml @@ -1,4 +1,5 @@ import QtQuick 2.5 +import QtQuick.Window 2.0 import CustomElements 1.0 import "../CustomBasics" @@ -36,6 +37,9 @@ CustomTouchArea { source: "qrc:/images/svg/" + iconName + ".svg" fillMode: Image.PreserveAspectFit smooth: true + + // render in double resolution to be antialiased and smooth: + sourceSize.width: width * Screen.devicePixelRatio * 2 } Rectangle {