mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 修复托盘区域调整尺寸的时候托盘图标不居中的问题
修改delegate类的sizeHint方法的返回值,在主窗体尺寸发生变化的时候,发送delegate的sizeHintChanged信号来保证sizeHint方法能实时调用 Log: Influence: 任务栏上下调整尺寸的时候观察托盘图标的位置变化 Task: https://pms.uniontech.com/task-view-110311.html Change-Id: I86b6bdc0fb991ff0a2674b0fa799add4b536a6bf
This commit is contained in:
parent
75cb4e8160
commit
1172b54b9f
@ -138,7 +138,15 @@ QSize TrayDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelInd
|
|||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
|
|
||||||
return QSize(ITEM_SIZE, ITEM_SIZE);
|
// 如果是弹出托盘,则显示正常大小
|
||||||
|
if (isPopupTray())
|
||||||
|
return QSize(ITEM_SIZE, ITEM_SIZE);
|
||||||
|
|
||||||
|
// 如果是任务栏的托盘,则高度显示为listView的高度或宽度
|
||||||
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||||
|
return QSize(ITEM_SIZE, m_listView->height());
|
||||||
|
|
||||||
|
return QSize(m_listView->width(), ITEM_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void TrayDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
@ -153,30 +161,34 @@ void TrayDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewI
|
|||||||
|
|
||||||
void TrayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void TrayDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (needDrawBackground()) {
|
Q_UNUSED(index);
|
||||||
QColor borderColor;
|
|
||||||
QColor backColor;
|
if (!isPopupTray())
|
||||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
return;
|
||||||
// 白色主题的情况下
|
|
||||||
borderColor = Qt::black;
|
QColor borderColor;
|
||||||
borderColor.setAlpha(static_cast<int>(255 * 0.05));
|
QColor backColor;
|
||||||
backColor = Qt::white;
|
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
||||||
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
// 白色主题的情况下
|
||||||
} else {
|
borderColor = Qt::black;
|
||||||
borderColor = Qt::black;
|
borderColor.setAlpha(static_cast<int>(255 * 0.05));
|
||||||
borderColor.setAlpha(static_cast<int>(255 * 0.2));
|
backColor = Qt::white;
|
||||||
backColor = Qt::black;
|
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
||||||
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
} else {
|
||||||
}
|
borderColor = Qt::black;
|
||||||
painter->save();
|
borderColor.setAlpha(static_cast<int>(255 * 0.2));
|
||||||
QPainterPath path;
|
backColor = Qt::black;
|
||||||
path.addRoundedRect(option.rect, 8, 8);
|
backColor.setAlpha(static_cast<int>(255 * 0.4));
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
|
||||||
painter->fillPath(path, backColor);
|
|
||||||
painter->setPen(borderColor);
|
|
||||||
painter->drawPath(path);
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRoundedRect(option.rect, 8, 8);
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter->fillPath(path, backColor);
|
||||||
|
painter->setPen(borderColor);
|
||||||
|
painter->drawPath(path);
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpandIconWidget *TrayDelegate::expandWidget()
|
ExpandIconWidget *TrayDelegate::expandWidget()
|
||||||
@ -198,7 +210,7 @@ ExpandIconWidget *TrayDelegate::expandWidget()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrayDelegate::needDrawBackground() const
|
bool TrayDelegate::isPopupTray() const
|
||||||
{
|
{
|
||||||
if (!m_listView)
|
if (!m_listView)
|
||||||
return false;
|
return false;
|
||||||
|
@ -59,7 +59,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ExpandIconWidget *expandWidget();
|
ExpandIconWidget *expandWidget();
|
||||||
bool needDrawBackground() const;
|
bool isPopupTray() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dock::Position m_position;
|
Dock::Position m_position;
|
||||||
|
@ -53,6 +53,11 @@ void TrayGridView::setPosition(Dock::Position position)
|
|||||||
m_positon = position;
|
m_positon = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dock::Position TrayGridView::position() const
|
||||||
|
{
|
||||||
|
return m_positon;
|
||||||
|
}
|
||||||
|
|
||||||
QSize TrayGridView::suitableSize() const
|
QSize TrayGridView::suitableSize() const
|
||||||
{
|
{
|
||||||
TrayModel *dataModel = qobject_cast<TrayModel *>(model());
|
TrayModel *dataModel = qobject_cast<TrayModel *>(model());
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
explicit TrayGridView(QWidget *parent = Q_NULLPTR);
|
explicit TrayGridView(QWidget *parent = Q_NULLPTR);
|
||||||
|
|
||||||
void setPosition(Dock::Position position);
|
void setPosition(Dock::Position position);
|
||||||
|
Dock::Position position() const;
|
||||||
QSize suitableSize() const;
|
QSize suitableSize() const;
|
||||||
void setDragDistance(int pixel);
|
void setDragDistance(int pixel);
|
||||||
void setAnimationProperty(const QEasingCurve::Type easing, const int duringTime = 250);
|
void setAnimationProperty(const QEasingCurve::Type easing, const int duringTime = 250);
|
||||||
|
@ -91,14 +91,7 @@ void TrayManagerWindow::setPositon(Dock::Position position)
|
|||||||
m_dateTimeWidget->setPositon(position);
|
m_dateTimeWidget->setPositon(position);
|
||||||
m_systemPluginWidget->setPositon(position);
|
m_systemPluginWidget->setPositon(position);
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, [ this ]{
|
QMetaObject::invokeMethod(this, &TrayManagerWindow::resetDirection, Qt::QueuedConnection);
|
||||||
if (showSingleRow())
|
|
||||||
resetSingleDirection();
|
|
||||||
else
|
|
||||||
resetMultiDirection();
|
|
||||||
|
|
||||||
resetChildWidgetSize();
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TrayManagerWindow::appDatetimeSize()
|
int TrayManagerWindow::appDatetimeSize()
|
||||||
@ -142,12 +135,7 @@ void TrayManagerWindow::resizeEvent(QResizeEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
||||||
if (showSingleRow())
|
resetDirection();
|
||||||
resetSingleDirection();
|
|
||||||
else
|
|
||||||
resetMultiDirection();
|
|
||||||
|
|
||||||
resetChildWidgetSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayManagerWindow::initUi()
|
void TrayManagerWindow::initUi()
|
||||||
@ -267,6 +255,18 @@ void TrayManagerWindow::initConnection()
|
|||||||
QMetaObject::invokeMethod(this, &TrayManagerWindow::resetChildWidgetSize, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &TrayManagerWindow::resetChildWidgetSize, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrayManagerWindow::resetDirection()
|
||||||
|
{
|
||||||
|
if (showSingleRow())
|
||||||
|
resetSingleDirection();
|
||||||
|
else
|
||||||
|
resetMultiDirection();
|
||||||
|
|
||||||
|
resetChildWidgetSize();
|
||||||
|
// 当尺寸发生变化的时候,通知托盘区域刷新尺寸,让托盘图标始终保持居中显示
|
||||||
|
Q_EMIT m_delegate->sizeHintChanged(m_model->index(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
bool TrayManagerWindow::showSingleRow()
|
bool TrayManagerWindow::showSingleRow()
|
||||||
{
|
{
|
||||||
if (m_postion == Dock::Position::Top || m_postion == Dock::Position::Bottom)
|
if (m_postion == Dock::Position::Top || m_postion == Dock::Position::Bottom)
|
||||||
@ -298,10 +298,9 @@ void TrayManagerWindow::resetChildWidgetSize()
|
|||||||
m_dateTimeWidget->setFixedSize(m_dateTimeWidget->suitableSize().width(), trayHeight);
|
m_dateTimeWidget->setFixedSize(m_dateTimeWidget->suitableSize().width(), trayHeight);
|
||||||
} else {
|
} else {
|
||||||
// 多行显示
|
// 多行显示
|
||||||
int trayHeight = m_appPluginDatetimeWidget->height() / 2 - m.top() - m.bottom();
|
m_trayView->setFixedSize(trayWidth, QWIDGETSIZE_MAX);
|
||||||
m_trayView->setFixedSize(trayWidth, trayHeight);
|
m_quickIconWidget->setFixedSize(m_quickIconWidget->suitableSize().width(), QWIDGETSIZE_MAX);
|
||||||
m_quickIconWidget->setFixedSize(m_quickIconWidget->suitableSize().width(), trayHeight);
|
m_appPluginWidget->setFixedSize(trayWidth + m_quickIconWidget->suitableSize().width(), QWIDGETSIZE_MAX);
|
||||||
m_appPluginWidget->setFixedSize(trayWidth + m_quickIconWidget->suitableSize().width(), trayHeight);
|
|
||||||
// 因为是两行,所以对于时间控件的尺寸,只能设置最小值
|
// 因为是两行,所以对于时间控件的尺寸,只能设置最小值
|
||||||
int dateTimeWidth = qMax(m_appPluginWidget->width(), m_dateTimeWidget->suitableSize().width());
|
int dateTimeWidth = qMax(m_appPluginWidget->width(), m_dateTimeWidget->suitableSize().width());
|
||||||
m_dateTimeWidget->setMinimumSize(dateTimeWidth, m_appPluginDatetimeWidget->height() / 2);
|
m_dateTimeWidget->setMinimumSize(dateTimeWidth, m_appPluginDatetimeWidget->height() / 2);
|
||||||
@ -347,6 +346,8 @@ void TrayManagerWindow::resetSingleDirection()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_splitLine->hide();
|
||||||
|
m_dateTimeWidget->setOneRow(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrayManagerWindow::resetMultiDirection()
|
void TrayManagerWindow::resetMultiDirection()
|
||||||
@ -356,12 +357,16 @@ void TrayManagerWindow::resetMultiDirection()
|
|||||||
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||||
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::BottomToTop);
|
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||||
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||||
|
m_splitLine->show();
|
||||||
|
m_dateTimeWidget->setOneRow(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Dock::Position::Bottom: {
|
case Dock::Position::Bottom: {
|
||||||
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||||
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||||
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
m_mainLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||||
|
m_splitLine->show();
|
||||||
|
m_dateTimeWidget->setOneRow(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Dock::Position::Left:
|
case Dock::Position::Left:
|
||||||
@ -369,6 +374,8 @@ void TrayManagerWindow::resetMultiDirection()
|
|||||||
m_appPluginLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
m_appPluginLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||||
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
m_appDatetimeLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||||
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
m_mainLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||||
|
m_splitLine->hide();
|
||||||
|
m_dateTimeWidget->setOneRow(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ private:
|
|||||||
void initUi();
|
void initUi();
|
||||||
void initConnection();
|
void initConnection();
|
||||||
|
|
||||||
|
void resetDirection();
|
||||||
void resetChildWidgetSize();
|
void resetChildWidgetSize();
|
||||||
void resetMultiDirection();
|
void resetMultiDirection();
|
||||||
void resetSingleDirection();
|
void resetSingleDirection();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user