Backport luma/lift/gain negative lift

parent 6ee98833
......@@ -21,7 +21,55 @@
#include "colorwheel.h"
#include <qmath.h>
ColorWheel::ColorWheel(const QString &id, const QString &name, const QColor &color, QWidget *parent)
NegQColor NegQColor::fromHsvF(qreal h, qreal s, qreal l, qreal a)
{
NegQColor color;
color.qcolor = QColor::fromHsvF(h,s,l<0?-l:l,a);
color.sign_r = l<0?-1:1;
color.sign_g = l<0?-1:1;
color.sign_b = l<0?-1:1;
return color;
}
NegQColor NegQColor::fromRgbF(qreal r, qreal g, qreal b, qreal a)
{
NegQColor color;
color.qcolor = QColor::fromRgbF(r<0?-r:r,g<0?-g:g,b<0?-b:b,a);
color.sign_r = r<0?-1:1;
color.sign_g = g<0?-1:1;
color.sign_b = b<0?-1:1;
return color;
}
qreal NegQColor::redF() {
return qcolor.redF()*sign_r;
}
qreal NegQColor::greenF() {
return qcolor.greenF()*sign_g;
}
qreal NegQColor::blueF() {
return qcolor.blueF()*sign_b;
}
qreal NegQColor::valueF() {
return qcolor.valueF()*sign_g;
}
int NegQColor::hue() {
return qcolor.hue();
}
qreal NegQColor::hueF() {
return qcolor.hueF();
}
qreal NegQColor::saturationF() {
return qcolor.saturationF();
}
ColorWheel::ColorWheel(const QString &id, const QString &name, const NegQColor &color, QWidget *parent)
: QWidget(parent)
, m_id(id)
, m_isMouseDown(false)
......@@ -41,12 +89,18 @@ ColorWheel::ColorWheel(const QString &id, const QString &name, const QColor &col
setCursor(Qt::CrossCursor);
}
QColor ColorWheel::color()
void ColorWheel::setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero) {
m_sizeFactor = factor;
m_defaultValue = defvalue;
m_zeroShift = zero;
}
NegQColor ColorWheel::color() const
{
return m_color;
}
void ColorWheel::setColor(const QColor &color)
void ColorWheel::setColor(const NegQColor &color)
{
m_color = color;
}
......@@ -56,10 +110,10 @@ int ColorWheel::wheelSize() const
return qMin(width() - m_sliderWidth, height() - m_unitSize);
}
QColor ColorWheel::colorForPoint(const QPoint &point)
NegQColor ColorWheel::colorForPoint(const QPoint &point)
{
if (!m_image.valid(point)) {
return QColor();
return NegQColor();
}
if (m_isInWheel) {
qreal w = wheelSize();
......@@ -74,13 +128,16 @@ QColor ColorWheel::colorForPoint(const QPoint &point)
theta += 2.0 * M_PI;
}
qreal hue = (theta * 180.0 / M_PI) / 360.0;
return QColor::fromHsvF(hue, rad, m_color.valueF());
return NegQColor::fromHsvF(hue, rad, m_color.valueF());
}
if (m_isInSquare) {
qreal value = 1.0 - qreal(point.y() - m_margin) / (wheelSize() - m_margin * 2);
return QColor::fromHsvF(m_color.hueF(), m_color.saturationF(), value);
if (!qFuzzyCompare(m_zeroShift, 0.)) {
value=value-m_zeroShift;
}
return NegQColor::fromHsvF(m_color.hueF(), m_color.saturationF(), value);
}
return QColor();
return NegQColor();
}
QSize ColorWheel::sizeHint() const
......@@ -107,7 +164,7 @@ void ColorWheel::mousePressEvent(QMouseEvent *event)
qreal g = m_color.greenF();
qreal max = qMax(r, b);
max = qMax(max, g);
changeColor(QColor::fromRgbF(max, max, max));
changeColor(NegQColor::fromRgbF(max, max, max));
}
} else if (m_sliderRegion.contains(m_lastPoint)) {
m_isInWheel = false;
......@@ -115,14 +172,8 @@ void ColorWheel::mousePressEvent(QMouseEvent *event)
if (event->button() != Qt::MidButton) {
changeColor(colorForPoint(m_lastPoint));
} else {
QColor c;
if (m_id == QLatin1String("lift")) {
c = QColor::fromRgbF(0, 0, 0);
} else if (m_id == QLatin1String("gamma")) {
c = QColor::fromRgbF(0.5, 0.5, 0.5);
} else {
c = QColor::fromRgbF(0.25, 0.25, 0.25);
}
NegQColor c;
c = NegQColor::fromRgbF(m_defaultValue/m_sizeFactor, m_defaultValue/m_sizeFactor, m_defaultValue/m_sizeFactor);
changeColor(c);
}
}
......@@ -136,10 +187,10 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *event)
return;
}
if (m_wheelRegion.contains(m_lastPoint) && m_isInWheel) {
const QColor color = colorForPoint(m_lastPoint);
const NegQColor color = colorForPoint(m_lastPoint);
changeColor(color);
} else if (m_sliderRegion.contains(m_lastPoint) && m_isInSquare) {
const QColor color = colorForPoint(m_lastPoint);
const NegQColor color = colorForPoint(m_lastPoint);
changeColor(color);
}
}
......@@ -164,17 +215,7 @@ void ColorWheel::resizeEvent(QResizeEvent *event)
QString ColorWheel::getParamValues()
{
if (m_id == QLatin1String("gamma")) {
return QString::number(m_color.redF() * 2, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * 2, 'g', 2) + QLatin1Char(',') +
QString::number(m_color.blueF() * 2, 'g', 2);
}
if (m_id == QLatin1String("gain")) {
return QString::number(m_color.redF() * 4, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * 4, 'g', 2) + QLatin1Char(',') +
QString::number(m_color.blueF() * 4, 'g', 2);
}
// default (lift)
return QString::number(m_color.redF(), 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF(), 'g', 2) + QLatin1Char(',') +
QString::number(m_color.blueF(), 'g', 2);
return QString::number(m_color.redF() * m_sizeFactor, 'g', 2) + QLatin1Char(',') + QString::number(m_color.greenF() * m_sizeFactor, 'g', 2) + QLatin1Char(',') + QString::number(m_color.blueF() * m_sizeFactor, 'g', 2);
}
void ColorWheel::paintEvent(QPaintEvent *event)
......@@ -265,6 +306,9 @@ void ColorWheel::drawWheelDot(QPainter &painter)
void ColorWheel::drawSliderBar(QPainter &painter)
{
qreal value = 1.0 - m_color.valueF();
if (m_id == QLatin1String("lift")) {
value -= m_zeroShift;
}
int ws = wheelSize();
qreal scale = qreal(ws + m_sliderWidth) / maximumWidth();
int w = m_sliderWidth * scale;
......@@ -278,7 +322,7 @@ void ColorWheel::drawSliderBar(QPainter &painter)
painter.resetTransform();
}
void ColorWheel::changeColor(const QColor &color)
void ColorWheel::changeColor(const NegQColor &color)
{
m_color = color;
drawWheel();
......
......@@ -23,22 +23,41 @@
#include <QResizeEvent>
#include <QWidget>
class NegQColor
{
public:
int8_t sign_r=1;
int8_t sign_g=1;
int8_t sign_b=1;
QColor qcolor;
static NegQColor fromHsvF(qreal h, qreal s, qreal l, qreal a = 1.0);
static NegQColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0);
qreal redF();
qreal greenF();
qreal blueF();
qreal valueF();
int hue();
qreal hueF();
qreal saturationF();
};
class ColorWheel : public QWidget
{
Q_OBJECT
public:
explicit ColorWheel(const QString &id, const QString &name, const QColor &color, QWidget *parent = nullptr);
explicit ColorWheel(const QString &id, const QString &name, const NegQColor &color, QWidget *parent = nullptr);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
QColor color();
void setColor(const QColor &color);
NegQColor color() const;
void setColor(const NegQColor &color);
void setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero);
signals:
void colorChange(const QColor &color);
void colorChange(const NegQColor &color);
public slots:
void changeColor(const QColor &color);
void changeColor(const NegQColor &color);
protected:
void mousePressEvent(QMouseEvent *event) override;
......@@ -57,14 +76,18 @@ private:
int m_sliderWidth;
QRegion m_wheelRegion;
QRegion m_sliderRegion;
QColor m_color;
NegQColor m_color;
bool m_isInWheel;
bool m_isInSquare;
int m_unitSize;
QString m_name;
qreal m_sizeFactor = 1;
qreal m_defaultValue = 1;
qreal m_zeroShift = 0;
int wheelSize() const;
QColor colorForPoint(const QPoint &point);
NegQColor colorForPoint(const QPoint &point);
void drawWheel();
void drawWheelDot(QPainter &painter);
void drawSliderBar(QPainter &painter);
......
......@@ -25,6 +25,7 @@
#include <KLocalizedString>
static const double LIFT_FACTOR = 2.0;
static const double GAMMA_FACTOR = 2.0;
static const double GAIN_FACTOR = 4.0;
......@@ -37,11 +38,14 @@ LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model,
layout->setSpacing(0);
*/
m_locale.setNumberOptions(QLocale::OmitGroupSeparator);
m_lift = new ColorWheel(QStringLiteral("lift"), i18n("Lift"), QColor(), this);
m_lift = new ColorWheel(QStringLiteral("lift"), i18n("Lift"), NegQColor(), this);
m_lift->setFactorDefaultZero(LIFT_FACTOR, 0, 0.5);
connect(m_lift, &ColorWheel::colorChange, this, &LumaLiftGainParam::liftChanged);
m_gamma = new ColorWheel(QStringLiteral("gamma"), i18n("Gamma"), QColor(), this);
m_gamma = new ColorWheel(QStringLiteral("gamma"), i18n("Gamma"), NegQColor(), this);
m_gamma->setFactorDefaultZero(GAMMA_FACTOR, 1, 0);
connect(m_gamma, &ColorWheel::colorChange, this, &LumaLiftGainParam::gammaChanged);
m_gain = new ColorWheel(QStringLiteral("gain"), i18n("Gain"), QColor(), this);
m_gain = new ColorWheel(QStringLiteral("gain"), i18n("Gain"), NegQColor(), this);
m_gain->setFactorDefaultZero(GAIN_FACTOR, 1, 0);
connect(m_gain, &ColorWheel::colorChange, this, &LumaLiftGainParam::gainChanged);
QMap<QString, QModelIndex> indexes;
for (int i = 0; i < m_model->rowCount(); ++i) {
......@@ -57,19 +61,19 @@ LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model,
slotRefresh();
connect(this, &LumaLiftGainParam::liftChanged, [this, indexes]() {
QColor liftColor = m_lift->color();
NegQColor liftColor = m_lift->color();
emit valueChanged(indexes.value(QStringLiteral("lift_r")), m_locale.toString(liftColor.redF()), true);
emit valueChanged(indexes.value(QStringLiteral("lift_g")), m_locale.toString(liftColor.greenF()), true);
emit valueChanged(indexes.value(QStringLiteral("lift_b")), m_locale.toString(liftColor.blueF()), true);
});
connect(this, &LumaLiftGainParam::gammaChanged, [this, indexes]() {
QColor gammaColor = m_gamma->color();
NegQColor gammaColor = m_gamma->color();
emit valueChanged(indexes.value(QStringLiteral("gamma_r")), m_locale.toString(gammaColor.redF() * GAMMA_FACTOR), true);
emit valueChanged(indexes.value(QStringLiteral("gamma_g")), m_locale.toString(gammaColor.greenF() * GAMMA_FACTOR), true);
emit valueChanged(indexes.value(QStringLiteral("gamma_b")), m_locale.toString(gammaColor.blueF() * GAMMA_FACTOR), true);
});
connect(this, &LumaLiftGainParam::gainChanged, [this, indexes]() {
QColor gainColor = m_gain->color();
NegQColor gainColor = m_gain->color();
emit valueChanged(indexes.value(QStringLiteral("gain_r")), m_locale.toString(gainColor.redF() * GAIN_FACTOR), true);
emit valueChanged(indexes.value(QStringLiteral("gain_g")), m_locale.toString(gainColor.greenF() * GAIN_FACTOR), true);
emit valueChanged(indexes.value(QStringLiteral("gain_b")), m_locale.toString(gainColor.blueF() * GAIN_FACTOR), true);
......@@ -78,13 +82,13 @@ LumaLiftGainParam::LumaLiftGainParam(std::shared_ptr<AssetParameterModel> model,
void LumaLiftGainParam::updateEffect(QDomElement &effect)
{
QColor lift = m_lift->color();
QColor gamma = m_gamma->color();
QColor gain = m_gain->color();
NegQColor lift = m_lift->color();
NegQColor gamma = m_gamma->color();
NegQColor gain = m_gain->color();
QMap<QString, double> values;
values.insert(QStringLiteral("lift_r"), lift.redF());
values.insert(QStringLiteral("lift_g"), lift.greenF());
values.insert(QStringLiteral("lift_b"), lift.blueF());
values.insert(QStringLiteral("lift_r"), lift.redF() * LIFT_FACTOR);
values.insert(QStringLiteral("lift_g"), lift.greenF() * LIFT_FACTOR);
values.insert(QStringLiteral("lift_b"), lift.blueF() * LIFT_FACTOR);
values.insert(QStringLiteral("gamma_r"), gamma.redF() * GAMMA_FACTOR);
values.insert(QStringLiteral("gamma_g"), gamma.greenF() * GAMMA_FACTOR);
......@@ -120,11 +124,21 @@ void LumaLiftGainParam::slotRefresh()
values.insert(name, val);
}
QColor lift = QColor::fromRgbF(values.value(QStringLiteral("lift_r")), values.value(QStringLiteral("lift_g")), values.value(QStringLiteral("lift_b")));
NegQColor lift = NegQColor::fromRgbF(values.value(QStringLiteral("lift_r")) / LIFT_FACTOR,
values.value(QStringLiteral("lift_g")) / LIFT_FACTOR,
values.value(QStringLiteral("lift_b")) / LIFT_FACTOR);
NegQColor gamma = NegQColor::fromRgbF(values.value(QStringLiteral("gamma_r")) / GAMMA_FACTOR,
values.value(QStringLiteral("gamma_g")) / GAMMA_FACTOR,
values.value(QStringLiteral("gamma_b")) / GAMMA_FACTOR);
NegQColor gain = NegQColor::fromRgbF(values.value(QStringLiteral("gain_r")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_g")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_b")) / GAIN_FACTOR);
/*QColor lift = QColor::fromRgbF(values.value(QStringLiteral("lift_r")), values.value(QStringLiteral("lift_g")), values.value(QStringLiteral("lift_b")));
QColor gamma = QColor::fromRgbF(values.value(QStringLiteral("gamma_r")) / GAMMA_FACTOR, values.value(QStringLiteral("gamma_g")) / GAMMA_FACTOR,
values.value(QStringLiteral("gamma_b")) / GAMMA_FACTOR);
QColor gain = QColor::fromRgbF(values.value(QStringLiteral("gain_r")) / GAIN_FACTOR, values.value(QStringLiteral("gain_g")) / GAIN_FACTOR,
values.value(QStringLiteral("gain_b")) / GAIN_FACTOR);
values.value(QStringLiteral("gain_b")) / GAIN_FACTOR);*/
qDebug() << "//REFRESHING WIDGET START 2--------------__";
m_lift->setColor(lift);
m_gamma->setColor(gamma);
......
......@@ -13,6 +13,6 @@ set(kdenlive_SRCS
effects/effectstack/view/collapsibleeffectview.cpp
effects/effectstack/view/effectstackview.cpp
effects/effectstack/view/builtstack.cpp
effects/effectstack/view/qml/colorwheelitem.cpp
#effects/effectstack/view/qml/colorwheelitem.cpp
PARENT_SCOPE)
......@@ -23,7 +23,7 @@
#include "assets/assetpanel.hpp"
#include "core.h"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "qml/colorwheelitem.h"
//#include "qml/colorwheelitem.h"
#include <KDeclarative/KDeclarative>
#include <QQmlContext>
......@@ -36,11 +36,11 @@ BuiltStack::BuiltStack(AssetPanel *parent)
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setupBindings();
qmlRegisterType<ColorWheelItem>("Kdenlive.Controls", 1, 0, "ColorWheelItem");
//qmlRegisterType<ColorWheelItem>("Kdenlive.Controls", 1, 0, "ColorWheelItem");
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setMinimumHeight(300);
// setClearColor(palette().base().color());
setSource(QUrl(QStringLiteral("qrc:/qml/BuiltStack.qml")));
//setSource(QUrl(QStringLiteral("qrc:/qml/BuiltStack.qml")));
setFocusPolicy(Qt::StrongFocus);
QQuickItem *root = rootObject();
QObject::connect(root, SIGNAL(valueChanged(QString, int)), parent, SLOT(parameterChanged(QString, int)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment