Commit 023944d8 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Merge remote-tracking branch 'origin/release/19.12'

parents 1db47cb2 b0a366c9
......@@ -10,12 +10,15 @@
#include "diagramproxywidget.h"
#include "debug_utils.h"
#include "uml.h"
#include "umldoc.h"
#include "umlscene.h"
#include "umlview.h"
#include "umlwidget.h"
DEBUG_REGISTER_DISABLED(DiagramProxyWidget)
DiagramProxyWidget::DiagramProxyWidget(UMLWidget *widget, qreal borderWidth)
: m_diagramLinkId(Uml::ID::None)
, m_widget(widget)
......@@ -43,6 +46,36 @@ bool DiagramProxyWidget::setDiagramLink(const Uml::ID::Type &id)
return view;
}
/**
* Return the area in which the linked diagram is displayed.
*
* @return area in current item coordinates
*/
const QRectF &DiagramProxyWidget::clientRect()
{
return m_clientRect;
}
/**
* Return scene area of the linked diagram.
*
* @return scene rectangle
*/
const QRectF &DiagramProxyWidget::sceneRect()
{
return m_sceneRect;
}
/**
* Set the area in which the linked diagram is displayed
*
* @param rect
*/
void DiagramProxyWidget::setClientRect(const QRectF &rect)
{
m_clientRect = rect;
}
bool DiagramProxyWidget::activate(IDChangeLog *changeLog)
{
Q_UNUSED(changeLog);
......@@ -222,3 +255,23 @@ void DiagramProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
event->ignore();
}
}
/**
* Paint linked diagram into current widget
*
* @param painter painter to paint on
* @param option The option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints
* @param widget The widget argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0
*/
void DiagramProxyWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
m_sceneRect = linkedDiagram()->sceneRect().adjusted(-1,-1, 1, 1);
if (Tracer::instance()->isEnabled(QLatin1String("DiagramProxyWidget"))) {
painter->setPen(Qt::magenta);
painter->drawRect(m_clientRect);
}
m_linkedDiagram->render(painter, m_clientRect, m_sceneRect);
}
......@@ -23,6 +23,7 @@ class UMLScene;
class IDChangeLog;
class QDomDocument;
class QDomElement;
class QStyleOptionGraphicsItem;
class DiagramProxyWidget {
public:
......@@ -31,6 +32,9 @@ public:
Uml::ID::Type diagramLink();
UMLScene *linkedDiagram();
bool setDiagramLink(const Uml::ID::Type &id);
const QRectF &clientRect();
const QRectF &sceneRect();
void setClientRect(const QRectF &rect);
bool isProxyWidget();
UMLWidget *getProxiedWidget(const QPointF &p);
......@@ -38,14 +42,8 @@ public:
QRectF mapFromClient(const QRectF &r);
QPointF mapToClient(const QPointF &pos);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
protected:
Uml::ID::Type m_diagramLinkId; ///< id of linked diagram
QPointer<UMLScene> m_linkedDiagram; ///< pointer to linked diagram
QRectF m_clientRect; ///< widget area for embedded diagram
QRectF m_sceneRect; ///< scene rectangle used for internal calculations
UMLWidget *m_widget;
qreal m_borderWidth;
DiagramProxyWidget& operator=(const DiagramProxyWidget& other);
bool activate(IDChangeLog* changeLog = 0);
bool loadFromXMI1(QDomElement &qElement);
......@@ -57,6 +55,14 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
Uml::ID::Type m_diagramLinkId; ///< id of linked diagram
QPointer<UMLScene> m_linkedDiagram; ///< pointer to linked diagram
QRectF m_clientRect; ///< widget area for embedded diagram
QRectF m_sceneRect; ///< scene rectangle used for internal calculations
UMLWidget *m_widget;
qreal m_borderWidth;
};
#endif // DIAGRAMPROXYWIDGET_H
......@@ -199,17 +199,13 @@ void StateWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
painter->setFont(font);
painter->drawText(STATE_MARGIN, 0, w - STATE_MARGIN * 2, fontHeight,
Qt::AlignCenter, name());
if (!m_linkedDiagram) {
if (!linkedDiagram()) {
m_size = QSizeF(fm.width(name()) + STATE_MARGIN * 2, fm.lineSpacing() + STATE_MARGIN);
} else {
m_sceneRect = m_linkedDiagram->sceneRect().adjusted(-1,-1, 1, 1);
m_clientRect = rect().adjusted(STATE_MARGIN, fontHeight + STATE_MARGIN, - STATE_MARGIN, -STATE_MARGIN);
if (Tracer::instance()->isEnabled(QLatin1String(metaObject()->className()))) {
painter->setPen(Qt::magenta);
painter->drawRect(m_clientRect);
}
m_linkedDiagram->render(painter, m_clientRect, m_sceneRect);
m_size = QSizeF(qMax<qreal>(fm.width(m_linkedDiagram->name()), m_sceneRect.width()) + STATE_MARGIN * 2, fm.lineSpacing() + STATE_MARGIN + m_sceneRect.height());
DiagramProxyWidget::setClientRect(rect().adjusted(STATE_MARGIN, fontHeight + STATE_MARGIN, - STATE_MARGIN, -STATE_MARGIN));
DiagramProxyWidget::paint(painter, option, widget);
QSizeF size = DiagramProxyWidget::sceneRect().size();
m_size = QSizeF(qMax<qreal>(fm.width(linkedDiagram()->name()), size.width()) + STATE_MARGIN * 2, fm.lineSpacing() + STATE_MARGIN + size.height());
setSize(m_size);
}
setPenFromSettings(painter);
......@@ -614,12 +610,12 @@ void StateWidget::slotMenuSelection(QAction* action)
break;
case ListPopupMenu::mt_EditCombinedState:
if (!m_linkedDiagram) {
if (!linkedDiagram()) {
uError() << "no diagram id defined at widget '" << Uml::ID::toString(id()) << "'";
break;
}
m_linkedDiagram->setWidgetLink(this);
UMLApp::app()->document()->changeCurrentView(m_diagramLinkId);
linkedDiagram()->setWidgetLink(this);
UMLApp::app()->document()->changeCurrentView(diagramLink());
break;
default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment