mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 08:15:30 +08:00
qt 6.5.1 original
This commit is contained in:
18
tests/manual/qtabbar/CMakeLists.txt
Normal file
18
tests/manual/qtabbar/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## qtabbar Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_manual_test(tst_manual_qtabbar
|
||||
GUI
|
||||
SOURCES
|
||||
main.cpp
|
||||
tabbarform.cpp tabbarform.h tabbarform.ui
|
||||
LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
ENABLE_AUTOGEN_TOOLS
|
||||
uic
|
||||
)
|
192
tests/manual/qtabbar/main.cpp
Normal file
192
tests/manual/qtabbar/main.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
// Copyright (C) 2020 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QStackedWidget>
|
||||
#include <QMap>
|
||||
#include <QTabBar>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QTabWidget>
|
||||
#include <QProxyStyle>
|
||||
#include <qdebug.h>
|
||||
#include "tabbarform.h"
|
||||
|
||||
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 alignment;
|
||||
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
|
||||
Qt::Alignment alignment;
|
||||
};
|
||||
|
||||
const int TabCount = 5;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
auto *proxyStyle = new TabBarProxyStyle;
|
||||
app.setStyle(proxyStyle);
|
||||
|
||||
QWidget widget;
|
||||
QStackedWidget stackedWidget;
|
||||
QTabBar tabBar;
|
||||
tabBar.setDocumentMode(true);
|
||||
tabBar.setTabsClosable(true);
|
||||
tabBar.setMovable(true);
|
||||
tabBar.setExpanding(false);
|
||||
|
||||
// top
|
||||
tabBar.setShape(QTabBar::RoundedNorth);
|
||||
// bottom
|
||||
// tabBar.setShape(QTabBar::RoundedSouth);
|
||||
// left
|
||||
// tabBar.setShape(QTabBar::RoundedWest);
|
||||
// right
|
||||
// tabBar.setShape(QTabBar::RoundedEast);
|
||||
|
||||
const auto shortLabel = QStringLiteral("Tab %1");
|
||||
const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");
|
||||
|
||||
QMap<int, QWidget*> tabs;
|
||||
for (int i = 0; i < TabCount; i++) {
|
||||
QString tabNumberString = QString::number(i);
|
||||
QLabel *label = new QLabel(QStringLiteral("Tab %1 content").arg(tabNumberString));
|
||||
tabs[i] = label;
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
stackedWidget.addWidget(label);
|
||||
tabBar.addTab(shortLabel.arg(tabNumberString));
|
||||
}
|
||||
|
||||
QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
|
||||
QWidget *thisWidget = tabs[from];
|
||||
QWidget *thatWidget = tabs[to];
|
||||
tabs[from] = thatWidget;
|
||||
tabs[to] = thisWidget;
|
||||
});
|
||||
|
||||
QObject::connect(&tabBar, &QTabBar::currentChanged, [&stackedWidget, &tabs](int index) {
|
||||
if (index >= 0)
|
||||
stackedWidget.setCurrentWidget(tabs[index]);
|
||||
});
|
||||
|
||||
QObject::connect(&tabBar, &QTabBar::tabCloseRequested, [&stackedWidget, &tabBar, &tabs](int index) {
|
||||
QWidget *widget = tabs[index];
|
||||
tabBar.removeTab(index);
|
||||
for (int i = index + 1; i < TabCount; i++)
|
||||
tabs[i-1] = tabs[i];
|
||||
int currentIndex = tabBar.currentIndex();
|
||||
if (currentIndex >= 0)
|
||||
stackedWidget.setCurrentWidget(tabs[currentIndex]);
|
||||
delete widget;
|
||||
});
|
||||
|
||||
QLayout *layout;
|
||||
switch (tabBar.shape()) {
|
||||
case QTabBar::RoundedEast:
|
||||
case QTabBar::TriangularEast:
|
||||
tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
layout = new QHBoxLayout(&widget);
|
||||
layout->addWidget(&stackedWidget);
|
||||
layout->addWidget(&tabBar);
|
||||
break;
|
||||
case QTabBar::RoundedWest:
|
||||
case QTabBar::TriangularWest:
|
||||
tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||
layout = new QHBoxLayout(&widget);
|
||||
layout->addWidget(&tabBar);
|
||||
layout->addWidget(&stackedWidget);
|
||||
break;
|
||||
case QTabBar::RoundedNorth:
|
||||
case QTabBar::TriangularNorth:
|
||||
tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
layout = new QVBoxLayout(&widget);
|
||||
layout->addWidget(&tabBar);
|
||||
layout->addWidget(&stackedWidget);
|
||||
break;
|
||||
case QTabBar::RoundedSouth:
|
||||
case QTabBar::TriangularSouth:
|
||||
tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
layout = new QVBoxLayout(&widget);
|
||||
layout->addWidget(&stackedWidget);
|
||||
layout->addWidget(&tabBar);
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
form.ui->longLabelButton->setChecked(false);
|
||||
QObject::connect(form.ui->longLabelButton, &QCheckBox::toggled, [&] {
|
||||
const auto &label = form.ui->longLabelButton->isChecked() ? longLabel : shortLabel;
|
||||
for (int i = 0; i < tabBar.count(); i++)
|
||||
tabBar.setTabText(i, label.arg(i));
|
||||
});
|
||||
|
||||
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->setContentsMargins(12, 12, 12, 12);
|
||||
widget.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
6
tests/manual/qtabbar/qtabbar.pro
Normal file
6
tests/manual/qtabbar/qtabbar.pro
Normal file
@ -0,0 +1,6 @@
|
||||
TARGET = qtabbar
|
||||
TEMPLATE = app
|
||||
QT = core gui widgets
|
||||
SOURCES = main.cpp tabbarform.cpp
|
||||
HEADERS = tabbarform.h
|
||||
FORMS = tabbarform.ui
|
13
tests/manual/qtabbar/tabbarform.cpp
Normal file
13
tests/manual/qtabbar/tabbarform.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "tabbarform.h"
|
||||
|
||||
TabBarForm::TabBarForm(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TabBarForm)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
TabBarForm::~TabBarForm()
|
||||
{
|
||||
delete ui;
|
||||
}
|
22
tests/manual/qtabbar/tabbarform.h
Normal file
22
tests/manual/qtabbar/tabbarform.h
Normal file
@ -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 = nullptr);
|
||||
~TabBarForm();
|
||||
|
||||
Ui::TabBarForm *ui;
|
||||
};
|
||||
|
||||
#endif // TABBARFORM_H
|
189
tests/manual/qtabbar/tabbarform.ui
Normal file
189
tests/manual/qtabbar/tabbarform.ui
Normal file
@ -0,0 +1,189 @@
|
||||
<?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>308</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="7" 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="8" 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="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="0" column="1">
|
||||
<widget class="QCheckBox" name="documentModeButton">
|
||||
<property name="text">
|
||||
<string>Document mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="closableTabsButton">
|
||||
<property name="text">
|
||||
<string>Closable tabs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" 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="1" column="1">
|
||||
<widget class="QCheckBox" name="movableTabsButton">
|
||||
<property name="text">
|
||||
<string>Movable tabs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" 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="3" column="1">
|
||||
<widget class="QCheckBox" name="expandingTabsButton">
|
||||
<property name="text">
|
||||
<string>Expanding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" 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="6" 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="4" column="1">
|
||||
<widget class="QCheckBox" name="displayIconButton">
|
||||
<property name="text">
|
||||
<string>Display icon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" 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="11" 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="5" column="1">
|
||||
<widget class="QCheckBox" name="longLabelButton">
|
||||
<property name="text">
|
||||
<string>Long tab label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="textAlignmentGroup"/>
|
||||
</buttongroups>
|
||||
</ui>
|
Reference in New Issue
Block a user