diff --git a/src/blackgui/components/cockpitcomponent.cpp b/src/blackgui/components/cockpitcomponent.cpp new file mode 100644 index 000000000..569eb73df --- /dev/null +++ b/src/blackgui/components/cockpitcomponent.cpp @@ -0,0 +1,120 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "cockpitcomponent.h" +#include "../showhidebar.h" +#include "../dockwidgetinfoarea.h" +#include "ui_cockpitcomponent.h" + +namespace BlackGui +{ + namespace Components + { + + CCockpitComponent::CCockpitComponent(QWidget *parent) : + QWidget(parent), + CEnableForDockWidgetInfoArea(), + ui(new Ui::CCockpitComponent) + { + ui->setupUi(this); + connect(ui->wip_CockpitComPanelShowHideBar, &BlackGui::CShowHideBar::toggleShowHide, this, &CCockpitComponent::ps_onToggleShowHideDetails); + } + + CCockpitComponent::~CCockpitComponent() + { } + + bool CCockpitComponent::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) + { + Q_ASSERT(parentDockableWidget); + bool ok = CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget); + if (ok && parentDockableWidget) + { + ok = connect(parentDockableWidget, &QDockWidget::topLevelChanged, this, &CCockpitComponent::ps_onToggleFloating); + } + return ok; + } + + bool CCockpitComponent::isInfoAreaShown() const + { + return this->ui->wip_CockpitComPanelShowHideBar->isShown(); + } + + void CCockpitComponent::ps_onToggleShowHideDetails(bool show) + { + Q_ASSERT(this->isParentDockWidgetFloating()); // show hide should not be visible if docked + Q_ASSERT(this->window()); + if (!this->isParentDockWidgetFloating()) { return; } + + // keep old size + QSize oldSize = this->window()->size(); + + // hide area + this->ui->comp_CockpitInfoArea->setVisible(show); + + // adjust size + if (show) + { + if (!this->m_sizeFloatingShown.isValid()) + { + // minimumSizeHint() not as good as expected + QSize m(300, 400); + this->setMinimumSize(m); + this->window()->setMinimumSize(m); + this->window()->resize(m); + this->m_sizeFloatingShown = this->window()->size(); + } + else + { + this->window()->resize(m_sizeFloatingShown); + } + if (this->m_sizeFloatingHidden.isValid()) + { + // was already initialized, override + this->m_sizeFloatingHidden = oldSize; + } + } + else + { + if (!this->m_sizeFloatingHidden.isValid()) + { + // minimumSizeHint() not as good as expected + QSize m(300, 125); + this->setMinimumSize(m); + this->window()->setMinimumSize(m); + this->window()->resize(m); + this->m_sizeFloatingHidden = this->window()->size(); + } + else + { + this->window()->resize(m_sizeFloatingHidden); + } + if (this->m_sizeFloatingShown.isValid()) + { + // was already initialized, override + this->m_sizeFloatingShown = oldSize; + } + } + } + + void CCockpitComponent::ps_onToggleFloating(bool floating) + { + this->ui->wip_CockpitComPanelShowHideBar->setVisible(floating); + if (floating) + { + // use the toggle method to set the sizes + this->ps_onToggleShowHideDetails(this->isInfoAreaShown()); + } + else + { + this->ui->comp_CockpitInfoArea->setVisible(true); + } + } + + } // namespace +} // namespace diff --git a/src/blackgui/components/cockpitcomponent.h b/src/blackgui/components/cockpitcomponent.h new file mode 100644 index 000000000..d391eaf83 --- /dev/null +++ b/src/blackgui/components/cockpitcomponent.h @@ -0,0 +1,60 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKGUI_COCKPITCOMPONENT_H +#define BLACKGUI_COCKPITCOMPONENT_H + +#include "enablefordockwidgetinfoarea.h" +#include +#include + +namespace Ui { class CCockpitComponent; } + +namespace BlackGui +{ + namespace Components + { + //! Cockpit component: COM unit, show / hide bar, voice rooms + class CCockpitComponent : + public QWidget, + public CEnableForDockWidgetInfoArea + { + Q_OBJECT + + public: + //! Constructor + explicit CCockpitComponent(QWidget *parent = nullptr); + + //! Destructor + ~CCockpitComponent(); + + //! \copydoc CDockWidgetInfoArea::setParentDockWidgetInfoArea + virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override; + + //! Is the info area shown? + bool isInfoAreaShown() const; + + private slots: + //! Show or hide cockpit details + void ps_onToggleShowHideDetails(bool show); + + //! Toogle floating + void ps_onToggleFloating(bool floating); + + private: + QScopedPointer ui; + QSize m_sizeFloatingShown; //! size when info area is shown + QSize m_sizeFloatingHidden; //! size when info area is hidden + }; + + } // namespace +} // namespace + + +#endif // guard diff --git a/src/blackgui/components/cockpitcomponent.ui b/src/blackgui/components/cockpitcomponent.ui new file mode 100644 index 000000000..df1a823f1 --- /dev/null +++ b/src/blackgui/components/cockpitcomponent.ui @@ -0,0 +1,104 @@ + + + CCockpitComponent + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 40 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 0 + 0 + + + + + 0 + 10 + + + + + + + + + 0 + 0 + + + + + + + + + BlackGui::CShowHideBar + QWidget +
blackgui/showhidebar.h
+ 1 +
+ + BlackGui::Components::CCockpitComComponent + QFrame +
blackgui/components/cockpitcomcomponent.h
+ 1 +
+ + BlackGui::Components::CCockpitInfoAreaComponent + QWidget +
blackgui/components/cockpitinfoareacomponent.h
+ 1 +
+
+ + +