forked from qt-creator/qt-creator
Utils: Introduce a Layouting::WithFormAlignment AttachType
Useful for layouts that should appear as forms but are using QGridLayout for further alignment in the fields as e.g. the Kit settings does. Change-Id: Iec3195b1528dfe052eed5a34379a946db6bf8e54 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -227,6 +227,7 @@ static void flushPendingFormItems(QFormLayout *formLayout,
|
||||
|
||||
static void doLayoutHelper(QLayout *layout,
|
||||
const LayoutBuilder::LayoutItems &items,
|
||||
const Layouting::AttachType attachType,
|
||||
int currentGridRow = 0)
|
||||
{
|
||||
int currentGridColumn = 0;
|
||||
@@ -252,15 +253,15 @@ static void doLayoutHelper(QLayout *layout,
|
||||
QWidget *widget = item.widget;
|
||||
|
||||
if (gridLayout) {
|
||||
Qt::Alignment align;
|
||||
if (item.align == LayoutBuilder::AlignmentType::AlignAsFormLabel)
|
||||
Qt::Alignment align = {};
|
||||
if (attachType == Layouting::WithFormAlignment && currentGridColumn == 0)
|
||||
align = Qt::Alignment(widget->style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
|
||||
if (widget)
|
||||
gridLayout->addWidget(widget, currentGridRow, currentGridColumn, 1, item.span, align);
|
||||
else if (item.layout)
|
||||
gridLayout->addLayout(item.layout, currentGridRow, currentGridColumn, 1, item.span, align);
|
||||
else if (!item.text.isEmpty())
|
||||
gridLayout->addWidget(new QLabel(item.text));
|
||||
gridLayout->addWidget(new QLabel(item.text), currentGridRow, currentGridColumn, 1, 1, align);
|
||||
currentGridColumn += item.span;
|
||||
} else if (boxLayout) {
|
||||
addItemToBoxLayout(boxLayout, item);
|
||||
@@ -280,7 +281,7 @@ static void doLayoutHelper(QLayout *layout,
|
||||
LayoutBuilder::LayoutItem::LayoutItem(const LayoutBuilder &builder)
|
||||
{
|
||||
layout = builder.createLayout();
|
||||
doLayoutHelper(layout, builder.m_items);
|
||||
doLayoutHelper(layout, builder.m_items, Layouting::WithoutMargins);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -384,7 +385,7 @@ void LayoutBuilder::doLayout(QWidget *parent, Layouting::AttachType attachType)
|
||||
QLayout *layout = createLayout();
|
||||
parent->setLayout(layout);
|
||||
|
||||
doLayoutHelper(layout, m_items);
|
||||
doLayoutHelper(layout, m_items, attachType);
|
||||
if (attachType == Layouting::WithoutMargins)
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
@@ -424,8 +425,8 @@ QWidget *LayoutBuilder::emerge(Layouting::AttachType attachType)
|
||||
new items will be added below existing ones.
|
||||
*/
|
||||
|
||||
LayoutExtender::LayoutExtender(QLayout *layout)
|
||||
: m_layout(layout)
|
||||
LayoutExtender::LayoutExtender(QLayout *layout, Layouting::AttachType attachType)
|
||||
: m_layout(layout), m_attachType(attachType)
|
||||
{}
|
||||
|
||||
LayoutExtender::~LayoutExtender()
|
||||
@@ -434,7 +435,7 @@ LayoutExtender::~LayoutExtender()
|
||||
int currentGridRow = 0;
|
||||
if (auto gridLayout = qobject_cast<QGridLayout *>(m_layout))
|
||||
currentGridRow = gridLayout->rowCount();
|
||||
doLayoutHelper(m_layout, m_items, currentGridRow);
|
||||
doLayoutHelper(m_layout, m_items, m_attachType, currentGridRow);
|
||||
}
|
||||
|
||||
// Special items
|
||||
@@ -462,12 +463,6 @@ LayoutBuilder::Span::Span(int span_, const LayoutItem &item)
|
||||
span = span_;
|
||||
}
|
||||
|
||||
LayoutBuilder::AlignAsFormLabel::AlignAsFormLabel(const LayoutItem &item)
|
||||
{
|
||||
LayoutBuilder::LayoutItem::operator=(item);
|
||||
align = AlignmentType::AlignAsFormLabel;
|
||||
}
|
||||
|
||||
namespace Layouting {
|
||||
|
||||
// "Widgets"
|
||||
|
@@ -48,6 +48,7 @@ namespace Layouting {
|
||||
enum AttachType {
|
||||
WithMargins,
|
||||
WithoutMargins,
|
||||
WithFormAlignment, // Handle Grid similar to QFormLayout, i.e. use special alignment for the first column on Mac
|
||||
};
|
||||
|
||||
} // Layouting
|
||||
@@ -93,7 +94,6 @@ public:
|
||||
|
||||
QString text; // FIXME: Use specialValue for that
|
||||
int span = 1;
|
||||
AlignmentType align = AlignmentType::DefaultAlignment;
|
||||
SpecialType specialType = SpecialType::NotSpecial;
|
||||
QVariant specialValue;
|
||||
};
|
||||
@@ -135,12 +135,6 @@ public:
|
||||
Span(int span, const LayoutItem &item);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT AlignAsFormLabel : public LayoutItem
|
||||
{
|
||||
public:
|
||||
AlignAsFormLabel(const LayoutItem &item);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Stretch : public LayoutItem
|
||||
{
|
||||
public:
|
||||
@@ -176,11 +170,12 @@ protected:
|
||||
class QTCREATOR_UTILS_EXPORT LayoutExtender : public LayoutBuilder
|
||||
{
|
||||
public:
|
||||
explicit LayoutExtender(QLayout *layout);
|
||||
explicit LayoutExtender(QLayout *layout, Layouting::AttachType attachType);
|
||||
~LayoutExtender();
|
||||
|
||||
private:
|
||||
QLayout *m_layout = nullptr;
|
||||
Layouting::AttachType m_attachType = {};
|
||||
};
|
||||
|
||||
namespace Layouting {
|
||||
@@ -236,7 +231,6 @@ public:
|
||||
|
||||
using Space = LayoutBuilder::Space;
|
||||
using Span = LayoutBuilder::Span;
|
||||
using AlignAsFormLabel = LayoutBuilder::AlignAsFormLabel;
|
||||
|
||||
using Stretch = LayoutBuilder::Stretch; // FIXME: Remove
|
||||
using Break = LayoutBuilder::Break; // FIXME: Remove
|
||||
|
@@ -771,7 +771,7 @@ void KitAspectWidget::addToLayoutWithLabel(QWidget *parent)
|
||||
emit labelLinkActivated(link);
|
||||
});
|
||||
|
||||
LayoutExtender builder(parent->layout());
|
||||
LayoutExtender builder(parent->layout(), Layouting::WithFormAlignment);
|
||||
builder.finishRow();
|
||||
builder.addItem(label);
|
||||
addToLayout(builder);
|
||||
|
@@ -87,13 +87,10 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
|
||||
this, &KitManagerConfigWidget::setFileSystemFriendlyName);
|
||||
|
||||
using namespace Layouting;
|
||||
Grid{AlignAsFormLabel(label),
|
||||
m_nameEdit,
|
||||
m_iconButton,
|
||||
br,
|
||||
AlignAsFormLabel(fsLabel),
|
||||
m_fileSystemFriendlyNameLineEdit}
|
||||
.attachTo(this);
|
||||
Grid {
|
||||
label, m_nameEdit, m_iconButton, br,
|
||||
fsLabel, m_fileSystemFriendlyNameLineEdit
|
||||
}.attachTo(this, WithFormAlignment);
|
||||
|
||||
m_iconButton->setToolTip(tr("Kit icon."));
|
||||
auto setIconAction = new QAction(tr("Select Icon..."), this);
|
||||
|
Reference in New Issue
Block a user