mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #312, Navigator (aka navigation bars)
* different dyn. property names for main window, dock window and infoarea * dyn.properties for nested QWidgets * style sheet for navigator * utility function to delete layout * added standard OS icons, some formatting in CICons * actions in main window to be used in navigator * main window becomes normal window when minimized so it is correctly displayed in Win taskbar Remark: Frameless floating dockwidgets with rounded borders not yet working
This commit is contained in:
@@ -57,6 +57,11 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
CNavigatorDockWidget *CInvisibleInfoAreaComponent::getNavigatorComponent()
|
||||
{
|
||||
return this->ui->comp_Navigator;
|
||||
}
|
||||
|
||||
void CInvisibleInfoAreaComponent::toggleNavigator()
|
||||
{
|
||||
this->ui->comp_Navigator->toggleFloating();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define BLACKGUI_COMPONENTS_INVISIBLEINFOAREACOMPONENT_H
|
||||
|
||||
#include "blackgui/infoarea.h"
|
||||
#include "blackgui/components/navigatordockwidget.h"
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui { class CInvisibleInfoAreaComponent; }
|
||||
@@ -47,6 +48,9 @@ namespace BlackGui
|
||||
//! \copydoc CInfoArea::indexToPixmap
|
||||
const QPixmap &indexToPixmap(int areaIndex) const override;
|
||||
|
||||
//! Get navigator component
|
||||
BlackGui::Components::CNavigatorDockWidget *getNavigatorComponent();
|
||||
|
||||
public slots:
|
||||
//! Navigator floating
|
||||
void toggleNavigator();
|
||||
|
||||
@@ -15,12 +15,6 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="qw_InvisibleInfoArea"/>
|
||||
<widget class="BlackGui::Components::CNavigatorDockWidget" name="comp_Navigator">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="floating">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
||||
@@ -281,7 +281,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
|
||||
@@ -8,9 +8,17 @@
|
||||
*/
|
||||
|
||||
#include "navigatordockwidget.h"
|
||||
#include "blackgui/infoarea.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "ui_navigatordockwidget.h"
|
||||
|
||||
#include <QToolButton>
|
||||
#include <QGridLayout>
|
||||
#include <QAction>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -27,5 +35,130 @@ namespace BlackGui
|
||||
CNavigatorDockWidget::~CNavigatorDockWidget()
|
||||
{ }
|
||||
|
||||
void CNavigatorDockWidget::addAction(QAction *action)
|
||||
{
|
||||
if (action)
|
||||
{
|
||||
this->m_actions.append(action);
|
||||
QToolButton *tb = new QToolButton(this->ui->fr_NavigatorDockWidgetInner);
|
||||
tb->setDefaultAction(action);
|
||||
tb->setObjectName(this->objectName().append(":").append(action->objectName()));
|
||||
this->m_widgets.append(tb);
|
||||
}
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::addActions(QList<QAction *> actions)
|
||||
{
|
||||
if (actions.isEmpty()) { return; }
|
||||
for (QAction *a : actions)
|
||||
{
|
||||
this->addAction(a);
|
||||
}
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::buildNavigator(int columns)
|
||||
{
|
||||
if (m_firstBuild)
|
||||
{
|
||||
m_firstBuild = false;
|
||||
this->insertOwnActions();
|
||||
}
|
||||
|
||||
// remove old layout
|
||||
CGuiUtility::deleteLayout(this->ui->fr_NavigatorDockWidgetInner->layout(), false);
|
||||
|
||||
// new layout
|
||||
QGridLayout *gridLayout = new QGridLayout(this->ui->fr_NavigatorDockWidgetInner);
|
||||
gridLayout->setObjectName("gl_CNavigatorDockWidget");
|
||||
gridLayout->setSpacing(0);
|
||||
gridLayout->setMargin(0);
|
||||
gridLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
this->ui->fr_NavigatorDockWidgetInner->setLayout(gridLayout);
|
||||
int r = 0;
|
||||
int c = 0;
|
||||
for (int i = 0; i < this->m_widgets.size(); i++)
|
||||
{
|
||||
gridLayout->addWidget(this->m_widgets[i], r, c++);
|
||||
this->m_widgets[i]->show();
|
||||
if (c < columns) { continue; }
|
||||
c = 0;
|
||||
r++;
|
||||
}
|
||||
|
||||
// set the real values
|
||||
c = gridLayout->columnCount();
|
||||
r = gridLayout->rowCount();
|
||||
this->setMinimumSizeForWidgets(r, c);
|
||||
|
||||
// sizes
|
||||
QSize ws(gridLayout->sizeHint());
|
||||
this->resize(ws);
|
||||
|
||||
// see documentation, required as layout was changed
|
||||
// this requires setting widget again
|
||||
this->ui->fr_NavigatorDockWidgetInner->show();
|
||||
this->setWidget(this->ui->fr_NavigatorDockWidgetInner);
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::addToContextMenu(QMenu *contextMenu) const
|
||||
{
|
||||
QAction *a;
|
||||
a = contextMenu->addAction(CIcons::resize16(), "1 row", this, SLOT(ps_changeLayout()));
|
||||
a->setData("1r");
|
||||
a = contextMenu->addAction(CIcons::resize16(), "2 rows", this, SLOT(ps_changeLayout()));
|
||||
a->setData("2r");
|
||||
a = contextMenu->addAction(CIcons::resize16(), "1 column", this, SLOT(ps_changeLayout()));
|
||||
a->setData("1c");
|
||||
a = contextMenu->addAction(CIcons::resize16(), "2 columns", this, SLOT(ps_changeLayout()));
|
||||
a->setData("2c");
|
||||
contextMenu->addSeparator();
|
||||
CDockWidgetInfoArea::addToContextMenu(contextMenu);
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::ps_onStyleSheetsChanged()
|
||||
{
|
||||
const QString fn(CStyleSheetUtility::fileNameNavigator());
|
||||
const QString qss(CStyleSheetUtility::instance().style(fn));
|
||||
this->setStyleSheet(qss);
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::ps_changeLayout()
|
||||
{
|
||||
QAction *a = qobject_cast<QAction *>(QObject::sender());
|
||||
if (!a) { return; }
|
||||
QString v(a->data().toString());
|
||||
if (v == "1c") { buildNavigator(1);}
|
||||
else if (v == "2c") { buildNavigator(2);}
|
||||
else if (v == "1r") { buildNavigator(columnsForRows(1));}
|
||||
else if (v == "2r") { buildNavigator(columnsForRows(2));}
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::insertOwnActions()
|
||||
{
|
||||
QIcon i(CIcons::changeIconBackgroundColor(this->style()->standardIcon(QStyle::SP_TitleBarCloseButton), Qt::white, QSize(16, 16)));
|
||||
QAction *a = new QAction(i, "Close", this);
|
||||
connect(a, &QAction::triggered, this, &CNavigatorDockWidget::close);
|
||||
this->addAction(a);
|
||||
}
|
||||
|
||||
int CNavigatorDockWidget::columnsForRows(int rows)
|
||||
{
|
||||
Q_ASSERT(rows >= 0);
|
||||
int items = this->m_widgets.size();
|
||||
int c = items / rows;
|
||||
return (c * rows) < items ? c + 1 : c;
|
||||
}
|
||||
|
||||
void CNavigatorDockWidget::setMinimumSizeForWidgets(int rows, int columns)
|
||||
{
|
||||
int w = 10 * columns;
|
||||
int h = 10 * rows;
|
||||
QSize min(w, h);
|
||||
this->ui->qw_NavigatorDockWidgetOuter->setMinimumSize(min);
|
||||
this->ui->fr_NavigatorDockWidgetInner->setMinimumSize(min);
|
||||
this->setMinimumSize(min);
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_NAVIGATORDOCKWIDGET_H
|
||||
#define BLACKGUI_NAVIGATORDOCKWIDGET_H
|
||||
#ifndef BLACKGUI_COMPONENTS_NAVIGATORDOCKWIDGET_H
|
||||
#define BLACKGUI_COMPONENTS_NAVIGATORDOCKWIDGET_H
|
||||
|
||||
#include "blackgui/dockwidgetinfoarea.h"
|
||||
#include <QDockWidget>
|
||||
@@ -35,8 +35,42 @@ namespace BlackGui
|
||||
//! Destructor
|
||||
~CNavigatorDockWidget();
|
||||
|
||||
//! Add action as navigator item
|
||||
void addAction(QAction * action);
|
||||
|
||||
//! Add actions as navigator items
|
||||
void addActions(QList<QAction *> actions);
|
||||
|
||||
//! Navigator
|
||||
void buildNavigator(int columns);
|
||||
|
||||
protected:
|
||||
//! \copydoc CDockWidgetInfoArea::addToContextMenu
|
||||
virtual void addToContextMenu(QMenu *contextMenu) const override;
|
||||
|
||||
protected:
|
||||
//! \copydoc CDockWidget::ps_onStyleSheetsChanged
|
||||
virtual void ps_onStyleSheetsChanged() override;
|
||||
|
||||
private slots:
|
||||
//! Change the layout
|
||||
void ps_changeLayout();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CNavigatorDockWidget> ui;
|
||||
QList<QWidget *> m_widgets;
|
||||
QList<QAction *> m_actions;
|
||||
bool m_firstBuild = true;
|
||||
|
||||
//! Insert own actions
|
||||
void insertOwnActions();
|
||||
|
||||
//! How many columns for given rows
|
||||
int columnsForRows(int rows);
|
||||
|
||||
//! Set widgets to their minimum size
|
||||
void setMinimumSizeForWidgets(int rows, int columns);
|
||||
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
||||
@@ -6,10 +6,16 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>89</width>
|
||||
<height>300</height>
|
||||
<width>90</width>
|
||||
<height>383</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="floating">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@@ -22,19 +28,33 @@
|
||||
<property name="windowTitle">
|
||||
<string>Navigator</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="qw_NavigatorDockWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QToolButton" name="toolButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
<widget class="QWidget" name="qw_NavigatorDockWidgetOuter">
|
||||
<layout class="QVBoxLayout" name="vl_NavigatorDockWidgetOuter">
|
||||
<property name="spacing">
|
||||
<number>0</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>
|
||||
<widget class="QFrame" name="fr_NavigatorDockWidgetInner">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QToolButton" name="toolButton_2">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user