WColorPicker: Early exit more/return color directly

This commit is contained in:
Lioncache
2025-12-20 22:48:48 -05:00
parent e0affd89b1
commit 5db96c7ad4
3 changed files with 38 additions and 42 deletions

View File

@@ -458,7 +458,7 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
WColorPicker* pColorPicker = static_cast<WColorPicker*>(pEditor);
CColorProperty* pColor = static_cast<CColorProperty*>(pProp);
QColor Color = pColorPicker->Color();
const QColor& Color = pColorPicker->Color();
pColor->ValueRef(pData) = TO_CCOLOR(Color);
break;
}

View File

@@ -1,8 +1,9 @@
#include "WColorPicker.h"
#include "Editor/Widgets/WColorPicker.h"
#include <QColorDialog>
#include <QMouseEvent>
#include <QPainter>
#include <QRectF>
#include <QMouseEvent>
#include <QColorDialog>
WColorPicker::WColorPicker(QWidget *parent)
: QWidget(parent)
@@ -37,12 +38,13 @@ void WColorPicker::paintEvent(QPaintEvent *)
void WColorPicker::keyPressEvent(QKeyEvent *pEvent)
{
if (pEvent->key() == Qt::Key_Return)
{
if (pEvent->key() != Qt::Key_Return)
return;
QColorDialog ColorPick;
ColorPick.setOptions(QColorDialog::ShowAlphaChannel);
ColorPick.setCurrentColor(mColor);
int result = ColorPick.exec();
const int result = ColorPick.exec();
if (result)
{
@@ -50,7 +52,6 @@ void WColorPicker::keyPressEvent(QKeyEvent *pEvent)
emit ColorChanged(mColor);
}
}
}
void WColorPicker::mousePressEvent(QMouseEvent *)
{
@@ -60,9 +61,9 @@ void WColorPicker::mousePressEvent(QMouseEvent *)
void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent)
{
const auto pos = pEvent->position().toPoint();
if (pos.x() >= width() || pos.y() >= height())
return;
if (pos.x() < width() && pos.y() < height())
{
mOldColor = mColor;
QColorDialog ColorPick(this);
@@ -70,7 +71,7 @@ void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent)
ColorPick.setCurrentColor(mColor);
connect(&ColorPick, &QColorDialog::currentColorChanged, this, &WColorPicker::DialogColorChanged);
connect(&ColorPick, &QColorDialog::rejected, this, &WColorPicker::DialogRejected);
int Result = ColorPick.exec();
const int Result = ColorPick.exec();
if (Result)
{
@@ -78,22 +79,16 @@ void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent)
emit ColorEditComplete(mColor);
}
}
}
QColor WColorPicker::Color() const
{
return mColor;
}
void WColorPicker::SetColor(const QColor& Color)
{
if (mColor != Color)
{
if (mColor == Color)
return;
mColor = Color;
emit ColorEditComplete(mColor);
update();
}
}
void WColorPicker::DialogColorChanged(const QColor& NewColor)
{

View File

@@ -17,7 +17,8 @@ public:
void keyPressEvent(QKeyEvent* pEvent) override;
void mousePressEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent* pEvent) override;
QColor Color() const;
const QColor& Color() const { return mColor; }
void SetColor(const QColor& Color);
signals: