Verified Commit c09643b0 authored by ita1024's avatar ita1024

Add a new cloud shape

parent 8334c039
......@@ -153,7 +153,7 @@ class data_box : public diagram_item, public node
int m_iHH;
enum IType { ACTIVITY=1, ACTIVITY_START=2, ACTIVITY_PARALLEL=3, LABEL=4, COMPONENT=5, NODE=6, \
ACTOR=7, USECASE=8, DECISION=9, MATRIX=10, FRAME=11, CLASS=12, CAPTION=13, DATABASE=14,
RECTANGLE=15, PIPE=16, SEQUENCE=17, ENTITY=18};
RECTANGLE=15, PIPE=16, SEQUENCE=17, ENTITY=18, CLOUD=19};
data_box::IType m_iType;
node& make_node(const QString&, const QXmlAttributes&);
......
// Thomas Nagy 2020-2020 GPLV3
#include <QApplication>
#include <QAbstractTextDocumentLayout>
#include <QTextDocument>
#include <QTextDocumentFragment>
#include <QGraphicsTextItem>
#include <QTextList>
#include <QClipboard>
#include <QPainter>
#include <QtDebug>
#include <QAction>
#include <QTextDocument>
#include <QInputDialog>
#include "box_cloud.h"
#include "data_item.h"
#include "res:zable.h"
#include "box_view.h"
#include "box_link.h"
#include "sem_mediator.h"
#include "mem_box.h"
#include <QFont>
#define MIN_FORK_SIZE 30
box_cloud::box_cloud(box_view* view, int id) : box_item(view, id)
{
m_oCaption = new QGraphicsTextItem();
m_oCaption->setParentItem(this);
m_oCaption->setPos(0, 0);
}
box_cloud::~box_cloud() {
delete m_oCaption;
}
void box_cloud::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QPen l_oPen = QPen(Qt::SolidLine);
l_oPen.setColor(Qt::black);
l_oPen.setCosmetic(false);
l_oPen.setWidthF(0.01 + 1);
painter->setPen(l_oPen);
qreal pad = l_oPen.width() / 2.;
QRectF l_oRect = rect().adjusted(pad, pad, -pad, -pad);
qreal xtop = l_oRect.x();
qreal ytop = l_oRect.y();
qreal xcoord = xtop + l_oRect.width() / 2.0;
qreal ycoord = l_oRect.height() / 5.;
QColor bc = m_oBox->getColor(m_oView->m_oMediator);
if (m_oView->m_bDisableGradient)
{
painter->setBrush(bc);
}
else
{
QLinearGradient linearGradient(0, 0, l_oRect.width(), 0);
linearGradient.setColorAt(0.0, bc);
linearGradient.setColorAt(1.0, bc.darker(GRADVAL));
painter->setBrush(linearGradient);
}
qreal w = l_oRect.width();
qreal h = l_oRect.height();
int hdiv = 4;
int vdiv = 2;
qreal min = h;
qreal prev_min = min;
for (int x=2; x < 100; ++x) {
qreal new_min = qAbs(h - (x * w) / hdiv);
if (new_min < min)
{
min = new_min;
vdiv = x;
}
if (new_min > prev_min) {
break;
}
prev_min = new_min;
}
qreal CONST = 1.2;
qreal dx = (CONST * l_oRect.width()) / hdiv;
qreal dy = (CONST * l_oRect.height()) / vdiv;
qreal xstep = (w - dx) / (hdiv - 1);
qreal ystep = (h - dy) / (vdiv - 1);
for (int i=0; i<hdiv; ++i)
{
painter->drawEllipse(QRectF(xtop + i * xstep, ytop, dx, dy));
}
for (int i=0; i<vdiv; ++i)
{
painter->drawEllipse(QRectF(xtop + w - dx, ytop + i * ystep, dx, dy));
}
for (int i=hdiv-1; i >= 0; --i)
{
painter->drawEllipse(QRectF(xtop + i * xstep, ytop + h - dy, dx, dy));
}
for (int i=vdiv-1; i >= 1; --i)
{
painter->drawEllipse(QRectF(xtop, ytop + i * ystep, dx, dy));
}
painter->setPen(Qt::NoPen);
painter->drawRect(l_oRect.adjusted(dx/4., dy/4., -dx/4., -dy/4.));
}
void box_cloud::properties()
{
bool ok = false;
QString text = QInputDialog::getText(m_oView, i18n("Cloud properties"),
i18n("Caption:"), QLineEdit::Normal, m_oBox->m_sText, &ok);
if (ok && text != m_oBox->m_sText)
{
mem_edit_box *ed = new mem_edit_box(m_oView->m_oMediator, m_oView->m_iId, m_iId);
ed->newText = text;
ed->apply();
}
}
void box_cloud::update_size() {
m_iWW = m_oBox->m_iWW;
m_iHH = m_oBox->m_iHH;
prepareGeometryChange();
setRect(0, 0, m_iWW, m_iHH);
m_oChain->setPos(m_iWW + 3, 0);
update_links();
update_sizers();
}
void box_cloud::update_links() {
QRectF r = boundingRect();
m_oCaption->setFont(scene()->font());
m_oCaption->setPlainText(m_oBox->m_sText);
m_oCaption->setPos((r.width() - m_oCaption->boundingRect().width()) / 2., (r.height() - m_oCaption->boundingRect().height()) / 2.);
box_item::update_links();
}
// Thomas Nagy 2020-2020 GPLV3
#ifndef BOX_CLOUD_H
#define BOX_CLOUD_H
#include <QGraphicsRectItem>
#include <QBrush>
#include "res:zable.h"
#include "ed:table.h"
#include "box_item.h"
#include "CON.h"
#include "con.h"
#define OFF 3
class QGraphicsTextItem;
class box_cloud : public box_item
{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *);
box_cloud(box_view*, int i_iId);
~box_cloud();
QGraphicsTextItem *m_oCaption;
void properties();
void update_size();
void update_links();
};
#endif // BOX_CLOUD_H
......@@ -58,6 +58,7 @@
#include "box_matrix.h"
#include "box_frame.h"
#include "box_class.h"
#include "box_cloud.h"
#include "box_entity.h"
#include "data_item.h"
#include "box_usecase.h"
......@@ -259,6 +260,8 @@ box_view::box_view(QWidget *i_oWidget, sem_mediator *i_oControl) : QGraphicsView
connect(m_oAddParallelVertical, SIGNAL(triggered()), this, SLOT(slot_add_element()));
m_oAddActor = new QAction(i18n("Actor"), this);
connect(m_oAddActor, SIGNAL(triggered()), this, SLOT(slot_add_element()));
m_oAddCloud = new QAction(i18n("Cloud"), this);
connect(m_oAddCloud, SIGNAL(triggered()), this, SLOT(slot_add_element()));
m_oAddUsecase = new QAction(i18n("Usecase"), this);
connect(m_oAddUsecase, SIGNAL(triggered()), this, SLOT(slot_add_element()));
m_oAddMatrix = new QAction(i18n("Matrix"), this);
......@@ -321,6 +324,7 @@ void box_view::init_menu()
m_oAddBoxMenu->addAction(m_oAddRectangle);
m_oAddBoxMenu->addAction(m_oAddClass);
m_oAddBoxMenu->addAction(m_oAddEntity);
m_oAddBoxMenu->addAction(m_oAddCloud);
m_oAddBoxMenu->addAction(m_oAddPipe);
m_oAddBoxMenu->addAction(m_oAddDatabase);
m_oAddBoxMenu->addAction(m_oAddSequence);
......@@ -479,6 +483,10 @@ void box_view::sync_view()
{
l_o = new box_actor(this, box->m_iId);
}
else if (box->m_iType == data_box::CLOUD)
{
l_o = new box_cloud(this, box->m_iId);
}
else if (box->m_iType == data_box::USECASE)
{
l_o = new box_usecase(this, box->m_iId);
......@@ -878,6 +886,13 @@ void box_view::slot_add_element()
add->box->m_iWW = 30;
add->box->m_iHH = 70;
}
else if (sender == m_oAddCloud)
{
add->box->m_iType = data_box::CLOUD;
add->box->m_iWW = 150;
add->box->m_iHH = 120;
add->box->m_oCustom.m_oInnerColor = QColor("#FCF2E2");
}
else if (sender == m_oAddUsecase)
{
add->box->m_iType = data_box::USECASE;
......@@ -1245,6 +1260,10 @@ void box_view::notify_add_box(int id, int box)
{
l_o = new box_actor(this, box);
}
else if (db->m_iType == data_box::CLOUD)
{
l_o = new box_cloud(this, box);
}
else if (db->m_iType == data_box::USECASE)
{
l_o = new box_usecase(this, box);
......
......@@ -58,6 +58,7 @@ class box_view : public QGraphicsView
QAction *m_oAddComponent;
QAction *m_oAddRectangle;
QAction *m_oAddActor;
QAction *m_oAddCloud;
QAction *m_oAddUsecase;
QAction *m_oAddNode;
QAction *m_oAddDotStart;
......
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