make item add or remove smoothly

Change-Id: I5a06edc9744f4ea57c3e0a2daf16ea8bf14a8490
This commit is contained in:
杨万青 2015-10-10 14:58:27 +08:00
parent 3e3f557d6a
commit 229fa218a1
Notes: Deepin Code Review 2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: <mr.asianwang@gmail.com>
Submitted-by: <mr.asianwang@gmail.com>
Submitted-at: Sat, 10 Oct 2015 14:53:57 +0800
Reviewed-on: https://cr.deepin.io/7650
Project: dde/dde-dock
Branch: refs/heads/master
3 changed files with 60 additions and 6 deletions

View File

@ -123,8 +123,9 @@ void Panel::initPluginManager()
connect(targetItem, &AbstractDockItem::needPreviewUpdate, m_globalPreview, &PreviewFrame::resizeWithContent);
});
connect(m_pluginManager, &DockPluginManager::itemRemoved, [=](AbstractDockItem* item) {
m_pluginLayout->removeItem(item);
item->setVisible(false);
item->deleteLater();
m_pluginLayout->removeItem(item);
});
connect(PanelMenu::instance(), &PanelMenu::settingPlugin, [=]{
QRect rec = QApplication::desktop()->screenGeometry();
@ -143,6 +144,7 @@ void Panel::initPluginLayout()
void Panel::initAppLayout()
{
m_appLayout = new DockLayout(this);
m_appLayout->setaddItemDelayInterval(0);
m_appLayout->setAcceptDrops(true);
m_appLayout->setSpacing(m_dockModeData->getAppItemSpacing());
m_appLayout->move(0, 1);
@ -281,8 +283,9 @@ void Panel::onAppItemRemove(const QString &id)
AppItem *tmpItem = qobject_cast<AppItem *>(tmpList.at(i));
if (tmpItem && tmpItem->getItemId() == id)
{
m_appLayout->removeItem(i);
tmpItem->setVisible(false);
tmpItem->deleteLater();
m_appLayout->removeItem(i);
return;
}
}
@ -447,6 +450,7 @@ void Panel::showPanelMenu()
void Panel::loadResources()
{
m_appManager->initEntries();
m_appLayout->setaddItemDelayInterval(500);
QTimer::singleShot(500, m_pluginManager, SLOT(initAll()));
}

View File

@ -44,6 +44,18 @@ void DockLayout::insertItem(AbstractDockItem *item, int index)
m_ddam->Sort(itemsIdList());
//hide for delay show
item->setVisible(false);
//Qt5.3.* not support singleshot with lamda expressions
QTimer *delayTimer = new QTimer(this);
connect(delayTimer, &QTimer::timeout, [=] {
delayTimer->stop();
delayTimer->deleteLater();
item->setVisible(true);
});
delayTimer->start(m_addItemDelayInterval);
relayout();
//reset state
@ -59,8 +71,17 @@ void DockLayout::moveItem(int from, int to)
void DockLayout::removeItem(int index)
{
m_appList.removeAt(index);
relayout();
//Qt5.3.* not support singleshot with lamda expressions
QTimer *delayTimer = new QTimer(this);
connect(delayTimer, &QTimer::timeout, [=] {
delayTimer->stop();
delayTimer->deleteLater();
m_appList.removeAt(index);
removeSpacingItem();
relayout();
});
delayTimer->start(m_removeItemDelayInterval);
}
void DockLayout::removeItem(AbstractDockItem *item)
@ -429,7 +450,8 @@ void DockLayout::removeSpacingItem()
MOVE_ANIMATION_DURATION_BASE + i * 25);
}
emit contentsWidthChange();
//emit the width change signal after the last animation is finish
QTimer::singleShot(MOVE_ANIMATION_DURATION_BASE + m_appList.count() * 25, this, SIGNAL(contentsWidthChange()));
}
void DockLayout::dragoutFromLayout(int index)
@ -489,3 +511,23 @@ QStringList DockLayout::itemsIdList() const
}
return idList;
}
int DockLayout::removeItemDelayInterval() const
{
return m_removeItemDelayInterval;
}
void DockLayout::setRemoveItemDelayInterval(int removeItemDelayInterval)
{
m_removeItemDelayInterval = removeItemDelayInterval;
}
int DockLayout::addItemDelayInterval() const
{
return m_addItemDelayInterval;
}
void DockLayout::setaddItemDelayInterval(int addItemDelayInterval)
{
m_addItemDelayInterval = addItemDelayInterval;
}

View File

@ -40,6 +40,12 @@ public:
QList<AbstractDockItem *> getItemList() const;
AbstractDockItem *getDraggingItem() const;
int addItemDelayInterval() const;
void setaddItemDelayInterval(int addItemDelayInterval);
int removeItemDelayInterval() const;
void setRemoveItemDelayInterval(int removeItemDelayInterval);
signals:
void startDrag();
void itemDropped();
@ -87,8 +93,10 @@ private:
qreal m_itemSpacing = 10;
QPoint m_lastPost = QPoint(0,0);
int m_lastHoverIndex = -1;
bool m_movingLeftward = true;
int m_lastHoverIndex = -1;
int m_addItemDelayInterval = 500;
int m_removeItemDelayInterval = 500;
const int MOVE_ANIMATION_DURATION_BASE = 300;
};