From 462d26f265d516fc77ff28f975e4801722c6b703 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 27 Jun 2017 14:41:25 -0700 Subject: 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 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 7 deletions(-) (limited to 'tests/manual/qtabbar/main.cpp') diff --git a/tests/manual/qtabbar/main.cpp b/tests/manual/qtabbar/main.cpp index 5a1a558c10..466a7e20fc 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(); -- cgit v1.2.3