mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-21 18:59:12 +00:00
WColorPicker: Early exit more/return color directly
This commit is contained in:
@@ -458,7 +458,7 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
|
|||||||
WColorPicker* pColorPicker = static_cast<WColorPicker*>(pEditor);
|
WColorPicker* pColorPicker = static_cast<WColorPicker*>(pEditor);
|
||||||
CColorProperty* pColor = static_cast<CColorProperty*>(pProp);
|
CColorProperty* pColor = static_cast<CColorProperty*>(pProp);
|
||||||
|
|
||||||
QColor Color = pColorPicker->Color();
|
const QColor& Color = pColorPicker->Color();
|
||||||
pColor->ValueRef(pData) = TO_CCOLOR(Color);
|
pColor->ValueRef(pData) = TO_CCOLOR(Color);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include "WColorPicker.h"
|
#include "Editor/Widgets/WColorPicker.h"
|
||||||
|
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QColorDialog>
|
|
||||||
|
|
||||||
WColorPicker::WColorPicker(QWidget *parent)
|
WColorPicker::WColorPicker(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
@@ -37,18 +38,18 @@ void WColorPicker::paintEvent(QPaintEvent *)
|
|||||||
|
|
||||||
void WColorPicker::keyPressEvent(QKeyEvent *pEvent)
|
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();
|
|
||||||
|
|
||||||
if (result)
|
QColorDialog ColorPick;
|
||||||
{
|
ColorPick.setOptions(QColorDialog::ShowAlphaChannel);
|
||||||
mColor = ColorPick.currentColor();
|
ColorPick.setCurrentColor(mColor);
|
||||||
emit ColorChanged(mColor);
|
const int result = ColorPick.exec();
|
||||||
}
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
mColor = ColorPick.currentColor();
|
||||||
|
emit ColorChanged(mColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,39 +61,33 @@ void WColorPicker::mousePressEvent(QMouseEvent *)
|
|||||||
void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent)
|
void WColorPicker::mouseReleaseEvent(QMouseEvent *pEvent)
|
||||||
{
|
{
|
||||||
const auto pos = pEvent->position().toPoint();
|
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);
|
||||||
|
ColorPick.setOptions(QColorDialog::ShowAlphaChannel);
|
||||||
|
ColorPick.setCurrentColor(mColor);
|
||||||
|
connect(&ColorPick, &QColorDialog::currentColorChanged, this, &WColorPicker::DialogColorChanged);
|
||||||
|
connect(&ColorPick, &QColorDialog::rejected, this, &WColorPicker::DialogRejected);
|
||||||
|
const int Result = ColorPick.exec();
|
||||||
|
|
||||||
|
if (Result)
|
||||||
{
|
{
|
||||||
mOldColor = mColor;
|
mColor = ColorPick.currentColor();
|
||||||
|
emit ColorEditComplete(mColor);
|
||||||
QColorDialog ColorPick(this);
|
|
||||||
ColorPick.setOptions(QColorDialog::ShowAlphaChannel);
|
|
||||||
ColorPick.setCurrentColor(mColor);
|
|
||||||
connect(&ColorPick, &QColorDialog::currentColorChanged, this, &WColorPicker::DialogColorChanged);
|
|
||||||
connect(&ColorPick, &QColorDialog::rejected, this, &WColorPicker::DialogRejected);
|
|
||||||
int Result = ColorPick.exec();
|
|
||||||
|
|
||||||
if (Result)
|
|
||||||
{
|
|
||||||
mColor = ColorPick.currentColor();
|
|
||||||
emit ColorEditComplete(mColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor WColorPicker::Color() const
|
|
||||||
{
|
|
||||||
return mColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WColorPicker::SetColor(const QColor& Color)
|
void WColorPicker::SetColor(const QColor& Color)
|
||||||
{
|
{
|
||||||
if (mColor != Color)
|
if (mColor == Color)
|
||||||
{
|
return;
|
||||||
mColor = Color;
|
|
||||||
emit ColorEditComplete(mColor);
|
mColor = Color;
|
||||||
update();
|
emit ColorEditComplete(mColor);
|
||||||
}
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WColorPicker::DialogColorChanged(const QColor& NewColor)
|
void WColorPicker::DialogColorChanged(const QColor& NewColor)
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public:
|
|||||||
void keyPressEvent(QKeyEvent* pEvent) override;
|
void keyPressEvent(QKeyEvent* pEvent) override;
|
||||||
void mousePressEvent(QMouseEvent*) override;
|
void mousePressEvent(QMouseEvent*) override;
|
||||||
void mouseReleaseEvent(QMouseEvent* pEvent) override;
|
void mouseReleaseEvent(QMouseEvent* pEvent) override;
|
||||||
QColor Color() const;
|
|
||||||
|
const QColor& Color() const { return mColor; }
|
||||||
void SetColor(const QColor& Color);
|
void SetColor(const QColor& Color);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
Reference in New Issue
Block a user