qskinny/src/controls/QskSpinBox.h

93 lines
3.7 KiB
C
Raw Normal View History

2023-02-17 12:01:56 +01:00
/******************************************************************************
2023-02-17 14:05:05 +01: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 12:01:56 +01:00
*****************************************************************************/
2023-02-17 14:05:05 +01:00
#ifndef QSK_SPIN_BOX_H
#define QSK_SPIN_BOX_H
2023-02-17 12:01:56 +01:00
2023-02-17 15:22:40 +01:00
#include <QskBoundedValueInput.h>
2023-02-17 12:01:56 +01:00
2023-02-19 10:25:04 +01:00
2023-02-17 17:46:52 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief
/// This control allows the user to increment and decrement a floating point value.
/// @details
/// The incement and decrement step size is configurable and the value's range can be limited
/// through an inclusive interval [min,max]. The value is being displayed on a readonly text label
/// surrounded by an increment and decrement button.
///
/// - The value can be increased by:
/// - clicking the increment button
/// - pressing the plus, right or up key
/// - scrolling up the mouse wheel
/// - focusing the increment button and clicking space or select
/// - The value can be decreased by:
/// - clicking the decrement button
/// - pressing the minus, left or down key
/// - scrolling down the mouse wheel
/// - focusing the decrement button and clicking space or select
////////////////////////////////////////////////////////////////////////////////////////////////////
class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
2023-02-17 12:01:56 +01:00
{
2023-02-17 15:22:40 +01:00
Q_OBJECT
using Inherited = QskBoundedValueInput;
public:
2023-02-17 17:46:52 +01:00
/// Focus indeces for the visual subcontrols
2023-02-17 15:22:40 +01:00
enum FocusIndeces : int
{
2023-02-17 17:46:52 +01:00
Decrement = 0, ///< the decrement buttons index
Textbox = 1, ///< the textbox' index
Increment = 2, ///< the increment button's index
None = 3 ///< index for when no subcontrol is focused (e.g. focus in/out )
2023-02-17 15:22:40 +01:00
};
Q_ENUM( FocusIndeces )
2023-02-17 17:46:52 +01:00
/// The currently focused subcontrol's index
2023-02-17 15:22:40 +01:00
Q_PROPERTY( FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged )
2023-02-17 17:46:52 +01:00
QSK_SUBCONTROLS( IncrementPanel ) ///< Use this to style the increment button.
QSK_SUBCONTROLS( DecrementPanel ) ///< Use this to style the decrement button.
QSK_SUBCONTROLS( IncrementText ) ///< Use this to style the increment button's text.
QSK_SUBCONTROLS( DecrementText ) ///< Use this to style the decrement button's text.
QSK_SUBCONTROLS( TextPanel ) ///< Use this to style the text's panel.
QSK_SUBCONTROLS( Text ) ///< Use this to style the text (e.g. font role).
QSK_SUBCONTROLS( Layout ) ///< Use this to style the spinbox's controls layout.
2023-02-17 15:22:40 +01:00
QSK_STATES( Pressed )
2023-02-17 17:46:52 +01:00
/// @brief C-TOR
/// @param parent This object's parent
2023-02-17 15:22:40 +01:00
explicit QskSpinBox( QQuickItem* parent = nullptr );
2023-02-17 17:46:52 +01:00
/// @brief D-TOR defaulted but required for std::unique_ptr
2023-02-17 15:22:40 +01:00
~QskSpinBox() override;
2023-02-17 17:46:52 +01:00
/// @brief Getter for property focusIndex.
/// @returns Returns the currently focused subcontrol's index.
/// @retval Return FocusIndeces::None if no subcontrol is currently focused.
2023-02-17 15:22:40 +01:00
FocusIndeces focusIndex() const;
Q_SIGNALS:
2023-02-17 17:46:52 +01:00
/// @brief Emitted when the property @c focusIndex changed.
2023-02-17 15:22:40 +01:00
void focusIndexChanged( int index );
private:
void hoverEnterEvent( QHoverEvent* event ) override;
void hoverLeaveEvent( QHoverEvent* event ) override;
void hoverMoveEvent( QHoverEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
void keyPressEvent( QKeyEvent* event ) override;
void keyReleaseEvent( QKeyEvent* event ) override;
void focusInEvent( QFocusEvent* event ) override;
QRectF focusIndicatorRect() const override;
class PrivateData;
std::unique_ptr< PrivateData > m_data;
2023-02-17 12:01:56 +01:00
};
2023-02-17 14:05:05 +01:00
#endif