From 807ea125f0da3a50191132bf5e1bf225d570bcaa Mon Sep 17 00:00:00 2001 From: ck Date: Tue, 30 Jan 2024 14:48:34 +0800 Subject: [PATCH] feat: sidebar widget with blur widget behind add a blur widget(behindwindowblend) behind sidebar widget --- examples/collections/mainwindow.cpp | 11 ++++++-- src/widgets/dmainwindow.cpp | 44 +++++++++++++++++------------ src/widgets/dtitlebar.cpp | 15 +++++++--- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/examples/collections/mainwindow.cpp b/examples/collections/mainwindow.cpp index 0be5165af..3f9a08de0 100644 --- a/examples/collections/mainwindow.cpp +++ b/examples/collections/mainwindow.cpp @@ -168,13 +168,18 @@ MainWindow::MainWindow(QWidget *parent) m_pStackedWidget = new QStackedWidget; m_pListViewModel = new QStandardItemModel(this); - m_pListView = new DListView(this); + QWidget *pw = new QWidget(this); + m_pListView = new DListView(pw); m_pListView->setFixedWidth(200); m_pListView->setItemSpacing(0); m_pListView->setModel(m_pListViewModel); + m_pListView->setViewportMargins(0, 0, 10, 0); - setSidebarWidget(m_pListView); - setSidebarWidth(200); + QHBoxLayout *hlay = new QHBoxLayout(pw); + hlay->setContentsMargins(10, 0, 10, 0); + hlay->addWidget(m_pListView); + setSidebarWidget(pw); + setSidebarWidth(210); // mainLayout->addWidget(m_pListView); diff --git a/src/widgets/dmainwindow.cpp b/src/widgets/dmainwindow.cpp index 7d638c2bc..0c9909fe8 100644 --- a/src/widgets/dmainwindow.cpp +++ b/src/widgets/dmainwindow.cpp @@ -148,11 +148,11 @@ void DMainWindowPrivate::_q_autoShowFeatureDialog() \class Dtk::Widget::DMainWindow \inmodule dtkwidget \brief The DMainWindow class provides a main application window. - + A main window provides a framework for building an application's user interface. DMainWindow has its own layout compared to QMainWindow, it has only title bar and content area, simpler and cleaner. - + Developers can provide customized title bar and content to make the application rich functional. */ @@ -203,20 +203,28 @@ void DMainWindow::setSidebarWidget(QWidget *widget) return; d->sidebarWidget = widget; - d->sidebarWidget->setAutoFillBackground(true); - d->sidebarWidget->setBackgroundRole(DPalette::Button); if (!d->sidebarHelper) { d->sidebarHelper = new DSidebarHelper(this); d->titlebar->setSidebarHelper(d->sidebarHelper); QToolBar *tb = new QToolBar(this); + tb->layout()->setMargin(0); tb->setMovable(false); - tb->setForegroundRole(QPalette::Base); auto *contentAction = tb->toggleViewAction(); contentAction->setVisible(false); addToolBar(Qt::LeftToolBarArea, tb); - widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - tb->addWidget(widget); - widget->resize(tb->size()); + d->sidebarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + setAttribute(Qt::WA_TranslucentBackground); + auto bgBlurWidget = new DBlurEffectWidget(this); + bgBlurWidget->setBlendMode(DBlurEffectWidget::BehindWindowBlend); + bgBlurWidget->setMaskColor(DBlurEffectWidget::AutoColor); + bgBlurWidget->setObjectName("sidebarBlurWidget"); + + QVBoxLayout *vlay = new QVBoxLayout(bgBlurWidget); + vlay->setContentsMargins(0, 0, 0, 0); + vlay->addWidget(d->sidebarWidget); + tb->addWidget(bgBlurWidget); + d->sidebarWidget->resize(tb->size()); connect(d->sidebarHelper, &DSidebarHelper::widthChanged, tb, &QToolBar::setFixedWidth); connect(d->sidebarHelper, &DSidebarHelper::expandChanged, this, [tb, d] (bool expanded) { @@ -295,7 +303,7 @@ void DMainWindow::setSidebarExpanded(bool expended) /*! \brief DMainWindow::isDXcbWindow \return Whether this window is dxcb backended. - + Many features like blurred background and window clipping are supported only if the window is using the dxcb Qt platform plugin. */ @@ -399,10 +407,10 @@ QColor DMainWindow::shadowColor() const /*! \property DMainWindow::clipPath \brief This property holds the custom QPainterPath to be used to clip the window. - + By default DMainWindow is clipped as a corner-rounded rectangle, but you can supply a custom QPainterPath to do custom shaped window. - + \sa DMainWindow::frameMask */ QPainterPath DMainWindow::clipPath() const @@ -419,7 +427,7 @@ QPainterPath DMainWindow::clipPath() const /*! \property DMainWindow::frameMask \brief This property holds the mask to be applied on the window. - + For better clip quality, for example antialiasing, use property DMainWindow::clipPath instead. */ @@ -463,9 +471,9 @@ bool DMainWindow::translucentBackground() const /*! \brief DMainWindow::enableSystemResize \return This property holds whether the window can be resized by the user. - + The default value of this property is true. - + You can set this property to false and implement the resize polizy of this window by you self. */ @@ -483,9 +491,9 @@ bool DMainWindow::enableSystemResize() const /*! \property DMainWindow::enableSystemMove \brief This property holds whether the window can be moved by the user. - + The default value of this property is true. - + You can set this property to false and choose the effective area to drag and move. */ bool DMainWindow::enableSystemMove() const @@ -517,10 +525,10 @@ bool DMainWindow::enableBlurWindow() const /*! \property DMainWindow::autoInputMaskByClipPath \brief This property holds whether the user input is masked by the clip path. - + Sometimes you may want to handle events happening in the areas that are visually clipped by the setting DMainWindow::clipPath. - + The default value of this property is true. */ bool DMainWindow::autoInputMaskByClipPath() const diff --git a/src/widgets/dtitlebar.cpp b/src/widgets/dtitlebar.cpp index 7a17ed5ad..0528e9a22 100644 --- a/src/widgets/dtitlebar.cpp +++ b/src/widgets/dtitlebar.cpp @@ -1272,19 +1272,26 @@ void DTitlebar::setSidebarHelper(DSidebarHelper *helper) d->expandButton = new DIconButton(this); d->expandButton->setIcon(DDciIcon::fromTheme("window_sidebar")); d->expandButton->setIconSize(QSize(DefaultExpandButtonHeight(), DefaultExpandButtonHeight())); - d->expandButton->setCheckable(true); - d->expandButton->setChecked(true); d->expandButton->setFlat(true); d->sidebarBackgroundWidget = new QWidget(this); + QHBoxLayout *hlay = new QHBoxLayout(d->sidebarBackgroundWidget); + hlay->setMargin(0); + auto bgBlurWidget = new DBlurEffectWidget(d->sidebarBackgroundWidget); + bgBlurWidget->setObjectName("titlebarBlurWidget"); + bgBlurWidget->setBlendMode(DBlurEffectWidget::BehindWindowBlend); + bgBlurWidget->setMaskColor(DBlurEffectWidget::AutoColor); + hlay->addWidget(bgBlurWidget); + d->sidebarBackgroundWidget->setAccessibleName("SidebarBackgroundWidget"); d->sidebarBackgroundWidget->setAutoFillBackground(true); d->sidebarBackgroundWidget->setBackgroundRole(DPalette::Button); d->sidebarBackgroundWidget->move(pos()); d->sidebarBackgroundWidget->lower(); d->leftLayout->addWidget(d->expandButton, 0, Qt::AlignLeft); - connect(d->expandButton, &DIconButton::clicked, [this, d] (bool isExpanded) { - d->sidebarHelper->setExpanded(isExpanded); + connect(d->expandButton, &DIconButton::clicked, [this, d] (bool) { + bool isExpanded = d->sidebarHelper->expanded(); + d->sidebarHelper->setExpanded(!isExpanded); int x = isExpanded ? d->sidebarHelper->width() : 0; d->separator->move(x, height() - d->separator->height()); });