]> SALOME platform Git repositories - modules/yacs.git/blob - src/genericgui/SceneHeaderItem.cxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / SceneHeaderItem.cxx
1 //  Copyright (C) 2006-2008  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.
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 #include "SceneHeaderItem.hxx"
20 #include "SceneHeaderNodeItem.hxx"
21 #include "SceneTextItem.hxx"
22 #include "Scene.hxx"
23 #include <QGraphicsSceneMouseEvent>
24
25 // #include "QtGuiContext.hxx"
26 // #include "Menus.hxx"
27 // #include <QGraphicsSceneHoverEvent>
28 // #include <QPointF>
29
30 #include <cassert>
31
32 //#define _DEVDEBUG_
33 #include "YacsTrace.hxx"
34
35 using namespace std;
36 using namespace YACS::ENGINE;
37 using namespace YACS::HMI;
38
39
40 SceneHeaderItem::SceneHeaderItem(QGraphicsScene *scene, SceneItem *parent,
41                                  QString label)
42   : SceneItem(scene, parent, label)
43 {
44   assert(_parent);
45   _height = 25;
46   _width = _parent->getInternWidth();
47   _text=0;
48   _brushColor   = QColor(215,220,238);
49   _hiBrushColor = QColor(161,178,238);
50 //   _penColor     = QColor(120,120,120);
51 //   _hiPenColor   = QColor( 60, 60, 60);
52   _hasNml = false;
53 }
54
55 SceneHeaderItem::~SceneHeaderItem()
56 {
57 }
58
59 QRectF SceneHeaderItem::getMinimalBoundingRect() const
60 {
61   return QRectF(x(), y(), 5, _height);
62 }
63
64 void SceneHeaderItem::paint(QPainter *painter,
65                             const QStyleOptionGraphicsItem *option,
66                             QWidget *widget)
67 {
68 //   DEBTRACE("SceneHeaderItem::paint");
69   painter->save();
70   painter->setPen(getPenColor());
71   painter->setBrush(getBrushColor());
72   painter->drawRoundRect(QRectF(0, 0, _width, _height), 33*_height/_width, 33);
73   painter->restore();
74 }
75
76 void SceneHeaderItem::setText(QString label)
77 {
78   if (!_text)
79     _text = new SceneTextItem(_scene,
80                               this,
81                               label);
82   else
83     _text->setPlainText(label);
84 }
85
86 void SceneHeaderItem::popupMenu(QWidget *caller, const QPoint &globalPos)
87 {
88   if (_parent) _parent->popupMenu(caller, globalPos);
89 }
90
91 void SceneHeaderItem::adjustGeometry()
92 {
93   _width = _parent->getInternWidth() -1;
94 }
95
96 QColor SceneHeaderItem::getPenColor()
97 {
98 QColor color = _penColor;
99  if (getParent())
100    if(getParent()->getParent())
101      if (getParent()->getParent()->isSelected())
102        color = _hiPenColor;
103  return color;
104 }
105
106 QColor SceneHeaderItem::getBrushColor()
107 {
108   QColor color = _brushColor;
109   if (dynamic_cast<SceneHeaderNodeItem*>(getParent()))
110     if (getParent()->getParent()->isSelected())
111       color = _hiBrushColor;
112   if (_hover)
113     color = hoverColor(color);
114   return color;
115 }
116
117 void SceneHeaderItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
118 {
119   event->ignore();
120 }