qskinny/src/controls/QskSpinBoxSkinlet.h

115 lines
5.7 KiB
C
Raw Normal View History

2023-02-17 11:01:56 +00:00
/******************************************************************************
2023-02-17 13:05:05 +00:00
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
2023-02-17 11:01:56 +00:00
*****************************************************************************/
2023-02-17 13:05:05 +00:00
#ifndef QSK_SPIN_BOX_SKINLET_H
#define QSK_SPIN_BOX_SKINLET_H
2023-02-17 11:01:56 +00:00
#include <QskSkinlet.h>
2023-02-17 16:46:52 +00:00
////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief
/// This skinlet's purpose is to draw a QskSpinBox instance.
/// @details
/// In order to manage individual subcontrol states this skinlet uses subcontrol sampling. Although
/// it is most usefull when dealing with dynamic or large numbers of subcontrols, it is a strategy
/// to index the subcontrol in order to have individual states instead of one collective state on
/// the skinnable object.
/// @note The placement and dimensions of all subcontrols depend on the following subctrontrol
/// aspects:
/// - QskSpinBox::Layout's alignment hint ( which affects the positions of all controls )
/// - QskSpinBox::Layout's spacing hint
/// - QskSpinBox::IncrementPanel's strut size hint
/// - QskSpinBox::DecrementPanel's strut size hint
/// - QskSpinBox::TextPanel's strut size hint
////////////////////////////////////////////////////////////////////////////////////////////////////
2023-02-17 11:01:56 +00:00
class QSK_EXPORT QskSpinBoxSkinlet : public QskSkinlet
{
2023-02-17 14:22:40 +00:00
Q_GADGET
using Inherited = QskSkinlet;
public:
2023-02-17 16:46:52 +00:00
/// @brief C-TOR defining the correct node's role order (e.g. panel before text)
Q_INVOKABLE QskSpinBoxSkinlet( QskSkin* = nullptr );
/// @brief Roles for the subcontrols.
2023-02-17 14:22:40 +00:00
enum NodeRole
{
2023-02-17 16:46:52 +00:00
IncrementPanel, ///< Identifier for the increment button's panel.
IncrementText, ///< Identifier for the increment button's text.
DecrementPanel, ///< Identifier for the decrement button's panel.
DecrementText, ///< Identifier for the decrement button's text.
TextPanel, ///< Identifier for the text's panel.
TextText, ///< Identifier for the text's glyphs.
RoleCount ///< Number of all roles in this skinlet.
2023-02-17 14:22:40 +00:00
};
protected:
2023-02-17 16:46:52 +00:00
/// @brief Getter for the number of samples in this skinlet.
/// @param skinnable The skinnable object.
/// @param subControl The skinnable object's subcontrol.
/// @returns Returns the number of samples.
/// @retval Returns 1 since each subcontrol a sample;
int sampleCount(
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl ) const override;
/// @brief Getter for a subcontrol's sample rectangle.
/// @param skinnable The skinnable object.
/// @param rect The skinnable object's content rectangle.
/// @param subControl The skinnable object's subcontrol.
/// @param index The skinnable object's subcontrol sample index.
/// @returns Returns the subcontrol's rectangle within the @p skinnable's content rectangle.
QRectF sampleRect( const QskSkinnable* skinnable, const QRectF& rect,
QskAspect::Subcontrol subControl, int index ) const override;
/// @brief Getter for a subcontrol's sample states.
/// @param skinnable The skinnable object.
/// @param subControl The skinnable object's subcontrol.
/// @param index The skinnable object's subcontrol sample index.
/// @return Returns the states of the subcontrol's sample at the given @p index.
/// @details Sets or unsets the @c pressed, @c hovered, @c focused bits in the returned states
/// object.
2023-02-17 14:22:40 +00:00
QskAspect::States sampleStates(
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl, int index ) const override;
2023-02-17 16:46:52 +00:00
/// @brief Getter for the skinnable object's size hints.
/// @param skinnable The skinnable object.
/// @param sizeHint The size hint.
/// @param rect The skinnable object's available rectangle.
/// @details Calculates the minimum, maximum and preferred size of the skinnable.
QSizeF sizeHint(
const QskSkinnable* skinnable, Qt::SizeHint sizeHint, const QSizeF& rect ) const override;
/// @brief Getter for the subcontrol's rectangle.
/// @param skinnable The skinnable object.
/// @param rect The skinnable object's content rectangle.
/// @param subControl The skinnable object's subcontrol.
/// @returns Returns the subcontrol's rectangle in the skinnable's content rectangle.
QRectF subControlRect( const QskSkinnable* skinnable, const QRectF& rect,
QskAspect::Subcontrol subControl ) const override;
/// @brief Updates the scene graph @p node for the given @p role
/// @param skinnable The skinnable object.
/// @param role The node's role number ( see: QskSpinBoxSkinlet::NodeRole ).
/// @param node The scene graph node for the given @p role.
/// @returns Returns a new or updated scene graph node for the given @p role.
/// @details This functions updates the text nodes and mediates updates for sampled
/// subcontrols to QskSpinBoxSkinlet::updateSampleNode.
/// @see QskSpinBoxSkinlet::NodeRole
QSGNode* updateSubNode(
const QskSkinnable* skinnable, quint8 role, QSGNode* node ) const override;
/// @brief Updates the scene graph @p node for the given @p subControl's sample @p index
/// @param skinnable The skinnable object.
/// @param subControl The skinnable object's subcontrol.
/// @param index The skinnable object's subcontrol sample index.
/// @param node The scene graph node for the @p subControl's sample @p index.
/// @returns Returns a new or updated scene graph node for the given @p subControl's sample @p
/// index.
2023-02-17 14:22:40 +00:00
QSGNode* updateSampleNode( const QskSkinnable* skinnable, QskAspect::Subcontrol subControl,
int index, QSGNode* node ) const override;
2023-02-17 11:01:56 +00:00
};
2023-02-17 13:05:05 +00:00
#endif