M(aterial)2 related code replaced

This commit is contained in:
Uwe Rathmann 2022-06-25 16:14:08 +02:00
parent 98368d42ac
commit 6c7ba0489c
15 changed files with 230 additions and 606 deletions

View File

@ -8,7 +8,7 @@
#include <QskBoxBorderColors.h>
#include <QskBoxBorderMetrics.h>
#include <QskBoxShapeMetrics.h>
#include <QskRgbPalette.h>
#include <QskHctColor.h>
Box::Box( QQuickItem* parentItem )
: QskBox( parentItem )
@ -22,7 +22,7 @@ Box::Box( QQuickItem* parentItem )
setGradientHint( QskBox::Panel, QskGradient() );
}
void Box::setBackground( FillType type, QskRgbPalette::Theme theme, bool inverted )
void Box::setBackground( FillType type, QGradient::Preset preset, bool inverted )
{
if ( type == Unfilled )
{
@ -30,59 +30,85 @@ void Box::setBackground( FillType type, QskRgbPalette::Theme theme, bool inverte
return;
}
const auto pal = QskRgbPalette::palette( theme );
QskGradient gradient( preset );
const QColor light = pal.color( QskRgbPalette::W300 );
const QColor mid = pal.color( QskRgbPalette::W600 );
switch ( type )
if ( type == Solid )
{
case Unfilled:
setGradient( QskGradient() );
break;
const auto& stops = gradient.stops();
case Solid:
setGradient( mid );
break;
const auto color = QskGradientStop::interpolated(
stops.first(), stops.last(), 0.5 );
default:
{
const auto orientation =
static_cast< QskGradient::Orientation >( type - 2 );
setGradient( QskGradient( color ) );
}
else
{
const auto orientation =
static_cast< QskGradient::Orientation >( type - 2 );
if ( inverted )
setGradient( orientation, mid, light );
else
setGradient( orientation, light, mid );
}
gradient.setOrientation( orientation );
if ( inverted )
gradient.reverse();
setGradient( gradient );
}
}
void Box::setBorder( BorderType type, QskRgbPalette::Theme theme )
void Box::setBackground( FillType type, const QRgb base, bool inverted )
{
const auto pal = QskRgbPalette::palette( theme );
if ( type == Unfilled )
{
setGradient( QskGradient() );
return;
}
double hue, chroma;
QskHctColor::getHueAndChroma( base, hue, chroma );
if ( type == Solid )
{
setGradient( QskHctColor::rgb( hue, chroma, 50 ) );
}
else
{
const auto dark = QskHctColor::rgb( hue, chroma, 40 );
const auto light = QskHctColor::rgb( hue, chroma, 70 );
const auto orientation =
static_cast< QskGradient::Orientation >( type - 2 );
if ( inverted )
setGradient( orientation, dark, light );
else
setGradient( orientation, light, dark );
}
}
void Box::setBorder( BorderType type, const QRgb base )
{
setBorderWidth( 5 );
QColor dark = pal.color( QskRgbPalette::W700 );
QColor mid = pal.color( QskRgbPalette::W500 );
QColor light = pal.color( QskRgbPalette::W300 );
#if 0
dark.setAlpha( 100 );
mid.setAlpha( 100 );
light.setAlpha( 100 );
#endif
switch ( type )
switch ( static_cast< int >( type ) )
{
case NoBorder:
setBorderWidth( 0 );
break;
return;
case Flat:
setBorderGradient( mid );
break;
setBorderGradient( base );
return;
}
double hue, chroma;
QskHctColor::getHueAndChroma( base, hue, chroma );
const auto dark = QskHctColor::rgb( hue, chroma, 40 );
const auto mid = QskHctColor::rgb( hue, chroma, 65 );
const auto light = QskHctColor::rgb( hue, chroma, 90 );
switch ( static_cast< int >( type ) )
{
case Raised1:
setBorderGradients( light, light, dark, dark );
break;
@ -178,8 +204,19 @@ void Box::setGradient( const QskGradient& gradient )
}
void Box::setGradient(
const QskGradient::Orientation orientation, QskRgbPalette::Theme theme )
const QskGradient::Orientation orientation, const QRgb base )
{
const auto pal = QskRgbPalette::palette( theme );
setGradient( QskGradient( orientation, pal.colorStops( true ) ) );
double hue, chroma;
QskHctColor::getHueAndChroma( base, hue, chroma );
QVector< QRgb > rgb;
rgb.reserve( 10 );
for ( int i = 0; i < 10; i++ )
{
const auto tone = 90 - i * 7;
rgb += QskHctColor::rgb( hue, chroma, tone );
}
setGradient( QskGradient( orientation, QskGradient::colorStops( rgb, true ) ) );
}

View File

@ -5,7 +5,6 @@
#pragma once
#include <QskRgbPalette.h>
#include <QskBox.h>
class Box : public QskBox
@ -32,8 +31,10 @@ class Box : public QskBox
Box( QQuickItem* parentItem = nullptr );
void setBackground( FillType, QskRgbPalette::Theme, bool inverted = false );
void setBorder( BorderType type, QskRgbPalette::Theme );
void setBackground( FillType, QRgb, bool inverted = false );
void setBackground( FillType, QGradient::Preset, bool inverted = false );
void setBorder( BorderType type, QRgb );
void setShape( const QskBoxShapeMetrics& );
void setShape( qreal radius, Qt::SizeMode );
@ -55,6 +56,6 @@ class Box : public QskBox
void setGradient( QskGradient::Orientation,
const QColor&, const QColor&, const QColor& );
void setGradient( const QskGradient& gradient );
void setGradient( const QskGradient::Orientation, QskRgbPalette::Theme );
void setGradient( const QskGradient& );
void setGradient( const QskGradient::Orientation, QRgb );
};

View File

@ -21,6 +21,18 @@
#include <QGuiApplication>
namespace
{
// Some leftover definitions from M(aterial)2. TODO ...
constexpr const QRgb Grey400 = 0xffbdbdbd;
constexpr const QRgb Grey500 = 0xff9e9e9e;
constexpr const QRgb Lime200 = 0xffe6ee9c;
constexpr const QRgb Lime300 = 0xffdce775;
constexpr const QRgb Lime600 = 0xffc0ca33;
}
class MyRectangle : public Box
{
public:
@ -55,7 +67,7 @@ static void addTestRectangle( QskLinearBox* parent )
auto box = new Box( parent );
box->setMargins( 50 );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setBorder( Box::Flat, QskRgb::OrangeRed );
box->setBorderWidth( 10, 20, 40, 20 );
QskBoxShapeMetrics shape( 50, Qt::RelativeSize );
@ -63,7 +75,7 @@ static void addTestRectangle( QskLinearBox* parent )
shape.setRadius( Qt::TopRightCorner, 70 );
box->setShape( shape );
box->setGradient( QskGradient::Diagonal, QskRgbPalette::Blue );
box->setGradient( QskGradient::Diagonal, QskRgb::DodgerBlue );
}
static void addRectangles1( QskLinearBox* parent )
@ -72,7 +84,7 @@ static void addRectangles1( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* rectangle = new MyRectangle( parent );
rectangle->setBackground( type, QskRgbPalette::Teal );
rectangle->setBackground( type, QskRgb::Teal );
}
}
@ -82,8 +94,8 @@ static void addRectangles2( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* rectangle = new MyRectangle( parent );
rectangle->setBorder( Box::Flat, QskRgbPalette::Brown );
rectangle->setBackground( type, QskRgbPalette::Yellow );
rectangle->setBorder( Box::Flat, QskRgb::SaddleBrown );
rectangle->setBackground( type, QGradient::SunnyMorning );
}
}
@ -91,8 +103,7 @@ static void addRectangles3( QskLinearBox* parent )
{
using namespace QskRgb;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Blue;
const auto borderTheme = QskRgb::LightGray;
Box* box;
@ -110,11 +121,11 @@ static void addRectangles3( QskLinearBox* parent )
box = new MyRectangle( parent );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box->setBackground( Box::Vertical, QGradient::RiverCity, true );
box = new MyRectangle( parent );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
box->setBackground( Box::Vertical, QGradient::RiverCity, false );
}
static void addRectangles4( QskLinearBox* parent )
@ -123,7 +134,7 @@ static void addRectangles4( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyRoundedRectangle( parent );
box->setBackground( type, QskRgbPalette::DeepOrange );
box->setBackground( type, QskRgb::OrangeRed );
}
}
@ -133,8 +144,8 @@ static void addRectangles5( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyRoundedRectangle( parent );
box->setBorder( Box::Flat, QskRgbPalette::Indigo );
box->setBackground( type, QskRgbPalette::Pink );
box->setBorder( Box::Flat, QskRgb::RoyalBlue );
box->setBackground( type, QskRgb::DeepPink );
}
}
@ -142,8 +153,7 @@ static void addRectangles6( QskLinearBox* parent )
{
using namespace QskRgb;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Lime;
const auto borderTheme = QskRgb::LightGrey;
Box* box;
@ -161,11 +171,11 @@ static void addRectangles6( QskLinearBox* parent )
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box->setGradient( QskGradient::Vertical, Lime300, Lime600 );
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
box->setGradient( QskGradient::Vertical, Lime600, Lime300 );
}
static void addRectangles7( QskLinearBox* parent )
@ -174,7 +184,7 @@ static void addRectangles7( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyEllipse( parent );
box->setBackground( type, QskRgbPalette::BlueGrey );
box->setBackground( type, QskRgb::SlateGrey );
}
}
@ -184,8 +194,8 @@ static void addRectangles8( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyEllipse( parent );
box->setBorder( Box::Flat, QskRgbPalette::Indigo );
box->setBackground( type, QskRgbPalette::Red );
box->setBorder( Box::Flat, QskRgb::RoyalBlue );
box->setBackground( type, QskRgb::FireBrick );
}
}
@ -193,8 +203,7 @@ static void addRectangles9( QskLinearBox* parent )
{
using namespace QskRgb;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Lime;
const auto borderTheme = QskRgb::LightGrey;
Box* box;
@ -212,11 +221,11 @@ static void addRectangles9( QskLinearBox* parent )
box = new MyEllipse( parent );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box->setGradient( QskGradient::Vertical, Lime200, Lime600 );
box = new MyEllipse( parent );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
box->setGradient( QskGradient::Vertical, Lime600, Lime200 );
}
static void addRectangles10( QskLinearBox* parent )
@ -263,14 +272,14 @@ static void addRectangles11( QskLinearBox* parent )
{
auto box = new MyRectangle( parent );
box->setBorder( Box::Flat, QskRgbPalette::Teal );
box->setBorder( Box::Flat, QskRgb::Teal );
qreal bw[ 4 ] = { border, border, border, border };
if ( i != 0 )
bw[ i - 1 ] = 0;
box->setBorderWidth( bw[ 0 ], bw[ 1 ], bw[ 2 ], bw[ 3 ] );
box->setBackground( fillType[ i ], QskRgbPalette::Brown, i >= 3 );
box->setBackground( fillType[ i ], QskRgb::Sienna, i >= 3 );
}
}
@ -281,14 +290,14 @@ static void addRectangles12( QskLinearBox* parent )
{
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setGradient( orientation, QskRgbPalette::Brown );
box->setGradient( orientation, QskRgb::LightSlateGray );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setGradient( orientation, QskRgbPalette::Blue );
box->setBorder( Box::Flat, QskRgb::OrangeRed );
box->setGradient( orientation, QskRgb::DodgerBlue );
}
for ( auto orientation : { QskGradient::Vertical,
@ -297,15 +306,15 @@ static void addRectangles12( QskLinearBox* parent )
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setShape( 30, 40, Qt::RelativeSize );
box->setGradient( orientation, QskRgbPalette::Brown );
box->setGradient( orientation, QskRgb::LightSlateGray );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setBorder( Box::Flat, QskRgb::OrangeRed );
box->setShape( 30, 40, Qt::RelativeSize );
box->setGradient( orientation, QskRgbPalette::Blue );
box->setGradient( orientation, QskRgb::DodgerBlue );
}
for ( auto orientation : { QskGradient::Vertical,
@ -314,15 +323,15 @@ static void addRectangles12( QskLinearBox* parent )
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setShape( 100, 100, Qt::RelativeSize );
box->setGradient( orientation, QskRgbPalette::Brown );
box->setGradient( orientation, QskRgb::LightSlateGray );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setBorder( Box::Flat, QskRgb::OrangeRed );
box->setShape( 100, 100, Qt::RelativeSize );
box->setGradient( orientation, QskRgbPalette::Blue );
box->setGradient( orientation, QskRgb::DodgerBlue );
}
}
@ -374,7 +383,7 @@ static void addColoredBorderRectangles1( QskLinearBox* parent, bool rounded, Box
box->setBorderGradients( gradient1, gradient2, gradient3, gradient4 );
if( fillType != Box::Unfilled )
box->setBackground( fillType, QskRgbPalette::Indigo );
box->setBackground( fillType, QskRgb::CornflowerBlue );
if( rounded )
box->setShape( 30, Qt::AbsoluteSize );
@ -387,7 +396,7 @@ static void addColoredBorderRectangles2( QskLinearBox* parent, bool rounded, Box
box->setBorderGradients( Qt::red, Qt::green, Qt::blue, Qt::yellow );
if( fillType != Box::Unfilled )
box->setBackground( fillType, QskRgbPalette::Indigo );
box->setBackground( fillType, QskRgb::CornflowerBlue );
if( rounded )
box->setShape( 30, Qt::AbsoluteSize );
@ -416,7 +425,7 @@ static void addColoredBorderRectangles3( QskLinearBox* parent, bool rounded, Box
box->setBorderGradients( gradient3, gradient3, gradient3, gradient3 );
if( fillType != Box::Unfilled )
box->setBackground( fillType, QskRgbPalette::Indigo );
box->setBackground( fillType, QskRgb::CornflowerBlue );
if( rounded )
box->setShape( 30, Qt::AbsoluteSize );
@ -430,7 +439,7 @@ static void addColoredBorderRectangles4( QskLinearBox* parent, bool rounded, Box
box->setBorderGradients( gradient, gradient, gradient, gradient );
if( fillType != Box::Unfilled )
box->setBackground( fillType, QskRgbPalette::Indigo );
box->setBackground( fillType, QskRgb::CornflowerBlue );
if( rounded )
box->setShape( 30, Qt::AbsoluteSize );
@ -447,7 +456,7 @@ static void addColoredBorderRectangles5( QskLinearBox* parent, bool rounded, Box
box->setBorderGradients( gradient, gradient, gradient, gradient );
if( fillType != Box::Unfilled )
box->setBackground( fillType, QskRgbPalette::Indigo );
box->setBackground( fillType, QskRgb::CornflowerBlue );
if( rounded )
box->setShape( { 10, 20, 20, 40 } );

View File

@ -8,7 +8,7 @@
#include <QskGraphicProvider.h>
#include <QskGraphic.h>
#include <QskGradient.h>
#include <QskRgbPalette.h>
#include <QskHctColor.h>
#include <QskRgbValue.h>
namespace
@ -25,17 +25,18 @@ namespace
setBoundaries( 0, 100 );
}
void setTheme( QskRgbPalette::Theme theme )
void setTheme( const QRgb base )
{
const auto pal = QskRgbPalette::palette( theme );
double hue, chroma;
QskHctColor::getHueAndChroma( base, hue, chroma );
QVector< QRgb > rgb;
rgb += pal.rgb( QskRgbPalette::W200 );
rgb += pal.rgb( QskRgbPalette::W400 );
rgb += pal.rgb( QskRgbPalette::W600 );
rgb += pal.rgb( QskRgbPalette::W900 );
rgb += QskHctColor::rgb( hue, chroma, 75 );
rgb += QskHctColor::rgb( hue, chroma, 60 );
rgb += QskHctColor::rgb( hue, chroma, 45 );
rgb += QskHctColor::rgb( hue, chroma, 30 );
const auto stops = QskRgbPalette::colorStops( rgb, true );
const auto stops = QskGradient::colorStops( rgb, true );
setBarGradient( QskGradient( orientation(), stops ) );
}
@ -62,19 +63,19 @@ void ProgressBarPage::populate()
{
auto bar = new ProgressBar( hBox );
bar->setTheme( QskRgbPalette::BlueGrey );
bar->setTheme( QskRgb::LightSteelBlue );
bar->setValue( 100 );
}
{
auto bar = new ProgressBar( hBox );
bar->setTheme( QskRgbPalette::Blue );
bar->setTheme( QskRgb::DodgerBlue );
bar->setValue( 75 );
}
{
auto bar = new ProgressBar( hBox );
bar->setTheme( QskRgbPalette::Blue );
bar->setTheme( QskRgb::DodgerBlue );
bar->setOrigin( 60 );
bar->setValue( 25 );
}
@ -90,20 +91,20 @@ void ProgressBarPage::populate()
{
auto bar = new ProgressBar( vBox );
bar->setTheme( QskRgbPalette::DeepOrange );
bar->setTheme( QskRgb::OrangeRed );
bar->setValue( 100 );
}
{
auto bar = new ProgressBar( vBox );
bar->setTheme( QskRgbPalette::Pink );
bar->setTheme( QskRgb::DeepPink );
bar->setMaximum( 40 );
bar->setValue( 25 );
}
{
auto bar = new ProgressBar( vBox );
bar->setTheme( QskRgbPalette::Pink );
bar->setTheme( QskRgb::DeepPink );
bar->setOrigin( 40 );
bar->setValue( 10 );
}

View File

@ -26,17 +26,17 @@ CustomSlider::CustomSlider( QQuickItem* parentItem )
QskSkinHintTableEditor ed( &hintTable() );
ed.setBoxShape( Fill, 0 );
ed.setGradient( Fill, Grey700 );
ed.setGradient( Fill, QskRgb::DimGray );
ed.setColor( Scale, qRgb( 178, 178, 178 ) ); // for the ticks
ed.setStrutSize( Handle, 80, 80 );
ed.setColor( Handle, Grey800 );
ed.setColor( Handle, QskRgb::DimGray );
ed.setColor( Handle | Pressed, Orange600 );
ed.setColor( Handle | Pressed, QskRgb::Orange );
const auto combinationMask = Focused | Hovered;
ed.setColor( Handle, Orange600, combinationMask );
ed.setColor( Handle, QskRgb::Orange, combinationMask );
ed.setAnimation( Handle | QskAspect::Color, 300, combinationMask );
ed.setAnimation( Handle | QskAspect::Color, 1000 );

View File

@ -307,7 +307,7 @@ QSGNode* CustomSliderSkinlet::updateDecorationNode(
labelNode = QskSkinlet::updateTextNode( slider, labelNode,
QRectF( x - 0.5 * w, y, w, h ), Qt::AlignHCenter, text, qskLabelFont,
QskTextOptions(), QskTextColors( QskRgb::Grey700 ), Qsk::Normal );
QskTextOptions(), QskTextColors( QskRgb::DimGray ), Qsk::Normal );
if ( labelNode )
{

View File

@ -37,8 +37,8 @@ OtherSlider::OtherSlider( QQuickItem* parentItem )
ed.setMetric( aspect | A::Size, h );
ed.setBoxShape( aspect, 4 );
ed.setBoxBorderMetrics( aspect, 1 );
ed.setBoxBorderColors( aspect, Grey900 );
ed.setGradient( aspect, Grey400 );
ed.setBoxBorderColors( aspect, DimGray );
ed.setGradient( aspect, Silver );
if ( placement == A::Horizontal )
ed.setPadding( aspect, QskMargins( paddingW, 0 ) );
@ -84,8 +84,8 @@ OtherSlider::OtherSlider( QQuickItem* parentItem )
for ( auto state : { A::NoState, Pressed } )
{
ed.setBoxBorderColors( aspect | state, Grey600 );
ed.setGradient( aspect | state, Blue400 );
ed.setBoxBorderColors( aspect | state, SlateGrey );
ed.setGradient( aspect | state, DodgerBlue );
}
}
}

View File

@ -61,11 +61,21 @@ static inline QColor qskShadedColor( const QColor color, qreal opacity )
namespace
{
#if 1
// temporary definitions, will be removed when moving to M(aterial)3
constexpr const QRgb Grey100 = 0xfff5f5f5;
constexpr const QRgb Grey300 = 0xffe0e0e0;
constexpr const QRgb Grey400 = 0xffbdbdbd;
constexpr const QRgb Grey500 = 0xff9e9e9e;
constexpr const QRgb Grey600 = 0xff757575;
constexpr const QRgb Blue500 = 0xff2196f3;
#endif
class ColorPalette
{
public:
ColorPalette( const QColor base = QColor::fromRgba( QskRgb::Grey100 ),
const QColor& accent = QColor::fromRgba( QskRgb::Blue500 ),
ColorPalette( const QColor base = QColor::fromRgba( Grey100 ),
const QColor& accent = QColor::fromRgba( Blue500 ),
const QColor& contrast = QColor::fromRgba( QskRgb::White ) )
{
baseColor = base;
@ -910,8 +920,7 @@ QskMaterialSkin::QskMaterialSkin( QObject* parent )
: Inherited( parent )
, m_data( new PrivateData() )
{
m_data->palette = ColorPalette( QskRgb::Grey100,
QskRgb::Blue500, QskRgb::White );
m_data->palette = ColorPalette( Grey100, Blue500, QskRgb::White );
// Default theme colors
setupFonts( QStringLiteral( "Roboto" ) );

View File

@ -89,7 +89,7 @@ namespace
contrasted = DarkGrey;
contrastedText = White;
highlighted = BlueGrey500;
highlighted = SlateGrey;
highlightedText = White;
base = Black;

View File

@ -194,6 +194,42 @@ static inline QskGradientStops qskGradientStops( const QGradientStops& qtStops )
return stops;
}
static inline QskGradientStops qskColorStops(
const QRgb* rgb, int count, bool discrete )
{
QskGradientStops stops;
if ( discrete )
stops.reserve( 2 * count - 2 );
else
stops.reserve( count );
stops += QskGradientStop( 0.0, rgb[0] );
if ( discrete )
{
const auto step = 1.0 / count;
for ( int i = 1; i < count; i++ )
{
const qreal pos = i * step;
stops += QskGradientStop( pos, rgb[i - 1] );
stops += QskGradientStop( pos, rgb[i] );
}
}
else
{
const auto step = 1.0 / ( count - 1 );
for ( int i = 1; i < count - 1; i++ )
stops += QskGradientStop( i * step, rgb[i] );
}
stops += QskGradientStop( 1.0, rgb[count - 1] );
return stops;
}
QskGradient::QskGradient( Orientation orientation )
: m_orientation( orientation )
, m_isDirty( false )
@ -635,6 +671,28 @@ void QskGradient::updateStatusBits() const
m_isDirty = false;
}
QskGradientStops QskGradient::colorStops(
const QVector< QRgb >& rgb, bool discrete )
{
const int count = rgb.count();
if ( count == 0 )
return QskGradientStops();
if ( count == 0 )
{
QskGradientStops stops;
stops.reserve( 2 );
stops += QskGradientStop( 0.0, rgb[0] );
stops += QskGradientStop( 1.0, rgb[0] );
return stops;
}
return qskColorStops( rgb.constData(), count, discrete );
}
#ifndef QT_NO_DEBUG_STREAM
#include <qdebug.h>

View File

@ -103,6 +103,9 @@ class QSK_EXPORT QskGradient
Q_INVOKABLE QColor colorAt( int index ) const;
Q_INVOKABLE int stopCount() const;
static QskGradientStops colorStops(
const QVector< QRgb >&, bool discrete = false );
private:
void setStopAt( int index, qreal stop );
void setColorAt( int index, const QColor& color );

View File

@ -1,130 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskRgbPalette.h"
#include "QskRgbValue.h"
#include "QskGradient.h"
#define RGB( color, weight ) color ## weight
#define RGBTABLE( c ) \
{ \
RGB( c, 50 ), RGB( c, 100 ), RGB( c, 200 ), RGB( c, 300 ), RGB( c, 400 ), \
RGB( c, 500 ), RGB( c, 600 ), RGB( c, 700 ), RGB( c, 800 ), RGB( c, 900 ) \
}
namespace
{
class Palette : public QskRgbPalette
{
public:
Palette( int index )
{
using namespace QskRgb;
static constexpr QRgb table[][ Palette::NumWeights ] =
{
RGBTABLE( Red ),
RGBTABLE( Pink ),
RGBTABLE( Purple ),
RGBTABLE( DeepPurple ),
RGBTABLE( Indigo ),
RGBTABLE( Blue ),
RGBTABLE( LightBlue ),
RGBTABLE( Cyan ),
RGBTABLE( Teal ),
RGBTABLE( Green ),
RGBTABLE( LightGreen ),
RGBTABLE( Lime ),
RGBTABLE( Yellow ),
RGBTABLE( Amber ),
RGBTABLE( Orange ),
RGBTABLE( DeepOrange ),
RGBTABLE( Brown ),
RGBTABLE( Grey ),
RGBTABLE( BlueGrey ),
};
const int count = sizeof( table ) / sizeof( table[ 0 ] );
m_rgb = table[ qBound( 0, index, count ) ];
}
};
}
QskRgbPalette QskRgbPalette::palette( Theme theme )
{
return Palette( static_cast< int >( theme ) );
}
static QskGradientStops qskColorStops(
const QRgb* rgb, int count, bool discrete )
{
QskGradientStops stops;
if ( discrete )
stops.reserve( 2 * count - 2 );
else
stops.reserve( count );
stops += QskGradientStop( 0.0, rgb[0] );
if ( discrete )
{
const auto step = 1.0 / count;
for ( int i = 1; i < count; i++ )
{
const qreal pos = i * step;
stops += QskGradientStop( pos, rgb[i - 1] );
stops += QskGradientStop( pos, rgb[i] );
}
}
else
{
const auto step = 1.0 / ( count - 1 );
for ( int i = 1; i < count - 1; i++ )
stops += QskGradientStop( i * step, rgb[i] );
}
stops += QskGradientStop( 1.0, rgb[count - 1] );
return stops;
}
QskGradientStops QskRgbPalette::colorStops( bool discrete ) const
{
return qskColorStops( m_rgb, NumWeights, discrete );
}
QskGradientStops QskRgbPalette::colorStops( Theme theme, bool discrete )
{
const auto pal = QskRgbPalette::palette( theme );
return pal.colorStops( discrete );
}
QskGradientStops QskRgbPalette::colorStops(
const QVector< QRgb >& rgb, bool discrete )
{
const int count = rgb.count();
if ( count == 0 )
return QskGradientStops();
if ( count == 0 )
{
QskGradientStops stops;
stops.reserve( 2 );
stops += QskGradientStop( 0.0, rgb[0] );
stops += QskGradientStop( 1.0, rgb[0] );
return stops;
}
return qskColorStops( rgb.constData(), count, discrete );
}
#include "moc_QskRgbPalette.cpp"

View File

@ -1,89 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_RGB_PALETTE_H
#define QSK_RGB_PALETTE_H
#include "QskGlobal.h"
#include "QskGradient.h"
#include <qmetaobject.h>
#include <qcolor.h>
class QSK_EXPORT QskRgbPalette
{
Q_GADGET
public:
enum Weight
{
W50,
W100,
W200,
W300,
W400,
W500,
W600,
W700,
W800,
W900,
NumWeights
};
Q_ENUM( Weight )
enum Theme
{
Red,
Pink,
Purple,
DeepPurple,
Indigo,
Blue,
LightBlue,
Cyan,
Teal,
Green,
LightGreen,
Lime,
Yellow,
Amber,
Orange,
DeepOrange,
Brown,
Grey,
BlueGrey,
NumThemes
};
Q_ENUM( Theme )
static QskRgbPalette palette( Theme );
inline QRgb rgb( Weight weight ) const
{
if ( weight < 0 || weight >= NumWeights )
return 0;
return m_rgb[ weight ];
}
inline QColor color( Weight weight ) const
{
return QColor::fromRgba( rgb( weight ) );
}
QskGradientStops colorStops( bool discrete = false ) const;
static QskGradientStops colorStops( Theme, bool discrete = false );
static QskGradientStops colorStops(
const QVector< QRgb >&, bool discrete = false );
protected:
const QRgb* m_rgb;
};
#endif

View File

@ -157,279 +157,6 @@
RGBVALUE( Yellow, 0xffffff00 ) \
RGBVALUE( YellowGreen, 0xff9acd32 ) \
RGBVALUE( White, 0xffffffff ) \
/* Material colors from https://material.google.com/style/color.html */ \
RGBVALUE( Red50, 0xffffebee ) \
RGBVALUE( Red100, 0xffffcdd2 ) \
RGBVALUE( Red200, 0xffef9a9a ) \
RGBVALUE( Red300, 0xffe57373 ) \
RGBVALUE( Red400, 0xffef5350 ) \
RGBVALUE( Red500, 0xfff44336 ) \
RGBVALUE( Red600, 0xffe53935 ) \
RGBVALUE( Red700, 0xffd32f2f ) \
RGBVALUE( Red800, 0xffc62828 ) \
RGBVALUE( Red900, 0xffb71c1c ) \
RGBVALUE( RedA100, 0xffff8a80 ) \
RGBVALUE( RedA200, 0xffff5252 ) \
RGBVALUE( RedA400, 0xffff1744 ) \
RGBVALUE( RedA700, 0xffd50000 ) \
\
RGBVALUE( Pink50, 0xfffce4ec ) \
RGBVALUE( Pink100, 0xfff8bbd0 ) \
RGBVALUE( Pink200, 0xfff48fb1 ) \
RGBVALUE( Pink300, 0xfff06292 ) \
RGBVALUE( Pink400, 0xffec407a ) \
RGBVALUE( Pink500, 0xffe91e63 ) \
RGBVALUE( Pink600, 0xffd81b60 ) \
RGBVALUE( Pink700, 0xffc2185b ) \
RGBVALUE( Pink800, 0xffad1457 ) \
RGBVALUE( Pink900, 0xff880e4f ) \
RGBVALUE( PinkA100, 0xffff80ab ) \
RGBVALUE( PinkA200, 0xffff4081 ) \
RGBVALUE( PinkA400, 0xfff50057 ) \
RGBVALUE( PinkA700, 0xffc51162 ) \
\
RGBVALUE( Purple50, 0xfff3e5f5 ) \
RGBVALUE( Purple100, 0xffe1bee7 ) \
RGBVALUE( Purple200, 0xffce93d8 ) \
RGBVALUE( Purple300, 0xffba68c8 ) \
RGBVALUE( Purple400, 0xffab47bc ) \
RGBVALUE( Purple500, 0xff9c27b0 ) \
RGBVALUE( Purple600, 0xff8e24aa ) \
RGBVALUE( Purple700, 0xff7b1fa2 ) \
RGBVALUE( Purple800, 0xff6a1b9a ) \
RGBVALUE( Purple900, 0xff4a148c ) \
RGBVALUE( PurpleA100, 0xffea80fc ) \
RGBVALUE( PurpleA200, 0xffe040fb ) \
RGBVALUE( PurpleA400, 0xffd500f9 ) \
RGBVALUE( PurpleA700, 0xffaa00ff ) \
\
RGBVALUE( DeepPurple50, 0xffede7f6 ) \
RGBVALUE( DeepPurple100, 0xffd1c4e9 ) \
RGBVALUE( DeepPurple200, 0xffb39ddb ) \
RGBVALUE( DeepPurple300, 0xff9575cd ) \
RGBVALUE( DeepPurple400, 0xff7e57c2 ) \
RGBVALUE( DeepPurple500, 0xff673ab7 ) \
RGBVALUE( DeepPurple600, 0xff5e35b1 ) \
RGBVALUE( DeepPurple700, 0xff512da8 ) \
RGBVALUE( DeepPurple800, 0xff4527a0 ) \
RGBVALUE( DeepPurple900, 0xff311b92 ) \
RGBVALUE( DeepPurpleA100, 0xffb388ff ) \
RGBVALUE( DeepPurpleA200, 0xff7c4dff ) \
RGBVALUE( DeepPurpleA400, 0xff651fff ) \
RGBVALUE( DeepPurpleA700, 0xff6200ea ) \
\
RGBVALUE( Indigo50, 0xffe8eaf6 ) \
RGBVALUE( Indigo100, 0xffc5cae9 ) \
RGBVALUE( Indigo200, 0xff9fa8da ) \
RGBVALUE( Indigo300, 0xff7986cb ) \
RGBVALUE( Indigo400, 0xff5c6bc0 ) \
RGBVALUE( Indigo500, 0xff3f51b5 ) \
RGBVALUE( Indigo600, 0xff3949ab ) \
RGBVALUE( Indigo700, 0xff303f9f ) \
RGBVALUE( Indigo800, 0xff283593 ) \
RGBVALUE( Indigo900, 0xff1a237e ) \
RGBVALUE( IndigoA100, 0xff8c9eff ) \
RGBVALUE( IndigoA200, 0xff536dfe ) \
RGBVALUE( IndigoA400, 0xff3d5afe ) \
RGBVALUE( IndigoA700, 0xff304ffe ) \
\
RGBVALUE( Blue50, 0xffe3f2fd ) \
RGBVALUE( Blue100, 0xffbbdefb ) \
RGBVALUE( Blue200, 0xff90caf9 ) \
RGBVALUE( Blue300, 0xff64b5f6 ) \
RGBVALUE( Blue400, 0xff42a5f5 ) \
RGBVALUE( Blue500, 0xff2196f3 ) \
RGBVALUE( Blue600, 0xff1e88e5 ) \
RGBVALUE( Blue700, 0xff1976d2 ) \
RGBVALUE( Blue800, 0xff1565c0 ) \
RGBVALUE( Blue900, 0xff0d47a1 ) \
RGBVALUE( BlueA100, 0xff82b1ff ) \
RGBVALUE( BlueA200, 0xff448aff ) \
RGBVALUE( BlueA400, 0xff2979ff ) \
RGBVALUE( BlueA700, 0xff2962ff ) \
\
RGBVALUE( LightBlue50, 0xffe1f5fe ) \
RGBVALUE( LightBlue100, 0xffb3e5fc ) \
RGBVALUE( LightBlue200, 0xff81d4fa ) \
RGBVALUE( LightBlue300, 0xff4fc3f7 ) \
RGBVALUE( LightBlue400, 0xff29b6f6 ) \
RGBVALUE( LightBlue500, 0xff03a9f4 ) \
RGBVALUE( LightBlue600, 0xff039be5 ) \
RGBVALUE( LightBlue700, 0xff0288d1 ) \
RGBVALUE( LightBlue800, 0xff0277bd ) \
RGBVALUE( LightBlue900, 0xff01579b ) \
RGBVALUE( LightBlueA100, 0xff80d8ff ) \
RGBVALUE( LightBlueA200, 0xff40c4ff ) \
RGBVALUE( LightBlueA400, 0xff00b0ff ) \
RGBVALUE( LightBlueA700, 0xff0091ea ) \
\
RGBVALUE( Cyan50, 0xffe0f7fa ) \
RGBVALUE( Cyan100, 0xffb2ebf2 ) \
RGBVALUE( Cyan200, 0xff80deea ) \
RGBVALUE( Cyan300, 0xff4dd0e1 ) \
RGBVALUE( Cyan400, 0xff26c6da ) \
RGBVALUE( Cyan500, 0xff00bcd4 ) \
RGBVALUE( Cyan600, 0xff00acc1 ) \
RGBVALUE( Cyan700, 0xff0097a7 ) \
RGBVALUE( Cyan800, 0xff00838f ) \
RGBVALUE( Cyan900, 0xff006064 ) \
RGBVALUE( CyanA100, 0xff84ffff ) \
RGBVALUE( CyanA200, 0xff18ffff ) \
RGBVALUE( CyanA400, 0xff00e5ff ) \
RGBVALUE( CyanA700, 0xff00b8d4 ) \
\
RGBVALUE( Teal50, 0xffe0f2f1 ) \
RGBVALUE( Teal100, 0xffb2dfdb ) \
RGBVALUE( Teal200, 0xff80cbc4 ) \
RGBVALUE( Teal300, 0xff4db6ac ) \
RGBVALUE( Teal400, 0xff26a69a ) \
RGBVALUE( Teal500, 0xff009688 ) \
RGBVALUE( Teal600, 0xff00897b ) \
RGBVALUE( Teal700, 0xff00796b ) \
RGBVALUE( Teal800, 0xff00695c ) \
RGBVALUE( Teal900, 0xff004d40 ) \
RGBVALUE( TealA100, 0xffa7ffeb ) \
RGBVALUE( TealA200, 0xff64ffda ) \
RGBVALUE( TealA400, 0xff1de9b6 ) \
RGBVALUE( TealA700, 0xff00bfa5 ) \
\
RGBVALUE( Green50, 0xffe8f5e9 ) \
RGBVALUE( Green100, 0xffc8e6c9 ) \
RGBVALUE( Green200, 0xffa5d6a7 ) \
RGBVALUE( Green300, 0xff81c784 ) \
RGBVALUE( Green400, 0xff66bb6a ) \
RGBVALUE( Green500, 0xff4caf50 ) \
RGBVALUE( Green600, 0xff43a047 ) \
RGBVALUE( Green700, 0xff388e3c ) \
RGBVALUE( Green800, 0xff2e7d32 ) \
RGBVALUE( Green900, 0xff1b5e20 ) \
RGBVALUE( GreenA100, 0xffb9f6ca ) \
RGBVALUE( GreenA200, 0xff69f0ae ) \
RGBVALUE( GreenA400, 0xff00e676 ) \
RGBVALUE( GreenA700, 0xff00c853 ) \
\
RGBVALUE( LightGreen50, 0xfff1f8e9 ) \
RGBVALUE( LightGreen100, 0xffdcedc8 ) \
RGBVALUE( LightGreen200, 0xffc5e1a5 ) \
RGBVALUE( LightGreen300, 0xffaed581 ) \
RGBVALUE( LightGreen400, 0xff9ccc65 ) \
RGBVALUE( LightGreen500, 0xff8bc34a ) \
RGBVALUE( LightGreen600, 0xff7cb342 ) \
RGBVALUE( LightGreen700, 0xff689f38 ) \
RGBVALUE( LightGreen800, 0xff558b2f ) \
RGBVALUE( LightGreen900, 0xff33691e ) \
RGBVALUE( LightGreenA100, 0xffccff90 ) \
RGBVALUE( LightGreenA200, 0xffb2ff59 ) \
RGBVALUE( LightGreenA400, 0xff76ff03 ) \
RGBVALUE( LightGreenA700, 0xff64dd17 ) \
\
RGBVALUE( Lime50, 0xfff9fbe7 ) \
RGBVALUE( Lime100, 0xfff0f4c3 ) \
RGBVALUE( Lime200, 0xffe6ee9c ) \
RGBVALUE( Lime300, 0xffdce775 ) \
RGBVALUE( Lime400, 0xffd4e157 ) \
RGBVALUE( Lime500, 0xffcddc39 ) \
RGBVALUE( Lime600, 0xffc0ca33 ) \
RGBVALUE( Lime700, 0xffafb42b ) \
RGBVALUE( Lime800, 0xff9e9d24 ) \
RGBVALUE( Lime900, 0xff827717 ) \
RGBVALUE( LimeA100, 0xfff4ff81 ) \
RGBVALUE( LimeA200, 0xffeeff41 ) \
RGBVALUE( LimeA400, 0xffc6ff00 ) \
RGBVALUE( LimeA700, 0xffaeea00 ) \
\
RGBVALUE( Yellow50, 0xfffffde7 ) \
RGBVALUE( Yellow100, 0xfffff9c4 ) \
RGBVALUE( Yellow200, 0xfffff59d ) \
RGBVALUE( Yellow300, 0xfffff176 ) \
RGBVALUE( Yellow400, 0xffffee58 ) \
RGBVALUE( Yellow500, 0xffffeb3b ) \
RGBVALUE( Yellow600, 0xfffdd835 ) \
RGBVALUE( Yellow700, 0xfffbc02d ) \
RGBVALUE( Yellow800, 0xfff9a825 ) \
RGBVALUE( Yellow900, 0xfff57f17 ) \
RGBVALUE( YellowA100, 0xffffff8d ) \
RGBVALUE( YellowA200, 0xffffff00 ) \
RGBVALUE( YellowA400, 0xffffea00 ) \
RGBVALUE( YellowA700, 0xffffd600 ) \
\
RGBVALUE( Amber50, 0xfffff8e1 ) \
RGBVALUE( Amber100, 0xffffecb3 ) \
RGBVALUE( Amber200, 0xffffe082 ) \
RGBVALUE( Amber300, 0xffffd54f ) \
RGBVALUE( Amber400, 0xffffca28 ) \
RGBVALUE( Amber500, 0xffffc107 ) \
RGBVALUE( Amber600, 0xffffb300 ) \
RGBVALUE( Amber700, 0xffffa000 ) \
RGBVALUE( Amber800, 0xffff8f00 ) \
RGBVALUE( Amber900, 0xffff6f00 ) \
RGBVALUE( AmberA100, 0xffffe57f ) \
RGBVALUE( AmberA200, 0xffffd740 ) \
RGBVALUE( AmberA400, 0xffffc400 ) \
RGBVALUE( AmberA700, 0xffffab00 ) \
\
RGBVALUE( Orange50, 0xfffff3e0 ) \
RGBVALUE( Orange100, 0xffffe0b2 ) \
RGBVALUE( Orange200, 0xffffcc80 ) \
RGBVALUE( Orange300, 0xffffb74d ) \
RGBVALUE( Orange400, 0xffffa726 ) \
RGBVALUE( Orange500, 0xffff9800 ) \
RGBVALUE( Orange600, 0xfffb8c00 ) \
RGBVALUE( Orange700, 0xfff57c00 ) \
RGBVALUE( Orange800, 0xffef6c00 ) \
RGBVALUE( Orange900, 0xffe65100 ) \
RGBVALUE( OrangeA100, 0xffffd180 ) \
RGBVALUE( OrangeA200, 0xffffab40 ) \
RGBVALUE( OrangeA400, 0xffff9100 ) \
RGBVALUE( OrangeA700, 0xffff6d00 ) \
\
RGBVALUE( DeepOrange50, 0xfffbe9e7 ) \
RGBVALUE( DeepOrange100, 0xffffccbc ) \
RGBVALUE( DeepOrange200, 0xffffab91 ) \
RGBVALUE( DeepOrange300, 0xffff8a65 ) \
RGBVALUE( DeepOrange400, 0xffff7043 ) \
RGBVALUE( DeepOrange500, 0xffff5722 ) \
RGBVALUE( DeepOrange600, 0xfff4511e ) \
RGBVALUE( DeepOrange700, 0xffe64a19 ) \
RGBVALUE( DeepOrange800, 0xffd84315 ) \
RGBVALUE( DeepOrange900, 0xffbf360c ) \
RGBVALUE( DeepOrangeA100, 0xffff9e80 ) \
RGBVALUE( DeepOrangeA200, 0xffff6e40 ) \
RGBVALUE( DeepOrangeA400, 0xffff3d00 ) \
RGBVALUE( DeepOrangeA700, 0xffdd2c00 ) \
\
RGBVALUE( Brown50, 0xffefebe9 ) \
RGBVALUE( Brown100, 0xffd7ccc8 ) \
RGBVALUE( Brown200, 0xffbcaaa4 ) \
RGBVALUE( Brown300, 0xffa1887f ) \
RGBVALUE( Brown400, 0xff8d6e63 ) \
RGBVALUE( Brown500, 0xff795548 ) \
RGBVALUE( Brown600, 0xff6d4c41 ) \
RGBVALUE( Brown700, 0xff5d4037 ) \
RGBVALUE( Brown800, 0xff4e342e ) \
RGBVALUE( Brown900, 0xff3e2723 ) \
\
RGBVALUE( Grey50, 0xfffafafa ) \
RGBVALUE( Grey100, 0xfff5f5f5 ) \
RGBVALUE( Grey200, 0xffeeeeee ) \
RGBVALUE( Grey300, 0xffe0e0e0 ) \
RGBVALUE( Grey400, 0xffbdbdbd ) \
RGBVALUE( Grey500, 0xff9e9e9e ) \
RGBVALUE( Grey600, 0xff757575 ) \
RGBVALUE( Grey700, 0xff616161 ) \
RGBVALUE( Grey800, 0xff424242 ) \
RGBVALUE( Grey900, 0xff212121 ) \
\
RGBVALUE( BlueGrey50, 0xffeceff1 ) \
RGBVALUE( BlueGrey100, 0xffcfd8dc ) \
RGBVALUE( BlueGrey200, 0xffb0bec5 ) \
RGBVALUE( BlueGrey300, 0xff90a4ae ) \
RGBVALUE( BlueGrey400, 0xff78909c ) \
RGBVALUE( BlueGrey500, 0xff607d8b ) \
RGBVALUE( BlueGrey600, 0xff546e7a ) \
RGBVALUE( BlueGrey700, 0xff455a64 ) \
RGBVALUE( BlueGrey800, 0xff37474f ) \
RGBVALUE( BlueGrey900, 0xff263238 ) \
\
RGBVALUE( Transparent, 0x00000000 ) \
RGBVALUE( AlphaMask, 0xff000000 ) \

View File

@ -38,7 +38,6 @@ HEADERS += \
common/QskPlacementPolicy.h \
common/QskPlatform.h \
common/QskRgbValue.h \
common/QskRgbPalette.h \
common/QskScaleEngine.h \
common/QskScaleTickmarks.h \
common/QskShadowMetrics.h \
@ -66,7 +65,6 @@ SOURCES += \
common/QskPlatform.cpp \
common/QskPlacementPolicy.cpp \
common/QskRgbValue.cpp \
common/QskRgbPalette.cpp \
common/QskScaleEngine.cpp \
common/QskScaleTickmarks.cpp \
common/QskShadowMetrics.cpp \