Skip to content

Commit

Permalink
#238 more efficient labelEditorVisible / expandButtonVisible group it…
Browse files Browse the repository at this point in the history
…em properties management from c++.

WIP.

Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Aug 12, 2024
1 parent 7d7568e commit 2409a6d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 37 deletions.
8 changes: 2 additions & 6 deletions src/Group.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import QtQuick.Layouts
import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan

//! \brief Default delegate for `qan::GroupItem`.
Qan.GroupItem {
id: groupItem

Expand All @@ -47,12 +48,7 @@ Qan.GroupItem {

default property alias children : template
container: template.container // See qan::GroupItem::container property documentation

//! Show or hide group top left label editor (default to visible).
property alias labelEditorVisible : template.labelEditorVisible

//! Show or hide group top left expand button (default to visible).
property alias expandButtonVisible : template.expandButtonVisible
labelEditorVisible: template.labelEditorVisible

Qan.RectGroupTemplate {
id: template
Expand Down
10 changes: 6 additions & 4 deletions src/LabelEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ Loader {
//! Editor target node or group (or any Qan primitive with a \c label property).
property var target: undefined

property bool bold: false
property real pixelSize: 12
property real fontPixelSize: 11

onVisibleChanged: {
if (visible && !item)
Expand Down Expand Up @@ -101,8 +100,8 @@ Loader {
anchors.left: parent.left
anchors.right: parent.right
text: target ? target.label : ""
font.bold: labelEditorLoader.bold
font.pixelSize: labelEditorLoader.pixelSize
font.bold: false
font.pixelSize: 22
onAccepted: {
if (target &&
text.length !== 0)
Expand All @@ -115,6 +114,9 @@ Loader {
text !== target.label) // Ensure that last edition text is removed
text = target.label // for exemple if edition has been interrupted in a focus change
}
background: Rectangle {
color: Qt.rgba(0., 0., 0., 0.) // Disable editor background
}
Keys.onEscapePressed: {
// Cancel edition on escape
labelEditorLoader.visible = false;
Expand Down
30 changes: 11 additions & 19 deletions src/RectGroupTemplate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ Item {
property var groupItem: undefined

//! Show or hide group top left label editor (default to visible).
property alias labelEditorVisible : labelEditorControl.visible

//! Show or hide group top left expand button (default to visible).
property alias expandButtonVisible : collapser.visible
readonly property alias labelEditorVisible: labelEditorControl.visible

property alias header: headerLayout

Expand Down Expand Up @@ -92,50 +89,45 @@ Item {
font.pixelSize: 13
font.bold: true
onClicked: groupItem.collapsed = !groupItem.collapsed
visible: groupItem?.expandButtonVisible
}
Item {
id: labelEditorControl
clip: false
Layout.fillWidth: true
Layout.fillHeight: true
property int fontPointSize : groupItem.style.fontPointSize // Do not set pointSize for -1 value
onFontPointSizeChanged: {
if (fontPointSize != -1)
labelEditor.pixelSize = fontPointSize
groupLabel.font.pointSize = fontPointSize
}
property int labelPointSize : groupItem?.style?.fontPointSize || Material.fontSize
LabelEditor {
clip: false
id: labelEditor
clip: false
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
target: groupItem && groupItem.group ? groupItem.group : undefined
target: groupItem?.group
visible: false
bold: groupItem.style.fontBold
fontPixelSize: labelEditorControl.labelPointSize
}
Label {
id: groupLabel
anchors.fill: parent
anchors.leftMargin: collapser.visible ? 0 : 10
text: groupItem &&
groupItem.group ? groupItem.group.label :
" "
visible: !labelEditor.visible
verticalAlignment: Text.AlignVCenter
font.bold: groupItem.style.fontBold
color: groupItem &&
groupItem.style &&
groupItem.style.labelColor ? groupItem.style.labelColor : "black"
font.pointSize: labelEditorControl.labelPointSize
color: groupItem?.style?.labelColor || "black"
elide: Text.ElideRight
/*MouseArea {
MouseArea {
anchors.fill: parent
enabled: !groupItem.group.isProtected &&
!groupItem.group.locked // Do not allow dragging of locked groups
preventStealing: true
propagateComposedEvents: true // Ensure event are forwarded to collapserArea
drag.target: groupItem.draggable ? groupItem : null
onDoubleClicked: labelEditor.visible = true
}*/
}
}
} // labelEditor Item
} // RowLayout: collapser + label
Expand Down
8 changes: 2 additions & 6 deletions src/TableGroup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import QtQuick
import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan

//! \brief Default delegate for `qan::TableGroup`.
//! \brief Default delegate for `qan::TableGroupItem`.
Qan.TableGroupItem {
id: tableGroupItem

Expand All @@ -47,11 +47,7 @@ Qan.TableGroupItem {

default property alias children : template
container: template.container // See qan::GroupItem::container property documentation

//! Show or hide group top left label editor (default to visible).
property bool labelEditorVisible : false
//! Show or hide group top left expand button (default to visible).
property bool expandButtonVisible : false
labelEditorVisible: template.labelEditorVisible
Qan.RectGroupTemplate {
id: template
anchors.fill: parent
Expand Down
8 changes: 7 additions & 1 deletion src/qanGroupItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ auto GroupItem::setRect(const QRectF& r) noexcept -> void
//-----------------------------------------------------------------------------


/* Collapse Management *///----------------------------------------------------
/* Collapse / Edition Management *///------------------------------------------
void GroupItem::setCollapsed(bool collapsed) noexcept
{
qan::NodeItem::setCollapsed(collapsed);
Expand All @@ -114,6 +114,12 @@ void GroupItem::setCollapsed(bool collapsed) noexcept
groupMoved(); // Force update of all adjacent edges
}
}

void GroupItem::setExpandButtonVisible(bool expandButtonVisible) { _expandButtonVisible = expandButtonVisible; emit expandButtonVisibleChanged(); }
bool GroupItem::getExpandButtonVisible() const { return _expandButtonVisible; }

void GroupItem::setLabelEditorVisible(bool labelEditorVisible) { _labelEditorVisible = labelEditorVisible; emit labelEditorVisibleChanged(); }
bool GroupItem::getLabelEditorVisible() const { return _labelEditorVisible; }
//-----------------------------------------------------------------------------

/* Group DnD Management *///---------------------------------------------------
Expand Down
30 changes: 29 additions & 1 deletion src/qanGroupItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,38 @@ class GroupItem : public qan::NodeItem
//@}
//-------------------------------------------------------------------------

/*! \name Collapse Management *///-----------------------------------------
/*! \name Collapse / Edition Management *///-------------------------------
//@{
protected:
virtual void setCollapsed(bool collapsed) noexcept override;

public:
//! \copydoc getExpandButtonVisible()
Q_PROPERTY(bool expandButtonVisible READ getExpandButtonVisible WRITE setExpandButtonVisible NOTIFY expandButtonVisibleChanged FINAL)
//! \copydoc getExpandButtonVisible()
void setExpandButtonVisible(bool expandButtonVisible);
//! \brief Show / hide the group expand / collapse button.
bool getExpandButtonVisible() const;
private:
//! \copydoc getExpandButtonVisible()
bool _expandButtonVisible = true;
signals:
//! \copydoc getExpandButtonVisible()
void expandButtonVisibleChanged();

public:
//! \copydoc getLabelEditorVisible()
Q_PROPERTY(bool labelEditorVisible READ getLabelEditorVisible WRITE setLabelEditorVisible NOTIFY labelEditorVisibleChanged FINAL)
//! \copydoc getLabelEditorVisible()
void setLabelEditorVisible(bool labelEditorVisible);
//! \brief True when the group label in group editor is beeing edited.
bool getLabelEditorVisible() const;
private:
//! \copydoc getLabelEditorVisible()
bool _labelEditorVisible = false;
signals:
//! \copydoc getLabelEditorVisible()
void labelEditorVisibleChanged();
//@}
//-------------------------------------------------------------------------

Expand Down

0 comments on commit 2409a6d

Please sign in to comment.