[qet] qet/qet: [5410] Element text item group can now be framed.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5410
Author:   blacksun
Date:     2018-06-24 13:16:37 +0200 (Sun, 24 Jun 2018)
Log Message:
-----------
Element text item group can now be framed.

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/diagramtextitem.cpp
    trunk/sources/qetgraphicsitem/diagramtextitem.h
    trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
    trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp
    trunk/sources/qetgraphicsitem/elementtextitemgroup.h
    trunk/sources/ui/dynamicelementtextmodel.cpp
    trunk/sources/ui/dynamicelementtextmodel.h

Modified: trunk/sources/qetgraphicsitem/diagramtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramtextitem.cpp	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/qetgraphicsitem/diagramtextitem.cpp	2018-06-24 11:16:37 UTC (rev 5410)
@@ -185,6 +185,30 @@
 }
 
 /**
+ * @brief DiagramTextItem::frameRect
+ * @return the rect used to draw a frame around this text
+ */
+QRectF DiagramTextItem::frameRect() const
+{	
+		//Get the bounding rectangle of the text
+	QSizeF size = document()->size();
+	size.setWidth(document()->idealWidth());
+		//Remove the margin. Size is exactly the bounding rect of the text
+	size.rheight() -= document()->documentMargin()*2;
+	size.rwidth() -= document()->documentMargin()*2;
+		//Add a little margin only for a better visual;
+	size.rheight() += 2;
+	size.rwidth() += 2;
+	
+		//The pos of the rect
+	QPointF pos = boundingRect().center();
+	pos.rx() -= size.width()/2;
+	pos.ry() -= size.height()/2;
+	
+	return QRectF(pos, size);
+}
+
+/**
  * @brief DiagramTextItem::paint
  * Draw this text field. This method draw the text by calling QGraphicsTextItem::paint.
  * If text is hovered, this method draw the bounding rect in grey

Modified: trunk/sources/qetgraphicsitem/diagramtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/diagramtextitem.h	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/qetgraphicsitem/diagramtextitem.h	2018-06-24 11:16:37 UTC (rev 5410)
@@ -76,6 +76,8 @@
 		void setAlignment(const Qt::Alignment &alignment);
 		Qt::Alignment alignment() const;
 		bool m_block_alignment = false;
+		
+		QRectF frameRect() const;
 
 	protected:
 		void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;

Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp	2018-06-24 11:16:37 UTC (rev 5410)
@@ -635,7 +635,6 @@
 	if (m_frame)
 	{
 		painter->save();
-		
 		painter->setFont(QETApp::diagramTextsFont(fontSize()));
 		
 			//Adjust the thickness according to the font size, 
@@ -653,24 +652,9 @@
 		painter->setPen(pen);
 		painter->setRenderHint(QPainter::Antialiasing);
 		
-			//Get the bounding rectangle of the text
-		QSizeF size = document()->size();
-		size.setWidth(document()->idealWidth());
-			//Remove the margin. Size is exactly the bounding rect of the text
-		size.rheight() -= document()->documentMargin()*2;
-		size.rwidth() -= document()->documentMargin()*2;
-			//Add a little margin only for a better visual;
-		size.rheight() += 2;
-		size.rwidth() += 2;
-		
-			//The pos of the rect
-		QPointF pos = boundingRect().center();
-		pos.rx() -= size.width()/2;
-		pos.ry() -= size.height()/2;
-		
 			//Adjust the rounding of the rectangle according to the size of the font
 		qreal ro = (qreal)fontSize()/3;
-		painter->drawRoundedRect(QRectF(pos, size), ro, ro);
+		painter->drawRoundedRect(frameRect(), ro, ro);
 		
 		painter->restore();
 	}

Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp	2018-06-24 11:16:37 UTC (rev 5410)
@@ -298,6 +298,17 @@
 	emit holdToBottomPageChanged(hold);
 }
 
+void ElementTextItemGroup::setFrame(const bool frame)
+{
+	m_frame = frame;
+	update();
+	emit frameChanged(m_frame);
+}
+
+bool ElementTextItemGroup::frame() const {
+	return m_frame;
+}
+
 /**
  * @brief ElementTextItemGroup::texts
  * @return Every texts in this group
@@ -356,6 +367,7 @@
 	
 	dom_element.setAttribute("rotation", this->rotation());
 	dom_element.setAttribute("vertical_adjustment", m_vertical_adjustment);
+	dom_element.setAttribute("frame", m_frame? "true" : "false");
 	
 	dom_element.setAttribute("hold_to_bottom_page", m_hold_to_bottom_of_page == true ? "true" : "false");
 	
@@ -392,6 +404,7 @@
 	
 	setRotation(dom_element.attribute("rotation", QString::number(0)).toDouble());
 	setVerticalAdjustment(dom_element.attribute("vertical_adjustment").toInt());
+	setFrame(dom_element.attribute("frame", "false") == "true"? true : false);
 	
 	QString hold = dom_element.attribute("hold_to_bottom_page", "false");
 	setHoldToBottomPage(hold == "true" ? true : false);
@@ -437,6 +450,36 @@
 		
 		painter->restore();
 	}
+	if(m_frame)
+	{		
+		int font_size = 1;
+		QRectF rect;
+		for(DynamicElementTextItem *deti : this->texts())
+		{
+			font_size = std::max(font_size, deti->fontSize());
+			rect = rect.united(mapFromItem(deti, deti->frameRect()).boundingRect());
+		}
+		
+			//Adjust the thickness according to the font size
+		qreal w=0.3;
+		if (font_size >= 5)
+		{
+			w = (qreal)font_size*0.1;
+			if(w > 2.5)
+				w = 2.5;
+		}
+		
+		painter->save();
+		QPen pen;
+		pen.setWidthF(w);
+		painter->setPen(pen);
+		painter->setRenderHint(QPainter::Antialiasing);
+		
+			//Adjust the rounding of the rectangle according to the size of the font
+		qreal ro = (qreal)font_size/3;
+		painter->drawRoundedRect(rect, ro, ro);
+		painter->restore();
+	}
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.h
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.h	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.h	2018-06-24 11:16:37 UTC (rev 5410)
@@ -42,6 +42,7 @@
 	Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
 	Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
 	Q_PROPERTY(bool holdToBottomPage READ holdToBottomPage WRITE setHoldToBottomPage NOTIFY holdToBottomPageChanged)
+	Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
 	
 	public:
 	signals:
@@ -52,6 +53,7 @@
 		void holdToBottomPageChanged(bool);
 		void xChanged();
 		void yChanged();
+		void frameChanged(bool frame);
 	
 	public:
 		ElementTextItemGroup(const QString &name, Element *parent);
@@ -69,6 +71,8 @@
 		QString name() const {return m_name;}
 		void setHoldToBottomPage(bool hold);
 		bool holdToBottomPage() const {return m_hold_to_bottom_of_page;}
+		void setFrame(const bool frame);
+		bool frame() const;
 		QList<DynamicElementTextItem *> texts() const;
 		Diagram *diagram() const;
 		Element *parentElement() const;
@@ -102,7 +106,8 @@
 		QString m_name;
 		bool m_first_move = true,
 			 m_hold_to_bottom_of_page = false,
-			 m_block_alignment_update = false;
+			 m_block_alignment_update = false,
+			 m_frame = false;
 		QPointF m_initial_position;
 		int m_vertical_adjustment = 0;
 		CrossRefItem *m_Xref_item = nullptr;

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2018-06-24 11:16:37 UTC (rev 5410)
@@ -53,7 +53,8 @@
 int y_grp_row              = 2;
 int rot_grp_row            = 3;
 int adjust_grp_row         = 4;
-int hold_to_bottom_grp_row = 5;
+int frame_grp_row          = 5;
+int hold_to_bottom_grp_row = 6;
 
 DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
 	QStandardItemModel(parent),
@@ -566,19 +567,23 @@
 	else if((alignment == tr("Centre")) && (group->alignment() != Qt::AlignVCenter))
 		new QPropertyUndoCommand(group, "alignment", QVariant(group->alignment()), QVariant(Qt::AlignVCenter), undo);
 	
-	QPointF pos(group_qsi->child(x_grp_row,1)->data(Qt::EditRole).toDouble(),
-				group_qsi->child(y_grp_row,1)->data(Qt::EditRole).toDouble());
-	if(group->pos() != pos)
-	{
-		QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "pos", QVariant(group->pos()), QVariant(pos), undo);
-		qpuc->setAnimated(true, false);
-	}
 	
-	qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
-	if(group->rotation() != rotation)
+	if (group_qsi->child(hold_to_bottom_grp_row, 1)->checkState() == Qt::Unchecked)
 	{
-		QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
-		qpuc->setAnimated(true, false);
+		QPointF pos(group_qsi->child(x_grp_row,1)->data(Qt::EditRole).toDouble(),
+					group_qsi->child(y_grp_row,1)->data(Qt::EditRole).toDouble());
+		if(group->pos() != pos)
+		{
+			QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "pos", QVariant(group->pos()), QVariant(pos), undo);
+			qpuc->setAnimated(true, false);
+		}
+		
+		qreal rotation = group_qsi->child(rot_grp_row,1)->data(Qt::EditRole).toDouble();
+		if(group->rotation() != rotation)
+		{
+			QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(group, "rotation", QVariant(group->rotation()), QVariant(rotation), undo);
+			qpuc->setAnimated(true, false);
+		}
 	}
 	
 	int v_adjustment = group_qsi->child(adjust_grp_row,1)->data(Qt::EditRole).toInt();
@@ -592,8 +597,11 @@
 	bool hold_to_bottom = group_qsi->child(hold_to_bottom_grp_row, 1)->checkState() == Qt::Checked? true : false;
 	if(group->holdToBottomPage() != hold_to_bottom)
 		new QPropertyUndoCommand(group, "holdToBottomPage", QVariant(group->holdToBottomPage()), QVariant(hold_to_bottom), undo);
+	
+	bool frame_ = group_qsi->child(frame_grp_row, 1)->checkState() == Qt::Checked? true : false;
+	if(group->frame() != frame_)
+		new QPropertyUndoCommand(group, "frame", QVariant(group->frame()), QVariant(frame_), undo);
 		
-	
 	return undo;
 }
 
@@ -689,6 +697,20 @@
 	qsi_list << v_adj << v_adj_a;
 	grp->appendRow(qsi_list);
 	
+		//Frame
+	QStandardItem *frame_ = new QStandardItem(tr("Cadre"));
+	frame_->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+	
+	QStandardItem *frame_a = new QStandardItem;
+	frame_a->setCheckable(true);
+	frame_a->setCheckState(group->frame()? Qt::Checked : Qt::Unchecked);
+	frame_a->setData(DynamicElementTextModel::grpFrame, Qt::UserRole+1);
+	frame_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
+	qsi_list.clear();
+	qsi_list << frame_ << frame_a;
+	grp->appendRow(qsi_list);
+	
+	
 		//Hold to the bottom of the page
 	QStandardItem *hold_bottom = new QStandardItem(tr("Maintenir en bas de page"));
 	hold_bottom->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
@@ -1233,6 +1255,7 @@
 		connection_list << connect(group, &ElementTextItemGroup::holdToBottomPageChanged, [group, this]() {this->updateDataFromGroup(group, grpHoldBottom);});
 		connection_list << connect(group, &ElementTextItemGroup::xChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
 		connection_list << connect(group, &ElementTextItemGroup::yChanged, [group, this]() {this->updateDataFromGroup(group, grpPos);});
+		connection_list << connect(group, &ElementTextItemGroup::frameChanged, [group, this]() {this->updateDataFromGroup(group, grpFrame);});
 		
 		m_hash_group_connect.insert(group, connection_list);
 	}
@@ -1373,6 +1396,9 @@
 			enableGroupRotationAndPos(group);
 			break;
 		}
+		case grpFrame:
+			qsi->child(frame_grp_row, 1)->setCheckState(group->frame()? Qt::Checked : Qt::Unchecked);
+			break;
 		default:break;
 	}
 	

Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h	2018-06-23 13:29:45 UTC (rev 5409)
+++ trunk/sources/ui/dynamicelementtextmodel.h	2018-06-24 11:16:37 UTC (rev 5410)
@@ -54,7 +54,8 @@
 			grpRotation,
 			grpVAdjust,
 			grpName,
-			grpHoldBottom
+			grpHoldBottom,
+			grpFrame
         };
         
 		DynamicElementTextModel(Element *element, QObject *parent = nullptr);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/