fix: Missing radius for tray's background

Add a common function to draw special background.
  Sub widget request a highlight background for parent.

Issue: https://github.com/linuxdeepin/developer-center/issues/3744
This commit is contained in:
Ye ShanShan 2023-03-09 16:46:07 +08:00 committed by yeshanshan
parent cfa53d0b1e
commit 2ff4a236a6
6 changed files with 56 additions and 22 deletions

View File

@ -40,7 +40,6 @@ DateTimeDisplayer::DateTimeDisplayer(bool showMultiRow, QWidget *parent)
, m_currentSize(0)
, m_oneRow(false)
, m_showMultiRow(showMultiRow)
, m_isEnter(false)
{
m_tipPopupWindow.reset(new DockPopupWindow);
// 日期格式变化的时候,需要重绘
@ -271,14 +270,6 @@ void DateTimeDisplayer::paintEvent(QPaintEvent *e)
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(QPen(palette().brightText(), 1));
// 绘制背景色
if (m_isEnter) {
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
// 鼠标进入的时候,绘制底色
painter.fillRect(rect(), backColor);
}
int timeAlignFlag = Qt::AlignCenter;
int dateAlignFlag = Qt::AlignCenter;
@ -395,7 +386,7 @@ QRect DateTimeDisplayer::textRect(const QRect &sourceRect) const
void DateTimeDisplayer::enterEvent(QEvent *event)
{
Q_UNUSED(event);
m_isEnter = true;
Q_EMIT requestDrawBackground(rect());
update();
m_tipPopupWindow->show(tipsPoint());
}
@ -403,7 +394,7 @@ void DateTimeDisplayer::enterEvent(QEvent *event)
void DateTimeDisplayer::leaveEvent(QEvent *event)
{
Q_UNUSED(event);
m_isEnter = false;
Q_EMIT requestDrawBackground(QRect());
update();
m_tipPopupWindow->hide();
}

View File

@ -42,6 +42,7 @@ public:
Q_SIGNALS:
void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸
void requestDrawBackground(const QRect &rect);
protected:
void mousePressEvent(QMouseEvent *event) override;
@ -83,7 +84,6 @@ private:
int m_currentSize;
bool m_oneRow;
bool m_showMultiRow;
bool m_isEnter;
};
#endif // DATETIMEDISPLAYER_H

View File

@ -208,7 +208,6 @@ StretchPluginsItem::StretchPluginsItem(DockInter *dockInter, PluginsItemInterfac
, m_itemKey(itemKey)
, m_displayMode(Dock::DisplayMode::Efficient)
, m_dockInter(dockInter)
, m_isEnter(false)
{
}
@ -266,12 +265,6 @@ void StretchPluginsItem::paintEvent(QPaintEvent *event)
rctPixmap.setHeight(ICONSIZE);
}
if (m_isEnter) {
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
// 鼠标进入的时候,绘制底色
painter.fillRect(rect(), backColor);
}
// 绘制图标
int iconSize = static_cast<int>(ICONSIZE * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize));
@ -393,14 +386,17 @@ void StretchPluginsItem::mouseReleaseEvent(QMouseEvent *e)
void StretchPluginsItem::enterEvent(QEvent *event)
{
m_isEnter = true;
if (auto view = qobject_cast<SystemPluginWindow *>(parentWidget()))
view->requestDrawBackground(rect());
update();
DockItem::enterEvent(event);
}
void StretchPluginsItem::leaveEvent(QEvent *event)
{
m_isEnter = false;
if (auto view = qobject_cast<SystemPluginWindow *>(parentWidget()))
view->requestDrawBackground(QRect());
update();
DockItem::leaveEvent(event);
}

View File

@ -35,6 +35,7 @@ public:
Q_SIGNALS:
void itemChanged();
void requestDrop(QDropEvent *dropEvent);
void requestDrawBackground(const QRect &rect);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
@ -99,7 +100,6 @@ private:
static Dock::Position m_position;
QPoint m_mousePressPoint;
DockInter *m_dockInter;
bool m_isEnter;
};
#endif // SYSTEMPLUGINWINDOW_H

View File

@ -241,6 +241,37 @@ void TrayManagerWindow::onTrayCountChanged()
Q_EMIT requestUpdate();
}
void TrayManagerWindow::updateHighlightArea(const QRect &rect)
{
do {
m_highlightArea.clear();
if (!rect.isValid())
break;
auto widget = qobject_cast<QWidget *>(sender());
Q_ASSERT(widget);
QRect tmp = rect;
tmp.moveTopLeft(widget->mapTo(this, rect.topLeft()));
const auto radius = pathRadius();
m_highlightArea.addRoundedRect(tmp, radius, radius);
if (widget == m_dateTimeWidget) {
if (!m_singleShow) {
QPainterPath path;
if(m_position == Dock::Position::Top)
path.addRect(tmp.adjusted(0, radius, 0, 0));
else
path.addRect(tmp.adjusted(0, 0, 0, -radius));
m_highlightArea += path;
}
}
} while (false);
update();
}
void TrayManagerWindow::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
@ -302,6 +333,7 @@ void TrayManagerWindow::initConnection()
Q_EMIT requestUpdate();
});
connect(m_systemPluginWidget, &SystemPluginWindow::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea);
connect(m_trayView, &TrayGridView::dragLeaved, m_delegate, [ this ]{
Q_EMIT m_delegate->requestDrag(true);
@ -313,6 +345,7 @@ void TrayManagerWindow::initConnection()
connect(m_model, &TrayModel::rowCountChanged, m_trayView, &TrayGridView::onUpdateEditorView);
connect(m_dateTimeWidget, &DateTimeDisplayer::requestUpdate, this, &TrayManagerWindow::requestUpdate);
connect(m_dateTimeWidget, &DateTimeDisplayer::requestDrawBackground, this, &TrayManagerWindow::updateHighlightArea);
m_trayView->installEventFilter(this);
m_quickIconWidget->installEventFilter(this);
@ -508,6 +541,17 @@ void TrayManagerWindow::paintEvent(QPaintEvent *event)
painter.setPen(maskColor(110));
painter.drawPath(path);
painter.restore();
// draw highlight background for special path.
if (!m_highlightArea.isEmpty()) {
painter.save();
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
painter.setPen(Qt::NoPen);
painter.setBrush(backColor);
painter.drawPath(m_highlightArea);
painter.restore();
}
}
QColor TrayManagerWindow::maskColor(uint8_t alpha) const

View File

@ -11,6 +11,7 @@
#include "org_deepin_dde_timedate1.h"
#include <QPainterPath>
#include <QWidget>
namespace Dtk { namespace Widget { class DBlurEffectWidget; } }
@ -72,6 +73,7 @@ private:
private Q_SLOTS:
void onTrayCountChanged();
void updateHighlightArea(const QRect &rect);
private:
QWidget *m_appPluginDatetimeWidget;
@ -90,6 +92,7 @@ private:
QLabel *m_splitLine;
bool m_singleShow; // 用于记录当前日期时间和插件区域是显示一行还是显示多行
int m_borderRadius; // 圆角的值
QPainterPath m_highlightArea;
};
#endif // PLUGINWINDOW_H