Skip to content

Commit

Permalink
#238 WIP.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Aug 12, 2024
1 parent af33391 commit 3552e90
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/RectGroupTemplate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Item {
default property alias children : content.children

// Binded to Tpp.Group.container in Tpp.Group.
property alias content: content
property alias container: content

property var groupItem: undefined

Expand All @@ -70,9 +70,8 @@ Item {

RectGradientBackground { // Node background and shadow with backOpacity and backRadius support
id: groupBackground
//anchors.fill: content // Note 20160328: Do not set as content child to avoid interferring
anchors.fill: parent
style: template.groupItem ? template.groupItem.style: undefined // with content.childrenRect
style: template.groupItem ? template.groupItem.style: undefined // with container.childrenRect
visible: !groupItem.collapsed
}

Expand All @@ -83,12 +82,6 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: false
Layout.alignment: Qt.AlignTop | Qt.AlignLeft
// x: 0
// y: -2 - Math.max(collapser.height, // Shift header by the size of collapser button or the label
// groupLabel.contentHeight, labelEditor.height) // height (for large font size) plus 2px margin
// z: 2
//width: content.width; height: collapser.height
//Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
spacing: 0
ToolButton {
id: collapser
Expand All @@ -114,7 +107,9 @@ Item {
LabelEditor {
clip: false
id: labelEditor
anchors.top: parent.top; anchors.left: parent.left; anchors.right: parent.right
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
target: groupItem && groupItem.group ? groupItem.group : undefined
visible: false
bold: groupItem.style.fontBold
Expand Down
3 changes: 0 additions & 3 deletions src/qanDraggable.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@

#pragma once

// Std headers
#include <memory>

// Qt headers
#include <QObject> // Q_DECLARE_INTERFACE
#include <QPointer>
Expand Down
20 changes: 19 additions & 1 deletion src/qanDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,32 @@ void DraggableCtrl::handleMouseReleaseEvent(QMouseEvent* event)

void DraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragSelection, bool notify)
{
//qWarning() << "DraggableCtrl::beginDragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection << " notify=" << notify;
qWarning() << "DraggableCtrl::beginDragMove(): target=" << getTargetItem() << " dragSelection=" << dragSelection << " notify=" << notify;
if (_targetItem == nullptr ||
_target == nullptr)
return;
if (_target->getIsProtected() || // Prevent dragging of protected or locked objects
_target->getLocked())
return;

if (_target->isGroup()) {
const auto groupItem = qobject_cast<qan::GroupItem*>(_targetItem);
// Convert sceneDragPos to group item local coordinates
const auto groupItemDragPos = _targetItem->mapFromScene(sceneDragPos);
qWarning() << " groupItem=" << groupItem;
qWarning() << " groupItemDragPos=" << groupItemDragPos;
qWarning() << " groupItem->getContainer()=" << groupItem->getContainer();
if (groupItem != nullptr) {
if ((groupItem->getDragPolicy() & qan::GroupItem::DragPolicy::Header) == qan::GroupItem::DragPolicy::Header) {
if (groupItemDragPos.y() > groupItem->getContainer()->y())
return;
} else if ((groupItem->getDragPolicy() & qan::GroupItem::DragPolicy::Container) == qan::GroupItem::DragPolicy::Container) {

} else
return;
}
}

const auto graph = getGraph();
if (graph == nullptr)
return;
Expand Down
11 changes: 11 additions & 0 deletions src/qanGroupItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ void GroupItem::setCollapsed(bool collapsed) noexcept
//-----------------------------------------------------------------------------

/* Group DnD Management *///---------------------------------------------------
bool GroupItem::setDragPolicy(DragPolicy dragPolicy) noexcept
{
if (dragPolicy != _dragPolicy) {
_dragPolicy = dragPolicy;
return true;
}
return false;
}
GroupItem::DragPolicy GroupItem::getDragPolicy() noexcept { return _dragPolicy; }
const GroupItem::DragPolicy GroupItem::getDragPolicy() const noexcept { return _dragPolicy; }

void GroupItem::groupMoved()
{
if (getCollapsed()) // Do not update edges when the group is collapsed
Expand Down
27 changes: 27 additions & 0 deletions src/qanGroupItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ class GroupItem : public qan::NodeItem

/*! \name Dragging Support Management *///---------------------------------
//@{
public:
//! FIXME #238
enum class DragPolicy : unsigned int {
//! Undefined / No dragging.
Undefined = 0,
//! Allow dragging group in the group header.
Header = 2,
//! Allow dragging group in the group content.
Container = 2
};
Q_ENUM(DragPolicy)

Q_PROPERTY(DragPolicy dragPolicy READ getDragPolicy WRITE setDragPolicy NOTIFY dragPolicyChanged FINAL)
virtual bool setDragPolicy(DragPolicy dragPolicy) noexcept;
DragPolicy getDragPolicy() noexcept;
const DragPolicy getDragPolicy() const noexcept;
protected:
DragPolicy _dragPolicy = DragPolicy::Header;
signals:
void dragPolicyChanged();


protected slots:
//! Group is monitored for position change, since group's nodes edges should be updated manually in that case.
void groupMoved();
Expand Down Expand Up @@ -175,6 +197,11 @@ protected slots:
//-------------------------------------------------------------------------
};

// Define the bitwise AND operator for MyEnum
inline GroupItem::DragPolicy operator&(GroupItem::DragPolicy lhs, GroupItem::DragPolicy rhs) {
return static_cast<GroupItem::DragPolicy>(static_cast<unsigned int>(lhs) & static_cast<unsigned int>(rhs));
}

} // ::qan

QML_DECLARE_TYPE(qan::GroupItem)

0 comments on commit 3552e90

Please sign in to comment.