qskinny/src/layouts/QskGridBox.h

147 lines
4.3 KiB
C
Raw Normal View History

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_GRID_BOX_H
#define QSK_GRID_BOX_H
#include "QskBox.h"
2017-07-21 18:21:34 +02:00
class QSK_EXPORT QskGridBox : public QskBox
2017-07-21 18:21:34 +02:00
{
Q_OBJECT
Q_PROPERTY( Qt::Alignment defaultAlignment READ defaultAlignment
WRITE setDefaultAlignment NOTIFY defaultAlignmentChanged )
Q_PROPERTY( bool empty READ isEmpty() )
Q_PROPERTY( int count READ count )
2017-07-21 18:21:34 +02:00
using Inherited = QskBox;
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
explicit QskGridBox( QQuickItem* parent = nullptr );
2018-07-31 17:32:25 +02:00
~QskGridBox() override;
2017-07-21 18:21:34 +02:00
Q_INVOKABLE int addItem( QQuickItem*,
int row, int column, int rowSpan, int columnSpan );
2017-07-21 18:21:34 +02:00
Q_INVOKABLE int addItem( QQuickItem*, int row, int column );
2017-07-21 18:21:34 +02:00
int addItem( QQuickItem*, int row, int column, Qt::Alignment );
int addItem( QQuickItem*, int row, int column,
int rowSpan, int columnSpan, Qt::Alignment );
Q_INVOKABLE int addSpacer( const QSizeF&,
int row, int column, int columnSpan = 1, int rowSpan = 1 );
void removeItem( const QQuickItem* );
void removeAt( int index );
2017-07-21 18:21:34 +02:00
Q_INVOKABLE int rowCount() const;
Q_INVOKABLE int columnCount() const;
int count() const;
#ifdef QSK_LAYOUT_COMPAT
int itemCount() const { return count(); } // items and spacers
#endif
2019-09-13 06:52:47 +02:00
QQuickItem* itemAtIndex( int index ) const;
int indexOf( const QQuickItem* ) const;
bool isEmpty() const;
2017-07-21 18:21:34 +02:00
Q_INVOKABLE QQuickItem* itemAt( int row, int column ) const;
Q_INVOKABLE int indexAt( int row, int column ) const;
Q_INVOKABLE QRect gridOfIndex( int index ) const;
Q_INVOKABLE QRect effectiveGridOfIndex( int index ) const;
2017-07-21 18:21:34 +02:00
void setDefaultAlignment( Qt::Alignment );
Qt::Alignment defaultAlignment() const;
2017-07-21 18:21:34 +02:00
void setSpacing( Qt::Orientations, qreal spacing );
void resetSpacing( Qt::Orientations );
qreal spacing( Qt::Orientation ) const;
void setSpacing( qreal spacing );
#ifdef QSK_LAYOUT_COMPAT
void setVerticalSpacing( qreal spacing ) { setSpacing( Qt::Vertical, spacing ); }
qreal verticalSpacing() const { return spacing( Qt::Vertical ); }
void setHorizontalSpacing( qreal spacing ) { setSpacing( Qt::Horizontal, spacing ); }
qreal horizontalSpacing() const { return spacing( Qt::Horizontal ); }
2017-07-21 18:21:34 +02:00
void setActive( bool ) {}
bool isActive() const { return true; }
void setRowMinimumHeight( int row, qreal height )
{ setRowSizeHint( row, Qt::MinimumSize, height ); }
void setColumnMaximumWidth( int column, qreal width )
{ setColumnSizeHint( column, Qt::MaximumSize, width ); }
#endif
2017-07-21 18:21:34 +02:00
// stretch factors
Q_INVOKABLE void setRowStretchFactor( int row, int stretch );
Q_INVOKABLE int rowStretchFactor( int row ) const;
Q_INVOKABLE void setColumnStretchFactor( int column, int stretch );
Q_INVOKABLE int columnStretchFactor( int column ) const;
// row/column size hints
Q_INVOKABLE void setColumnSizeHint( int column, Qt::SizeHint, qreal width );
Q_INVOKABLE qreal columnSizeHint( int column, Qt::SizeHint ) const;
2017-07-21 18:21:34 +02:00
Q_INVOKABLE void setRowSizeHint( int row, Qt::SizeHint, qreal height );
Q_INVOKABLE qreal rowSizeHint( int row, Qt::SizeHint ) const;
2017-07-21 18:21:34 +02:00
Q_INVOKABLE void setRowFixedHeight( int row, qreal height );
Q_INVOKABLE void setColumnFixedWidth( int column, qreal width );
public Q_SLOTS:
void invalidate();
void clear( bool autoDelete = false );
2017-07-21 18:21:34 +02:00
Q_SIGNALS:
void defaultAlignmentChanged();
2018-08-03 08:15:28 +02:00
protected:
bool event( QEvent* ) override;
void geometryChangeEvent( QskGeometryChangeEvent* ) override;
2017-07-21 18:21:34 +02:00
void itemChange( ItemChange, const ItemChangeData& ) override;
void updateLayout() override;
2017-07-21 18:21:34 +02:00
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
2019-09-05 15:16:33 +02:00
private:
void setItemActive( QQuickItem*, bool );
2017-07-21 18:21:34 +02:00
class PrivateData;
std::unique_ptr< PrivateData > m_data;
};
inline int QskGridBox::addItem( QQuickItem* item, int row, int column )
2017-07-21 18:21:34 +02:00
{
return addItem( item, row, column, 1, 1 );
2017-07-21 18:21:34 +02:00
}
inline bool QskGridBox::isEmpty() const
{
return count() <= 0;
}
inline void QskGridBox::setSpacing( qreal spacing )
{
setSpacing( Qt::Horizontal | Qt::Vertical, spacing );
}
2017-07-21 18:21:34 +02:00
#endif