WQtRoiTreeItem.cpp 5.36 KB
Newer Older
schurade's avatar
schurade committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut 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 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

schurade's avatar
[STYLE]  
schurade committed
25 26
#include <string>

27 28 29 30 31 32 33 34 35 36 37
#include <QtCore/QList>
#include <QtGui/QScrollArea>
#include <QtGui/QVBoxLayout>
#include <QtGui/QListWidgetItem>
#include <QtGui/QApplication>
#include <QtGui/QWidgetAction>

#include "../guiElements/WScaleLabel.h"
#include "../WQt4Gui.h"
#include "../WMainWindow.h"
#include "WPropertyBoolWidget.h"
38
#include "WPropertyStringWidget.h"
39

40
#include "WTreeItemTypes.h"
schurade's avatar
schurade committed
41 42
#include "WQtRoiTreeItem.h"

43
WQtRoiTreeItem::WQtRoiTreeItem( QTreeWidgetItem * parent, osg::ref_ptr< WROI > roi, WTreeItemType type ) :
schurade's avatar
schurade committed
44 45 46
    QTreeWidgetItem( parent, type ),
    m_roi( roi )
{
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    setFlags( Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled );

    // create nice widget
    m_itemWidget = new QWidget( );
    QHBoxLayout* containerLayout = new QHBoxLayout();
    m_itemWidget->setLayout( containerLayout );

    // create a slider for the  for the texture
    QWidget* labelContainer = new QWidget( m_itemWidget );
    QHBoxLayout* labelContainerLayout = new QHBoxLayout();
    labelContainer->setLayout( labelContainerLayout );

    QWidget* propertyContainer = new QWidget( m_itemWidget );
    QHBoxLayout* propertyContainerLayout = new QHBoxLayout();
    propertyContainer->setLayout( propertyContainerLayout );
    propertyContainer->setObjectName( "propertyContainer" );

64 65 66 67 68
    // name
    WPropertyStringWidget* name = new WPropertyStringWidget( roi->nameProperty(), NULL, m_itemWidget );
    name->setToolTip( "The name of this ROI." );
    name->forceInformationMode();
    name->disableTextInteraction();
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

    // inverse
    WPropertyBoolWidget* isnot = new WPropertyBoolWidget( roi->invertProperty(), NULL, m_itemWidget );
    isnot->setToolTip( QString::fromStdString( roi->invertProperty()->getDescription() ) );

    // active
    WPropertyBoolWidget* active = new WPropertyBoolWidget( roi->activeProperty(), NULL, m_itemWidget );
    active->setToolTip( QString::fromStdString( roi->activeProperty()->getDescription() ) );

    // show
    WPropertyBoolWidget* show = new WPropertyBoolWidget( roi->showProperty(), NULL, m_itemWidget );
    show->setToolTip( QString::fromStdString( roi->showProperty()->getDescription() ) );

    QLabel* grabWidget = new QLabel( m_itemWidget );
    grabWidget->setPixmap( WQt4Gui::getMainWindow()->getIconManager()->getIcon( "touchpoint_small" ).pixmap( 24, 32 ) );
    grabWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
    grabWidget->setFixedWidth( 24 );
86
    grabWidget->setToolTip( "Drag and drop this ROI to change their ordering." );
87 88 89 90 91 92 93 94 95 96

    // style
    QPalette palette;
    QColor defaultCol = palette.window().color();

    // label color
    QColor labelCol = defaultCol.darker( 115 );
    // property color
    QColor propertyCol = defaultCol;

97
    //name->setStyleSheet( "background-color:" + labelCol.name() + ";border:none;" );
98 99 100 101 102 103 104 105
    labelContainer->setStyleSheet( "background-color:" + labelCol.name() + ";" );
    propertyContainer->setStyleSheet( "QWidget#propertyContainer{ background-color:" + propertyCol.name() + ";}" );

    // fill all layouts
    propertyContainerLayout->addWidget( isnot );
    propertyContainerLayout->addWidget( show );

    labelContainerLayout->addWidget( active );
106 107
    labelContainerLayout->addWidget( name );
    labelContainerLayout->setStretchFactor( name, 100 );
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    labelContainerLayout->setStretchFactor( active, 0 );

    // fill layout
    containerLayout->addWidget( grabWidget );
    containerLayout->addWidget( labelContainer );
    containerLayout->addWidget( propertyContainer );

    // compact layout
    containerLayout->setContentsMargins( 0, 2, 0, 2 );
    containerLayout->setSpacing( 0 );
    labelContainerLayout->setContentsMargins( 2, 2, 0, 2 );
    labelContainerLayout->setSpacing( 0 );
    propertyContainerLayout->setContentsMargins( 2, 2, 0, 2 );
    propertyContainerLayout->setSpacing( 0 );

    // prefer stretching the label
    containerLayout->setStretchFactor( grabWidget, 0 );
    containerLayout->setStretchFactor( labelContainer, 100 );
    containerLayout->setStretchFactor( propertyContainer, 0 );

    // widget size constraints and policies
    m_itemWidget->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
schurade's avatar
schurade committed
130 131 132 133 134 135
}

WQtRoiTreeItem::~WQtRoiTreeItem()
{
}

136
osg::ref_ptr< WROI > WQtRoiTreeItem::getRoi()
schurade's avatar
schurade committed
137 138 139
{
    return m_roi;
}
140 141 142 143 144 145

QWidget* WQtRoiTreeItem::getWidget() const
{
    return m_itemWidget;
}