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->ps_setDockArea(Qt::TopDockWidgetArea);
this->setMarginsWhenFloating(5, 5, 5, 5); // left, top, right bottom 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->connectAllWidgets();
this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable); this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable);
this->tabifyAllWidgets(); this->tabifyAllWidgets();
this->setPreferredSizesWhenFloating();
// context menu // context menu
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -78,7 +79,7 @@ namespace BlackGui
for (int i = 0; i < this->m_dockableWidgets.size(); i++) for (int i = 0; i < this->m_dockableWidgets.size(); i++)
{ {
const CDockWidgetInfoArea *dw = this->m_dockableWidgets.at(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(); const QString t = dw->windowTitleBackup();
QAction *checkableMenuAction = new QAction(menu); QAction *checkableMenuAction = new QAction(menu);
checkableMenuAction->setObjectName(QString(t).append("ToggleFloatingAction")); checkableMenuAction->setObjectName(QString(t).append("ToggleFloatingAction"));
@@ -125,14 +126,14 @@ namespace BlackGui
connect(showMenuText, &QAction::toggled, this, &CMainInfoAreaComponent::ps_showTabTexts); connect(showMenuText, &QAction::toggled, this, &CMainInfoAreaComponent::ps_showTabTexts);
// auto adjust floating widgets // auto adjust floating widgets
QAction *autoAdjustFloatingWidget = new QAction(menu); QAction *showTabbar = new QAction(menu);
autoAdjustFloatingWidget->setObjectName("AutoAdjustFloatingWidgets"); showTabbar->setObjectName("ShowTabBar");
autoAdjustFloatingWidget->setIconText("Auto adjust floating widgets"); showTabbar->setIconText("Show tab bar");
autoAdjustFloatingWidget->setIcon(CIcons::resize16()); showTabbar->setIcon(CIcons::dockBottom16());
autoAdjustFloatingWidget->setCheckable(true); showTabbar->setCheckable(true);
autoAdjustFloatingWidget->setChecked(this->m_autoAdjustFloatingWidgets); showTabbar->setChecked(this->m_showTabBar);
menu->addAction(autoAdjustFloatingWidget); menu->addAction(showTabbar);
connect(autoAdjustFloatingWidget, &QAction::toggled, this, &CMainInfoAreaComponent::ps_toggleAutoAdjustFloatingWidget); connect(showTabbar, &QAction::toggled, this, &CMainInfoAreaComponent::ps_showTabBar);
// tab bar position // tab bar position
menu->addAction(CIcons::dockBottom16(), "Toogle tabbar position", this, SLOT(ps_toggleTabBarPosition())); menu->addAction(CIcons::dockBottom16(), "Toogle tabbar position", this, SLOT(ps_toggleTabBarPosition()));
@@ -184,6 +185,16 @@ namespace BlackGui
this->tabifyAllWidgets(); 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() void CMainInfoAreaComponent::floatAllWidgets()
{ {
// I fake the double click here, which queues the events in the queue // I fake the double click here, which queues the events in the queue
@@ -305,9 +316,14 @@ namespace BlackGui
after->setVisible(false); after->setVisible(false);
after->setFloating(true); after->setFloating(true);
after->move(initPoint); after->move(initPoint);
after->setFloating(false);
after->resetWasAlreadyFLoating();
after->setVisible(true); after->setVisible(true);
} }
after->setFloating(false); else
{
after->setFloating(false);
}
if (!first) { continue; } if (!first) { continue; }
this->tabifyDockWidget(first, after); this->tabifyDockWidget(first, after);
} }
@@ -323,7 +339,7 @@ namespace BlackGui
this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab"); this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab");
this->m_tabBar->setMovable(false); this->m_tabBar->setMovable(false);
this->m_tabBar->setElideMode(Qt::ElideNone); 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) // East / West does not work (shown, but area itself empty)
// South does not have any effect // 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) switch (infoArea)
{ {
@@ -458,7 +501,7 @@ namespace BlackGui
for (int i = 0; i < this->m_tabBar->count(); i++) for (int i = 0; i < this->m_tabBar->count(); i++)
{ {
InfoArea area = static_cast<InfoArea>(i); InfoArea area = static_cast<InfoArea>(i);
const QPixmap p(infoAreaToIcon(area)); const QPixmap p(infoAreaToPixmap(area));
this->m_tabBar->setTabIcon(i, p); this->m_tabBar->setTabIcon(i, p);
} }
} }
@@ -502,7 +545,6 @@ namespace BlackGui
QAction *selectedItem = contextMenu.data()->exec(globalPos); QAction *selectedItem = contextMenu.data()->exec(globalPos);
Q_UNUSED(selectedItem); Q_UNUSED(selectedItem);
} }
void CMainInfoAreaComponent::ps_showTabTexts(bool show) 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; if (show == this->m_showTabBar) return;
this->m_autoAdjustFloatingWidgets = adjust; this->m_showTabBar = show;
QList<CDockWidgetInfoArea *>::iterator i; if (!this->m_tabBar) return;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i) 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
CDockWidgetInfoArea *dw = (*i); this->adjustSizeForAllDockWidgets();
dw->setAutoAdjustWhenFloating(adjust);
}
} }
void CMainInfoAreaComponent::ps_setTabBarPosition(QTabWidget::TabPosition position) void CMainInfoAreaComponent::ps_setTabBarPosition(QTabWidget::TabPosition position)

View File

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

View File

@@ -119,9 +119,15 @@ namespace BlackGui
} }
this->setNullTitleBar(); this->setNullTitleBar();
this->setContentsMargins(this->m_marginsWhenFloating); this->setContentsMargins(this->m_marginsWhenFloating);
if (this->m_autoAdjustWhenFloating) { if (!this->m_wasAlreadyFloating)
this->adjustSize(); {
// for the first time resize
if (!this->m_preferredSizeWhenFloating.isNull())
{
this->resize(this->m_preferredSizeWhenFloating);
}
} }
this->m_wasAlreadyFloating = true;
} }
else else
{ {
@@ -143,6 +149,20 @@ namespace BlackGui
this->setTitleBarWidget(this->m_emptyTitleBar); 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) void CDockWidget::ps_showContextMenu(const QPoint &pos)
{ {
QPoint globalPos = this->mapToGlobal(pos); QPoint globalPos = this->mapToGlobal(pos);

View File

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

View File

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