refs #299, dockable widgets improvements

* preferred size instead of a auto adjustment for floatable widgets
* hack for hiding the tabbar (it still cosnumes space)
This commit is contained in:
Klaus Basan
2014-08-04 02:24:20 +02:00
parent d3858a8b37
commit 3c12cd7b30
5 changed files with 112 additions and 35 deletions

View File

@@ -39,10 +39,11 @@ namespace BlackGui
this->ps_setDockArea(Qt::TopDockWidgetArea);
this->setMarginsWhenFloating(5, 5, 5, 5); // left, top, right bottom
this->setMarginsWhenDocked(1, 1, 1, 1); // top has no effect
this->setMarginsWhenDocked(1, 1, 1, 1); // top has no effect
this->connectAllWidgets();
this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable);
this->tabifyAllWidgets();
this->setPreferredSizesWhenFloating();
// context menu
this->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -78,7 +79,7 @@ namespace BlackGui
for (int i = 0; i < this->m_dockableWidgets.size(); i++)
{
const CDockWidgetInfoArea *dw = this->m_dockableWidgets.at(i);
const QPixmap pm = infoAreaToIcon(static_cast<InfoArea>(i));
const QPixmap pm = infoAreaToPixmap(static_cast<InfoArea>(i));
const QString t = dw->windowTitleBackup();
QAction *checkableMenuAction = new QAction(menu);
checkableMenuAction->setObjectName(QString(t).append("ToggleFloatingAction"));
@@ -125,14 +126,14 @@ namespace BlackGui
connect(showMenuText, &QAction::toggled, this, &CMainInfoAreaComponent::ps_showTabTexts);
// auto adjust floating widgets
QAction *autoAdjustFloatingWidget = new QAction(menu);
autoAdjustFloatingWidget->setObjectName("AutoAdjustFloatingWidgets");
autoAdjustFloatingWidget->setIconText("Auto adjust floating widgets");
autoAdjustFloatingWidget->setIcon(CIcons::resize16());
autoAdjustFloatingWidget->setCheckable(true);
autoAdjustFloatingWidget->setChecked(this->m_autoAdjustFloatingWidgets);
menu->addAction(autoAdjustFloatingWidget);
connect(autoAdjustFloatingWidget, &QAction::toggled, this, &CMainInfoAreaComponent::ps_toggleAutoAdjustFloatingWidget);
QAction *showTabbar = new QAction(menu);
showTabbar->setObjectName("ShowTabBar");
showTabbar->setIconText("Show tab bar");
showTabbar->setIcon(CIcons::dockBottom16());
showTabbar->setCheckable(true);
showTabbar->setChecked(this->m_showTabBar);
menu->addAction(showTabbar);
connect(showTabbar, &QAction::toggled, this, &CMainInfoAreaComponent::ps_showTabBar);
// tab bar position
menu->addAction(CIcons::dockBottom16(), "Toogle tabbar position", this, SLOT(ps_toggleTabBarPosition()));
@@ -184,6 +185,16 @@ namespace BlackGui
this->tabifyAllWidgets();
}
void CMainInfoAreaComponent::adjustSizeForAllDockWidgets()
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{
CDockWidgetInfoArea *dw = (*i);
dw->adjustSize();
}
}
void CMainInfoAreaComponent::floatAllWidgets()
{
// I fake the double click here, which queues the events in the queue
@@ -305,9 +316,14 @@ namespace BlackGui
after->setVisible(false);
after->setFloating(true);
after->move(initPoint);
after->setFloating(false);
after->resetWasAlreadyFLoating();
after->setVisible(true);
}
after->setFloating(false);
else
{
after->setFloating(false);
}
if (!first) { continue; }
this->tabifyDockWidget(first, after);
}
@@ -323,7 +339,7 @@ namespace BlackGui
this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab");
this->m_tabBar->setMovable(false);
this->m_tabBar->setElideMode(Qt::ElideNone);
this->m_tabBar->setShape(QTabBar::TriangularEast);
this->setDocumentMode(true);
// East / West does not work (shown, but area itself empty)
// South does not have any effect
@@ -379,7 +395,34 @@ namespace BlackGui
}
}
const QPixmap &CMainInfoAreaComponent::infoAreaToIcon(CMainInfoAreaComponent::InfoArea infoArea)
void CMainInfoAreaComponent::setPreferredSizesWhenFloating()
{
if (this->m_dockableWidgets.isEmpty()) return;
for (int i = 0; i < this->m_dockableWidgets.size(); i++)
{
InfoArea ia = static_cast<InfoArea>(i);
switch (ia)
{
case InfoAreaAircrafts:
case InfoAreaAtc:
case InfoAreaUsers:
case InfoAreaLog:
case InfoAreaSimulator:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(400, 300));
break;
case InfoAreaMappings:
case InfoAreaSettings:
case InfoAreaTextMessages:
case InfoAreaFlightPlan:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(600, 400));
break;
default:
break;
}
}
}
const QPixmap &CMainInfoAreaComponent::infoAreaToPixmap(CMainInfoAreaComponent::InfoArea infoArea)
{
switch (infoArea)
{
@@ -458,7 +501,7 @@ namespace BlackGui
for (int i = 0; i < this->m_tabBar->count(); i++)
{
InfoArea area = static_cast<InfoArea>(i);
const QPixmap p(infoAreaToIcon(area));
const QPixmap p(infoAreaToPixmap(area));
this->m_tabBar->setTabIcon(i, p);
}
}
@@ -502,7 +545,6 @@ namespace BlackGui
QAction *selectedItem = contextMenu.data()->exec(globalPos);
Q_UNUSED(selectedItem);
}
void CMainInfoAreaComponent::ps_showTabTexts(bool show)
@@ -517,16 +559,14 @@ namespace BlackGui
}
}
void CMainInfoAreaComponent::ps_toggleAutoAdjustFloatingWidget(bool adjust)
void CMainInfoAreaComponent::ps_showTabBar(bool show)
{
if (adjust == this->m_autoAdjustFloatingWidgets) return;
this->m_autoAdjustFloatingWidgets = adjust;
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{
CDockWidgetInfoArea *dw = (*i);
dw->setAutoAdjustWhenFloating(adjust);
}
if (show == this->m_showTabBar) return;
this->m_showTabBar = show;
if (!this->m_tabBar) return;
this->m_tabBar->setVisible(show); // not working, but setting right value will not harm anything
this->m_tabBar->setMaximumHeight(show ? 10000 : 0); // does the trick
this->adjustSizeForAllDockWidgets();
}
void CMainInfoAreaComponent::ps_setTabBarPosition(QTabWidget::TabPosition position)

View File

@@ -94,6 +94,9 @@ namespace BlackGui
//! Dock all widgets
void dockAllWidgets();
//! Adjust size for all dock widgets
void adjustSizeForAllDockWidgets();
//! All widgets floating
void floatAllWidgets();
@@ -122,7 +125,7 @@ namespace BlackGui
QTabBar *m_tabBar = nullptr;
bool m_showTabTexts = true;
bool m_infoAreaFloating = false; //!< whole info area floating
bool m_autoAdjustFloatingWidgets = true; //!< auto ajdust the floating widgets
bool m_showTabBar = true; //!< auto ajdust the floating widgets
//! Tabify the widgets
void tabifyAllWidgets();
@@ -163,8 +166,11 @@ namespace BlackGui
//! Margins for the dockable widgets
void setMarginsWhenDocked(int left, int top, int right, int bottom);
//! Set window sizes when floating
void setPreferredSizesWhenFloating();
//! Info area to icon
static const QPixmap &infoAreaToIcon(InfoArea infoArea);
static const QPixmap &infoAreaToPixmap(InfoArea infoArea);
private slots:
//! Tab bar has been double clicked
@@ -182,8 +188,8 @@ namespace BlackGui
//! Show the tab texts, or just the icons
void ps_showTabTexts(bool show);
//! Toggle checkable setting
void ps_toggleAutoAdjustFloatingWidget(bool adjust);
//! Show tab bar
void ps_showTabBar(bool show);
//! Tab position for docked widgets tab
//! \remarks North or South working, East / West not

View File

@@ -119,9 +119,15 @@ namespace BlackGui
}
this->setNullTitleBar();
this->setContentsMargins(this->m_marginsWhenFloating);
if (this->m_autoAdjustWhenFloating) {
this->adjustSize();
if (!this->m_wasAlreadyFloating)
{
// for the first time resize
if (!this->m_preferredSizeWhenFloating.isNull())
{
this->resize(this->m_preferredSizeWhenFloating);
}
}
this->m_wasAlreadyFloating = true;
}
else
{
@@ -143,6 +149,20 @@ namespace BlackGui
this->setTitleBarWidget(this->m_emptyTitleBar);
}
QList<QWidget *> CDockWidget::findEmbeddedRuntimeComponents() const
{
QList<QWidget *> widgets = this->findChildren<QWidget *>();
QList<QWidget *> widgetsWithRuntimeComponent;
foreach(QWidget * w, widgets)
{
if (dynamic_cast<Components::CRuntimeBasedComponent *>(w))
{
widgetsWithRuntimeComponent.append(w);
}
}
return widgetsWithRuntimeComponent;
}
void CDockWidget::ps_showContextMenu(const QPoint &pos)
{
QPoint globalPos = this->mapToGlobal(pos);

View File

@@ -12,6 +12,7 @@
#ifndef BLACKGUI_DOCKWIDGET_H
#define BLACKGUI_DOCKWIDGET_H
#include "components/runtimebasedcomponent.h"
#include <QDockWidget>
#include <QTabWidget>
#include <QMenu>
@@ -50,9 +51,6 @@ namespace BlackGui
//! Margins when widget is floating
void setMarginsWhenDocked(int left, int top, int right, int bottom) { this->m_marginsWhenDocked = QMargins(left, top, right, bottom); }
//! Auto adjust size when floating
void setAutoAdjustWhenFloating(bool autoAdjust) { this->m_autoAdjustWhenFloating = autoAdjust; }
//! Window title backup
const QString &windowTitleBackup() const { return this->m_windowTitleBackup; }
@@ -62,6 +60,15 @@ namespace BlackGui
//! Show the window title when docked
void showTitleWhenDocked(bool show);
//! Reset first time floating
void resetWasAlreadyFLoating() { this->m_wasAlreadyFloating = false; }
//! Was widget already floating
bool wasAlreadyFloating() const { return this->m_wasAlreadyFloating; }
//! Size when floating
void setPreferredSizeWhenFloating(const QSize &size) { this->m_preferredSizeWhenFloating = size; }
public slots:
//! Toggle floating
void toggleFloating();
@@ -101,10 +108,15 @@ namespace BlackGui
QMargins m_marginsWhenDocked; //!< Offsets when window is floating
QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes
bool m_windowTitleWhenDocked = true;
bool m_autoAdjustWhenFloating = true;
bool m_wasAlreadyFloating = false;
QSize m_preferredSizeWhenFloating;
//! Empty widget with no size
void initTitleBarWidgets();
//! Find all embedded runtime components
QList<QWidget *> findEmbeddedRuntimeComponents() const;
};
} // namespace

View File

@@ -21,7 +21,6 @@ namespace BlackGui
{
CDockWidgetInfoBar::CDockWidgetInfoBar(QWidget *parent) : CDockWidget(parent)
{
this->setAutoAdjustWhenFloating(false);
this->setMarginsWhenDocked(0, 0, 0, -1);
this->setWindowTitle("Info bar");
this->setWindowIcon(CIcons::swift24());