mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
kdeui: remove unused private member
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
7df1c4b6bb
commit
a2e4da709f
5 changed files with 361 additions and 348 deletions
|
@ -23,14 +23,17 @@
|
||||||
|
|
||||||
#include "kcolorchoosermode_p.h"
|
#include "kcolorchoosermode_p.h"
|
||||||
|
|
||||||
using namespace KDEPrivate;
|
|
||||||
|
|
||||||
class KColorValueSelector::Private
|
class KColorValueSelector::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(KColorValueSelector *q): q(q), _hue(0), _sat(0), _colorValue(0), _mode(ChooserClassic) {}
|
Private()
|
||||||
|
: _hue(0),
|
||||||
|
_sat(0),
|
||||||
|
_colorValue(0),
|
||||||
|
_mode(KColorChooserMode::ChooserClassic)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
KColorValueSelector *q;
|
|
||||||
int _hue;
|
int _hue;
|
||||||
int _sat;
|
int _sat;
|
||||||
int _colorValue;
|
int _colorValue;
|
||||||
|
@ -38,16 +41,18 @@ public:
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
KColorValueSelector::KColorValueSelector( QWidget *parent )
|
KColorValueSelector::KColorValueSelector(QWidget *parent)
|
||||||
: KSelector( Qt::Vertical, parent ), d( new Private( this ) )
|
: KSelector(Qt::Vertical, parent),
|
||||||
|
d( new Private())
|
||||||
{
|
{
|
||||||
setRange( 0, 255 );
|
setRange(0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
KColorValueSelector::KColorValueSelector( Qt::Orientation o, QWidget *parent )
|
KColorValueSelector::KColorValueSelector(Qt::Orientation o, QWidget *parent)
|
||||||
: KSelector( o, parent ), d( new Private( this ) )
|
: KSelector(o, parent),
|
||||||
|
d(new Private())
|
||||||
{
|
{
|
||||||
setRange( 0, 255 );
|
setRange(0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
KColorValueSelector::~KColorValueSelector()
|
KColorValueSelector::~KColorValueSelector()
|
||||||
|
@ -60,7 +65,7 @@ int KColorValueSelector::hue() const
|
||||||
return d->_hue;
|
return d->_hue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::setHue( int hue )
|
void KColorValueSelector::setHue(int hue)
|
||||||
{
|
{
|
||||||
d->_hue = hue;
|
d->_hue = hue;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +75,7 @@ int KColorValueSelector::saturation() const
|
||||||
return d->_sat;
|
return d->_sat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::setSaturation( int saturation )
|
void KColorValueSelector::setSaturation(int saturation)
|
||||||
{
|
{
|
||||||
d->_sat = saturation;
|
d->_sat = saturation;
|
||||||
}
|
}
|
||||||
|
@ -80,47 +85,46 @@ int KColorValueSelector::colorValue () const
|
||||||
return d->_colorValue;
|
return d->_colorValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::setColorValue ( int colorValue )
|
void KColorValueSelector::setColorValue(int colorValue)
|
||||||
{
|
{
|
||||||
d->_colorValue = colorValue;
|
d->_colorValue = colorValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void KColorValueSelector::updateContents()
|
void KColorValueSelector::updateContents()
|
||||||
{
|
{
|
||||||
drawPalette( &d->pixmap );
|
drawPalette(&d->pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::resizeEvent( QResizeEvent * )
|
void KColorValueSelector::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
updateContents();
|
updateContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::drawContents( QPainter *painter )
|
void KColorValueSelector::drawContents(QPainter *painter)
|
||||||
{
|
{
|
||||||
painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
|
painter->drawPixmap(contentsRect().x(), contentsRect().y(), d->pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::setChooserMode( KColorChooserMode c )
|
void KColorValueSelector::setChooserMode(KColorChooserMode chooserMode)
|
||||||
{
|
{
|
||||||
if ( c == ChooserHue ) {
|
if (chooserMode == KColorChooserMode::ChooserHue) {
|
||||||
setRange( 0, 360 );
|
setRange(0, 360);
|
||||||
} else {
|
} else {
|
||||||
setRange( 0, 255 );
|
setRange(0, 255);
|
||||||
}
|
}
|
||||||
d->_mode = c;
|
d->_mode = chooserMode;
|
||||||
|
|
||||||
//really needed?
|
// really needed?
|
||||||
//emit modeChanged();
|
// emit modeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
KColorChooserMode KColorValueSelector::chooserMode () const
|
KColorChooserMode KColorValueSelector::chooserMode() const
|
||||||
{
|
{
|
||||||
return d->_mode;
|
return d->_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KColorValueSelector::drawPalette( QPixmap *pixmap )
|
void KColorValueSelector::drawPalette(QPixmap *pixmap)
|
||||||
{
|
{
|
||||||
QColor color;
|
QColor color;
|
||||||
if (chooserMode() == ChooserHue) {
|
if (chooserMode() == ChooserHue) {
|
||||||
|
@ -138,9 +142,9 @@ void KColorValueSelector::drawPalette( QPixmap *pixmap )
|
||||||
gradient.setFinalStop(contentsRect().width(), 0);
|
gradient.setFinalStop(contentsRect().width(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int steps = componentValueSteps(chooserMode());
|
const int steps = KDEPrivate::componentValueSteps(chooserMode());
|
||||||
for (int v = 0; v <= steps; ++v) {
|
for (int v = 0; v <= steps; ++v) {
|
||||||
setComponentValue(color, chooserMode(), v * (1.0 / steps));
|
KDEPrivate::setComponentValue(color, chooserMode(), v * (1.0 / steps));
|
||||||
gradient.setColorAt(v * (1.0 / steps), color);
|
gradient.setColorAt(v * (1.0 / steps), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,5 +153,4 @@ void KColorValueSelector::drawPalette( QPixmap *pixmap )
|
||||||
painter.fillRect(pixmap->rect(), gradient);
|
painter.fillRect(pixmap->rect(), gradient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "moc_kcolorvalueselector.cpp"
|
#include "moc_kcolorvalueselector.cpp"
|
||||||
|
|
|
@ -23,23 +23,24 @@
|
||||||
|
|
||||||
#include "kselector.h"
|
#include "kselector.h"
|
||||||
#include "kcolorchoosermode.h"
|
#include "kcolorchoosermode.h"
|
||||||
#include <QtGui/QPixmap>
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
class KDEUI_EXPORT KColorValueSelector : public KSelector
|
class KDEUI_EXPORT KColorValueSelector : public KSelector
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( int hue READ hue WRITE setHue )
|
Q_PROPERTY(int hue READ hue WRITE setHue)
|
||||||
Q_PROPERTY( int saturation READ saturation WRITE setSaturation )
|
Q_PROPERTY(int saturation READ saturation WRITE setSaturation)
|
||||||
Q_PROPERTY( int colorValue READ colorValue WRITE setColorValue )
|
Q_PROPERTY(int colorValue READ colorValue WRITE setColorValue)
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructs a widget for color selection.
|
* Constructs a widget for color selection.
|
||||||
*/
|
*/
|
||||||
explicit KColorValueSelector( QWidget *parent=0 );
|
explicit KColorValueSelector(QWidget *parent = nullptr);
|
||||||
/**
|
/**
|
||||||
* Constructs a widget for color selection with a given orientation
|
* Constructs a widget for color selection with a given orientation
|
||||||
*/
|
*/
|
||||||
explicit KColorValueSelector( Qt::Orientation o, QWidget *parent = 0 );
|
explicit KColorValueSelector(Qt::Orientation o, QWidget *parent = nullptr);
|
||||||
|
|
||||||
~KColorValueSelector();
|
~KColorValueSelector();
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param hue Sets the hue value (0-359)
|
* @param hue Sets the hue value (0-359)
|
||||||
*/
|
*/
|
||||||
void setHue( int hue );
|
void setHue(int hue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current saturation value.
|
* Returns the current saturation value.
|
||||||
|
@ -76,7 +77,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param saturation Sets the saturation value (0-255)
|
* @param saturation Sets the saturation value (0-255)
|
||||||
*/
|
*/
|
||||||
void setSaturation( int saturation );
|
void setSaturation(int saturation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current color value.
|
* Returns the current color value.
|
||||||
|
@ -91,7 +92,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param colorValue Sets the color value (0-255)
|
* @param colorValue Sets the color value (0-255)
|
||||||
*/
|
*/
|
||||||
void setColorValue( int colorValue );
|
void setColorValue(int colorValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the chooser mode. Doesn't automatically update the widget;
|
* Sets the chooser mode. Doesn't automatically update the widget;
|
||||||
|
@ -99,29 +100,29 @@ public:
|
||||||
*
|
*
|
||||||
* @param chooserMode Sets the chooser mode (one of the KColorChooserMode constants)
|
* @param chooserMode Sets the chooser mode (one of the KColorChooserMode constants)
|
||||||
*/
|
*/
|
||||||
void setChooserMode (KColorChooserMode chooserMode);
|
void setChooserMode(KColorChooserMode chooserMode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current chooser mode.
|
* Returns the current chooser mode.
|
||||||
*
|
*
|
||||||
* @return The chooser mode (one of the KColorChooserMode constants)
|
* @return The chooser mode (one of the KColorChooserMode constants)
|
||||||
*/
|
*/
|
||||||
KColorChooserMode chooserMode () const;
|
KColorChooserMode chooserMode() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Draws the contents of the widget on a pixmap,
|
* Draws the contents of the widget on a pixmap,
|
||||||
* which is used for buffering.
|
* which is used for buffering.
|
||||||
*/
|
*/
|
||||||
virtual void drawPalette( QPixmap *pixmap );
|
virtual void drawPalette(QPixmap *pixmap);
|
||||||
virtual void resizeEvent( QResizeEvent * );
|
virtual void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reimplemented from KSelector. The drawing is
|
* Reimplemented from KSelector. The drawing is
|
||||||
* buffered in a pixmap here. As real drawing
|
* buffered in a pixmap here. As real drawing
|
||||||
* routine, drawPalette() is used.
|
* routine, drawPalette() is used.
|
||||||
*/
|
*/
|
||||||
virtual void drawContents( QPainter *painter );
|
virtual void drawContents(QPainter *painter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
|
|
|
@ -19,12 +19,10 @@
|
||||||
|
|
||||||
#include "khuesaturationselect.h"
|
#include "khuesaturationselect.h"
|
||||||
|
|
||||||
#include <QtGui/QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "kcolorchoosermode_p.h"
|
#include "kcolorchoosermode_p.h"
|
||||||
|
|
||||||
using namespace KDEPrivate;
|
|
||||||
|
|
||||||
class KHueSaturationSelector::Private
|
class KHueSaturationSelector::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -135,17 +133,17 @@ void KHueSaturationSelector::drawContents(QPainter *painter)
|
||||||
|
|
||||||
void KHueSaturationSelector::drawPalette(QPixmap *pixmap)
|
void KHueSaturationSelector::drawPalette(QPixmap *pixmap)
|
||||||
{
|
{
|
||||||
int xSteps = componentXSteps(chooserMode());
|
int xSteps = KDEPrivate::componentXSteps(chooserMode());
|
||||||
int ySteps = componentYSteps(chooserMode());
|
int ySteps = KDEPrivate::componentYSteps(chooserMode());
|
||||||
|
|
||||||
QColor color;
|
QColor color;
|
||||||
color.setHsv(hue(), saturation(), chooserMode() == ChooserClassic ? 192 : colorValue());
|
color.setHsv(hue(), saturation(), chooserMode() == KColorChooserMode::ChooserClassic ? 192 : colorValue());
|
||||||
|
|
||||||
QImage image(QSize(xSteps + 1, ySteps + 1), QImage::Format_RGB32);
|
QImage image(QSize(xSteps + 1, ySteps + 1), QImage::Format_RGB32);
|
||||||
for (int y = 0; y <= ySteps; ++y) {
|
for (int y = 0; y <= ySteps; ++y) {
|
||||||
setComponentY(color, chooserMode(), y * (1.0 / ySteps));
|
KDEPrivate::setComponentY(color, chooserMode(), y * (1.0 / ySteps));
|
||||||
for (int x = 0; x <= xSteps; ++x) {
|
for (int x = 0; x <= xSteps; ++x) {
|
||||||
setComponentX(color, chooserMode(), x * (1.0 / xSteps));
|
KDEPrivate::setComponentX(color, chooserMode(), x * (1.0 / xSteps));
|
||||||
image.setPixel(x, ySteps - y, color.rgb());
|
image.setPixel(x, ySteps - y, color.rgb());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kxyselector.h"
|
#include "kxyselector.h"
|
||||||
|
#include "kdebug.h"
|
||||||
|
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QtGui/qpen.h>
|
#include <QPen>
|
||||||
#include <QtGui/qstyleoption.h>
|
#include <QStyleOptionFrame>
|
||||||
#include <QtGui/qevent.h>
|
#include <QWheelEvent>
|
||||||
#include <kdebug.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
|
@ -34,8 +35,8 @@
|
||||||
class KXYSelector::Private
|
class KXYSelector::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(KXYSelector *q):
|
Private(KXYSelector *q)
|
||||||
q(q),
|
: q(q),
|
||||||
xPos(0),
|
xPos(0),
|
||||||
yPos(0),
|
yPos(0),
|
||||||
minX(0),
|
minX(0),
|
||||||
|
@ -43,7 +44,8 @@ public:
|
||||||
minY(0),
|
minY(0),
|
||||||
maxY(100),
|
maxY(100),
|
||||||
m_markerColor(Qt::white)
|
m_markerColor(Qt::white)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void setValues(int _xPos, int _yPos);
|
void setValues(int _xPos, int _yPos);
|
||||||
|
|
||||||
|
@ -59,9 +61,9 @@ public:
|
||||||
QColor m_markerColor;
|
QColor m_markerColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
KXYSelector::KXYSelector( QWidget *parent )
|
KXYSelector::KXYSelector(QWidget *parent)
|
||||||
: QWidget( parent )
|
: QWidget(parent),
|
||||||
, d(new Private(this))
|
d(new Private(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +83,7 @@ int KXYSelector::yValue() const
|
||||||
return d->yPos;
|
return d->yPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
|
void KXYSelector::setRange(int _minX, int _minY, int _maxX, int _maxY)
|
||||||
{
|
{
|
||||||
if (_maxX == _minX) {
|
if (_maxX == _minX) {
|
||||||
kWarning() << "KXYSelector::setRange invalid range: " << _maxX << " == " << _minX << " (for X) ";
|
kWarning() << "KXYSelector::setRange invalid range: " << _maxX << " == " << _minX << " (for X) ";
|
||||||
|
@ -92,7 +94,6 @@ void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
d->px = w;
|
d->px = w;
|
||||||
d->py = w;
|
d->py = w;
|
||||||
|
@ -102,37 +103,39 @@ void KXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
|
||||||
d->maxY = _maxY;
|
d->maxY = _maxY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setXValue( int _xPos )
|
void KXYSelector::setXValue(int _xPos)
|
||||||
{
|
{
|
||||||
setValues(_xPos, d->yPos);
|
setValues(_xPos, d->yPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setYValue( int _yPos )
|
void KXYSelector::setYValue( int _yPos)
|
||||||
{
|
{
|
||||||
setValues(d->xPos, _yPos);
|
setValues(d->xPos, _yPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setValues( int _xPos, int _yPos )
|
void KXYSelector::setValues(int _xPos, int _yPos)
|
||||||
{
|
{
|
||||||
d->setValues(_xPos, _yPos);
|
d->setValues(_xPos, _yPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::Private::setValues(int _xPos, int _yPos )
|
void KXYSelector::Private::setValues(int _xPos, int _yPos)
|
||||||
{
|
{
|
||||||
int w = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int w = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
|
|
||||||
xPos = _xPos;
|
xPos = _xPos;
|
||||||
yPos = _yPos;
|
yPos = _yPos;
|
||||||
|
|
||||||
if ( xPos > maxX )
|
if (xPos > maxX) {
|
||||||
xPos = maxX;
|
xPos = maxX;
|
||||||
else if ( xPos < minX )
|
} else if (xPos < minX) {
|
||||||
xPos = minX;
|
xPos = minX;
|
||||||
|
}
|
||||||
|
|
||||||
if ( yPos > maxY )
|
if (yPos > maxY) {
|
||||||
yPos = maxY;
|
yPos = maxY;
|
||||||
else if ( yPos < minY )
|
} else if (yPos < minY) {
|
||||||
yPos = minY;
|
yPos = minY;
|
||||||
|
}
|
||||||
|
|
||||||
Q_ASSERT(maxX != minX);
|
Q_ASSERT(maxX != minX);
|
||||||
int xp = w + (q->width() - 2 * w) * xPos / (maxX - minX);
|
int xp = w + (q->width() - 2 * w) * xPos / (maxX - minX);
|
||||||
|
@ -143,7 +146,7 @@ void KXYSelector::Private::setValues(int _xPos, int _yPos )
|
||||||
q->setPosition( xp, yp );
|
q->setPosition( xp, yp );
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setMarkerColor( const QColor &col )
|
void KXYSelector::setMarkerColor(const QColor &col)
|
||||||
{
|
{
|
||||||
d->m_markerColor = col;
|
d->m_markerColor = col;
|
||||||
}
|
}
|
||||||
|
@ -157,81 +160,89 @@ QRect KXYSelector::contentsRect() const
|
||||||
QSize KXYSelector::minimumSizeHint() const
|
QSize KXYSelector::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
return QSize( 2 * w, 2 * w );
|
return QSize(2 * w, 2 * w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::paintEvent( QPaintEvent * /* ev */ )
|
void KXYSelector::paintEvent(QPaintEvent *e)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(e);
|
||||||
|
|
||||||
QStyleOptionFrame opt;
|
QStyleOptionFrame opt;
|
||||||
opt.initFrom(this);
|
opt.initFrom(this);
|
||||||
|
|
||||||
QPainter painter;
|
QPainter painter;
|
||||||
painter.begin( this );
|
painter.begin(this);
|
||||||
|
|
||||||
drawContents( &painter );
|
drawContents(&painter );
|
||||||
drawMarker( &painter, d->px, d->py );
|
drawMarker(&painter, d->px, d->py);
|
||||||
|
|
||||||
style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
|
style()->drawPrimitive(QStyle::PE_Frame, &opt, &painter, this);
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::mousePressEvent( QMouseEvent *e )
|
void KXYSelector::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
mouseMoveEvent( e );
|
mouseMoveEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::mouseMoveEvent( QMouseEvent *e )
|
void KXYSelector::mouseMoveEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
int xVal, yVal;
|
int xVal = 0;
|
||||||
int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
|
int yVal = 0;
|
||||||
valuesFromPosition( e->pos().x() - w, e->pos().y() - w, xVal, yVal );
|
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth );
|
||||||
setValues( xVal, yVal );
|
valuesFromPosition(e->pos().x() - w, e->pos().y() - w, xVal, yVal);
|
||||||
|
setValues(xVal, yVal);
|
||||||
|
|
||||||
emit valueChanged( d->xPos, d->yPos );
|
emit valueChanged(d->xPos, d->yPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::wheelEvent( QWheelEvent *e )
|
void KXYSelector::wheelEvent(QWheelEvent *e)
|
||||||
{
|
{
|
||||||
if ( e->orientation() == Qt::Horizontal )
|
if (e->orientation() == Qt::Horizontal) {
|
||||||
setValues( xValue() + e->delta()/120, yValue() );
|
setValues(xValue() + e->delta() / 120, yValue());
|
||||||
else
|
} else {
|
||||||
setValues( xValue(), yValue() + e->delta()/120 );
|
setValues(xValue(), yValue() + e->delta() / 120);
|
||||||
|
}
|
||||||
|
|
||||||
emit valueChanged( d->xPos, d->yPos );
|
emit valueChanged(d->xPos, d->yPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const
|
void KXYSelector::valuesFromPosition(int x, int y, int &xVal, int &yVal) const
|
||||||
{
|
{
|
||||||
int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
|
int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
|
||||||
|
|
||||||
xVal = ( ( d->maxX - d->minX ) * ( x - w ) ) / ( width() - 2 * w );
|
xVal = ((d->maxX - d->minX) * (x - w)) / (width() - 2 * w);
|
||||||
yVal = d->maxY - ( ( ( d->maxY - d->minY ) * (y - w) ) / ( height() - 2 * w ) );
|
yVal = (d->maxY - (((d->maxY - d->minY) * (y - w) ) / (height() - 2 * w)));
|
||||||
|
|
||||||
if ( xVal > d->maxX )
|
if (xVal > d->maxX) {
|
||||||
xVal = d->maxX;
|
xVal = d->maxX;
|
||||||
else if ( xVal < d->minX )
|
} else if (xVal < d->minX) {
|
||||||
xVal = d->minX;
|
xVal = d->minX;
|
||||||
|
}
|
||||||
|
|
||||||
if ( yVal > d->maxY )
|
if (yVal > d->maxY) {
|
||||||
yVal = d->maxY;
|
yVal = d->maxY;
|
||||||
else if ( yVal < d->minY )
|
} else if ( yVal < d->minY) {
|
||||||
yVal = d->minY;
|
yVal = d->minY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::setPosition( int xp, int yp )
|
void KXYSelector::setPosition(int xp, int yp)
|
||||||
{
|
{
|
||||||
int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
|
int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
|
|
||||||
if ( xp < w )
|
if (xp < w) {
|
||||||
xp = w;
|
xp = w;
|
||||||
else if ( xp > width() - w )
|
} else if (xp > width() - w) {
|
||||||
xp = width() - w;
|
xp = width() - w;
|
||||||
|
}
|
||||||
|
|
||||||
if ( yp < w )
|
if (yp < w) {
|
||||||
yp = w;
|
yp = w;
|
||||||
else if ( yp > height() - w )
|
} else if (yp > height() - w) {
|
||||||
yp = height() - w;
|
yp = height() - w;
|
||||||
|
}
|
||||||
|
|
||||||
d->px = xp;
|
d->px = xp;
|
||||||
d->py = yp;
|
d->py = yp;
|
||||||
|
@ -239,14 +250,15 @@ void KXYSelector::setPosition( int xp, int yp )
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KXYSelector::drawContents( QPainter * )
|
void KXYSelector::drawContents(QPainter *p)
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void KXYSelector::drawMarker( QPainter *p, int xp, int yp )
|
|
||||||
{
|
{
|
||||||
QPen pen( d->m_markerColor );
|
Q_UNUSED(p);
|
||||||
p->setPen( pen );
|
}
|
||||||
|
|
||||||
|
void KXYSelector::drawMarker(QPainter *p, int xp, int yp )
|
||||||
|
{
|
||||||
|
QPen pen(d->m_markerColor);
|
||||||
|
p->setPen(pen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
|
p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
#include <kdeui_export.h>
|
#include <kdeui_export.h>
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QWidget>
|
||||||
#include <QtGui/QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* KXYSelector is the base class for other widgets which
|
* KXYSelector is the base class for other widgets which
|
||||||
|
@ -37,15 +37,14 @@
|
||||||
class KDEUI_EXPORT KXYSelector : public QWidget
|
class KDEUI_EXPORT KXYSelector : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( int xValue READ xValue WRITE setXValue )
|
Q_PROPERTY(int xValue READ xValue WRITE setXValue)
|
||||||
Q_PROPERTY( int yValue READ yValue WRITE setYValue )
|
Q_PROPERTY(int yValue READ yValue WRITE setYValue)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructs a two-dimensional selector widget which
|
* Constructs a two-dimensional selector widget which
|
||||||
* has a value range of [0..100] in both directions.
|
* has a value range of [0..100] in both directions.
|
||||||
*/
|
*/
|
||||||
explicit KXYSelector( QWidget *parent=0 );
|
explicit KXYSelector(QWidget *parent = nullptr);
|
||||||
/**
|
/**
|
||||||
* Destructs the widget.
|
* Destructs the widget.
|
||||||
*/
|
*/
|
||||||
|
@ -57,30 +56,30 @@ public:
|
||||||
* @param xPos the horizontal value
|
* @param xPos the horizontal value
|
||||||
* @param yPos the vertical value
|
* @param yPos the vertical value
|
||||||
*/
|
*/
|
||||||
void setValues( int xPos, int yPos );
|
void setValues(int xPos, int yPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current horizontal value
|
* Sets the current horizontal value
|
||||||
* @param xPos the horizontal value
|
* @param xPos the horizontal value
|
||||||
*/
|
*/
|
||||||
void setXValue( int xPos );
|
void setXValue(int xPos );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current vertical value
|
* Sets the current vertical value
|
||||||
* @param yPos the vertical value
|
* @param yPos the vertical value
|
||||||
*/
|
*/
|
||||||
void setYValue( int yPos );
|
void setYValue(int yPos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the range of possible values.
|
* Sets the range of possible values.
|
||||||
*/
|
*/
|
||||||
void setRange( int minX, int minY, int maxX, int maxY );
|
void setRange(int minX, int minY, int maxX, int maxY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color used to draw the marker
|
* Sets the color used to draw the marker
|
||||||
* @param col the color
|
* @param col the color
|
||||||
*/
|
*/
|
||||||
void setMarkerColor( const QColor &col );
|
void setMarkerColor(const QColor &col);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current value in horizontal direction.
|
* @return the current value in horizontal direction.
|
||||||
|
@ -115,26 +114,26 @@ protected:
|
||||||
*
|
*
|
||||||
* Draw within contentsRect() only.
|
* Draw within contentsRect() only.
|
||||||
*/
|
*/
|
||||||
virtual void drawContents( QPainter * );
|
virtual void drawContents(QPainter *p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this function to draw the marker which
|
* Override this function to draw the marker which
|
||||||
* indicates the currently selected value pair.
|
* indicates the currently selected value pair.
|
||||||
*/
|
*/
|
||||||
virtual void drawMarker( QPainter *p, int xp, int yp );
|
virtual void drawMarker(QPainter *p, int xp, int yp);
|
||||||
|
|
||||||
virtual void paintEvent( QPaintEvent *e );
|
virtual void paintEvent(QPaintEvent *event);
|
||||||
virtual void mousePressEvent( QMouseEvent *e );
|
virtual void mousePressEvent(QMouseEvent *event);
|
||||||
virtual void mouseMoveEvent( QMouseEvent *e );
|
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||||
virtual void wheelEvent( QWheelEvent * );
|
virtual void wheelEvent(QWheelEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a pixel position to its corresponding values.
|
* Converts a pixel position to its corresponding values.
|
||||||
*/
|
*/
|
||||||
void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
|
void valuesFromPosition(int x, int y, int &xVal, int &yVal) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setPosition( int xp, int yp );
|
void setPosition(int xp, int yp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
|
|
Loading…
Add table
Reference in a new issue