Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#550
  • Loading branch information
deepin-ci-robot committed Feb 22, 2024
1 parent 45fc32d commit 33ccaf3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 33 deletions.
11 changes: 8 additions & 3 deletions examples/collections/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/dblureffectwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ QColor DBlurEffectWidgetPrivate::getMaskColor(const QColor &baseColor) const

int maskAlpha = this->getMaskColorAlpha();

if (!isBehindWindowBlendMode() || DWindowManagerHelper::instance()->hasComposite()) {
if (!isBehindWindowBlendMode() || DWindowManagerHelper::instance()->hasBlurWindow()) {
color.setAlpha(maskAlpha);
} else {
return ct == DGuiApplicationHelper::DarkType ? "#202020" : "#D2D2D2";
Expand All @@ -158,7 +158,7 @@ void DBlurEffectWidgetPrivate::setMaskColor(const QColor &color)
maskColor = color;

if (isBehindWindowBlendMode()) {
maskColor.setAlpha(DWindowManagerHelper::instance()->hasComposite() ? getMaskColorAlpha() : MASK_COLOR_ALPHA_DEFAULT);
maskColor.setAlpha(DWindowManagerHelper::instance()->hasBlurWindow() ? getMaskColorAlpha() : MASK_COLOR_ALPHA_DEFAULT);
}

D_Q(DBlurEffectWidget);
Expand Down
56 changes: 38 additions & 18 deletions src/widgets/dmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <qwidgetaction.h>
#include <QScreen>

#include <DAnchors>
#include <DConfig>

#ifdef Q_OS_MAC
Expand Down Expand Up @@ -148,11 +149,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.
*/
Expand Down Expand Up @@ -203,28 +204,45 @@ 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);
d->sidebarSep = new DVerticalLine(this);
d->sidebarSep->setWindowFlag(Qt::WindowStaysOnTopHint);
d->sidebarSep->setLineWidth(1);
d->sidebarSep->raise();
DAnchorsBase::setAnchor(d->sidebarSep, Qt::AnchorRight, tb, Qt::AnchorRight);

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");
bgBlurWidget->setMaskAlpha(229); // 90%

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) {
tb->setVisible(expanded);
d->sidebarSep->setVisible(expanded);
d->updateTitleShadowGeometry();
});
connect(d->sidebarHelper, &DSidebarHelper::visibleChanged, tb, [tb, d] {
tb->setVisible(d->sidebarHelper->sectionVisible());
d->sidebarSep->setVisible(d->sidebarHelper->sectionVisible());
d->updateTitleShadowGeometry();
});

Expand Down Expand Up @@ -295,7 +313,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.
*/
Expand Down Expand Up @@ -399,10 +417,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
Expand All @@ -419,7 +437,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.
*/
Expand Down Expand Up @@ -463,9 +481,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.
*/
Expand All @@ -483,9 +501,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
Expand Down Expand Up @@ -517,10 +535,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
Expand Down Expand Up @@ -818,6 +836,8 @@ void DMainWindow::resizeEvent(QResizeEvent *event)

if (sidebarWidget()) {
sidebarWidget()->resize(d->tb->size());
d->sidebarSep->resize({1, rect().height()});
d->sidebarSep->raise();
}
return QMainWindow::resizeEvent(event);
}
Expand Down
16 changes: 10 additions & 6 deletions src/widgets/dslider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ void SliderStrip::paintEvent(QPaintEvent *event)
if (scaleInfo.isEmpty())
return;

auto elidedText = [this](const QString &text, int width) {
return fontMetrics().elidedText(text, Qt::ElideRight, width);
};

if (orient == Qt::Horizontal) {
width -= 2 * offsetSize + margin * 2;
startX += offsetSize + margin;
Expand All @@ -837,15 +841,15 @@ void SliderStrip::paintEvent(QPaintEvent *event)
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(endX, textPos, width, height - tickSize), Qt::AlignLeft, scaleInfo[0]);
pa.drawText(QRectF(endX, textPos, width, height - tickSize), Qt::AlignLeft, elidedText(scaleInfo[0], width / paragraph));

for (int i = 1; i < paragraph - 1; i++) {
startX += average;
endX = startX;
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(endX - width / 2, textPos, width, height - tickSize), Qt::AlignHCenter, scaleInfo[i]);
pa.drawText(QRectF(endX - width / 2, textPos, width, height - tickSize), Qt::AlignHCenter, elidedText(scaleInfo[i], width / paragraph));
}

if (paragraph > 1) {
Expand All @@ -854,7 +858,7 @@ void SliderStrip::paintEvent(QPaintEvent *event)
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(endX - width, textPos, width, height - tickSize), Qt::AlignRight, scaleInfo[paragraph - 1]);
pa.drawText(QRectF(endX - width, textPos, width, height - tickSize), Qt::AlignRight, elidedText(scaleInfo[paragraph - 1], width / paragraph));
}
} else {
startY = offsetSize + margin;
Expand All @@ -877,15 +881,15 @@ void SliderStrip::paintEvent(QPaintEvent *event)
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(textPos, endY - average / 2 + offsetSize / 2, width - tickSize, average), text_flags, scaleInfo[0]);
pa.drawText(QRectF(textPos, endY - average / 2 + offsetSize / 2, width - tickSize, average), text_flags, elidedText(scaleInfo[0], width - tickSize));

for (int i = 1; i < paragraph - 1; i++) {
startY += average;
endY = startY;
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(textPos, endY - average / 2, width - tickSize, average), text_flags, scaleInfo[i]);
pa.drawText(QRectF(textPos, endY - average / 2, width - tickSize, average), text_flags, elidedText(scaleInfo[i], width - tickSize));
}

if (paragraph > 1) {
Expand All @@ -894,7 +898,7 @@ void SliderStrip::paintEvent(QPaintEvent *event)
pa.setPen(penLine);
pa.drawLine(QPointF(startX, startY), QPointF(endX, endY));
pa.setPen(penNumber);
pa.drawText(QRectF(textPos, endY - average / 2 - offsetSize / 2, width - tickSize, average), text_flags, scaleInfo[paragraph - 1]);
pa.drawText(QRectF(textPos, endY - average / 2 - offsetSize / 2, width - tickSize, average), text_flags, elidedText(scaleInfo[paragraph - 1], width - tickSize));
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,19 +1272,27 @@ 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);
bgBlurWidget->setMaskAlpha(229); // 90%
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());
});
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/private/dmainwindow_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <DMainWindow>
#include <DShadowLine>

#include <DFrame>
#include <DObjectPrivate>

class QShortcut;
Expand Down Expand Up @@ -118,6 +119,7 @@ class DMainWindowPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
DSidebarHelper *sidebarHelper = nullptr;
QWidget *sidebarWidget = nullptr;
QToolBar *tb = nullptr;
DVerticalLine *sidebarSep = nullptr;

private:
D_DECLARE_PUBLIC(DMainWindow)

Check warning on line 125 in src/widgets/private/dmainwindow_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If D_DECLARE_PUBLIC is a macro then please configure it.
Expand Down

0 comments on commit 33ccaf3

Please sign in to comment.