Added minimumSizeHint function to DockWidget to prevent jumping of the height of a dock area when switching between dock widgets, fixed use of findParent function in DockWidget - non current dock widgets do not have a parent so this function will fail

This commit is contained in:
Uwe Kindler 2018-10-15 08:29:30 +02:00
parent 30bbd26d0a
commit ada3d6b3b5
10 changed files with 50 additions and 9 deletions

View File

@ -182,7 +182,7 @@ void MainWindowPrivate::createContent()
ToolBar->addAction(ui.actionRestoreState); ToolBar->addAction(ui.actionRestoreState);
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget); DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
/*FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu); FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
ToolBar = FileSystemWidget->toolBar(); ToolBar = FileSystemWidget->toolBar();
ToolBar->addAction(ui.actionSaveState); ToolBar->addAction(ui.actionSaveState);
ToolBar->addAction(ui.actionRestoreState); ToolBar->addAction(ui.actionRestoreState);
@ -197,7 +197,7 @@ void MainWindowPrivate::createContent()
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/ DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
} }

View File

@ -17,6 +17,7 @@
#include <QScrollArea> #include <QScrollArea>
#include <QMouseEvent> #include <QMouseEvent>
#include <QDebug> #include <QDebug>
#include <QStyleOptionButton>
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
@ -149,7 +150,6 @@ CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
//============================================================================ //============================================================================
void CDockAreaTitleBar::markTabsMenuOutdated() void CDockAreaTitleBar::markTabsMenuOutdated()
{ {
qDebug() << "CDockAreaTitleBar::markTabsMenuOutdated()";
d->MenuOutdated = true; d->MenuOutdated = true;
} }

View File

@ -291,6 +291,8 @@ void DockAreaWidgetPrivate::createTitleBar()
SLOT(onTabCloseRequested(int))); SLOT(onTabCloseRequested(int)));
_this->connect(tabBar(), SIGNAL(tabBarClicked(int)), _this->connect(tabBar(), SIGNAL(tabBarClicked(int)),
SLOT(setCurrentIndex(int))); SLOT(setCurrentIndex(int)));
_this->connect(tabBar(), SIGNAL(tabMoved(int, int)),
SLOT(reorderDockWidget(int, int)));
} }
@ -480,7 +482,6 @@ void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
//============================================================================ //============================================================================
void CDockAreaWidget::setCurrentIndex(int index) void CDockAreaWidget::setCurrentIndex(int index)
{ {
std::cout << "CDockAreaWidget::setCurrentIndex " << index << std::endl;
auto TabBar = d->tabBar(); auto TabBar = d->tabBar();
if (index < 0 || index > (TabBar->count() - 1)) if (index < 0 || index > (TabBar->count() - 1))
{ {
@ -583,6 +584,7 @@ CDockWidget* CDockAreaWidget::dockWidget(int Index) const
//============================================================================ //============================================================================
void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex) void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex)
{ {
qDebug() << "CDockAreaWidget::reorderDockWidget";
if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0 if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0
|| toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex) || toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex)
{ {
@ -658,7 +660,7 @@ CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
//============================================================================ //============================================================================
CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
{ {
CDockWidget::DockWidgetFeatures Features; CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
for (const auto DockWidget : dockWidgets()) for (const auto DockWidget : dockWidgets())
{ {
Features &= DockWidget->features(); Features &= DockWidget->features();
@ -667,6 +669,20 @@ CDockWidget::DockWidgetFeatures CDockAreaWidget::features() const
return Features; return Features;
} }
//============================================================================
void CDockAreaWidget::setVisible(bool visible)
{
Super::setVisible(visible);
QString FirstDockWidgetLabel;
if (dockWidgetsCount())
{
FirstDockWidgetLabel = dockWidget(0)->windowTitle();
}
qDebug() << "CDockAreaWidget::setVisible " << visible << " " << FirstDockWidgetLabel
<< " count: " << dockWidgetsCount() << " open count: " << openDockWidgetsCount();
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -129,6 +129,8 @@ protected:
void updateTabBarVisibility(); void updateTabBarVisibility();
public: public:
using Super = QFrame;
/** /**
* Default Constructor * Default Constructor
*/ */
@ -223,6 +225,11 @@ public slots:
*/ */
void setCurrentIndex(int index); void setCurrentIndex(int index);
/**
* This function is required for debugging purposes
*/
virtual void setVisible(bool visible) override;
signals: signals:
/** /**
* This signal is emitted when user clicks on a tab at an index. * This signal is emitted when user clicks on a tab at an index.

View File

@ -1156,7 +1156,7 @@ QList<CDockWidget*> CDockContainerWidget::dockWidgets() const
//============================================================================ //============================================================================
CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const CDockWidget::DockWidgetFeatures CDockContainerWidget::features() const
{ {
CDockWidget::DockWidgetFeatures Features; CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
for (const auto DockArea : d->DockAreas) for (const auto DockArea : d->DockAreas)
{ {
Features &= DockArea->features(); Features &= DockArea->features();

View File

@ -252,6 +252,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
} }
} }
// Now all dock areas are properly restored and we setup the index of // Now all dock areas are properly restored and we setup the index of
// The dock areas because the previous toggleView() action has changed // The dock areas because the previous toggleView() action has changed
// the dock area index // the dock area index
@ -278,6 +279,7 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
} }
} }
// Finally we need to send the topLevelChanged() signals for all dock // Finally we need to send the topLevelChanged() signals for all dock
// widgets if top level changed // widgets if top level changed
for (auto DockContainer : Containers) for (auto DockContainer : Containers)

View File

@ -133,7 +133,7 @@ void DockWidgetPrivate::showDockWidget()
DockArea->show(); DockArea->show();
DockArea->setCurrentDockWidget(_this); DockArea->setCurrentDockWidget(_this);
TabWidget->show(); TabWidget->show();
QSplitter* Splitter = internal::findParent<QSplitter*>(_this); QSplitter* Splitter = internal::findParent<QSplitter*>(DockArea);
while (Splitter && !Splitter->isVisible()) while (Splitter && !Splitter->isVisible())
{ {
Splitter->show(); Splitter->show();
@ -666,6 +666,13 @@ void CDockWidget::setClosedState(bool Closed)
d->Closed = Closed; d->Closed = Closed;
} }
//============================================================================
QSize CDockWidget::minimumSizeHint() const
{
return QSize(60, 40);
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -209,6 +209,11 @@ public:
*/ */
virtual ~CDockWidget(); virtual ~CDockWidget();
/**
* We return a fixed minimum size hint for all dock widgets
*/
virtual QSize minimumSizeHint() const override;
/** /**
* Sets the widget for the dock widget to widget. * Sets the widget for the dock widget to widget.
*/ */

View File

@ -398,10 +398,10 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
//============================================================================ //============================================================================
void CDockWidgetTab::setVisible(bool visible) void CDockWidgetTab::setVisible(bool visible)
{ {
if (!visible) /*if (!visible)
{ {
qDebug() << "CDockWidgetTab::setVisible " << visible; qDebug() << "CDockWidgetTab::setVisible " << visible;
} }*/
Super::setVisible(visible); Super::setVisible(visible);
} }

View File

@ -97,6 +97,10 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area);
* Searches for the parent widget of the given type. * Searches for the parent widget of the given type.
* Returns the parent widget of the given widget or 0 if the widget is not * Returns the parent widget of the given widget or 0 if the widget is not
* child of any widget of type T * child of any widget of type T
*
* It is not safe to use this function in in CDockWidget because only
* the current dock widget has a parent. All dock widgets that are not the
* current dock widget in a dock area have no parent.
*/ */
template <class T> template <class T>
T findParent(const QWidget* w) T findParent(const QWidget* w)