QskRgbPalette added

This commit is contained in:
Uwe Rathmann 2020-07-31 12:43:08 +02:00
parent 6871b7a0b8
commit 39f4d80153
7 changed files with 104 additions and 96 deletions

View File

@ -21,7 +21,7 @@ Box::Box( QQuickItem* parentItem )
setGradientHint( QskBox::Panel, QskGradient() );
}
void Box::setBackground( FillType type, Palette::Color color, bool inverted )
void Box::setBackground( FillType type, QskRgbPalette::Theme theme, bool inverted )
{
if ( type == Unfilled )
{
@ -29,10 +29,10 @@ void Box::setBackground( FillType type, Palette::Color color, bool inverted )
return;
}
const auto pal = Palette::palette( color );
const auto pal = QskRgbPalette::palette( theme );
const QColor light = pal.color( Palette::W300 );
const QColor mid = pal.color( Palette::W600 );
const QColor light = pal.color( QskRgbPalette::W300 );
const QColor mid = pal.color( QskRgbPalette::W600 );
switch ( type )
{
@ -57,15 +57,15 @@ void Box::setBackground( FillType type, Palette::Color color, bool inverted )
}
}
void Box::setBorder( BorderType type, Palette::Color color )
void Box::setBorder( BorderType type, QskRgbPalette::Theme theme )
{
const auto pal = Palette::palette( color );
const auto pal = QskRgbPalette::palette( theme );
setBorderWidth( 5 );
QColor dark = pal.color( Palette::W700 );
QColor mid = pal.color( Palette::W500 );
QColor light = pal.color( Palette::W300 );
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 );
@ -177,26 +177,26 @@ void Box::setGradient( const QskGradient& gradient )
}
void Box::setGradient(
const QskGradient::Orientation orientation, Palette::Color color )
const QskGradient::Orientation orientation, QskRgbPalette::Theme theme )
{
const auto pal = Palette::palette( color );
const auto pal = QskRgbPalette::palette( theme );
QVector< QskGradientStop > stops;
stops += QskGradientStop( 0.0, pal.color( static_cast< Palette::Weight >( 0 ) ) );
stops += QskGradientStop( 0.0, pal.color( static_cast< QskRgbPalette::Weight >( 0 ) ) );
const int count = Palette::NumWeights - 1;
const int count = QskRgbPalette::NumWeights - 1;
for ( int i = 1; i < count; i++ )
{
const qreal pos = qreal( i ) / count;
const auto weight = static_cast< Palette::Weight >( i );
const auto weight = static_cast< QskRgbPalette::Weight >( i );
stops += QskGradientStop( pos, stops.last().color() );
stops += QskGradientStop( pos, pal.color( weight ) );
}
stops += QskGradientStop( 1.0,
pal.color( static_cast< Palette::Weight >( Palette::NumWeights - 1 ) ) );
pal.color( static_cast< QskRgbPalette::Weight >( QskRgbPalette::NumWeights - 1 ) ) );
setGradient( QskGradient( orientation, stops ) );
}

View File

@ -6,7 +6,7 @@
#ifndef BOX_H
#define BOX_H
#include "Palette.h"
#include <QskRgbPalette.h>
#include <QskBox.h>
class Box : public QskBox
@ -33,8 +33,8 @@ class Box : public QskBox
Box( QQuickItem* parentItem = nullptr );
void setBackground( FillType, Palette::Color, bool inverted = false );
void setBorder( BorderType type, Palette::Color );
void setBackground( FillType, QskRgbPalette::Theme, bool inverted = false );
void setBorder( BorderType type, QskRgbPalette::Theme );
void setShape( const QskBoxShapeMetrics& );
void setShape( qreal radius, Qt::SizeMode );
@ -57,7 +57,7 @@ class Box : public QskBox
const QColor&, const QColor&, const QColor& );
void setGradient( const QskGradient& gradient );
void setGradient( const QskGradient::Orientation, Palette::Color );
void setGradient( const QskGradient::Orientation, QskRgbPalette::Theme );
};
#endif

View File

@ -1,10 +1,8 @@
CONFIG += qskexample
HEADERS += \
Box.h \
Palette.h
Box.h
SOURCES += \
Box.cpp \
Palette.cpp \
main.cpp

View File

@ -56,7 +56,7 @@ static void addTestRectangle( QskLinearBox* parent )
auto box = new Box( parent );
box->setMargins( 50 );
box->setBorder( Box::Flat, Palette::DeepOrange );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setBorderWidth( 10, 20, 40, 20 );
QskBoxShapeMetrics shape( 50, Qt::RelativeSize );
@ -64,7 +64,7 @@ static void addTestRectangle( QskLinearBox* parent )
shape.setRadius( Qt::TopRightCorner, 70 );
box->setShape( shape );
box->setGradient( QskGradient::Diagonal, Palette::Blue );
box->setGradient( QskGradient::Diagonal, QskRgbPalette::Blue );
}
static void addRectangles1( QskLinearBox* parent )
@ -73,7 +73,7 @@ static void addRectangles1( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* rectangle = new MyRectangle( parent );
rectangle->setBackground( type, Palette::Teal );
rectangle->setBackground( type, QskRgbPalette::Teal );
}
}
@ -83,8 +83,8 @@ static void addRectangles2( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* rectangle = new MyRectangle( parent );
rectangle->setBorder( Box::Flat, Palette::Brown );
rectangle->setBackground( type, Palette::Yellow );
rectangle->setBorder( Box::Flat, QskRgbPalette::Brown );
rectangle->setBackground( type, QskRgbPalette::Yellow );
}
}
@ -92,30 +92,30 @@ static void addRectangles3( QskLinearBox* parent )
{
using namespace QskRgbValue;
const Palette::Color borderColor = Palette::Grey;
const Palette::Color fillColor = Palette::Blue;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Blue;
Box* box;
box = new MyRectangle( parent );
box->setBorder( Box::Raised1, borderColor );
box->setBorder( Box::Raised1, borderTheme );
box->setGradient( Grey400 );
box = new MyRectangle( parent );
box->setBorder( Box::Sunken1, borderColor );
box->setBorder( Box::Sunken1, borderTheme );
box->setGradient( QskGradient::Diagonal, Grey400, Grey500 );
box = new MyRectangle( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBorder( Box::Raised2, borderTheme );
box->setGradient( QskGradient::Vertical, Grey400, Grey500 );
box = new MyRectangle( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBackground( Box::Vertical, fillColor, false );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box = new MyRectangle( parent );
box->setBorder( Box::Sunken2, borderColor );
box->setBackground( Box::Vertical, fillColor, true );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
}
static void addRectangles4( QskLinearBox* parent )
@ -124,7 +124,7 @@ static void addRectangles4( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyRoundedRectangle( parent );
box->setBackground( type, Palette::DeepOrange );
box->setBackground( type, QskRgbPalette::DeepOrange );
}
}
@ -134,8 +134,8 @@ static void addRectangles5( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyRoundedRectangle( parent );
box->setBorder( Box::Flat, Palette::Indigo );
box->setBackground( type, Palette::Pink );
box->setBorder( Box::Flat, QskRgbPalette::Indigo );
box->setBackground( type, QskRgbPalette::Pink );
}
}
@ -143,30 +143,30 @@ static void addRectangles6( QskLinearBox* parent )
{
using namespace QskRgbValue;
const Palette::Color borderColor = Palette::Grey;
const Palette::Color fillColor = Palette::Lime;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Lime;
Box* box;
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Raised1, borderColor );
box->setBorder( Box::Raised1, borderTheme );
box->setGradient( Grey400 );
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Sunken1, borderColor );
box->setBorder( Box::Sunken1, borderTheme );
box->setGradient( QskGradient::Diagonal, Grey400, Grey500 );
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBorder( Box::Raised2, borderTheme );
box->setGradient( QskGradient::Vertical, Grey400, Grey500 );
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBackground( Box::Vertical, fillColor, false );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box = new MyRoundedRectangle( parent );
box->setBorder( Box::Sunken2, borderColor );
box->setBackground( Box::Vertical, fillColor, true );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
}
static void addRectangles7( QskLinearBox* parent )
@ -175,7 +175,7 @@ static void addRectangles7( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyEllipse( parent );
box->setBackground( type, Palette::BlueGrey );
box->setBackground( type, QskRgbPalette::BlueGrey );
}
}
@ -185,8 +185,8 @@ static void addRectangles8( QskLinearBox* parent )
Box::Horizontal, Box::Vertical, Box::Diagonal } )
{
auto* box = new MyEllipse( parent );
box->setBorder( Box::Flat, Palette::Indigo );
box->setBackground( type, Palette::Red );
box->setBorder( Box::Flat, QskRgbPalette::Indigo );
box->setBackground( type, QskRgbPalette::Red );
}
}
@ -194,36 +194,36 @@ static void addRectangles9( QskLinearBox* parent )
{
using namespace QskRgbValue;
const Palette::Color borderColor = Palette::Grey;
const Palette::Color fillColor = Palette::Lime;
const auto borderTheme = QskRgbPalette::Grey;
const auto fillTheme = QskRgbPalette::Lime;
Box* box;
box = new MyEllipse( parent );
box->setBorder( Box::Raised1, borderColor );
box->setBorder( Box::Raised1, borderTheme );
box->setGradient( Grey400 );
box = new MyEllipse( parent );
box->setBorder( Box::Sunken1, borderColor );
box->setBorder( Box::Sunken1, borderTheme );
box->setGradient( QskGradient::Diagonal, Grey400, Grey500 );
box = new MyEllipse( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBorder( Box::Raised2, borderTheme );
box->setGradient( QskGradient::Vertical, Grey400, Grey500 );
box = new MyEllipse( parent );
box->setBorder( Box::Raised2, borderColor );
box->setBackground( Box::Vertical, fillColor, false );
box->setBorder( Box::Raised2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, false );
box = new MyEllipse( parent );
box->setBorder( Box::Sunken2, borderColor );
box->setBackground( Box::Vertical, fillColor, true );
box->setBorder( Box::Sunken2, borderTheme );
box->setBackground( Box::Vertical, fillTheme, true );
}
static void addRectangles10( QskLinearBox* parent )
{
QColor borderColor( "Indigo" );
// borderColor.setAlpha( 100 );
QColor borderTheme( "Indigo" );
// borderTheme.setAlpha( 100 );
Box* box;
@ -232,25 +232,25 @@ static void addRectangles10( QskLinearBox* parent )
box = new Box( parent );
box->setBorderWidth( 10 );
box->setBorderColor( borderColor );
box->setBorderColor( borderTheme );
box->setGradient( QskGradient::Diagonal, "DeepPink", "DarkOrange", "HotPink" );
box = new Box( parent );
box->setShape( 100, Qt::RelativeSize );
box->setBorderWidth( 5 );
box->setBorderColor( borderColor );
box->setBorderColor( borderTheme );
box->setGradient( QskGradient::Vertical, "DeepPink", "DarkOrange", "HotPink" );
box = new Box( parent );
box->setShape( 100, Qt::RelativeSize );
box->setBorderWidth( 5 );
box->setBorderColor( borderColor );
box->setBorderColor( borderTheme );
box->setGradient( QskGradient::Diagonal, "DeepPink", "DarkOrange", "HotPink" );
box = new Box( parent );
box->setShape( 100, Qt::RelativeSize );
box->setBorderWidth( 5, 20, 30, 5 );
box->setBorderColor( borderColor );
box->setBorderColor( borderTheme );
box->setGradient( QskGradient::Vertical, "DeepPink", "DarkOrange", "HotPink" );
}
@ -264,14 +264,14 @@ static void addRectangles11( QskLinearBox* parent )
{
auto box = new MyRectangle( parent );
box->setBorder( Box::Flat, Palette::Teal );
box->setBorder( Box::Flat, QskRgbPalette::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 ], Palette::Brown, i >= 3 );
box->setBackground( fillType[ i ], QskRgbPalette::Brown, i >= 3 );
}
}
@ -282,14 +282,14 @@ static void addRectangles12( QskLinearBox* parent )
{
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setGradient( orientation, Palette::Brown );
box->setGradient( orientation, QskRgbPalette::Brown );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, Palette::DeepOrange );
box->setGradient( orientation, Palette::Blue );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setGradient( orientation, QskRgbPalette::Blue );
}
for ( auto orientation : { QskGradient::Vertical,
@ -298,15 +298,15 @@ static void addRectangles12( QskLinearBox* parent )
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setShape( 30, 40, Qt::RelativeSize );
box->setGradient( orientation, Palette::Brown );
box->setGradient( orientation, QskRgbPalette::Brown );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, Palette::DeepOrange );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setShape( 30, 40, Qt::RelativeSize );
box->setGradient( orientation, Palette::Blue );
box->setGradient( orientation, QskRgbPalette::Blue );
}
for ( auto orientation : { QskGradient::Vertical,
@ -315,15 +315,15 @@ static void addRectangles12( QskLinearBox* parent )
auto* box = new Box( parent );
box->setBorderWidth( 0 );
box->setShape( 100, 100, Qt::RelativeSize );
box->setGradient( orientation, Palette::Brown );
box->setGradient( orientation, QskRgbPalette::Brown );
}
for ( auto orientation : { QskGradient::Vertical, QskGradient::Diagonal } )
{
auto* box = new Box( parent );
box->setBorder( Box::Flat, Palette::DeepOrange );
box->setBorder( Box::Flat, QskRgbPalette::DeepOrange );
box->setShape( 100, 100, Qt::RelativeSize );
box->setGradient( orientation, Palette::Blue );
box->setGradient( orientation, QskRgbPalette::Blue );
}
}

View File

@ -1,10 +1,10 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "Palette.h"
#include <QskRgbValue.h>
#include "QskRgbPalette.h"
#include "QskRgbValue.h"
#define RGB( color, weight ) color ## weight
@ -16,14 +16,14 @@
namespace
{
class StandardPalette : public Palette
class Palette : public QskRgbPalette
{
public:
StandardPalette( int index )
Palette( int index )
{
using namespace QskRgbValue;
static QRgb table[][ Palette::NumWeights ] =
static constexpr QRgb table[][ Palette::NumWeights ] =
{
RGBTABLE( Red ),
RGBTABLE( Pink ),
@ -52,7 +52,7 @@ namespace
};
}
Palette Palette::palette( Color color )
QskRgbPalette QskRgbPalette::palette( Theme theme )
{
return StandardPalette( static_cast< int >( color ) );
return Palette( static_cast< int >( theme ) );
}

View File

@ -1,16 +1,19 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef PALETTE_H
#define PALETTE_H 1
#ifndef QSK_RGB_PALETTE_H
#define QSK_RGB_PALETTE_H
#include <QColor>
#include <QVector>
#include "QskGlobal.h"
#include <qmetaobject.h>
#include <qcolor.h>
class Palette
class QSK_EXPORT QskRgbPalette
{
Q_GADGET
public:
enum Weight
{
@ -27,8 +30,9 @@ class Palette
NumWeights
};
Q_ENUM( Weight )
enum Color
enum Theme
{
Red,
Pink,
@ -50,11 +54,15 @@ class Palette
Grey,
BlueGrey,
NumColors
NumThemes
};
Q_ENUM( Theme )
QRgb rgb( Weight weight ) const
inline QRgb rgb( Weight weight ) const
{
if ( weight < 0 || weight >= NumWeights )
return 0;
return m_rgb[ weight ];
}
@ -63,10 +71,10 @@ class Palette
return QColor::fromRgba( rgb( weight ) );
}
static Palette palette( Color );
static QskRgbPalette palette( Theme );
protected:
QRgb* m_rgb;
const QRgb* m_rgb;
};
#endif

View File

@ -29,6 +29,7 @@ HEADERS += \
common/QskNamespace.h \
common/QskObjectCounter.h \
common/QskRgbValue.h \
common/QskRgbPalette.h \
common/QskSizePolicy.h \
common/QskTextColors.h \
common/QskTextOptions.h
@ -47,6 +48,7 @@ SOURCES += \
common/QskMetaInvokable.cpp \
common/QskObjectCounter.cpp \
common/QskRgbValue.cpp \
common/QskRgbPalette.cpp \
common/QskSizePolicy.cpp \
common/QskTextColors.cpp \
common/QskTextOptions.cpp