2019-07-01 12:45:25 +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_LAYOUT_CHAIN_H
|
|
|
|
#define QSK_LAYOUT_CHAIN_H
|
|
|
|
|
|
|
|
#include <QskLayoutHint.h>
|
2019-07-27 10:36:52 +00:00
|
|
|
#include <qrect.h>
|
2019-07-01 12:45:25 +00:00
|
|
|
#include <qvector.h>
|
|
|
|
|
2019-07-02 16:18:15 +00:00
|
|
|
class QDebug;
|
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
class QskLayoutChain
|
|
|
|
{
|
|
|
|
public:
|
2019-07-27 10:36:52 +00:00
|
|
|
class Segment
|
2019-07-01 12:45:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline qreal end() const { return start + length; }
|
|
|
|
|
|
|
|
qreal start = 0.0;
|
|
|
|
qreal length = 0.0;
|
|
|
|
};
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
typedef QVector< Segment > Segments;
|
|
|
|
|
|
|
|
class CellData
|
2019-07-01 12:45:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-07-27 10:36:52 +00:00
|
|
|
inline bool operator==( const CellData& other ) const
|
2019-07-13 08:03:04 +00:00
|
|
|
{
|
2019-07-27 10:36:52 +00:00
|
|
|
return ( isValid == other.isValid )
|
|
|
|
&& ( canGrow == other.canGrow )
|
|
|
|
&& ( stretch == other.stretch )
|
|
|
|
&& ( hint == other.hint );
|
2019-07-13 08:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
inline bool operator!=( const CellData& other ) const
|
2019-07-13 08:03:04 +00:00
|
|
|
{
|
2019-07-27 10:36:52 +00:00
|
|
|
return !( *this == other );
|
2019-07-13 08:03:04 +00:00
|
|
|
}
|
2019-07-02 16:18:15 +00:00
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
inline qreal size( int which ) const
|
2019-07-02 16:18:15 +00:00
|
|
|
{
|
2019-07-27 10:36:52 +00:00
|
|
|
return hint.size( which );
|
2019-07-02 16:18:15 +00:00
|
|
|
}
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
inline void setSize( int which, qreal size )
|
2019-07-02 16:18:15 +00:00
|
|
|
{
|
2019-07-27 10:36:52 +00:00
|
|
|
hint.setSize( which, size );
|
2019-07-02 16:18:15 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
QskLayoutHint hint;
|
2019-07-27 10:36:52 +00:00
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
int stretch = 0;
|
|
|
|
bool canGrow = false;
|
2019-07-13 08:03:04 +00:00
|
|
|
bool isValid = false;
|
2019-07-01 12:45:25 +00:00
|
|
|
};
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
enum ExtraSpacing
|
|
|
|
{
|
|
|
|
Leading = 1 << 0,
|
|
|
|
Trailing = 1 << 1
|
|
|
|
};
|
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
QskLayoutChain();
|
|
|
|
~QskLayoutChain();
|
|
|
|
|
|
|
|
void invalidate();
|
|
|
|
|
|
|
|
void reset( int count, qreal constraint );
|
2019-07-27 10:36:52 +00:00
|
|
|
void expandCell( int index, const CellData& );
|
|
|
|
void expandCells( int start, int end, const CellData& );
|
|
|
|
void narrowCell( int index, const CellData& );
|
2019-07-01 12:45:25 +00:00
|
|
|
void finish();
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
const CellData& cell( int index ) const { return m_cells[ index ]; }
|
2019-07-02 16:18:15 +00:00
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
bool setSpacing( qreal spacing );
|
|
|
|
qreal spacing() const { return m_spacing; }
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
void setExtraSpacingAt( int extraSpacingAt ) { m_extraSpacingAt = extraSpacingAt; }
|
2019-07-01 12:45:25 +00:00
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
Segments segments( qreal size ) const;
|
2019-07-01 12:45:25 +00:00
|
|
|
QskLayoutHint boundingHint() const { return m_boundingHint; }
|
|
|
|
|
|
|
|
inline qreal constraint() const { return m_constraint; }
|
|
|
|
inline int count() const { return m_cells.size(); }
|
|
|
|
|
|
|
|
private:
|
2019-07-27 10:36:52 +00:00
|
|
|
Segments distributed( int which, qreal offset, qreal extra ) const;
|
|
|
|
Segments minimumExpanded( qreal size ) const;
|
|
|
|
Segments preferredStretched( qreal size ) const;
|
2019-07-01 12:45:25 +00:00
|
|
|
|
|
|
|
QskLayoutHint m_boundingHint;
|
2019-07-01 14:48:57 +00:00
|
|
|
qreal m_constraint = -2.0;
|
2019-07-01 12:45:25 +00:00
|
|
|
|
|
|
|
qreal m_spacing = 0;
|
2019-07-27 10:36:52 +00:00
|
|
|
int m_extraSpacingAt;
|
2019-07-01 12:45:25 +00:00
|
|
|
|
|
|
|
int m_sumStretches = 0;
|
2019-07-13 08:03:04 +00:00
|
|
|
int m_validCells = 0;
|
2019-07-27 10:36:52 +00:00
|
|
|
|
|
|
|
QVector< CellData > m_cells;
|
2019-07-01 12:45:25 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 16:18:15 +00:00
|
|
|
#ifndef QT_NO_DEBUG_STREAM
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
QDebug operator<<( QDebug, const QskLayoutChain::Segment& );
|
|
|
|
QDebug operator<<( QDebug, const QskLayoutChain::CellData& );
|
2019-07-02 16:18:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-07-27 10:36:52 +00:00
|
|
|
Q_DECLARE_TYPEINFO( QskLayoutChain::Segment, Q_MOVABLE_TYPE );
|
|
|
|
Q_DECLARE_TYPEINFO( QskLayoutChain::CellData, Q_MOVABLE_TYPE );
|
2019-07-02 16:18:15 +00:00
|
|
|
|
2019-07-01 12:45:25 +00:00
|
|
|
#endif
|