mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: add hold container
Change-Id: I370c68c6e234d49965657bc293e7d5028b1f8eb2
This commit is contained in:
parent
aae408d5b7
commit
902cb3271f
Notes:
gerrit
2018-12-27 08:55:27 +08:00
Verified+1: <jenkins@deepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Thu, 27 Dec 2018 08:55:26 +0800 Reviewed-on: https://cr.deepin.io/40913 Project: dde/dde-dock Branch: refs/heads/dev/drag-and-hold-tray
@ -4,11 +4,12 @@
|
||||
#define SpliterSize 2
|
||||
#define TraySpace 10
|
||||
|
||||
FashionTrayHoldContainer::FashionTrayHoldContainer(Dock::Position dockPosistion, QWidget *parent)
|
||||
FashionTrayHoldContainer::FashionTrayHoldContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_mainBoxLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight)),
|
||||
m_holdSpliter(new QLabel),
|
||||
m_dockPosistion(dockPosistion)
|
||||
m_trayPlugin(trayPlugin),
|
||||
m_dockPosistion(trayPlugin->dockPosition())
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
@ -59,6 +60,66 @@ void FashionTrayHoldContainer::setTrayExpand(const bool expand)
|
||||
});
|
||||
}
|
||||
|
||||
bool FashionTrayHoldContainer::exists(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
for (auto w : m_holdWrapperList) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FashionTrayHoldContainer::isHoldTrayWrapper(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
const QString &key = QString("%1_hold").arg(wrapper->itemKey());
|
||||
return m_trayPlugin->getValue(key, false).toBool();
|
||||
}
|
||||
|
||||
void FashionTrayHoldContainer::addTrayWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
const QString &key = QString("%1_hold").arg(wrapper->itemKey());
|
||||
m_trayPlugin->saveValue(key, true);
|
||||
|
||||
const int index = whereToInsert(wrapper);
|
||||
m_mainBoxLayout->insertWidget(index, wrapper);
|
||||
m_holdWrapperList.insert(index, wrapper);
|
||||
}
|
||||
|
||||
bool FashionTrayHoldContainer::removeTrayWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
return false;
|
||||
|
||||
const QString &key = QString("%1_hold").arg(wrapper->itemKey());
|
||||
m_trayPlugin->saveValue(key, false);
|
||||
}
|
||||
|
||||
int FashionTrayHoldContainer::whereToInsert(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
if (m_holdWrapperList.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int destSortKey = m_trayPlugin->itemSortKey(wrapper->itemKey());
|
||||
|
||||
if (destSortKey < -1) {
|
||||
return 0;
|
||||
}
|
||||
if (destSortKey == -1) {
|
||||
return m_holdWrapperList.size();
|
||||
}
|
||||
|
||||
// 当目标插入位置为列表的大小时将从最后面追加到列表中
|
||||
int destIndex = m_holdWrapperList.size();
|
||||
for (int i = 0; i < m_holdWrapperList.size(); ++i) {
|
||||
if (destSortKey > m_trayPlugin->itemSortKey(m_holdWrapperList.at(i)->itemKey())) {
|
||||
continue;
|
||||
}
|
||||
destIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
return destIndex;
|
||||
}
|
||||
|
||||
QSize FashionTrayHoldContainer::sizeHint() const
|
||||
{
|
||||
QSize size;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define FASHIONTRAYHOLDCONTAINER_H
|
||||
|
||||
#include "constants.h"
|
||||
#include "trayplugin.h"
|
||||
#include "fashiontraywidgetwrapper.h"
|
||||
|
||||
#include <QWidget>
|
||||
@ -12,11 +13,19 @@ class FashionTrayHoldContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FashionTrayHoldContainer(Dock::Position dockPosistion, QWidget *parent = nullptr);
|
||||
explicit FashionTrayHoldContainer(TrayPlugin *trayPlugin, QWidget *parent = nullptr);
|
||||
|
||||
void setDockPostion(Dock::Position pos);
|
||||
void setTrayExpand(const bool expand);
|
||||
|
||||
bool exists(FashionTrayWidgetWrapper *wrapper) const;
|
||||
bool isHoldTrayWrapper(FashionTrayWidgetWrapper *wrapper) const;
|
||||
|
||||
void addTrayWrapper(FashionTrayWidgetWrapper *wrapper);
|
||||
bool removeTrayWrapper(FashionTrayWidgetWrapper *wrapper);
|
||||
|
||||
int whereToInsert(FashionTrayWidgetWrapper *wrapper) const;
|
||||
|
||||
public:
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
@ -25,6 +34,8 @@ private:
|
||||
QBoxLayout *m_mainBoxLayout;
|
||||
QLabel *m_holdSpliter;
|
||||
|
||||
TrayPlugin *m_trayPlugin;
|
||||
|
||||
bool m_expand;
|
||||
|
||||
Dock::Position m_dockPosistion;
|
||||
|
@ -47,7 +47,7 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_controlWidget(new FashionTrayControlWidget(m_dockPosistion)),
|
||||
m_currentAttentionTray(nullptr),
|
||||
m_currentDraggingTray(nullptr),
|
||||
m_holdContainer(new FashionTrayHoldContainer(m_dockPosistion))
|
||||
m_holdContainer(new FashionTrayHoldContainer(m_trayPlugin))
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
@ -100,9 +100,9 @@ void FashionTrayItem::setTrayWidgets(const QMap<QString, AbstractTrayWidget *> &
|
||||
|
||||
void FashionTrayItem::trayWidgetAdded(const QString &itemKey, AbstractTrayWidget *trayWidget)
|
||||
{
|
||||
for (auto w : m_wrapperList) {
|
||||
for (auto w : m_totalWrapperList) {
|
||||
if (w->absTrayWidget() == trayWidget) {
|
||||
qDebug() << "Reject! want to isert duplicate trayWidget:" << itemKey << trayWidget;
|
||||
qDebug() << "Reject! want to insert duplicate trayWidget:" << itemKey << trayWidget;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ void FashionTrayItem::trayWidgetAdded(const QString &itemKey, AbstractTrayWidget
|
||||
|
||||
const int index = whereToInsert(wrapper);
|
||||
m_trayBoxLayout->insertWidget(index, wrapper);
|
||||
m_wrapperList.insert(index, wrapper);
|
||||
m_normalWrapperList.insert(index, wrapper);
|
||||
|
||||
wrapper->setVisible(m_controlWidget->expanded());
|
||||
|
||||
@ -132,7 +132,7 @@ void FashionTrayItem::trayWidgetRemoved(AbstractTrayWidget *trayWidget)
|
||||
{
|
||||
bool founded = false;
|
||||
|
||||
for (auto wrapper : m_wrapperList) {
|
||||
for (auto wrapper : m_normalWrapperList) {
|
||||
// found the removed tray
|
||||
if (wrapper->absTrayWidget() == trayWidget) {
|
||||
// the removed tray is a attention tray
|
||||
@ -150,7 +150,7 @@ void FashionTrayItem::trayWidgetRemoved(AbstractTrayWidget *trayWidget)
|
||||
// the real tray object should be deleted in TrayPlugin class
|
||||
trayWidget->setParent(nullptr);
|
||||
wrapper->deleteLater();
|
||||
m_wrapperList.removeAll(wrapper);
|
||||
m_normalWrapperList.removeAll(wrapper);
|
||||
founded = true;
|
||||
break;
|
||||
}
|
||||
@ -165,13 +165,13 @@ void FashionTrayItem::trayWidgetRemoved(AbstractTrayWidget *trayWidget)
|
||||
|
||||
void FashionTrayItem::clearTrayWidgets()
|
||||
{
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> mList = m_wrapperList;
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> mList = m_normalWrapperList;
|
||||
|
||||
for (auto wrapper : mList) {
|
||||
trayWidgetRemoved(wrapper->absTrayWidget());
|
||||
}
|
||||
|
||||
m_wrapperList.clear();
|
||||
m_normalWrapperList.clear();
|
||||
|
||||
requestResize();
|
||||
}
|
||||
@ -241,7 +241,7 @@ void FashionTrayItem::setSuggestIconSize(QSize size)
|
||||
|
||||
m_controlWidget->setFixedSize(newSize);
|
||||
|
||||
for (auto wrapper : m_wrapperList) {
|
||||
for (auto wrapper : m_normalWrapperList) {
|
||||
wrapper->setFixedSize(newSize);
|
||||
}
|
||||
|
||||
@ -319,22 +319,22 @@ QSize FashionTrayItem::wantedTotalSize() const
|
||||
if (m_controlWidget->expanded()) {
|
||||
if (m_dockPosistion == Dock::Position::Top || m_dockPosistion == Dock::Position::Bottom) {
|
||||
size.setWidth(
|
||||
m_wrapperList.size() * TrayWidgetWidth // 所有托盘图标
|
||||
m_normalWrapperList.size() * TrayWidgetWidth // 所有托盘图标
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
+ SpliterSize * 2 // 两个分隔条
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ m_wrapperList.size() * TraySpace // TrayBoxLayout 中所有 space + 后面跟一个 space
|
||||
+ m_normalWrapperList.size() * TraySpace // TrayBoxLayout 中所有 space + 后面跟一个 space
|
||||
+ m_holdContainer->sizeHint().width() // 保留区域的宽
|
||||
);
|
||||
size.setHeight(height());
|
||||
} else {
|
||||
size.setWidth(width());
|
||||
size.setHeight(
|
||||
m_wrapperList.size() * TrayWidgetHeight // 所有托盘图标
|
||||
m_normalWrapperList.size() * TrayWidgetHeight // 所有托盘图标
|
||||
+ TrayWidgetHeight // 控制按钮
|
||||
+ SpliterSize * 2 // 两个分隔条
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ m_wrapperList.size() * TraySpace // TrayBoxLayout 中所有 space + 后面跟一个 space
|
||||
+ m_normalWrapperList.size() * TraySpace // TrayBoxLayout 中所有 space + 后面跟一个 space
|
||||
+ m_holdContainer->sizeHint().height() // 保留区域的高
|
||||
);
|
||||
}
|
||||
@ -381,7 +381,7 @@ int FashionTrayItem::whereToInsert(FashionTrayWidgetWrapper *wrapper) const
|
||||
|
||||
int FashionTrayItem::whereToInsertBySortKey(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
if (m_wrapperList.isEmpty()) {
|
||||
if (m_normalWrapperList.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -391,13 +391,13 @@ int FashionTrayItem::whereToInsertBySortKey(FashionTrayWidgetWrapper *wrapper) c
|
||||
return 0;
|
||||
}
|
||||
if (destSortKey == -1) {
|
||||
return m_wrapperList.size();
|
||||
return m_normalWrapperList.size();
|
||||
}
|
||||
|
||||
// 当目标插入位置为列表的大小时将从最后面追加到列表中
|
||||
int destIndex = m_wrapperList.size();
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
if (destSortKey > m_trayPlugin->itemSortKey(m_wrapperList.at(i)->itemKey())) {
|
||||
int destIndex = m_normalWrapperList.size();
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
if (destSortKey > m_trayPlugin->itemSortKey(m_normalWrapperList.at(i)->itemKey())) {
|
||||
continue;
|
||||
}
|
||||
destIndex = i;
|
||||
@ -426,13 +426,13 @@ int FashionTrayItem::whereToInsertByDefault(FashionTrayWidgetWrapper *wrapper) c
|
||||
|
||||
int FashionTrayItem::whereToInsertAppTrayByDefault(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
if (m_wrapperList.isEmpty() || wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
if (m_normalWrapperList.isEmpty() || wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lastAppTrayIndex = -1;
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
if (m_wrapperList.at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
if (m_normalWrapperList.at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
lastAppTrayIndex = i;
|
||||
continue;
|
||||
}
|
||||
@ -452,12 +452,12 @@ int FashionTrayItem::whereToInsertAppTrayByDefault(FashionTrayWidgetWrapper *wra
|
||||
if (insertIndex < -1) {
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
if (m_wrapperList.at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
if (m_normalWrapperList.at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::ApplicationTray) {
|
||||
insertIndex = i;
|
||||
break;
|
||||
}
|
||||
if (insertIndex > m_trayPlugin->itemSortKey(m_wrapperList.at(i)->itemKey())) {
|
||||
if (insertIndex > m_trayPlugin->itemSortKey(m_normalWrapperList.at(i)->itemKey())) {
|
||||
continue;
|
||||
}
|
||||
insertIndex = i;
|
||||
@ -472,20 +472,20 @@ int FashionTrayItem::whereToInsertAppTrayByDefault(FashionTrayWidgetWrapper *wra
|
||||
|
||||
int FashionTrayItem::whereToInsertSystemTrayByDefault(FashionTrayWidgetWrapper *wrapper) const
|
||||
{
|
||||
if (m_wrapperList.isEmpty()) {
|
||||
if (m_normalWrapperList.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int firstSystemTrayIndex = -1;
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
if (m_wrapperList.at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::SystemTray) {
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
if (m_normalWrapperList.at(i)->absTrayWidget()->trayTyep() == AbstractTrayWidget::TrayType::SystemTray) {
|
||||
firstSystemTrayIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// there is no SystemTray
|
||||
if (firstSystemTrayIndex == -1) {
|
||||
return m_wrapperList.size();
|
||||
return m_normalWrapperList.size();
|
||||
}
|
||||
// the inserting tray is not a SystemTray
|
||||
if (wrapper->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::SystemTray) {
|
||||
@ -497,11 +497,11 @@ int FashionTrayItem::whereToInsertSystemTrayByDefault(FashionTrayWidgetWrapper *
|
||||
if (insertIndex < -1) {
|
||||
return firstSystemTrayIndex;
|
||||
}
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
if (m_wrapperList.at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::SystemTray) {
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
if (m_normalWrapperList.at(i)->absTrayWidget()->trayTyep() != AbstractTrayWidget::TrayType::SystemTray) {
|
||||
continue;
|
||||
}
|
||||
if (insertIndex > m_trayPlugin->itemSortKey(m_wrapperList.at(i)->itemKey())) {
|
||||
if (insertIndex > m_trayPlugin->itemSortKey(m_normalWrapperList.at(i)->itemKey())) {
|
||||
continue;
|
||||
}
|
||||
insertIndex = i;
|
||||
@ -516,8 +516,8 @@ int FashionTrayItem::whereToInsertSystemTrayByDefault(FashionTrayWidgetWrapper *
|
||||
|
||||
void FashionTrayItem::saveCurrentOrderToConfig()
|
||||
{
|
||||
for (int i = 0; i < m_wrapperList.size(); ++i) {
|
||||
m_trayPlugin->setSortKey(m_wrapperList.at(i)->itemKey(), i + 1);
|
||||
for (int i = 0; i < m_normalWrapperList.size(); ++i) {
|
||||
m_trayPlugin->setSortKey(m_normalWrapperList.at(i)->itemKey(), i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,7 +642,7 @@ void FashionTrayItem::refreshTraysVisible()
|
||||
m_currentAttentionTray = nullptr;
|
||||
}
|
||||
|
||||
for (auto wrapper : m_wrapperList) {
|
||||
for (auto wrapper : m_normalWrapperList) {
|
||||
wrapper->setVisible(expand);
|
||||
// reset all tray item attention state
|
||||
wrapper->setAttention(false);
|
||||
@ -695,5 +695,5 @@ void FashionTrayItem::onItemRequestSwapWithDragging()
|
||||
m_trayBoxLayout->removeWidget(m_currentDraggingTray);
|
||||
m_trayBoxLayout->insertWidget(indexOfDest, m_currentDraggingTray);
|
||||
|
||||
m_wrapperList.insert(indexOfDest, m_wrapperList.takeAt(indexOfDragging));
|
||||
m_normalWrapperList.insert(indexOfDest, m_normalWrapperList.takeAt(indexOfDragging));
|
||||
}
|
||||
|
@ -102,7 +102,8 @@ private:
|
||||
FashionTrayWidgetWrapper *m_currentDraggingTray;
|
||||
FashionTrayHoldContainer *m_holdContainer;
|
||||
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> m_wrapperList;
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> m_totalWrapperList;
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> m_normalWrapperList;
|
||||
|
||||
static int TrayWidgetWidth;
|
||||
static int TrayWidgetHeight;
|
||||
|
Loading…
x
Reference in New Issue
Block a user