Commit 0bfac17e authored by Boudewijn Rempt's avatar Boudewijn Rempt

Move the gradients widget to krita/ui

We can use this widget in other places than the levels filter.
parent def9629a
set(kritalevelfilter_PART_SRCS set(kritalevelfilter_PART_SRCS
levelfilter.cpp levelfilter.cpp
kis_level_filter.cpp kis_level_filter.cpp
kgradientslider.cpp
) )
kde4_add_ui_files(kritalevelfilter_PART_SRCS kde4_add_ui_files(kritalevelfilter_PART_SRCS
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "kis_iterator.h" #include "kis_iterator.h"
#include "kis_histogram.h" #include "kis_histogram.h"
#include "kis_painter.h" #include "kis_painter.h"
#include "kgradientslider.h" #include "kis_gradient_slider.h"
#include "kis_processing_information.h" #include "kis_processing_information.h"
#include "kis_selection.h" #include "kis_selection.h"
#include "kis_types.h" #include "kis_types.h"
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="KGradientSlider" name="ingradient" native="true"> <widget class="KisGradientSlider" name="ingradient" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>256</width> <width>256</width>
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="7" column="0">
<widget class="KGradientSlider" name="outgradient" native="true"> <widget class="KisGradientSlider" name="outgradient" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>256</width> <width>256</width>
...@@ -263,14 +263,14 @@ ...@@ -263,14 +263,14 @@
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>KGradientSlider</class> <class>KisGradientSlider</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>kgradientslider.h</header> <header>kis_gradient_slider.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<includes> <includes>
<include location="local">kgradientslider.h</include> <include location="local">kis_gradient_slider.h</include>
<include location="local">kgradientslider.h</include> <include location="local">kis_gradient_slider.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>
......
...@@ -158,6 +158,7 @@ set(kritaui_LIB_SRCS ...@@ -158,6 +158,7 @@ set(kritaui_LIB_SRCS
widgets/kis_filter_selector_widget.cc widgets/kis_filter_selector_widget.cc
widgets/kis_gradient_chooser.cc widgets/kis_gradient_chooser.cc
widgets/kis_gradient_slider_widget.cc widgets/kis_gradient_slider_widget.cc
widgets/kis_gradient_slider.cpp
widgets/kis_iconwidget.cc widgets/kis_iconwidget.cc
widgets/kis_mask_widgets.cpp widgets/kis_mask_widgets.cpp
widgets/kis_meta_data_merge_strategy_chooser_widget.cc widgets/kis_meta_data_merge_strategy_chooser_widget.cc
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
*/ */
// Local includes. // Local includes.
#include "kgradientslider.h" #include "kis_gradient_slider.h"
// C++ includes. // C++ includes.
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
KGradientSlider::KGradientSlider(QWidget *parent) KisGradientSlider::KisGradientSlider(QWidget *parent)
: QWidget(parent), m_black(0), m_white(255), m_gamma(1.0), m_gammaEnabled(false) : QWidget(parent), m_black(0), m_white(255), m_gamma(1.0), m_gammaEnabled(false)
{ {
m_feedback = false; m_feedback = false;
...@@ -47,11 +47,21 @@ KGradientSlider::KGradientSlider(QWidget *parent) ...@@ -47,11 +47,21 @@ KGradientSlider::KGradientSlider(QWidget *parent)
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
} }
KGradientSlider::~KGradientSlider() KisGradientSlider::~KisGradientSlider()
{ {
} }
void KGradientSlider::paintEvent(QPaintEvent *) int KisGradientSlider::black() const
{
return m_black;
}
int KisGradientSlider::white() const
{
return m_white;
}
void KisGradientSlider::paintEvent(QPaintEvent *)
{ {
int x, y; int x, y;
int wWidth = width(); int wWidth = width();
...@@ -112,14 +122,14 @@ void KGradientSlider::paintEvent(QPaintEvent *) ...@@ -112,14 +122,14 @@ void KGradientSlider::paintEvent(QPaintEvent *)
p1.drawPolygon(a, 3); p1.drawPolygon(a, 3);
} }
void KGradientSlider::resizeEvent(QResizeEvent *) void KisGradientSlider::resizeEvent(QResizeEvent *)
{ {
m_scalingFactor = (double)width() / 255; m_scalingFactor = (double)width() / 255;
calculateCursorPositions(); calculateCursorPositions();
update(); update();
} }
void KGradientSlider::mousePressEvent(QMouseEvent * e) void KisGradientSlider::mousePressEvent(QMouseEvent * e)
{ {
eCursor closest_cursor; eCursor closest_cursor;
int distance; int distance;
...@@ -200,7 +210,7 @@ void KGradientSlider::mousePressEvent(QMouseEvent * e) ...@@ -200,7 +210,7 @@ void KGradientSlider::mousePressEvent(QMouseEvent * e)
update(); update();
} }
void KGradientSlider::mouseReleaseEvent(QMouseEvent * e) void KisGradientSlider::mouseReleaseEvent(QMouseEvent * e)
{ {
if (e->button() != Qt::LeftButton) if (e->button() != Qt::LeftButton)
return; return;
...@@ -229,7 +239,7 @@ void KGradientSlider::mouseReleaseEvent(QMouseEvent * e) ...@@ -229,7 +239,7 @@ void KGradientSlider::mouseReleaseEvent(QMouseEvent * e)
m_feedback = false; m_feedback = false;
} }
void KGradientSlider::mouseMoveEvent(QMouseEvent * e) void KisGradientSlider::mouseMoveEvent(QMouseEvent * e)
{ {
int x = e->pos().x(); int x = e->pos().x();
...@@ -274,14 +284,14 @@ void KGradientSlider::mouseMoveEvent(QMouseEvent * e) ...@@ -274,14 +284,14 @@ void KGradientSlider::mouseMoveEvent(QMouseEvent * e)
update(); update();
} }
void KGradientSlider::calculateCursorPositions() void KisGradientSlider::calculateCursorPositions()
{ {
m_blackCursor = (int)round(m_black * m_scalingFactor); m_blackCursor = (int)round(m_black * m_scalingFactor);
m_whiteCursor = (int)round(m_white * m_scalingFactor); m_whiteCursor = (int)round(m_white * m_scalingFactor);
m_gammaCursor = calculateGammaCursor(); m_gammaCursor = calculateGammaCursor();
} }
unsigned int KGradientSlider::calculateGammaCursor() unsigned int KisGradientSlider::calculateGammaCursor()
{ {
double delta = (double)(m_whiteCursor - m_blackCursor) / 2.0; double delta = (double)(m_whiteCursor - m_blackCursor) / 2.0;
double mid = (double)m_blackCursor + delta; double mid = (double)m_blackCursor + delta;
...@@ -290,18 +300,18 @@ unsigned int KGradientSlider::calculateGammaCursor() ...@@ -290,18 +300,18 @@ unsigned int KGradientSlider::calculateGammaCursor()
} }
void KGradientSlider::enableGamma(bool b) void KisGradientSlider::enableGamma(bool b)
{ {
m_gammaEnabled = b; m_gammaEnabled = b;
update(); update();
} }
double KGradientSlider::getGamma(void) double KisGradientSlider::getGamma(void)
{ {
return m_gamma; return m_gamma;
} }
void KGradientSlider::slotModifyBlack(int v) void KisGradientSlider::slotModifyBlack(int v)
{ {
if (v >= 0 && v <= (int)m_white && !m_feedback) { if (v >= 0 && v <= (int)m_white && !m_feedback) {
m_black = v; m_black = v;
...@@ -310,7 +320,7 @@ void KGradientSlider::slotModifyBlack(int v) ...@@ -310,7 +320,7 @@ void KGradientSlider::slotModifyBlack(int v)
update(); update();
} }
} }
void KGradientSlider::slotModifyWhite(int v) void KisGradientSlider::slotModifyWhite(int v)
{ {
if (v >= (int)m_black && v <= width() && !m_feedback) { if (v >= (int)m_black && v <= width() && !m_feedback) {
m_white = v; m_white = v;
...@@ -319,7 +329,7 @@ void KGradientSlider::slotModifyWhite(int v) ...@@ -319,7 +329,7 @@ void KGradientSlider::slotModifyWhite(int v)
update(); update();
} }
} }
void KGradientSlider::slotModifyGamma(double v) void KisGradientSlider::slotModifyGamma(double v)
{ {
if (m_gamma != v) { if (m_gamma != v) {
emit sigModifiedGamma(v); emit sigModifiedGamma(v);
...@@ -329,4 +339,4 @@ void KGradientSlider::slotModifyGamma(double v) ...@@ -329,4 +339,4 @@ void KGradientSlider::slotModifyGamma(double v)
update(); update();
} }
#include "kgradientslider.moc" #include "kis_gradient_slider.moc"
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef KGRADIENTSLIDER_H #ifndef KIS_GRADIENT_SLIDER_H
#define KGRADIENTSLIDER_H #define KIS_GRADIENT_SLIDER_H
// Qt includes. // Qt includes.
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
#include <QList> #include <QList>
#include <QPair> #include <QPair>
class KGradientSlider : public QWidget #include <krita_export.h>
class KRITAUI_EXPORT KisGradientSlider : public QWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -40,9 +42,12 @@ class KGradientSlider : public QWidget ...@@ -40,9 +42,12 @@ class KGradientSlider : public QWidget
} eCursor; } eCursor;
public: public:
KGradientSlider(QWidget *parent = 0); KisGradientSlider(QWidget *parent = 0);
virtual ~KisGradientSlider();
virtual ~KGradientSlider(); int black() const;
int white() const;
public slots: public slots:
void slotModifyBlack(int); void slotModifyBlack(int);
...@@ -90,4 +95,4 @@ private: ...@@ -90,4 +95,4 @@ private:
}; };
#endif /* KGRADIENTSLIDER_H */ #endif /* KIS_GRADIENT_SLIDER_H */
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