2020-09-18 12:11:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QString>
|
2021-03-02 12:48:46 +01:00
|
|
|
#include <QVariant>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QLayout;
|
|
|
|
|
class QWidget;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
class BaseAspect;
|
2021-03-18 18:23:21 +01:00
|
|
|
class BoolAspect;
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutBuilder
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-02-18 14:18:34 +01:00
|
|
|
enum LayoutType {
|
2021-03-11 19:02:42 +01:00
|
|
|
HBoxLayout,
|
|
|
|
|
VBoxLayout,
|
|
|
|
|
FormLayout,
|
|
|
|
|
GridLayout,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class AlignmentType {
|
|
|
|
|
DefaultAlignment,
|
|
|
|
|
AlignAsFormLabel,
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
2020-10-08 07:24:19 +02:00
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
enum class SpecialType {
|
|
|
|
|
NotSpecial,
|
|
|
|
|
Space,
|
|
|
|
|
Stretch,
|
|
|
|
|
Break,
|
2021-03-11 19:02:42 +01:00
|
|
|
Title,
|
2021-03-02 12:48:46 +01:00
|
|
|
};
|
|
|
|
|
|
2020-09-25 14:58:04 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutItem
|
2020-09-18 12:11:40 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-21 09:39:54 +02:00
|
|
|
LayoutItem();
|
2021-03-11 19:02:42 +01:00
|
|
|
LayoutItem(QLayout *layout);
|
|
|
|
|
LayoutItem(QWidget *widget);
|
|
|
|
|
LayoutItem(BaseAspect *aspect); // Remove
|
|
|
|
|
LayoutItem(BaseAspect &aspect);
|
|
|
|
|
LayoutItem(const QString &text);
|
|
|
|
|
LayoutItem(const LayoutBuilder &builder);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QLayout *layout = nullptr;
|
|
|
|
|
QWidget *widget = nullptr;
|
|
|
|
|
BaseAspect *aspect = nullptr;
|
2021-03-11 19:02:42 +01:00
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
QString text; // FIXME: Use specialValue for that
|
2020-09-18 12:11:40 +02:00
|
|
|
int span = 1;
|
2021-03-11 19:02:42 +01:00
|
|
|
AlignmentType align = AlignmentType::DefaultAlignment;
|
2021-03-02 12:48:46 +01:00
|
|
|
SpecialType specialType = SpecialType::NotSpecial;
|
|
|
|
|
QVariant specialValue;
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using LayoutItems = QList<LayoutItem>;
|
|
|
|
|
|
|
|
|
|
explicit LayoutBuilder(LayoutType layoutType, const LayoutItems &items = {});
|
|
|
|
|
|
|
|
|
|
LayoutBuilder(const LayoutBuilder &) = delete;
|
|
|
|
|
LayoutBuilder(LayoutBuilder &&) = default;
|
|
|
|
|
LayoutBuilder &operator=(const LayoutBuilder &) = delete;
|
|
|
|
|
LayoutBuilder &operator=(LayoutBuilder &&) = default;
|
|
|
|
|
|
|
|
|
|
~LayoutBuilder();
|
|
|
|
|
|
2020-09-18 04:54:41 +02:00
|
|
|
LayoutBuilder &addItem(const LayoutItem &item);
|
2021-02-18 14:18:34 +01:00
|
|
|
LayoutBuilder &addItems(const LayoutItems &items);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2020-09-18 04:54:41 +02:00
|
|
|
LayoutBuilder &finishRow();
|
2020-09-18 12:11:40 +02:00
|
|
|
LayoutBuilder &addRow(const LayoutItem &item);
|
2021-02-18 14:18:34 +01:00
|
|
|
LayoutBuilder &addRow(const LayoutItems &items);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
LayoutType layoutType() const { return m_layoutType; }
|
2021-02-18 14:18:34 +01:00
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
void attachTo(QWidget *w, bool withMargins = true);
|
|
|
|
|
QWidget *emerge(bool withMargins = true);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Space : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Space(int space);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Span : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Span(int span, const LayoutItem &item);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT AlignAsFormLabel : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AlignAsFormLabel(const LayoutItem &item);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Stretch : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Stretch(int stretch = 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Break : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Break();
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Title : public LayoutItem
|
2021-03-02 12:48:46 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-18 18:23:21 +01:00
|
|
|
explicit Title(const QString &title, BoolAspect *check = nullptr);
|
2021-03-02 12:48:46 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
protected:
|
|
|
|
|
explicit LayoutBuilder(); // Adds to existing layout.
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
void doLayout(QWidget *parent);
|
|
|
|
|
|
|
|
|
|
LayoutItems m_items;
|
|
|
|
|
LayoutType m_layoutType;
|
|
|
|
|
bool m_withMargins = false;
|
|
|
|
|
};
|
2021-02-18 14:18:34 +01:00
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutExtender : public LayoutBuilder
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-11 19:02:42 +01:00
|
|
|
explicit LayoutExtender(QLayout *layout);
|
|
|
|
|
~LayoutExtender();
|
2021-02-18 14:18:34 +01:00
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
private:
|
|
|
|
|
QLayout *m_layout = nullptr;
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
namespace Layouting {
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Group : public LayoutBuilder::LayoutItem
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-11 19:02:42 +01:00
|
|
|
Group(std::initializer_list<LayoutBuilder::LayoutItem> items);
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Column : public LayoutBuilder
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-17 08:46:15 +01:00
|
|
|
Column() : LayoutBuilder(VBoxLayout) {}
|
2021-03-11 19:02:42 +01:00
|
|
|
Column(std::initializer_list<LayoutItem> items) : LayoutBuilder(VBoxLayout, items) {}
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Row : public LayoutBuilder
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-17 08:46:15 +01:00
|
|
|
Row() : LayoutBuilder(HBoxLayout) {}
|
2021-03-11 19:02:42 +01:00
|
|
|
Row(std::initializer_list<LayoutItem> items) : LayoutBuilder(HBoxLayout, items) {}
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Grid : public LayoutBuilder
|
2021-02-18 14:18:34 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-17 08:46:15 +01:00
|
|
|
Grid() : LayoutBuilder(GridLayout) {}
|
2021-03-11 19:02:42 +01:00
|
|
|
Grid(std::initializer_list<LayoutItem> items) : LayoutBuilder(GridLayout, items) {}
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-11 19:02:42 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Form : public LayoutBuilder
|
2021-03-02 12:48:46 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2021-03-17 08:46:15 +01:00
|
|
|
Form() : LayoutBuilder(FormLayout) {}
|
2021-03-11 19:02:42 +01:00
|
|
|
Form(std::initializer_list<LayoutItem> items) : LayoutBuilder(FormLayout, items) {}
|
2021-03-02 12:48:46 +01:00
|
|
|
};
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
using Stretch = LayoutBuilder::Stretch;
|
|
|
|
|
using Space = LayoutBuilder::Space;
|
2021-03-11 19:02:42 +01:00
|
|
|
using Span = LayoutBuilder::Span;
|
|
|
|
|
using AlignAsFormLabel = LayoutBuilder::AlignAsFormLabel;
|
2021-02-18 14:18:34 +01:00
|
|
|
using Break = LayoutBuilder::Break;
|
2021-03-02 12:48:46 +01:00
|
|
|
using Title = LayoutBuilder::Title;
|
2021-02-18 14:18:34 +01:00
|
|
|
|
|
|
|
|
}
|
2020-09-18 12:11:40 +02:00
|
|
|
} // namespace Utils
|