summaryrefslogtreecommitdiffstats
path: root/tests/manual/qtabbar
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-06-27 14:41:25 -0700
committerGabriel de Dietrich <gabriel.dedietrich@qt.io>2017-07-06 00:58:17 +0000
commit462d26f265d516fc77ff28f975e4801722c6b703 (patch)
treeea274806495ce299efe396df9f644d5528e8d0ce /tests/manual/qtabbar
parenteaa54a8f9884652513c7c3ab489f31ff1e5d712c (diff)
qtabbar manual test: Improve usability
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ø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/manual/qtabbar')
-rw-r--r--tests/manual/qtabbar/main.cpp74
-rw-r--r--tests/manual/qtabbar/qtabbar.pro4
-rw-r--r--tests/manual/qtabbar/tabbarform.cpp13
-rw-r--r--tests/manual/qtabbar/tabbarform.h22
-rw-r--r--tests/manual/qtabbar/tabbarform.ui182
5 files changed, 287 insertions, 8 deletions
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 <QDesktopWidget>
#include <QTabWidget>
#include <QProxyStyle>
+#include <qdebug.h>
+#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<int>::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<QAbstractButton *>::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 a63da72158..867e06735e 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 0000000000..51271f7373
--- /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 0000000000..7db3f71fa5
--- /dev/null
+++ b/tests/manual/qtabbar/tabbarform.h
@@ -0,0 +1,22 @@
+#ifndef TABBARFORM_H
+#define TABBARFORM_H
+
+#include <QWidget>
+#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 0000000000..17100b3b62
--- /dev/null
+++ b/tests/manual/qtabbar/tabbarform.ui
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TabBarForm</class>
+ <widget class="QWidget" name="TabBarForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>308</width>
+ <height>260</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="10" column="1">
+ <widget class="QRadioButton" name="rightAlignedButton">
+ <property name="text">
+ <string>Right aligned</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string notr="true">textAlignmentGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item row="8" column="1">
+ <widget class="QRadioButton" name="leftAlignedButton">
+ <property name="text">
+ <string>Left aligned</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string notr="true">textAlignmentGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QCheckBox" name="closableTabsButton">
+ <property name="text">
+ <string>Closable tabs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Tabs alignment:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="movableTabsButton">
+ <property name="text">
+ <string>Movable tabs</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QCheckBox" name="documentModeButton">
+ <property name="text">
+ <string>Document mode</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QCheckBox" name="expandingTabsButton">
+ <property name="text">
+ <string>Expanding</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1">
+ <widget class="QComboBox" name="shapeComboBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <item>
+ <property name="text">
+ <string>North</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>South</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>West</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>East</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="7" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>12</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="5" column="1">
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>12</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Tab bar options:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="9" column="1">
+ <widget class="QRadioButton" name="centeredButton">
+ <property name="text">
+ <string>Centered</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string notr="true">textAlignmentGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Tab shape (TODO):</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QCheckBox" name="displayIconButton">
+ <property name="text">
+ <string>Display icon</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <buttongroups>
+ <buttongroup name="textAlignmentGroup"/>
+ </buttongroups>
+</ui>