Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkwidget #24

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
101 changes: 67 additions & 34 deletions src/widgets/daboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
DCORE_USE_NAMESPACE
DWIDGET_BEGIN_NAMESPACE

const QString DAboutDialogPrivate::websiteLinkTemplate = "<a href='%1' style='text-decoration: none; font-size:13px; color: #004EE5;'>%2</a>";
const QString DAboutDialogPrivate::websiteLinkTemplate = "<a href='%1' style='text-decoration: none; font-size:12px; color: rgba(0,129,255,0.9);'>%2</a>";

DRedPointLabel::DRedPointLabel(QWidget *parent)
: QLabel(parent)
Expand Down Expand Up @@ -62,25 +62,31 @@ void DAboutDialogPrivate::init()
{
D_Q(DAboutDialog);

q->setMaximumWidth(540);
q->setFixedSize(540, 290);

// overwrite default info if distribution config file existed.
loadDistributionInfo();

logoLabel = new QLabel();
logoLabel->setContentsMargins(0, 0, 0, 0);
logoLabel->setAlignment(Qt::AlignCenter);

productNameLabel = new QLabel();
productNameLabel->setForegroundRole(QPalette::BrightText);
productNameLabel->setObjectName("ProductNameLabel");
productNameLabel->setWordWrap(true);
productNameLabel->setAlignment(Qt::AlignCenter);
DFontSizeManager *fontManager = DFontSizeManager::instance();
fontManager->bind(productNameLabel, DFontSizeManager::T5, QFont::DemiBold);
fontManager->bind(productNameLabel, DFontSizeManager::T5, QFont::Medium);

versionLabel = new QLabel();
versionLabel->setObjectName("VersionLabel");
fontManager->bind(versionLabel, DFontSizeManager::T8, QFont::DemiBold);
versionLabel->setForegroundRole(QPalette::BrightText);
fontManager->bind(versionLabel, DFontSizeManager::T8, QFont::Medium);

companyLogoLabel = new QLabel();
companyLogoLabel->setPixmap(loadPixmap(logoPath));
companyLogoLabel->hide();

websiteLabel = new QLabel();
websiteLabel->setObjectName("WebsiteLabel");
Expand All @@ -89,24 +95,26 @@ void DAboutDialogPrivate::init()
updateWebsiteLabel();

descriptionLabel = new QLabel();
descriptionLabel->setForegroundRole(QPalette::BrightText);
descriptionLabel->setFixedWidth(280);
descriptionLabel->setObjectName("DescriptionLabel");
descriptionLabel->setAlignment(Qt::AlignLeft);
descriptionLabel->setWordWrap(true);
descriptionLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
fontManager->bind(descriptionLabel, DFontSizeManager::T8, QFont::DemiBold);
fontManager->bind(descriptionLabel, DFontSizeManager::T8, QFont::Medium);

licenseLabel = new QLabel();
licenseLabel->setFixedWidth(180);
licenseLabel->setObjectName("LicenseLabel");
licenseLabel->setAlignment(Qt::AlignHCenter);
licenseLabel->setWordWrap(true);
licenseLabel->setForegroundRole(QPalette::BrightText);
licenseLabel->setFixedWidth(280);
licenseLabel->setAlignment(Qt::AlignLeft);
licenseLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
fontManager->bind(licenseLabel, DFontSizeManager::T8, QFont::Medium);
licenseLabel->hide();
fontManager->bind(licenseLabel, DFontSizeManager::T10, QFont::Medium);

QLabel *versionTipLabel = new QLabel(QObject::tr("Version"));
fontManager->bind(versionTipLabel, DFontSizeManager::T10, QFont::Normal);
fontManager->bind(versionTipLabel, DFontSizeManager::T10, QFont::Thin);
featureLabel = new QLabel(websiteLinkTemplate.arg(websiteLink).arg(QObject::tr("Features")));
featureLabel->setContextMenuPolicy(Qt::NoContextMenu);
featureLabel->setOpenExternalLinks(false);
Expand All @@ -123,37 +131,53 @@ void DAboutDialogPrivate::init()
vFeatureLayout->addWidget(redPointLabel, 0, Qt::AlignLeft);
vFeatureLayout->addStretch(0);
QLabel *homePageTipLabel = new QLabel(QObject::tr("Homepage"));
fontManager->bind(homePageTipLabel, DFontSizeManager::T10, QFont::Normal);
fontManager->bind(homePageTipLabel, DFontSizeManager::T10, QFont::Thin);
QLabel *descriptionTipLabel = new QLabel(QObject::tr("Description"));
fontManager->bind(descriptionTipLabel, DFontSizeManager::T10, QFont::Normal);
fontManager->bind(descriptionTipLabel, DFontSizeManager::T10, QFont::Thin);
acknowledgementTipLabel = new QLabel(QObject::tr("Acknowledgements"));
fontManager->bind(acknowledgementTipLabel, DFontSizeManager::T10, QFont::Normal);
fontManager->bind(acknowledgementTipLabel, DFontSizeManager::T10, QFont::Thin);
licenseTipLabel = new QLabel(QObject::tr("License"));
fontManager->bind(licenseTipLabel, DFontSizeManager::T10, QFont::Thin);
licenseTipLabel->hide();

acknowledgementLabel = new QLabel(QObject::tr("Sincerely appreciate the open-source software used."));
acknowledgementLabel->setForegroundRole(QPalette::BrightText);
acknowledgementLabel->setFixedWidth(280);
acknowledgementLabel->setWordWrap(true);
acknowledgementLabel->setContextMenuPolicy(Qt::NoContextMenu);
acknowledgementLabel->setOpenExternalLinks(false);
fontManager->bind(acknowledgementLabel, DFontSizeManager::T8, QFont::DemiBold);
fontManager->bind(acknowledgementLabel, DFontSizeManager::T8, QFont::Medium);

q->connect(websiteLabel, SIGNAL(linkActivated(QString)), q, SLOT(_q_onLinkActivated(QString)));
q->connect(featureLabel, SIGNAL(linkActivated(QString)), q, SLOT(_q_onFeatureActivated(QString)));
q->connect(descriptionLabel, SIGNAL(linkActivated(QString)), q, SLOT(_q_onLinkActivated(QString)));
q->connect(licenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_q_onLinkActivated(QString)));
q->connect(acknowledgementLabel, SIGNAL(linkActivated(QString)), q, SLOT(_q_onLicenseActivated(QString)));

QScrollArea *productNameScrollArea = new QScrollArea;
productNameScrollArea->setMaximumHeight(50);
productNameScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
productNameScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
QPalette scrollPalette;

scrollPalette.setBrush(QPalette::Window, Qt::transparent);
productNameScrollArea->setFrameShape(QFrame::NoFrame);
productNameScrollArea->setWidget(productNameLabel);
productNameScrollArea->setWidgetResizable(true);
productNameScrollArea->setPalette(scrollPalette);

QVBoxLayout *leftVLayout = new QVBoxLayout;
leftVLayout->setContentsMargins(10, 3, 0, 10);
leftVLayout->setSpacing(0);
leftVLayout->addWidget(logoLabel, 0, Qt::AlignCenter);
leftVLayout->setContentsMargins(0, 10, 0, 0);
leftVLayout->addWidget(logoLabel);
leftVLayout->addSpacing(8);
leftVLayout->addWidget(productNameLabel, 0, Qt::AlignCenter);
leftVLayout->addStretch(0);
leftVLayout->addWidget(companyLogoLabel, 0, Qt::AlignCenter);
leftVLayout->addWidget(productNameScrollArea);
leftVLayout->addSpacing(16);
leftVLayout->addWidget(companyLogoLabel);
leftVLayout->addSpacing(3);
leftVLayout->addWidget(licenseLabel, 0, Qt::AlignHCenter);
leftVLayout->addStretch(0);

QVBoxLayout *rightVLayout = new QVBoxLayout;
rightVLayout->setContentsMargins(0, 3, 20, 10);
rightVLayout->setContentsMargins(0, 0, 10, 0);
rightVLayout->setSpacing(0);
rightVLayout->addWidget(versionTipLabel, 0, Qt::AlignLeft);
rightVLayout->addWidget(versionLabel, 0, Qt::AlignLeft);
Expand All @@ -167,27 +191,35 @@ void DAboutDialogPrivate::init()
rightVLayout->addSpacing(10);
rightVLayout->addWidget(acknowledgementTipLabel, 0, Qt::AlignLeft);
rightVLayout->addWidget(acknowledgementLabel, 0, Qt::AlignLeft);
rightVLayout->addSpacing(10);
rightVLayout->addWidget(licenseTipLabel, 0, Qt::AlignLeft);
rightVLayout->addWidget(licenseLabel, 0, Qt::AlignLeft);
rightVLayout->addStretch(0);

QScrollArea *rightScrollArea = new QScrollArea;
rightScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
rightScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
QWidget *rightContent = new QWidget;
rightContent->setLayout(rightVLayout);

rightScrollArea->setFrameShape(QFrame::NoFrame);
rightScrollArea->setWidget(rightContent);
rightScrollArea->setWidgetResizable(true);
rightScrollArea->setPalette(scrollPalette);

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addLayout(leftVLayout);
mainLayout->addSpacing(29);
mainLayout->addLayout(rightVLayout);
mainLayout->setSpacing(0);
mainLayout->setMargin(0);
mainLayout->addLayout(leftVLayout, 2);
mainLayout->addSpacing(20);
mainLayout->addWidget(rightScrollArea, 3);

QScrollArea *mainScrollArea = new QScrollArea;
QWidget *mainContent = new QWidget;
QPalette scrollPalette;

scrollPalette.setBrush(QPalette::Window, Qt::transparent);
mainScrollArea->setFrameShape(QFrame::NoFrame);
mainScrollArea->setWidget(mainContent);
mainScrollArea->setWidgetResizable(true);
mainScrollArea->setPalette(scrollPalette);

mainContent->setLayout(mainLayout);
q->addContent(mainScrollArea);
q->addContent(mainContent);
q->setContentsMargins(0, 0, 0, 10);

DConfig config("org.deepin.dtk.preference");
bool isUpdated = config.value("featureUpdated", false).toBool();
Expand Down Expand Up @@ -540,6 +572,7 @@ void DAboutDialog::setLicense(const QString &license)

d->licenseLabel->setText(license);
d->licenseLabel->setVisible(!license.isEmpty());
d->licenseTipLabel->setVisible(!license.isEmpty());
}

void DAboutDialog::keyPressEvent(QKeyEvent *event)
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
Loading
Loading