Squashed commit of the following:

commit 547927f937a3260d5b23068f06cd181de9b7c763
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:38:40 2022 +0100

    wip

commit ca06b1da4bf9c5b30ef2857f0b6c1e4fb137a64e
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:30:31 2022 +0100

    using private classes

commit 4977b0afa481039f22b64e7f55262be8053a26c2
Author: Uwe Rathmann <Uwe.Rathmann@tigertal.de>
Date:   Wed Mar 23 15:18:20 2022 +0100

    avoid using private Qt headers in examples
This commit is contained in:
Uwe Rathmann 2022-03-23 15:39:17 +01:00
parent 9be4562d8f
commit f44208213c
5 changed files with 89 additions and 89 deletions

View File

@ -11,6 +11,7 @@
#include <QskArcMetrics.h>
#include <QskTextOptions.h>
#include <QskScaleTickmarks.h>
#include <QFontMetrics>
#include <QtMath>
@ -125,8 +126,7 @@ QRectF LightDisplaySkinlet::subControlRect( const QskSkinnable* skinnable,
QSGNode* LightDisplaySkinlet::updateSubNode(
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
{
auto* display = static_cast< const LightDisplay* >( skinnable );
const auto* display = static_cast< const LightDisplay* >( skinnable );
switch( nodeRole )
{
@ -166,16 +166,16 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
if ( ticksNode == nullptr )
ticksNode = new RadialTickmarksNode();
QColor color = display->color( LightDisplay::Tickmarks );
QRectF ticksRect = display->subControlRect( LightDisplay::Tickmarks );
QskArcMetrics arcMetrics = display->arcMetricsHint( LightDisplay::Tickmarks );
QskIntervalF boundaries = display->boundaries();
QskScaleTickmarks tickmarks;
tickmarks.setMajorTicks( {0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180 } );
int tickLineWidth = display->metric( LightDisplay::Tickmarks );
const auto color = display->color( LightDisplay::Tickmarks );
const auto ticksRect = display->subControlRect( LightDisplay::Tickmarks );
const auto arcMetrics = display->arcMetricsHint( LightDisplay::Tickmarks );
ticksNode->update( color, ticksRect, arcMetrics, boundaries,
tickmarks, tickLineWidth, Qt::Horizontal );
QskScaleTickmarks tickmarks;
tickmarks.setMajorTicks( { 0, 22.5, 45, 67.5, 90, 112.5, 135, 157.5, 180 } );
const auto tickLineWidth = display->metric( LightDisplay::Tickmarks );
ticksNode->update( color, ticksRect, arcMetrics, tickmarks, tickLineWidth );
return ticksNode;
}
@ -207,11 +207,11 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
QSizeF LightDisplaySkinlet::textLabelsSize( const LightDisplay* display ) const
{
QFont font = display->effectiveFont( LightDisplay::LeftLabel );
QFontMetricsF fm( font );
const QFontMetricsF fm( display->effectiveFont( LightDisplay::LeftLabel ) );
qreal w = fm.width( QStringLiteral( " 100" ) );
qreal h = fm.height();
return { w, h };
}

View File

@ -5,78 +5,50 @@
#include "RadialTickmarksNode.h"
#include <QSGFlatColorMaterial>
#include <QskScaleTickmarks.h>
#include <QskArcMetrics.h>
#include <QtMath>
QSK_QT_PRIVATE_BEGIN
#include <private/qsgnode_p.h>
QSK_QT_PRIVATE_END
static constexpr inline qreal qskTickFactor( QskScaleTickmarks::TickType type )
{
using TM = QskScaleTickmarks;
return type == TM::MinorTick ? 0.7 : ( type == TM::MinorTick ? 0.85 : 1.0 );
}
class RadialTickmarksNodePrivate final : public QSGGeometryNodePrivate
{
public:
RadialTickmarksNodePrivate()
: geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
geometry.setDrawingMode( QSGGeometry::DrawLines );
geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
}
QSGGeometry geometry;
QSGFlatColorMaterial material;
QskIntervalF boundaries;
QskScaleTickmarks tickmarks;
QRectF rect;
int lineWidth = 0;
uint hash = 0;
};
RadialTickmarksNode::RadialTickmarksNode()
: QSGGeometryNode( *new RadialTickmarksNodePrivate )
: m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 )
{
Q_D( RadialTickmarksNode );
m_geometry.setDrawingMode( QSGGeometry::DrawLines );
m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern );
setGeometry( &d->geometry );
setMaterial( &d->material );
setGeometry( &m_geometry );
setMaterial( &m_material );
}
RadialTickmarksNode::~RadialTickmarksNode()
{
}
void RadialTickmarksNode::update(const QColor& color, const QRectF& rect,
const QskArcMetrics& arcMetrics, const QskIntervalF& /*boundaries*/,
const QskScaleTickmarks& tickmarks, int lineWidth,
Qt::Orientation /*orientation*/ )
void RadialTickmarksNode::update( const QColor& color, const QRectF& rect,
const QskArcMetrics& arcMetrics, const QskScaleTickmarks& tickmarks, int lineWidth )
{
Q_D( RadialTickmarksNode );
if( lineWidth != d->lineWidth )
if( lineWidth != m_lineWidth )
{
d->lineWidth = lineWidth;
d->geometry.setLineWidth( lineWidth );
m_lineWidth = lineWidth;
m_geometry.setLineWidth( lineWidth );
markDirty( QSGNode::DirtyGeometry );
}
const uint hash = tickmarks.hash( 17435 );
if( ( hash != d->hash ) || ( rect != d->rect ) )
if( ( hash != m_hash ) || ( rect != m_rect ) )
{
d->hash = hash;
d->rect = rect;
m_hash = hash;
m_rect = rect;
d->geometry.allocate( tickmarks.tickCount() * 2 );
auto vertexData = d->geometry.vertexDataAsPoint2D();
m_geometry.allocate( tickmarks.tickCount() * 2 );
auto vertexData = m_geometry.vertexDataAsPoint2D();
const auto center = rect.center();
const auto radius = 0.5 * rect.width();
@ -113,13 +85,13 @@ void RadialTickmarksNode::update(const QColor& color, const QRectF& rect,
}
}
d->geometry.markVertexDataDirty();
m_geometry.markVertexDataDirty();
markDirty( QSGNode::DirtyGeometry );
}
if ( color != d->material.color() )
if ( color != m_material.color() )
{
d->material.setColor( color );
m_material.setColor( color );
markDirty( QSGNode::DirtyMaterial );
}
}

View File

@ -5,13 +5,13 @@
#pragma once
#include <QskArcMetrics.h>
#include <QskIntervalF.h>
#include <QskScaleTickmarks.h>
#include <QSGGeometryNode>
#include <QSGFlatColorMaterial>
class RadialTickmarksNodePrivate;
class QskArcMetrics;
class QskScaleTickmarks;
class RadialTickmarksNode : public QSGGeometryNode
{
@ -19,9 +19,15 @@ class RadialTickmarksNode : public QSGGeometryNode
RadialTickmarksNode();
~RadialTickmarksNode() override;
void update( const QColor&, const QRectF&, const QskArcMetrics&,
const QskIntervalF&, const QskScaleTickmarks&, int, Qt::Orientation );
void update( const QColor&, const QRectF&,
const QskArcMetrics&, const QskScaleTickmarks&, int lineWidth );
private:
Q_DECLARE_PRIVATE( RadialTickmarksNode )
QSGGeometry m_geometry;
QSGFlatColorMaterial m_material;
QRectF m_rect;
int m_lineWidth = 0;
uint m_hash = 0;
};

View File

@ -14,6 +14,10 @@
#include <qsgflatcolormaterial.h>
#include <qsgvertexcolormaterial.h>
QSK_QT_PRIVATE_BEGIN
#include <private/qsgnode_p.h>
QSK_QT_PRIVATE_END
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialVertex )
static inline uint qskMetricsHash(
@ -33,13 +37,28 @@ static inline uint qskColorsHash(
return fillGradient.hash( hash );
}
QskBoxNode::QskBoxNode()
: m_metricsHash( 0 )
, m_colorsHash( 0 )
, m_geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 )
class QskBoxNodePrivate final : public QSGGeometryNodePrivate
{
public:
QskBoxNodePrivate()
: geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 )
{
}
uint metricsHash = 0;
uint colorsHash = 0;
QRectF rect;
QSGGeometry geometry;
};
QskBoxNode::QskBoxNode()
: QSGGeometryNode( *new QskBoxNodePrivate )
{
Q_D( QskBoxNode );
setMaterial( qskMaterialVertex );
setGeometry( &m_geometry );
setGeometry( &d->geometry );
}
QskBoxNode::~QskBoxNode()
@ -58,6 +77,8 @@ void QskBoxNode::setBoxData( const QRectF& rect,
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics,
const QskBoxBorderColors& borderColors, const QskGradient& gradient )
{
Q_D( QskBoxNode );
QskGradient fillGradient = gradient;
#if 1
// Renderer is buggy for monochrome gradients with stops. TODO ...
@ -71,15 +92,15 @@ void QskBoxNode::setBoxData( const QRectF& rect,
const uint metricsHash = qskMetricsHash( shape, borderMetrics );
const uint colorsHash = qskColorsHash( borderColors, fillGradient );
if ( ( metricsHash == m_metricsHash ) &&
( colorsHash == m_colorsHash ) && ( rect == m_rect ) )
if ( ( metricsHash == d->metricsHash ) &&
( colorsHash == d->colorsHash ) && ( rect == d->rect ) )
{
return;
}
m_metricsHash = metricsHash;
m_colorsHash = colorsHash;
m_rect = rect;
d->metricsHash = metricsHash;
d->colorsHash = colorsHash;
d->rect = rect;
markDirty( QSGNode::DirtyMaterial );
markDirty( QSGNode::DirtyGeometry );
@ -87,7 +108,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( rect.isEmpty() )
{
m_geometry.allocate( 0 );
d->geometry.allocate( 0 );
return;
}
@ -106,7 +127,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( !hasBorder && !hasFill )
{
m_geometry.allocate( 0 );
d->geometry.allocate( 0 );
return;
}
@ -155,7 +176,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
{
setMonochrome( false );
renderer.renderBox( m_rect, shape, borderMetrics,
renderer.renderBox( d->rect, shape, borderMetrics,
borderColors, fillGradient, *geometry() );
}
else
@ -168,12 +189,12 @@ void QskBoxNode::setBoxData( const QRectF& rect,
if ( hasFill )
{
flatMaterial->setColor( fillGradient.startColor() );
renderer.renderFill( m_rect, shape, QskBoxBorderMetrics(), *geometry() );
renderer.renderFill( d->rect, shape, QskBoxBorderMetrics(), *geometry() );
}
else
{
flatMaterial->setColor( borderColors.gradient( Qsk::Left ).startColor().rgba() );
renderer.renderBorder( m_rect, shape, borderMetrics, *geometry() );
renderer.renderBorder( d->rect, shape, borderMetrics, *geometry() );
}
}
}
@ -185,14 +206,16 @@ void QskBoxNode::setMonochrome( bool on )
if ( on == ( material != qskMaterialVertex ) )
return;
m_geometry.allocate( 0 );
Q_D( QskBoxNode );
d->geometry.allocate( 0 );
if ( on )
{
setMaterial( new QSGFlatColorMaterial() );
const QSGGeometry g( QSGGeometry::defaultAttributes_Point2D(), 0 );
memcpy( ( void* ) &m_geometry, ( void* ) &g, sizeof( QSGGeometry ) );
memcpy( ( void* ) &d->geometry, ( void* ) &g, sizeof( QSGGeometry ) );
}
else
{
@ -200,6 +223,6 @@ void QskBoxNode::setMonochrome( bool on )
delete material;
const QSGGeometry g( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 );
memcpy( ( void* ) &m_geometry, ( void* ) &g, sizeof( QSGGeometry ) );
memcpy( ( void* ) &d->geometry, ( void* ) &g, sizeof( QSGGeometry ) );
}
}

View File

@ -14,6 +14,8 @@ class QskBoxBorderMetrics;
class QskBoxBorderColors;
class QskGradient;
class QskBoxNodePrivate;
class QSK_EXPORT QskBoxNode : public QSGGeometryNode
{
public:
@ -29,11 +31,8 @@ class QSK_EXPORT QskBoxNode : public QSGGeometryNode
private:
void setMonochrome( bool on );
uint m_metricsHash;
uint m_colorsHash;
QRectF m_rect;
Q_DECLARE_PRIVATE( QskBoxNode )
QSGGeometry m_geometry;
};
#endif