Version: 8.3.0
SceneTextItem.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "SceneTextItem.hxx"
21 
22 // #include "QtGuiContext.hxx"
23 // #include "Menus.hxx"
24 // #include <QGraphicsSceneHoverEvent>
25 #include <QPointF>
26 
27 #include "Resource.hxx"
28 
29 // #include <cassert>
30 
31 //#define _DEVDEBUG_
32 #include "YacsTrace.hxx"
33 
34 using namespace std;
35 using namespace YACS::ENGINE;
36 using namespace YACS::HMI;
37 
38 
39 SceneTextItem::SceneTextItem(QGraphicsScene *scene, SceneItem *parent,
40  QString label, bool center )
41  : QGraphicsTextItem(parent), AbstractSceneItem(scene, parent, label)
42 {
43  setToolTip(label);
44  _center = center;
45  DEBTRACE("SceneTextItem::SceneTextItem "<<label.toStdString()<<" "<<this<<" "<<_parent<<" "<< _level);
46 }
47 
49 {
50 }
51 
53 {
54  return QGraphicsTextItem::boundingRect();
55 }
56 void SceneTextItem::paint(QPainter *painter,
57  const QStyleOptionGraphicsItem *option,
58  QWidget *widget)
59 {
60  QGraphicsTextItem::paint(painter, option, widget);
61 
62  int dx, fl;
63  if (_center) {
64  dx = 0;
65  fl = Qt::AlignCenter;
66  } else {
67  dx = Resource::Text_DX;
68  fl = Qt::AlignLeft | Qt::AlignVCenter;
69  };
70  painter->drawText(dx, 0, _parent->getWidth()-dx*2, _parent->getHeight(), fl, _label);
71 }
72 
73 void SceneTextItem::setTopLeft(QPointF topLeft)
74 {
75 }
76 
77 void SceneTextItem::setPlainTextTrunc(QString label) {
78  _label = label;
79 }
80 
82 {
83 }
84 
85 void SceneTextItem::popupMenu(QWidget *caller, const QPoint &globalPos)
86 {
87  DEBTRACE("SceneTextItem::popupMenu " << _parent);
88  if (_parent) _parent->popupMenu(caller, globalPos);
89 }
90 
95 {
96  QString tooltip = _label;
97  SceneItem *parent = getParent();
98  if (parent)
99  tooltip = parent->getToolTip();
100  return tooltip;
101 }
102 
103 void SceneTextItem::setEventPos(QPointF point)
104 {
105  _eventPos = mapFromScene(point);
106 }