mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 19:22:05 +08:00
refs #335, cockpit component:
* COM unit * show / hide bar * info area (nested)
This commit is contained in:
committed by
Roland Winklmeier
parent
fc4fb23b91
commit
7028bcf66a
120
src/blackgui/components/cockpitcomponent.cpp
Normal file
120
src/blackgui/components/cockpitcomponent.cpp
Normal file
@@ -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
|
||||||
60
src/blackgui/components/cockpitcomponent.h
Normal file
60
src/blackgui/components/cockpitcomponent.h
Normal file
@@ -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 <QWidget>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
|
||||||
|
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::CCockpitComponent> ui;
|
||||||
|
QSize m_sizeFloatingShown; //! size when info area is shown
|
||||||
|
QSize m_sizeFloatingHidden; //! size when info area is hidden
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
104
src/blackgui/components/cockpitcomponent.ui
Normal file
104
src/blackgui/components/cockpitcomponent.ui
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CCockpitComponent</class>
|
||||||
|
<widget class="QWidget" name="CCockpitComponent">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="vl_CockpitComponent">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item alignment="Qt::AlignTop">
|
||||||
|
<widget class="BlackGui::Components::CCockpitComComponent" name="comp_CockpitComComponent">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item alignment="Qt::AlignTop">
|
||||||
|
<widget class="BlackGui::CShowHideBar" name="wip_CockpitComPanelShowHideBar" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>10</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::Components::CCockpitInfoAreaComponent" name="comp_CockpitInfoArea" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CShowHideBar</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>blackgui/showhidebar.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::Components::CCockpitComComponent</class>
|
||||||
|
<extends>QFrame</extends>
|
||||||
|
<header>blackgui/components/cockpitcomcomponent.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::Components::CCockpitInfoAreaComponent</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>blackgui/components/cockpitinfoareacomponent.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user