Salome HOME
refs #550: fix crash when myObject is NULL
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ColorDlg.cxx
index 278fdad2b5f69ddde64769a94a10cabf245c7d14..8fe8a36ae742e054ffedf67aec51095951a41a9a 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // 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.
+// 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
 #include <QRadioButton>
 #include <QPushButton>
 
-HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent )
-: QDialog( theParent )
+HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent, bool theIsOneColor )
+: QDialog( theParent ),
+  myIsOneColor( theIsOneColor )
 {
-  // Filling color
-  QFrame* aFillingFrame = new QFrame( this );
-  QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
-  myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
-  myFillingTransparent->setChecked( true );
-  myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
-  myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
-
-  QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
-  aFillingLayout->setMargin( 5 );
-  aFillingLayout->setSpacing( 5 );
-  aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
-  aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
-  aFillingLayout->addWidget( myFillingColor,       1, 1 );
-  aFillingLayout->addWidget( myFillingColorBox,    1, 2 );
-
-  // Border color
-  myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
-  myBorderColorGroup->setCheckable( true );
-
-  myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
-
-  QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
-  aBorderColorLayout->setMargin( 5 );
-  aBorderColorLayout->setSpacing( 5 );
-  aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
-  aBorderColorLayout->addWidget( myBorderColorBox );
+  QVBoxLayout* aMainLayout = new QVBoxLayout( this );
+  aMainLayout->setMargin( 5 );
+  aMainLayout->setSpacing( 5 );
+
+  if ( !theIsOneColor )
+  {
+    // Filling color
+    QFrame* aFillingFrame = new QFrame( this );
+    QLabel* aFillingLabel = new QLabel( tr( "FILLING_COLOR" ), aFillingFrame );
+    myFillingTransparent = new QRadioButton( tr( "TRANSPARENT" ), aFillingFrame );
+    myFillingTransparent->setChecked( true );
+    myFillingColor = new QRadioButton( tr( "COLOR" ), aFillingFrame );
+    myFillingColorBox = new HYDROGUI_ColorWidget( aFillingFrame );
+
+    QGridLayout* aFillingLayout = new QGridLayout( aFillingFrame );
+    aFillingLayout->setMargin( 5 );
+    aFillingLayout->setSpacing( 5 );
+    aFillingLayout->addWidget( aFillingLabel, 0, 0, 2, 1 );
+    aFillingLayout->addWidget( myFillingTransparent, 0, 1 );
+    aFillingLayout->addWidget( myFillingColor,       1, 1 );
+    aFillingLayout->addWidget( myFillingColorBox,    1, 2 );
+
+    // Border color
+    myBorderColorGroup = new QGroupBox( tr( "BORDER_COLOR" ), this );
+    myBorderColorGroup->setCheckable( true );
+
+    myBorderColorBox = new HYDROGUI_ColorWidget( myBorderColorGroup );
+
+    QBoxLayout* aBorderColorLayout = new QHBoxLayout( myBorderColorGroup );
+    aBorderColorLayout->setMargin( 5 );
+    aBorderColorLayout->setSpacing( 5 );
+    aBorderColorLayout->addWidget( new QLabel( tr( "COLOR" ), myBorderColorGroup ) );
+    aBorderColorLayout->addWidget( myBorderColorBox );
+
+    aMainLayout->addWidget( aFillingFrame );
+    aMainLayout->addWidget( myBorderColorGroup );
+
+    connect( myFillingTransparent, SIGNAL( toggled( bool ) ), 
+             myFillingColorBox, SLOT( setDisabled( bool ) ) );
+  }
+  else
+  {
+    QFrame* aColorFrame = new QFrame( this );
+    QLabel* aColorLabel = new QLabel( tr( "OBJECT_COLOR" ), aColorFrame );
+    myColorBox = new HYDROGUI_ColorWidget( aColorFrame );
+    myColorBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); 
+    myColorBox->setFixedHeight( 20 );
+
+    QBoxLayout* aColorLayout = new QHBoxLayout( aColorFrame );
+    aColorLayout->setMargin( 10 );
+    aColorLayout->setSpacing( 5 );
+    aColorLayout->addWidget( aColorLabel );
+    aColorLayout->addWidget( myColorBox );
+
+    aMainLayout->addWidget( aColorFrame );
+  }
 
   // Buttons
   QPushButton* anOkButton = new QPushButton( tr( "OK" ), this );
@@ -76,12 +102,6 @@ HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent )
   aButtonsLayout->addWidget( aCancelButton );
 
   // Common
-  QVBoxLayout* aMainLayout = new QVBoxLayout( this );
-  aMainLayout->setMargin( 5 );
-  aMainLayout->setSpacing( 5 );
-
-  aMainLayout->addWidget( aFillingFrame );
-  aMainLayout->addWidget( myBorderColorGroup );
   aMainLayout->addStretch();
   aMainLayout->addLayout( aButtonsLayout );
 
@@ -91,43 +111,67 @@ HYDROGUI_ColorDlg::HYDROGUI_ColorDlg( QWidget* theParent )
   connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
   connect( aCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
-  setFixedSize( 300, 150 );
+  setFixedSize( 300, theIsOneColor ? 90 : 150 );
 }
 
 HYDROGUI_ColorDlg::~HYDROGUI_ColorDlg()
 {
 }
 
-void HYDROGUI_ColorDlg::setFillingColor( const QColor& theColor )
+void HYDROGUI_ColorDlg::setFirstColor( const QColor& theColor )
 {
-  if( theColor.alpha() == 0 ) // transparent
-    myFillingTransparent->setChecked( true );
+  if ( !myIsOneColor )
+  {
+    if( theColor.alpha() == 0 ) // transparent
+      myFillingTransparent->setChecked( true );
+    else
+      myFillingColor->setChecked( true );
+
+    myFillingColorBox->setColor( theColor );
+  }
   else
-    myFillingColor->setChecked( true );
-
-  myFillingColorBox->setColor( theColor );
+  {
+    myColorBox->setColor( theColor );
+  }
 }
 
-QColor HYDROGUI_ColorDlg::getFillingColor() const
+QColor HYDROGUI_ColorDlg::getFirstColor() const
 {
-  QColor aColor( 255, 255, 255, 0 ); // transparent
-  if( myFillingColor->isChecked() )
-    aColor = myFillingColorBox->color();
+  QColor aColor;
+  if ( !myIsOneColor )
+  {
+    aColor = QColor( 255, 255, 255, 0 ); // transparent
+    if( myFillingColor->isChecked() )
+      aColor = myFillingColorBox->color();
+  }
+  else
+  {
+    aColor = myColorBox->color();
+  }
+
   return aColor;
 }
 
-void HYDROGUI_ColorDlg::setBorderColor( const QColor& theColor )
+void HYDROGUI_ColorDlg::setSecondColor( const QColor& theColor )
 {
+  if ( myIsOneColor )
+    return;
+
   bool isTransparent = theColor.alpha() == 0;
   myBorderColorGroup->setChecked( !isTransparent );
   myBorderColorBox->setColor( !isTransparent ? theColor : QColor( Qt::black ) );
 }
 
-QColor HYDROGUI_ColorDlg::getBorderColor() const
+QColor HYDROGUI_ColorDlg::getSecondColor() const
 {
   QColor aColor( Qt::transparent ); // transparent
+  if ( myIsOneColor )
+    return aColor;
+
   if( myBorderColorGroup->isChecked() )
     aColor = myBorderColorBox->color();
+  
   return aColor;
 }