modified: CMakeLists.txt
modified: src/MainWindow.cpp modified: src/MainWindow.h modified: src/items/ArrowItem.cpp modified: src/items/ArrowItem.h modified: src/items/BlockItem.cpp modified: src/items/BlockItem.h modified: src/items/DiagramScene.cpp modified: src/items/DiagramScene.h new file: src/items/HeaderFooterItem.cpp new file: src/items/HeaderFooterItem.h modified: src/items/JunctionItem.cpp modified: src/items/JunctionItem.h modified: src/main.cpp
This commit is contained in:
parent
abdbae5a11
commit
f6f0598ff2
14 changed files with 2543 additions and 96 deletions
|
|
@ -1,10 +1,14 @@
|
|||
#include "JunctionItem.h"
|
||||
#include "ArrowItem.h"
|
||||
#include "items/DiagramScene.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <cmath>
|
||||
|
||||
QColor JunctionItem::s_normalColor = QColor(30, 30, 30);
|
||||
QColor JunctionItem::s_selectedColor = QColor(40, 100, 255);
|
||||
|
||||
JunctionItem::JunctionItem(QGraphicsItem* parent, int id)
|
||||
: QGraphicsObject(parent),
|
||||
m_id(id)
|
||||
|
|
@ -20,10 +24,15 @@ QRectF JunctionItem::boundingRect() const {
|
|||
void JunctionItem::paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*) {
|
||||
p->setRenderHint(QPainter::Antialiasing, true);
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(isSelected() ? QColor(40, 100, 255) : QColor(30, 30, 30));
|
||||
p->setBrush(isSelected() ? s_selectedColor : s_normalColor);
|
||||
p->drawEllipse(QPointF(0, 0), m_radius, m_radius);
|
||||
}
|
||||
|
||||
void JunctionItem::setVisualTheme(const QColor& normalColor, const QColor& selectedColor) {
|
||||
s_normalColor = normalColor;
|
||||
s_selectedColor = selectedColor;
|
||||
}
|
||||
|
||||
void JunctionItem::addArrow(ArrowItem* a) {
|
||||
m_arrows.insert(a);
|
||||
}
|
||||
|
|
@ -38,6 +47,20 @@ bool JunctionItem::hitTest(const QPointF& scenePos, qreal radius) const {
|
|||
}
|
||||
|
||||
QVariant JunctionItem::itemChange(GraphicsItemChange change, const QVariant& value) {
|
||||
if (change == ItemPositionChange) {
|
||||
const QPointF desired = value.toPointF();
|
||||
if (auto* ds = qobject_cast<DiagramScene*>(scene())) {
|
||||
QRectF bounds = ds->contentRect();
|
||||
if (bounds.isNull()) bounds = ds->sceneRect();
|
||||
QRectF rect = boundingRect().translated(desired);
|
||||
QPointF clamped = desired;
|
||||
if (rect.left() < bounds.left()) clamped.setX(desired.x() + (bounds.left() - rect.left()));
|
||||
if (rect.right() > bounds.right()) clamped.setX(clamped.x() - (rect.right() - bounds.right()));
|
||||
if (rect.top() < bounds.top()) clamped.setY(desired.y() + (bounds.top() - rect.top()));
|
||||
if (rect.bottom() > bounds.bottom()) clamped.setY(clamped.y() - (rect.bottom() - bounds.bottom()));
|
||||
return clamped;
|
||||
}
|
||||
}
|
||||
if (change == ItemPositionHasChanged || change == ItemTransformHasChanged) {
|
||||
for (ArrowItem* a : m_arrows) {
|
||||
if (a) a->updatePath();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue