Skip to content

Commit

Permalink
Gui: Add option to show alpha in QColorDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Oct 11, 2021
1 parent 834831b commit 70ad139
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Gui/Widgets.cpp
Expand Up @@ -595,6 +595,7 @@ struct ColorButtonP
bool allowChange;
bool autoChange;
bool drawFrame;
bool allowTransparency;
bool modal;
bool dirty;

Expand All @@ -603,6 +604,7 @@ struct ColorButtonP
, allowChange(true)
, autoChange(false)
, drawFrame(true)
, allowTransparency(false)
, modal(true)
, dirty(true)
{
Expand Down Expand Up @@ -672,6 +674,21 @@ bool ColorButton::drawFrame() const
return d->drawFrame;
}

void Gui::ColorButton::setAllowTransparency(bool allow)
{
d->allowTransparency = allow;
if (d->cd)
d->cd->setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, allow);
}

bool Gui::ColorButton::allowTransparency() const
{
if (d->cd)
return d->cd->testOption(QColorDialog::ColorDialogOption::ShowAlphaChannel);
else
return d->allowTransparency;
}

void ColorButton::setModal(bool b)
{
d->modal = b;
Expand Down Expand Up @@ -764,6 +781,7 @@ void ColorButton::onChooseColor()
QColor currentColor = d->col;
QColorDialog cd(d->col, this);
cd.setOptions(QColorDialog::DontUseNativeDialog);
cd.setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, d->allowTransparency);

if (d->autoChange) {
connect(&cd, SIGNAL(currentColorChanged(const QColor &)),
Expand All @@ -789,6 +807,7 @@ void ColorButton::onChooseColor()
d->old = d->col;
d->cd = new QColorDialog(d->col, this);
d->cd->setOptions(QColorDialog::DontUseNativeDialog);
d->cd->setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, d->allowTransparency);
d->cd->setAttribute(Qt::WA_DeleteOnClose);
connect(d->cd, SIGNAL(rejected()),
this, SLOT(onRejected()));
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/Widgets.h
Expand Up @@ -202,6 +202,7 @@ class GuiExport ColorButton : public QPushButton
Q_PROPERTY( QColor color READ color WRITE setColor )
Q_PROPERTY( bool allowChangeColor READ allowChangeColor WRITE setAllowChangeColor )
Q_PROPERTY( bool drawFrame READ drawFrame WRITE setDrawFrame )
Q_PROPERTY( bool allowTransparency READ allowTransparency WRITE setAllowTransparency)

public:
ColorButton(QWidget* parent = 0);
Expand All @@ -216,6 +217,9 @@ class GuiExport ColorButton : public QPushButton
void setDrawFrame(bool);
bool drawFrame() const;

void setAllowTransparency(bool);
bool allowTransparency() const;

void setModal(bool);
bool isModal() const;

Expand Down

0 comments on commit 70ad139

Please sign in to comment.