Skip to content

Commit

Permalink
#41 started
Browse files Browse the repository at this point in the history
  • Loading branch information
ArsMasiuk committed Nov 21, 2021
1 parent 1e6faae commit b49629f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
30 changes: 21 additions & 9 deletions src/qvgelib/CEditorScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This file is a part of
QVGE - Qt Visual Graph Editor
(c) 2016 Ars L.Masiuk([email protected])
(c) 2016-2021 Ars L. Masiuk L.Masiuk([email protected])
It can be used freely, maintaining the information above.
*/
Expand Down Expand Up @@ -106,24 +106,36 @@ void CEditorScene::initialize()
m_classAttributesConstrains.clear();

// default item attrs
createClassAttribute(class_item, "label", "Label", "", ATTR_NODEFAULT | ATTR_FIXED, nullptr, true);
createClassAttribute(class_item, "label.color", "Label Color", QColor(Qt::black));
createClassAttribute(class_item, "label", tr("Label"), "", ATTR_NODEFAULT | ATTR_FIXED, nullptr, true);
createClassAttribute(class_item, "label.color", tr("Label Color"), QColor(Qt::black));

QFont labelFont;
CAttribute labelFontAttr("label.font", "Label Font", labelFont, ATTR_FIXED);
CAttribute labelFontAttr("label.font", tr("Label Font"), labelFont, ATTR_FIXED);
setClassAttribute(class_item, labelFontAttr);

createClassAttribute(class_item, "id", "ID", "", ATTR_NODEFAULT | ATTR_FIXED, nullptr, true);
createClassAttribute(class_item, "id", tr("ID"), "", ATTR_NODEFAULT | ATTR_FIXED, nullptr, true);

// labels position
static CAttributeConstrainsEnum *labelsPositions = new CAttributeConstrainsEnum();
if (labelsPositions->ids.isEmpty())
{
labelsPositions->names << tr("Center") << tr("Top") << tr("Bottom") << tr("Left") << tr("Right");
labelsPositions->ids << Center << Top << Bottom << Left << Right;
}

createClassAttribute(class_node, attr_label_position, tr("Label Position"), Center, ATTR_FIXED, labelsPositions);
//createClassAttribute(class_scene, attr_label_position, tr("Labels Position"), Center, ATTR_FIXED, labelsPositions);


// labels policy
static CAttributeConstrainsEnum *labelsPolicy = new CAttributeConstrainsEnum();
if (labelsPolicy->ids.isEmpty()) {
if (labelsPolicy->ids.isEmpty())
{
labelsPolicy->names << tr("Auto") << tr("Always On") << tr("Always Off");
labelsPolicy->ids << Auto << AlwaysOn << AlwaysOff;
}

createClassAttribute(class_scene, attr_labels_policy, "Labels Policy", Auto, ATTR_FIXED, labelsPolicy);
createClassAttribute(class_scene, attr_labels_policy, tr("Labels Policy"), Auto, ATTR_FIXED, labelsPolicy);
}


Expand Down Expand Up @@ -1331,8 +1343,8 @@ void CEditorScene::layoutItemLabels()
return;
}

QElapsedTimer tm;
tm.start();
//QElapsedTimer tm;
//tm.start();

// else layout texts
for (auto citem : allItems)
Expand Down
4 changes: 4 additions & 0 deletions src/qvgelib/CEditorScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class CEditorScene : public QGraphicsScene
bool itemLabelsEnabled() const { return m_labelsEnabled; }
bool itemLabelsNeedUpdate() const { return m_labelsUpdate; }

enum LabelsPosition {
Center, Top, Bottom, Left, Right
};

enum LabelsPolicy {
Auto, AlwaysOn, AlwaysOff
};
Expand Down
1 change: 1 addition & 0 deletions src/qvgelib/CEditorSceneDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const QByteArray attr_stroke_size = QByteArrayLiteral("stroke.size");
const QByteArray attr_label = QByteArrayLiteral("label");
const QByteArray attr_label_font = QByteArrayLiteral("label.font");
const QByteArray attr_label_color = QByteArrayLiteral("label.color");
const QByteArray attr_label_position = QByteArrayLiteral("label.position");
const QByteArray attr_labels_policy = QByteArrayLiteral("labels.policy");
const QByteArray attr_labels_visIds = QByteArrayLiteral("labels.visibleIds");
const QByteArray attr_edge_direction = QByteArrayLiteral("direction");
25 changes: 22 additions & 3 deletions src/qvgelib/CNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,11 +964,30 @@ void CNode::updateLabelPosition()
int w = m_labelItem->boundingRect().width();
int h = m_labelItem->boundingRect().height();

auto labelPos = (CEditorScene::LabelsPosition) getAttribute(QByteArrayLiteral("label.position")).toInt();

QRectF r = Shape::boundingRect();
if (r.width() < 16 || r.height() < 16)
m_labelItem->setPos(-w / 2, boundingRect().height() / 2); // if too small: put label at the bottom
else

switch (labelPos)
{
case CEditorScene::Top:
m_labelItem->setPos(-w / 2, -boundingRect().height() / 2 - h);
break;

case CEditorScene::Bottom:
m_labelItem->setPos(-w / 2, boundingRect().height() / 2);
break;

default:
m_labelItem->setPos(-w / 2, -h / 2); // else center
break;
}


//if (r.width() < 16 || r.height() < 16)
// m_labelItem->setPos(-w / 2, boundingRect().height() / 2); // if too small: put label at the bottom
//else
// m_labelItem->setPos(-w / 2, -h / 2); // else center
}


Expand Down
2 changes: 1 addition & 1 deletion win32/build_msvc_2017_64/makevc.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
call "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"

c:\Qt5.7\5.13.2\msvc2017_64\bin\qmake -r ../../src/qvge.pro -tp vc -recursive
c:\Qt\5.13.2\msvc2017_64\bin\qmake -r ../../src/qvge.pro -tp vc -recursive
2 changes: 1 addition & 1 deletion win32/build_msvc_2019_64/makevc.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
call "c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"

c:\Qt5.7\5.15.1\msvc2019_64\bin\qmake -r ../../src/qvge.pro -tp vc -recursive
c:\Qt\5.15.1\msvc2019_64\bin\qmake -r ../../src/qvge.pro -tp vc -recursive

0 comments on commit b49629f

Please sign in to comment.