2023-02-16 13:51:55 +08:00
|
|
|
|
// Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2020-05-27 16:40:12 +08:00
|
|
|
|
|
2018-12-27 16:54:49 +08:00
|
|
|
|
#include "normalcontainer.h"
|
2018-12-28 17:00:29 +08:00
|
|
|
|
#include "../fashiontrayconstants.h"
|
2018-12-27 16:54:49 +08:00
|
|
|
|
|
|
|
|
|
NormalContainer::NormalContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
|
|
|
|
: AbstractContainer(trayPlugin, parent)
|
2019-09-12 15:28:19 +08:00
|
|
|
|
, m_sizeAnimation(new QVariantAnimation(this))
|
2018-12-27 16:54:49 +08:00
|
|
|
|
{
|
2019-09-12 15:28:19 +08:00
|
|
|
|
m_sizeAnimation->setEasingCurve(QEasingCurve::InOutCubic);
|
|
|
|
|
|
|
|
|
|
connect(m_sizeAnimation, &QVariantAnimation::valueChanged, [ = ](const QVariant & value) {
|
2019-10-31 15:38:56 +08:00
|
|
|
|
|
|
|
|
|
if (m_sizeAnimation->state() != QVariantAnimation::Running)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-10-16 13:41:30 +08:00
|
|
|
|
adjustMaxSize(value.toSize());
|
2019-09-12 15:28:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-09-17 13:14:23 +08:00
|
|
|
|
connect(m_sizeAnimation, &QVariantAnimation::finished, [ = ]() {
|
|
|
|
|
this->setVisible(expand());
|
2019-09-12 15:28:19 +08:00
|
|
|
|
});
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
|
|
|
|
connect(DWindowManagerHelper::instance(), &DWindowManagerHelper::hasCompositeChanged, this, &NormalContainer::compositeChanged, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
QTimer::singleShot(1, this, &NormalContainer::compositeChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NormalContainer::compositeChanged()
|
|
|
|
|
{
|
2019-12-26 15:14:12 +08:00
|
|
|
|
int duration = DWindowManagerHelper::instance()->hasComposite() ? 300 : 1;
|
|
|
|
|
if (isEmpty())
|
|
|
|
|
duration = 0;
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
|
|
|
|
m_sizeAnimation->setDuration(duration);
|
2019-09-12 15:28:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize NormalContainer::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return totalSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NormalContainer::resizeEvent(QResizeEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (QPropertyAnimation::Stopped == m_sizeAnimation->state()) {
|
|
|
|
|
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom)
|
|
|
|
|
setMaximumWidth(totalSize().width());
|
|
|
|
|
else {
|
|
|
|
|
setMaximumHeight(totalSize().height());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractContainer::resizeEvent(event);
|
2018-12-27 16:54:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NormalContainer::acceptWrapper(FashionTrayWidgetWrapper *wrapper)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(wrapper);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 17:00:29 +08:00
|
|
|
|
void NormalContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
|
|
|
|
{
|
|
|
|
|
AbstractContainer::addWrapper(wrapper);
|
|
|
|
|
|
|
|
|
|
if (containsWrapper(wrapper)) {
|
2019-04-04 17:31:31 +08:00
|
|
|
|
const QString &key = HoldKeyPrefix + wrapper->absTrayWidget()->itemKeyForConfig();
|
2018-12-28 17:00:29 +08:00
|
|
|
|
trayPlugin()->saveValue(wrapper->itemKey(), key, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 16:54:49 +08:00
|
|
|
|
void NormalContainer::refreshVisible()
|
|
|
|
|
{
|
2019-09-06 11:20:14 +08:00
|
|
|
|
AbstractContainer::refreshVisible();
|
|
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
|
for (auto w : wrapperList()) {
|
|
|
|
|
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom)
|
|
|
|
|
w->setFixedSize(itemSize(), QWIDGETSIZE_MAX);
|
|
|
|
|
else
|
|
|
|
|
w->setFixedSize(QWIDGETSIZE_MAX, itemSize());
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-02 09:44:47 +08:00
|
|
|
|
if (isEmpty()) {
|
|
|
|
|
// set the minimum size to 1 to avoid can not drag back wrappers when
|
|
|
|
|
// all wrappers has been drag out
|
2019-09-06 11:20:14 +08:00
|
|
|
|
setMinimumSize(TraySpace, TraySpace);
|
2019-01-02 09:44:47 +08:00
|
|
|
|
} else {
|
|
|
|
|
// set the minimum size back to 0 in order to make the fold animation works correctly
|
|
|
|
|
setMinimumSize(0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-26 15:14:12 +08:00
|
|
|
|
compositeChanged();
|
2019-09-12 15:28:19 +08:00
|
|
|
|
QSize endSize = expand() ? totalSize() : QSize(0, 0);
|
|
|
|
|
|
|
|
|
|
const QPropertyAnimation::State state = m_sizeAnimation->state();
|
|
|
|
|
|
2019-10-09 17:06:11 +08:00
|
|
|
|
if (state == QPropertyAnimation::Stopped && size() == endSize) {
|
|
|
|
|
setVisible(expand());
|
2019-09-12 15:28:19 +08:00
|
|
|
|
return;
|
2019-10-09 17:06:11 +08:00
|
|
|
|
}
|
2019-09-12 15:28:19 +08:00
|
|
|
|
|
|
|
|
|
if (state == QPropertyAnimation::Running)
|
|
|
|
|
return m_sizeAnimation->setEndValue(endSize);
|
|
|
|
|
|
|
|
|
|
m_sizeAnimation->setStartValue(size());
|
|
|
|
|
m_sizeAnimation->setEndValue(endSize);
|
|
|
|
|
|
2019-10-16 13:41:30 +08:00
|
|
|
|
if (isVisible() == expand()) {
|
|
|
|
|
// 非x86平台,第一次启动setEndValue时,不进QVariantAnimation::valueChanged
|
|
|
|
|
adjustMaxSize(endSize);
|
2019-09-12 15:28:19 +08:00
|
|
|
|
return;
|
2019-10-16 13:41:30 +08:00
|
|
|
|
}
|
2019-09-12 15:28:19 +08:00
|
|
|
|
|
|
|
|
|
if (expand()) {
|
|
|
|
|
setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sizeAnimation->start();
|
2018-12-27 16:54:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 13:41:30 +08:00
|
|
|
|
void NormalContainer::adjustMaxSize(const QSize size)
|
|
|
|
|
{
|
|
|
|
|
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom) {
|
|
|
|
|
this->setMaximumWidth(size.width());
|
|
|
|
|
this->setMaximumHeight(DOCK_MAX_SIZE);
|
|
|
|
|
} else {
|
|
|
|
|
this->setMaximumWidth(DOCK_MAX_SIZE);
|
|
|
|
|
this->setMaximumHeight(size.height());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 09:42:09 +08:00
|
|
|
|
int NormalContainer::itemCount()
|
|
|
|
|
{
|
2019-10-31 15:38:56 +08:00
|
|
|
|
if (expand())
|
2019-10-30 09:42:09 +08:00
|
|
|
|
return AbstractContainer::itemCount();
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-27 16:54:49 +08:00
|
|
|
|
void NormalContainer::setExpand(const bool expand)
|
|
|
|
|
{
|
2020-06-12 09:51:42 +08:00
|
|
|
|
// int itemSize;
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
2020-06-12 09:51:42 +08:00
|
|
|
|
// if (dockPosition() == Dock::Position::Top || dockPosition() == Dock::Position::Bottom)
|
|
|
|
|
// itemSize = std::min(parentWidget()->height(), PLUGIN_BACKGROUND_MAX_SIZE);
|
|
|
|
|
// else
|
|
|
|
|
// itemSize = std::min(parentWidget()->width(), PLUGIN_BACKGROUND_MAX_SIZE);
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
|
for (auto w : wrapperList()) {
|
|
|
|
|
w->setAttention(false);
|
2019-09-17 13:14:23 +08:00
|
|
|
|
|
2019-10-31 15:38:56 +08:00
|
|
|
|
// w->setFixedSize(itemSize, itemSize);
|
2018-12-27 16:54:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractContainer::setExpand(expand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NormalContainer::whereToInsert(FashionTrayWidgetWrapper *wrapper)
|
|
|
|
|
{
|
|
|
|
|
// 如果已经对图标进行过排序则完全按照从配置文件中获取的顺序来插入图标(即父类的实现)
|
|
|
|
|
if (trayPlugin()->traysSortedInFashionMode()) {
|
|
|
|
|
return AbstractContainer::whereToInsert(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果没有对图标进行过排序则使用下面的默认排序算法:
|
|
|
|
|
// 所有应用图标在系统图标的左侧
|
|
|
|
|
// 新的应用图标在最左侧的应用图标处插入
|
2020-05-27 16:40:12 +08:00
|
|
|
|
// 系统图标按插件默认顺序(收缩箭头起从右往左由大到小排)在应用图标右侧插入
|
2018-12-27 16:54:49 +08:00
|
|
|
|
return whereToInsertByDefault(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NormalContainer::whereToInsertByDefault(FashionTrayWidgetWrapper *wrapper) const
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
switch (wrapper->absTrayWidget()->trayTyep()) {
|
|
|
|
|
case AbstractTrayWidget::TrayType::ApplicationTray:
|
|
|
|
|
index = whereToInsertAppTrayByDefault(wrapper);
|
|
|
|
|
break;
|
|
|
|
|
case AbstractTrayWidget::TrayType::SystemTray:
|
|
|
|
|
index = whereToInsertSystemTrayByDefault(wrapper);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NormalContainer::whereToInsertAppTrayByDefault(FashionTrayWidgetWrapper *wrapper) const
|
|
|
|
|
{
|
|
|
|
|
if (wrapperList().isEmpty() || wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lastAppTrayIndex = -1;
|
|
|
|
|
for (int i = 0; i < wrapperList().size(); ++i) {
|
|
|
|
|
if (wrapperList().at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::ApplicationTray) {
|
|
|
|
|
lastAppTrayIndex = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// there is no AppTray
|
|
|
|
|
if (lastAppTrayIndex == -1) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// the inserting tray is not a AppTray
|
|
|
|
|
if (wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
|
|
|
|
return lastAppTrayIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int insertIndex = trayPlugin()->itemSortKey(wrapper->itemKey());
|
|
|
|
|
// invalid index
|
|
|
|
|
if (insertIndex < -1) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < wrapperList().size(); ++i) {
|
|
|
|
|
if (wrapperList().at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
|
|
|
|
insertIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (insertIndex > trayPlugin()->itemSortKey(wrapperList().at(i)->itemKey())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
insertIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (insertIndex > lastAppTrayIndex + 1) {
|
|
|
|
|
insertIndex = lastAppTrayIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return insertIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NormalContainer::whereToInsertSystemTrayByDefault(FashionTrayWidgetWrapper *wrapper) const
|
|
|
|
|
{
|
|
|
|
|
if (wrapperList().isEmpty()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int firstSystemTrayIndex = -1;
|
|
|
|
|
for (int i = 0; i < wrapperList().size(); ++i) {
|
|
|
|
|
if (wrapperList().at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::SystemTray) {
|
|
|
|
|
firstSystemTrayIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// there is no SystemTray
|
|
|
|
|
if (firstSystemTrayIndex == -1) {
|
|
|
|
|
return wrapperList().size();
|
|
|
|
|
}
|
|
|
|
|
// the inserting tray is not a SystemTray
|
|
|
|
|
if (wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::SystemTray) {
|
|
|
|
|
return firstSystemTrayIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int insertIndex = trayPlugin()->itemSortKey(wrapper->itemKey());
|
|
|
|
|
// invalid index
|
|
|
|
|
if (insertIndex < -1) {
|
|
|
|
|
return firstSystemTrayIndex;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < wrapperList().size(); ++i) {
|
|
|
|
|
if (wrapperList().at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::SystemTray) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (insertIndex > trayPlugin()->itemSortKey(wrapperList().at(i)->itemKey())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
insertIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (insertIndex < firstSystemTrayIndex) {
|
|
|
|
|
return firstSystemTrayIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return insertIndex;
|
|
|
|
|
}
|
2020-01-02 14:59:42 +08:00
|
|
|
|
void NormalContainer::updateSize()
|
|
|
|
|
{
|
|
|
|
|
if (QPropertyAnimation::Stopped == m_sizeAnimation->state()) {
|
|
|
|
|
if (dockPosition() == Dock::Top || dockPosition() == Dock::Bottom)
|
|
|
|
|
setMaximumWidth(totalSize().width());
|
|
|
|
|
else {
|
|
|
|
|
setMaximumHeight(totalSize().height());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|