Gui: fix transparency saving in PrefColorButton

This commit is contained in:
Zheng, Lei
2022-11-24 07:13:06 +08:00
committed by Chris Hennes
parent 61a4bf5719
commit 26e38309c8
4 changed files with 43 additions and 7 deletions

View File

@@ -552,18 +552,23 @@ void PrefColorButton::restorePreferences()
return;
}
QColor col = color();
if (!m_Restored)
m_Default = color();
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
const QColor &col = m_Default;
auto lcol = static_cast<unsigned long>(icol);
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | col.alpha();
unsigned long lcol = static_cast<unsigned long>(icol);
lcol = getWindowParameter()->GetUnsigned( entryName(), lcol );
icol = static_cast<unsigned int>(lcol);
int r = (icol >> 24)&0xff;
int g = (icol >> 16)&0xff;
int b = (icol >> 8)&0xff;
setColor(QColor(r,g,b));
int a = (icol )&0xff;
if (!this->allowTransparency())
a = 0xff;
setColor(QColor(r,g,b,a));
}
void PrefColorButton::savePreferences()
@@ -576,8 +581,8 @@ void PrefColorButton::savePreferences()
QColor col = color();
// (r,g,b,a) with a = 255 (opaque)
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | 255;
auto lcol = static_cast<unsigned long>(icol);
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | col.alpha();
unsigned long lcol = static_cast<unsigned long>(icol);
getWindowParameter()->SetUnsigned( entryName(), lcol );
}

View File

@@ -329,6 +329,9 @@ protected:
// restore from/save to parameters
void restorePreferences() override;
void savePreferences() override;
private:
QColor m_Default;
};
/** The PrefUnitSpinBox class.

View File

@@ -44,6 +44,7 @@
#include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <App/ExpressionParser.h>
#include <App/Material.h>
#include "Widgets.h"
#include "Action.h"
@@ -685,6 +686,30 @@ QColor ColorButton::color() const
return d->col;
}
/**
* Sets the packed color \a c to the button.
*/
void ColorButton::setPackedColor(uint32_t c)
{
App::Color color;
color.setPackedValue(c);
d->col.setRedF(color.r);
d->col.setGreenF(color.g);
d->col.setBlueF(color.b);
d->col.setAlphaF(color.a);
d->dirty = true;
update();
}
/**
* Returns the current packed color of the button.
*/
uint32_t ColorButton::packedColor() const
{
App::Color color(d->col.redF(), d->col.greenF(), d->col.blueF(), d->col.alphaF());
return color.getPackedValue();
}
void ColorButton::setAllowChangeColor(bool ok)
{
d->allowChange = ok;

View File

@@ -238,6 +238,9 @@ public:
void setColor(const QColor&);
QColor color() const;
void setPackedColor(uint32_t);
uint32_t packedColor() const;
void setAllowChangeColor(bool);
bool allowChangeColor() const;