box_frame.cpp 1.96 KB
Newer Older
ita1024's avatar
ita1024 committed
1
// Thomas Nagy 2007-2018 GPLV3
Thomas Nagy's avatar
Thomas Nagy committed
2 3 4 5 6

#include <QApplication>
#include <QAbstractTextDocumentLayout>
#include <QTextDocument>
#include <QTextDocumentFragment>
7 8
 #include <box_frame_properties.h>
   #include <QComboBox>
Thomas Nagy's avatar
Thomas Nagy committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <QTextList>
#include <QClipboard>
#include <QPainter>
#include <QtDebug>
#include <QAction>
#include <QTextDocument>
#include "box_frame.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>

25
#define PAD 2
Thomas Nagy's avatar
Thomas Nagy committed
26 27 28 29
#define MIN_FORK_SIZE 30

box_frame::box_frame(box_view* view, int id) : box_item(view, id)
{
ita1024's avatar
ita1024 committed
30 31 32 33
	m_oCaption = new QGraphicsTextItem();
	m_oCaption->setParentItem(this);
	m_oCaption->setPos(0, 0);

Thomas Nagy's avatar
Thomas Nagy committed
34 35 36 37 38 39 40 41
	setZValue(80);
}

void box_frame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	QPen l_oPen = QPen(Qt::SolidLine);
	l_oPen.setColor(Qt::black);
	l_oPen.setCosmetic(false);
ita1024's avatar
ita1024 committed
42
	if (isSelected()) l_oPen.setStyle(Qt::DotLine);
43
	l_oPen.setWidthF(0.01 + 1);
Thomas Nagy's avatar
Thomas Nagy committed
44 45
	painter->setPen(l_oPen);

ita1024's avatar
ita1024 committed
46 47
	qreal pad = l_oPen.width() / 2.;
	QRectF l_oRect = rect().adjusted(pad, pad, -pad, -pad);
Thomas Nagy's avatar
Thomas Nagy committed
48 49 50 51

	painter->drawRect(l_oRect);
}

52 53
void box_frame::update_links()
{
54
	m_oCaption->setFont(scene()->font());
ita1024's avatar
ita1024 committed
55
	m_oCaption->setPlainText(m_oBox->m_sText);
56 57

	QRectF l_oR = boundingRect();
58 59 60 61 62
	int l_iVpos;
	if (m_oBox->m_iLabelPosition == Qt::TopEdge)
	{
		l_iVpos = 0;
	}
63 64
	else
	{
65 66 67 68 69 70 71
		l_iVpos = l_oR.height() - m_oCaption->boundingRect().height();
	}

	int l_iHpos;
	if (m_oBox->m_iAlign == Qt::AlignLeft)
	{
		l_iHpos = l_oR.left() + PAD;
72
	}
73 74 75 76 77 78 79 80 81 82
	else if (m_oBox->m_iAlign == Qt::AlignRight)
	{
		l_iHpos = l_oR.right() - m_oCaption->boundingRect().width() - PAD;
	}
	else
	{
		l_iHpos = (l_oR.width() - m_oCaption->boundingRect().width()) / 2.;
	}

	m_oCaption->setPos(l_iHpos, l_iVpos);
ita1024's avatar
ita1024 committed
83 84 85
	box_item::update_links();
}

86 87 88 89 90 91 92 93 94 95 96 97
void box_frame::update_data()
{
	box_item::update_data();
	update_links();
}

void box_frame::properties()
{
	box_frame_properties props(m_oView, this);
	props.exec();
}