initial commit
This commit is contained in:
parent
31feeff9aa
commit
4a3738759f
|
@ -45,6 +45,12 @@ SOURCES += \
|
|||
HEADERS += \
|
||||
Page.h
|
||||
|
||||
HEADERS += \
|
||||
slider/LinearGradientSlider.h \
|
||||
|
||||
SOURCES += \
|
||||
slider/LinearGradientSlider.cpp \
|
||||
|
||||
SOURCES += \
|
||||
Page.cpp \
|
||||
main.cpp
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#include "LinearGradientSlider.h"
|
||||
|
||||
#include <QskBoxBorderColors.h>
|
||||
#include <QskBoxBorderMetrics.h>
|
||||
|
||||
LinearGradientSlider::LinearGradientSlider( QQuickItem* parent )
|
||||
: LinearGradientSlider( Qt::Horizontal, parent )
|
||||
{
|
||||
}
|
||||
|
||||
LinearGradientSlider::LinearGradientSlider( Qt::Orientation orientation, QQuickItem* parent )
|
||||
: Inherited( orientation, parent )
|
||||
{
|
||||
const QVector< QskGradientStop > gradientStop = {
|
||||
{ 0.0000, QColor::fromRgb( 255, 0, 0 ) },
|
||||
{ 0.1667, QColor::fromRgb( 255, 255, 0 ) },
|
||||
{ 0.3333, QColor::fromRgb( 0, 255, 0 ) },
|
||||
{ 0.5000, QColor::fromRgb( 0, 255, 255 ) },
|
||||
{ 0.6667, QColor::fromRgb( 0, 0, 255 ) },
|
||||
{ 0.8333, QColor::fromRgb( 255, 0, 255 ) },
|
||||
{ 1.0000, QColor::fromRgb( 255, 0, 0 ) },
|
||||
};
|
||||
|
||||
const QskGradient gradient( orientation, gradientStop );
|
||||
setColor( Inherited::Fill, Qt::transparent );
|
||||
setGradientHint( Inherited::Groove, gradient );
|
||||
setBoxBorderColorsHint( Inherited::Handle, Qt::white );
|
||||
setBoxBorderMetricsHint( Inherited::Handle, 2 );
|
||||
|
||||
connect( this, &QskSlider::valueChanged, this, [ this, gradient ]( qreal value ) {
|
||||
value = this->orientation() == Qt::Horizontal ? value : 1.0 - value;
|
||||
const auto selectedColor = gradient.extracted( value, value ).startColor();
|
||||
setColor( Inherited::Handle, selectedColor );
|
||||
setSelectedColor( selectedColor );
|
||||
} );
|
||||
}
|
||||
|
||||
const QColor& LinearGradientSlider::selectedColor() const
|
||||
{
|
||||
return m_selectedColor;
|
||||
}
|
||||
|
||||
void LinearGradientSlider::setSelectedColor( const QColor& newSelectedColor )
|
||||
{
|
||||
if ( m_selectedColor == newSelectedColor )
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_selectedColor = newSelectedColor;
|
||||
Q_EMIT selectedColorChanged();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <QskSlider.h>
|
||||
|
||||
class LinearGradientSlider : public QskSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(
|
||||
QColor selectedColor READ selectedColor WRITE setSelectedColor NOTIFY selectedColorChanged )
|
||||
using Inherited = QskSlider;
|
||||
|
||||
public:
|
||||
explicit LinearGradientSlider( QQuickItem* parent = nullptr );
|
||||
explicit LinearGradientSlider( Qt::Orientation orientation, QQuickItem* parent = nullptr );
|
||||
const QColor& selectedColor() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setSelectedColor( const QColor& newSelectedColor );
|
||||
|
||||
Q_SIGNALS:
|
||||
void selectedColorChanged();
|
||||
|
||||
private:
|
||||
QColor m_selectedColor;
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "SliderPage.h"
|
||||
#include "LinearGradientSlider.h"
|
||||
#include <QskSlider.h>
|
||||
|
||||
namespace
|
||||
|
@ -50,4 +51,7 @@ void SliderPage::populate()
|
|||
{
|
||||
( void ) new Slider( Qt::Horizontal, this );
|
||||
( void ) new Slider( Qt::Vertical, this );
|
||||
|
||||
( void ) new LinearGradientSlider( Qt::Horizontal, this );
|
||||
( void ) new LinearGradientSlider( Qt::Vertical, this );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue