forked from qt-creator/qt-creator
QmlEditorWidgets: Reduce code in colorbox.cpp
Use Qt's equivalent helpers. Change-Id: Ia2a494f9126bc80e55c24482d17fe9a6c72fa385 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -29,10 +29,7 @@
|
|||||||
|
|
||||||
static inline QString properName(const QColor &color)
|
static inline QString properName(const QColor &color)
|
||||||
{
|
{
|
||||||
if (color.alpha() == 255)
|
return color.name(color.alpha() == 255 ? QColor::HexRgb : QColor::HexArgb);
|
||||||
return QString::asprintf("#%02x%02x%02x", color.red(), color.green(), color.blue());
|
|
||||||
else
|
|
||||||
return QString::asprintf("#%02x%02x%02x%02x", color.alpha(), color.red(), color.green(), color.blue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QColor properColor(const QString &str)
|
static inline QColor properColor(const QString &str)
|
||||||
@@ -61,11 +58,7 @@ static inline QColor properColor(const QString &str)
|
|||||||
|
|
||||||
static inline int clamp(int x, int lower, int upper)
|
static inline int clamp(int x, int lower, int upper)
|
||||||
{
|
{
|
||||||
if (x < lower)
|
return qBound(lower, x, upper);
|
||||||
x = lower;
|
|
||||||
if (x > upper)
|
|
||||||
x = upper;
|
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace QmlEditorWidgets {
|
namespace QmlEditorWidgets {
|
||||||
@@ -85,10 +78,7 @@ void ColorBox::setHue(int newHue)
|
|||||||
|
|
||||||
int ColorBox::hue() const
|
int ColorBox::hue() const
|
||||||
{
|
{
|
||||||
int retval = m_color.hsvHue();
|
return clamp(m_color.hsvHue(), 0, 359);
|
||||||
if (retval<0) retval=0;
|
|
||||||
if (retval>359) retval=359;
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBox::setAlpha(int newAlpha)
|
void ColorBox::setAlpha(int newAlpha)
|
||||||
|
Reference in New Issue
Block a user