mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
AppItems in docklayout API to AbstractDockItem
This commit is contained in:
parent
40127b7d49
commit
c06ed28b6f
@ -30,22 +30,6 @@ AppItem::AppItem(QString title, QString iconPath, QWidget *parent) :
|
||||
setIcon(m_itemIconPath);
|
||||
}
|
||||
|
||||
QPoint AppItem::getNextPos()
|
||||
{
|
||||
return this->nextPos;
|
||||
}
|
||||
|
||||
void AppItem::setNextPos(const QPoint &value)
|
||||
{
|
||||
this->nextPos = value;
|
||||
}
|
||||
|
||||
void AppItem::setNextPos(int x, int y)
|
||||
{
|
||||
this->nextPos.setX(x);
|
||||
this->nextPos.setY(y);
|
||||
}
|
||||
|
||||
void AppItem::resizeResources()
|
||||
{
|
||||
if (m_appIcon != NULL)
|
||||
@ -73,24 +57,24 @@ void AppItem::initBackground()
|
||||
void AppItem::mousePressEvent(QMouseEvent * event)
|
||||
{
|
||||
//qWarning() << "mouse press...";
|
||||
emit mousePress(event->globalX(), event->globalY(),this);
|
||||
emit mousePress(event->globalX(), event->globalY());
|
||||
}
|
||||
|
||||
void AppItem::mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
// qWarning() << "mouse release...";
|
||||
emit mouseRelease(event->globalX(), event->globalY(),this);
|
||||
emit mouseRelease(event->globalX(), event->globalY());
|
||||
}
|
||||
|
||||
void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
|
||||
{
|
||||
emit mouseDoubleClick(this);
|
||||
emit mouseDoubleClick();
|
||||
}
|
||||
|
||||
void AppItem::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
//this event will only execp onec then handle by Drag
|
||||
emit dragStart(this);
|
||||
emit dragStart();
|
||||
|
||||
Qt::MouseButtons btn = event->buttons();
|
||||
if(btn == Qt::LeftButton)
|
||||
@ -112,17 +96,17 @@ void AppItem::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void AppItem::enterEvent(QEvent *event)
|
||||
{
|
||||
emit mouseEntered(this);
|
||||
emit mouseEntered();
|
||||
}
|
||||
|
||||
void AppItem::leaveEvent(QEvent *event)
|
||||
{
|
||||
emit mouseExited(this);
|
||||
emit mouseExited();
|
||||
}
|
||||
|
||||
void AppItem::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
emit dragEntered(event,this);
|
||||
emit dragEntered(event);
|
||||
|
||||
AppItem *tmpItem = NULL;
|
||||
tmpItem = dynamic_cast<AppItem *>(event->source());
|
||||
@ -139,13 +123,13 @@ void AppItem::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
||||
void AppItem::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
emit dragExited(event,this);
|
||||
emit dragExited(event);
|
||||
}
|
||||
|
||||
void AppItem::dropEvent(QDropEvent *event)
|
||||
{
|
||||
qWarning() << "Item get drop:" << event->pos();
|
||||
emit drop(event,this);
|
||||
emit drop(event);
|
||||
}
|
||||
|
||||
AppItem::~AppItem()
|
||||
|
@ -27,10 +27,6 @@ public:
|
||||
AppItem(QString title, QString iconPath, QWidget *parent = 0);
|
||||
~AppItem();
|
||||
|
||||
QPoint getNextPos();
|
||||
void setNextPos(const QPoint &value);
|
||||
void setNextPos(int x, int y);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
@ -42,17 +38,6 @@ protected:
|
||||
void dragLeaveEvent(QDragLeaveEvent * event);
|
||||
void dropEvent(QDropEvent * event);
|
||||
|
||||
signals:
|
||||
void dragStart(AppItem *item);
|
||||
void dragEntered(QDragEnterEvent * event,AppItem *item);
|
||||
void dragExited(QDragLeaveEvent * event,AppItem *item);
|
||||
void drop(QDropEvent * event,AppItem *item);
|
||||
void mouseEntered(AppItem *item);
|
||||
void mouseExited(AppItem *item);
|
||||
void mousePress(int x, int y, AppItem *item);
|
||||
void mouseRelease(int x, int y, AppItem *item);
|
||||
void mouseDoubleClick( AppItem *item);
|
||||
|
||||
private:
|
||||
void resizeResources();
|
||||
void initBackground();
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "docklayout.h"
|
||||
#include "abstractdockitem.h"
|
||||
|
||||
DockLayout::DockLayout(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
@ -11,22 +12,22 @@ void DockLayout::setParent(QWidget *parent)
|
||||
this->setParent(parent);
|
||||
}
|
||||
|
||||
void DockLayout::addItem(AppItem *item)
|
||||
void DockLayout::addItem(AbstractDockItem *item)
|
||||
{
|
||||
insertItem(item,appList.count());
|
||||
}
|
||||
|
||||
void DockLayout::insertItem(AppItem *item, int index)
|
||||
void DockLayout::insertItem(AbstractDockItem *item, int index)
|
||||
{
|
||||
item->setParent(this);
|
||||
int appCount = appList.count();
|
||||
index = index > appCount ? appCount : (index < 0 ? 0 : index);
|
||||
|
||||
appList.insert(index,item);
|
||||
connect(item,SIGNAL(mouseRelease(int,int,AppItem*)),this,SLOT(slotItemRelease(int,int,AppItem*)));
|
||||
connect(item, SIGNAL(dragStart(AppItem*)),this,SLOT(slotItemDrag(AppItem*)));
|
||||
connect(item,SIGNAL(dragEntered(QDragEnterEvent*,AppItem*)),this,SLOT(slotItemEntered(QDragEnterEvent*,AppItem*)));
|
||||
connect(item,SIGNAL(dragExited(QDragLeaveEvent*,AppItem*)),this,SLOT(slotItemExited(QDragLeaveEvent*,AppItem*)));
|
||||
connect(item, &AbstractDockItem::mouseRelease, this, &DockLayout::slotItemRelease);
|
||||
connect(item, &AbstractDockItem::dragStart, this, &DockLayout::slotItemDrag);
|
||||
connect(item, &AbstractDockItem::dragEntered, this, &DockLayout::slotItemEntered);
|
||||
connect(item, &AbstractDockItem::dragExited, this, &DockLayout::slotItemExited);
|
||||
|
||||
relayout();
|
||||
}
|
||||
@ -95,7 +96,7 @@ void DockLayout::sortLeftToRight()
|
||||
|
||||
for (int i = 1; i < appList.count(); i ++)
|
||||
{
|
||||
AppItem * frontItem = appList.at(i - 1);
|
||||
AbstractDockItem * frontItem = appList.at(i - 1);
|
||||
appList.at(i)->move(frontItem->pos().x() + frontItem->width() + itemSpacing,0);
|
||||
}
|
||||
}
|
||||
@ -109,8 +110,8 @@ void DockLayout::sortRightToLeft()
|
||||
|
||||
for (int i = 1; i < appList.count(); i++)
|
||||
{
|
||||
AppItem *fromItem = appList.at(i - 1);
|
||||
AppItem *toItem = appList.at(i);
|
||||
AbstractDockItem *fromItem = appList.at(i - 1);
|
||||
AbstractDockItem *toItem = appList.at(i);
|
||||
toItem->move(fromItem->x() - itemSpacing - toItem->width(),0);
|
||||
}
|
||||
}
|
||||
@ -125,7 +126,7 @@ void DockLayout::sortBottomToTop()
|
||||
|
||||
}
|
||||
|
||||
int DockLayout::indexOf(AppItem *item)
|
||||
int DockLayout::indexOf(AbstractDockItem *item)
|
||||
{
|
||||
return appList.indexOf(item);
|
||||
}
|
||||
@ -162,10 +163,10 @@ void DockLayout::addSpacingItem()
|
||||
if (tmpAppMap.isEmpty())
|
||||
return;
|
||||
|
||||
AppItem *tmpItem = tmpAppMap.firstKey();
|
||||
AbstractDockItem *tmpItem = tmpAppMap.firstKey();
|
||||
for (int i = appList.count() -1;i > lastHoverIndex; i-- )
|
||||
{
|
||||
AppItem *targetItem = appList.at(i);
|
||||
AbstractDockItem *targetItem = appList.at(i);
|
||||
targetItem->setNextPos(targetItem->x() + tmpItem->width() + itemSpacing,0);
|
||||
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(targetItem, "pos");
|
||||
@ -180,7 +181,7 @@ void DockLayout::addSpacingItem()
|
||||
|
||||
void DockLayout::dragoutFromLayout(int index)
|
||||
{
|
||||
AppItem * tmpItem = appList.takeAt(index);
|
||||
AbstractDockItem * tmpItem = appList.takeAt(index);
|
||||
tmpItem->setVisible(false);
|
||||
tmpAppMap.insert(tmpItem,index);
|
||||
}
|
||||
@ -193,7 +194,7 @@ void DockLayout::dragEnterEvent(QDragEnterEvent *event)
|
||||
|
||||
void DockLayout::dropEvent(QDropEvent *event)
|
||||
{
|
||||
AppItem * tmpItem = tmpAppMap.firstKey();
|
||||
AbstractDockItem * tmpItem = tmpAppMap.firstKey();
|
||||
tmpAppMap.remove(tmpItem);
|
||||
tmpItem->setVisible(true);
|
||||
if (indexOf(tmpItem) == -1)
|
||||
@ -207,9 +208,11 @@ void DockLayout::dropEvent(QDropEvent *event)
|
||||
emit itemDropped();
|
||||
}
|
||||
|
||||
void DockLayout::slotItemDrag(AppItem *item)
|
||||
void DockLayout::slotItemDrag()
|
||||
{
|
||||
// qWarning() << "Item draging..."<<x<<y<<item;
|
||||
AbstractDockItem *item = qobject_cast<AbstractDockItem*>(sender());
|
||||
|
||||
int tmpIndex = indexOf(item);
|
||||
if (tmpIndex != -1)
|
||||
{
|
||||
@ -221,10 +224,12 @@ void DockLayout::slotItemDrag(AppItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void DockLayout::slotItemRelease(int x, int y, AppItem *item)
|
||||
void DockLayout::slotItemRelease(int, int)
|
||||
{
|
||||
//outside frame,destroy it
|
||||
//inside frame,insert it
|
||||
AbstractDockItem *item = qobject_cast<AbstractDockItem*>(sender());
|
||||
|
||||
item->setVisible(true);
|
||||
if (indexOf(item) == -1)
|
||||
{
|
||||
@ -232,8 +237,10 @@ void DockLayout::slotItemRelease(int x, int y, AppItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void DockLayout::slotItemEntered(QDragEnterEvent * event,AppItem *item)
|
||||
void DockLayout::slotItemEntered(QDragEnterEvent *)
|
||||
{
|
||||
AbstractDockItem *item = qobject_cast<AbstractDockItem*>(sender());
|
||||
|
||||
int tmpIndex = indexOf(item);
|
||||
QPoint tmpPos = QCursor::pos();
|
||||
|
||||
@ -259,7 +266,7 @@ void DockLayout::slotItemEntered(QDragEnterEvent * event,AppItem *item)
|
||||
|
||||
if (!tmpAppMap.isEmpty())
|
||||
{
|
||||
AppItem *targetItem = appList.at(tmpIndex);
|
||||
AbstractDockItem *targetItem = appList.at(tmpIndex);
|
||||
if (movingForward)
|
||||
{
|
||||
targetItem->setNextPos(QPoint(targetItem->x() + tmpAppMap.firstKey()->width() + itemSpacing,0));
|
||||
@ -277,7 +284,7 @@ void DockLayout::slotItemEntered(QDragEnterEvent * event,AppItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void DockLayout::slotItemExited(QDragLeaveEvent *event,AppItem *item)
|
||||
void DockLayout::slotItemExited(QDragLeaveEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
explicit DockLayout(QWidget *parent = 0);
|
||||
|
||||
void setParent(QWidget *parent);
|
||||
void addItem(AppItem * item);
|
||||
void insertItem(AppItem *item, int index);
|
||||
void addItem(AbstractDockItem * item);
|
||||
void insertItem(AbstractDockItem *item, int index);
|
||||
void removeItem(int index);
|
||||
void moveItem(int from, int to);
|
||||
void setItemMoveable(int index, bool moveable);
|
||||
@ -38,7 +38,7 @@ public:
|
||||
void setMargin(DockLayout::MarginEdge edge, qreal margin);
|
||||
void setSpacing(qreal spacing);
|
||||
void setSortDirection(DockLayout::Direction value);
|
||||
int indexOf(AppItem * item);
|
||||
int indexOf(AbstractDockItem * item);
|
||||
int indexOf(int x,int y);
|
||||
void relayout();
|
||||
void addSpacingItem();
|
||||
@ -53,10 +53,10 @@ protected:
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
void slotItemDrag(AppItem *item);
|
||||
void slotItemRelease(int x, int y, AppItem *item);
|
||||
void slotItemEntered(QDragEnterEvent * event,AppItem *item);
|
||||
void slotItemExited(QDragLeaveEvent *event,AppItem *item);
|
||||
void slotItemDrag();
|
||||
void slotItemRelease(int x, int y);
|
||||
void slotItemEntered(QDragEnterEvent * event);
|
||||
void slotItemExited(QDragLeaveEvent *event);
|
||||
|
||||
private:
|
||||
void sortLeftToRight();
|
||||
@ -65,8 +65,8 @@ private:
|
||||
void sortBottomToTop();
|
||||
|
||||
private:
|
||||
QList<AppItem *> appList;
|
||||
QMap<AppItem *,int> tmpAppMap;//only one item inside
|
||||
QList<AbstractDockItem *> appList;
|
||||
QMap<AbstractDockItem *,int> tmpAppMap;//only one item inside
|
||||
|
||||
DockLayout::Direction sortDirection = DockLayout::LeftToRight;
|
||||
qreal itemSpacing = 10;
|
||||
|
@ -31,6 +31,21 @@ public:
|
||||
virtual void setIndex(int value) { m_itemIndex = value; }
|
||||
virtual int index() { return m_itemIndex; }
|
||||
|
||||
QPoint getNextPos() { return m_itemNextPos; }
|
||||
void setNextPos(const QPoint &value) { m_itemNextPos = value; }
|
||||
void setNextPos(int x, int y) { m_itemNextPos.setX(x); m_itemNextPos.setY(y); }
|
||||
|
||||
signals:
|
||||
void dragStart();
|
||||
void dragEntered(QDragEnterEvent * event);
|
||||
void dragExited(QDragLeaveEvent * event);
|
||||
void drop(QDropEvent * event);
|
||||
void mouseEntered();
|
||||
void mouseExited();
|
||||
void mousePress(int x, int y);
|
||||
void mouseRelease(int x, int y);
|
||||
void mouseDoubleClick();
|
||||
|
||||
protected:
|
||||
QLabel * m_appIcon = NULL;
|
||||
|
||||
@ -39,6 +54,7 @@ protected:
|
||||
|
||||
QString m_itemTitle = "";
|
||||
QString m_itemIconPath = "";
|
||||
QPoint m_itemNextPos;
|
||||
|
||||
int m_itemIndex = 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user