2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef FREE_LAYOUT_H
|
|
|
|
#define FREE_LAYOUT_H
|
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tcommon.h"
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QList>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TOONZQT_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//************************************************************************************
|
|
|
|
// DummyLayout declaration
|
|
|
|
//************************************************************************************
|
|
|
|
|
|
|
|
/*!
|
2016-06-15 18:43:10 +12:00
|
|
|
\brief The DummyLayout class implements a layout whose items' geometry is
|
|
|
|
not
|
2016-03-19 06:57:51 +13:00
|
|
|
enforced at all, ignoring parent size bounds or geometry.
|
|
|
|
|
|
|
|
\details A DummyLayout serves as a simple, inert container of layout items.
|
|
|
|
It does not enforce geometry to items added to it, allowing objects
|
|
|
|
using this layout to appear as a 'viewport' for free-geometry items.
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
\note As this layout does not effectively manage its objects' geometry,
|
|
|
|
these
|
2016-03-19 06:57:51 +13:00
|
|
|
must be managed outside.
|
|
|
|
*/
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
class DVAPI DummyLayout : public QLayout {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
DummyLayout();
|
|
|
|
virtual ~DummyLayout();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
QSize sizeHint() const override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
QSize minimumSize() const override { return QSize(0, 0); }
|
2016-06-20 14:23:05 +12:00
|
|
|
QSize maximumSize() const override {
|
|
|
|
return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
int count() const override { return m_items.count(); }
|
|
|
|
void addItem(QLayoutItem *item) override { m_items.push_back(item); }
|
|
|
|
QLayoutItem *itemAt(int index) const override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return (index < count()) ? m_items.at(index) : 0;
|
|
|
|
}
|
2016-06-19 20:06:29 +12:00
|
|
|
QLayoutItem *takeAt(int index) override {
|
2016-06-15 18:43:10 +12:00
|
|
|
return (index < count()) ? m_items.takeAt(index) : 0;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void setGeometry(const QRect &r) override {}
|
2016-06-15 18:43:10 +12:00
|
|
|
// Qt::Orientations expandingDirections () const { return
|
|
|
|
// Qt::Orientations(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
QList<QLayoutItem *> m_items;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//************************************************************************************
|
|
|
|
// FreeLayout declaration
|
|
|
|
//************************************************************************************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief The FreeLayout class implements a layout whose items can be freely
|
|
|
|
positioned, ignoring parent size bounds or geometry.
|
|
|
|
|
|
|
|
\details A FreeLayout instance can be used to achieve results similar to that
|
2016-06-15 18:43:10 +12:00
|
|
|
of a QScrollArea, with a more straightforward API and without
|
|
|
|
restriction
|
|
|
|
to just one item at a time. Please observe that layouts can be
|
|
|
|
inserted too.
|
|
|
|
|
|
|
|
Specifically, FreeLayout is a convenience subclass of DummyLayout
|
|
|
|
whose items'
|
|
|
|
sizes are enforced to their sizeHint() - in order to spare users
|
|
|
|
from having to deal
|
|
|
|
with it externally. This complies with the idea that its items are
|
|
|
|
comfortly
|
|
|
|
free to adapt to their preferred size, as it would be in a
|
|
|
|
scrollable environment.
|
2016-03-19 06:57:51 +13:00
|
|
|
*/
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class FreeLayout final : public DummyLayout {
|
2016-03-19 06:57:51 +13:00
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
FreeLayout() : DummyLayout() {}
|
|
|
|
~FreeLayout() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void setGeometry(const QRect &r) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // FREE_LAYOUT_H
|