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()) {
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)
{
if (index == ui->tabInfos->currentIndex()) {
int width = ui->tabInfos->tabBar()->width();
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)
{
qDebug()<<"-----";
qDebug()<<ui->dockMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSizeHint();
switch(area) {
case Qt::DockWidgetArea::BottomDockWidgetArea:
case Qt::DockWidgetArea::TopDockWidgetArea:
ui->splitterDebug->setOrientation(Qt::Orientation::Horizontal);
ui->splitterProblem->setOrientation(Qt::Orientation::Horizontal);
ui->dockMessages->setFeatures( ui->dockMessages->features() | QDockWidget::DockWidgetVerticalTitleBar);
break;
default:
ui->splitterDebug->setOrientation(Qt::Orientation::Vertical);
ui->splitterProblem->setOrientation(Qt::Orientation::Vertical);
ui->dockMessages->setFeatures( ui->dockMessages->features() & ~QDockWidget::DockWidgetVerticalTitleBar);
}
switch(area) {
case Qt::DockWidgetArea::BottomDockWidgetArea:
@ -7734,8 +7736,5 @@ void MainWindow::on_dockMessages_dockLocationChanged(const Qt::DockWidgetArea &a
default:
break;
}
qDebug()<<ui->dockMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSize();
qDebug()<<ui->tabMessages->minimumSizeHint();
}

View File

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

View File

@ -18,6 +18,8 @@
#include <QTabBar>
#include <QDebug>
QHash<const ShrinkableTabWidget*,QSize> ShrinkableTabWidget::BeforeShrinkSizes;
ShrinkableTabWidget::ShrinkableTabWidget(QWidget *parent):QTabWidget(parent),
mShrinked(false)
{
@ -26,8 +28,8 @@ ShrinkableTabWidget::ShrinkableTabWidget(QWidget *parent):QTabWidget(parent),
void ShrinkableTabWidget::setShrinked(bool shrinked)
{
if (!mShrinked) {
mBeforeShrinkSize = size();
if (!mShrinked && shrinked) {
BeforeShrinkSizes.insert(this, size());
}
mShrinked = shrinked;
switch(this->tabPosition()) {
@ -49,11 +51,43 @@ void ShrinkableTabWidget::setShrinked(bool shrinked)
}
}
bool ShrinkableTabWidget::isShrinked() const
{
return mShrinked;
}
void ShrinkableTabWidget::toggleShrined()
{
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
{
return QTabWidget::sizeHint();
@ -71,7 +105,5 @@ QSize ShrinkableTabWidget::minimumSizeHint() const
case QTabWidget::South:
size.setHeight(tabBar()->height());
}
// qDebug()<<"min size hint()"<<size;
// qDebug()<<"mininum size"<<minimumSize();
return size;
}

View File

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