7#include <QtDesigner/abstractformwindow.h>
9#include <QtWidgets/qapplication.h>
10#include <QtWidgets/qmenu.h>
12#include <QtGui/qaction.h>
13#include <QtGui/qpainter.h>
14#include <QtGui/qevent.h>
15#include <QtGui/qfontmetrics.h>
16#include <QtGui/qpixmap.h>
17#include <QtGui/qtransform.h>
19#include <QtCore/qmap.h>
32
33
37 return QRect(r.x(), r.y(), r.width() - 1, r.height() - 1);
42 return QRect(r.x() - i, r.y() - i, r.width() + 2*i, r.height() + 2*i);
47 const QRect r(pos + QPoint(-LINE_PROXIMITY_RADIUS, -LINE_PROXIMITY_RADIUS),
48 QSize(2*LINE_PROXIMITY_RADIUS, 2*LINE_PROXIMITY_RADIUS));
54 const QPoint mid = r.center();
55 p->drawLine(mid.x(), r.top(), mid.x(), mid.y());
56 p->drawLine(r.left(), mid.y(), r.right(), mid.y());
57 int y = r.top() + 4*r.height()/6;
59 p->drawLine(r.left() + x, y, r.right() - x, y);
60 y = r.top() + 5*r.height()/6;
62 p->drawLine(r.left() + x, y, r.right() - x, y);
63 p->drawLine(mid.x(), r.bottom(), mid.x() + 1, r.bottom());
68 const QRect r(pos + QPoint(-LINE_PROXIMITY_RADIUS, -LINE_PROXIMITY_RADIUS),
69 QSize(2*LINE_PROXIMITY_RADIUS, 2*LINE_PROXIMITY_RADIUS));
70 p->fillRect(fixRect(r), p->pen().color());
76 return p1.y() < p2.y() ? qdesigner_internal::CETypes::DownDir : qdesigner_internal::CETypes::UpDir;
77 Q_ASSERT(p1.y() == p2.y());
78 return p1.x() < p2.x() ? qdesigner_internal::CETypes::RightDir : qdesigner_internal::CETypes::LeftDir;
85 else if (p.x() > r.right())
90 else if (p.y() > r.bottom())
99
100
133 const QPoint &old_source_pos,
134 const QPoint &old_target_pos,
135 const QPoint &new_source_pos,
136 const QPoint &new_target_pos);
141 const QPoint m_old_source_pos;
142 const QPoint m_old_target_pos;
143 const QPoint m_new_source_pos;
144 const QPoint m_new_target_pos;
148 const QPoint &old_source_pos,
149 const QPoint &old_target_pos,
150 const QPoint &new_source_pos,
151 const QPoint &new_target_pos) :
159 setText(QApplication::translate(
"Command",
"Adjust connection"));
164 m_con->setEndPoint(EndPoint::Source, m_con->widget(EndPoint::Source), m_old_source_pos);
165 m_con->setEndPoint(EndPoint::Target, m_con->widget(EndPoint::Target), m_old_target_pos);
170 m_con->setEndPoint(EndPoint::Source, m_con->widget(EndPoint::Source), m_new_source_pos);
171 m_con->setEndPoint(EndPoint::Target, m_con->widget(EndPoint::Target), m_new_target_pos);
217 const EndPoint::Type m_type;
218 QObject *m_old_widget, *m_new_widget;
219 const QPoint m_old_pos;
224 EndPoint::Type type, QObject *object) :
232 if (QWidget *widget = qobject_cast<QWidget*>(object)) {
233 m_new_pos = edit->widgetRect(widget).center();
236 if (m_type == EndPoint::Source)
237 setText(QApplication::translate(
"Command",
"Change source"));
239 setText(QApplication::translate(
"Command",
"Change target"));
244 m_con->setEndPoint(m_type, m_new_widget, m_new_pos);
245 emit edit()->connectionChanged(m_con);
250 m_con->setEndPoint(m_type, m_old_widget, m_old_pos);
251 emit edit()->connectionChanged(m_con);
255
256
334 switch (classifyLine(p1, p2)) {
336 result = QPoint(p1.x(), rect.bottom());
338 case CETypes::DownDir:
339 result = QPoint(p1.x(), rect.top());
341 case CETypes::LeftDir:
342 result = QPoint(rect.right(), p1.y());
344 case CETypes::RightDir:
345 result = QPoint(rect.left(), p1.y());
356 switch (classifyLine(p1, p2)) {
358 result.append(p2 + QPoint(0, 1));
362 case CETypes::DownDir:
367 case CETypes::LeftDir:
368 result.append(p2 + QPoint(1, 0));
372 case CETypes::RightDir:
384 CETypes::LineDir result = CETypes::UpDir;
385 int min = p.y() - r.top();
387 int d = p.x() - r.left();
390 result = CETypes::LeftDir;
393 d = r.bottom() - p.y();
396 result = CETypes::DownDir;
399 d = r.right() - p.x();
402 result = CETypes::RightDir;
410 if (l1.x() == l2.x())
411 return p.x() >= l1.x();
412 return p.y() <= l1.y() + (p.x() - l1.x())*(l2.y() - l1.y())/(l2.x() - l1.x());
440
441
442
443
444
445
446
447
448
449
450
451
475
476
477
478
479
480
481
482
483
484
485
503
504
505
506
507
508
509
515
516
517
518
519
520
521
522
523
524
525
526
544
545
546
547
548
549
550
551
552
553
558
559
560
561
562
563
564
565
566
567
568
678 const QPoint c(qMin(a.x(), b.x()), qMin(a.y(), b.y()));
679 const QPoint d(qMax(a.x(), b.x()), qMax(a.y(), b.y()));
682 return expand(result, LINE_PROXIMITY_RADIUS);
901
902
1100#if QT_CONFIG(cursor)
1193#if QT_CONFIG(cursor)
1228#if QT_CONFIG(cursor)
1251#if QT_CONFIG(cursor)
1331template <
class ObjectIterator>
1334 ConnectionEdit::ConnectionSet rc;
1336 const auto ccend = cl.cend();
1337 for ( ; oi1 != oi2; ++oi1) {
1338 for (
auto cit = cl.constBegin(); cit != ccend; ++cit) {
1339 Connection *con = *cit;
1340 if (con->object(ConnectionEdit::EndPoint::Source) == *oi1 || con->object(ConnectionEdit::EndPoint::Target) == *oi1)
1341 rc.insert(con, con);
void redo() override
Applies a change to the document.
AdjustConnectionCommand(ConnectionEdit *edit, Connection *con, const QPoint &old_source_pos, const QPoint &old_target_pos, const QPoint &new_source_pos, const QPoint &new_target_pos)
void undo() override
Reverts a change to the document.
void undo() override
Reverts a change to the document.
SetEndPointCommand(ConnectionEdit *edit, Connection *con, EndPoint::Type type, QObject *object)
void redo() override
Applies a change to the document.
static const int VLABEL_MARGIN
static QT_BEGIN_NAMESPACE const int BG_ALPHA
static qdesigner_internal::CETypes::LineDir classifyLine(const QPoint &p1, const QPoint &p2)
static QRect fixRect(const QRect &r)
static QPoint pointInsideRect(const QRect &r, QPoint p)
static QRect expand(const QRect &r, int i)
static const int LINE_PROXIMITY_RADIUS
static const int LOOP_MARGIN
static const int GROUND_H
static const int HLABEL_MARGIN
static QRect endPointRectHelper(const QPoint &pos)
static const int GROUND_W
static void paintGround(QPainter *p, QRect r)
static void paintEndPoint(QPainter *p, const QPoint &pos)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static bool pointAboveLine(const QPoint &l1, const QPoint &l2, const QPoint &p)
static QPolygonF arrowHead(const QPoint &p1, const QPoint &p2)
static QRect lineRect(const QPoint &a, const QPoint &b)
static QPoint lineEntryPos(const QPoint &p1, const QPoint &p2, const QRect &rect)
static ConnectionEdit::ConnectionSet findConnectionsOf(const ConnectionEdit::ConnectionList &cl, ObjectIterator oi1, const ObjectIterator &oi2)
static CETypes::LineDir closestEdge(const QPoint &p, const QRect &r)