mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-04-11 19:07:28 +05:00
225 lines
8.0 KiB
C++
225 lines
8.0 KiB
C++
![]() |
// Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
|
||
|
//
|
||
|
// 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.
|
||
|
//
|
||
|
// 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
|
||
|
//
|
||
|
|
||
|
#include "DependencyTree_Object.h"
|
||
|
|
||
|
// GUI includes
|
||
|
#include <SUIT_Session.h>
|
||
|
#include <SUIT_ResourceMgr.h>
|
||
|
|
||
|
// Qt includes
|
||
|
#include <QFont>
|
||
|
|
||
|
const int itemH = 20;
|
||
|
const int itemW = 90;
|
||
|
|
||
|
DependencyTree_Object::DependencyTree_Object( const QString& theEntry, QGraphicsItem* theParent )
|
||
|
:GraphicsView_Object( theParent ),
|
||
|
myIsMainObject( false ),
|
||
|
myIsLongName( false )
|
||
|
{
|
||
|
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
|
||
|
|
||
|
myColor = resMgr->colorValue( "Geometry", "dependency_tree_node_color", QColor( 62, 180, 238 ) );
|
||
|
mySelectColor = resMgr->colorValue( "Geometry", "dependency_tree_select_node_color", QColor( 237, 243, 58 ) );
|
||
|
myMainObjectColor = resMgr->colorValue( "Geometry", "dependency_tree_main_node_color", QColor( 238, 90, 125 ) );
|
||
|
|
||
|
myPolygonItem = new QGraphicsPolygonItem();
|
||
|
QPolygonF myPolygon;
|
||
|
myPolygon << QPointF( -itemW, -itemH ) << QPointF( itemW, -itemH ) << QPointF( itemW, itemH )
|
||
|
<< QPointF( -itemW, itemH ) << QPointF( -itemW, -itemH );
|
||
|
|
||
|
myPolygonItem->setPolygon( myPolygon );
|
||
|
myPolygonItem->setBrush( myColor );
|
||
|
myPolygonItem->setPen( getPen( myColor ) );
|
||
|
|
||
|
myTextItem = new QGraphicsSimpleTextItem();
|
||
|
QFont textFont;
|
||
|
textFont.setPointSize( itemH );
|
||
|
myTextItem->setFont( textFont );
|
||
|
|
||
|
myEntry = theEntry;
|
||
|
updateName();
|
||
|
|
||
|
addToGroup( myPolygonItem );
|
||
|
addToGroup( myTextItem );
|
||
|
}
|
||
|
|
||
|
DependencyTree_Object::~DependencyTree_Object()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : highlight()
|
||
|
// purpose : highlight current item
|
||
|
//=================================================================================
|
||
|
bool DependencyTree_Object::highlight( double theX, double theY )
|
||
|
{
|
||
|
if( !isHighlighted() ) {
|
||
|
QColor color = myPolygonItem->brush().color();
|
||
|
int saturation = ( color.saturation() - 100 ) > 10 ? color.saturation() - 100 : 10;
|
||
|
color.setHsv( color.hsvHue(), saturation, color.value() );
|
||
|
|
||
|
myPolygonItem->setBrush( color );
|
||
|
myPolygonItem->setPen( getPen( color ) );
|
||
|
|
||
|
if( myIsLongName )
|
||
|
myPolygonItem->setToolTip( getName() );
|
||
|
}
|
||
|
return GraphicsView_Object::highlight( theX, theY );
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : unhighlight()
|
||
|
// purpose : set properties for unhighlighted item
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::unhighlight()
|
||
|
{
|
||
|
if( isSelected() )
|
||
|
myPolygonItem->setBrush( mySelectColor );
|
||
|
else if( myIsMainObject )
|
||
|
myPolygonItem->setBrush( myMainObjectColor );
|
||
|
else
|
||
|
myPolygonItem->setBrush( myColor );
|
||
|
|
||
|
myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
|
||
|
|
||
|
GraphicsView_Object::unhighlight();
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : select()
|
||
|
// purpose : select current item
|
||
|
//=================================================================================
|
||
|
bool DependencyTree_Object::select( double theX, double theY, const QRectF& theRect )
|
||
|
{
|
||
|
myPolygonItem->setBrush( mySelectColor );
|
||
|
myPolygonItem->setPen( getPen( mySelectColor ) );
|
||
|
|
||
|
return GraphicsView_Object::select( theX, theY, theRect );
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : unselect()
|
||
|
// purpose : set properties for unselected item
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::unselect()
|
||
|
{
|
||
|
if( myIsMainObject )
|
||
|
myPolygonItem->setBrush( myMainObjectColor );
|
||
|
else
|
||
|
myPolygonItem->setBrush( myColor );
|
||
|
|
||
|
myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
|
||
|
|
||
|
GraphicsView_Object::unselect();
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : getEntry()
|
||
|
// purpose : get entry of current item
|
||
|
//=================================================================================
|
||
|
QString DependencyTree_Object::getEntry() const
|
||
|
{
|
||
|
return myEntry;
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : updateName()
|
||
|
// purpose : update name of current item using its entry
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::updateName()
|
||
|
{
|
||
|
QString name = myEntry;
|
||
|
|
||
|
setName( myEntry );
|
||
|
|
||
|
myTextItem->setText( name );
|
||
|
double textWidth = myTextItem->sceneBoundingRect().width();
|
||
|
double textHeight = myTextItem->sceneBoundingRect().height();
|
||
|
|
||
|
double polygonWidth = myPolygonItem->sceneBoundingRect().width();
|
||
|
double polygonHeight = myPolygonItem->sceneBoundingRect().height();
|
||
|
|
||
|
if( ( textWidth - 4 ) > polygonWidth ) {
|
||
|
myIsLongName = true;
|
||
|
int numberSymbol = int( polygonWidth * name.length() / textWidth );
|
||
|
QString newName = name.left( numberSymbol - 3 ) + "...";
|
||
|
myTextItem->setText( newName );
|
||
|
textWidth = myTextItem->sceneBoundingRect().width();
|
||
|
}
|
||
|
myTextItem->setPos( ( polygonWidth - textWidth ) / 2 - itemW,
|
||
|
( polygonHeight - textHeight ) / 2 - itemH );
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : setColor()
|
||
|
// purpose : set default color of current item
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::setColor( const QColor& theColor )
|
||
|
{
|
||
|
myColor = theColor;
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : setSelectColor()
|
||
|
// purpose : set color of selected item
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::setSelectColor( const QColor& theColor )
|
||
|
{
|
||
|
mySelectColor = theColor;
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : setMainObjectColor()
|
||
|
// purpose : set color if current item is main object of dependency tree
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::setMainObjectColor( const QColor& theColor )
|
||
|
{
|
||
|
myMainObjectColor = theColor;
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : setIsMainObject()
|
||
|
// purpose : set true if current item is main object of dependency tree
|
||
|
//=================================================================================
|
||
|
void DependencyTree_Object::setIsMainObject( bool theIsMainObject )
|
||
|
{
|
||
|
myIsMainObject = theIsMainObject;
|
||
|
|
||
|
if( myIsMainObject )
|
||
|
myPolygonItem->setBrush( myMainObjectColor );
|
||
|
else
|
||
|
myPolygonItem->setBrush( myColor );
|
||
|
|
||
|
myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
|
||
|
}
|
||
|
|
||
|
//=================================================================================
|
||
|
// function : getPen()
|
||
|
// purpose : get pen which is dependent of current color
|
||
|
//=================================================================================
|
||
|
QPen DependencyTree_Object::getPen( const QColor& theColor )
|
||
|
{
|
||
|
int value = ( theColor.value() - 100 ) > 10 ? theColor.value() - 100 : 10;
|
||
|
QColor penColor;
|
||
|
penColor.setHsv( theColor.hsvHue(), theColor.saturation(), value );
|
||
|
return QPen( QBrush( penColor ), 4 );
|
||
|
}
|