Made the color picker a modeless popup.

This commit is contained in:
Leonardo Zide 2024-08-08 14:37:21 -07:00
parent 82463473d5
commit eaf5241655
4 changed files with 82 additions and 1 deletions

View file

@ -699,7 +699,26 @@ void lcPropertiesWidget::ColorButtonClicked()
QColor InitialColor = Partial ? QColor(128, 128, 128) : lcQColorFromVector3(Value.value<lcVector3>());
QColor Color = QColorDialog::getColor(InitialColor, this, tr("Select Light Color"));
QMenu* Menu = new QMenu(ColorButton);
QWidgetAction* Action = new QWidgetAction(Menu);
lcColorDialogPopup *Popup = new lcColorDialogPopup(InitialColor, Menu);
Action->setDefaultWidget(Popup);
Menu->addAction(Action);
connect(Popup, &lcColorDialogPopup::ColorSelected, this, &lcPropertiesWidget::ColorChanged);
Menu->exec(ColorButton->mapToGlobal(ColorButton->rect().bottomLeft()));
delete Menu;
}
void lcPropertiesWidget::ColorChanged(QColor Color)
{
lcColorDialogPopup* Popup = qobject_cast<lcColorDialogPopup*>(sender());
QMenu* Menu = qobject_cast<QMenu*>(Popup->parent());
QToolButton* ColorButton = qobject_cast<QToolButton*>(Menu->parent());
lcObjectPropertyId PropertyId = GetEditorWidgetPropertyId(ColorButton);
if (!Color.isValid())
return;

View file

@ -24,6 +24,7 @@ protected slots:
void StringChanged();
void StringListChanged(int Index);
void ColorButtonClicked();
void ColorChanged(QColor Color);
void PieceColorButtonClicked();
void PieceColorChanged(int ColorIndex);
void PieceIdButtonClicked();

View file

@ -226,3 +226,44 @@ void lcPieceIdPickerPopup::Close()
if (Menu)
Menu->close();
}
lcColorDialogPopup::lcColorDialogPopup(const QColor& InitialColor, QWidget* Parent)
: QWidget(Parent)
{
QVBoxLayout* Layout = new QVBoxLayout(this);
Layout->setContentsMargins(0, 0, 0, 0);
mColorDialog = new QColorDialog(InitialColor, this);
mColorDialog->setWindowFlags(Qt::Widget);
mColorDialog->setOptions(QColorDialog::DontUseNativeDialog | QColorDialog::NoButtons);
Layout->addWidget(mColorDialog);
QDialogButtonBox* ButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
Layout->addWidget(ButtonBox);
QObject::connect(ButtonBox, &QDialogButtonBox::accepted, this, &lcColorDialogPopup::Accept);
QObject::connect(ButtonBox, &QDialogButtonBox::rejected, this, &lcColorDialogPopup::Reject);
}
void lcColorDialogPopup::Accept()
{
QColor Color = mColorDialog->currentColor();
emit ColorSelected(Color);
Close();
}
void lcColorDialogPopup::Reject()
{
Close();
}
void lcColorDialogPopup::Close()
{
QMenu* Menu = qobject_cast<QMenu*>(parent());
if (Menu)
Menu->close();
}

View file

@ -189,3 +189,23 @@ protected:
lcPartSelectionWidget* mPartSelectionWidget = nullptr;
PieceInfo* mInitialPart = nullptr;
};
class lcColorDialogPopup : public QWidget
{
Q_OBJECT
public:
lcColorDialogPopup(const QColor& InitialColor, QWidget* Parent);
signals:
void ColorSelected(QColor Color);
protected slots:
void Accept();
void Reject();
protected:
void Close();
QColorDialog* mColorDialog = nullptr;
};