mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
fix: 优化插件图标样式
鼠标进入的时候,图标显示底色 Log: 优化图标样式 Influence: 图标样式 Task: https://pms.uniontech.com/bug-view-181945.html Change-Id: I9eb594119f0dbef36aee64ae4fd7a99fa12389c7
This commit is contained in:
parent
f7812cfb66
commit
60e5e1b749
@ -23,23 +23,38 @@
|
||||
#include "pluginmanagerinterface.h"
|
||||
|
||||
#include <QMetaObject>
|
||||
#include <customevent.h>
|
||||
|
||||
QuickSettingController::QuickSettingController(QObject *parent)
|
||||
: AbstractPluginsController(parent)
|
||||
{
|
||||
qApp->installEventFilter(this);
|
||||
// 只有在非安全模式下才加载插件,安全模式会在等退出安全模式后通过接受事件的方式来加载插件
|
||||
if (!qApp->property("safeMode").toBool())
|
||||
QMetaObject::invokeMethod(this, [ = ] {
|
||||
QMetaObject::invokeMethod(this, &QuickSettingController::startLoader, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QuickSettingController::~QuickSettingController()
|
||||
{
|
||||
}
|
||||
|
||||
bool QuickSettingController::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == qApp && event->type() == PluginLoadEvent::eventType()) {
|
||||
// 如果收到的是重新加载插件的消息(一般是在退出安全模式后),则直接加载插件即可
|
||||
startLoader();
|
||||
}
|
||||
|
||||
return AbstractPluginsController::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void QuickSettingController::startLoader()
|
||||
{
|
||||
#ifdef QT_DEBUG
|
||||
AbstractPluginsController::startLoader(new PluginLoader(QString("%1/..%2").arg(qApp->applicationDirPath()).arg("/plugins/loader"), this));
|
||||
#else
|
||||
AbstractPluginsController::startLoader(new PluginLoader("/usr/lib/dde-dock/plugins/loader", this));
|
||||
#endif
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QuickSettingController::~QuickSettingController()
|
||||
{
|
||||
}
|
||||
|
||||
void QuickSettingController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
|
@ -59,6 +59,9 @@ Q_SIGNALS:
|
||||
protected:
|
||||
explicit QuickSettingController(QObject *parent = Q_NULLPTR);
|
||||
~QuickSettingController() override;
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
void startLoader();
|
||||
|
||||
protected:
|
||||
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) override;
|
||||
|
@ -26,11 +26,13 @@
|
||||
|
||||
#include <DFontSizeManager>
|
||||
#include <DDBusSender>
|
||||
#include <DGuiApplicationHelper>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QFont>
|
||||
#include <QMenu>
|
||||
#include <QPainterPath>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
DGUI_USE_NAMESPACE
|
||||
@ -53,6 +55,7 @@ DateTimeDisplayer::DateTimeDisplayer(bool showMultiRow, QWidget *parent)
|
||||
, m_currentSize(0)
|
||||
, m_oneRow(false)
|
||||
, m_showMultiRow(showMultiRow)
|
||||
, m_isEnter(false)
|
||||
{
|
||||
m_tipPopupWindow.reset(new DockPopupWindow);
|
||||
// 日期格式变化的时候,需要重绘
|
||||
@ -274,6 +277,14 @@ 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;
|
||||
if (m_showMultiRow) {
|
||||
@ -383,12 +394,16 @@ QRect DateTimeDisplayer::textRect(const QRect &sourceRect) const
|
||||
void DateTimeDisplayer::enterEvent(QEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_isEnter = true;
|
||||
update();
|
||||
m_tipPopupWindow->show(tipsPoint());
|
||||
}
|
||||
|
||||
void DateTimeDisplayer::leaveEvent(QEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
m_isEnter = false;
|
||||
update();
|
||||
m_tipPopupWindow->hide();
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,7 @@ private:
|
||||
int m_currentSize;
|
||||
bool m_oneRow;
|
||||
bool m_showMultiRow;
|
||||
bool m_isEnter;
|
||||
};
|
||||
|
||||
#endif // DATETIMEDISPLAYER_H
|
||||
|
@ -40,7 +40,8 @@
|
||||
#include <QDragLeaveEvent>
|
||||
|
||||
#define ITEMSIZE 22
|
||||
#define ITEMSPACE 6
|
||||
#define STARTSPACE 6
|
||||
#define ITEMSPACE 0
|
||||
#define ICONWIDTH 18
|
||||
#define ICONHEIGHT 16
|
||||
|
||||
@ -114,6 +115,7 @@ void QuickPluginWindow::initUi()
|
||||
m_mainLayout->setDirection(QBoxLayout::RightToLeft);
|
||||
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainLayout->setSpacing(ITEMSPACE);
|
||||
m_mainLayout->addSpacing(STARTSPACE);
|
||||
}
|
||||
|
||||
void QuickPluginWindow::setPositon(Position position)
|
||||
@ -169,7 +171,7 @@ QSize QuickPluginWindow::suitableSize() const
|
||||
QSize QuickPluginWindow::suitableSize(const Dock::Position &position) const
|
||||
{
|
||||
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
||||
int itemWidth = 0;
|
||||
int itemWidth = STARTSPACE;
|
||||
for (int i = 0; i < m_mainLayout->count(); i++) {
|
||||
QWidget *itemWidget = m_mainLayout->itemAt(i)->widget();
|
||||
if (itemWidget)
|
||||
@ -180,7 +182,7 @@ QSize QuickPluginWindow::suitableSize(const Dock::Position &position) const
|
||||
return QSize(itemWidth, QWIDGETSIZE_MAX);
|
||||
}
|
||||
|
||||
int itemHeight = 0;
|
||||
int itemHeight = STARTSPACE;
|
||||
for (int i = 0; i < m_mainLayout->count(); i++) {
|
||||
QWidget *itemWidget = m_mainLayout->itemAt(i)->widget();
|
||||
if (itemWidget)
|
||||
@ -447,6 +449,8 @@ void QuickPluginWindow::onRequestAppletVisible(PluginsItemInterface *itemInter,
|
||||
{
|
||||
if (visible)
|
||||
showPopup(getDockItemByPlugin(itemInter), itemInter, itemInter->itemPopupApplet(itemKey), false);
|
||||
else
|
||||
getPopWindow()->hide();
|
||||
}
|
||||
|
||||
void QuickPluginWindow::startDrag()
|
||||
@ -703,6 +707,7 @@ QuickDockItem::QuickDockItem(PluginsItemInterface *pluginItem, const QString &it
|
||||
, m_mainWidget(nullptr)
|
||||
, m_mainLayout(nullptr)
|
||||
, m_dockItemParent(nullptr)
|
||||
, m_isEnter(false)
|
||||
{
|
||||
initUi();
|
||||
initConnection();
|
||||
@ -712,9 +717,14 @@ QuickDockItem::QuickDockItem(PluginsItemInterface *pluginItem, const QString &it
|
||||
QuickDockItem::~QuickDockItem()
|
||||
{
|
||||
QWidget *tipWidget = m_pluginItem->itemTipsWidget(m_itemKey);
|
||||
if (tipWidget && tipWidget->parentWidget() == m_popupWindow)
|
||||
if (tipWidget && (tipWidget->parentWidget() == m_popupWindow || tipWidget->parentWidget() == this))
|
||||
tipWidget->setParent(m_tipParent);
|
||||
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget) {
|
||||
itemWidget->setParent(nullptr);
|
||||
itemWidget->hide();
|
||||
}
|
||||
m_popupWindow->deleteLater();
|
||||
}
|
||||
|
||||
@ -722,6 +732,12 @@ void QuickDockItem::setPosition(Dock::Position position)
|
||||
{
|
||||
m_position = position;
|
||||
updateWidgetSize();
|
||||
if (m_mainLayout) {
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget && m_mainLayout->indexOf(itemWidget) < 0) {
|
||||
itemWidget->setFixedSize(suitableSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PluginsItemInterface *QuickDockItem::pluginItem()
|
||||
@ -746,25 +762,35 @@ void QuickDockItem::hideToolTip()
|
||||
|
||||
QSize QuickDockItem::suitableSize() const
|
||||
{
|
||||
int widgetSize = (m_pluginItem->displayMode() == Dock::DisplayMode::Efficient) ? 24 : 30;
|
||||
if (m_pluginItem->pluginSizePolicy() == PluginsItemInterface::PluginSizePolicy::Custom) {
|
||||
QPixmap pixmap = iconPixmap();
|
||||
if (!pixmap.isNull())
|
||||
return pixmap.size();
|
||||
if (!pixmap.isNull()) {
|
||||
QSize size = pixmap.size();
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
if (size.width() < widgetSize)
|
||||
size.setWidth(widgetSize);
|
||||
return size;
|
||||
}
|
||||
if (size.height() < widgetSize)
|
||||
size.setHeight(widgetSize);
|
||||
return size;
|
||||
}
|
||||
|
||||
QWidget *itemWidget = m_pluginItem->itemWidget(m_itemKey);
|
||||
if (itemWidget) {
|
||||
int itemWidth = ICONWIDTH;
|
||||
int itemWidth = widgetSize;
|
||||
int itemHeight = ICONHEIGHT;
|
||||
QSize itemSize = itemWidget->sizeHint();
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
if (itemSize.width() > 0)
|
||||
if (itemSize.width() > widgetSize)
|
||||
itemWidth = itemSize.width();
|
||||
if (itemSize.height() > 0 && itemSize.height() <= topLevelWidget()->height())
|
||||
itemHeight = itemSize.height();
|
||||
} else {
|
||||
if (itemSize.width() > 0 && itemSize.width() < topLevelWidget()->width())
|
||||
itemWidth = itemSize.width();
|
||||
if (itemSize.height() > 0 && itemSize.height() < ICONHEIGHT)
|
||||
if (itemSize.height() > widgetSize && itemSize.height() < ICONHEIGHT)
|
||||
itemHeight = itemSize.height();
|
||||
}
|
||||
|
||||
@ -772,7 +798,10 @@ QSize QuickDockItem::suitableSize() const
|
||||
}
|
||||
}
|
||||
|
||||
return QSize(ICONWIDTH, ICONHEIGHT);
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
return QSize(widgetSize, ICONHEIGHT);
|
||||
|
||||
return QSize(ICONWIDTH, widgetSize);
|
||||
}
|
||||
|
||||
void QuickDockItem::paintEvent(QPaintEvent *event)
|
||||
@ -780,14 +809,37 @@ void QuickDockItem::paintEvent(QPaintEvent *event)
|
||||
if (!m_pluginItem)
|
||||
return QWidget::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
|
||||
backColor.setAlphaF(0.2);
|
||||
if (m_isEnter) {
|
||||
// 鼠标进入的时候,绘制底色
|
||||
QPainterPath path;
|
||||
int borderRadius = shadowRadius();
|
||||
QRect rectBackground;
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
int backHeight = qBound(20, height() - 4, 30);
|
||||
rectBackground.setTop((height() - backHeight) / 2);
|
||||
rectBackground.setHeight(backHeight);
|
||||
rectBackground.setWidth(width());
|
||||
path.addRoundedRect(rectBackground, borderRadius, borderRadius);
|
||||
} else {
|
||||
int backWidth = qBound(20, width() - 4, 30);
|
||||
rectBackground.setLeft((width() - backWidth) / 2);
|
||||
rectBackground.setWidth(backWidth);
|
||||
rectBackground.setHeight(height());
|
||||
path.addRoundedRect(rectBackground, borderRadius, borderRadius);
|
||||
}
|
||||
painter.fillPath(path, backColor);
|
||||
}
|
||||
|
||||
QPixmap pixmap = iconPixmap();
|
||||
if (pixmap.isNull())
|
||||
return QWidget::paintEvent(event);
|
||||
|
||||
QSize size = suitableSize();
|
||||
QSize size = pixmap.size();
|
||||
QRect pixmapRect = QRect(QPoint((rect().width() - size.width()) / 2, (rect().height() - size.height()) / 2), pixmap.size());
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(pixmapRect, pixmap);
|
||||
}
|
||||
|
||||
@ -824,6 +876,8 @@ void QuickDockItem::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void QuickDockItem::enterEvent(QEvent *event)
|
||||
{
|
||||
m_isEnter = true;
|
||||
update();
|
||||
QWidget::enterEvent(event);
|
||||
|
||||
QWidget *tipWidget = m_pluginItem->itemTipsWidget(m_itemKey);
|
||||
@ -858,6 +912,9 @@ void QuickDockItem::enterEvent(QEvent *event)
|
||||
|
||||
void QuickDockItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
m_isEnter = false;
|
||||
update();
|
||||
|
||||
QWidget::leaveEvent(event);
|
||||
m_popupWindow->hide();
|
||||
}
|
||||
@ -981,6 +1038,24 @@ void QuickDockItem::updateWidgetSize()
|
||||
}
|
||||
}
|
||||
|
||||
int QuickDockItem::shadowRadius() const
|
||||
{
|
||||
#define EFFECTRADIUS 8
|
||||
#define MARGIN 4
|
||||
// 高效模式下固定为8
|
||||
if (m_pluginItem->displayMode() == Dock::DisplayMode::Efficient)
|
||||
return EFFECTRADIUS;
|
||||
|
||||
return qApp->property("trayBorderRadius").toInt() - MARGIN;
|
||||
}
|
||||
|
||||
int QuickDockItem::iconSize() const
|
||||
{
|
||||
if (m_pluginItem->displayMode() == Dock::DisplayMode::Efficient)
|
||||
return 24;
|
||||
return 30;
|
||||
}
|
||||
|
||||
QPoint QuickDockItem::topleftPoint() const
|
||||
{
|
||||
QPoint p = this->pos();
|
||||
|
@ -133,6 +133,8 @@ private:
|
||||
void initConnection();
|
||||
|
||||
void updateWidgetSize();
|
||||
int shadowRadius() const;
|
||||
int iconSize() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onMenuActionClicked(QAction *action);
|
||||
@ -148,6 +150,7 @@ private:
|
||||
QWidget *m_mainWidget;
|
||||
QHBoxLayout *m_mainLayout;
|
||||
QWidget *m_dockItemParent;
|
||||
bool m_isEnter;
|
||||
};
|
||||
|
||||
#endif // QUICKPLUGINWINDOW_H
|
||||
|
@ -222,6 +222,7 @@ StretchPluginsItem::StretchPluginsItem(DockInter *dockInter, PluginsItemInterfac
|
||||
, m_itemKey(itemKey)
|
||||
, m_displayMode(Dock::DisplayMode::Efficient)
|
||||
, m_dockInter(dockInter)
|
||||
, m_isEnter(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -279,6 +280,12 @@ 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));
|
||||
@ -399,6 +406,20 @@ void StretchPluginsItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
mouseClick();
|
||||
}
|
||||
|
||||
void StretchPluginsItem::enterEvent(QEvent *event)
|
||||
{
|
||||
m_isEnter = true;
|
||||
update();
|
||||
DockItem::enterEvent(event);
|
||||
}
|
||||
|
||||
void StretchPluginsItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
m_isEnter = false;
|
||||
update();
|
||||
DockItem::leaveEvent(event);
|
||||
}
|
||||
|
||||
void StretchPluginsItem::mouseClick()
|
||||
{
|
||||
QStringList commandArgument = m_pluginInter->itemCommand(m_itemKey).split(" ");
|
||||
|
@ -93,6 +93,8 @@ protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
|
||||
const QString contextMenu() const override;
|
||||
void invokedMenuItem(const QString &itemId, const bool checked) override;
|
||||
@ -112,6 +114,7 @@ private:
|
||||
static Dock::Position m_position;
|
||||
QPoint m_mousePressPoint;
|
||||
DockInter *m_dockInter;
|
||||
bool m_isEnter;
|
||||
};
|
||||
|
||||
#endif // SYSTEMPLUGINWINDOW_H
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "widgets/snitrayitemwidget.h"
|
||||
#include "widgets/expandiconwidget.h"
|
||||
#include "utils.h"
|
||||
#include "constants.h"
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "quicksettingcontroller.h"
|
||||
#include "systempluginitem.h"
|
||||
@ -186,31 +187,76 @@ void TrayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
|
||||
if (!isPopupTray())
|
||||
return;
|
||||
|
||||
QColor borderColor;
|
||||
QColor backColor;
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
// 白色主题的情况下
|
||||
borderColor = Qt::black;
|
||||
borderColor.setAlpha(static_cast<int>(255 * 0.05));
|
||||
backColor = Qt::white;
|
||||
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
||||
} else {
|
||||
borderColor = Qt::black;
|
||||
borderColor.setAlpha(static_cast<int>(255 * 0.2));
|
||||
backColor = Qt::black;
|
||||
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
||||
}
|
||||
// 如果不是弹出菜单(在任务栏上显示的),在鼠标没有移入的时候无需绘制背景
|
||||
if (!isPopupTray() && !(option.state & QStyle::State_MouseOver))
|
||||
return QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
painter->save();
|
||||
QPainterPath path;
|
||||
path.addRoundedRect(option.rect, 8, 8);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->fillPath(path, backColor);
|
||||
painter->setPen(borderColor);
|
||||
painter->drawPath(path);
|
||||
|
||||
if (isPopupTray()) {
|
||||
QPainterPath path;
|
||||
path.addRoundedRect(option.rect, 8, 8);
|
||||
QColor borderColor;
|
||||
QColor backColor;
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
// 白色主题的情况下
|
||||
borderColor = Qt::black;
|
||||
borderColor.setAlpha(static_cast<int>(255 * 0.05));
|
||||
backColor = Qt::white;
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
backColor.setAlphaF(0.4);
|
||||
} else
|
||||
backColor.setAlphaF(0.2);
|
||||
} else {
|
||||
borderColor = Qt::black;
|
||||
borderColor.setAlpha(static_cast<int>(255 * 0.2));
|
||||
backColor = Qt::black;
|
||||
if (option.state & QStyle::State_MouseOver)
|
||||
backColor.setAlphaF(0.4);
|
||||
else
|
||||
backColor.setAlphaF(0.2);
|
||||
}
|
||||
|
||||
painter->fillPath(path, backColor);
|
||||
painter->setPen(borderColor);
|
||||
painter->drawPath(path);
|
||||
} else {
|
||||
// 如果是任务栏上面的托盘图标,则绘制背景色
|
||||
int borderRadius = 8;
|
||||
if (qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>() == Dock::DisplayMode::Fashion) {
|
||||
borderRadius = qApp->property("trayBorderRadius").toInt() - 4;
|
||||
}
|
||||
QRect rectBackground;
|
||||
QPainterPath path;
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
int backHeight = qBound(20, option.rect.height() - 4, 30);
|
||||
rectBackground.setLeft(option.rect.left());
|
||||
rectBackground.setTop(option.rect.top() + (option.rect.height() - backHeight) / 2);
|
||||
rectBackground.setHeight(backHeight);
|
||||
rectBackground.setWidth(option.rect.width());
|
||||
path.addRoundedRect(rectBackground, borderRadius, borderRadius);
|
||||
} else {
|
||||
int backWidth = qBound(20, option.rect.width() - 4, 30);
|
||||
rectBackground.setLeft(option.rect.left() + (option.rect.width() - backWidth) / 2);
|
||||
rectBackground.setTop(option.rect.top());
|
||||
rectBackground.setWidth(backWidth);
|
||||
rectBackground.setHeight(option.rect.height());
|
||||
path.addRoundedRect(rectBackground, borderRadius, borderRadius);
|
||||
}
|
||||
QColor backColor;
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||
// 白色主题的情况下
|
||||
backColor = Qt::white;
|
||||
backColor.setAlphaF(0.2);
|
||||
} else {
|
||||
backColor = QColor(20, 20, 20);
|
||||
backColor.setAlphaF(0.2);
|
||||
}
|
||||
|
||||
painter->fillPath(path, backColor);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,7 @@ void TrayManagerWindow::updateBorderRadius(int borderRadius)
|
||||
{
|
||||
m_borderRadius = borderRadius;
|
||||
update();
|
||||
qApp->setProperty("trayBorderRadius", pathRadius());
|
||||
}
|
||||
|
||||
void TrayManagerWindow::updateLayout()
|
||||
@ -128,6 +129,12 @@ void TrayManagerWindow::updateItemLayout(int dockSize)
|
||||
Q_EMIT m_delegate->sizeHintChanged(m_model->index(0, 0));
|
||||
}
|
||||
|
||||
int TrayManagerWindow::pathRadius() const
|
||||
{
|
||||
QMargins mainMargin = m_mainLayout->contentsMargins();
|
||||
return m_borderRadius - mainMargin.top();
|
||||
}
|
||||
|
||||
void TrayManagerWindow::setPositon(Dock::Position position)
|
||||
{
|
||||
if (m_position == position)
|
||||
@ -218,7 +225,7 @@ QSize TrayManagerWindow::suitableSize(const Dock::Position &position) const
|
||||
QPainterPath TrayManagerWindow::roundedPaths()
|
||||
{
|
||||
QMargins mainMargin = m_mainLayout->contentsMargins();
|
||||
int radius = m_borderRadius - mainMargin.top();
|
||||
int radius = pathRadius();
|
||||
QPainterPath path;
|
||||
if ((m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
&& m_singleShow) {
|
||||
|
@ -83,6 +83,7 @@ private:
|
||||
int appDatetimeSize(const Dock::Position &position) const;
|
||||
QPainterPath roundedPaths();
|
||||
void updateItemLayout(int dockSize);
|
||||
int pathRadius() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onTrayCountChanged();
|
||||
|
@ -145,7 +145,7 @@ QIcon BluetoothPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::Col
|
||||
|
||||
QString iconFile;
|
||||
if (themeType == DGuiApplicationHelper::ColorType::DarkType)
|
||||
iconFile = ":/bluetooth-active-symbolic.sv";
|
||||
iconFile = ":/bluetooth-active-symbolic.svg";
|
||||
else
|
||||
iconFile = ":/bluetooth-active-symbolic-dark.svg";
|
||||
|
||||
|
@ -46,14 +46,14 @@ OnboardItem::OnboardItem(QWidget *parent)
|
||||
m_icon = QIcon::fromTheme(":/icons/icon/deepin-virtualkeyboard.svg");
|
||||
}
|
||||
|
||||
QPixmap OnboardItem::iconPixmap(int iconWidth, int iconHeight) const
|
||||
QPixmap OnboardItem::iconPixmap(QSize size, DGuiApplicationHelper::ColorType themeType) const
|
||||
{
|
||||
QString iconName = "deepin-virtualkeyboard";
|
||||
if (std::min(width(), height()) <= PLUGIN_BACKGROUND_MIN_SIZE
|
||||
|| DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||
|| themeType == DGuiApplicationHelper::LightType)
|
||||
iconName.append(PLUGIN_MIN_ICON_NAME);
|
||||
|
||||
return loadSvg(iconName, QSize(iconWidth, iconHeight));
|
||||
return loadSvg(iconName, size);
|
||||
}
|
||||
|
||||
void OnboardItem::paintEvent(QPaintEvent *e)
|
||||
@ -102,7 +102,7 @@ void OnboardItem::paintEvent(QPaintEvent *e)
|
||||
painter.fillPath(path, color);
|
||||
}
|
||||
|
||||
QPixmap pixmap = iconPixmap(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE);
|
||||
QPixmap pixmap = iconPixmap(QSize(PLUGIN_ICON_MAX_SIZE, PLUGIN_ICON_MAX_SIZE), DGuiApplicationHelper::instance()->themeType());
|
||||
painter.setOpacity(1);
|
||||
const QRectF &rf = QRectF(rect());
|
||||
const QRectF &rfp = QRectF(pixmap.rect());
|
||||
|
@ -24,16 +24,20 @@
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QIcon>
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
class OnboardItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OnboardItem(QWidget *parent = nullptr);
|
||||
QPixmap iconPixmap(int iconWidth, int iconHeight) const;
|
||||
QPixmap iconPixmap(QSize size, DGuiApplicationHelper::ColorType themeType) const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
@ -184,9 +184,9 @@ QIcon OnboardPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::Color
|
||||
}
|
||||
|
||||
if (dockPart == DockPart::QuickPanel)
|
||||
return m_onboardItem->iconPixmap(24, 24);
|
||||
return m_onboardItem->iconPixmap(QSize(24, 24), themeType);
|
||||
|
||||
return m_onboardItem->iconPixmap(18, 16);
|
||||
return m_onboardItem->iconPixmap(QSize(18, 16), themeType);
|
||||
}
|
||||
|
||||
PluginsItemInterface::PluginMode OnboardPlugin::status() const
|
||||
|
@ -23,6 +23,9 @@
|
||||
#include "pluginsiteminterface.h"
|
||||
|
||||
#include <DDciIcon>
|
||||
#include <DWindowManagerHelper>
|
||||
#include <DSysInfo>
|
||||
#include <DPlatformTheme>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
@ -30,6 +33,7 @@
|
||||
#define ITEMSPACE 6
|
||||
#define ITEMHEIGHT 16
|
||||
#define ITEMWIDTH 18
|
||||
|
||||
static QStringList pluginNames = {"power", "sound", "network"};
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
@ -39,6 +43,7 @@ IconManager::IconManager(DockPluginController *pluginController, QObject *parent
|
||||
, m_pluginController(pluginController)
|
||||
, m_size(QSize(ITEMWIDTH, ITEMHEIGHT))
|
||||
, m_position(Dock::Position::Bottom)
|
||||
, m_displayMode(Dock::DisplayMode::Efficient)
|
||||
{
|
||||
}
|
||||
|
||||
@ -52,7 +57,12 @@ void IconManager::setPosition(Dock::Position position)
|
||||
m_position = position;
|
||||
}
|
||||
|
||||
QPixmap IconManager::pixmap() const
|
||||
void IconManager::setDisplayMode(Dock::DisplayMode displayMode)
|
||||
{
|
||||
m_displayMode = displayMode;
|
||||
}
|
||||
|
||||
QPixmap IconManager::pixmap(DGuiApplicationHelper::ColorType colorType) const
|
||||
{
|
||||
QList<PluginsItemInterface *> plugins;
|
||||
for (const QString &pluginName : pluginNames) {
|
||||
@ -65,25 +75,37 @@ QPixmap IconManager::pixmap() const
|
||||
// 缺省图标
|
||||
DDciIcon::Theme theme = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType ? DDciIcon::Light : DDciIcon::Dark;
|
||||
DDciIcon dciIcon(QString(":/resources/dock_control.dci"));
|
||||
return dciIcon.pixmap(QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio(), ITEMHEIGHT, theme, DDciIcon::Normal);
|
||||
QPixmap pixmap = dciIcon.pixmap(QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio(), ITEMHEIGHT, theme, DDciIcon::Normal);
|
||||
QColor foreColor = (colorType == DGuiApplicationHelper::ColorType::DarkType ? Qt::white : Qt::black);
|
||||
foreColor.setAlphaF(0.8);
|
||||
QPainter pa(&pixmap);
|
||||
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
pa.fillRect(pixmap.rect(), foreColor);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
// 组合图标
|
||||
QPixmap pixmap;
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
pixmap = QPixmap(ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1), m_size.height() - 8);
|
||||
if (m_displayMode == Dock::DisplayMode::Efficient) {
|
||||
// 高效模式下,高度固定为30,圆角固定为8
|
||||
pixmap = QPixmap(ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1), 30);
|
||||
} else {
|
||||
// 时尚模式下,高度随着任务栏的大小变化而变化
|
||||
pixmap = QPixmap(ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1), m_size.height() - 8);
|
||||
}
|
||||
} else {
|
||||
pixmap = QPixmap(m_size.width() - 8, ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1));
|
||||
if (m_displayMode == Dock::DisplayMode::Efficient) {
|
||||
// 高校模式下,宽度固定
|
||||
pixmap = QPixmap(30, ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1));
|
||||
} else {
|
||||
pixmap = QPixmap(m_size.width() - 8, ITEMWIDTH * plugins.size() + ITEMSPACE * (plugins.size() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing);
|
||||
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
|
||||
backColor.setAlphaF(0.2);
|
||||
QPainterPath path;
|
||||
path.addRoundedRect(pixmap.rect(), 5, 5);
|
||||
painter.fillPath(path, backColor);
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
QPoint pointPixmap(ITEMSPACE, (pixmap.height() - ITEMHEIGHT) / 2);
|
||||
for (PluginsItemInterface *plugin : plugins) {
|
||||
|
@ -37,7 +37,8 @@ public:
|
||||
explicit IconManager(DockPluginController *pluginController, QObject *parent = nullptr);
|
||||
void updateSize(QSize size);
|
||||
void setPosition(Dock::Position position);
|
||||
QPixmap pixmap() const;
|
||||
void setDisplayMode(Dock::DisplayMode displayMode);
|
||||
QPixmap pixmap(DGuiApplicationHelper::ColorType colorType) const;
|
||||
bool isFixedPlugin(PluginsItemInterface *plugin) const;
|
||||
|
||||
private:
|
||||
@ -47,6 +48,7 @@ private:
|
||||
DockPluginController *m_pluginController;
|
||||
QSize m_size;
|
||||
Dock::Position m_position;
|
||||
Dock::DisplayMode m_displayMode;
|
||||
};
|
||||
|
||||
#endif // ICONMANAGER_H
|
||||
|
@ -52,6 +52,7 @@ void PluginManager::init(PluginProxyInterface *proxyInter)
|
||||
m_quickContainer.reset(new QuickSettingContainer(m_dockController.data()));
|
||||
m_iconManager.reset(new IconManager(m_dockController.data()));
|
||||
m_iconManager->setPosition(position());
|
||||
m_iconManager->setDisplayMode(displayMode());
|
||||
|
||||
connect(m_dockController.data(), &DockPluginController::pluginInserted, this, [ this ](PluginsItemInterface *itemInter) {
|
||||
if (m_iconManager->isFixedPlugin(itemInter)) {
|
||||
@ -105,7 +106,7 @@ QWidget *PluginManager::itemPopupApplet(const QString &itemKey)
|
||||
QIcon PluginManager::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType)
|
||||
{
|
||||
if (dockPart == DockPart::QuickShow) {
|
||||
return m_iconManager->pixmap();
|
||||
return m_iconManager->pixmap(themeType);
|
||||
}
|
||||
|
||||
return QIcon();
|
||||
@ -137,6 +138,12 @@ void PluginManager::positionChanged(const Dock::Position position)
|
||||
m_proxyInter->itemUpdate(this, pluginName());
|
||||
}
|
||||
|
||||
void PluginManager::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||
{
|
||||
m_iconManager->setDisplayMode(displayMode);
|
||||
m_proxyInter->itemUpdate(this, pluginName());
|
||||
}
|
||||
|
||||
QList<PluginsItemInterface *> PluginManager::plugins() const
|
||||
{
|
||||
return m_dockController->plugins();
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
protected:
|
||||
bool eventHandler(QEvent *event) override;
|
||||
void positionChanged(const Dock::Position position) override;
|
||||
void displayModeChanged(const Dock::DisplayMode displayMode) override;
|
||||
|
||||
protected:
|
||||
// 实现PluginManagerInterface接口,用于向dock提供所有已经加载的插件
|
||||
|
Loading…
x
Reference in New Issue
Block a user