00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #include "QmitkColorPropertyView.h" 00018 #include <QPixmap> 00019 #define ROUND_P(x) ((int)((x)+0.5)) 00020 00021 QmitkColorPropertyView::QmitkColorPropertyView( const mitk::ColorProperty* property, QWidget* parent ) 00022 : QLabel( parent ), 00023 PropertyView( property ), 00024 m_ColorProperty(property) 00025 //m_SelfCall(false) 00026 { 00027 setText(" "); // two spaces for some minimun height 00028 setMinimumSize(15,15); 00029 PropertyChanged(); 00030 00031 m_WidgetPalette = QWidget::palette(); 00032 QWidget::setPalette(m_WidgetPalette); 00033 QWidget::setAutoFillBackground(true); 00034 } 00035 00036 QmitkColorPropertyView::~QmitkColorPropertyView() 00037 { 00038 } 00039 00040 //void QmitkColorPropertyView::unsetPalette() 00041 //{ 00042 // // just ignore calls... this widget is the only one to change its background color 00043 //} 00044 00045 //void QmitkColorPropertyView::setPalette( const QPalette& p) 00046 //{ 00047 // // just ignore calls... this widget is the only one to change its background color 00048 // if (m_SelfCall) QWidget::setPalette(p); 00049 //} 00050 00051 //void QmitkColorPropertyView::setBackgroundMode( QWidget::BackgroundMode ) 00052 //{ 00053 // // just ignore calls... this widget is the only one to change its background color 00054 //} 00055 00056 //void QmitkColorPropertyView::setPaletteBackgroundColor( const QColor & ) 00057 //{ 00058 // // just ignore calls... this widget is the only one to change its background color 00059 //} 00060 00061 void QmitkColorPropertyView::PropertyChanged() 00062 { 00063 if ( m_Property ) 00064 DisplayColor(); 00065 } 00066 00067 void QmitkColorPropertyView::PropertyRemoved() 00068 { 00069 m_Property = NULL; 00070 m_ColorProperty = NULL; 00071 //QLabel::setPaletteBackgroundPixmap( QPixmap(no_color_icon_xpm) ); 00072 } 00073 00074 void QmitkColorPropertyView::DisplayColor() 00075 { 00076 const mitk::Color& tmp_col(m_ColorProperty->GetColor()); 00077 00078 QColor color( ROUND_P(tmp_col[0] * 255.0), ROUND_P(tmp_col[1] * 255.0) , ROUND_P(tmp_col[2] * 255.0) ); 00079 //m_SelfCall = true; 00080 //QWidget::setPaletteBackgroundColor( color ); 00081 //m_SelfCall = false; 00082 00083 m_WidgetPalette.setColor(QPalette::Background, color); 00084 } 00085 00086