Add STFSlider
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
#include "stfslider.h"
|
||||||
|
#include <cmath>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
|
||||||
|
STFSlider::STFSlider(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
setMinimumHeight(15);
|
||||||
|
setMouseTracking(true);
|
||||||
|
m_blackPoint = 0;
|
||||||
|
m_midPoint = 0.5;
|
||||||
|
m_whitePoint = 1;
|
||||||
|
m_grabbed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void STFSlider::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
QRect rect = event->rect();
|
||||||
|
qreal w = rect.width() - 1;
|
||||||
|
qreal h = rect.height();
|
||||||
|
QLinearGradient gradient(rect.topLeft(), rect.topRight());
|
||||||
|
gradient.setColorAt(0, Qt::black);
|
||||||
|
for(int i=1; i<=32; i++)
|
||||||
|
{
|
||||||
|
qreal p = i/32.0f;
|
||||||
|
qreal c = std::pow(p, 1.0/2.2)*255;
|
||||||
|
gradient.setColorAt(p, QColor(c, c, c));
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath tick(QPointF(0, 0));
|
||||||
|
tick.lineTo(0, h - 5);
|
||||||
|
tick.lineTo(-5, h);
|
||||||
|
tick.lineTo(5, h);
|
||||||
|
tick.lineTo(0, h - 5);
|
||||||
|
|
||||||
|
painter.setBrush(gradient);
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.drawRect(rect);
|
||||||
|
|
||||||
|
auto drawTick = [&](qreal p)
|
||||||
|
{
|
||||||
|
painter.setPen(p < 0.4 ? Qt::white : Qt::black);
|
||||||
|
painter.resetTransform();
|
||||||
|
painter.translate(w*p, 0);
|
||||||
|
painter.drawPath(tick);
|
||||||
|
};
|
||||||
|
|
||||||
|
painter.setBrush(Qt::NoBrush);
|
||||||
|
drawTick(m_blackPoint);
|
||||||
|
drawTick(m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint);
|
||||||
|
drawTick(m_whitePoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void STFSlider::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(std::abs(m_blackPoint*width() - event->x()) < 5 ||
|
||||||
|
std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*width() - event->x()) < 5 ||
|
||||||
|
std::abs(m_whitePoint*width() - event->x()) < 5)
|
||||||
|
setCursor(Qt::SplitHCursor);
|
||||||
|
else
|
||||||
|
unsetCursor();
|
||||||
|
|
||||||
|
switch(m_grabbed)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
m_blackPoint = (qreal)event->x()/width();
|
||||||
|
m_whitePoint = std::max(m_whitePoint, m_blackPoint);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
m_midPoint = ((qreal)event->x()/width() - m_blackPoint) / (m_whitePoint - m_blackPoint);
|
||||||
|
m_midPoint = std::max(std::min(m_midPoint, 1.0f), 0.0f);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_whitePoint = (qreal)event->x()/width();
|
||||||
|
m_blackPoint = std::min(m_blackPoint, m_whitePoint);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(m_grabbed >= 0)
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void STFSlider::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*width() - event->x()) < 5)
|
||||||
|
m_grabbed = 1;
|
||||||
|
else if(std::abs(m_blackPoint*width() - event->x()) < 5)
|
||||||
|
m_grabbed = 0;
|
||||||
|
else if(std::abs(m_whitePoint*width() - event->x()) < 5)
|
||||||
|
m_grabbed = 2;
|
||||||
|
else
|
||||||
|
m_grabbed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void STFSlider::mouseReleaseEvent(QMouseEvent *)
|
||||||
|
{
|
||||||
|
m_grabbed = -1;
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef STFSLIDER_H
|
||||||
|
#define STFSLIDER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class STFSlider : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
float m_blackPoint;
|
||||||
|
float m_midPoint;
|
||||||
|
float m_whitePoint;
|
||||||
|
int m_grabbed;
|
||||||
|
public:
|
||||||
|
explicit STFSlider(QWidget *parent = nullptr);
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STFSLIDER_H
|
||||||
+5
-1
@@ -1,7 +1,8 @@
|
|||||||
#include "stretchpanel.h"
|
#include "stretchpanel.h"
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include "imageringlist.h"
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "imageringlist.h"
|
||||||
|
#include "stfslider.h"
|
||||||
|
|
||||||
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
@@ -12,6 +13,8 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
|||||||
m_highSlider = new QSlider(Qt::Horizontal, this);
|
m_highSlider = new QSlider(Qt::Horizontal, this);
|
||||||
m_paramSlider = new QSlider(Qt::Horizontal, this);
|
m_paramSlider = new QSlider(Qt::Horizontal, this);
|
||||||
|
|
||||||
|
STFSlider *stfslider = new STFSlider(this);
|
||||||
|
|
||||||
m_lowSlider->setRange(0, UINT16_MAX);
|
m_lowSlider->setRange(0, UINT16_MAX);
|
||||||
m_lowSlider->setPageStep(512);
|
m_lowSlider->setPageStep(512);
|
||||||
m_highSlider->setRange(0, UINT16_MAX);
|
m_highSlider->setRange(0, UINT16_MAX);
|
||||||
@@ -27,6 +30,7 @@ StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
|||||||
layout->addWidget(m_highSlider);
|
layout->addWidget(m_highSlider);
|
||||||
layout->addWidget(m_paramSlider);
|
layout->addWidget(m_paramSlider);
|
||||||
layout->addWidget(m_stretchSelect);
|
layout->addWidget(m_stretchSelect);
|
||||||
|
layout->addWidget(stfslider);
|
||||||
|
|
||||||
connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int)));
|
connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int)));
|
||||||
connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(int)));
|
connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(int)));
|
||||||
|
|||||||
+5
-2
@@ -33,7 +33,9 @@ SOURCES += main.cpp\
|
|||||||
starfit.cpp \
|
starfit.cpp \
|
||||||
imagescrollareagl.cpp \
|
imagescrollareagl.cpp \
|
||||||
stretchpanel.cpp \
|
stretchpanel.cpp \
|
||||||
rawimage.cpp
|
rawimage.cpp \
|
||||||
|
stfslider.cpp
|
||||||
|
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
filesystemwidget.h \
|
filesystemwidget.h \
|
||||||
@@ -45,7 +47,8 @@ HEADERS += mainwindow.h \
|
|||||||
rawimage.h \
|
rawimage.h \
|
||||||
starfit.h \
|
starfit.h \
|
||||||
imagescrollareagl.h \
|
imagescrollareagl.h \
|
||||||
stretchpanel.h
|
stretchpanel.h \
|
||||||
|
stfslider.h
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
|||||||
Reference in New Issue
Block a user