Seamly2D
Code documentation
vtextgraphicsitem.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vtextgraphicsitem.cpp
4  ** @author Bojan Kverh
5  ** @date June 16, 2016
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include <QApplication>
30 #include <QColor>
31 #include <QFlags>
32 #include <QFont>
33 #include <QGraphicsItem>
34 #include <QGraphicsSceneHoverEvent>
35 #include <QGraphicsSceneMouseEvent>
36 #include <QPainter>
37 #include <QPen>
38 #include <QPoint>
39 #include <QStyleOptionGraphicsItem>
40 #include <Qt>
41 #include <QDebug>
42 
43 #include "../vmisc/def.h"
44 #include "../vmisc/vmath.h"
45 #include "../vmisc/vcommonsettings.h"
46 #include "../vmisc/vabstractapplication.h"
47 #include "vtextgraphicsitem.h"
48 
49 const qreal resizeSquare = (3./*mm*/ / 25.4) * PrintDPI;
50 const qreal rotateCircle = (2./*mm*/ / 25.4) * PrintDPI;
51 #define ROTATE_RECT 60
52 #define ROTATE_ARC 50
53 const qreal minW = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
54 const qreal minH = (4./*mm*/ / 25.4) * PrintDPI + resizeSquare;
55 #define ACTIVE_Z 10
56 
57 namespace
58 {
59 //---------------------------------------------------------------------------------------------------------------------
60 /**
61  * @brief GetBoundingRect calculates the bounding box around rectBB rectangle, rotated around its center by rotation degrees
62  * @param rectBB rectangle of interest
63  * @param rotation rectangle rotation
64  * @return bounding box around rectBB rotated by rotation
65  */
66 QRectF GetBoundingRect(QRectF rectBB, qreal rotation)
67 {
68  QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() };
69  QPointF ptCenter = rectBB.center();
70 
71  qreal xPos1 = 0;
72  qreal xPos2 = 0;
73  qreal yPos1 = 0;
74  qreal yPos2 = 0;
75 
76  double angle = qDegreesToRadians(rotation);
77  for (int i = 0; i < 4; ++i)
78  {
79  QPointF pt = apt[i] - ptCenter;
80  qreal xPos = pt.x()*cos(angle) + pt.y()*sin(angle);
81  qreal yPos = -pt.x()*sin(angle) + pt.y()*cos(angle);
82 
83  if (i == 0)
84  {
85  xPos1 = xPos2 = xPos;
86  yPos1 = yPos2 = yPos;
87  }
88  else
89  {
90  if (xPos < xPos1)
91  {
92  xPos1 = xPos;
93  }
94  else if (xPos > xPos2)
95  {
96  xPos2 = xPos;
97  }
98  if (yPos < yPos1)
99  {
100  yPos1 = yPos;
101  }
102  else if (yPos > yPos2)
103  {
104  yPos2 = yPos;
105  }
106  }
107  }
108  QRectF rect;
109  rect.setTopLeft(ptCenter + QPointF(xPos1, yPos1));
110  rect.setWidth(xPos2 - xPos1);
111  rect.setHeight(yPos2 - yPos1);
112  return rect;
113 }
114 }//static functions
115 
116 //---------------------------------------------------------------------------------------------------------------------
117 /**
118  * @brief VTextGraphicsItem::VTextGraphicsItem constructor
119  * @param parent pointer to the parent item
120  */
122  : VPieceItem(parent)
123  , m_startPos()
124  , m_start()
125  , m_startSize()
126  , m_rotation(0)
127  , m_angle(0)
128  , m_rectResize()
129  , m_textMananger()
130 {
131  m_inactiveZ = 2;
132  setSize(minW, minH);
133  setZValue(m_inactiveZ);
134 }
135 
136 //---------------------------------------------------------------------------------------------------------------------
137 /**
138  * @brief VTextGraphicsItem::SetFont sets the item font
139  * @param font font to be used in item
140  */
141 void VTextGraphicsItem::setFont(const QFont &font)
142 {
143  m_textMananger.setFont(font);
144 }
145 
146 //---------------------------------------------------------------------------------------------------------------------
147 /**
148  * @brief VTextGraphicsItem::paint redraws the item content
149  * @param painter pointer to the QPainter in use
150  * @param option pointer to the object containing the actual label rectangle
151  * @param widget not used
152  */
153 void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
154 {
155  Q_UNUSED(widget)
156  Q_UNUSED(option)
157 
158  QColor color = QColor(qApp->Settings()->getDefaultLabelColor());
159 
160  painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
161  painter->setPen(QPen(color));
162 
163  QFont font = m_textMananger.GetFont();
164  int width = qFloor(boundingRect().width());
165  // draw text lines
166  int yPos = 0;
167  for (int i = 0; i < m_textMananger.GetSourceLinesCount(); ++i)
168  {
169  const TextLine& textLine = m_textMananger.GetSourceLine(i);
170 
171  font.setPixelSize(m_textMananger.GetFont().pixelSize() + textLine.m_iFontSize);
172  font.setBold(textLine.bold);
173  font.setItalic(textLine.italic);
174 
175  QString text = textLine.m_text;
176  QFontMetrics fm(font);
177 
178  // check if the next line will go out of bounds
179  if (yPos + fm.height() > boundingRect().height())
180  {
181  break;
182  }
183 
184  if (fm.horizontalAdvance(text) > width)
185  {
186  text = fm.elidedText(text, Qt::ElideMiddle, width);
187  }
188 
189  painter->setFont(font);
190  painter->drawText(0, yPos, width, fm.height(), static_cast<int>(textLine.m_eAlign), text);
191  yPos += fm.height() + m_textMananger.GetSpacing();
192  }
193 
194  // now draw the features specific to non-normal modes
195  if (m_eMode != mNormal)
196  {
197  // outextLineine the rectangle
198  painter->setPen(QPen(Qt::black, 2, Qt::DashLine));
199  painter->drawRect(boundingRect().adjusted(1, 1, -1, -1));
200 
201  if (m_eMode != mRotate)
202  {
203  // draw the resize square
204  painter->setPen(Qt::black);
205  painter->setBrush(Qt::black);
206  painter->drawRect(m_rectResize.adjusted(-1, -1, -1, -1));
207 
208  if (m_eMode == mResize)
209  {
210  // draw the resize diagonal lines
211  painter->drawLine(1, 1, qFloor(m_rectBoundingBox.width())-1, qFloor(m_rectBoundingBox.height())-1);
212  painter->drawLine(1, qFloor(m_rectBoundingBox.height())-1, qFloor(m_rectBoundingBox.width())-1, 1);
213  }
214  }
215  else
216  {
217  // in rotate mode, draw the circle in the middle
218  painter->setPen(Qt::black);
219  painter->setBrush(Qt::black);
220  painter->drawEllipse(
221  QPointF(m_rectBoundingBox.width()/2, m_rectBoundingBox.height()/2),
222  rotateCircle,
224  );
225  if (m_rectBoundingBox.width() > minW*3 && m_rectBoundingBox.height() > minH*3)
226  {
227  painter->setPen(QPen(Qt::black, 3));
228  painter->setBrush(Qt::NoBrush);
229  // and then draw the arc in each of the corners
230  int top = ROTATE_RECT - ROTATE_ARC;
231  int left = ROTATE_RECT - ROTATE_ARC;
232  int right = qRound(m_rectBoundingBox.width()) - ROTATE_RECT;
233  int bottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT;
234  painter->drawArc(left, top, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16);
235  painter->drawArc(right, top, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16);
236  painter->drawArc(left, bottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16);
237  painter->drawArc(right, bottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16);
238  }
239  }
240  }
241 }
242 
243 //---------------------------------------------------------------------------------------------------------------------
244 /**
245  * @brief VTextGraphicsItem::setSize Tries to set the label size to (width, height).
246  * If either of those is too small, the labelsize does not change.
247  * @param width label width
248  * @param height label height
249  */
250 void VTextGraphicsItem::setSize(qreal width, qreal height)
251 {
252  // Take into account the rotation of the bounding rectangle
253  QTransform transform = QTransform().rotate(-rotation());
254  QRectF bbRect = transform.map(parentItem()->boundingRect()).boundingRect();
255 
256  // don't allow resize under specific size
257  if (width > bbRect.width())
258  {
259  width = bbRect.width();
260  qDebug() << "Setting label width to parent item width" << width;
261  }
262  if (width < minW)
263  {
264  width = minW;
265  qDebug() << "Setting label width to min width" << width;
266  }
267  if (height > bbRect.height())
268  {
269  height = bbRect.height();
270  qDebug() << "Setting label height to parent item height" << width;
271  }
272  if (height < minH)
273  {
274  height = minH;
275  qDebug() << "Setting label height to min item height" << width;
276  }
277 
278  prepareGeometryChange();
279  m_rectBoundingBox.setTopLeft(QPointF(0, 0));
280  m_rectBoundingBox.setWidth(width);
281  m_rectBoundingBox.setHeight(height);
282  m_rectResize.setTopLeft(QPointF(width - resizeSquare, height - resizeSquare));
283  m_rectResize.setWidth(resizeSquare);
284  m_rectResize.setHeight(resizeSquare);
285  setTransformOriginPoint(m_rectBoundingBox.center());
286 }
287 
288 //---------------------------------------------------------------------------------------------------------------------
289 /**
290  * @brief VTextGraphicsItem::Update sets the correct size and font size and redraws the label
291  */
293 {
294  correctLabel();
295  //UpdateBox();
296 }
297 
298 //---------------------------------------------------------------------------------------------------------------------
299 /**
300  * @brief VTextGraphicsItem::isContained checks if the bounding box around rotated rectBB is contained in
301  * the parent. If that is not the case, it calculates the amount of movement needed to put it inside the parent
302  * and write it into xPos, yPos
303  * @param rectBB bounding box in question
304  * @param rotation bounding box rotation in degrees
305  * @param xPos horizontal translation needed to put the box inside parent item
306  * @param yPos vertical translation needed to put the box inside parent item
307  * @return true, if rectBB is contained in parent item and false otherwise
308  */
309 bool VTextGraphicsItem::isContained(QRectF rectBB, qreal rotation, qreal &xPos, qreal &yPos) const
310 {
311  QRectF rectParent = parentItem()->boundingRect();
312  rectBB = GetBoundingRect(rectBB, rotation);
313  xPos = 0;
314  yPos = 0;
315 
316  if (rectParent.contains(rectBB) == false)
317  {
318  if (rectParent.left() - rectBB.left() > fabs(xPos))
319  {
320  xPos = rectParent.left() - rectBB.left();
321  }
322  else if (rectBB.right() - rectParent.right() > fabs(xPos))
323  {
324  xPos = rectParent.right() - rectBB.right();
325  }
326 
327  if (rectParent.top() - rectBB.top() > fabs(yPos))
328  {
329  yPos = rectParent.top() - rectBB.top();
330  }
331  else if (rectBB.bottom() - rectParent.bottom() > fabs(yPos))
332  {
333  yPos = rectParent.bottom() - rectBB.bottom();
334  }
335 
336  return false;
337  }
338  return true;
339 }
340 
341 //---------------------------------------------------------------------------------------------------------------------
342 /**
343  * @brief VTextGraphicsItem::updateData Updates the detail label
344  * @param name name of detail
345  * @param data reference to VPatternPieceData
346  */
347 void VTextGraphicsItem::updateData(const QString &name, const VPieceLabelData &data)
348 {
349  m_textMananger.Update(name, data);
350 }
351 
352 //---------------------------------------------------------------------------------------------------------------------
353 /**
354  * @brief VTextGraphicsItem::updateData Updates the pattern label
355  * @param doc pointer to the pattern object
356  */
358 {
359  m_textMananger.Update(doc);
360 }
361 
362 //---------------------------------------------------------------------------------------------------------------------
363 /**
364  * @brief VTextGraphicsItem::getTextLines returns the number of lines of text to show
365  * @return number of lines of text
366  */
368 {
370 }
371 
372 //---------------------------------------------------------------------------------------------------------------------
373 /**
374  * @brief VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size
375  * @return current text base font size
376  */
378 {
379  return m_textMananger.GetFont().pixelSize();
380 }
381 
382 //---------------------------------------------------------------------------------------------------------------------
383 /**
384  * @brief VTextGraphicsItem::mousePressEvent handles left button mouse press events
385  * @param event pointer to QGraphicsSceneMouseEvent object
386  */
387 void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
388 {
389  qDebug() << "VTextGraphicsItem::mousePressEvent\n";
390  if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick
391  && (flags() & QGraphicsItem::ItemIsMovable))
392  {
393  if (m_moveType == NotMovable)
394  {
395  event->ignore();
396  return;
397  }
398 
399  // record the parameters of the mouse press. Specially record the position
400  // of the press as the origin for the following operations
401  m_startPos = pos();
402  qDebug() << " start position" << m_startPos;
403  m_start = event->scenePos();
405  m_ptRotCenter = mapToScene(m_rectBoundingBox.center());
406  qDebug() << " center position" << m_ptRotCenter;
407  m_angle = GetAngle(event->scenePos());
408  m_rotation = rotation();
409  // in rotation mode, do not do any changes here, because user might want to
410  // rotate the label more.
411 
413  {
414  allUserModifications(event->pos());
415  setZValue(ACTIVE_Z);
416  Update();
417  }
418  else if (m_moveType & IsRotatable)
419  {
420  if (m_moveType & IsResizable)
421  {
422  allUserModifications(event->pos());
423  }
424  else if (m_moveType & IsMovable)
425  {
427  }
428  else
429  {
430  m_eMode = mRotate;
432  }
433  setZValue(ACTIVE_Z);
434  Update();
435  }
436  else if (m_moveType & IsResizable)
437  {
438  qDebug() << " Item is Movable\n";
439  if (m_moveType & IsRotatable)
440  {
441  allUserModifications(event->pos());
442  }
443  else if (m_moveType & IsMovable)
444  {
445  userMoveAndResize(event->pos());
446  }
447  setZValue(ACTIVE_Z);
448  Update();
449  }
450  else if (m_moveType & IsMovable)
451  {
452  if (m_moveType & IsRotatable)
453  {
455  }
456  else if (m_moveType & IsResizable)
457  {
458  userMoveAndResize(event->pos());
459  }
460  else
461  {
462  m_eMode = mMove;
464  }
465 
466  setZValue(ACTIVE_Z);
467  Update();
468  }
469  else
470  {
471  event->ignore();
472  return;
473  }
474  }
475 }
476 
477 //---------------------------------------------------------------------------------------------------------------------
478 /**
479  * @brief VTextGraphicsItem::mouseMoveEvent handles mouse move events
480  * @param event pointer to QGraphicsSceneMouseEvent object
481  */
482 void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event )
483 {
484  qDebug() << "VTextGraphicsItem::mouseMoveEvent\n";
485  qreal xPos;
486  qreal yPos;
487  QRectF rectBB;
488  const QPointF ptDiff = event ->scenePos() - m_start;
489  if (m_eMode == mMove && m_moveType & IsMovable)
490  {
491  qDebug() << " Item is Movable\n";
492  // in move mode move the label along the mouse move from the origin
493  QPointF pt = m_startPos + ptDiff;
494  rectBB.setTopLeft(pt);
495  rectBB.setWidth(m_rectBoundingBox.width());
496  rectBB.setHeight(m_rectBoundingBox.height());
497  // before moving label to a new position, check if it will still be inside the parent item
498  if (isContained(rectBB, rotation(), xPos, yPos) == false)
499  {
500  qDebug() << " Item is contained\n";
501  pt.setX(pt.x() + xPos);
502  pt.setY(pt.y() + yPos);
503  }
504  setPos(pt);
505  qDebug() << " Item position" << pt;
506  UpdateBox();
507  }
508  else if (m_eMode == mResize && m_moveType & IsResizable)
509  {
510  qDebug() << " Item is Resizable\n";
511  // in resize mode, resize the label along the mouse move from the origin
512  QPointF pt;
513 
514  if (m_moveType & IsMovable)
515  {
516  pt = m_startPos;
517  }
518  else
519  {
520  pt = m_ptRotCenter - QRectF(0, 0, m_startSize.width() + ptDiff.x(),
521  m_startSize.height() + ptDiff.y()).center();
522  }
523 
524  rectBB.setTopLeft(pt);
525 
526  // Apply rotation to ptDiff in order to resize based on current rotation
527  QTransform transform = QTransform().rotate(-rotation());
528  QPointF ptDiff2 = transform.map(ptDiff);
529 
530  QSizeF size(m_startSize.width() + ptDiff2.x(), m_startSize.height() + ptDiff2.y());
531  rectBB.setSize(size);
532  // before resizing the label to a new size, check if it will still be inside the parent item
533  if (isContained(rectBB, rotation(), xPos, yPos) == false)
534  {
535  size = QSizeF(size.width()+xPos, size.height()+yPos);
536  }
537  else
538  {
539  if (not (m_moveType & IsMovable))
540  {
541  setPos(pt);
542  }
543  }
544 
545  setSize(size.width(), size.height());
546  qDebug() << " Item size" << size.width() << size.height();
547  Update();
548  emit textShrink();
549  }
550  else if (m_eMode == mRotate && m_moveType & IsRotatable)
551  {
552  qDebug() << " Item is Rotatable\n";
553  // if the angle from the original position is small (0.5 degrees), just remeber the new angle
554  // new angle will be the starting angle for rotation
555  if (fabs(m_angle) < 0.01)
556  {
557  m_angle = GetAngle(event ->scenePos());
558  return;
559  }
560  // calculate the angle difference from the starting angle
561  double angle = qRadiansToDegrees(GetAngle(event ->scenePos()) - m_angle);
562  rectBB.setTopLeft(m_startPos);
563  rectBB.setWidth(m_rectBoundingBox.width());
564  rectBB.setHeight(m_rectBoundingBox.height());
565  // check if the rotated label will be inside the parent item and then rotate it
566  if (isContained(rectBB, m_rotation + angle, xPos, yPos) == true)
567  {
568  setRotation(m_rotation + angle);
569  Update();
570  }
571  }
572 }
573 
574 //---------------------------------------------------------------------------------------------------------------------
575 /**
576  * @brief VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events
577  * @param event pointer to QGraphicsSceneMouseEvent object
578  */
579 void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event )
580 {
581  if (event ->button() == Qt::LeftButton)
582  {
583  // restore the cursor
584  if ((m_eMode == mMove || m_eMode == mRotate || m_eMode == mResize) && (flags() & QGraphicsItem::ItemIsMovable))
585  {
587  }
588  double distance = fabs(event ->scenePos().x() - m_start.x()) + fabs(event ->scenePos().y() - m_start.y());
589  // determine if this was just press/release (isShort) or user did some operation between press and release
590  bool isShort = (distance < 2);
591 
592  if (m_eMode == mMove || m_eMode == mResize)
593  { // if user just pressed and released the button, we must switch the mode to rotate
594  // but if user did some operation (move/resize), emit the proper signal and update the label
595  if (isShort)
596  {
598  {
599  m_eMode = mRotate;
600  UpdateBox();
601  }
602  }
603  else if (m_eMode == mMove && m_moveType & IsMovable)
604  {
605  emit itemMoved(pos());
606  UpdateBox();
607  }
608  else if (m_moveType & IsResizable)
609  {
610  emit itemResized(m_rectBoundingBox.width(), m_textMananger.GetFont().pixelSize());
611  Update();
612  }
613  }
614  else
615  { // in rotate mode, if user did just press/release, switch to move mode
616  if (isShort && (m_moveType & IsMovable || m_moveType & IsResizable))
617  {
618  m_eMode = mMove;
619  }
620  else if (m_moveType & IsRotatable)
621  {
622  // if user rotated the item, emit proper signal and update the label
623  emit itemRotated(rotation());
624  }
625  UpdateBox();
626  }
627  m_bReleased = true;
628  }
629 }
630 
631 //---------------------------------------------------------------------------------------------------------------------
632 /**
633  * @brief VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed
634  * @param event pointer to the scene hover event
635  */
636 void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
637 {
639  {
640  if (m_rectResize.contains(event->pos()))
641  {
642  setCursor(Qt::SizeFDiagCursor);
643  }
644  else
645  {
647  }
648  }
649  VPieceItem::hoverMoveEvent(event);
650 }
651 
652 //---------------------------------------------------------------------------------------------------------------------
653 /**
654  * @brief VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor
655  * @param event pointer to the scene hover event
656  */
657 void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
658 {
659  setCursor(QCursor());
660  VPieceItem::hoverLeaveEvent(event);
661 }
662 
663 //---------------------------------------------------------------------------------------------------------------------
664 /**
665  * @brief VTextGraphicsItem::UpdateBox redraws the label content
666  */
668 {
669  update(m_rectBoundingBox);
670 }
671 
672 //---------------------------------------------------------------------------------------------------------------------
673 /**
674  * @brief VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will
675  * just fit into the label bounding box
676  */
678 {
679  qreal xPos;
680  qreal yPos;
681  QRectF rectBB;
682  rectBB.setTopLeft(pos());
683  rectBB.setSize(m_rectBoundingBox.size());
684  if (isContained(rectBB, rotation(), xPos, yPos) == false)
685  {
686  // put the label inside the pattern
687  setPos(pos().x() + xPos, pos().y() + yPos);
688  }
690  UpdateBox();
691 }
692 
693 //---------------------------------------------------------------------------------------------------------------------
695 {
696  if (m_eMode != mRotate)
697  {
698  userMoveAndResize(pos);
699  }
700  else
701  {
703  }
704 }
705 
706 //---------------------------------------------------------------------------------------------------------------------
708 {
709  if (m_eMode != mRotate)
710  {
711  m_eMode = mMove;
712  }
714 }
715 
716 //---------------------------------------------------------------------------------------------------------------------
717 void VTextGraphicsItem::userMoveAndResize(const QPointF &pos)
718 {
719  if (m_rectResize.contains(pos) == true)
720  {
721  m_eMode = mResize;
722  setCursor(Qt::SizeAllCursor);
723  }
724  else
725  {
726  m_eMode = mMove; // block later if need
728  }
729 }
@ AllModifications
Definition: vpieceitem.h:70
QRectF m_rectBoundingBox
Definition: vpieceitem.h:102
VPieceItem::MoveTypes m_moveType
Definition: vpieceitem.h:106
qreal m_inactiveZ
Definition: vpieceitem.h:108
bool m_bReleased
Definition: vpieceitem.h:104
virtual QRectF boundingRect() const Q_DECL_OVERRIDE
boundingRect returns the item bounding box
Definition: vpieceitem.cpp:81
virtual double GetAngle(const QPointF &pt) const
GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis.
Definition: vpieceitem.cpp:118
void itemMoved(const QPointF &ptPos)
QPointF m_ptRotCenter
Definition: vpieceitem.h:105
Mode m_eMode
Definition: vpieceitem.h:103
The VPieceLabelData class holds some information about a single piece like letter,...
void itemRotated(qreal angle)
void UpdateBox()
VTextGraphicsItem::UpdateBox redraws the label content.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events.
void itemResized(qreal width, int fontSize)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mousePressEvent handles left button mouse press events.
void allUserModifications(const QPointF &pos)
int getFontSize() const
VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size.
int getTextLines() const
VTextGraphicsItem::getTextLines returns the number of lines of text to show.
void userMoveAndResize(const QPointF &pos)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
VTextGraphicsItem::paint redraws the item content.
void updateData(const QString &name, const VPieceLabelData &data)
VTextGraphicsItem::updateData Updates the detail label.
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed.
VTextGraphicsItem(QGraphicsItem *pParent=nullptr)
VTextGraphicsItem::VTextGraphicsItem constructor.
void correctLabel()
VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will just fit into the...
void setFont(const QFont &font)
VTextGraphicsItem::SetFont sets the item font.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mouseMoveEvent handles mouse move events.
VTextManager m_textMananger
void setSize(qreal width, qreal height)
VTextGraphicsItem::setSize Tries to set the label size to (width, height). If either of those is too ...
virtual void Update() Q_DECL_OVERRIDE
VTextGraphicsItem::Update sets the correct size and font size and redraws the label.
bool isContained(QRectF rectBB, qreal rotation, qreal &xPos, qreal &yPos) const
VTextGraphicsItem::isContained checks if the bounding box around rotated rectBB is contained in the p...
int GetSourceLinesCount() const
VTextManager::GetSourceLinesCount returns the number of input text lines.
virtual int GetSpacing() const
GetSpacing returns the vertical spacing between the lines.
const QFont & GetFont() const
GetFont returns the text base font.
const TextLine & GetSourceLine(int i) const
VTextManager::GetSourceLine returns the reference to i-th text line.
void Update(const QString &qsName, const VPieceLabelData &data)
VTextManager::Update updates the text lines with detail data.
void setFont(const QFont &font)
SetFont set the text base font.
void FitFontSize(qreal fW, qreal fH)
VTextManager::FitFontSize sets the font size just big enough, so that the text fits into rectangle of...
const QString cursorArrowOpenHand
Definition: def.cpp:191
const qreal PrintDPI
Definition: def.cpp:228
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
Definition: def.cpp:206
const QString cursorArrowCloseHand
Definition: def.cpp:192
QRectF GetBoundingRect(QRectF rectBB, qreal rotation)
GetBoundingRect calculates the bounding box around rectBB rectangle, rotated around its center by rot...
The TextLine struct holds the information about one text line.
Definition: vtextmanager.h:51
QString m_text
Definition: vtextmanager.h:52
bool bold
Definition: vtextmanager.h:54
int m_iFontSize
Definition: vtextmanager.h:53
Qt::Alignment m_eAlign
Definition: vtextmanager.h:56
bool italic
Definition: vtextmanager.h:55
#define qApp
Definition: vapplication.h:67
const qreal rotateCircle
const qreal resizeSquare
#define ACTIVE_Z
#define ROTATE_ARC
const qreal minH
#define ROTATE_RECT
const qreal minW