qskinny/src/controls/QskSkinlet.h

220 lines
6.8 KiB
C
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
2024-01-17 13:31:45 +00:00
* QSkinny - Copyright (C) The authors
2023-04-06 07:23:37 +00:00
* SPDX-License-Identifier: BSD-3-Clause
2017-07-21 16:21:34 +00:00
*****************************************************************************/
#ifndef QSK_SKINLET_H
#define QSK_SKINLET_H
2017-07-21 16:21:34 +00:00
#include "QskAspect.h"
#include "QskNamespace.h"
2017-07-21 16:21:34 +00:00
2018-07-19 12:10:48 +00:00
#include <qnamespace.h>
#include <qrect.h>
2017-07-21 16:21:34 +00:00
#include <memory>
class QskArcMetrics;
2017-07-21 16:21:34 +00:00
class QskSkin;
class QskControl;
class QskSkinnable;
class QskGradient;
class QskColorFilter;
class QskGraphic;
class QskTextOptions;
class QskTextColors;
2022-01-04 12:44:53 +00:00
class QskBoxShapeMetrics;
class QskBoxBorderMetrics;
class QskBoxBorderColors;
class QskBoxHints;
2017-07-21 16:21:34 +00:00
class QSGNode;
class QSK_EXPORT QskSkinlet
{
Q_GADGET
2018-08-03 06:15:28 +00:00
public:
2017-07-21 16:21:34 +00:00
Q_INVOKABLE QskSkinlet( QskSkin* = nullptr );
virtual ~QskSkinlet();
QskSkin* skin() const;
2020-07-29 05:22:04 +00:00
virtual void updateNode( QskSkinnable*, QSGNode* parent ) const;
2021-12-26 08:15:15 +00:00
virtual QSizeF sizeHint( const QskSkinnable*,
Qt::SizeHint, const QSizeF& ) const;
virtual QRectF subControlRect( const QskSkinnable*,
const QRectF&, QskAspect::Subcontrol ) const;
/*
When having more than one instance for the
same QskAspect::Subcontrol it is called a sample
*/
virtual QRectF sampleRect( const QskSkinnable*,
2021-12-27 16:33:06 +00:00
const QRectF&, QskAspect::Subcontrol, int index ) const;
2021-12-24 15:50:34 +00:00
virtual int sampleIndexAt( const QskSkinnable*,
2021-12-26 08:15:15 +00:00
const QRectF&, QskAspect::Subcontrol, const QPointF& ) const;
2017-07-21 16:21:34 +00:00
virtual int sampleCount( const QskSkinnable*, QskAspect::Subcontrol ) const;
virtual QskAspect::States sampleStates( const QskSkinnable*,
QskAspect::Subcontrol, int index ) const;
virtual QVariant sampleAt( const QskSkinnable*,
2021-12-28 14:33:13 +00:00
QskAspect::Subcontrol, int index ) const;
2017-07-21 16:21:34 +00:00
const QVector< quint8 >& nodeRoles() const;
void setOwnedBySkinnable( bool on );
bool isOwnedBySkinnable() const;
// Helper functions for creating nodes
static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*,
const QRectF&, QskAspect::Subcontrol );
2022-01-04 12:44:53 +00:00
static QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*,
const QRectF&, const QskBoxHints& );
static QSGNode* updateInterpolatedBoxNode(
const QskSkinnable*, QSGNode*, const QRectF&,
QskAspect aspect1, QskAspect aspect2, qreal ratio );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
const QRectF&, QskAspect::Subcontrol );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
const QRectF&, const QskGradient&, QskAspect::Subcontrol );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
2023-04-17 08:54:44 +00:00
const QRectF&, qreal borderWidth, const QColor& borderColor,
const QskGradient&, const QskArcMetrics& );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
2021-10-20 07:27:05 +00:00
const QRectF&, qreal startAngle, qreal spanAngle, QskAspect::Subcontrol );
static QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
2021-10-20 07:27:05 +00:00
const QRectF&, const QskGradient&, qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol );
2023-05-25 13:03:48 +00:00
static QSGNode* updateLineNode( const QskSkinnable*, QSGNode*,
const QLineF&, QskAspect::Subcontrol );
static QSGNode* updateLinesNode( const QskSkinnable*,
2023-05-25 13:03:48 +00:00
QSGNode*, const QVector< QLineF >&, QskAspect::Subcontrol );
static QSGNode* updateTextNode( const QskSkinnable*, QSGNode*,
2022-08-25 07:39:33 +00:00
const QRectF&, Qt::Alignment, const QString&, QskAspect::Subcontrol );
static QSGNode* updateTextNode( const QskSkinnable*, QSGNode*,
const QRectF&, Qt::Alignment, const QString&, const QFont&,
const QskTextOptions&, const QskTextColors&, Qsk::TextStyle );
static QSGNode* updateTextNode( const QskSkinnable*, QSGNode*,
const QRectF&, Qt::Alignment, const QskTextOptions&,
const QString&, QskAspect::Subcontrol );
// keeping the aspect ratio
static QSGNode* updateGraphicNode( const QskSkinnable*, QSGNode*,
2020-11-19 10:48:25 +00:00
const QskGraphic&, const QskColorFilter&, const QRectF&,
Qt::Alignment, Qt::Orientations mirrored = Qt::Orientations() );
// stretching to fit
static QSGNode* updateGraphicNode( const QskSkinnable*, QSGNode*,
2020-11-01 14:44:15 +00:00
const QskGraphic&, const QskColorFilter&, const QRectF&,
Qt::Orientations mirrored = Qt::Orientations() );
2017-10-23 08:19:49 +00:00
static QSGNode* updateBoxClipNode( const QskSkinnable*, QSGNode*,
const QRectF&, QskAspect::Subcontrol );
2018-08-03 06:15:28 +00:00
protected:
2017-07-21 16:21:34 +00:00
void setNodeRoles( const QVector< quint8 >& );
void appendNodeRoles( const QVector< quint8 >& );
virtual QSGNode* updateSubNode( const QskSkinnable*,
quint8 nodeRole, QSGNode* ) const;
virtual QSGNode* updateBackgroundNode(
const QskControl*, QSGNode* ) const;
virtual QSGNode* updateDebugNode(
const QskControl*, QSGNode* node ) const;
QSGNode* updateBoxNode( const QskSkinnable*, QSGNode*,
QskAspect::Subcontrol ) const;
QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
QskAspect::Subcontrol ) const;
QSGNode* updateArcNode( const QskSkinnable*, QSGNode*,
2021-10-20 07:27:05 +00:00
qreal startAngle, qreal spanAngle,
QskAspect::Subcontrol ) const;
QSGNode* updateBoxClipNode( const QskSkinnable*, QSGNode*,
QskAspect::Subcontrol ) const;
2017-07-21 16:21:34 +00:00
QSGNode* updateTextNode( const QskSkinnable*, QSGNode*,
2022-08-25 07:39:33 +00:00
const QString&, QskAspect::Subcontrol ) const;
2017-07-21 16:21:34 +00:00
QSGNode* updateSymbolNode( const QskSkinnable*, QSGNode*,
QskAspect::Subcontrol ) const;
2017-07-21 16:21:34 +00:00
QSGNode* updateGraphicNode( const QskSkinnable*, QSGNode*,
2020-11-01 14:44:15 +00:00
const QskGraphic&, QskAspect::Subcontrol,
Qt::Orientations mirrored = Qt::Orientations() ) const;
2017-07-21 16:21:34 +00:00
2021-12-28 14:33:13 +00:00
QSGNode* updateSeriesNode( const QskSkinnable*,
QskAspect::Subcontrol, QSGNode* ) const;
virtual QSGNode* updateSampleNode( const QskSkinnable*,
2021-12-28 14:33:13 +00:00
QskAspect::Subcontrol, int index, QSGNode* ) const;
2020-11-22 14:27:58 +00:00
void replaceChildNode( quint8 nodeRole, QSGNode* parentNode,
QSGNode* oldNode, QSGNode* newNode ) const;
2017-07-21 16:21:34 +00:00
2021-12-23 18:05:59 +00:00
QSizeF hintWithoutConstraint(
2021-08-26 13:17:41 +00:00
const QSizeF& hint, const QSizeF& constraint ) const;
2018-08-03 06:15:28 +00:00
private:
2022-03-24 10:12:45 +00:00
Q_DISABLE_COPY( QskSkinlet )
2017-07-21 16:21:34 +00:00
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
2017-09-01 09:55:55 +00:00
inline QRectF QskSkinlet::subControlRect(
const QskSkinnable*, const QRectF&, QskAspect::Subcontrol ) const
2017-09-01 09:55:55 +00:00
{
return QRectF();
}
inline QSGNode* QskSkinlet::updateSubNode(
const QskSkinnable*, quint8, QSGNode*) const
{
return nullptr;
}
inline QSizeF QskSkinlet::sizeHint(
const QskSkinnable*, Qt::SizeHint, const QSizeF& ) const
{
return QSizeF();
}
inline QRectF QskSkinlet::sampleRect( const QskSkinnable*,
const QRectF&, QskAspect::Subcontrol, int index ) const
{
Q_UNUSED( index )
return QRectF();
}
inline int QskSkinlet::sampleCount(
const QskSkinnable*, QskAspect::Subcontrol ) const
{
return 0;
}
2017-07-21 16:21:34 +00:00
#endif