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
25#include <QGraphicsView>
26#include <QPainter>
27#include <QStyleOptionGraphicsItem>
28#include <qgraphicssceneevent.h>
29
31
32namespace armarx
33{
34
35 MorphingItem::MorphingItem(QGraphicsItem* derivedItem) : derivedItem(derivedItem)
36 {
37 }
38
39 QGraphicsView*
40 MorphingItem::getView(QGraphicsSceneEvent* event)
41 {
42 QGraphicsView* view = qobject_cast<QGraphicsView*>(event->widget()->parent());
43 return view;
44 }
45
47 MorphingItem::getLevelOfDetail(QPainter* painter) const
48 {
49 qreal lodT =
50 QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
51
53 {
54 // ARMARX_IMPORTANT_S << "Hiding: " << lodT;
55 return eHidden;
56 }
57
58 return getLevelOfDetail(lodT);
59 }
60
62 MorphingItem::getLevelOfDetail(float levelOfDetail) const
63 {
64 float width = derivedItem->boundingRect().width() * levelOfDetail;
65
66 // ARMARX_INFO_S << "width is " << width;
67 if (width < minSizeToShowSubstates)
68 {
69 return eNoSubstates;
70 }
71 else
72 {
73 // ARMARX_INFO_S << "width is " << width;
74 return eFull;
75 }
76 }
77
79 MorphingItem::getLevelOfDetailByParent(QPainter* painter, MorphingItem* parent) const
80 {
81 qreal lodT =
82 QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
83 qreal lodP = lodT;
85
86
87 if (derivedItem)
88 {
89 lodP /= derivedItem->scale();
90
91 if (parent)
92 if (parent->getLevelOfDetail(lodP) >= eNoSubstates)
93 {
95 }
96 }
97
98 return detail;
99 }
100
101} // namespace armarx
static QGraphicsView * getView(QGraphicsSceneEvent *event)
MorphingItem(QGraphicsItem *derivedItem)
virtual LevelOfDetail getLevelOfDetail(QPainter *painter) const
static constexpr float minSizeToShowSubstates
static constexpr float hideOnHighDeZoomThreshold
virtual LevelOfDetail getLevelOfDetailByParent(QPainter *painter, MorphingItem *parent) const
This file offers overloads of toIce() and fromIce() functions for STL container types.
@ eNoSubstates