use shadow
This commit is contained in:
parent
1b90e27b72
commit
bf1f4906e6
|
@ -18,6 +18,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRadialGradient>
|
#include <QRadialGradient>
|
||||||
|
|
||||||
|
QSK_SUBCONTROL( LightDisplay, Panel )
|
||||||
QSK_SUBCONTROL( LightDisplay, Groove )
|
QSK_SUBCONTROL( LightDisplay, Groove )
|
||||||
QSK_SUBCONTROL( LightDisplay, ColdPart )
|
QSK_SUBCONTROL( LightDisplay, ColdPart )
|
||||||
QSK_SUBCONTROL( LightDisplay, WarmPart )
|
QSK_SUBCONTROL( LightDisplay, WarmPart )
|
||||||
|
@ -29,6 +30,44 @@ LightDisplay::LightDisplay( QQuickItem* parent )
|
||||||
: QskBoundedControl( parent )
|
: QskBoundedControl( parent )
|
||||||
{
|
{
|
||||||
setAlignmentHint( LeftLabel, Qt::AlignRight );
|
setAlignmentHint( LeftLabel, Qt::AlignRight );
|
||||||
|
|
||||||
|
// ### move to Skin:
|
||||||
|
setGradient( Qt::magenta );
|
||||||
|
setShadow( { 0, 20 } );
|
||||||
|
setShadowColor( 0xe5e5e5 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void LightDisplay::setShadow( const QskShadowMetrics& shadow )
|
||||||
|
{
|
||||||
|
m_shadow = shadow;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QskShadowMetrics& LightDisplay::shadow() const
|
||||||
|
{
|
||||||
|
return m_shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LightDisplay::setGradient( const QskGradient& gradient )
|
||||||
|
{
|
||||||
|
m_gradient = gradient;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QskGradient& LightDisplay::gradient() const
|
||||||
|
{
|
||||||
|
return m_gradient;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LightDisplay::setShadowColor( const QColor& color )
|
||||||
|
{
|
||||||
|
m_shadowColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor LightDisplay::shadowColor() const
|
||||||
|
{
|
||||||
|
return m_shadowColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_LightDisplay.cpp"
|
#include "moc_LightDisplay.cpp"
|
||||||
|
|
|
@ -6,13 +6,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QskBoundedControl.h>
|
#include <QskBoundedControl.h>
|
||||||
|
#include <QskBoxShapeMetrics.h>
|
||||||
|
#include <QskShadowMetrics.h>
|
||||||
|
|
||||||
class LightDisplay : public QskBoundedControl
|
class LightDisplay : public QskBoundedControl
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Groove, ColdPart, WarmPart, ValueText, LeftLabel, RightLabel )
|
QSK_SUBCONTROLS( Panel, Groove, ColdPart, WarmPart, ValueText, LeftLabel, RightLabel )
|
||||||
|
|
||||||
LightDisplay( QQuickItem* parent = nullptr );
|
LightDisplay( QQuickItem* parent = nullptr );
|
||||||
|
|
||||||
|
void setShadow( const QskShadowMetrics& );
|
||||||
|
const QskShadowMetrics& shadow() const;
|
||||||
|
|
||||||
|
void setGradient( const QskGradient& );
|
||||||
|
const QskGradient& gradient() const;
|
||||||
|
|
||||||
|
void setShadowColor( const QColor& );
|
||||||
|
QColor shadowColor() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QskShadowMetrics m_shadow;
|
||||||
|
QColor m_shadowColor = Qt::black;
|
||||||
|
|
||||||
|
QskGradient m_gradient;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "LightDisplaySkinlet.h"
|
#include "LightDisplaySkinlet.h"
|
||||||
#include "LightDisplay.h"
|
#include "LightDisplay.h"
|
||||||
|
|
||||||
|
#include "nodes/BoxShadowNode.h"
|
||||||
|
|
||||||
#include <QskTextOptions.h>
|
#include <QskTextOptions.h>
|
||||||
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
@ -13,8 +15,8 @@
|
||||||
LightDisplaySkinlet::LightDisplaySkinlet( QskSkin* skin )
|
LightDisplaySkinlet::LightDisplaySkinlet( QskSkin* skin )
|
||||||
: QskSkinlet( skin )
|
: QskSkinlet( skin )
|
||||||
{
|
{
|
||||||
setNodeRoles( { GrooveRole, WarmPartRole, ColdPartRole, ValueTextRole,
|
setNodeRoles( { GrooveRole, PanelRole, WarmPartRole, ColdPartRole,
|
||||||
LeftLabelRole, RightLabelRole } );
|
ValueTextRole, LeftLabelRole, RightLabelRole } );
|
||||||
}
|
}
|
||||||
|
|
||||||
LightDisplaySkinlet::~LightDisplaySkinlet()
|
LightDisplaySkinlet::~LightDisplaySkinlet()
|
||||||
|
@ -27,7 +29,8 @@ QRectF LightDisplaySkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||||
auto* display = static_cast< const LightDisplay* >( skinnable );
|
auto* display = static_cast< const LightDisplay* >( skinnable );
|
||||||
QRectF rect = contentsRect;
|
QRectF rect = contentsRect;
|
||||||
|
|
||||||
if( subControl == LightDisplay::Groove )
|
if( subControl == LightDisplay::Groove
|
||||||
|
|| subControl == LightDisplay::Panel )
|
||||||
{
|
{
|
||||||
QSizeF size = textLabelsSize( display );
|
QSizeF size = textLabelsSize( display );
|
||||||
|
|
||||||
|
@ -72,12 +75,36 @@ QRectF LightDisplaySkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||||
QSGNode* LightDisplaySkinlet::updateSubNode(
|
QSGNode* LightDisplaySkinlet::updateSubNode(
|
||||||
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
||||||
{
|
{
|
||||||
|
auto* display = static_cast< const LightDisplay* >( skinnable );
|
||||||
|
|
||||||
|
|
||||||
switch( nodeRole )
|
switch( nodeRole )
|
||||||
{
|
{
|
||||||
|
case PanelRole:
|
||||||
|
{
|
||||||
|
return updateBoxNode( skinnable, node, LightDisplay::Panel );
|
||||||
|
}
|
||||||
case GrooveRole:
|
case GrooveRole:
|
||||||
{
|
{
|
||||||
return updateArcNode( skinnable, node, 0, 5760,
|
const QRectF grooveRect = display->subControlRect( LightDisplay::Groove );
|
||||||
LightDisplay::Groove );
|
if ( grooveRect.isEmpty() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto shadowNode = static_cast< BoxShadowNode* >( node );
|
||||||
|
if ( shadowNode == nullptr )
|
||||||
|
shadowNode = new BoxShadowNode();
|
||||||
|
|
||||||
|
const auto& shadowMetrics = display->shadow();
|
||||||
|
|
||||||
|
shadowNode->setRect( shadowMetrics.shadowRect( grooveRect ) );
|
||||||
|
shadowNode->setShape( grooveRect.width() / 2 );
|
||||||
|
shadowNode->setBlurRadius( shadowMetrics.blurRadius() );
|
||||||
|
shadowNode->setColor( display->shadowColor() );
|
||||||
|
shadowNode->setClipRect( grooveRect );
|
||||||
|
|
||||||
|
shadowNode->updateGeometry();
|
||||||
|
|
||||||
|
return shadowNode;
|
||||||
}
|
}
|
||||||
case WarmPartRole:
|
case WarmPartRole:
|
||||||
{
|
{
|
||||||
|
@ -98,12 +125,12 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
|
||||||
}
|
}
|
||||||
case LeftLabelRole:
|
case LeftLabelRole:
|
||||||
{
|
{
|
||||||
return updateTextNode( skinnable, node, QStringLiteral( "0" ), {},
|
return updateTextNode( skinnable, node, QStringLiteral( "0 " ), {},
|
||||||
LightDisplay::LeftLabel );
|
LightDisplay::LeftLabel );
|
||||||
}
|
}
|
||||||
case RightLabelRole:
|
case RightLabelRole:
|
||||||
{
|
{
|
||||||
return updateTextNode( skinnable, node, QStringLiteral( "100" ), {},
|
return updateTextNode( skinnable, node, QStringLiteral( " 100" ), {},
|
||||||
LightDisplay::RightLabel );
|
LightDisplay::RightLabel );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +143,7 @@ QSizeF LightDisplaySkinlet::textLabelsSize( const LightDisplay* display ) const
|
||||||
QFont font = display->effectiveFont( LightDisplay::LeftLabel );
|
QFont font = display->effectiveFont( LightDisplay::LeftLabel );
|
||||||
QFontMetricsF fm( font );
|
QFontMetricsF fm( font );
|
||||||
|
|
||||||
qreal w = fm.width( QStringLiteral( "100" ) );
|
qreal w = fm.width( QStringLiteral( " 100" ) );
|
||||||
qreal h = fm.height();
|
qreal h = fm.height();
|
||||||
return { w, h };
|
return { w, h };
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ class LightDisplaySkinlet : public QskSkinlet
|
||||||
public:
|
public:
|
||||||
enum NodeRole
|
enum NodeRole
|
||||||
{
|
{
|
||||||
|
PanelRole,
|
||||||
GrooveRole,
|
GrooveRole,
|
||||||
ColdPartRole,
|
ColdPartRole,
|
||||||
WarmPartRole,
|
WarmPartRole,
|
||||||
|
|
|
@ -182,8 +182,7 @@ void Skin::initHints( const Palette& palette )
|
||||||
ed.setColor( Diagram::ChartArea3, "#66ff7d34" );
|
ed.setColor( Diagram::ChartArea3, "#66ff7d34" );
|
||||||
|
|
||||||
// light intensity:
|
// light intensity:
|
||||||
ed.setGradient( LightDisplay::Groove, Qt::magenta );
|
ed.setBoxShape( LightDisplay::Panel, 100, Qt::RelativeSize );
|
||||||
ed.setArcMetrics( LightDisplay::Groove, { 10, 0, 5760 } );
|
|
||||||
ed.setGradient( LightDisplay::ColdPart, { Qt::Horizontal, "#a7b0ff", "#6776ff" } );
|
ed.setGradient( LightDisplay::ColdPart, { Qt::Horizontal, "#a7b0ff", "#6776ff" } );
|
||||||
ed.setGradient( LightDisplay::WarmPart, { Qt::Horizontal, "#feeeb7", "#ff3122" } );
|
ed.setGradient( LightDisplay::WarmPart, { Qt::Horizontal, "#feeeb7", "#ff3122" } );
|
||||||
ed.setFontRole( LightDisplay::ValueText, QskSkin::LargeFont );
|
ed.setFontRole( LightDisplay::ValueText, QskSkin::LargeFont );
|
||||||
|
@ -195,7 +194,7 @@ void Skin::initHints( const Palette& palette )
|
||||||
ed.setGradient( Box::Panel, palette.box );
|
ed.setGradient( Box::Panel, palette.box );
|
||||||
ed.setGradient( BoxWithButtons::Panel, palette.box );
|
ed.setGradient( BoxWithButtons::Panel, palette.box );
|
||||||
ed.setGradient( UsageDiagramBox::Panel, palette.box );
|
ed.setGradient( UsageDiagramBox::Panel, palette.box );
|
||||||
// ed.setColor( LightDisplay::Panel, palette.lightDisplay ); ###
|
ed.setGradient( LightDisplay::Panel, palette.box );
|
||||||
ed.setGradient( RoundButton::Panel, palette.roundButton );
|
ed.setGradient( RoundButton::Panel, palette.roundButton );
|
||||||
ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox );
|
ed.setBoxBorderColors( UsageDiagramBox::DaysBox, palette.weekdayBox );
|
||||||
ed.setColor( QskTextLabel::Text, palette.text );
|
ed.setColor( QskTextLabel::Text, palette.text );
|
||||||
|
|
Loading…
Reference in New Issue