2017-07-21 16:21:34 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_LINEAR_BOX_H
|
|
|
|
#define QSK_LINEAR_BOX_H
|
|
|
|
|
|
|
|
#include "QskIndexedLayoutBox.h"
|
|
|
|
|
|
|
|
class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
Q_PROPERTY( Qt::Orientation orientation READ orientation
|
|
|
|
WRITE setOrientation NOTIFY orientationChanged FINAL )
|
|
|
|
|
|
|
|
Q_PROPERTY( uint dimension READ dimension
|
|
|
|
WRITE setDimension NOTIFY dimensionChanged FINAL )
|
|
|
|
|
|
|
|
Q_PROPERTY( qreal spacing READ spacing
|
2019-06-19 12:08:45 +00:00
|
|
|
WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL )
|
|
|
|
|
|
|
|
Q_PROPERTY( Qt::Alignment defaultAlignment READ defaultAlignment
|
|
|
|
WRITE setDefaultAlignment NOTIFY defaultAlignmentChanged )
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
Q_PROPERTY( Qt::Edges extraSpacingAt READ extraSpacingAt
|
|
|
|
WRITE setExtraSpacingAt NOTIFY extraSpacingAtChanged )
|
|
|
|
|
2020-11-11 09:31:39 +00:00
|
|
|
Q_PROPERTY( int elementCount READ elementCount )
|
2019-06-19 12:08:45 +00:00
|
|
|
Q_PROPERTY( bool empty READ isEmpty() )
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
using Inherited = QskIndexedLayoutBox;
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
public:
|
2017-07-21 16:21:34 +00:00
|
|
|
explicit QskLinearBox( QQuickItem* parent = nullptr );
|
|
|
|
explicit QskLinearBox( Qt::Orientation, QQuickItem* parent = nullptr );
|
|
|
|
|
2017-12-07 16:04:05 +00:00
|
|
|
QskLinearBox( Qt::Orientation, uint dimension, QQuickItem* parent = nullptr );
|
2018-07-31 15:32:25 +00:00
|
|
|
~QskLinearBox() override;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
bool isEmpty() const;
|
2020-11-11 09:31:39 +00:00
|
|
|
int elementCount() const; // items and spacers
|
2019-06-19 12:08:45 +00:00
|
|
|
|
2019-09-16 10:32:37 +00:00
|
|
|
qreal spacingAtIndex( int index ) const;
|
2019-07-09 12:27:50 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
QQuickItem* itemAtIndex( int index ) const;
|
|
|
|
int indexOf( const QQuickItem* ) const;
|
|
|
|
|
|
|
|
void removeItem( const QQuickItem* );
|
|
|
|
void removeAt( int index );
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
Qt::Orientation orientation() const;
|
|
|
|
void setOrientation( Qt::Orientation );
|
|
|
|
|
|
|
|
void setDimension( uint );
|
|
|
|
uint dimension() const;
|
|
|
|
|
|
|
|
void setExtraSpacingAt( Qt::Edges );
|
|
|
|
Qt::Edges extraSpacingAt() const;
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void setDefaultAlignment( Qt::Alignment );
|
|
|
|
Qt::Alignment defaultAlignment() const;
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
void setSpacing( qreal spacing );
|
|
|
|
void resetSpacing();
|
|
|
|
qreal spacing() const;
|
|
|
|
|
2019-09-05 08:46:42 +00:00
|
|
|
Q_INVOKABLE int addItem( QQuickItem* );
|
2019-09-14 13:28:49 +00:00
|
|
|
int addItem( QQuickItem*, Qt::Alignment );
|
|
|
|
|
2019-09-05 08:46:42 +00:00
|
|
|
Q_INVOKABLE int insertItem( int index, QQuickItem* );
|
2019-09-14 13:28:49 +00:00
|
|
|
int insertItem( int index, QQuickItem*, Qt::Alignment );
|
2019-06-19 12:08:45 +00:00
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
Q_INVOKABLE int addSpacer( qreal spacing, int stretchFactor = 0 );
|
|
|
|
Q_INVOKABLE int insertSpacer( int index, qreal spacing, int stretchFactor = 0 );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
Q_INVOKABLE int addStretch( int stretchFactor = 0 );
|
|
|
|
Q_INVOKABLE int insertStretch( int index, int stretchFactor = 0 );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
Q_INVOKABLE void setStretchFactor( int index, int stretchFactor );
|
|
|
|
Q_INVOKABLE int stretchFactor( int index ) const;
|
|
|
|
|
|
|
|
void setStretchFactor( const QQuickItem*, int stretchFactor );
|
|
|
|
int stretchFactor( const QQuickItem* ) const;
|
|
|
|
|
2021-01-20 15:39:15 +00:00
|
|
|
void dump() const;
|
2019-09-23 11:20:56 +00:00
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
public Q_SLOTS:
|
2017-07-21 16:21:34 +00:00
|
|
|
void transpose();
|
2019-06-19 12:08:45 +00:00
|
|
|
void activate();
|
|
|
|
void invalidate();
|
|
|
|
void clear( bool autoDelete = false );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
Q_SIGNALS:
|
2017-07-21 16:21:34 +00:00
|
|
|
void orientationChanged();
|
|
|
|
void dimensionChanged();
|
2019-06-19 12:08:45 +00:00
|
|
|
void defaultAlignmentChanged();
|
2017-07-21 16:21:34 +00:00
|
|
|
void spacingChanged();
|
|
|
|
void extraSpacingAtChanged();
|
|
|
|
|
2018-08-03 06:15:28 +00:00
|
|
|
protected:
|
2019-06-19 12:08:45 +00:00
|
|
|
bool event( QEvent* ) override;
|
|
|
|
void geometryChangeEvent( QskGeometryChangeEvent* ) override;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
void itemChange( ItemChange, const ItemChangeData& ) override;
|
|
|
|
void updateLayout() override;
|
|
|
|
|
2019-09-10 15:01:47 +00:00
|
|
|
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
2019-09-05 13:16:33 +00:00
|
|
|
|
2019-11-29 16:33:26 +00:00
|
|
|
private:
|
2019-06-19 12:08:45 +00:00
|
|
|
void autoAddItem( QQuickItem* ) override final;
|
|
|
|
void autoRemoveItem( QQuickItem* ) override final;
|
2017-07-21 16:21:34 +00:00
|
|
|
|
2019-09-14 13:40:20 +00:00
|
|
|
void setItemActive( QQuickItem*, bool );
|
2019-12-03 16:21:56 +00:00
|
|
|
void removeItemInternal( int index, bool unparent );
|
2017-07-21 16:21:34 +00:00
|
|
|
|
|
|
|
class PrivateData;
|
|
|
|
std::unique_ptr< PrivateData > m_data;
|
|
|
|
};
|
|
|
|
|
2019-06-19 12:08:45 +00:00
|
|
|
inline bool QskLinearBox::isEmpty() const
|
|
|
|
{
|
2020-11-11 09:31:39 +00:00
|
|
|
return elementCount() <= 0;
|
2019-06-19 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 16:21:34 +00:00
|
|
|
#endif
|