forked from qt-creator/qt-creator
Layouting: Add some support for spin boxes
Change-Id: I5eff963cf605f5239a96daee924e91b2c170f506 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QStackedLayout>
|
||||
#include <QSpacerItem>
|
||||
#include <QSpinBox>
|
||||
#include <QSplitter>
|
||||
#include <QStyle>
|
||||
#include <QTabWidget>
|
||||
@@ -559,6 +560,12 @@ PushButton::PushButton(std::initializer_list<LayoutItem> items)
|
||||
setupWidget<QPushButton>(this);
|
||||
}
|
||||
|
||||
SpinBox::SpinBox(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
this->subItems = items;
|
||||
setupWidget<QSpinBox>(this);
|
||||
}
|
||||
|
||||
TextEdit::TextEdit(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
this->subItems = items;
|
||||
@@ -630,17 +637,6 @@ LayoutItem title(const QString &title)
|
||||
};
|
||||
}
|
||||
|
||||
LayoutItem onClicked(const std::function<void ()> &func, QObject *guard)
|
||||
{
|
||||
return [func, guard](QObject *target) {
|
||||
if (auto button = qobject_cast<QAbstractButton *>(target)) {
|
||||
QObject::connect(button, &QAbstractButton::clicked, guard ? guard : target, func);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
LayoutItem text(const QString &text)
|
||||
{
|
||||
return [text](QObject *target) {
|
||||
@@ -698,6 +694,43 @@ LayoutItem columnStretch(int column, int stretch)
|
||||
};
|
||||
}
|
||||
|
||||
// Signals
|
||||
|
||||
LayoutItem onClicked(const std::function<void ()> &func, QObject *guard)
|
||||
{
|
||||
return [func, guard](QObject *target) {
|
||||
if (auto button = qobject_cast<QAbstractButton *>(target)) {
|
||||
QObject::connect(button, &QAbstractButton::clicked, guard ? guard : target, func);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
LayoutItem onTextChanged(const std::function<void (const QString &)> &func, QObject *guard)
|
||||
{
|
||||
return [func, guard](QObject *target) {
|
||||
if (auto button = qobject_cast<QSpinBox *>(target)) {
|
||||
QObject::connect(button, &QSpinBox::textChanged, guard ? guard : target, func);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
LayoutItem onValueChanged(const std::function<void (int)> &func, QObject *guard)
|
||||
{
|
||||
return [func, guard](QObject *target) {
|
||||
if (auto button = qobject_cast<QSpinBox *>(target)) {
|
||||
QObject::connect(button, &QSpinBox::valueChanged, guard ? guard : target, func);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Convenience
|
||||
|
||||
QWidget *createHr(QWidget *parent)
|
||||
{
|
||||
auto frame = new QFrame(parent);
|
||||
|
||||
@@ -143,6 +143,12 @@ public:
|
||||
PushButton(std::initializer_list<LayoutItem> items);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT SpinBox : public LayoutItem
|
||||
{
|
||||
public:
|
||||
SpinBox(std::initializer_list<LayoutItem> items);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Splitter : public LayoutItem
|
||||
{
|
||||
public:
|
||||
@@ -193,8 +199,15 @@ QTCREATOR_UTILS_EXPORT LayoutItem resize(int, int);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem columnStretch(int column, int stretch);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem spacing(int);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem windowTitle(const QString &windowTitle);
|
||||
|
||||
// "Signals"
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onClicked(const std::function<void()> &,
|
||||
QObject *guard = nullptr);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onTextChanged(const std::function<void(const QString &)> &,
|
||||
QObject *guard = nullptr);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onValueChanged(const std::function<void(int)> &,
|
||||
QObject *guard = nullptr);
|
||||
|
||||
// Convenience
|
||||
|
||||
|
||||
Reference in New Issue
Block a user