From 462d26f265d516fc77ff28f975e4801722c6b703 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 27 Jun 2017 14:41:25 -0700 Subject: [PATCH] qtabbar manual test: Improve usability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Covers non-document mode, tab icon, and adds a more useable interface. Some parts are still missing, like tab orientation and long tab titles. Task-number: QTBUG-61092 Change-Id: Idbda84f513e3ff7f87fa04ae4476b11bd8bb6bf2 Reviewed-by: Tor Arne Vestbø --- tests/manual/qtabbar/main.cpp | 74 +++++++++-- tests/manual/qtabbar/qtabbar.pro | 4 +- tests/manual/qtabbar/tabbarform.cpp | 13 ++ tests/manual/qtabbar/tabbarform.h | 22 ++++ tests/manual/qtabbar/tabbarform.ui | 182 ++++++++++++++++++++++++++++ 5 files changed, 287 insertions(+), 8 deletions(-) create mode 100644 tests/manual/qtabbar/tabbarform.cpp create mode 100644 tests/manual/qtabbar/tabbarform.h create mode 100644 tests/manual/qtabbar/tabbarform.ui diff --git a/tests/manual/qtabbar/main.cpp b/tests/manual/qtabbar/main.cpp index 5a1a558c10a..466a7e20fc7 100644 --- a/tests/manual/qtabbar/main.cpp +++ b/tests/manual/qtabbar/main.cpp @@ -57,19 +57,25 @@ #include #include #include +#include +#include "tabbarform.h" -class MyProxyStyle : public QProxyStyle +class TabBarProxyStyle : public QProxyStyle { public: + TabBarProxyStyle() : QProxyStyle(), alignment(Qt::AlignLeft) + { } + int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const { if (hint == QStyle::SH_TabBar_Alignment) - return Qt::AlignLeft; -// return Qt::AlignRight; -// return Qt::AlignCenter; + return alignment; + return QProxyStyle::styleHint(hint, option, widget, returnData); } + + Qt::Alignment alignment; }; const int TabCount = 5; @@ -77,7 +83,8 @@ const int TabCount = 5; int main(int argc, char *argv[]) { QApplication app(argc, argv); - app.setStyle(new MyProxyStyle); + auto *proxyStyle = new TabBarProxyStyle; + app.setStyle(proxyStyle); QWidget widget; QStackedWidget stackedWidget; @@ -161,8 +168,61 @@ int main(int argc, char *argv[]) break; } - layout->setMargin(0); - widget.resize(QApplication::desktop()->screenGeometry(&widget).size() * 0.5); + TabBarForm form; + layout->addWidget(&form); + layout->setAlignment(&form, Qt::AlignHCenter); + + form.ui->documentModeButton->setChecked(tabBar.documentMode()); + QObject::connect(form.ui->documentModeButton, &QCheckBox::toggled, [&] { + tabBar.setDocumentMode(form.ui->documentModeButton->isChecked()); + // QMacStyle (and maybe other styles) requires a re-polish to get the right font + QApplication::sendEvent(&tabBar, new QEvent(QEvent::ThemeChange)); + }); + + form.ui->movableTabsButton->setChecked(tabBar.isMovable()); + QObject::connect(form.ui->movableTabsButton, &QCheckBox::toggled, [&] { + tabBar.setMovable(form.ui->movableTabsButton->isChecked()); + tabBar.update(); + }); + + form.ui->closableTabsButton->setChecked(tabBar.tabsClosable()); + QObject::connect(form.ui->closableTabsButton, &QCheckBox::toggled, [&] { + tabBar.setTabsClosable(form.ui->closableTabsButton->isChecked()); + tabBar.update(); + }); + + form.ui->expandingTabsButton->setChecked(tabBar.expanding()); + QObject::connect(form.ui->expandingTabsButton, &QCheckBox::toggled, [&] { + tabBar.setExpanding(form.ui->expandingTabsButton->isChecked()); + tabBar.update(); + }); + + form.ui->displayIconButton->setChecked(!tabBar.tabIcon(0).isNull()); + QObject::connect(form.ui->displayIconButton, &QCheckBox::toggled, [&] { + const auto icon = form.ui->displayIconButton->isChecked() ? + tabBar.style()->standardIcon(QStyle::SP_ComputerIcon) : QIcon(); + for (int i = 0; i < tabBar.count(); i++) + tabBar.setTabIcon(i, icon); + }); + + QObject::connect(form.ui->shapeComboBox, QOverload::of(&QComboBox::currentIndexChanged), [&](int index) { + Q_UNUSED(index); + // TODO + }); + + if (proxyStyle->alignment == Qt::AlignLeft) + form.ui->leftAlignedButton->setChecked(true); + else if (proxyStyle->alignment == Qt::AlignRight) + form.ui->rightAlignedButton->setChecked(true); + else + form.ui->centeredButton->setChecked(true); + QObject::connect(form.ui->textAlignmentGroup, QOverload::of(&QButtonGroup::buttonClicked), [&](QAbstractButton *b) { + proxyStyle->alignment = b == form.ui->leftAlignedButton ? Qt::AlignLeft : + b == form.ui->rightAlignedButton ? Qt::AlignRight : Qt::AlignCenter; + QApplication::sendEvent(&tabBar, new QEvent(QEvent::StyleChange)); + }); + + layout->setMargin(12); widget.show(); return app.exec(); diff --git a/tests/manual/qtabbar/qtabbar.pro b/tests/manual/qtabbar/qtabbar.pro index a63da72158e..867e06735e0 100644 --- a/tests/manual/qtabbar/qtabbar.pro +++ b/tests/manual/qtabbar/qtabbar.pro @@ -1,4 +1,6 @@ TARGET = qtabbar TEMPLATE = app QT = core gui widgets -SOURCES = main.cpp +SOURCES = main.cpp tabbarform.cpp +HEADERS = tabbarform.h +FORMS = tabbarform.ui diff --git a/tests/manual/qtabbar/tabbarform.cpp b/tests/manual/qtabbar/tabbarform.cpp new file mode 100644 index 00000000000..51271f73736 --- /dev/null +++ b/tests/manual/qtabbar/tabbarform.cpp @@ -0,0 +1,13 @@ +#include "tabbarform.h" + +TabBarForm::TabBarForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TabBarForm) +{ + ui->setupUi(this); +} + +TabBarForm::~TabBarForm() +{ + delete ui; +} diff --git a/tests/manual/qtabbar/tabbarform.h b/tests/manual/qtabbar/tabbarform.h new file mode 100644 index 00000000000..7db3f71fa55 --- /dev/null +++ b/tests/manual/qtabbar/tabbarform.h @@ -0,0 +1,22 @@ +#ifndef TABBARFORM_H +#define TABBARFORM_H + +#include +#include "ui_tabbarform.h" + +namespace Ui { +class TabBarForm; +} + +class TabBarForm : public QWidget +{ + Q_OBJECT + +public: + explicit TabBarForm(QWidget *parent = 0); + ~TabBarForm(); + + Ui::TabBarForm *ui; +}; + +#endif // TABBARFORM_H diff --git a/tests/manual/qtabbar/tabbarform.ui b/tests/manual/qtabbar/tabbarform.ui new file mode 100644 index 00000000000..17100b3b62e --- /dev/null +++ b/tests/manual/qtabbar/tabbarform.ui @@ -0,0 +1,182 @@ + + + TabBarForm + + + + 0 + 0 + 308 + 260 + + + + + 0 + 0 + + + + Form + + + + + + + + Right aligned + + + textAlignmentGroup + + + + + + + Left aligned + + + textAlignmentGroup + + + + + + + Closable tabs + + + + + + + Tabs alignment: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Movable tabs + + + + + + + Document mode + + + + + + + Expanding + + + + + + + false + + + + North + + + + + South + + + + + West + + + + + East + + + + + + + + Qt::Vertical + + + + 20 + 12 + + + + + + + + Qt::Vertical + + + + 20 + 12 + + + + + + + + Tab bar options: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Centered + + + textAlignmentGroup + + + + + + + Tab shape (TODO): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Display icon + + + + + + + + + + + + +