[opengtl-commits] [551] add support for rgba colors

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 551
Author:   cyrille
Date:     2008-12-18 22:41:03 +0100 (Thu, 18 Dec 2008)

Log Message:
-----------
add support for rgba colors
hide the alpha channel when selecting a rgb color

Modified Paths:
--------------
    trunk/libQtGTL/QtShiva/ColorButton_p.cpp
    trunk/libQtGTL/QtShiva/ColorButton_p.h
    trunk/libQtGTL/QtShiva/ParametersWidget_p.cpp
    trunk/libQtGTL/QtShiva/Proxy_p.cpp
    trunk/libQtGTL/QtShiva/Proxy_p.h
    trunk/libQtGTL/QtShiva/RgbaDialog_p.cpp
    trunk/libQtGTL/QtShiva/RgbaDialog_p.h
    trunk/libQtGTL/QtShiva/UiRgbaDialog.ui


Modified: trunk/libQtGTL/QtShiva/ColorButton_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/ColorButton_p.cpp	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/ColorButton_p.cpp	2008-12-18 21:41:03 UTC (rev 551)
@@ -25,7 +25,7 @@
 
 using namespace QtShiva;
 
-ColorButton::ColorButton( QWidget* _parent ) : QPushButton( _parent )
+ColorButton::ColorButton( QWidget* _parent, bool _showAlpha ) : QPushButton( _parent ), m_showAlpha(_showAlpha)
 {
   connect( this, SIGNAL(released()), SLOT(activated()));
 }
@@ -53,7 +53,7 @@
 
 void ColorButton::activated()
 {
-  RgbaDialog dialog( this );
+  RgbaDialog dialog( this, m_showAlpha );
   dialog.setColor( m_color );
   if(dialog.exec() == QDialog::Accepted )
   {

Modified: trunk/libQtGTL/QtShiva/ColorButton_p.h
===================================================================
--- trunk/libQtGTL/QtShiva/ColorButton_p.h	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/ColorButton_p.h	2008-12-18 21:41:03 UTC (rev 551)
@@ -30,7 +30,7 @@
   class ColorButton : public QPushButton {
     Q_OBJECT
     public:
-      ColorButton( QWidget* _parent );
+      ColorButton( QWidget* _parent, bool _showAlpha );
       ~ColorButton();
       void setCurrentColor( const QColor& _color );
       const QColor& currentColor() const;
@@ -40,6 +40,7 @@
       void activated();
     private:
       QColor m_color;
+      bool m_showAlpha;
   };
 }
 

Modified: trunk/libQtGTL/QtShiva/ParametersWidget_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/ParametersWidget_p.cpp	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/ParametersWidget_p.cpp	2008-12-18 21:41:03 UTC (rev 551)
@@ -176,7 +176,7 @@
       break;
     case GTLCore::Metadata::ParameterEntry::RgbColorWidget:
     {
-      ColorButton* colorButton = new ColorButton( _parent );
+      ColorButton* colorButton = new ColorButton( _parent, false );
       const std::vector< GTLCore::Value >* valArr = _parameterEntry->defaultValue().asArray();
       Q_ASSERT( valArr );
       Q_ASSERT( valArr->size() >= 3 );
@@ -185,9 +185,24 @@
       double b = (*valArr)[2].asFloat() * 255;
       colorButton->setCurrentColor( QColor(r,g,b ) );
       _gridLayout->addWidget(colorButton, _layoutIndex, 1, 1, 1);
-      connect( colorButton, SIGNAL(colorChanged(const QColor&)), proxy, SLOT(setColor(const QColor&)));
+      connect( colorButton, SIGNAL(colorChanged(const QColor&)), proxy, SLOT(setRgb(const QColor&)));
     }
       break;
+    case GTLCore::Metadata::ParameterEntry::RgbaColorWidget:
+    {
+      ColorButton* colorButton = new ColorButton( _parent, true );
+      const std::vector< GTLCore::Value >* valArr = _parameterEntry->defaultValue().asArray();
+      Q_ASSERT( valArr );
+      Q_ASSERT( valArr->size() >= 3 );
+      double r = (*valArr)[0].asFloat() * 255;
+      double g = (*valArr)[1].asFloat() * 255;
+      double b = (*valArr)[2].asFloat() * 255;
+      double a = (*valArr)[3].asFloat() * 255;
+      colorButton->setCurrentColor( QColor(r,g,b, a ) );
+      _gridLayout->addWidget(colorButton, _layoutIndex, 1, 1, 1);
+      connect( colorButton, SIGNAL(colorChanged(const QColor&)), proxy, SLOT(setRgba(const QColor&)));
+    }
+      break;
   }
 }
 

Modified: trunk/libQtGTL/QtShiva/Proxy_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/Proxy_p.cpp	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/Proxy_p.cpp	2008-12-18 21:41:03 UTC (rev 551)
@@ -48,7 +48,7 @@
 }
 
 #include <cstdlib>
-void Proxy::setColor( const QColor& c )
+void Proxy::setRgb( const QColor& c )
 {
   std::vector< GTLCore::Value > cv;
   cv.push_back( c.red() / 255.0f );
@@ -57,4 +57,14 @@
   m_kernel->setParameter( m_name, GTLCore::Value( cv, GTLCore::TypesManager::getVector( GTLCore::Type::Float, 3 ) ) );
 }
 
+void Proxy::setRgba( const QColor& c )
+{
+  std::vector< GTLCore::Value > cv;
+  cv.push_back( c.red() / 255.0f );
+  cv.push_back( c.green() / 255.0f );
+  cv.push_back( c.blue() / 255.0f );
+  cv.push_back( c.alpha() / 255.0f );
+  m_kernel->setParameter( m_name, GTLCore::Value( cv, GTLCore::TypesManager::getVector( GTLCore::Type::Float, 4 ) ) );
+}
+
 #include "Proxy_p.moc"

Modified: trunk/libQtGTL/QtShiva/Proxy_p.h
===================================================================
--- trunk/libQtGTL/QtShiva/Proxy_p.h	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/Proxy_p.h	2008-12-18 21:41:03 UTC (rev 551)
@@ -38,7 +38,8 @@
     public slots:
       void setIntValue( int );
       void setDoubleValue( double );
-      void setColor( const QColor& );
+      void setRgb( const QColor& );
+      void setRgba( const QColor& );
     private:
       GTLCore::String m_name;
       OpenShiva::Kernel* m_kernel;

Modified: trunk/libQtGTL/QtShiva/RgbaDialog_p.cpp
===================================================================
--- trunk/libQtGTL/QtShiva/RgbaDialog_p.cpp	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/RgbaDialog_p.cpp	2008-12-18 21:41:03 UTC (rev 551)
@@ -25,7 +25,7 @@
 
 using namespace QtShiva;
 
-RgbaDialog::RgbaDialog( QWidget* _widget ) : QDialog(_widget), m_rgbaDialog( new Ui_RgbaDialog )
+RgbaDialog::RgbaDialog( QWidget* _widget, bool showAlpha ) : QDialog(_widget), m_rgbaDialog( new Ui_RgbaDialog )
 {
   m_rgbaDialog->setupUi( this );
   
@@ -39,6 +39,9 @@
   connect( m_connectors[2], SIGNAL(valueChanged(double)), SLOT(spinBoxesValuesChanged()));
   m_connectors[3] = new SpinBoxSliderConnector( this, m_rgbaDialog->doubleSpinBoxAlpha, m_rgbaDialog->sliderAlpha );
   connect( m_connectors[3], SIGNAL(valueChanged(double)), SLOT(spinBoxesValuesChanged()));
+  m_rgbaDialog->doubleSpinBoxAlpha->setVisible( showAlpha );
+  m_rgbaDialog->sliderAlpha->setVisible( showAlpha );
+  m_rgbaDialog->labelAlpha->setVisible( showAlpha );
 }
 
 RgbaDialog::~RgbaDialog()

Modified: trunk/libQtGTL/QtShiva/RgbaDialog_p.h
===================================================================
--- trunk/libQtGTL/QtShiva/RgbaDialog_p.h	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/RgbaDialog_p.h	2008-12-18 21:41:03 UTC (rev 551)
@@ -31,7 +31,7 @@
   class RgbaDialog : public QDialog {
     Q_OBJECT
     public:
-      RgbaDialog( QWidget* );
+      RgbaDialog( QWidget*, bool showAlpha );
       ~RgbaDialog();
       QColor color();
       void setColor( const QColor& );

Modified: trunk/libQtGTL/QtShiva/UiRgbaDialog.ui
===================================================================
--- trunk/libQtGTL/QtShiva/UiRgbaDialog.ui	2008-12-18 21:40:01 UTC (rev 550)
+++ trunk/libQtGTL/QtShiva/UiRgbaDialog.ui	2008-12-18 21:41:03 UTC (rev 551)
@@ -96,7 +96,7 @@
         </widget>
        </item>
        <item row="7" column="0" >
-        <widget class="QLabel" name="label_4" >
+        <widget class="QLabel" name="labelAlpha" >
          <property name="text" >
           <string>Alpha:</string>
          </property>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/