mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
fix: 修复快捷设置窗体上下不同方向的位置显示不正确
1.在任务栏方向变化后,重新给DArrowRectangle调用setContent方法确保内容窗体显示正确 2.调整快捷设置面板的部件的高度 3.任务栏左右显示的时候,调整快捷设置插件居中显示 Log: Influence: 任务栏-快捷设置面板位置和尺寸 Task: https://pms.uniontech.com/task-view-110309.html Change-Id: I3a58070b723bc89c26af07a09e1cbb665d79cbe8
This commit is contained in:
parent
fdfe0ba05c
commit
75cb4e8160
@ -37,7 +37,8 @@
|
||||
|
||||
#define ITEMSIZE 22
|
||||
#define ITEMSPACE 6
|
||||
#define ICONSIZE 16
|
||||
#define ICONWIDTH 20
|
||||
#define ICONHEIGHT 16
|
||||
|
||||
static QStringList fixedPluginKeys{ "network-item-key", "sound-item-key", "power" };
|
||||
const int itemDataRole = Dtk::UserRole + 1;
|
||||
@ -45,7 +46,7 @@ const int itemSortRole = Dtk::UserRole + 2;
|
||||
|
||||
QuickPluginWindow::QuickPluginWindow(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_mainLayout(new QBoxLayout(QBoxLayout::LeftToRight, this))
|
||||
, m_mainLayout(new QBoxLayout(QBoxLayout::RightToLeft, this))
|
||||
, m_position(Dock::Position::Bottom)
|
||||
{
|
||||
initUi();
|
||||
@ -63,7 +64,7 @@ void QuickPluginWindow::initUi()
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
m_mainLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
m_mainLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
m_mainLayout->setDirection(QBoxLayout::RightToLeft);
|
||||
m_mainLayout->setContentsMargins(ITEMSPACE, 0, ITEMSPACE, 0);
|
||||
m_mainLayout->setSpacing(ITEMSPACE);
|
||||
const QList<QuickSettingItem *> &items = QuickSettingController::instance()->settingItems();
|
||||
@ -83,10 +84,13 @@ void QuickPluginWindow::setPositon(Position position)
|
||||
|
||||
m_position = position;
|
||||
QuickSettingContainer::setPosition(position);
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
m_mainLayout->setDirection(QBoxLayout::RightToLeft);
|
||||
else
|
||||
m_mainLayout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
} else {
|
||||
m_mainLayout->setDirection(QBoxLayout::BottomToTop);
|
||||
m_mainLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
||||
}
|
||||
}
|
||||
|
||||
int QuickPluginWindow::findActiveTargetIndex(QWidget *widget)
|
||||
@ -136,6 +140,7 @@ void QuickPluginWindow::addPlugin(QuickSettingItem *item)
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
widget->setFixedSize(ICONWIDTH, ICONHEIGHT);
|
||||
widget->installEventFilter(this);
|
||||
if (fixedPluginKeys.contains(item->itemKey())) {
|
||||
// 新插入的插件如果是固定插件,则将其插入到固定插件列表中,并对其进行排序
|
||||
@ -156,13 +161,26 @@ void QuickPluginWindow::addPlugin(QuickSettingItem *item)
|
||||
QSize QuickPluginWindow::suitableSize()
|
||||
{
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom)
|
||||
return QSize((ITEMSPACE + ICONSIZE) * m_mainLayout->count() + ITEMSIZE, ITEMSIZE);
|
||||
return QSize((ITEMSPACE + ICONWIDTH) * m_mainLayout->count() + ITEMSPACE, ITEMSIZE);
|
||||
|
||||
return QSize(ITEMSIZE, (ITEMSIZE + ITEMSPACE) * m_mainLayout->count() + ITEMSPACE);
|
||||
int height = 0;
|
||||
int itemCount = m_mainLayout->count();
|
||||
if (itemCount > 0) {
|
||||
// 每个图标占据的高度
|
||||
height += ICONHEIGHT * itemCount;
|
||||
// 图标间距占据的高度
|
||||
height += ITEMSPACE * itemCount;
|
||||
}
|
||||
|
||||
return QSize(ITEMSIZE, height);
|
||||
}
|
||||
|
||||
void QuickPluginWindow::removePlugin(QuickSettingItem *item)
|
||||
{
|
||||
QWidget *widget = item->pluginItem()->itemWidget(item->itemKey());
|
||||
if (widget)
|
||||
widget->setFixedSize(ICONWIDTH, ICONHEIGHT);
|
||||
|
||||
if (m_fixedSettingItems.contains(item))
|
||||
m_fixedSettingItems.removeOne(item);
|
||||
else if (m_activeSettingItems.contains(item))
|
||||
@ -201,6 +219,36 @@ void QuickPluginWindow::mousePressEvent(QMouseEvent *event)
|
||||
startDrag(quickItem);
|
||||
}
|
||||
|
||||
QPoint QuickPluginWindow::popupPoint() const
|
||||
{
|
||||
if (!parentWidget())
|
||||
return pos();
|
||||
|
||||
QPoint pointCurrent = parentWidget()->mapToGlobal(pos());
|
||||
switch (m_position) {
|
||||
case Dock::Position::Bottom: {
|
||||
// 在下方的时候,Y坐标设置在顶层窗口的y值,保证下方对齐
|
||||
pointCurrent.setY(topLevelWidget()->y());
|
||||
break;
|
||||
}
|
||||
case Dock::Position::Top: {
|
||||
// 在上面的时候,Y坐标设置为任务栏的下方,保证上方对齐
|
||||
pointCurrent.setY(topLevelWidget()->y() + topLevelWidget()->height());
|
||||
break;
|
||||
}
|
||||
case Dock::Position::Left: {
|
||||
// 在左边的时候,X坐标设置在顶层窗口的最右侧,保证左对齐
|
||||
pointCurrent.setX(topLevelWidget()->x() + topLevelWidget()->width());
|
||||
break;
|
||||
}
|
||||
case Dock::Position::Right: {
|
||||
// 在右边的时候,X坐标设置在顶层窗口的最左侧,保证右对齐
|
||||
pointCurrent.setX(topLevelWidget()->x());
|
||||
}
|
||||
}
|
||||
return pointCurrent;
|
||||
}
|
||||
|
||||
void QuickPluginWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
// 查找固定团图标,然后点击弹出快捷面板
|
||||
@ -208,20 +256,9 @@ void QuickPluginWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||
if (!quickItem)
|
||||
return;
|
||||
|
||||
// 如果是固定图标,则让其弹出列表
|
||||
QPoint currentPoint = pos();
|
||||
QWidget *callWidget = parentWidget();
|
||||
if (callWidget) {
|
||||
currentPoint = callWidget->mapToGlobal(currentPoint);
|
||||
// 如果是向上的方向,则需要减去高度
|
||||
if (m_position == Dock::Position::Top)
|
||||
currentPoint.setY(currentPoint.y() + callWidget->height());
|
||||
else if (m_position == Dock::Position::Left)
|
||||
currentPoint.setX(currentPoint.x() + callWidget->width());
|
||||
}
|
||||
|
||||
// 弹出快捷设置面板
|
||||
DockPopupWindow *popWindow = QuickSettingContainer::popWindow();
|
||||
popWindow->show(currentPoint);
|
||||
popWindow->show(popupPoint());
|
||||
}
|
||||
|
||||
void QuickPluginWindow::startDrag(QuickSettingItem *moveItem)
|
||||
@ -312,8 +349,8 @@ void QuickPluginWindow::resetPluginDisplay()
|
||||
}
|
||||
};
|
||||
|
||||
addWidget(m_activeSettingItems);
|
||||
addWidget(m_fixedSettingItems);
|
||||
addWidget(m_activeSettingItems);
|
||||
}
|
||||
|
||||
void QuickPluginWindow::initConnection()
|
||||
|
@ -72,6 +72,7 @@ private:
|
||||
QuickSettingItem *findQuickSettingItem(const QPoint &mousePoint, const QList<QuickSettingItem *> &settingItems);
|
||||
int findActiveTargetIndex(QWidget *widget);
|
||||
void resetPluginDisplay();
|
||||
QPoint popupPoint() const;
|
||||
|
||||
private:
|
||||
QBoxLayout *m_mainLayout;
|
||||
|
@ -44,7 +44,6 @@ static const int QuickItemRole = Dtk::UserRole + 10;
|
||||
|
||||
#define ITEMWIDTH 70
|
||||
#define ITEMHEIGHT 60
|
||||
#define CTRLHEIGHT 56
|
||||
#define ITEMSPACE 10
|
||||
#define COLUMNCOUNT 4
|
||||
|
||||
@ -56,11 +55,12 @@ QuickSettingContainer::QuickSettingContainer(QWidget *parent)
|
||||
, m_switchLayout(new QStackedLayout(this))
|
||||
, m_mainWidget(new QWidget(this))
|
||||
, m_pluginWidget(new QWidget(m_mainWidget))
|
||||
, m_componentWidget(new QWidget(m_mainWidget))
|
||||
, m_mainlayout(new QVBoxLayout(m_mainWidget))
|
||||
, m_pluginLoader(QuickSettingController::instance())
|
||||
, m_playerWidget(new MediaWidget(m_mainWidget))
|
||||
, m_volumnWidget(new VolumeWidget(m_mainWidget))
|
||||
, m_brihtnessWidget(new BrightnessWidget(m_mainWidget))
|
||||
, m_playerWidget(new MediaWidget(m_componentWidget))
|
||||
, m_volumnWidget(new VolumeWidget(m_componentWidget))
|
||||
, m_brihtnessWidget(new BrightnessWidget(m_componentWidget))
|
||||
, m_volumeSettingWidget(new VolumeDevicesWidget(m_volumnWidget->model(), this))
|
||||
, m_brightSettingWidget(new BrightnessMonitorWidget(m_brihtnessWidget->model(), this))
|
||||
, m_childPage(new PluginChildPage(this))
|
||||
@ -114,8 +114,8 @@ DockPopupWindow *QuickSettingContainer::popWindow()
|
||||
m_popWindow->setShadowXOffset(0);
|
||||
m_popWindow->setArrowWidth(18);
|
||||
m_popWindow->setArrowHeight(10);
|
||||
m_popWindow->setContent(new QuickSettingContainer(m_popWindow));
|
||||
m_popWindow->setArrowDirection(getDirection(m_position));
|
||||
m_popWindow->setContent(new QuickSettingContainer(m_popWindow));
|
||||
return m_popWindow;
|
||||
}
|
||||
|
||||
@ -126,8 +126,13 @@ void QuickSettingContainer::setPosition(Position position)
|
||||
|
||||
m_position = position;
|
||||
|
||||
if (m_popWindow)
|
||||
if (m_popWindow) {
|
||||
m_popWindow->setArrowDirection(getDirection(m_position));
|
||||
// 在任务栏位置发生变化的时候,需要将当前的content获取后,重新调用setContent接口
|
||||
// 如果不调用,那么就会出现内容在容器内部的位置错误,界面上的布局会乱
|
||||
QWidget *widget = m_popWindow->getContent();
|
||||
m_popWindow->setContent(widget);
|
||||
}
|
||||
}
|
||||
|
||||
void QuickSettingContainer::initQuickItem(QuickSettingItem *quickItem)
|
||||
@ -297,31 +302,28 @@ void QuickSettingContainer::initUi()
|
||||
};
|
||||
|
||||
// 添加音乐播放插件
|
||||
m_playerWidget->setFixedHeight(CTRLHEIGHT);
|
||||
m_volumnWidget->setFixedHeight(CTRLHEIGHT);
|
||||
m_brihtnessWidget->setFixedHeight(CTRLHEIGHT);
|
||||
m_playerWidget->setFixedHeight(ITEMHEIGHT);
|
||||
m_volumnWidget->setFixedHeight(ITEMHEIGHT);
|
||||
m_brihtnessWidget->setFixedHeight(ITEMHEIGHT);
|
||||
|
||||
setWidgetStyle(m_playerWidget);
|
||||
setWidgetStyle(m_volumnWidget);
|
||||
setWidgetStyle(m_brihtnessWidget);
|
||||
|
||||
m_mainlayout->setSpacing(0);
|
||||
m_mainlayout->setSpacing(ITEMSPACE);
|
||||
m_mainlayout->setContentsMargins(0, ITEMSPACE, 0, ITEMSPACE);
|
||||
|
||||
m_mainlayout->addWidget(m_pluginWidget);
|
||||
|
||||
QWidget *ctrlWidget = new QWidget(m_mainWidget);
|
||||
QVBoxLayout *ctrlLayout = new QVBoxLayout(ctrlWidget);
|
||||
ctrlLayout->setContentsMargins(ITEMSPACE, ITEMSPACE, ITEMSPACE, ITEMSPACE);
|
||||
QVBoxLayout *ctrlLayout = new QVBoxLayout(m_componentWidget);
|
||||
ctrlLayout->setContentsMargins(ITEMSPACE, 0, ITEMSPACE, 0);
|
||||
ctrlLayout->setSpacing(ITEMSPACE);
|
||||
|
||||
ctrlLayout->addSpacing(ITEMSPACE);
|
||||
ctrlLayout->addWidget(m_playerWidget);
|
||||
ctrlLayout->setSpacing(ITEMSPACE);
|
||||
ctrlLayout->addWidget(m_volumnWidget);
|
||||
ctrlLayout->setSpacing(ITEMSPACE);
|
||||
ctrlLayout->addWidget(m_brihtnessWidget);
|
||||
|
||||
m_mainlayout->addWidget(ctrlWidget);
|
||||
m_mainlayout->addWidget(m_componentWidget);
|
||||
// 加载所有的插件
|
||||
QList<QuickSettingItem *> pluginItems = m_pluginLoader->settingItems();
|
||||
for (QuickSettingItem *quickItem: pluginItems)
|
||||
@ -393,8 +395,8 @@ void QuickSettingContainer::resizeView()
|
||||
if (m_brihtnessWidget->isVisible())
|
||||
panelCount++;
|
||||
|
||||
int topHeight = ((ITEMHEIGHT + ITEMSPACE) * rowCount) + ITEMSPACE;
|
||||
setFixedHeight(topHeight + (CTRLHEIGHT + ITEMSPACE) * panelCount + ITEMSPACE);
|
||||
m_componentWidget->setFixedHeight(ITEMHEIGHT * panelCount + ITEMSPACE * (panelCount - 1));
|
||||
setFixedHeight(ITEMSPACE * 3 + m_pluginWidget->height() + m_componentWidget->height());
|
||||
} else if (m_switchLayout->currentWidget() == m_childPage) {
|
||||
setFixedHeight(m_childPage->height());
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ private:
|
||||
QStackedLayout *m_switchLayout;
|
||||
QWidget *m_mainWidget;
|
||||
QWidget *m_pluginWidget;
|
||||
QWidget *m_componentWidget;
|
||||
QVBoxLayout *m_mainlayout;
|
||||
QuickSettingController *m_pluginLoader;
|
||||
MediaWidget *m_playerWidget;
|
||||
|
@ -259,6 +259,7 @@ void TrayManagerWindow::initConnection()
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(m_dateTimeWidget, &DateTimeDisplayer::sizeChanged, this, &TrayManagerWindow::sizeChanged);
|
||||
|
||||
m_trayView->installEventFilter(this);
|
||||
m_quickIconWidget->installEventFilter(this);
|
||||
@ -302,7 +303,8 @@ void TrayManagerWindow::resetChildWidgetSize()
|
||||
m_quickIconWidget->setFixedSize(m_quickIconWidget->suitableSize().width(), trayHeight);
|
||||
m_appPluginWidget->setFixedSize(trayWidth + m_quickIconWidget->suitableSize().width(), trayHeight);
|
||||
// 因为是两行,所以对于时间控件的尺寸,只能设置最小值
|
||||
m_dateTimeWidget->setMinimumSize(m_dateTimeWidget->suitableSize().width(), m_appPluginDatetimeWidget->height() / 2);
|
||||
int dateTimeWidth = qMax(m_appPluginWidget->width(), m_dateTimeWidget->suitableSize().width());
|
||||
m_dateTimeWidget->setMinimumSize(dateTimeWidth, m_appPluginDatetimeWidget->height() / 2);
|
||||
}
|
||||
m_appPluginDatetimeWidget->setFixedWidth(appDatetimeSize());
|
||||
break;
|
||||
|
@ -59,6 +59,10 @@ public:
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||
void dropEvent(QDropEvent *e) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
|
||||
private:
|
||||
void initUi();
|
||||
@ -68,11 +72,6 @@ private:
|
||||
void resetMultiDirection();
|
||||
void resetSingleDirection();
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void dragMoveEvent(QDragMoveEvent *e) override;
|
||||
void dropEvent(QDropEvent *e) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
|
||||
bool showSingleRow();
|
||||
int appDatetimeSize();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user