Skip to content

Commit

Permalink
fix: border color issue
Browse files Browse the repository at this point in the history
adjust Inner border and outer border

Issue: linuxdeepin/developer-center#8342
  • Loading branch information
mhduiy committed Jun 24, 2024
1 parent 3026678 commit 21c9f5e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
8 changes: 2 additions & 6 deletions app/mainview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
DGUI_USE_NAMESPACE
WIDGETS_FRAME_BEGIN_NAMESPACE
MainView::MainView( WidgetManager *manager, QWidget *parent)
: DBlurEffectWidget (parent)
: QWidget (parent)
, m_manager(manager)
, m_animationContainer(new AnimationViewContainer(parent))
, m_layout(new QHBoxLayout(this))
Expand All @@ -31,6 +31,7 @@ MainView::MainView( WidgetManager *manager, QWidget *parent)
, m_trickTimer(new QTimer(this))
{
setParent(m_animationContainer);
setAttribute(Qt::WA_TranslucentBackground);
m_appearancehandler->addTargetWidget(m_animationContainer);

// don't display tray in Dock
Expand All @@ -45,7 +46,6 @@ MainView::MainView( WidgetManager *manager, QWidget *parent)
handler.setEnableSystemMove(false);
}

setBlendMode(DBlurEffectWidget::BehindWindowBlend);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);

m_layout->setContentsMargins(UI::defaultMargins);
Expand Down Expand Up @@ -91,10 +91,6 @@ MainView::MainView( WidgetManager *manager, QWidget *parent)
});

m_layout->addStretch();

DPlatformWindowHandle handler(parentWidget());
handler.setBorderWidth(0);
handler.setShadowRadius(0);
}

MainView::~MainView()
Expand Down
2 changes: 1 addition & 1 deletion app/mainview.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GeometryHandler;
class Appearancehandler;
DWIDGET_USE_NAMESPACE

class MainView : public DBlurEffectWidget
class MainView : public QWidget
{
Q_OBJECT

Expand Down
64 changes: 62 additions & 2 deletions app/utils/animationviewcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,57 @@
#include <QScreen>
#include <QDBusInterface>
#include <QPropertyAnimation>
#include <QPainter>

static QColor outerBorderColor = QColor(0, 0, 0, static_cast<int>(0.15 * 255));
static QColor innerBorderColor = QColor(255, 255, 255, static_cast<int>(0.2 * 255));
#define ALPHA_OFFSET 10

WIDGETS_USE_NAMESPACE
DGUI_USE_NAMESPACE
WIDGETS_FRAME_BEGIN_NAMESPACE
AnimationViewContainer::AnimationViewContainer(QWidget *parent)
: DBlurEffectWidget (parent)
, m_windowHandle(new DPlatformWindowHandle(this, this))
{
setBlurEnabled(false);
setAttribute(Qt::WA_TranslucentBackground);
resize(0, 0); // Should set size explicitly for region monitor to work correctly.
setWindowFlags(Qt::Tool);
m_cornerRadius = m_windowHandle->windowRadius();
m_themeType= DGuiApplicationHelper::instance()->themeType();
m_windowHandle->setBorderWidth(1);

auto setOuterBorderColor = [this]() {
auto outerBorderNewColor = outerBorderColor;
if (m_themeType == DGuiApplicationHelper::ColorType::DarkType) {
outerBorderNewColor.setAlpha(maskAlpha() + ALPHA_OFFSET * 2);
}

m_windowHandle->setBorderColor(outerBorderNewColor);
};

connect(this, &DBlurEffectWidget::maskAlphaChanged, [this, setOuterBorderColor]() {
setOuterBorderColor();
update();
});

connect(m_windowHandle, &DPlatformWindowHandle::windowRadiusChanged, this, [this](){
if (m_cornerRadius == m_windowHandle->windowRadius())
return;

m_cornerRadius = m_windowHandle->windowRadius();
update();
});

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, [this, setOuterBorderColor](DGuiApplicationHelper::ColorType type){
if (!m_windowHandle || type == m_themeType)
return;

m_themeType = type;
setOuterBorderColor();
update();
});

setOuterBorderColor();
}

AnimationViewContainer::~AnimationViewContainer()
Expand Down Expand Up @@ -145,4 +185,24 @@ void AnimationViewContainer::setCurrentX(const int x)
rect.setWidth(m_targetRect.right() - x);
setGeometry(rect);
}

void AnimationViewContainer::paintEvent(QPaintEvent *e)
{
DBlurEffectWidget::paintEvent(e);

QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
QPen pen;
pen.setWidth(1);

auto innerBorderNewColor = innerBorderColor;
if (m_themeType != DGuiApplicationHelper::DarkType) {
innerBorderNewColor.setAlpha(maskAlpha() + ALPHA_OFFSET);
}

pen.setColor(innerBorderNewColor);
p.setPen(pen);
p.drawRoundedRect(rect(), m_cornerRadius, m_cornerRadius);
}

WIDGETS_FRAME_END_NAMESPACE
9 changes: 9 additions & 0 deletions app/utils/animationviewcontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <QWidget>
#include <DRegionMonitor>
#include <DBlurEffectWidget>
#include <DGuiApplicationHelper>
#include <DPlatformWindowHandle>

class QPropertyAnimation;
DGUI_USE_NAMESPACE
Expand All @@ -26,6 +28,9 @@ class AnimationViewContainer : public DBlurEffectWidget
void refreshView();
void updateGeometry(const QRect &rect);

protected:
void paintEvent(QPaintEvent *e) override;

Q_SIGNALS:
void outsideAreaReleased();

Expand All @@ -42,5 +47,9 @@ private Q_SLOTS:
QRect m_targetRect;
QPropertyAnimation *m_currentXAni = nullptr;
DRegionMonitor *m_regionMonitor = nullptr;

DGuiApplicationHelper::ColorType m_themeType;
int m_cornerRadius;
DPlatformWindowHandle *m_windowHandle = nullptr;
};
WIDGETS_FRAME_END_NAMESPACE

0 comments on commit 21c9f5e

Please sign in to comment.