From 978b4ae7ae22d425ec4ed22235950aa2b3ffa45b Mon Sep 17 00:00:00 2001 From: Tats Date: Sat, 11 Jul 2015 12:52:07 -0600 Subject: [PATCH] Added paint opacity. --- Mapper.cpp | 15 ++++++--------- Mapping.h | 6 ++++-- Paint.cpp | 1 + Paint.h | 7 +++++++ PaintGui.cpp | 50 ++++++++++++++++++++++++++++++++++++++------------ PaintGui.h | 6 ++---- 6 files changed, 58 insertions(+), 27 deletions(-) diff --git a/Mapper.cpp b/Mapper.cpp index c5f6fdc..d8bf51e 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -378,11 +378,8 @@ void TextureGraphicsItem::_prePaint(QPainter* painter, _texture->update(); // Allow alpha blending. - if (isOutput()) - { - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Get texture. glEnable (GL_TEXTURE_2D); @@ -404,7 +401,7 @@ void TextureGraphicsItem::_prePaint(QPainter* painter, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set texture color (apply opacity). - glColor4f(1.0f, 1.0f, 1.0f, isOutput() ? _mapping->getOpacity() : 1.0f); + glColor4f(1.0f, 1.0f, 1.0f, isOutput() ? _mapping->getOpacity() : _mapping->getPaint()->getOpacity()); } void TextureGraphicsItem::_postPaint(QPainter* painter, @@ -631,7 +628,7 @@ Mapper::Mapper(Mapping::ptr mapping) _opacityItem->setAttribute("minimum", 0.0); _opacityItem->setAttribute("maximum", 100.0); _opacityItem->setAttribute("decimals", 1); - _opacityItem->setValue(_mapping->getOpacity()*100.0); + _opacityItem->setValue(_mapping->getRawOpacity()*100.0); _topItem->addSubProperty(_opacityItem); // Output shape. @@ -667,9 +664,9 @@ void Mapper::setValue(QtProperty* property, const QVariant& value) if (property == _opacityItem) { double opacity = qBound(value.toDouble() / 100.0, 0.0, 1.0); - if (opacity != _mapping->getOpacity()) + if (opacity != _mapping->getRawOpacity()) { - _mapping->setOpacity(opacity); + _mapping->setRawOpacity(opacity); emit valueChanged(); } } diff --git a/Mapping.h b/Mapping.h index 5f2dc11..ee0a3b0 100644 --- a/Mapping.h +++ b/Mapping.h @@ -99,7 +99,7 @@ public: void setLocked(bool locked) { _isLocked = locked; } void setSolo(bool solo) { _isSolo = solo; } void setVisible(bool visible) { _isVisible = visible; } - void setOpacity(float opacity) { + void setRawOpacity(float opacity) { Q_ASSERT(0.0f <= opacity && opacity <= 1.0f); _opacity = opacity; } @@ -112,9 +112,11 @@ public: bool isLocked() const { return _isLocked; } bool isSolo() const { return _isSolo; } bool isVisible() const { return _isVisible; } - float getOpacity() const { return _opacity; } + float getRawOpacity() const { return _opacity; } int getDepth() const { return _depth; } + float getOpacity() const { return _opacity * _paint->getOpacity(); } + void setPaint(Paint::ptr p) { _paint = p; } void removePaint() { if (_paint) delete _paint.get(); } }; diff --git a/Paint.cpp b/Paint.cpp index a4c954c..e4e2d59 100644 --- a/Paint.cpp +++ b/Paint.cpp @@ -25,6 +25,7 @@ UidAllocator Paint::allocator; Paint::Paint(uid id) + : _opacity(1.0f) { if (id == NULL_UID) id = allocator.allocate(); diff --git a/Paint.h b/Paint.h index 943db78..c415e52 100644 --- a/Paint.h +++ b/Paint.h @@ -86,10 +86,17 @@ public: QString getName() const { return _name; } uid getId() const { return _id; } + float getOpacity() const { return _opacity; } + void setOpacity(float opacity) { + Q_ASSERT(0.0f <= opacity && opacity <= 1.0f); + _opacity = opacity; + } + virtual QString getType() const = 0; private: QString _name; + float _opacity; }; class Color : public Paint diff --git a/PaintGui.cpp b/PaintGui.cpp index ab9b279..c884ca9 100644 --- a/PaintGui.cpp +++ b/PaintGui.cpp @@ -36,6 +36,14 @@ PaintGui::PaintGui(Paint::ptr paint) this, SLOT(setValue(QtProperty*, const QVariant&))); _propertyBrowser->addProperty(_topItem); + + // Paint basic properties. + _opacityItem = _variantManager->addProperty(QVariant::Double, QObject::tr("Opacity (%)")); + _opacityItem->setAttribute("minimum", 0.0); + _opacityItem->setAttribute("maximum", 100.0); + _opacityItem->setAttribute("decimals", 1); + _opacityItem->setValue(_paint->getOpacity()*100.0); + _topItem->addSubProperty(_opacityItem); } PaintGui::~PaintGui() @@ -48,6 +56,20 @@ QWidget* PaintGui::getPropertiesEditor() return _propertyBrowser; } +void PaintGui::setValue(QtProperty* property, const QVariant& value) +{ + if (property == _opacityItem) + { + double opacity = qBound(value.toDouble() / 100.0, 0.0, 1.0); + if (opacity != _paint->getOpacity()) + { + _paint->setOpacity(opacity); + emit valueChanged(_paint); + } + } +} + + ColorGui::ColorGui(Paint::ptr paint) : PaintGui(paint) { @@ -67,6 +89,8 @@ void ColorGui::setValue(QtProperty* property, const QVariant& value) { color->setColor(value.value()); emit valueChanged(_paint); } + else + PaintGui::setValue(property, value); } TextureGui::TextureGui(Paint::ptr paint) : PaintGui(paint) { @@ -92,6 +116,8 @@ void ImageGui::setValue(QtProperty* property, const QVariant& value) { image->setUri(value.toString()); emit valueChanged(_paint); } + else + PaintGui::setValue(property, value); } MediaGui::MediaGui(Paint::ptr paint) @@ -137,23 +163,23 @@ void MediaGui::setValue(QtProperty* property, const QVariant& value) media->setUri(value.toString()); emit valueChanged(_paint); } - else { - if (property == _mediaRateItem) - { - double rateSign = (media->getRate() <= 0 ? -1 : +1); - media->setRate(value.toDouble()); - emit valueChanged(_paint); - } + else if (property == _mediaRateItem) + { + double rateSign = (media->getRate() <= 0 ? -1 : +1); + media->setRate(value.toDouble()); + emit valueChanged(_paint); + } // else if (property == _mediaReverseItem) // { // double absoluteRate = abs( media->getRate() ); // media->setRate( (value.toBool() ? -1 : +1) * absoluteRate ); // emit valueChanged(_paint); // } - else if (property == _mediaVolumeItem) - { - media->setVolume(value.toDouble()); - emit valueChanged(_paint); - } + else if (property == _mediaVolumeItem) + { + media->setVolume(value.toDouble()); + emit valueChanged(_paint); } + else + PaintGui::setValue(property, value); } diff --git a/PaintGui.h b/PaintGui.h index ff6c08e..f2b648d 100644 --- a/PaintGui.h +++ b/PaintGui.h @@ -61,10 +61,7 @@ public: virtual QWidget* getPropertiesEditor(); public slots: - virtual void setValue(QtProperty* property, const QVariant& value) { - Q_UNUSED(property); - Q_UNUSED(value); - } + virtual void setValue(QtProperty* property, const QVariant& value); signals: void valueChanged(Paint::ptr); @@ -75,6 +72,7 @@ protected: QtVariantEditorFactory* _variantFactory; QtVariantPropertyManager* _variantManager; QtProperty* _topItem; + QtVariantProperty* _opacityItem; }; class ColorGui : public PaintGui {