work save: resizable panels

This commit is contained in:
Roy Qu 2022-05-21 17:40:52 +08:00
parent 06ee536431
commit da1647538f
4 changed files with 54 additions and 25 deletions

View File

@ -4935,6 +4935,9 @@ void MainWindow::on_tabMessages_tabBarClicked(int index)
{ {
if (index == ui->tabMessages->currentIndex()) { if (index == ui->tabMessages->currentIndex()) {
ui->tabMessages->toggleShrined(); ui->tabMessages->toggleShrined();
if (!ui->tabMessages->isShrinked()) {
resizeDocks({ui->dockMessages},{ui->tabMessages->beforeShrinkWidthOrHeight()},ui->tabMessages->shrinkOrientation());
}
} }
} }
@ -5366,9 +5369,10 @@ void MainWindow::on_actionForward_triggered()
void MainWindow::on_tabInfos_tabBarClicked(int index) void MainWindow::on_tabInfos_tabBarClicked(int index)
{ {
if (index == ui->tabInfos->currentIndex()) { if (index == ui->tabInfos->currentIndex()) {
int width = ui->tabInfos->tabBar()->width();
ui->tabInfos->toggleShrined(); ui->tabInfos->toggleShrined();
// openCloseLeftPanel(!mLeftPanelOpenned); if (!ui->tabInfos->isShrinked()) {
resizeDocks({ui->dockInfos},{ui->tabInfos->beforeShrinkWidthOrHeight()},ui->tabInfos->shrinkOrientation());
}
} }
} }
@ -7703,19 +7707,17 @@ void MainWindow::on_dockInfos_dockLocationChanged(const Qt::DockWidgetArea &area
void MainWindow::on_dockMessages_dockLocationChanged(const Qt::DockWidgetArea &area) void MainWindow::on_dockMessages_dockLocationChanged(const Qt::DockWidgetArea &area)
{ {
qDebug()<<"-----";
qDebug()<<ui->dockMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSizeHint();
switch(area) { switch(area) {
case Qt::DockWidgetArea::BottomDockWidgetArea: case Qt::DockWidgetArea::BottomDockWidgetArea:
case Qt::DockWidgetArea::TopDockWidgetArea: case Qt::DockWidgetArea::TopDockWidgetArea:
ui->splitterDebug->setOrientation(Qt::Orientation::Horizontal); ui->splitterDebug->setOrientation(Qt::Orientation::Horizontal);
ui->splitterProblem->setOrientation(Qt::Orientation::Horizontal); ui->splitterProblem->setOrientation(Qt::Orientation::Horizontal);
ui->dockMessages->setFeatures( ui->dockMessages->features() | QDockWidget::DockWidgetVerticalTitleBar);
break; break;
default: default:
ui->splitterDebug->setOrientation(Qt::Orientation::Vertical); ui->splitterDebug->setOrientation(Qt::Orientation::Vertical);
ui->splitterProblem->setOrientation(Qt::Orientation::Vertical); ui->splitterProblem->setOrientation(Qt::Orientation::Vertical);
ui->dockMessages->setFeatures( ui->dockMessages->features() & ~QDockWidget::DockWidgetVerticalTitleBar);
} }
switch(area) { switch(area) {
case Qt::DockWidgetArea::BottomDockWidgetArea: case Qt::DockWidgetArea::BottomDockWidgetArea:
@ -7734,8 +7736,5 @@ void MainWindow::on_dockMessages_dockLocationChanged(const Qt::DockWidgetArea &a
default: default:
break; break;
} }
qDebug()<<ui->dockMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSizeHint();
} }

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1114</width> <width>945</width>
<height>627</height> <height>619</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -116,7 +116,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1114</width> <width>945</width>
<height>26</height> <height>26</height>
</rect> </rect>
</property> </property>
@ -829,14 +829,8 @@
</widget> </widget>
</widget> </widget>
<widget class="QDockWidget" name="dockMessages"> <widget class="QDockWidget" name="dockMessages">
<property name="minimumSize">
<size>
<width>818</width>
<height>235</height>
</size>
</property>
<property name="features"> <property name="features">
<set>QDockWidget::DockWidgetMovable</set> <set>QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetVerticalTitleBar</set>
</property> </property>
<property name="allowedAreas"> <property name="allowedAreas">
<set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> <set>Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set>
@ -858,7 +852,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>4</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>

View File

@ -18,6 +18,8 @@
#include <QTabBar> #include <QTabBar>
#include <QDebug> #include <QDebug>
QHash<const ShrinkableTabWidget*,QSize> ShrinkableTabWidget::BeforeShrinkSizes;
ShrinkableTabWidget::ShrinkableTabWidget(QWidget *parent):QTabWidget(parent), ShrinkableTabWidget::ShrinkableTabWidget(QWidget *parent):QTabWidget(parent),
mShrinked(false) mShrinked(false)
{ {
@ -26,8 +28,8 @@ ShrinkableTabWidget::ShrinkableTabWidget(QWidget *parent):QTabWidget(parent),
void ShrinkableTabWidget::setShrinked(bool shrinked) void ShrinkableTabWidget::setShrinked(bool shrinked)
{ {
if (!mShrinked) { if (!mShrinked && shrinked) {
mBeforeShrinkSize = size(); BeforeShrinkSizes.insert(this, size());
} }
mShrinked = shrinked; mShrinked = shrinked;
switch(this->tabPosition()) { switch(this->tabPosition()) {
@ -49,11 +51,43 @@ void ShrinkableTabWidget::setShrinked(bool shrinked)
} }
} }
bool ShrinkableTabWidget::isShrinked() const
{
return mShrinked;
}
void ShrinkableTabWidget::toggleShrined() void ShrinkableTabWidget::toggleShrined()
{ {
setShrinked(!mShrinked); setShrinked(!mShrinked);
} }
QSize ShrinkableTabWidget::beforeShrinkSize()
{
QSize size = BeforeShrinkSizes.value(this,QSize());
if (!size.isValid())
size = QSize(width(),height());
return size;
}
int ShrinkableTabWidget::beforeShrinkWidthOrHeight()
{
if (shrinkOrientation()==Qt::Vertical)
return beforeShrinkSize().height();
else
return beforeShrinkSize().width();
}
Qt::Orientation ShrinkableTabWidget::shrinkOrientation()
{
switch(this->tabPosition()) {
case QTabWidget::East:
case QTabWidget::West:
return Qt::Horizontal;
default:
return Qt::Vertical;
}
}
QSize ShrinkableTabWidget::sizeHint() const QSize ShrinkableTabWidget::sizeHint() const
{ {
return QTabWidget::sizeHint(); return QTabWidget::sizeHint();
@ -71,7 +105,5 @@ QSize ShrinkableTabWidget::minimumSizeHint() const
case QTabWidget::South: case QTabWidget::South:
size.setHeight(tabBar()->height()); size.setHeight(tabBar()->height());
} }
// qDebug()<<"min size hint()"<<size;
// qDebug()<<"mininum size"<<minimumSize();
return size; return size;
} }

View File

@ -26,7 +26,11 @@ public:
ShrinkableTabWidget(QWidget* parent=nullptr); ShrinkableTabWidget(QWidget* parent=nullptr);
void setShrinked(bool shrinked); void setShrinked(bool shrinked);
bool isShrinked() const;
void toggleShrined(); void toggleShrined();
QSize beforeShrinkSize();
int beforeShrinkWidthOrHeight();
Qt::Orientation shrinkOrientation();
// QWidget interface // QWidget interface
public: public:
@ -34,7 +38,7 @@ public:
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
private: private:
bool mShrinked; bool mShrinked;
QSize mBeforeShrinkSize; static QHash<const ShrinkableTabWidget*,QSize> BeforeShrinkSizes;
}; };
#endif // SHRINKABLETABWIDGET_H #endif // SHRINKABLETABWIDGET_H