Merge branch 'duerr-ndt-auto_hide_feature' into auto_hide_feature_refactor

This commit is contained in:
Uwe Kindler 2022-10-28 11:17:13 +02:00
commit 38ee87f762
6 changed files with 32 additions and 32 deletions

View File

@ -12,6 +12,7 @@
#include <QPlainTextEdit>
#include <QToolBar>
#include "AutoHideDockContainer.h"
#include "DockAreaWidget.h"
#include "DockAreaTitleBar.h"
@ -44,10 +45,9 @@ CMainWindow::CMainWindow(QWidget *parent)
CDockWidget* TableDockWidget = new CDockWidget("Table 1");
TableDockWidget->setWidget(table);
TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
TableDockWidget->resize(250, 150);
TableDockWidget->setMinimumSize(200,150);
TableDockWidget->setDefaultAutoHideDockProportion(0.5);
DockManager->addAutoHideDockWidget(SideBarLocation::Left, TableDockWidget, CDockWidget::Last);
const auto autoHideContainer = DockManager->addAutoHideDockWidget(SideBarLocation::Left, TableDockWidget, CDockWidget::Last);
autoHideContainer->setSize(480, 100);
ui->menuView->addAction(TableDockWidget->toggleViewAction());
table = new QTableWidget();

View File

@ -47,7 +47,7 @@
namespace ads
{
static const int ResizeMargin = 4;
static const int ResizeMargin = 30;
//============================================================================
bool static isHorizontalArea(SideBarLocation Area)
@ -136,8 +136,9 @@ struct AutoHideDockContainerPrivate
void updateResizeHandleSizeLimitMax()
{
auto Rect = _this->parentContainer()->contentRect();
ResizeHandle->setMaxResizeSize(ResizeHandle->orientation() == Qt::Horizontal
? Rect.width() : Rect.height());
const auto maxResizeHandleSize = ResizeHandle->orientation() == Qt::Horizontal
? Rect.width() : Rect.height();
ResizeHandle->setMaxResizeSize(maxResizeHandleSize - ResizeMargin);
}
/**
@ -216,18 +217,18 @@ void CAutoHideDockContainer::updateSize()
switch (sideTabBarArea())
{
case SideBarLocation::Top:
resize(rect.width(), qMin(rect.height(), d->Size.height()));
resize(rect.width(), qMin(rect.height(), d->Size.height() - ResizeMargin));
move(rect.topLeft());
break;
case SideBarLocation::Left:
resize(qMin(d->Size.width(), rect.width()), rect.height());
resize(qMin(d->Size.width(), rect.width() - ResizeMargin), rect.height());
move(rect.topLeft());
break;
case SideBarLocation::Right:
{
resize(qMin(d->Size.width(), rect.width()), rect.height());
resize(qMin(d->Size.width(), rect.width() - ResizeMargin), rect.height());
QPoint p = rect.topRight();
p.rx() -= (width() - 1);
move(p);
@ -236,7 +237,7 @@ void CAutoHideDockContainer::updateSize()
case SideBarLocation::Bottom:
{
resize(rect.width(), qMin(rect.height(), d->Size.height()));
resize(rect.width(), qMin(rect.height(), d->Size.height() - ResizeMargin));
QPoint p = rect.bottomLeft();
p.ry() -= (height() - 1);
move(p);
@ -293,7 +294,7 @@ void CAutoHideDockContainer::addDockWidget(CDockWidget* DockWidget)
// Prevent overriding of d->Size parameter when this function is called during
// state restoring
if (!DockWidget->dockManager()->isRestoringState())
if (!DockWidget->dockManager()->isRestoringState() && OldDockArea)
{
// The initial size should be a little bit bigger than the original dock
// area size to prevent that the resize handle of this auto hid dock area
@ -321,7 +322,7 @@ CDockAreaWidget* CAutoHideDockContainer::dockAreaWidget() const
void CAutoHideDockContainer::moveContentsToParent()
{
cleanupAndDelete();
// If we unpin the auto hide tock widget, then we insert it into the same
// If we unpin the auto hide dock widget, then we insert it into the same
// location like it had as a auto hide widget. This brings the least surprise
// to the user and he does not have to search where the widget was inserted.
d->DockWidget->setDockArea(nullptr);
@ -438,6 +439,12 @@ void CAutoHideDockContainer::toggleCollapseState()
collapseView(isVisible());
}
void CAutoHideDockContainer::setSize(int width, int height)
{
d->Size = QSize(width, height);
updateSize();
}
//============================================================================
bool CAutoHideDockContainer::eventFilter(QObject* watched, QEvent* event)
@ -510,7 +517,7 @@ void CAutoHideDockContainer::resizeEvent(QResizeEvent* event)
Super::resizeEvent(event);
if (d->ResizeHandle->isResizing())
{
d->Size = this->size();
d->Size = this->size();
d->updateResizeHandleSizeLimitMax();
}
}

View File

@ -99,7 +99,7 @@ public:
*/
void addDockWidget(CDockWidget* DockWidget);
/**
/**
* Returns the side tab bar area of this Auto Hide dock container
*/
SideBarLocation sideTabBarArea() const;
@ -146,6 +146,13 @@ public:
* Toggles the current collapse state
*/
void toggleCollapseState();
/**
* Use this instead of resize. This will ensure the size is consistent internally.
* E.g. If you set a height less than the parent height when it's vertical
* It will simply be rescaled to the parent height while the width will be resized
*/
void setSize(int width, int height);
};
}

View File

@ -31,6 +31,7 @@ set(ads_SRCS
DockWidgetSideTab.cpp
AutoHideDockContainer.cpp
PushButton.cpp
ResizeHandle.cpp
ads.qrc
)
set(ads_HEADERS
@ -56,6 +57,7 @@ set(ads_HEADERS
DockWidgetSideTab.h
AutoHideDockContainer.h
PushButton.h
ResizeHandle.h
)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
if (UNIX AND NOT APPLE)

View File

@ -1537,7 +1537,7 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
{
if (d->DockManager != DockWidget->dockManager())
{
DockWidget->setDockManager(d->DockManager); // Overlay Dock Container needs a valid dock manager
DockWidget->setDockManager(d->DockManager); // Auto hide Dock Container needs a valid dock manager
}
if (!CDockManager::testConfigFlag(CDockManager::AutoHideFeatureEnabled))
{
@ -1550,11 +1550,10 @@ CAutoHideDockContainer* CDockContainerWidget::createAndSetupAutoHideContainer(
sideTabBar(area)->insertSideTab(insertOrder == CDockWidget::First ? 0 : -1, DockWidget->sideTabWidget());
DockWidget->sideTabWidget()->show();
auto AutoHideContainer = new CAutoHideDockContainer(DockWidget, area, this);
const auto AutoHideContainer = new CAutoHideDockContainer(DockWidget, area, this);
AutoHideContainer->hide();
d->DockManager->dockFocusController()->clearDockWidgetFocus(DockWidget);
//auto AutoHideContainer = sideTabBar(area)->insertDockWidget(insertOrder == CDockWidget::First ? 0 : -1, DockWidget);
return AutoHideContainer;
}

View File

@ -94,7 +94,6 @@ struct DockWidgetPrivate
QList<QAction*> TitleBarActions;
CDockWidget::eMinimumSizeHintMode MinimumSizeHintMode = CDockWidget::MinimumSizeHintFromDockWidget;
WidgetFactory* Factory = nullptr;
double DefaultAutoHideDockProportion = 0.25;
CDockWidget::eAutoHideInsertOrder AutoHideInsertOrder = CDockWidget::Last;
QPointer<CDockWidgetSideTab> SideTabWidget;
@ -1133,20 +1132,6 @@ bool CDockWidget::isCurrentTab() const
}
//============================================================================
void CDockWidget::setDefaultAutoHideDockProportion(float Proportion)
{
d->DefaultAutoHideDockProportion = Proportion;
}
//============================================================================
float CDockWidget::DefaultAutoHideDockProportion() const
{
return d->DefaultAutoHideDockProportion;
}
//============================================================================
void CDockWidget::setAutoHideInsertOrder(eAutoHideInsertOrder insertOrder)
{