MorphingItem.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "MorphingItem.h"
24 #include <QStyleOptionGraphicsItem>
25 
26 
28 
29 #include <QGraphicsView>
30 #include <QPainter>
31 #include <qgraphicssceneevent.h>
32 
33 namespace armarx
34 {
35 
36  MorphingItem::MorphingItem(QGraphicsItem* derivedItem) :
37  derivedItem(derivedItem)
38  {
39 
40  }
41 
42  QGraphicsView* MorphingItem::getView(QGraphicsSceneEvent* event)
43  {
44  QGraphicsView* view = qobject_cast<QGraphicsView*>(event->widget()->parent());
45  return view;
46  }
47 
49  {
50  qreal lodT = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
51 
52  if (lodT > hideOnHighDeZoomThreshold)
53  {
54  // ARMARX_IMPORTANT_S << "Hiding: " << lodT;
55  return eHidden;
56  }
57 
58  return getLevelOfDetail(lodT);
59  }
60 
61  LevelOfDetail MorphingItem::getLevelOfDetail(float levelOfDetail) const
62  {
63  float width = derivedItem->boundingRect().width() * levelOfDetail;
64 
65  // ARMARX_INFO_S << "width is " << width;
66  if (width < minSizeToShowSubstates)
67  {
68  return eNoSubstates;
69  }
70  else
71  {
72  // ARMARX_INFO_S << "width is " << width;
73  return eFull;
74  }
75  }
76 
78  {
79  qreal lodT = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
80  qreal lodP = lodT;
82 
83 
84  if (derivedItem)
85  {
86  lodP /= derivedItem->scale();
87 
88  if (parent)
89  if (parent->getLevelOfDetail(lodP) >= eNoSubstates)
90  {
91  detail = eHidden;
92  }
93  }
94 
95  return detail;
96  }
97 
98 } // namespace armarx
armarx::eFull
@ eFull
Definition: MorphingItem.h:35
armarx::MorphingItem::getLevelOfDetail
virtual LevelOfDetail getLevelOfDetail(QPainter *painter) const
Definition: MorphingItem.cpp:48
armarx::MorphingItem::getView
static QGraphicsView * getView(QGraphicsSceneEvent *event)
Definition: MorphingItem.cpp:42
detail
Definition: OpenCVUtil.cpp:127
armarx::MorphingItem
Definition: MorphingItem.h:39
armarx::eHidden
@ eHidden
Definition: MorphingItem.h:37
armarx::MorphingItem::MorphingItem
MorphingItem(QGraphicsItem *derivedItem)
Definition: MorphingItem.cpp:36
MorphingItem.h
armarx::MorphingItem::minSizeToShowSubstates
static constexpr float minSizeToShowSubstates
Definition: MorphingItem.h:49
armarx::MorphingItem::getLevelOfDetailByParent
virtual LevelOfDetail getLevelOfDetailByParent(QPainter *painter, MorphingItem *parent) const
Definition: MorphingItem.cpp:77
armarx::MorphingItem::hideOnHighDeZoomThreshold
static constexpr float hideOnHighDeZoomThreshold
Definition: MorphingItem.h:48
armarx::LevelOfDetail
LevelOfDetail
Definition: MorphingItem.h:33
Logging.h
armarx::eNoSubstates
@ eNoSubstates
Definition: MorphingItem.h:36
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28