mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: add hold container
wrappers can be drop into hold container from normal container, of course, wrappers in hold container can also be drop into normal container Change-Id: I21013beede7661507a9c389af21c35692b777dd4
This commit is contained in:
parent
7c1ae86a79
commit
fea60742c5
Notes:
gerrit
2018-12-28 17:44:30 +08:00
Verified+1: <jenkins@deepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Fri, 28 Dec 2018 17:44:30 +0800 Reviewed-on: https://cr.deepin.io/40960 Project: dde/dde-dock Branch: refs/heads/dev/drag-and-hold-tray
@ -10,6 +10,8 @@ AbstractContainer::AbstractContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_dockPosition(Dock::Position::Bottom),
|
||||
m_wrapperSize(QSize(TrayWidgetWidthMin, TrayWidgetHeightMin))
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
m_wrapperLayout->setMargin(0);
|
||||
m_wrapperLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_wrapperLayout->setSpacing(TraySpace);
|
||||
@ -22,10 +24,6 @@ AbstractContainer::AbstractContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
|
||||
void AbstractContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
if (!acceptWrapper(wrapper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
return;
|
||||
}
|
||||
@ -78,6 +76,10 @@ FashionTrayWidgetWrapper *AbstractContainer::takeWrapper(FashionTrayWidgetWrappe
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_currentDraggingWrapper == wrapper) {
|
||||
m_currentDraggingWrapper = nullptr;
|
||||
}
|
||||
|
||||
wrapper->disconnect();
|
||||
m_wrapperLayout->removeWidget(wrapper);
|
||||
m_wrapperList.removeAll(wrapper);
|
||||
@ -173,7 +175,7 @@ bool AbstractContainer::isEmpty()
|
||||
bool AbstractContainer::containsWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
for (auto w : m_wrapperList) {
|
||||
if (w->absTrayWidget() == wrapper->absTrayWidget()) {
|
||||
if (w == wrapper) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -201,6 +203,24 @@ FashionTrayWidgetWrapper *AbstractContainer::wrapperByTrayWidget(AbstractTrayWid
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AbstractContainer::addDraggingWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
addWrapper(wrapper);
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
m_currentDraggingWrapper = wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
FashionTrayWidgetWrapper *AbstractContainer::takeDraggingWrapper()
|
||||
{
|
||||
if (!m_currentDraggingWrapper) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return takeWrapper(m_currentDraggingWrapper);
|
||||
}
|
||||
|
||||
int AbstractContainer::whereToInsert(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
if (m_wrapperList.isEmpty()) {
|
||||
@ -245,6 +265,14 @@ QBoxLayout *AbstractContainer::wrapperLayout() const
|
||||
return m_wrapperLayout;
|
||||
}
|
||||
|
||||
// replace current WrapperLayout by "layout"
|
||||
// but will not setLayout here, so the caller should handle the new WrapperLayout
|
||||
void AbstractContainer::setWrapperLayout(QBoxLayout *layout)
|
||||
{
|
||||
delete m_wrapperLayout;
|
||||
m_wrapperLayout = layout;
|
||||
}
|
||||
|
||||
bool AbstractContainer::expand() const
|
||||
{
|
||||
return m_expand;
|
||||
@ -260,6 +288,17 @@ QSize AbstractContainer::wrapperSize() const
|
||||
return m_wrapperSize;
|
||||
}
|
||||
|
||||
void AbstractContainer::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(TRAY_ITEM_DRAG_MIMEDATA) && !m_currentDraggingWrapper) {
|
||||
event->accept();
|
||||
Q_EMIT requestDraggingWrapper();
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget::dragEnterEvent(event);
|
||||
}
|
||||
|
||||
void AbstractContainer::onWrapperAttentionhChanged(const bool attention)
|
||||
{
|
||||
FashionTrayWidgetWrapper *wrapper = dynamic_cast<FashionTrayWidgetWrapper *>(sender());
|
||||
@ -302,10 +341,21 @@ void AbstractContainer::onWrapperRequestSwapWithDragging()
|
||||
{
|
||||
FashionTrayWidgetWrapper *wrapper = static_cast<FashionTrayWidgetWrapper *>(sender());
|
||||
|
||||
if (!wrapper || !m_currentDraggingWrapper || wrapper == m_currentDraggingWrapper) {
|
||||
if (!wrapper || wrapper == m_currentDraggingWrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the current dragging wrapper is null means that the dragging wrapper is contains by
|
||||
// another container, so this container need to emit requireDraggingWrapper() signal
|
||||
// to notify FashionTrayItem, the FashionTrayItem will move the dragging wrapper to this container
|
||||
if (!m_currentDraggingWrapper) {
|
||||
Q_EMIT requestDraggingWrapper();
|
||||
// here have to give up if dragging wrapper is still null
|
||||
if (!m_currentDraggingWrapper) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const int indexOfDest = m_wrapperLayout->indexOf(wrapper);
|
||||
const int indexOfDragging = m_wrapperLayout->indexOf(m_currentDraggingWrapper);
|
||||
|
||||
|
@ -34,8 +34,12 @@ public:
|
||||
bool containsWrapperByTrayWidget(AbstractTrayWidget *trayWidget);
|
||||
FashionTrayWidgetWrapper *wrapperByTrayWidget(AbstractTrayWidget *trayWidget);
|
||||
|
||||
void addDraggingWrapper(FashionTrayWidgetWrapper *wrapper);
|
||||
FashionTrayWidgetWrapper *takeDraggingWrapper();
|
||||
|
||||
Q_SIGNALS:
|
||||
void attentionChanged(FashionTrayWidgetWrapper *wrapper, const bool attention);
|
||||
void requestDraggingWrapper();
|
||||
|
||||
protected:
|
||||
virtual int whereToInsert(FashionTrayWidgetWrapper *wrapper);
|
||||
@ -43,10 +47,14 @@ protected:
|
||||
TrayPlugin *trayPlugin() const;
|
||||
QList<QPointer<FashionTrayWidgetWrapper>> wrapperList() const;
|
||||
QBoxLayout *wrapperLayout() const;
|
||||
void setWrapperLayout(QBoxLayout *layout);
|
||||
bool expand() const;
|
||||
Dock::Position dockPosition() const;
|
||||
QSize wrapperSize() const;
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onWrapperAttentionhChanged(const bool attention);
|
||||
void onWrapperDragStart();
|
||||
|
@ -1,6 +1,108 @@
|
||||
#include "holdcontainer.h"
|
||||
#include "../fashiontrayconstants.h"
|
||||
|
||||
HoldContainer::HoldContainer(QWidget *parent) : QWidget(parent)
|
||||
HoldContainer::HoldContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
: AbstractContainer(trayPlugin, parent),
|
||||
m_mainBoxLayout(new QBoxLayout(QBoxLayout::Direction::LeftToRight)),
|
||||
m_holdSpliter(new QLabel)
|
||||
{
|
||||
m_holdSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
|
||||
|
||||
m_mainBoxLayout->setMargin(0);
|
||||
m_mainBoxLayout->setContentsMargins(0, 0, 0, 0);
|
||||
m_mainBoxLayout->setSpacing(TraySpace);
|
||||
|
||||
QBoxLayout *preLayout = wrapperLayout();
|
||||
QBoxLayout *newLayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight);
|
||||
for (int i = 0; i < preLayout->count(); ++i) {
|
||||
newLayout->addItem(preLayout->takeAt(i));
|
||||
}
|
||||
setWrapperLayout(newLayout);
|
||||
|
||||
m_mainBoxLayout->addWidget(m_holdSpliter);
|
||||
m_mainBoxLayout->addLayout(newLayout);
|
||||
|
||||
m_mainBoxLayout->setAlignment(m_holdSpliter, Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(newLayout, Qt::AlignCenter);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setLayout(m_mainBoxLayout);
|
||||
}
|
||||
|
||||
bool HoldContainer::acceptWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
return trayPlugin()->getValue(wrapper->itemKey(), key, false).toBool();
|
||||
}
|
||||
|
||||
void HoldContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
AbstractContainer::addWrapper(wrapper);
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
trayPlugin()->saveValue(wrapper->itemKey(), key, true);
|
||||
}
|
||||
}
|
||||
|
||||
void HoldContainer::refreshVisible()
|
||||
{
|
||||
setVisible(expand() || !isEmpty());
|
||||
}
|
||||
|
||||
void HoldContainer::setDockPosition(const Dock::Position pos)
|
||||
{
|
||||
if (pos == Dock::Position::Top || pos == Dock::Position::Bottom) {
|
||||
m_mainBoxLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
} else{
|
||||
m_mainBoxLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
}
|
||||
|
||||
AbstractContainer::setDockPosition(pos);
|
||||
}
|
||||
|
||||
void HoldContainer::setExpand(const bool expand)
|
||||
{
|
||||
m_holdSpliter->setVisible(expand);
|
||||
|
||||
AbstractContainer::setExpand(expand);
|
||||
}
|
||||
|
||||
QSize HoldContainer::totalSize() const
|
||||
{
|
||||
QSize size = AbstractContainer::totalSize();
|
||||
|
||||
if (expand()) {
|
||||
if (dockPosition() == Dock::Position::Top || dockPosition() == Dock::Position::Bottom) {
|
||||
size.setWidth(
|
||||
size.width()
|
||||
+ SpliterSize
|
||||
+ TraySpace
|
||||
);
|
||||
size.setHeight(height());
|
||||
} else {
|
||||
size.setWidth(width());
|
||||
size.setHeight(
|
||||
size.height()
|
||||
+ SpliterSize
|
||||
+ TraySpace
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void HoldContainer::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const QSize &mSize = event->size();
|
||||
const Dock::Position dockPosition = trayPlugin()->dockPosition();
|
||||
|
||||
if (dockPosition == Dock::Position::Top || dockPosition == Dock::Position::Bottom) {
|
||||
m_holdSpliter->setFixedSize(SpliterSize, mSize.height() * 0.3);
|
||||
} else{
|
||||
m_holdSpliter->setFixedSize(mSize.width() * 0.3, SpliterSize);
|
||||
}
|
||||
|
||||
AbstractContainer::resizeEvent(event);
|
||||
}
|
||||
|
@ -1,17 +1,28 @@
|
||||
#ifndef HOLDCONTAINER_H
|
||||
#define HOLDCONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "abstractcontainer.h"
|
||||
|
||||
class HoldContainer : public QWidget
|
||||
class HoldContainer : public AbstractContainer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HoldContainer(QWidget *parent = nullptr);
|
||||
explicit HoldContainer(TrayPlugin *trayPlugin, QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
public:
|
||||
bool acceptWrapper(FashionTrayWidgetWrapper *wrapper) Q_DECL_OVERRIDE;
|
||||
void addWrapper(FashionTrayWidgetWrapper *wrapper) Q_DECL_OVERRIDE;
|
||||
void refreshVisible() Q_DECL_OVERRIDE;
|
||||
void setDockPosition(const Dock::Position pos) Q_DECL_OVERRIDE;
|
||||
void setExpand(const bool expand) Q_DECL_OVERRIDE;
|
||||
QSize totalSize() const Q_DECL_OVERRIDE;
|
||||
|
||||
public slots:
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QBoxLayout *m_mainBoxLayout;
|
||||
QLabel *m_holdSpliter;
|
||||
};
|
||||
|
||||
#endif // HOLDCONTAINER_H
|
||||
#endif // HOLDCONTAINER_H
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "normalcontainer.h"
|
||||
#include "../fashiontrayconstants.h"
|
||||
|
||||
NormalContainer::NormalContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
: AbstractContainer(trayPlugin, parent)
|
||||
@ -13,6 +14,16 @@ bool NormalContainer::acceptWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
return true;
|
||||
}
|
||||
|
||||
void NormalContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
AbstractContainer::addWrapper(wrapper);
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
trayPlugin()->saveValue(wrapper->itemKey(), key, false);
|
||||
}
|
||||
}
|
||||
|
||||
void NormalContainer::refreshVisible()
|
||||
{
|
||||
setVisible(expand() && !isEmpty());
|
||||
|
@ -12,6 +12,7 @@ public:
|
||||
// AbstractContainer interface
|
||||
public:
|
||||
bool acceptWrapper(FashionTrayWidgetWrapper *wrapper) Q_DECL_OVERRIDE;
|
||||
void addWrapper(FashionTrayWidgetWrapper *wrapper) Q_DECL_OVERRIDE;
|
||||
void refreshVisible() Q_DECL_OVERRIDE;
|
||||
void setExpand(const bool expand) Q_DECL_OVERRIDE;
|
||||
|
||||
|
@ -8,6 +8,9 @@ namespace Dock {
|
||||
#define TrayWidgetWidthMin 24
|
||||
#define TrayWidgetHeightMin 24
|
||||
|
||||
|
||||
#define HoldKeySuffix "-holded"
|
||||
|
||||
}
|
||||
|
||||
#endif // FASHIONTRAYCONSTANTS_H
|
||||
|
@ -41,7 +41,8 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_controlWidget(new FashionTrayControlWidget(trayPlugin->dockPosition())),
|
||||
m_currentDraggingTray(nullptr),
|
||||
m_normalContainer(new NormalContainer(m_trayPlugin)),
|
||||
m_attentionContainer(new AttentionContainer(m_trayPlugin))
|
||||
m_attentionContainer(new AttentionContainer(m_trayPlugin)),
|
||||
m_holdContainer(new HoldContainer(m_trayPlugin))
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
|
||||
@ -49,8 +50,10 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
m_rightSpliter->setStyleSheet("background-color: rgba(255, 255, 255, 0.1);");
|
||||
|
||||
m_controlWidget->setFixedSize(QSize(TrayWidgetWidth, TrayWidgetHeight));
|
||||
|
||||
m_normalContainer->setVisible(false);
|
||||
m_attentionContainer->setVisible(false);
|
||||
m_holdContainer->setVisible(false);
|
||||
|
||||
m_mainBoxLayout->setMargin(0);
|
||||
m_mainBoxLayout->setContentsMargins(0, 0, 0, 0);
|
||||
@ -58,15 +61,13 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
|
||||
m_mainBoxLayout->addWidget(m_leftSpliter);
|
||||
m_mainBoxLayout->addWidget(m_normalContainer);
|
||||
m_mainBoxLayout->addWidget(m_holdContainer);
|
||||
m_mainBoxLayout->addWidget(m_controlWidget);
|
||||
m_mainBoxLayout->addWidget(m_attentionContainer);
|
||||
m_mainBoxLayout->addWidget(m_rightSpliter);
|
||||
|
||||
m_mainBoxLayout->setAlignment(Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(m_leftSpliter, Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(m_normalContainer, Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(m_controlWidget, Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(m_attentionContainer, Qt::AlignCenter);
|
||||
m_mainBoxLayout->setAlignment(m_rightSpliter, Qt::AlignCenter);
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
@ -78,6 +79,8 @@ FashionTrayItem::FashionTrayItem(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
connect(m_controlWidget, &FashionTrayControlWidget::expandChanged, this, &FashionTrayItem::onExpandChanged);
|
||||
connect(m_normalContainer, &NormalContainer::attentionChanged, this, &FashionTrayItem::onWrapperAttentionChanged);
|
||||
connect(m_attentionContainer, &NormalContainer::attentionChanged, this, &FashionTrayItem::onWrapperAttentionChanged);
|
||||
connect(m_normalContainer, &NormalContainer::requestDraggingWrapper, this, &FashionTrayItem::onRequireDraggingWrapper);
|
||||
connect(m_holdContainer, &NormalContainer::requestDraggingWrapper, this, &FashionTrayItem::onRequireDraggingWrapper);
|
||||
|
||||
// do not call init immediately the TrayPlugin has not be constructed for now
|
||||
QTimer::singleShot(0, this, &FashionTrayItem::init);
|
||||
@ -102,6 +105,10 @@ void FashionTrayItem::trayWidgetAdded(const QString &itemKey, AbstractTrayWidget
|
||||
FashionTrayWidgetWrapper *wrapper = new FashionTrayWidgetWrapper(itemKey, trayWidget);
|
||||
|
||||
do {
|
||||
if (m_holdContainer->acceptWrapper(wrapper)) {
|
||||
m_holdContainer->addWrapper(wrapper);
|
||||
break;
|
||||
}
|
||||
if (m_normalContainer->acceptWrapper(wrapper)) {
|
||||
m_normalContainer->addWrapper(wrapper);
|
||||
break;
|
||||
@ -124,6 +131,10 @@ void FashionTrayItem::trayWidgetRemoved(AbstractTrayWidget *trayWidget)
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
if (m_holdContainer->removeWrapperByTrayWidget(trayWidget)) {
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
if (!deleted) {
|
||||
@ -137,6 +148,7 @@ void FashionTrayItem::clearTrayWidgets()
|
||||
{
|
||||
m_normalContainer->clearWrapper();
|
||||
m_attentionContainer->clearWrapper();
|
||||
m_holdContainer->clearWrapper();
|
||||
|
||||
requestResize();
|
||||
}
|
||||
@ -148,6 +160,7 @@ void FashionTrayItem::setDockPosition(Dock::Position pos)
|
||||
|
||||
m_normalContainer->setDockPosition(pos);
|
||||
m_attentionContainer->setDockPosition(pos);
|
||||
m_holdContainer->setDockPosition(pos);
|
||||
|
||||
if (pos == Dock::Position::Top || pos == Dock::Position::Bottom) {
|
||||
m_mainBoxLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
@ -160,7 +173,7 @@ void FashionTrayItem::setDockPosition(Dock::Position pos)
|
||||
|
||||
void FashionTrayItem::onExpandChanged(const bool expand)
|
||||
{
|
||||
m_trayPlugin->saveValue(ExpandedKey, expand);
|
||||
m_trayPlugin->saveValue(FASHION_MODE_ITEM_KEY, ExpandedKey, expand);
|
||||
|
||||
refreshHoldContainerPosition();
|
||||
|
||||
@ -180,6 +193,7 @@ void FashionTrayItem::onExpandChanged(const bool expand)
|
||||
}
|
||||
|
||||
m_attentionContainer->setExpand(expand);
|
||||
m_holdContainer->setExpand(expand);
|
||||
|
||||
m_attentionDelayTimer->start();
|
||||
|
||||
@ -210,6 +224,7 @@ void FashionTrayItem::setSuggestIconSize(QSize size)
|
||||
|
||||
m_normalContainer->setWrapperSize(newSize);
|
||||
m_attentionContainer->setWrapperSize(newSize);
|
||||
m_holdContainer->setWrapperSize(newSize);
|
||||
|
||||
requestResize();
|
||||
}
|
||||
@ -273,7 +288,7 @@ QSize FashionTrayItem::sizeHint() const
|
||||
void FashionTrayItem::init()
|
||||
{
|
||||
qDebug() << "init Fashion mode tray plugin item";
|
||||
m_controlWidget->setExpanded(m_trayPlugin->getValue(ExpandedKey, true).toBool());
|
||||
m_controlWidget->setExpanded(m_trayPlugin->getValue(FASHION_MODE_ITEM_KEY, ExpandedKey, true).toBool());
|
||||
setDockPosition(m_trayPlugin->dockPosition());
|
||||
onExpandChanged(m_controlWidget->expanded());
|
||||
}
|
||||
@ -290,7 +305,7 @@ QSize FashionTrayItem::wantedTotalSize() const
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
+ m_normalContainer->sizeHint().width() // 普通区域
|
||||
// + m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().width() // 活动区域
|
||||
);
|
||||
size.setHeight(height());
|
||||
@ -301,7 +316,7 @@ QSize FashionTrayItem::wantedTotalSize() const
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
+ m_normalContainer->sizeHint().height() // 普通区域
|
||||
// + m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().height() // 活动区域
|
||||
);
|
||||
}
|
||||
@ -311,7 +326,7 @@ QSize FashionTrayItem::wantedTotalSize() const
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
// + m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_holdContainer->sizeHint().width() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().width() // 活动区域
|
||||
);
|
||||
size.setHeight(height());
|
||||
@ -321,7 +336,7 @@ QSize FashionTrayItem::wantedTotalSize() const
|
||||
SpliterSize * 2 // 两个分隔条
|
||||
+ TraySpace * 2 // 两个分隔条旁边的 space
|
||||
+ TrayWidgetWidth // 控制按钮
|
||||
// + m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_holdContainer->sizeHint().height() // 保留区域
|
||||
+ m_attentionContainer->sizeHint().height() // 活动区域
|
||||
);
|
||||
}
|
||||
@ -389,8 +404,41 @@ void FashionTrayItem::requestResize()
|
||||
|
||||
void FashionTrayItem::refreshHoldContainerPosition()
|
||||
{
|
||||
// const int destIndex = m_mainBoxLayout->indexOf(m_controlWidget)
|
||||
// + (m_controlWidget->expanded() ? 0 : 1);
|
||||
m_mainBoxLayout->removeWidget(m_holdContainer);
|
||||
|
||||
// m_mainBoxLayout->insertWidget(destIndex, m_holdContainer);
|
||||
int destIndex = 0;
|
||||
if (m_controlWidget->expanded()) {
|
||||
destIndex = m_mainBoxLayout->indexOf(m_controlWidget);
|
||||
} else {
|
||||
destIndex = m_mainBoxLayout->indexOf(m_attentionContainer);
|
||||
}
|
||||
|
||||
m_mainBoxLayout->insertWidget(destIndex, m_holdContainer);
|
||||
}
|
||||
|
||||
void FashionTrayItem::onRequireDraggingWrapper()
|
||||
{
|
||||
AbstractContainer *container = dynamic_cast<AbstractContainer *>(sender());
|
||||
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
|
||||
FashionTrayWidgetWrapper *draggingWrapper = nullptr;
|
||||
do {
|
||||
draggingWrapper = m_normalContainer->takeDraggingWrapper();
|
||||
if (draggingWrapper) {
|
||||
break;
|
||||
}
|
||||
draggingWrapper = m_holdContainer->takeDraggingWrapper();
|
||||
if (draggingWrapper) {
|
||||
break;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
if (!draggingWrapper) {
|
||||
return;
|
||||
}
|
||||
|
||||
container->addDraggingWrapper(draggingWrapper);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "fashiontraycontrolwidget.h"
|
||||
#include "containers/normalcontainer.h"
|
||||
#include "containers/attentioncontainer.h"
|
||||
#include "containers/holdcontainer.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
@ -36,6 +37,8 @@
|
||||
|
||||
#include <abstracttraywidget.h>
|
||||
|
||||
#define FASHION_MODE_ITEM_KEY "fashion-mode-item"
|
||||
|
||||
class FashionTrayItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -75,6 +78,7 @@ private Q_SLOTS:
|
||||
void normalWrapperToAttentionWrapper(FashionTrayWidgetWrapper *wrapper);
|
||||
void requestResize();
|
||||
void refreshHoldContainerPosition();
|
||||
void onRequireDraggingWrapper();
|
||||
|
||||
private:
|
||||
QBoxLayout *m_mainBoxLayout;
|
||||
@ -88,6 +92,7 @@ private:
|
||||
|
||||
NormalContainer *m_normalContainer;
|
||||
AttentionContainer *m_attentionContainer;
|
||||
HoldContainer *m_holdContainer;
|
||||
|
||||
static int TrayWidgetWidth;
|
||||
static int TrayWidgetHeight;
|
||||
|
@ -266,3 +266,25 @@ void SystemTraysController::setSystemTrayItemSortKey(const QString &itemKey, con
|
||||
|
||||
inter->setSortKey(itemKey, order);
|
||||
}
|
||||
|
||||
const QVariant SystemTraysController::getValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant &fallback)
|
||||
{
|
||||
auto inter = pluginInterAt(itemKey);
|
||||
|
||||
if (!inter) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return getValue(inter, key, fallback);
|
||||
}
|
||||
|
||||
void SystemTraysController::saveValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant &value)
|
||||
{
|
||||
auto inter = pluginInterAt(itemKey);
|
||||
|
||||
if (!inter) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveValue(inter, key, value);
|
||||
}
|
||||
|
@ -46,11 +46,14 @@ public:
|
||||
void requestWindowAutoHide(PluginsItemInterface * const itemInter, const QString &itemKey, const bool autoHide) Q_DECL_OVERRIDE;
|
||||
void requestRefreshWindowVisible(PluginsItemInterface * const itemInter, const QString &itemKey) Q_DECL_OVERRIDE;
|
||||
void saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value) Q_DECL_OVERRIDE;
|
||||
const QVariant getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& failback = QVariant()) Q_DECL_OVERRIDE;
|
||||
const QVariant getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& fallback = QVariant()) Q_DECL_OVERRIDE;
|
||||
|
||||
int systemTrayItemSortKey(const QString &itemKey);
|
||||
void setSystemTrayItemSortKey(const QString &itemKey, const int order);
|
||||
|
||||
const QVariant getValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant& fallback = QVariant());
|
||||
void saveValueSystemTrayItem(const QString &itemKey, const QString &key, const QVariant &value);
|
||||
|
||||
public slots:
|
||||
void startLoader();
|
||||
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "xcb/xcb_icccm.h"
|
||||
|
||||
#define FASHION_MODE_ITEM "fashion-mode-item"
|
||||
#define FASHION_MODE_TRAYS_SORTED "fashion-mode-trays-sorted"
|
||||
|
||||
#define SNI_WATCHER_SERVICE "org.kde.StatusNotifierWatcher"
|
||||
@ -130,7 +129,7 @@ void TrayPlugin::positionChanged(const Dock::Position position)
|
||||
|
||||
QWidget *TrayPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
if (itemKey == FASHION_MODE_ITEM) {
|
||||
if (itemKey == FASHION_MODE_ITEM_KEY) {
|
||||
return m_fashionItem;
|
||||
}
|
||||
|
||||
@ -209,7 +208,7 @@ void TrayPlugin::setItemIsInContainer(const QString &itemKey, const bool contain
|
||||
|
||||
void TrayPlugin::refreshIcon(const QString &itemKey)
|
||||
{
|
||||
if (itemKey == FASHION_MODE_ITEM) {
|
||||
if (itemKey == FASHION_MODE_ITEM_KEY) {
|
||||
for (auto trayWidget : m_trayMap.values()) {
|
||||
if (trayWidget) {
|
||||
trayWidget->updateIcon();
|
||||
@ -234,13 +233,23 @@ bool TrayPlugin::traysSortedInFashionMode()
|
||||
return m_proxyInter->getValue(this, FASHION_MODE_TRAYS_SORTED, false).toBool();
|
||||
}
|
||||
|
||||
void TrayPlugin::saveValue(const QString &key, const QVariant &value)
|
||||
void TrayPlugin::saveValue(const QString &itemKey, const QString &key, const QVariant &value)
|
||||
{
|
||||
// 如果是系统托盘图标则调用内部插件的相应接口
|
||||
if (isSystemTrayItem(itemKey)) {
|
||||
return m_systemTraysController->saveValueSystemTrayItem(itemKey, key, value);
|
||||
}
|
||||
|
||||
m_proxyInter->saveValue(this, key, value);
|
||||
}
|
||||
|
||||
const QVariant TrayPlugin::getValue(const QString &key, const QVariant &fallback)
|
||||
const QVariant TrayPlugin::getValue(const QString &itemKey, const QString &key, const QVariant &fallback)
|
||||
{
|
||||
// 如果是系统托盘图标则调用内部插件的相应接口
|
||||
if (isSystemTrayItem(itemKey)) {
|
||||
return m_systemTraysController->getValueSystemTrayItem(itemKey, key, fallback);
|
||||
}
|
||||
|
||||
return m_proxyInter->getValue(this, key, fallback);
|
||||
}
|
||||
|
||||
@ -281,7 +290,7 @@ QString TrayPlugin::itemKeyOfTrayWidget(AbstractTrayWidget *trayWidget)
|
||||
QString itemKey;
|
||||
|
||||
if (displayMode() == Dock::DisplayMode::Fashion) {
|
||||
itemKey = FASHION_MODE_ITEM;
|
||||
itemKey = FASHION_MODE_ITEM_KEY;
|
||||
} else {
|
||||
itemKey = m_trayMap.key(trayWidget);
|
||||
}
|
||||
@ -339,7 +348,7 @@ void TrayPlugin::addTrayWidget(const QString &itemKey, AbstractTrayWidget *trayW
|
||||
if (displayMode() == Dock::Efficient) {
|
||||
m_proxyInter->itemAdded(this, itemKey);
|
||||
} else {
|
||||
m_proxyInter->itemAdded(this, FASHION_MODE_ITEM);
|
||||
m_proxyInter->itemAdded(this, FASHION_MODE_ITEM_KEY);
|
||||
m_fashionItem->trayWidgetAdded(itemKey, trayWidget);
|
||||
}
|
||||
|
||||
@ -435,14 +444,14 @@ void TrayPlugin::switchToMode(const Dock::DisplayMode mode)
|
||||
m_proxyInter->itemRemoved(this, itemKey);
|
||||
}
|
||||
if (m_trayMap.isEmpty()) {
|
||||
m_proxyInter->itemRemoved(this, FASHION_MODE_ITEM);
|
||||
m_proxyInter->itemRemoved(this, FASHION_MODE_ITEM_KEY);
|
||||
} else {
|
||||
m_fashionItem->setTrayWidgets(m_trayMap);
|
||||
m_proxyInter->itemAdded(this, FASHION_MODE_ITEM);
|
||||
m_proxyInter->itemAdded(this, FASHION_MODE_ITEM_KEY);
|
||||
}
|
||||
} else {
|
||||
m_fashionItem->clearTrayWidgets();
|
||||
m_proxyInter->itemRemoved(this, FASHION_MODE_ITEM);
|
||||
m_proxyInter->itemRemoved(this, FASHION_MODE_ITEM_KEY);
|
||||
for (auto itemKey : m_trayMap.keys()) {
|
||||
m_proxyInter->itemAdded(this, itemKey);
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ public:
|
||||
|
||||
Dock::Position dockPosition() const;
|
||||
bool traysSortedInFashionMode();
|
||||
void saveValue(const QString &key, const QVariant &value);
|
||||
const QVariant getValue(const QString &key, const QVariant& fallback = QVariant());
|
||||
void saveValue(const QString &itemKey, const QString &key, const QVariant &value);
|
||||
const QVariant getValue(const QString &itemKey, const QString &key, const QVariant& fallback = QVariant());
|
||||
|
||||
private:
|
||||
void loadIndicator();
|
||||
|
Loading…
x
Reference in New Issue
Block a user