2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_CONTROL_H
|
2019-09-04 06:59:43 +02:00
|
|
|
#define QSK_CONTROL_H
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-04 06:59:43 +02:00
|
|
|
#include "QskQuickItem.h"
|
|
|
|
#include "QskSkinnable.h"
|
2018-08-03 08:15:28 +02:00
|
|
|
#include "QskAspect.h"
|
2017-10-17 17:34:00 +02:00
|
|
|
#include "QskGradient.h"
|
2018-05-08 10:34:00 +02:00
|
|
|
#include "QskSizePolicy.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-07-19 14:10:48 +02:00
|
|
|
#include <qlocale.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class QskControlPrivate;
|
|
|
|
class QskGestureEvent;
|
|
|
|
|
2019-09-04 06:59:43 +02:00
|
|
|
class QSK_EXPORT QskControl : public QskQuickItem, public QskSkinnable
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY( QLocale locale READ locale
|
2021-03-08 12:25:31 +01:00
|
|
|
WRITE setLocale RESET resetLocale NOTIFY localeChanged )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
Q_PROPERTY( bool autoFillBackground READ autoFillBackground
|
2021-03-08 12:25:31 +01:00
|
|
|
WRITE setAutoFillBackground )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
Q_PROPERTY( bool autoLayoutChildren READ autoLayoutChildren
|
2021-03-08 12:25:31 +01:00
|
|
|
WRITE setAutoLayoutChildren )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-24 19:32:54 +02:00
|
|
|
Q_PROPERTY( Qt::FocusPolicy focusPolicy READ focusPolicy
|
2021-03-08 12:25:31 +01:00
|
|
|
WRITE setFocusPolicy NOTIFY focusPolicyChanged )
|
2017-10-24 19:32:54 +02:00
|
|
|
|
|
|
|
Q_PROPERTY( bool wheelEnabled READ isWheelEnabled
|
2021-03-08 12:25:31 +01:00
|
|
|
WRITE setWheelEnabled NOTIFY wheelEnabledChanged )
|
|
|
|
|
|
|
|
Q_PROPERTY( bool visibleToLayout READ isVisibleToLayout )
|
2017-10-24 19:32:54 +02:00
|
|
|
|
2020-10-28 19:35:51 +01:00
|
|
|
Q_PROPERTY( QskMargins margins READ margins
|
2017-10-30 08:48:49 +01:00
|
|
|
WRITE setMargins RESET resetMargins NOTIFY marginsChanged )
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
Q_PROPERTY( QskGradient background READ background
|
2017-10-30 12:06:19 +01:00
|
|
|
WRITE setBackground RESET resetBackground NOTIFY backgroundChanged )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
Q_PROPERTY( QskSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy )
|
2018-08-03 08:15:28 +02:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
Q_PROPERTY( QSizeF minimumSize READ minimumSize WRITE setMinimumSize )
|
|
|
|
Q_PROPERTY( QSizeF maximumSize READ maximumSize WRITE setMaximumSize )
|
|
|
|
Q_PROPERTY( QSizeF preferredSize READ preferredSize WRITE setPreferredSize )
|
2021-02-02 10:15:01 +01:00
|
|
|
Q_PROPERTY( QSizeF sizeConstraint READ sizeConstraint )
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-04 06:59:43 +02:00
|
|
|
using Inherited = QskQuickItem;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public:
|
2017-07-21 18:21:34 +02:00
|
|
|
QSK_STATES( Disabled, Hovered, Focused )
|
|
|
|
|
2019-09-05 10:46:42 +02:00
|
|
|
enum LayoutHint
|
|
|
|
{
|
|
|
|
// How to be treated by layouts
|
2020-03-10 10:30:44 +01:00
|
|
|
RetainSizeWhenHidden = 1 << 0,
|
|
|
|
|
|
|
|
/*
|
|
|
|
Adjust the item even, even when being hidden
|
|
|
|
Depending on the type of layout the value only works
|
|
|
|
in combination with RetainSizeWhenHidden
|
|
|
|
*/
|
2021-04-23 17:31:55 +02:00
|
|
|
LayoutWhenHidden = 1 << 1
|
2019-09-05 10:46:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUM( LayoutHint )
|
|
|
|
Q_DECLARE_FLAGS( LayoutHints, LayoutHint )
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QskControl( QQuickItem* parent = nullptr );
|
2018-07-31 17:32:25 +02:00
|
|
|
~QskControl() override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
void setMargins( qreal );
|
2021-08-05 11:06:14 +02:00
|
|
|
void setMargins( qreal, qreal, qreal, qreal );
|
2017-07-21 18:21:34 +02:00
|
|
|
void setMargins( const QMarginsF& );
|
|
|
|
void resetMargins();
|
|
|
|
QMarginsF margins() const;
|
|
|
|
|
|
|
|
void setBackgroundColor( const QColor& );
|
|
|
|
|
2017-10-17 17:34:00 +02:00
|
|
|
void setBackground( const QskGradient& );
|
|
|
|
void resetBackground();
|
|
|
|
QskGradient background() const;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QRectF contentsRect() const;
|
2019-04-26 18:09:59 +02:00
|
|
|
QRectF layoutRect() const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-04-26 18:09:59 +02:00
|
|
|
virtual QRectF layoutRectForSize( const QSizeF& ) const;
|
2017-07-21 18:21:34 +02:00
|
|
|
virtual QRectF gestureRect() const;
|
2020-03-13 07:39:31 +01:00
|
|
|
|
2018-01-19 10:15:29 +01:00
|
|
|
virtual QRectF focusIndicatorRect() const;
|
2020-03-16 13:17:51 +01:00
|
|
|
virtual QRectF focusIndicatorClipRect() const;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-29 12:57:03 +01:00
|
|
|
using QskSkinnable::subControlRect;
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF subControlRect( QskAspect::Subcontrol ) const;
|
2019-04-26 18:09:59 +02:00
|
|
|
QRectF subControlRect( const QSizeF&, QskAspect::Subcontrol ) const;
|
2019-04-25 14:23:39 +02:00
|
|
|
|
2020-12-29 12:57:03 +01:00
|
|
|
using QskSkinnable::subControlContentsRect;
|
|
|
|
QRectF subControlContentsRect( QskAspect::Subcontrol ) const;
|
|
|
|
QRectF subControlContentsRect( const QSizeF&, QskAspect::Subcontrol ) const;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
void setAutoFillBackground( bool );
|
|
|
|
bool autoFillBackground() const;
|
|
|
|
|
|
|
|
void setAutoLayoutChildren( bool );
|
|
|
|
bool autoLayoutChildren() const;
|
|
|
|
|
2017-10-24 19:32:54 +02:00
|
|
|
void setWheelEnabled( bool );
|
|
|
|
bool isWheelEnabled() const;
|
|
|
|
|
|
|
|
void setFocusPolicy( Qt::FocusPolicy );
|
|
|
|
Qt::FocusPolicy focusPolicy() const;
|
|
|
|
|
2018-05-08 10:34:00 +02:00
|
|
|
void setSizePolicy( QskSizePolicy::Policy, QskSizePolicy::Policy );
|
2019-06-20 11:45:32 +02:00
|
|
|
void setSizePolicy( QskSizePolicy );
|
2018-05-08 10:34:00 +02:00
|
|
|
void setSizePolicy( Qt::Orientation, QskSizePolicy::Policy );
|
|
|
|
|
2019-06-20 11:45:32 +02:00
|
|
|
QskSizePolicy sizePolicy() const;
|
2018-05-08 10:34:00 +02:00
|
|
|
QskSizePolicy::Policy sizePolicy( Qt::Orientation ) const;
|
|
|
|
|
2019-09-05 10:46:42 +02:00
|
|
|
// hints for how to be treated by layouts
|
|
|
|
void setLayoutAlignmentHint( Qt::Alignment );
|
|
|
|
Qt::Alignment layoutAlignmentHint() const;
|
|
|
|
|
2019-09-13 06:54:55 +02:00
|
|
|
void setLayoutHint( LayoutHint, bool on = true );
|
2019-09-05 10:46:42 +02:00
|
|
|
bool testLayoutHint( LayoutHint ) const;
|
|
|
|
|
|
|
|
void setLayoutHints( LayoutHints );
|
|
|
|
LayoutHints layoutHints() const;
|
|
|
|
|
2019-09-06 19:57:25 +02:00
|
|
|
bool isVisibleToLayout() const;
|
|
|
|
|
2018-05-08 10:34:00 +02:00
|
|
|
void setMinimumSize( const QSizeF& );
|
|
|
|
void setMinimumSize( qreal width, qreal height );
|
|
|
|
void setMinimumWidth( qreal width );
|
|
|
|
void setMinimumHeight( qreal height );
|
|
|
|
|
|
|
|
void setMaximumSize( const QSizeF& );
|
|
|
|
void setMaximumSize( qreal width, qreal height );
|
|
|
|
void setMaximumWidth( qreal width );
|
|
|
|
void setMaximumHeight( qreal height );
|
|
|
|
|
|
|
|
void setPreferredSize( const QSizeF& );
|
|
|
|
void setPreferredSize( qreal width, qreal height );
|
|
|
|
void setPreferredWidth( qreal width );
|
|
|
|
void setPreferredHeight( qreal height );
|
|
|
|
|
|
|
|
void setFixedSize( const QSizeF& );
|
|
|
|
void setFixedSize( qreal width, qreal height );
|
|
|
|
void setFixedWidth( qreal width );
|
|
|
|
void setFixedHeight( qreal height );
|
|
|
|
|
|
|
|
void setExplicitSizeHint( Qt::SizeHint, const QSizeF& );
|
|
|
|
void setExplicitSizeHint( Qt::SizeHint, qreal width, qreal height );
|
|
|
|
void resetExplicitSizeHint( Qt::SizeHint );
|
|
|
|
|
|
|
|
QSizeF minimumSize() const;
|
|
|
|
QSizeF maximumSize() const;
|
|
|
|
QSizeF preferredSize() const;
|
|
|
|
|
|
|
|
QSizeF explicitSizeHint( Qt::SizeHint ) const;
|
2019-07-17 17:52:15 +02:00
|
|
|
QSizeF implicitSizeHint( Qt::SizeHint, const QSizeF& constraint ) const;
|
2018-05-08 10:34:00 +02:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QSizeF sizeHint() const;
|
2019-09-10 17:01:47 +02:00
|
|
|
qreal heightForWidth( qreal width ) const;
|
|
|
|
qreal widthForHeight( qreal height ) const;
|
|
|
|
|
2019-07-17 17:52:15 +02:00
|
|
|
QSizeF effectiveSizeHint( Qt::SizeHint,
|
2019-08-09 10:15:03 +02:00
|
|
|
const QSizeF& constraint = QSizeF() ) const;
|
2018-05-01 13:55:26 +02:00
|
|
|
|
2019-09-14 15:27:04 +02:00
|
|
|
QSizeF sizeConstraint( Qt::SizeHint, const QSizeF& constraint = QSizeF() ) const;
|
|
|
|
QSizeF sizeConstraint() const;
|
2019-09-13 06:54:55 +02:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QLocale locale() const;
|
|
|
|
void resetLocale();
|
|
|
|
|
|
|
|
QVector< QskAspect::Subcontrol > subControls() const;
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
Q_SIGNALS:
|
2017-10-30 12:06:19 +01:00
|
|
|
void backgroundChanged();
|
2020-12-27 16:31:07 +01:00
|
|
|
void marginsChanged( const QMarginsF& );
|
2018-01-19 10:15:29 +01:00
|
|
|
void focusIndicatorRectChanged();
|
2017-07-21 18:21:34 +02:00
|
|
|
void localeChanged( const QLocale& );
|
2017-10-25 14:53:49 +02:00
|
|
|
void focusPolicyChanged();
|
|
|
|
void wheelEnabledChanged();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
public Q_SLOTS:
|
2017-07-21 18:21:34 +02:00
|
|
|
void setLocale( const QLocale& );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
protected:
|
2018-07-31 17:32:25 +02:00
|
|
|
bool event( QEvent* ) override;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
virtual void gestureEvent( QskGestureEvent* );
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
void hoverEnterEvent( QHoverEvent* ) override;
|
|
|
|
void hoverLeaveEvent( QHoverEvent* ) override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
bool childMouseEventFilter( QQuickItem*, QEvent* ) override;
|
2017-07-21 18:21:34 +02:00
|
|
|
virtual bool gestureFilter( QQuickItem*, QEvent* );
|
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
void itemChange( ItemChange, const ItemChangeData& ) override;
|
2020-10-26 17:59:19 +01:00
|
|
|
void geometryChange( const QRectF&, const QRectF& ) override;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-05-08 10:34:00 +02:00
|
|
|
void initSizePolicy( QskSizePolicy::Policy, QskSizePolicy::Policy );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-09-04 06:59:43 +02:00
|
|
|
// called from updatePolish
|
|
|
|
virtual void updateResources();
|
|
|
|
virtual void updateLayout();
|
2019-06-23 12:53:38 +02:00
|
|
|
|
2019-09-10 17:01:47 +02:00
|
|
|
virtual QSizeF contentsSizeHint( Qt::SizeHint, const QSizeF& ) const;
|
|
|
|
virtual QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const;
|
2019-09-05 13:09:04 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
|
|
|
void setActiveFocusOnTab( bool ) = delete; // use setFocusPolicy
|
2018-04-05 14:18:15 +02:00
|
|
|
void updateInputMethod( Qt::InputMethodQueries ) = delete; // use qskUpdateInputMethod
|
2017-10-24 19:32:54 +02:00
|
|
|
|
2019-09-04 06:59:43 +02:00
|
|
|
QSGNode* updateItemPaintNode( QSGNode* ) override final;
|
|
|
|
void updateItemPolish() override final;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-07-31 17:32:25 +02:00
|
|
|
QskControl* owningControl() const override final;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
private:
|
2017-07-21 18:21:34 +02:00
|
|
|
Q_DECLARE_PRIVATE( QskControl )
|
|
|
|
};
|
|
|
|
|
2019-09-14 15:27:04 +02:00
|
|
|
inline QSizeF QskControl::sizeConstraint() const
|
|
|
|
{
|
|
|
|
return sizeConstraint( Qt::PreferredSize, QSizeF() );
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
inline QSizeF QskControl::sizeHint() const
|
|
|
|
{
|
2018-05-01 13:55:26 +02:00
|
|
|
return effectiveSizeHint( Qt::PreferredSize );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 10:34:00 +02:00
|
|
|
inline QSizeF QskControl::minimumSize() const
|
|
|
|
{
|
2019-07-17 17:52:15 +02:00
|
|
|
return effectiveSizeHint( Qt::MinimumSize );
|
2018-05-08 10:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QSizeF QskControl::maximumSize() const
|
|
|
|
{
|
2019-07-17 17:52:15 +02:00
|
|
|
return effectiveSizeHint( Qt::MaximumSize );
|
2018-05-08 10:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline QSizeF QskControl::preferredSize() const
|
|
|
|
{
|
2019-07-17 17:52:15 +02:00
|
|
|
return effectiveSizeHint( Qt::PreferredSize );
|
2018-05-08 10:34:00 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 11:56:09 +02:00
|
|
|
inline QskControl* qskControlCast( QObject* object )
|
|
|
|
{
|
|
|
|
return qobject_cast< QskControl* >( object );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const QskControl* qskControlCast( const QObject* object )
|
|
|
|
{
|
|
|
|
return qobject_cast< const QskControl* >( object );
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
#endif
|