Add STFSlider ability to be vertical
This commit is contained in:
+78
-12
@@ -12,7 +12,7 @@ static float clamp(float x)
|
|||||||
|
|
||||||
STFSlider::STFSlider(const QColor &color, QWidget *parent) : QWidget(parent)
|
STFSlider::STFSlider(const QColor &color, QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
setMinimumWidth(100);
|
setMinimumWidth(100);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
@@ -64,12 +64,51 @@ void STFSlider::setMTFParams(float low, float mid, float high)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void STFSlider::orientationChanged(Qt::Orientations orientation)
|
||||||
|
{
|
||||||
|
m_orientation = orientation;
|
||||||
|
if(m_orientation == Qt::Horizontal)
|
||||||
|
{
|
||||||
|
if(m_color == Qt::white)
|
||||||
|
{
|
||||||
|
setMaximumSize(QWIDGETSIZE_MAX, 16);
|
||||||
|
setMinimumSize(16, 16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setMaximumSize(QWIDGETSIZE_MAX, 10);
|
||||||
|
setMinimumSize(10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(m_color == Qt::white)
|
||||||
|
{
|
||||||
|
setMaximumSize(16, QWIDGETSIZE_MAX);
|
||||||
|
setMinimumSize(16, 16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setMaximumSize(10, QWIDGETSIZE_MAX);
|
||||||
|
setMinimumSize(10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void STFSlider::paintEvent(QPaintEvent *event)
|
void STFSlider::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QRect rect = event->rect();
|
QRect rect = event->rect();
|
||||||
qreal w = rect.width() - 1;
|
qreal w = rect.width() - 1;
|
||||||
qreal h = rect.height();
|
qreal h = rect.height();
|
||||||
|
if(m_orientation == Qt::Vertical)
|
||||||
|
{
|
||||||
|
rect = rect.transposed();
|
||||||
|
painter.rotate(90);
|
||||||
|
w = rect.width() - 1;
|
||||||
|
h = rect.height();
|
||||||
|
painter.translate(0, -h);
|
||||||
|
}
|
||||||
QLinearGradient gradient(rect.topLeft(), rect.topRight());
|
QLinearGradient gradient(rect.topLeft(), rect.topRight());
|
||||||
gradient.setColorAt(0, Qt::black);
|
gradient.setColorAt(0, Qt::black);
|
||||||
for(int i=1; i<=32; i++)
|
for(int i=1; i<=32; i++)
|
||||||
@@ -93,6 +132,11 @@ void STFSlider::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
painter.setPen(p < m_threshold ? Qt::white : Qt::black);
|
painter.setPen(p < m_threshold ? Qt::white : Qt::black);
|
||||||
painter.resetTransform();
|
painter.resetTransform();
|
||||||
|
if(m_orientation == Qt::Vertical)
|
||||||
|
{
|
||||||
|
painter.rotate(90);
|
||||||
|
painter.translate(0, -h);
|
||||||
|
}
|
||||||
painter.translate(w*p, 0);
|
painter.translate(w*p, 0);
|
||||||
painter.drawPath(tick);
|
painter.drawPath(tick);
|
||||||
};
|
};
|
||||||
@@ -105,15 +149,26 @@ void STFSlider::paintEvent(QPaintEvent *event)
|
|||||||
|
|
||||||
void STFSlider::mouseMoveEvent(QMouseEvent *event)
|
void STFSlider::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
const qreal x = event->position().x();
|
qreal x,w;
|
||||||
if(std::abs(m_blackPoint*width() - x) < 5 ||
|
if(m_orientation == Qt::Horizontal)
|
||||||
std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*width() - x) < 5 ||
|
{
|
||||||
std::abs(m_whitePoint*width() - x) < 5)
|
x = event->position().x();
|
||||||
setCursor(Qt::SplitHCursor);
|
w = width();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = event->position().y();
|
||||||
|
w = height();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(std::abs(m_blackPoint*w - x) < 5 ||
|
||||||
|
std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*w - x) < 5 ||
|
||||||
|
std::abs(m_whitePoint*w - x) < 5)
|
||||||
|
setCursor(m_orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
|
||||||
else
|
else
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
|
|
||||||
qreal xw = x/width();
|
qreal xw = x/w;
|
||||||
if(event->modifiers() & Qt::ShiftModifier && !m_fineTune)
|
if(event->modifiers() & Qt::ShiftModifier && !m_fineTune)
|
||||||
{
|
{
|
||||||
m_fineTune = true;
|
m_fineTune = true;
|
||||||
@@ -154,18 +209,29 @@ void STFSlider::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void STFSlider::mousePressEvent(QMouseEvent *event)
|
void STFSlider::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
const qreal x = event->position().x();
|
qreal x,w;
|
||||||
|
if(m_orientation == Qt::Horizontal)
|
||||||
|
{
|
||||||
|
x = event->position().x();
|
||||||
|
w = width();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = event->position().y();
|
||||||
|
w = height();
|
||||||
|
}
|
||||||
|
|
||||||
if(event->modifiers() & Qt::ShiftModifier)
|
if(event->modifiers() & Qt::ShiftModifier)
|
||||||
{
|
{
|
||||||
m_fineTune = true;
|
m_fineTune = true;
|
||||||
m_fineTuneX = x/width();
|
m_fineTuneX = x/w;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*width() - x) < 5)
|
if(std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*w - x) < 5)
|
||||||
m_grabbed = 1;
|
m_grabbed = 1;
|
||||||
else if(std::abs(m_blackPoint*width() - x) < 5)
|
else if(std::abs(m_blackPoint*w - x) < 5)
|
||||||
m_grabbed = 0;
|
m_grabbed = 0;
|
||||||
else if(std::abs(m_whitePoint*width() - x) < 5)
|
else if(std::abs(m_whitePoint*w - x) < 5)
|
||||||
m_grabbed = 2;
|
m_grabbed = 2;
|
||||||
else
|
else
|
||||||
m_grabbed = -1;
|
m_grabbed = -1;
|
||||||
|
|||||||
@@ -15,12 +15,15 @@ class STFSlider : public QWidget
|
|||||||
float m_fineTuneX;
|
float m_fineTuneX;
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
float m_threshold;
|
float m_threshold;
|
||||||
|
Qt::Orientations m_orientation = Qt::Horizontal;
|
||||||
public:
|
public:
|
||||||
explicit STFSlider(const QColor &color = Qt::white, QWidget *parent = nullptr);
|
explicit STFSlider(const QColor &color = Qt::white, QWidget *parent = nullptr);
|
||||||
float blackPoint() const;
|
float blackPoint() const;
|
||||||
float midPoint() const;
|
float midPoint() const;
|
||||||
float whitePoint() const;
|
float whitePoint() const;
|
||||||
void setMTFParams(float low, float mid, float high);
|
void setMTFParams(float low, float mid, float high);
|
||||||
|
public slots:
|
||||||
|
void orientationChanged(Qt::Orientations orientation);
|
||||||
signals:
|
signals:
|
||||||
void paramChanged(float blackPoint, float midPoint, float whitePoint);
|
void paramChanged(float blackPoint, float midPoint, float whitePoint);
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
+12
-16
@@ -6,17 +6,6 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include "imageringlist.h"
|
#include "imageringlist.h"
|
||||||
|
|
||||||
const float BLACK_POINT_SIGMA = -2.8f;
|
|
||||||
const float MAD_TO_SIGMA = 1.4826f;
|
|
||||||
const float TARGET_BACKGROUND = 0.25f;
|
|
||||||
|
|
||||||
float MTF(float x, float m)
|
|
||||||
{
|
|
||||||
if(x < 0)return 0;
|
|
||||||
if(x > 1)return 1;
|
|
||||||
return ((m - 1) * x) / ((2 * m - 1) * x - m);
|
|
||||||
}
|
|
||||||
|
|
||||||
StretchToolbar::StretchToolbar(QWidget *parent) : QToolBar(tr("Stretch toolbar"), parent)
|
StretchToolbar::StretchToolbar(QWidget *parent) : QToolBar(tr("Stretch toolbar"), parent)
|
||||||
{
|
{
|
||||||
setObjectName("stretchtoolbar");
|
setObjectName("stretchtoolbar");
|
||||||
@@ -24,16 +13,23 @@ StretchToolbar::StretchToolbar(QWidget *parent) : QToolBar(tr("Stretch toolbar")
|
|||||||
QVBoxLayout *vbox1 = new QVBoxLayout(lum);
|
QVBoxLayout *vbox1 = new QVBoxLayout(lum);
|
||||||
m_stfSlider = new STFSlider(Qt::white, this);
|
m_stfSlider = new STFSlider(Qt::white, this);
|
||||||
vbox1->addWidget(m_stfSlider);
|
vbox1->addWidget(m_stfSlider);
|
||||||
|
connect(this, &StretchToolbar::orientationChanged, m_stfSlider, &STFSlider::orientationChanged);
|
||||||
|
|
||||||
m_stfSliderR = new STFSlider(Qt::red, this);
|
m_stfSliderR = new STFSlider(Qt::red, this);
|
||||||
m_stfSliderG = new STFSlider(Qt::green, this);
|
m_stfSliderG = new STFSlider(Qt::green, this);
|
||||||
m_stfSliderB = new STFSlider(Qt::blue, this);
|
m_stfSliderB = new STFSlider(Qt::blue, this);
|
||||||
QWidget *rgb = new QWidget(this);
|
QWidget *rgb = new QWidget(this);
|
||||||
QVBoxLayout *vbox2 = new QVBoxLayout(rgb);
|
QBoxLayout *box2 = new QBoxLayout(orientation() == Qt::Horizontal ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight, rgb);
|
||||||
vbox2->setSpacing(0);
|
box2->setSpacing(0);
|
||||||
vbox2->addWidget(m_stfSliderR);
|
box2->addWidget(m_stfSliderR);
|
||||||
vbox2->addWidget(m_stfSliderG);
|
box2->addWidget(m_stfSliderG);
|
||||||
vbox2->addWidget(m_stfSliderB);
|
box2->addWidget(m_stfSliderB);
|
||||||
|
connect(this, &StretchToolbar::orientationChanged, m_stfSliderR, &STFSlider::orientationChanged);
|
||||||
|
connect(this, &StretchToolbar::orientationChanged, m_stfSliderG, &STFSlider::orientationChanged);
|
||||||
|
connect(this, &StretchToolbar::orientationChanged, m_stfSliderB, &STFSlider::orientationChanged);
|
||||||
|
connect(this, &StretchToolbar::orientationChanged, [box2](Qt::Orientations orientation){
|
||||||
|
box2->setDirection(orientation == Qt::Horizontal ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||||
|
});
|
||||||
|
|
||||||
m_stack = new QStackedWidget(this);
|
m_stack = new QStackedWidget(this);
|
||||||
m_stack->addWidget(lum);
|
m_stack->addWidget(lum);
|
||||||
|
|||||||
Reference in New Issue
Block a user