OpenWalnut  1.5.0dev
WQtRoiTreeItem.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 
27 #include <QtCore/QList>
28 #include <QScrollArea>
29 #include <QVBoxLayout>
30 #include <QListWidgetItem>
31 #include <QApplication>
32 #include <QWidgetAction>
33 
34 #include "../guiElements/WScaleLabel.h"
35 #include "../WQtGui.h"
36 #include "../WMainWindow.h"
37 #include "WPropertyBoolWidget.h"
38 #include "WPropertyStringWidget.h"
39 
40 #include "WTreeItemTypes.h"
41 #include "WQtRoiTreeItem.h"
42 
43 WQtRoiTreeItem::WQtRoiTreeItem( QTreeWidgetItem * parent, osg::ref_ptr< WROI > roi, WTreeItemType type ) :
44  QTreeWidgetItem( parent, type ),
45  m_roi( roi )
46 {
47  setFlags( Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled );
48 }
49 
51 {
52 }
53 
54 osg::ref_ptr< WROI > WQtRoiTreeItem::getRoi()
55 {
56  return m_roi;
57 }
58 
60 {
61  // create nice widget
62  QWidget* itemWidget = new QWidget( );
63  QHBoxLayout* containerLayout = new QHBoxLayout();
64  itemWidget->setLayout( containerLayout );
65 
66  // create a slider for the for the texture
67  QWidget* labelContainer = new QWidget( itemWidget );
68  QHBoxLayout* labelContainerLayout = new QHBoxLayout();
69  labelContainer->setLayout( labelContainerLayout );
70 
71  QWidget* propertyContainer = new QWidget( itemWidget );
72  QHBoxLayout* propertyContainerLayout = new QHBoxLayout();
73  propertyContainer->setLayout( propertyContainerLayout );
74  propertyContainer->setObjectName( "propertyContainer" );
75 
76  // name
77  WPropertyStringWidget* name = new WPropertyStringWidget( m_roi->nameProperty(), NULL, itemWidget );
78  name->setToolTip( "The name of this ROI." );
79  name->forceInformationMode();
80  name->disableTextInteraction();
81 
82  // inverse
83  WPropertyBoolWidget* isnot = new WPropertyBoolWidget( m_roi->invertProperty(), NULL, itemWidget );
84  isnot->setToolTip( QString::fromStdString( m_roi->invertProperty()->getDescription() ) );
85 
86  // active
87  WPropertyBoolWidget* active = new WPropertyBoolWidget( m_roi->activeProperty(), NULL, itemWidget );
88  active->setToolTip( QString::fromStdString( m_roi->activeProperty()->getDescription() ) );
89 
90  // show
91  WPropertyBoolWidget* show = new WPropertyBoolWidget( m_roi->showProperty(), NULL, itemWidget );
92  show->setToolTip( QString::fromStdString( m_roi->showProperty()->getDescription() ) );
93 
94  QLabel* grabWidget = new QLabel( itemWidget );
95  grabWidget->setPixmap( WQtGui::getMainWindow()->getIconManager()->getIcon( "touchpoint_small" ).pixmap( 24, 32 ) );
96  grabWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
97  grabWidget->setFixedWidth( 24 );
98  grabWidget->setToolTip( "Drag and drop this ROI to change their ordering." );
99 
100  // style
101  QPalette palette;
102  QColor defaultCol = palette.window().color();
103 
104  // label color
105  QColor labelCol = defaultCol.darker( 115 );
106  // property color
107  QColor propertyCol = defaultCol;
108 
109  //name->setStyleSheet( "background-color:" + labelCol.name() + ";border:none;" );
110  labelContainer->setStyleSheet( "background-color:" + labelCol.name() + ";" );
111  propertyContainer->setStyleSheet( "QWidget#propertyContainer{ background-color:" + propertyCol.name() + ";}" );
112 
113  // fill all layouts
114  propertyContainerLayout->addWidget( isnot );
115  propertyContainerLayout->addWidget( show );
116 
117  labelContainerLayout->addWidget( active );
118  labelContainerLayout->addWidget( name );
119  labelContainerLayout->setStretchFactor( name, 100 );
120  labelContainerLayout->setStretchFactor( active, 0 );
121 
122  // fill layout
123  containerLayout->addWidget( grabWidget );
124  containerLayout->addWidget( labelContainer );
125  containerLayout->addWidget( propertyContainer );
126 
127  // compact layout
128  containerLayout->setContentsMargins( 0, 2, 0, 2 );
129  containerLayout->setSpacing( 0 );
130  labelContainerLayout->setContentsMargins( 2, 2, 0, 2 );
131  labelContainerLayout->setSpacing( 0 );
132  propertyContainerLayout->setContentsMargins( 2, 2, 0, 2 );
133  propertyContainerLayout->setSpacing( 0 );
134 
135  // prefer stretching the label
136  containerLayout->setStretchFactor( grabWidget, 0 );
137  containerLayout->setStretchFactor( labelContainer, 100 );
138  containerLayout->setStretchFactor( propertyContainer, 0 );
139 
140  // widget size constraints and policies
141  itemWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
142 
143  return itemWidget;
144 }
145 
Implements a property widget for WPropBool.
Implements a property widget for WPropString.
void disableTextInteraction(bool disable=true)
Disable the ability to select text.
void forceInformationMode(bool force=true)
Force the widget to use the information widgets.
static WMainWindow * getMainWindow()
Returns the current main window instance or NULL if not existent.
Definition: WQtGui.cpp:88
osg::ref_ptr< WROI > getRoi()
Getter.
WQtRoiTreeItem(QTreeWidgetItem *parent, osg::ref_ptr< WROI > roi, WTreeItemType type=ROI)
Constructor.
QWidget * createWidget() const
Create a representation widget for this item.
osg::ref_ptr< WROI > m_roi
Pointer to the ROI represented by this item.
virtual ~WQtRoiTreeItem()
Destructor.