mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
refactoring, multiple changes included
Changes: 1,make spacing item add or remove smoothly 2,reconstruct Panel 3,make dock more stable on crazy drag-out or drag-in Change-Id: I78a9ded502ffb352d187cbc0b835a16e7f9bfd37
This commit is contained in:
parent
a1dbbe2876
commit
814cff724b
Notes:
Deepin Code Review
2016-06-14 07:19:47 +00:00
Code-Review+2: <mr.asianwang@gmail.com> Verified+1: Anonymous Coward #1000004 Submitted-by: <yangwanqing@linuxdeepin.com> Submitted-at: Fri, 28 Aug 2015 09:00:54 +0800 Reviewed-on: https://cr.deepin.io/6646 Project: dde/dde-dock Branch: refs/heads/master
@ -9,47 +9,19 @@ Panel::Panel(QWidget *parent)
|
||||
{
|
||||
setObjectName("Panel");
|
||||
|
||||
m_pluginLayout = new DockLayout(this);
|
||||
m_pluginLayout->setSpacing(m_dockModeData->getAppletsItemSpacing());
|
||||
m_pluginLayout->resize(0,m_dockModeData->getItemHeight());
|
||||
|
||||
m_appLayout = new DockLayout(this);
|
||||
m_appLayout->setAcceptDrops(true);
|
||||
m_appLayout->setSpacing(m_dockModeData->getAppItemSpacing());
|
||||
m_appLayout->resize(this->width() - m_pluginLayout->width(),m_dockModeData->getItemHeight());
|
||||
m_appLayout->move(0,1);
|
||||
|
||||
connect(m_appLayout, &DockLayout::startDrag, this, &Panel::slotDragStarted);
|
||||
connect(m_appLayout, &DockLayout::itemDropped, this, &Panel::slotItemDropped);
|
||||
connect(m_appLayout, &DockLayout::contentsWidthChange, this, &Panel::slotLayoutContentsWidthChanged);
|
||||
|
||||
connect(m_pluginLayout, &DockLayout::contentsWidthChange, this, &Panel::slotLayoutContentsWidthChanged);
|
||||
|
||||
connect(m_dockModeData, &DockModeData::dockModeChanged, this, &Panel::changeDockMode);
|
||||
|
||||
initAppManager();
|
||||
initShowHideAnimation();
|
||||
initHideStateManager();
|
||||
initWidthAnimation();
|
||||
initPluginLayout();
|
||||
initAppLayout();
|
||||
initPluginManager();
|
||||
initHSManager();
|
||||
initState();
|
||||
initAppManager();
|
||||
initReflection();
|
||||
initScreenMask();
|
||||
|
||||
updateBackground();
|
||||
}
|
||||
reloadStyleSheet();
|
||||
|
||||
void Panel::showScreenMask()
|
||||
{
|
||||
m_maskWidget->show();
|
||||
}
|
||||
|
||||
bool Panel::isFashionMode()
|
||||
{
|
||||
return m_isFashionMode;
|
||||
}
|
||||
|
||||
void Panel::hideScreenMask()
|
||||
{
|
||||
m_maskWidget->hide();
|
||||
connect(m_dockModeData, &DockModeData::dockModeChanged, this, &Panel::onDockModeChanged);
|
||||
}
|
||||
|
||||
void Panel::setContainMouse(bool value)
|
||||
@ -57,115 +29,67 @@ void Panel::setContainMouse(bool value)
|
||||
m_containMouse = value;
|
||||
}
|
||||
|
||||
void Panel::slotDragStarted()
|
||||
bool Panel::isFashionMode()
|
||||
{
|
||||
showScreenMask();
|
||||
}
|
||||
|
||||
void Panel::slotItemDropped()
|
||||
{
|
||||
hideScreenMask();
|
||||
m_appLayout->clearTmpItem();
|
||||
m_appLayout->relayout();
|
||||
}
|
||||
|
||||
void Panel::slotEnteredMask()
|
||||
{
|
||||
m_appLayout->relayout();
|
||||
}
|
||||
|
||||
void Panel::slotExitedMask()
|
||||
{
|
||||
m_appLayout->relayout();
|
||||
}
|
||||
|
||||
void Panel::changeDockMode(Dock::DockMode newMode, Dock::DockMode oldMode)
|
||||
{
|
||||
updateBackground();
|
||||
|
||||
m_appLayout->relayout();
|
||||
m_pluginLayout->relayout();
|
||||
|
||||
reanchorsLayout(newMode);
|
||||
}
|
||||
|
||||
void Panel::slotLayoutContentsWidthChanged()
|
||||
{
|
||||
reanchorsLayout(m_dockModeData->getDockMode());
|
||||
}
|
||||
|
||||
void Panel::slotAddAppItem(AbstractDockItem *item)
|
||||
{
|
||||
m_appLayout->addItem(item);
|
||||
}
|
||||
|
||||
void Panel::slotRemoveAppItem(const QString &id)
|
||||
{
|
||||
QList<AbstractDockItem *> tmpList = m_appLayout->getItemList();
|
||||
for (int i = 0; i < tmpList.count(); i ++)
|
||||
{
|
||||
AppItem *tmpItem = qobject_cast<AppItem *>(tmpList.at(i));
|
||||
if (tmpItem && tmpItem->getItemId() == id)
|
||||
{
|
||||
m_appLayout->removeItem(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return m_isFashionMode;
|
||||
}
|
||||
|
||||
void Panel::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton)
|
||||
showMenu();
|
||||
showPanelMenu();
|
||||
}
|
||||
|
||||
void Panel::mouseReleaseEvent(QMouseEvent *event)
|
||||
void Panel::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Panel::reanchorsLayout(Dock::DockMode mode)
|
||||
void Panel::initShowHideAnimation()
|
||||
{
|
||||
if (mode == Dock::FashionMode)
|
||||
{
|
||||
m_appLayout->resize(m_appLayout->getContentsWidth() + m_dockModeData->getAppItemSpacing(),m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(),m_dockModeData->getAppletsItemHeight());
|
||||
this->setFixedSize(FASHION_PANEL_LPADDING
|
||||
+ FASHION_PANEL_RPADDING
|
||||
+ m_appLayout->getContentsWidth()
|
||||
+ m_pluginLayout->getContentsWidth()
|
||||
,m_dockModeData->getDockHeight());
|
||||
m_appLayout->move(FASHION_PANEL_LPADDING,1);
|
||||
QStateMachine * machine = new QStateMachine(this);
|
||||
QState * showState = new QState(machine);
|
||||
showState->assignProperty(this,"y", 0);
|
||||
QState * hideState = new QState(machine);
|
||||
hideState->assignProperty(this,"y", height());
|
||||
machine->setInitialState(showState);
|
||||
|
||||
QPropertyAnimation *showAnimation = new QPropertyAnimation(this, "y");
|
||||
showAnimation->setDuration(SHOW_HIDE_ANIMATION_DURATION);
|
||||
showAnimation->setEasingCurve(SHOW_HIDE_EASINGCURVE);
|
||||
connect(showAnimation,&QPropertyAnimation::finished,this,&Panel::onShowPanelFinished);
|
||||
QPropertyAnimation *hideAnimation = new QPropertyAnimation(this, "y");
|
||||
hideAnimation->setDuration(SHOW_HIDE_ANIMATION_DURATION);
|
||||
hideAnimation->setEasingCurve(SHOW_HIDE_EASINGCURVE);
|
||||
connect(hideAnimation,&QPropertyAnimation::finished,this,&Panel::onHidePanelFinished);
|
||||
|
||||
QSignalTransition *ts1 = showState->addTransition(this,SIGNAL(startHide()), hideState);
|
||||
ts1->addAnimation(hideAnimation);
|
||||
connect(ts1,&QSignalTransition::triggered,[=]{m_HSManager->SetState(2);});
|
||||
QSignalTransition *ts2 = hideState->addTransition(this,SIGNAL(startShow()),showState);
|
||||
ts2->addAnimation(showAnimation);
|
||||
connect(ts2,&QSignalTransition::triggered,[=]{m_HSManager->SetState(0);});
|
||||
|
||||
machine->start();
|
||||
}
|
||||
|
||||
void Panel::initHideStateManager()
|
||||
{
|
||||
m_HSManager = new DBusHideStateManager(this);
|
||||
connect(m_HSManager,&DBusHideStateManager::ChangeState,this,&Panel::onHideStateChanged);
|
||||
}
|
||||
|
||||
void Panel::initWidthAnimation()
|
||||
{
|
||||
m_widthAnimation = new QPropertyAnimation(this, "width", this);
|
||||
m_widthAnimation->setDuration(WIDTH_ANIMATION_DURATION);
|
||||
connect(m_widthAnimation, &QPropertyAnimation::valueChanged, [=]{
|
||||
m_appLayout->move(FASHION_PANEL_LPADDING, 1);
|
||||
m_pluginLayout->move(width() - m_pluginLayout->width() - FASHION_PANEL_RPADDING, 1);
|
||||
updateRightReflection();
|
||||
|
||||
m_pluginLayout->move(m_appLayout->x() + m_appLayout->width() - m_dockModeData->getAppItemSpacing(),1);
|
||||
this->move((m_parentWidget->width() - width()) / 2,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(),m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->move(m_parentWidget->width() - m_pluginLayout->width(),1);
|
||||
|
||||
m_appLayout->move(0,1);
|
||||
m_appLayout->resize(m_parentWidget->width() - m_pluginLayout->width() ,m_dockModeData->getItemHeight());
|
||||
|
||||
this->setFixedSize(m_appLayout->width() + m_pluginLayout->width(),m_dockModeData->getDockHeight());
|
||||
this->move((m_parentWidget->width() - m_appLayout->width() - m_pluginLayout->width()) / 2,0);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::showMenu()
|
||||
{
|
||||
QPoint tmpPos = QCursor::pos();
|
||||
|
||||
PanelMenu::instance()->showMenu(tmpPos.x(),tmpPos.y());
|
||||
}
|
||||
|
||||
void Panel::updateBackground()
|
||||
{
|
||||
m_isFashionMode = m_dockModeData->getDockMode() == Dock::FashionMode;
|
||||
|
||||
style()->unpolish(this);
|
||||
style()->polish(this);// force a stylesheet recomputation
|
||||
});
|
||||
}
|
||||
|
||||
void Panel::initPluginManager()
|
||||
@ -187,72 +111,34 @@ void Panel::initPluginManager()
|
||||
pluginManager->initAll();
|
||||
}
|
||||
|
||||
void Panel::initPluginLayout()
|
||||
{
|
||||
m_pluginLayout = new DockLayout(this);
|
||||
m_pluginLayout->setSpacing(m_dockModeData->getAppletsItemSpacing());
|
||||
m_pluginLayout->resize(0, m_dockModeData->getItemHeight());
|
||||
connect(m_pluginLayout, &DockLayout::contentsWidthChange, this, &Panel::onLayoutContentsWidthChanged);
|
||||
}
|
||||
|
||||
void Panel::initAppLayout()
|
||||
{
|
||||
m_appLayout = new DockLayout(this);
|
||||
m_appLayout->setAcceptDrops(true);
|
||||
m_appLayout->setSpacing(m_dockModeData->getAppItemSpacing());
|
||||
m_appLayout->move(0, 1);
|
||||
|
||||
connect(m_appLayout, &DockLayout::startDrag, this, &Panel::onItemDragStarted);
|
||||
connect(m_appLayout, &DockLayout::itemDropped, this, &Panel::onItemDropped);
|
||||
connect(m_appLayout, &DockLayout::contentsWidthChange, this, &Panel::onLayoutContentsWidthChanged);
|
||||
}
|
||||
|
||||
void Panel::initAppManager()
|
||||
{
|
||||
m_appManager = new AppManager(this);
|
||||
connect(m_appManager,SIGNAL(entryAdded(AbstractDockItem*)),this, SLOT(slotAddAppItem(AbstractDockItem*)));
|
||||
connect(m_appManager, SIGNAL(entryRemoved(QString)),this, SLOT(slotRemoveAppItem(QString)));
|
||||
connect(m_appManager, &AppManager::entryAdded, this, &Panel::onAppItemAdd);
|
||||
connect(m_appManager, &AppManager::entryRemoved, this, &Panel::onAppItemRemove);
|
||||
m_appManager->updateEntries();
|
||||
}
|
||||
|
||||
void Panel::hasShown()
|
||||
{
|
||||
m_HSManager->SetState(1);
|
||||
emit panelHasShown();
|
||||
}
|
||||
|
||||
void Panel::hasHidden()
|
||||
{
|
||||
m_HSManager->SetState(3);
|
||||
emit panelHasHidden();
|
||||
}
|
||||
|
||||
void Panel::hideStateChanged(int value)
|
||||
{
|
||||
if (value == 0)
|
||||
emit startShow();
|
||||
else if (value == 1 && !m_containMouse)
|
||||
emit startHide();
|
||||
}
|
||||
|
||||
void Panel::initHSManager()
|
||||
{
|
||||
m_HSManager = new DBusHideStateManager(this);
|
||||
connect(m_HSManager,&DBusHideStateManager::ChangeState,this,&Panel::hideStateChanged);
|
||||
}
|
||||
|
||||
void Panel::initState()
|
||||
{
|
||||
QStateMachine * machine = new QStateMachine(this);
|
||||
QState * showState = new QState(machine);
|
||||
showState->assignProperty(this,"y", 0);
|
||||
QState * hideState = new QState(machine);
|
||||
hideState->assignProperty(this,"y", height());
|
||||
machine->setInitialState(showState);
|
||||
|
||||
QPropertyAnimation *sa = new QPropertyAnimation(this, "y");
|
||||
sa->setDuration(SHOW_HIDE_DURATION);
|
||||
sa->setEasingCurve(SHOW_HIDE_EASINGCURVE);
|
||||
connect(sa,&QPropertyAnimation::finished,this,&Panel::hasShown);
|
||||
QPropertyAnimation *ha = new QPropertyAnimation(this, "y");
|
||||
ha->setDuration(SHOW_HIDE_DURATION);
|
||||
ha->setEasingCurve(SHOW_HIDE_EASINGCURVE);
|
||||
connect(ha,&QPropertyAnimation::finished,this,&Panel::hasHidden);
|
||||
|
||||
QSignalTransition *ts1 = showState->addTransition(this,SIGNAL(startHide()), hideState);
|
||||
ts1->addAnimation(ha);
|
||||
connect(ts1,&QSignalTransition::triggered,[=]{
|
||||
m_HSManager->SetState(2);
|
||||
});
|
||||
QSignalTransition *ts2 = hideState->addTransition(this,SIGNAL(startShow()),showState);
|
||||
ts2->addAnimation(sa);
|
||||
connect(ts2,&QSignalTransition::triggered,[=]{
|
||||
m_HSManager->SetState(0);
|
||||
});
|
||||
|
||||
machine->start();
|
||||
}
|
||||
|
||||
void Panel::initReflection()
|
||||
{
|
||||
if (m_appLayout)
|
||||
@ -277,14 +163,149 @@ void Panel::initScreenMask()
|
||||
{
|
||||
m_maskWidget = new ScreenMask();
|
||||
m_maskWidget->hide();
|
||||
connect(m_maskWidget,SIGNAL(itemDropped(QPoint)),this,SLOT(slotItemDropped()));
|
||||
connect(m_maskWidget,SIGNAL(itemEntered()),this,SLOT(slotEnteredMask()));
|
||||
connect(m_maskWidget,SIGNAL(itemExited()),this,SLOT(slotExitedMask()));
|
||||
connect(m_maskWidget, &ScreenMask::itemDropped, this, &Panel::onItemDropped);
|
||||
connect(m_maskWidget, &ScreenMask::itemEntered, m_appLayout, &DockLayout::removeSpacingItem);
|
||||
connect(m_maskWidget, &ScreenMask::itemMissing, m_appLayout, &DockLayout::restoreTmpItem);
|
||||
}
|
||||
|
||||
void Panel::onItemDropped()
|
||||
{
|
||||
m_maskWidget->hide();
|
||||
m_appLayout->clearTmpItem();
|
||||
m_appLayout->relayout();
|
||||
}
|
||||
|
||||
void Panel::onItemDragStarted()
|
||||
{
|
||||
m_maskWidget->show();
|
||||
}
|
||||
|
||||
void Panel::onLayoutContentsWidthChanged()
|
||||
{
|
||||
if (m_dockModeData->getDockMode() == Dock::FashionMode)
|
||||
{
|
||||
m_appLayout->resize(m_appLayout->getContentsWidth() + m_dockModeData->getAppItemSpacing(),m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(),m_dockModeData->getAppletsItemHeight());
|
||||
|
||||
int targetWidth = FASHION_PANEL_LPADDING
|
||||
+ FASHION_PANEL_RPADDING
|
||||
+ m_appLayout->getContentsWidth()
|
||||
+ m_pluginLayout->getContentsWidth();
|
||||
|
||||
m_widthAnimation->setStartValue(width());
|
||||
m_widthAnimation->setEndValue(targetWidth);
|
||||
m_widthAnimation->start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(),m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->move(m_parentWidget->width() - m_pluginLayout->width(),1);
|
||||
|
||||
m_appLayout->move(0,1);
|
||||
m_appLayout->resize(m_parentWidget->width() - m_pluginLayout->width() ,m_dockModeData->getItemHeight());
|
||||
|
||||
this->setFixedSize(m_appLayout->width() + m_pluginLayout->width(),m_dockModeData->getDockHeight());
|
||||
this->move((m_parentWidget->width() - m_appLayout->width() - m_pluginLayout->width()) / 2,0);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::onAppItemAdd(AbstractDockItem *item)
|
||||
{
|
||||
m_appLayout->addItem(item);
|
||||
}
|
||||
|
||||
void Panel::onAppItemRemove(const QString &id)
|
||||
{
|
||||
QList<AbstractDockItem *> tmpList = m_appLayout->getItemList();
|
||||
for (int i = 0; i < tmpList.count(); i ++)
|
||||
{
|
||||
AppItem *tmpItem = qobject_cast<AppItem *>(tmpList.at(i));
|
||||
if (tmpItem && tmpItem->getItemId() == id)
|
||||
{
|
||||
m_appLayout->removeItem(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::onDockModeChanged(Dock::DockMode newMode, Dock::DockMode)
|
||||
{
|
||||
m_appLayout->relayout();
|
||||
m_pluginLayout->relayout();
|
||||
|
||||
reanchorsLayout(newMode);
|
||||
|
||||
reloadStyleSheet();
|
||||
}
|
||||
|
||||
void Panel::onHideStateChanged(int dockState)
|
||||
{
|
||||
if (dockState == 0)
|
||||
emit startShow();
|
||||
else if (dockState == 1 && !m_containMouse)
|
||||
emit startHide();
|
||||
}
|
||||
|
||||
void Panel::onShowPanelFinished()
|
||||
{
|
||||
m_HSManager->SetState(1);
|
||||
emit panelHasShown();
|
||||
}
|
||||
|
||||
void Panel::onHidePanelFinished()
|
||||
{
|
||||
m_HSManager->SetState(3);
|
||||
emit panelHasHidden();
|
||||
}
|
||||
|
||||
void Panel::reanchorsLayout(Dock::DockMode mode)
|
||||
{
|
||||
if (mode == Dock::FashionMode)
|
||||
{
|
||||
m_appLayout->resize(m_appLayout->getContentsWidth() + m_dockModeData->getAppItemSpacing(),m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(),m_dockModeData->getAppletsItemHeight());
|
||||
this->setFixedSize(FASHION_PANEL_LPADDING
|
||||
+ FASHION_PANEL_RPADDING
|
||||
+ m_appLayout->getContentsWidth()
|
||||
+ m_pluginLayout->getContentsWidth()
|
||||
,m_dockModeData->getDockHeight());
|
||||
m_appLayout->move(FASHION_PANEL_LPADDING,1);
|
||||
|
||||
m_pluginLayout->move(m_appLayout->x() + m_appLayout->width() - m_dockModeData->getAppItemSpacing(),1);
|
||||
this->move((m_parentWidget->width() - width()) / 2,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pluginLayout->resize(m_pluginLayout->getContentsWidth(), m_dockModeData->getItemHeight());
|
||||
m_pluginLayout->move(m_parentWidget->width() - m_pluginLayout->width(),1);
|
||||
|
||||
m_appLayout->move(0,1);
|
||||
m_appLayout->resize(m_parentWidget->width() - m_pluginLayout->width() ,m_dockModeData->getItemHeight());
|
||||
|
||||
this->setFixedSize(m_appLayout->width() + m_pluginLayout->width(), m_dockModeData->getDockHeight());
|
||||
this->move((m_parentWidget->width() - m_appLayout->width() - m_pluginLayout->width()) / 2,0);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::updateRightReflection()
|
||||
{
|
||||
if (!m_pluginReflection)
|
||||
return;
|
||||
if (m_dockModeData->getDockMode() == Dock::FashionMode)
|
||||
{
|
||||
m_pluginReflection->setFixedSize(m_pluginLayout->width(), REFLECTION_HEIGHT);
|
||||
m_pluginReflection->move(m_pluginLayout->x(), m_pluginLayout->y() + m_pluginLayout->height());
|
||||
m_pluginReflection->updateReflection();
|
||||
}
|
||||
else
|
||||
m_pluginReflection->setFixedSize(m_pluginLayout->width(), 0);
|
||||
}
|
||||
|
||||
void Panel::updateLeftReflection()
|
||||
{
|
||||
if (!m_appReflection)
|
||||
return;
|
||||
if (m_dockModeData->getDockMode() == Dock::FashionMode){
|
||||
m_appReflection->setFixedSize(m_appLayout->width(), 40);
|
||||
m_appReflection->move(m_appLayout->x(), m_appLayout->y() + 25);
|
||||
@ -294,16 +315,19 @@ void Panel::updateLeftReflection()
|
||||
m_appReflection->setFixedSize(m_appLayout->width(), 0);
|
||||
}
|
||||
|
||||
void Panel::updateRightReflection()
|
||||
void Panel::reloadStyleSheet()
|
||||
{
|
||||
if (m_dockModeData->getDockMode() == Dock::FashionMode)
|
||||
{
|
||||
m_pluginReflection->setFixedSize(m_pluginLayout->width(), REFLECTION_HEIGHT);
|
||||
m_pluginReflection->move(m_pluginLayout->x(), m_pluginLayout->y() + m_pluginLayout->height());
|
||||
m_pluginReflection->updateReflection();
|
||||
}
|
||||
else
|
||||
m_pluginReflection->setFixedSize(m_pluginLayout->width(), 0);
|
||||
m_isFashionMode = m_dockModeData->getDockMode() == Dock::FashionMode;
|
||||
|
||||
style()->unpolish(this);
|
||||
style()->polish(this); // force a stylesheet recomputation
|
||||
}
|
||||
|
||||
void Panel::showPanelMenu()
|
||||
{
|
||||
QPoint tmpPos = QCursor::pos();
|
||||
|
||||
PanelMenu::instance()->showMenu(tmpPos.x(),tmpPos.y());
|
||||
}
|
||||
|
||||
void Panel::setY(int value)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "DBus/dbushidestatemanager.h"
|
||||
#include "Controller/dockmodedata.h"
|
||||
#include "Controller/appmanager.h"
|
||||
@ -20,22 +20,14 @@ class Panel : public QLabel
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int y READ y WRITE setY)
|
||||
Q_PROPERTY(bool isFashionMode READ isFashionMode)
|
||||
Q_PROPERTY(int width READ width WRITE setFixedWidth)
|
||||
|
||||
public:
|
||||
explicit Panel(QWidget *parent = 0);
|
||||
~Panel();
|
||||
|
||||
void showScreenMask();
|
||||
void hideScreenMask();
|
||||
void setContainMouse(bool value);
|
||||
|
||||
bool isFashionMode();
|
||||
|
||||
public slots:
|
||||
void slotDragStarted();
|
||||
void slotItemDropped();
|
||||
void slotEnteredMask();
|
||||
void slotExitedMask();
|
||||
void setContainMouse(bool value); //for smart-hide and keep-hide
|
||||
bool isFashionMode(); //for qss setting background
|
||||
|
||||
signals:
|
||||
void startShow();
|
||||
@ -43,52 +35,57 @@ signals:
|
||||
void panelHasShown();
|
||||
void panelHasHidden();
|
||||
|
||||
private slots:
|
||||
void slotLayoutContentsWidthChanged();
|
||||
|
||||
void slotAddAppItem(AbstractDockItem *item);
|
||||
void slotRemoveAppItem(const QString &id);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
|
||||
private:
|
||||
void changeDockMode(Dock::DockMode newMode,Dock::DockMode oldMode);
|
||||
void reanchorsLayout(Dock::DockMode mode);
|
||||
|
||||
void showMenu();
|
||||
void updateBackground();
|
||||
void initShowHideAnimation();
|
||||
void initHideStateManager();
|
||||
void initWidthAnimation();
|
||||
void initPluginManager();
|
||||
void initPluginLayout();
|
||||
void initAppLayout();
|
||||
void initAppManager();
|
||||
void hasShown();
|
||||
void hasHidden();
|
||||
void hideStateChanged(int value);
|
||||
void initHSManager();
|
||||
void initState();
|
||||
void initReflection();
|
||||
void initScreenMask();
|
||||
void updateLeftReflection();
|
||||
|
||||
void onItemDropped();
|
||||
void onItemDragStarted();
|
||||
void onLayoutContentsWidthChanged();
|
||||
void onAppItemAdd(AbstractDockItem *item);
|
||||
void onAppItemRemove(const QString &id);
|
||||
void onDockModeChanged(Dock::DockMode newMode, Dock::DockMode);
|
||||
void onHideStateChanged(int dockState);
|
||||
void onShowPanelFinished();
|
||||
void onHidePanelFinished();
|
||||
|
||||
void reanchorsLayout(Dock::DockMode mode);
|
||||
void updateRightReflection();
|
||||
void setY(int value);
|
||||
void updateLeftReflection();
|
||||
void reloadStyleSheet();
|
||||
void showPanelMenu();
|
||||
void setY(int value); //for hide and show animation
|
||||
|
||||
private:
|
||||
DockModeData *m_dockModeData = DockModeData::instance();
|
||||
QPropertyAnimation *m_widthAnimation = NULL;
|
||||
DBusHideStateManager *m_HSManager = NULL;
|
||||
DockLayout *m_appLayout = NULL;
|
||||
ReflectionEffect *m_pluginReflection = NULL;
|
||||
ReflectionEffect *m_appReflection = NULL;
|
||||
DockLayout *m_pluginLayout = NULL;
|
||||
ScreenMask * m_maskWidget = NULL;
|
||||
AppManager *m_appManager = NULL;
|
||||
QWidget *m_parentWidget = NULL;
|
||||
ScreenMask * m_maskWidget = NULL;
|
||||
DockModeData *m_dockModeData = DockModeData::instance();
|
||||
ReflectionEffect *m_appReflection = NULL;
|
||||
ReflectionEffect *m_pluginReflection = NULL;
|
||||
DockLayout *m_appLayout = NULL;
|
||||
|
||||
bool m_containMouse = false;
|
||||
bool m_isFashionMode = false;
|
||||
const int FASHION_PANEL_LPADDING = 21;
|
||||
const int FASHION_PANEL_RPADDING = 21;
|
||||
const int REFLECTION_HEIGHT = 15;
|
||||
const int SHOW_HIDE_DURATION = 200;
|
||||
const int WIDTH_ANIMATION_DURATION = 200;
|
||||
const int SHOW_HIDE_ANIMATION_DURATION = 200;
|
||||
const QEasingCurve SHOW_HIDE_EASINGCURVE = QEasingCurve::InSine;
|
||||
};
|
||||
|
||||
|
@ -29,6 +29,7 @@ void AppItem::moveWithAnimation(QPoint targetPos, int duration)
|
||||
animation->setEasingCurve(MOVE_ANIMATION_CURVE);
|
||||
animation->start();
|
||||
connect(animation, &QPropertyAnimation::finished, this, &AppItem::moveAnimationFinished);
|
||||
connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater);
|
||||
}
|
||||
|
||||
QWidget *AppItem::getApplet()
|
||||
|
@ -48,7 +48,6 @@ void DockLayout::insertItem(AbstractDockItem *item, int index)
|
||||
|
||||
//reset state
|
||||
m_movingLeftward = true;
|
||||
m_animationItemCount = 0;
|
||||
}
|
||||
|
||||
void DockLayout::moveItem(int from, int to)
|
||||
@ -183,8 +182,8 @@ bool DockLayout::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::MouseMove:
|
||||
case QEvent::Enter:
|
||||
case QEvent::Leave:
|
||||
// case QEvent::Enter:
|
||||
// case QEvent::Leave:
|
||||
if (m_dragItemMap.isEmpty())
|
||||
break;
|
||||
restoreTmpItem();
|
||||
@ -259,7 +258,7 @@ void DockLayout::slotItemEntered(QDragEnterEvent *)
|
||||
|
||||
int tmpIndex = indexOf(item);
|
||||
m_lastHoverIndex = tmpIndex;
|
||||
if (spacingItemIndex() == -1 && m_animationItemCount <= 0){ //if some animation still running ,there must has spacing item
|
||||
if (spacingItemIndex() == -1 && animatingItemCount() <= 0){ //if some animation still running ,there must has spacing item
|
||||
addSpacingItem();
|
||||
return;
|
||||
}
|
||||
@ -274,7 +273,7 @@ void DockLayout::slotItemEntered(QDragEnterEvent *)
|
||||
{
|
||||
case LeftToRight:
|
||||
m_movingLeftward = tmpPos.x() - m_lastPost.x() < 0;
|
||||
if (m_movingLeftward != lastState && m_animationItemCount > 0)
|
||||
if (m_movingLeftward != lastState && animatingItemCount() > 0)
|
||||
{
|
||||
m_movingLeftward = lastState;
|
||||
return;
|
||||
@ -298,15 +297,13 @@ void DockLayout::slotItemExited(QDragLeaveEvent *)
|
||||
|
||||
void DockLayout::slotAnimationFinish()
|
||||
{
|
||||
if (m_animationItemCount > 0){
|
||||
if (animatingItemCount() > 0){
|
||||
//now the animation count should be 0
|
||||
//for overlap
|
||||
//e.g: spacingIndex is 4 and now if drag item hover item(1) and out of dock suddenly
|
||||
//item(1~3) will move to index 4 witch is no longer a spacingItem
|
||||
if (m_animationItemCount == 1 && spacingItemIndex() == -1)
|
||||
if (animatingItemCount() == 1 && spacingItemIndex() == -1)
|
||||
relayout();
|
||||
|
||||
m_animationItemCount --;
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,8 +363,7 @@ void DockLayout::leftToRightMove(int hoverIndex)
|
||||
QPoint nextPos = QPoint(targetItem->x() + itemWidth + m_itemSpacing,0);
|
||||
if (targetItem->x() != targetItem->getNextPos().x()) //animation not finish
|
||||
break;
|
||||
m_animationItemCount ++;
|
||||
targetItem->moveWithAnimation(nextPos, MOVE_ANIMATION_DURATION_BASE + m_animationItemCount * 25);
|
||||
targetItem->moveWithAnimation(nextPos, MOVE_ANIMATION_DURATION_BASE + i * 25);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -378,8 +374,7 @@ void DockLayout::leftToRightMove(int hoverIndex)
|
||||
QPoint nextPos = QPoint(targetItem->x() - itemWidth - m_itemSpacing,0);
|
||||
if (targetItem->x() != targetItem->getNextPos().x()) //animation not finish
|
||||
break;
|
||||
m_animationItemCount ++;
|
||||
targetItem->moveWithAnimation(nextPos, MOVE_ANIMATION_DURATION_BASE + m_animationItemCount * 25);
|
||||
targetItem->moveWithAnimation(nextPos, MOVE_ANIMATION_DURATION_BASE + i * 25);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -391,6 +386,9 @@ void DockLayout::topToBottomMove(int hoverIndex)
|
||||
|
||||
void DockLayout::addSpacingItem()
|
||||
{
|
||||
if (spacingItemIndex() != -1 || animatingItemCount() > 0)
|
||||
return;
|
||||
|
||||
int spacingValue = 0;
|
||||
if (m_dragItemMap.isEmpty())
|
||||
spacingValue = DockModeData::instance()->getNormalItemWidth();
|
||||
@ -400,19 +398,35 @@ void DockLayout::addSpacingItem()
|
||||
for (int i = m_appList.count() -1;i >= m_lastHoverIndex; i-- )
|
||||
{
|
||||
AbstractDockItem *targetItem = m_appList.at(i);
|
||||
targetItem->setNextPos(targetItem->x() + spacingValue + m_itemSpacing,0);
|
||||
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(targetItem, "pos");
|
||||
animation->setStartValue(targetItem->pos());
|
||||
animation->setEndValue(targetItem->getNextPos());
|
||||
animation->setDuration(MOVE_ANIMATION_DURATION_BASE + i * 10);
|
||||
animation->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(animation, &QPropertyAnimation::finished, this, &DockLayout::contentsWidthChange);
|
||||
|
||||
animation->start();
|
||||
targetItem->moveWithAnimation(QPoint(targetItem->x() + spacingValue + m_itemSpacing,0),
|
||||
MOVE_ANIMATION_DURATION_BASE + i * 25);
|
||||
}
|
||||
|
||||
emit contentsWidthChange();
|
||||
}
|
||||
|
||||
void DockLayout::removeSpacingItem()
|
||||
{
|
||||
if (spacingItemIndex() == -1)
|
||||
return;
|
||||
if (animatingItemCount() > 0){//try to remove spacing again
|
||||
QTimer::singleShot(100, this, SLOT(removeSpacingItem()));
|
||||
return;
|
||||
}
|
||||
|
||||
int spacingValue = 0;
|
||||
if (m_dragItemMap.isEmpty())
|
||||
spacingValue = DockModeData::instance()->getNormalItemWidth();
|
||||
else
|
||||
spacingValue = m_dragItemMap.firstKey()->width();
|
||||
|
||||
for (int i = spacingItemIndex(); i < m_appList.count(); i ++)
|
||||
{
|
||||
AbstractDockItem *targetItem = m_appList.at(i);
|
||||
targetItem->moveWithAnimation(QPoint(targetItem->x() - spacingValue - m_itemSpacing, 0),
|
||||
MOVE_ANIMATION_DURATION_BASE + i * 25);
|
||||
}
|
||||
|
||||
//make panel resize immediately
|
||||
emit contentsWidthChange();
|
||||
}
|
||||
|
||||
@ -421,8 +435,6 @@ void DockLayout::dragoutFromLayout(int index)
|
||||
AbstractDockItem * tmpItem = m_appList.takeAt(index);
|
||||
tmpItem->setVisible(false);
|
||||
m_dragItemMap.insert(tmpItem,index);
|
||||
|
||||
emit contentsWidthChange();
|
||||
}
|
||||
|
||||
int DockLayout::spacingItemWidth() const
|
||||
@ -451,6 +463,16 @@ int DockLayout::spacingItemIndex() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
int DockLayout::animatingItemCount()
|
||||
{
|
||||
int tmpCount = 0;
|
||||
foreach (AbstractDockItem *item, m_appList) {
|
||||
if (item->pos() != item->getNextPos())
|
||||
tmpCount ++;
|
||||
}
|
||||
return tmpCount;
|
||||
}
|
||||
|
||||
|
||||
//return the docked app id list,just for app
|
||||
QStringList DockLayout::itemsIdList() const
|
||||
|
@ -46,6 +46,7 @@ signals:
|
||||
void frameUpdate();
|
||||
|
||||
public slots:
|
||||
void removeSpacingItem();
|
||||
void restoreTmpItem();
|
||||
void clearTmpItem();
|
||||
void relayout();
|
||||
@ -72,6 +73,7 @@ private:
|
||||
|
||||
int spacingItemWidth() const;
|
||||
int spacingItemIndex() const;
|
||||
int animatingItemCount();
|
||||
QStringList itemsIdList() const;
|
||||
|
||||
private:
|
||||
@ -85,7 +87,6 @@ private:
|
||||
qreal m_itemSpacing = 10;
|
||||
QPoint m_lastPost = QPoint(0,0);
|
||||
int m_lastHoverIndex = -1;
|
||||
int m_animationItemCount = 0;
|
||||
bool m_movingLeftward = true;
|
||||
|
||||
const int MOVE_ANIMATION_DURATION_BASE = 300;
|
||||
|
Loading…
x
Reference in New Issue
Block a user