8#include <QtDesigner/abstractformwindow.h>
10#include <QtWidgets/qapplication.h>
11#include <QtWidgets/qmenu.h>
13#include <QtGui/qaction.h>
14#include <QtGui/qpainter.h>
15#include <QtGui/qevent.h>
16#include <QtGui/qfontmetrics.h>
17#include <QtGui/qpixmap.h>
18#include <QtGui/qtransform.h>
20#include <QtCore/qmap.h>
33
34
38 return QRect(r.x(), r.y(), r.width() - 1, r.height() - 1);
43 return QRect(r.x() - i, r.y() - i, r.width() + 2*i, r.height() + 2*i);
55 const QPoint mid = r.center();
56 p->drawLine(mid.x(), r.top(), mid.x(), mid.y());
57 p->drawLine(r.left(), mid.y(), r.right(), mid.y());
58 int y = r.top() + 4*r.height()/6;
60 p->drawLine(r.left() + x, y, r.right() - x, y);
61 y = r.top() + 5*r.height()/6;
63 p->drawLine(r.left() + x, y, r.right() - x, y);
64 p->drawLine(mid.x(), r.bottom(), mid.x() + 1, r.bottom());
71 p->fillRect(fixRect(r), p->pen().color());
77 return p1.y() < p2.y() ? qdesigner_internal::CETypes::DownDir : qdesigner_internal::CETypes::UpDir;
78 Q_ASSERT(p1.y() == p2.y());
79 return p1.x() < p2.x() ? qdesigner_internal::CETypes::RightDir : qdesigner_internal::CETypes::LeftDir;
86 else if (p.x() > r.right())
91 else if (p.y() > r.bottom())
100
101
134 const QPoint &old_source_pos,
135 const QPoint &old_target_pos,
136 const QPoint &new_source_pos,
137 const QPoint &new_target_pos);
142 const QPoint m_old_source_pos;
143 const QPoint m_old_target_pos;
144 const QPoint m_new_source_pos;
145 const QPoint m_new_target_pos;
149 const QPoint &old_source_pos,
150 const QPoint &old_target_pos,
151 const QPoint &new_source_pos,
152 const QPoint &new_target_pos) :
160 setText(QApplication::translate(
"Command",
"Adjust connection"));
165 m_con->setEndPoint(EndPoint::Source, m_con->widget(EndPoint::Source), m_old_source_pos);
166 m_con->setEndPoint(EndPoint::Target, m_con->widget(EndPoint::Target), m_old_target_pos);
171 m_con->setEndPoint(EndPoint::Source, m_con->widget(EndPoint::Source), m_new_source_pos);
172 m_con->setEndPoint(EndPoint::Target, m_con->widget(EndPoint::Target), m_new_target_pos);
218 const EndPoint::Type m_type;
219 QObject *m_old_widget, *m_new_widget;
220 const QPoint m_old_pos;
225 EndPoint::Type type, QObject *object) :
233 if (QWidget *widget = qobject_cast<QWidget*>(object)) {
234 m_new_pos = edit->widgetRect(widget).center();
237 if (m_type == EndPoint::Source)
238 setText(QApplication::translate(
"Command",
"Change source"));
240 setText(QApplication::translate(
"Command",
"Change target"));
245 m_con->setEndPoint(m_type, m_new_widget, m_new_pos);
246 emit edit()->connectionChanged(m_con);
251 m_con->setEndPoint(m_type, m_old_widget, m_old_pos);
252 emit edit()->connectionChanged(m_con);
256
257
335 switch (classifyLine(p1, p2)) {
337 result = QPoint(p1.x(), rect.bottom());
339 case CETypes::DownDir:
340 result = QPoint(p1.x(), rect.top());
342 case CETypes::LeftDir:
343 result = QPoint(rect.right(), p1.y());
345 case CETypes::RightDir:
346 result = QPoint(rect.left(), p1.y());
357 switch (classifyLine(p1, p2)) {
359 result.append(p2 + QPoint(0, 1));
363 case CETypes::DownDir:
368 case CETypes::LeftDir:
369 result.append(p2 + QPoint(1, 0));
373 case CETypes::RightDir:
385 CETypes::LineDir result = CETypes::UpDir;
386 int min = p.y() - r.top();
388 int d = p.x() - r.left();
391 result = CETypes::LeftDir;
394 d = r.bottom() - p.y();
397 result = CETypes::DownDir;
400 d = r.right() - p.x();
403 result = CETypes::RightDir;
411 if (l1.x() == l2.x())
412 return p.x() >= l1.x();
413 return p.y() <= l1.y() + (p.x() - l1.x())*(l2.y() - l1.y())/(l2.x() - l1.x());
441
442
443
444
445
446
447
448
449
450
451
452
476
477
478
479
480
481
482
483
484
485
486
504
505
506
507
508
509
510
516
517
518
519
520
521
522
523
524
525
526
527
545
546
547
548
549
550
551
552
553
554
559
560
561
562
563
564
565
566
567
568
569
679 const QPoint c(qMin(a.x(), b.x()), qMin(a.y(), b.y()));
680 const QPoint d(qMax(a.x(), b.x()), qMax(a.y(), b.y()));
683 return expand(result, LINE_PROXIMITY_RADIUS);
902
903
1101#if QT_CONFIG(cursor)
1194#if QT_CONFIG(cursor)
1229#if QT_CONFIG(cursor)
1252#if QT_CONFIG(cursor)
1332template <
class ObjectIterator>
1335 ConnectionEdit::ConnectionSet rc;
1337 const auto ccend = cl.cend();
1338 for ( ; oi1 != oi2; ++oi1) {
1339 for (
auto cit = cl.constBegin(); cit != ccend; ++cit) {
1340 Connection *con = *cit;
1341 if (con->object(ConnectionEdit::EndPoint::Source) == *oi1 || con->object(ConnectionEdit::EndPoint::Target) == *oi1)
1342 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)