qskinny/qmlexport/QskLayoutQml.h

95 lines
2.2 KiB
C
Raw Normal View History

2019-05-12 13:54:22 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2019-05-12 13:54:22 +02:00
*****************************************************************************/
#ifndef QSK_LAYOUT_QML_H
#define QSK_LAYOUT_QML_H
#include "QskQmlGlobal.h"
#include <QskLinearBox.h>
#include <QskGridBox.h>
2019-05-12 15:19:49 +02:00
/*
QML need methods being Q_INVOKABLE and QQuickItem parameters
need to be non const.
*/
2019-05-12 13:54:22 +02:00
template< typename LayoutBox >
class QskLayoutBoxQml : public LayoutBox
{
public:
Q_INVOKABLE bool isEmpty() const
{
return LayoutBox::isEmpty();
}
Q_INVOKABLE QQuickItem* itemAtIndex( int index ) const
{
return LayoutBox::itemAtIndex( index );
}
Q_INVOKABLE int indexOf( const QQuickItem* item ) const
{
return LayoutBox::indexOf( item );
}
2019-05-12 13:54:22 +02:00
Q_INVOKABLE void removeAt( int index )
{
return LayoutBox::removeAt( index );
}
Q_INVOKABLE void removeItem( QQuickItem* item )
{
// QML does not like a const version
LayoutBox::removeItem( item );
}
2019-05-12 15:19:49 +02:00
};
class QskLinearBoxQml : public QskLayoutBoxQml< QskLinearBox >
{
Q_OBJECT
public:
Q_INVOKABLE void setStretchFactor( QQuickItem* item, int stretchFactor )
{
QskLinearBox::setStretchFactor( item, stretchFactor );
}
Q_INVOKABLE int stretchFactor( QQuickItem* item ) const
{
return QskLinearBox::stretchFactor( item );
}
};
class QskGridBoxQml : public QskLayoutBoxQml< QskGridBox >
{
Q_OBJECT
Q_PROPERTY( qreal horizontalSpacing READ horizontalSpacing
WRITE setHorizontalSpacing RESET resetHorizontalSpacing
NOTIFY horizontalSpacingChanged )
Q_PROPERTY( qreal verticalSpacing READ verticalSpacing
WRITE setVerticalSpacing RESET resetVerticalSpacing
NOTIFY verticalSpacingChanged )
2019-05-12 15:19:49 +02:00
public:
void setHorizontalSpacing( qreal );
void resetHorizontalSpacing();
qreal horizontalSpacing() const;
void setVerticalSpacing( qreal );
void resetVerticalSpacing();
qreal verticalSpacing() const;
2019-05-12 15:19:49 +02:00
Q_SIGNALS:
void verticalSpacingChanged();
void horizontalSpacingChanged();
2019-05-12 15:19:49 +02:00
};
2019-05-12 13:54:22 +02:00
#endif