qskinny/src/controls/QskQuickItem.h

203 lines
5.4 KiB
C
Raw Normal View History

2019-09-04 06:59:43 +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_QUICK_ITEM_H
#define QSK_QUICK_ITEM_H
#include "QskGlobal.h"
#include <qquickitem.h>
class QskQuickItemPrivate;
class QskGeometryChangeEvent;
class QskWindowChangeEvent;
class QSK_EXPORT QskQuickItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
2021-02-02 10:15:01 +01:00
Q_PROPERTY( QRectF rect READ rect )
2019-09-04 06:59:43 +02:00
Q_PROPERTY( bool transparentForPositioners READ isTransparentForPositioner
WRITE setTransparentForPositioner NOTIFY itemFlagsChanged )
Q_PROPERTY( bool tabFence READ isTabFence
WRITE setTabFence NOTIFY itemFlagsChanged )
Q_PROPERTY( bool polishOnResize READ polishOnResize
WRITE setPolishOnResize NOTIFY itemFlagsChanged FINAL )
2021-02-01 10:09:37 +01:00
Q_PROPERTY( bool visibleToParent READ isVisibleToParent )
Q_PROPERTY( bool hasChildItems READ hasChildItems )
Q_PROPERTY( bool initiallyPainted READ isInitiallyPainted )
Q_PROPERTY( UpdateFlags updateFlags READ updateFlags NOTIFY updateFlagsChanged )
2019-09-04 06:59:43 +02:00
using Inherited = QQuickItem;
public:
2021-02-09 08:13:20 +01:00
enum UpdateFlag
2019-09-04 06:59:43 +02:00
{
DeferredUpdate = 1 << 0,
DeferredPolish = 1 << 1,
DeferredLayout = 1 << 2,
CleanupOnVisibility = 1 << 3,
PreferRasterForTextures = 1 << 4,
2021-02-02 10:15:01 +01:00
DebugForceBackground = 1 << 7
2019-09-04 06:59:43 +02:00
};
2021-02-09 08:13:20 +01:00
Q_ENUM( UpdateFlag )
Q_DECLARE_FLAGS( UpdateFlags, UpdateFlag )
2019-09-04 06:59:43 +02:00
~QskQuickItem() override;
const char* className() const;
bool isVisibleTo( const QQuickItem* ) const;
2019-09-06 19:56:03 +02:00
bool isVisibleToParent() const;
2019-09-04 06:59:43 +02:00
2020-12-27 16:08:18 +01:00
bool hasChildItems() const;
2019-09-04 06:59:43 +02:00
QRectF rect() const;
2020-01-17 13:58:15 +01:00
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
2019-09-04 06:59:43 +02:00
QSizeF size() const;
2020-01-17 13:58:15 +01:00
#endif
2019-09-04 06:59:43 +02:00
QSizeF implicitSize() const;
void setGeometry( qreal x, qreal y, qreal width, qreal height );
2021-01-25 11:04:25 +01:00
QRectF geometry() const;
2019-09-04 06:59:43 +02:00
void setPolishOnResize( bool );
bool polishOnResize() const;
void setTransparentForPositioner( bool );
bool isTransparentForPositioner() const;
void setTabFence( bool );
bool isTabFence() const;
void setLayoutMirroring( bool on, bool childrenInherit = false );
2019-09-04 06:59:43 +02:00
void resetLayoutMirroring();
bool layoutMirroring() const;
2021-02-09 08:13:20 +01:00
void resetUpdateFlags();
UpdateFlags updateFlags() const;
2019-09-04 06:59:43 +02:00
2021-02-09 08:13:20 +01:00
Q_INVOKABLE void setUpdateFlag( UpdateFlag, bool on = true );
Q_INVOKABLE void resetUpdateFlag( UpdateFlag );
Q_INVOKABLE bool testUpdateFlag( UpdateFlag ) const;
2019-09-04 06:59:43 +02:00
void classBegin() override;
void componentComplete() override;
void releaseResources() override;
bool isPolishScheduled() const;
bool isUpdateNodeScheduled() const;
bool isInitiallyPainted() const;
bool maybeUnresized() const;
Q_SIGNALS:
void itemFlagsChanged();
2021-02-09 08:13:20 +01:00
void updateFlagsChanged( UpdateFlags );
2019-09-04 06:59:43 +02:00
public Q_SLOTS:
void setGeometry( const QRectF& );
void show();
void hide();
2021-02-15 09:17:29 +01:00
void setHidden( bool );
void setDisabled( bool );
2019-09-04 06:59:43 +02:00
void resetImplicitSize();
2021-02-15 09:17:29 +01:00
#ifdef Q_MOC_RUN
// methods from QQuickItem, we want to be available as string based slots
void setVisible( bool );
void setEnabled( bool );
#endif
2019-09-04 06:59:43 +02:00
protected:
QskQuickItem( QskQuickItemPrivate&, QQuickItem* = nullptr );
bool event( QEvent* ) override;
virtual void changeEvent( QEvent* );
virtual void geometryChangeEvent( QskGeometryChangeEvent* );
virtual void windowChangeEvent( QskWindowChangeEvent* );
2021-08-04 09:31:16 +02:00
void mouseUngrabEvent() override;
void touchUngrabEvent() override;
2021-03-02 17:09:38 +01:00
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
void windowDeactivateEvent() override;
2021-03-02 17:09:38 +01:00
#endif
2019-09-04 06:59:43 +02:00
void itemChange( ItemChange, const ItemChangeData& ) override;
2020-10-26 17:59:19 +01:00
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
void geometryChange( const QRectF&, const QRectF& ) override;
#else
// using geometryChange also for Qt5
void geometryChanged( const QRectF&, const QRectF& ) override final;
virtual void geometryChange( const QRectF&, const QRectF& );
#endif
2019-09-04 06:59:43 +02:00
virtual void aboutToShow(); // called in updatePolish
private:
// don't use boundingRect - it seems to be deprecated
QRectF boundingRect() const override final { return rect(); }
/*
childrenRect()/childrenRectChanged does not make much sense
in a system, where the parent is responsible for laying out
its children.
*/
void childrenRect() = delete;
2021-02-09 08:13:20 +01:00
void applyUpdateFlag( UpdateFlag, bool on );
2019-09-23 16:59:48 +02:00
void sendEnabledChangeEvent();
2019-09-04 06:59:43 +02:00
QSGNode* updatePaintNode( QSGNode*, UpdatePaintNodeData* ) override final;
virtual QSGNode* updateItemPaintNode( QSGNode* );
void updatePolish() override final;
virtual void updateItemPolish();
Q_DECLARE_PRIVATE( QskQuickItem )
};
2020-12-27 16:08:18 +01:00
inline bool QskQuickItem::hasChildItems() const
{
return !childItems().isEmpty();
}
2019-09-04 06:59:43 +02:00
inline void QskQuickItem::setGeometry( const QRectF& rect )
{
setGeometry( rect.x(), rect.y(), rect.width(), rect.height() );
}
2020-01-17 13:58:15 +01:00
#if QT_VERSION < QT_VERSION_CHECK( 5, 10, 0 )
2019-09-04 06:59:43 +02:00
inline QSizeF QskQuickItem::size() const
{
return QSizeF( width(), height() );
}
2020-01-17 13:58:15 +01:00
#endif
2019-09-04 06:59:43 +02:00
inline QSizeF QskQuickItem::implicitSize() const
{
return QSizeF( implicitWidth(), implicitHeight() );
}
2021-02-09 08:13:20 +01:00
Q_DECLARE_OPERATORS_FOR_FLAGS( QskQuickItem::UpdateFlags )
Q_DECLARE_METATYPE( QskQuickItem::UpdateFlags )
2019-09-04 06:59:43 +02:00
#endif