mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
refs #304, style sheet support for dock widgets
This commit is contained in:
@@ -8,17 +8,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dockwidget.h"
|
#include "dockwidget.h"
|
||||||
#include "blackmisc/iconsstandard.h"
|
#include "blackmisc/icons.h"
|
||||||
|
#include "blackgui/stylesheetutility.h"
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
CDockWidget::CDockWidget(QWidget *parent) : QDockWidget(parent)
|
CDockWidget::CDockWidget(QWidget *parent) : QDockWidget(parent)
|
||||||
{
|
{
|
||||||
|
this->ps_onStyleSheetsChanged();
|
||||||
this->initTitleBarWidgets();
|
this->initTitleBarWidgets();
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
connect(this, &QDockWidget::topLevelChanged, this, &CDockWidget::ps_onTopLevelChanged);
|
connect(this, &QDockWidget::topLevelChanged, this, &CDockWidget::ps_onTopLevelChanged);
|
||||||
|
connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDockWidget::ps_onStyleSheetsChanged);
|
||||||
|
|
||||||
// context menu
|
// context menu
|
||||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
@@ -85,14 +90,24 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (this->isFloating())
|
if (this->isFloating())
|
||||||
{
|
{
|
||||||
contextMenu->addAction(BlackMisc::CIconsStandard::dockTop16(), "Dock", this, SLOT(toggleFloating()));
|
contextMenu->addAction(BlackMisc::CIcons::dockTop16(), "Dock", this, SLOT(toggleFloating()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
contextMenu->addAction(BlackMisc::CIconsStandard::floatOne16(), "Float", this, SLOT(toggleFloating()));
|
contextMenu->addAction(BlackMisc::CIcons::floatOne16(), "Float", this, SLOT(toggleFloating()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDockWidget::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
// included for style sheet compliance
|
||||||
|
// QStyleOption opt;
|
||||||
|
// opt.init(this);
|
||||||
|
// QPainter p(this);
|
||||||
|
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||||
|
QDockWidget::paintEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
||||||
{
|
{
|
||||||
if (topLevel)
|
if (topLevel)
|
||||||
@@ -126,11 +141,15 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDockWidget::ps_showContextMenu(const QPoint &pos)
|
void CDockWidget::ps_showContextMenu(const QPoint &pos)
|
||||||
{
|
{
|
||||||
// for most widgets
|
|
||||||
QPoint globalPos = this->mapToGlobal(pos);
|
QPoint globalPos = this->mapToGlobal(pos);
|
||||||
QScopedPointer<QMenu> contextMenu(new QMenu(this));
|
QScopedPointer<QMenu> contextMenu(new QMenu(this));
|
||||||
this->addToContextMenu(contextMenu.data());
|
this->addToContextMenu(contextMenu.data());
|
||||||
QAction *selectedItem = contextMenu.data()->exec(globalPos);
|
QAction *selectedItem = contextMenu.data()->exec(globalPos);
|
||||||
Q_UNUSED(selectedItem);
|
Q_UNUSED(selectedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDockWidget::ps_onStyleSheetsChanged()
|
||||||
|
{
|
||||||
|
// void
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,12 +79,19 @@ namespace BlackGui
|
|||||||
//! Contribute to menu
|
//! Contribute to menu
|
||||||
virtual void addToContextMenu(QMenu *contextMenu) const;
|
virtual void addToContextMenu(QMenu *contextMenu) const;
|
||||||
|
|
||||||
|
//! Paint event
|
||||||
|
virtual void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
//! Style sheet has changed
|
||||||
|
virtual void ps_onStyleSheetsChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Top level has been chaged
|
//! Top level has been chaged
|
||||||
virtual void ps_onTopLevelChanged(bool topLevel);
|
virtual void ps_onTopLevelChanged(bool topLevel);
|
||||||
|
|
||||||
//! Context menu
|
//! Context menu
|
||||||
void ps_showContextMenu(const QPoint &pos);
|
virtual void ps_showContextMenu(const QPoint &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_emptyTitleBar = nullptr; //!< replacing default title bar
|
QWidget *m_emptyTitleBar = nullptr; //!< replacing default title bar
|
||||||
@@ -96,7 +103,6 @@ namespace BlackGui
|
|||||||
|
|
||||||
//! Empty widget with no size
|
//! Empty widget with no size
|
||||||
void initTitleBarWidgets();
|
void initTitleBarWidgets();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user