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/task-view-112073.html Change-Id: I50c80880b811e7bb06b917891045d462628a8ee4
This commit is contained in:
parent
091ed36a88
commit
e011333e5a
@ -51,15 +51,7 @@ SystemPluginWindow::~SystemPluginWindow()
|
||||
void SystemPluginWindow::setDisplayMode(const DisplayMode &displayMode)
|
||||
{
|
||||
m_displayMode = displayMode;
|
||||
|
||||
QObjectList childObjects = children();
|
||||
for (QObject *childObject : childObjects) {
|
||||
StretchPluginsItem *item = qobject_cast<StretchPluginsItem *>(childObject);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
item->setDisplayMode(displayMode);
|
||||
}
|
||||
StretchPluginsItem::setDisplayMode(displayMode);
|
||||
}
|
||||
|
||||
void SystemPluginWindow::setPositon(Position position)
|
||||
@ -74,13 +66,15 @@ void SystemPluginWindow::setPositon(Position position)
|
||||
else
|
||||
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
|
||||
StretchPluginsItem::setPosition(position);
|
||||
|
||||
QObjectList childObjects = children();
|
||||
for (QObject *childObject : childObjects) {
|
||||
StretchPluginsItem *item = qobject_cast<StretchPluginsItem *>(childObject);
|
||||
if (!item)
|
||||
continue;
|
||||
|
||||
item->setPosition(m_position);
|
||||
item->update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,12 +193,13 @@ void SystemPluginWindow::onPluginItemUpdated(PluginsItemInterface *pluginItem)
|
||||
#define ICONTEXTSPACE 6
|
||||
#define PLUGIN_ITEM_DRAG_THRESHOLD 20
|
||||
|
||||
Dock::DisplayMode StretchPluginsItem::m_displayMode = Dock::DisplayMode::Efficient;
|
||||
Dock::Position StretchPluginsItem::m_position = Dock::Position::Bottom;
|
||||
|
||||
StretchPluginsItem::StretchPluginsItem(PluginsItemInterface * const pluginInter, const QString &itemKey, QWidget *parent)
|
||||
: DockItem(parent)
|
||||
, m_pluginInter(pluginInter)
|
||||
, m_itemKey(itemKey)
|
||||
, m_displayMode(Dock::DisplayMode::Efficient)
|
||||
, m_position(Dock::Position::Bottom)
|
||||
{
|
||||
}
|
||||
|
||||
@ -220,7 +215,6 @@ void StretchPluginsItem::setDisplayMode(const DisplayMode &displayMode)
|
||||
void StretchPluginsItem::setPosition(Position position)
|
||||
{
|
||||
m_position = position;
|
||||
update();
|
||||
}
|
||||
|
||||
QString StretchPluginsItem::itemKey() const
|
||||
@ -272,15 +266,19 @@ QSize StretchPluginsItem::suitableSize(const Position &position) const
|
||||
{
|
||||
int iconSize = static_cast<int>(ICONSIZE * (qApp->devicePixelRatio()));
|
||||
if (position == Dock::Position::Top || position == Dock::Position::Bottom) {
|
||||
int textWidth = QFontMetrics(textFont(position)).boundingRect(m_pluginInter->pluginDisplayName()).width();
|
||||
return QSize(qMax(textWidth, iconSize) + 10 * 2, -1);
|
||||
int textWidth = 0;
|
||||
if (needShowText())
|
||||
textWidth = QFontMetrics(textFont(position)).boundingRect(m_pluginInter->pluginDisplayName()).width();
|
||||
|
||||
return QSize(qMax(textWidth, iconSize) + (m_displayMode == Dock::DisplayMode::Efficient ? 5 : 10) * 2, -1);
|
||||
}
|
||||
|
||||
int height = 6; // 图标上边距6
|
||||
height += iconSize; // 图标尺寸20
|
||||
height += ICONTEXTSPACE; // 图标与文字间距6
|
||||
height += QFontMetrics(textFont(position)).height(); // 文本高度
|
||||
height += 4; // 下间距4
|
||||
int height = 6; // 图标上边距6
|
||||
height += iconSize; // 图标尺寸20
|
||||
height += ICONTEXTSPACE; // 图标与文字间距6
|
||||
if (needShowText()) // 只有在显示文本的时候才计算文本的高度
|
||||
height += QFontMetrics(textFont(position)).height(); // 文本高度
|
||||
height += 4; // 下间距4
|
||||
return QSize(-1, height);
|
||||
}
|
||||
|
||||
@ -373,7 +371,7 @@ void StretchPluginsItem::mouseClick()
|
||||
{
|
||||
const QString command = m_pluginInter->itemCommand(m_itemKey);
|
||||
if (!command.isEmpty()) {
|
||||
QProcess::startDetached(command);
|
||||
QProcess::startDetached(command, QStringList());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ class StretchPluginsItem : public DockItem
|
||||
public:
|
||||
StretchPluginsItem(PluginsItemInterface *const pluginInter, const QString &itemKey, QWidget *parent = nullptr);
|
||||
~StretchPluginsItem() override;
|
||||
void setDisplayMode(const Dock::DisplayMode &displayMode);
|
||||
void setPosition(Dock::Position position);
|
||||
static void setDisplayMode(const Dock::DisplayMode &displayMode);
|
||||
static void setPosition(Dock::Position position);
|
||||
PluginsItemInterface *pluginInter() const;
|
||||
QString itemKey() const;
|
||||
QSize suitableSize() const;
|
||||
@ -105,8 +105,8 @@ private:
|
||||
private:
|
||||
PluginsItemInterface *m_pluginInter;
|
||||
QString m_itemKey;
|
||||
Dock::DisplayMode m_displayMode;
|
||||
Dock::Position m_position;
|
||||
static Dock::DisplayMode m_displayMode;
|
||||
static Dock::Position m_position;
|
||||
QPoint m_mousePressPoint;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user