Salome HOME
Copyright update 2021
[modules/yacs.git] / src / genericgui / SceneTextItem.cxx
index 79b908d5702ad6325f9a4dbcb3bd55276042c270..1785ceb15e802c25109fc0640b617df93792910d 100644 (file)
@@ -1,21 +1,22 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "SceneTextItem.hxx"
 
 // #include "QtGuiContext.hxx"
@@ -23,6 +24,8 @@
 // #include <QGraphicsSceneHoverEvent>
 #include <QPointF>
 
+#include "Resource.hxx"
+
 // #include <cassert>
 
 //#define _DEVDEBUG_
@@ -34,12 +37,12 @@ using namespace YACS::HMI;
 
 
 SceneTextItem::SceneTextItem(QGraphicsScene *scene, SceneItem *parent,
-                             QString label)
-  : QGraphicsTextItem(label, parent), AbstractSceneItem(scene, parent, label)
+                             QString label, bool center )
+  : QGraphicsTextItem(parent), AbstractSceneItem(scene, parent, label)
 {
   setToolTip(label);
+  _center = center;
   DEBTRACE("SceneTextItem::SceneTextItem "<<label.toStdString()<<" "<<this<<" "<<_parent<<" "<< _level); 
-  setPos(x()+10, y());
 }
 
 SceneTextItem::~SceneTextItem()
@@ -55,17 +58,49 @@ void SceneTextItem::paint(QPainter *painter,
            QWidget *widget)
 {
   QGraphicsTextItem::paint(painter, option, widget);
+
+  int dx, fl;
+  if (_center) {
+    dx = 0;
+    fl = Qt::AlignCenter;
+  } else {
+    dx = Resource::Text_DX;
+    fl = Qt::AlignLeft | Qt::AlignVCenter;
+  };
+  painter->drawText(dx, 0, _parent->getWidth()-dx*2, _parent->getHeight(), fl, _label);
 }
 
 void SceneTextItem::setTopLeft(QPointF topLeft)
 {
 }
 
+void SceneTextItem::setPlainTextTrunc(QString label) {
+  _label = label;
+}
+
 void SceneTextItem::checkGeometryChange()
 {
 }
 
 void SceneTextItem::popupMenu(QWidget *caller, const QPoint &globalPos)
 {
+  DEBTRACE("SceneTextItem::popupMenu " << _parent);
   if (_parent) _parent->popupMenu(caller, globalPos);
 }
+
+/*! generic behaviour for headers:
+ *  obtain the tooltip from parent.
+ */
+QString SceneTextItem::getToolTip()
+{
+  QString tooltip = _label;
+  SceneItem *parent = getParent();
+  if (parent)
+    tooltip = parent->getToolTip();
+  return tooltip;
+}
+
+void SceneTextItem::setEventPos(QPointF point)
+{
+  _eventPos = mapFromScene(point);
+}