refs #304, style sheet support for dock widgets

This commit is contained in:
Klaus Basan
2014-08-02 22:22:58 +02:00
parent f8774540f2
commit c197ec8296
2 changed files with 31 additions and 6 deletions

View File

@@ -8,17 +8,22 @@
*/
#include "dockwidget.h"
#include "blackmisc/iconsstandard.h"
#include "blackmisc/icons.h"
#include "blackgui/stylesheetutility.h"
#include <QCloseEvent>
#include <QStyleOption>
#include <QPainter>
namespace BlackGui
{
CDockWidget::CDockWidget(QWidget *parent) : QDockWidget(parent)
{
this->ps_onStyleSheetsChanged();
this->initTitleBarWidgets();
// connect
connect(this, &QDockWidget::topLevelChanged, this, &CDockWidget::ps_onTopLevelChanged);
connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDockWidget::ps_onStyleSheetsChanged);
// context menu
this->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -85,14 +90,24 @@ namespace BlackGui
{
if (this->isFloating())
{
contextMenu->addAction(BlackMisc::CIconsStandard::dockTop16(), "Dock", this, SLOT(toggleFloating()));
contextMenu->addAction(BlackMisc::CIcons::dockTop16(), "Dock", this, SLOT(toggleFloating()));
}
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)
{
if (topLevel)
@@ -126,11 +141,15 @@ namespace BlackGui
void CDockWidget::ps_showContextMenu(const QPoint &pos)
{
// for most widgets
QPoint globalPos = this->mapToGlobal(pos);
QScopedPointer<QMenu> contextMenu(new QMenu(this));
this->addToContextMenu(contextMenu.data());
QAction *selectedItem = contextMenu.data()->exec(globalPos);
Q_UNUSED(selectedItem);
}
void CDockWidget::ps_onStyleSheetsChanged()
{
// void
}
}

View File

@@ -79,12 +79,19 @@ namespace BlackGui
//! Contribute to menu
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:
//! Top level has been chaged
virtual void ps_onTopLevelChanged(bool topLevel);
//! Context menu
void ps_showContextMenu(const QPoint &pos);
virtual void ps_showContextMenu(const QPoint &pos);
private:
QWidget *m_emptyTitleBar = nullptr; //!< replacing default title bar
@@ -96,7 +103,6 @@ namespace BlackGui
//! Empty widget with no size
void initTitleBarWidgets();
};
} // namespace