1 /*
2 # PostgreSQL Database Modeler (pgModeler)
3 #
4 # Copyright 2006-2020 - Raphael Araújo e Silva <raphael@pgmodeler.io>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # The complete text of GPLv3 is at LICENSE file on source code root directory.
16 # Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
17 */
18
19 #include "textboxview.h"
20 #include "roundedrectitem.h"
21
TextboxView(Textbox * txtbox,bool override_style)22 TextboxView::TextboxView(Textbox *txtbox, bool override_style) : BaseObjectView(txtbox)
23 {
24 connect(txtbox, SIGNAL(s_objectModified()), this, SLOT(configureObject()));
25
26 box=new QGraphicsPolygonItem;
27 text=new QGraphicsSimpleTextItem;
28
29 text_item = new TextPolygonItem;
30 this->addToGroup(text_item);
31
32 obj_shadow=new QGraphicsPolygonItem;
33 obj_shadow->setZValue(-1);
34 this->addToGroup(obj_shadow);
35
36 obj_selection=new QGraphicsPolygonItem;
37 obj_selection->setVisible(false);
38 obj_selection->setZValue(4);
39 this->addToGroup(obj_selection);
40
41 this->override_style=override_style;
42 this->configureObject();
43 }
44
~TextboxView()45 TextboxView::~TextboxView()
46 {
47 this->removeFromGroup(text_item);
48 delete text_item;
49 }
50
setColorStyle(const QBrush & fill_style,const QPen & border_style)51 void TextboxView::setColorStyle(const QBrush &fill_style, const QPen &border_style)
52 {
53 if(override_style)
54 {
55 text_item->setBrush(fill_style);
56 text_item->setPen(border_style);
57 }
58 }
59
setFontStyle(const QTextCharFormat & fmt)60 void TextboxView::setFontStyle(const QTextCharFormat &fmt)
61 {
62 if(override_style)
63 {
64 text_item->setFont(fmt.font());
65 text_item->setTextBrush(fmt.foreground());
66 }
67 }
68
setToolTip(const QString & tooltip)69 void TextboxView::setToolTip(const QString &tooltip)
70 {
71 txtbox_tooltip = tooltip;
72 }
73
__configureObject()74 void TextboxView::__configureObject()
75 {
76 Textbox *txtbox=dynamic_cast<Textbox *>(this->getUnderlyingObject());
77 QTextCharFormat fmt=font_config[Attributes::Global];
78 QPolygonF polygon;
79
80 polygon.append(QPointF(0.0,0.0));
81 polygon.append(QPointF(1.0,0.0));
82 polygon.append(QPointF(1.0,1.0));
83 polygon.append(QPointF(0.0,1.0));
84
85 if(!override_style)
86 {
87 QFont font;
88
89 text_item->setBrush(this->getFillStyle(BaseObject::getSchemaName(ObjectType::Textbox)));
90 text_item->setPen(this->getBorderStyle(BaseObject::getSchemaName(ObjectType::Textbox)));
91
92 font=fmt.font();
93 font.setItalic(txtbox->getTextAttribute(Textbox::ItalicText));
94 font.setBold(txtbox->getTextAttribute(Textbox::BoldText));
95 font.setUnderline(txtbox->getTextAttribute(Textbox::UnderlineText));
96 font.setPointSizeF(txtbox->getFontSize());
97
98 text_item->setFont(font);
99 text_item->setTextBrush(txtbox->getTextColor());
100 }
101
102 text_item->setText(txtbox->getComment());
103 text_item->setTextPos(HorizSpacing * 2, VertSpacing * (text_item->getFont().italic() ? 0.90 : 0.50));
104
105 TextPolygonItem::resizePolygon(polygon, round(text_item->getTextBoundingRect().width() + (2.5 * HorizSpacing)),
106 round(text_item->getTextBoundingRect().height() + (1.5 * VertSpacing)));
107
108 text_item->setPos(0,0);
109 text_item->setPolygon(polygon);
110
111 protected_icon->setPos(text_item->boundingRect().width() + 2 * HorizSpacing,
112 text_item->boundingRect().height() * 0.70);
113
114 this->bounding_rect.setTopLeft(text_item->boundingRect().topLeft());
115 this->bounding_rect.setBottomRight(text_item->boundingRect().bottomRight());
116
117 this->setZValue(dynamic_cast<Textbox *>(getUnderlyingObject())->getZValue());
118 BaseObjectView::__configureObject();
119
120 if(!txtbox_tooltip.isEmpty())
121 this->BaseObjectView::setToolTip(txtbox_tooltip);
122 }
123
configureObject()124 void TextboxView::configureObject()
125 {
126 this->__configureObject();
127 this->configureObjectShadow();
128 this->configureObjectSelection();
129 }
130
configureObjectShadow()131 void TextboxView::configureObjectShadow()
132 {
133 QGraphicsPolygonItem *pol_item=dynamic_cast<QGraphicsPolygonItem *>(obj_shadow);
134
135 pol_item->setPen(Qt::NoPen);
136 pol_item->setBrush(QColor(50,50,50,60));
137 pol_item->setPolygon(text_item->polygon());
138 pol_item->setPos(3.5,3.5);
139 }
140
configureObjectSelection()141 void TextboxView::configureObjectSelection()
142 {
143 QGraphicsPolygonItem *pol_item=dynamic_cast<QGraphicsPolygonItem *>(obj_selection);
144
145 pol_item->setPolygon(text_item->polygon());
146 pol_item->setPos(0,0);
147 pol_item->setBrush(this->getFillStyle(Attributes::ObjSelection));
148 pol_item->setPen(this->getBorderStyle(Attributes::ObjSelection));
149 }
150
itemChange(GraphicsItemChange change,const QVariant & value)151 QVariant TextboxView::itemChange(GraphicsItemChange change, const QVariant &value)
152 {
153 if(change == ItemZValueHasChanged)
154 {
155 Textbox *txtbox = dynamic_cast<Textbox *>(getUnderlyingObject());
156 txtbox->setZValue(zValue());
157 }
158
159 return BaseObjectView::itemChange(change, value);
160 }
161