mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Update DOckLayout:
DockLayout add verticalalignment for sort item Fix right-layout item position error
This commit is contained in:
parent
d878097c18
commit
dc3acf5c55
@ -12,13 +12,12 @@ Panel::Panel(QWidget *parent)
|
||||
rightLayout = new DockLayout(this);
|
||||
rightLayout->setSortDirection(DockLayout::RightToLeft);
|
||||
rightLayout->setSpacing(dockCons->getAppletsItemSpacing());
|
||||
rightLayout->resize(80,dockCons->getItemHeight());
|
||||
rightLayout->resize(0,dockCons->getItemHeight());
|
||||
|
||||
leftLayout = new DockLayout(this);
|
||||
leftLayout->setSpacing(dockCons->getAppItemSpacing());
|
||||
leftLayout->resize(this->width() - rightLayout->width(),dockCons->getItemHeight());
|
||||
leftLayout->move(0,1);
|
||||
|
||||
connect(leftLayout,SIGNAL(dragStarted()),this,SLOT(slotDragStarted()));
|
||||
connect(leftLayout,SIGNAL(itemDropped()),this,SLOT(slotItemDropped()));
|
||||
|
||||
|
@ -46,6 +46,11 @@ void DockLayout::setSpacing(qreal spacing)
|
||||
this->itemSpacing = spacing;
|
||||
}
|
||||
|
||||
void DockLayout::setVerticalAlignment(DockLayout::VerticalAlignment value)
|
||||
{
|
||||
this->m_verticalAlignment = value;
|
||||
}
|
||||
|
||||
void DockLayout::setSortDirection(DockLayout::Direction value)
|
||||
{
|
||||
this->sortDirection = value;
|
||||
@ -56,13 +61,37 @@ void DockLayout::sortLeftToRight()
|
||||
if (appList.count() <= 0)
|
||||
return;
|
||||
|
||||
appList.at(0)->move(itemSpacing,(height() - appList.at(0)->height()) / 2);
|
||||
switch (m_verticalAlignment)
|
||||
{
|
||||
case DockLayout::AlignTop:
|
||||
appList.at(0)->move(itemSpacing,0);
|
||||
break;
|
||||
case DockLayout::AlignVCenter:
|
||||
appList.at(0)->move(itemSpacing,(height() - appList.at(0)->height()) / 2);
|
||||
break;
|
||||
case DockLayout::AlignBottom:
|
||||
appList.at(0)->move(itemSpacing,height() - appList.at(0)->height());
|
||||
break;
|
||||
}
|
||||
appList.at(0)->setNextPos(appList.at(0)->pos());
|
||||
|
||||
for (int i = 1; i < appList.count(); i ++)
|
||||
{
|
||||
AbstractDockItem * frontItem = appList.at(i - 1);
|
||||
appList.at(i)->move(frontItem->pos().x() + frontItem->width() + itemSpacing,height() - appList.at(i)->height());
|
||||
AbstractDockItem * toItem = appList.at(i);
|
||||
switch (m_verticalAlignment)
|
||||
{
|
||||
case DockLayout::AlignTop:
|
||||
toItem->move(frontItem->pos().x() + frontItem->width() + itemSpacing,0);
|
||||
break;
|
||||
case DockLayout::AlignVCenter:
|
||||
toItem->move(frontItem->pos().x() + frontItem->width() + itemSpacing,(height() - toItem->height()) / 2);
|
||||
break;
|
||||
case DockLayout::AlignBottom:
|
||||
toItem->move(frontItem->pos().x() + frontItem->width() + itemSpacing,height() - toItem->height());
|
||||
break;
|
||||
}
|
||||
|
||||
appList.at(i)->setNextPos(appList.at(i)->pos());
|
||||
}
|
||||
}
|
||||
@ -72,13 +101,35 @@ void DockLayout::sortRightToLeft()
|
||||
if (appList.count()<=0)
|
||||
return;
|
||||
|
||||
appList.at(0)->move(this->width() - itemSpacing - appList.at(0)->width(),0);
|
||||
switch (m_verticalAlignment)
|
||||
{
|
||||
case DockLayout::AlignTop:
|
||||
appList.at(0)->move(getContentsWidth() - itemSpacing - appList.at(0)->width(),0);
|
||||
break;
|
||||
case DockLayout::AlignVCenter:
|
||||
appList.at(0)->move(getContentsWidth() - itemSpacing - appList.at(0)->width(),(height() - appList.at(0)->height()) / 2);
|
||||
break;
|
||||
case DockLayout::AlignBottom:
|
||||
appList.at(0)->move(getContentsWidth() - itemSpacing - appList.at(0)->width(),height() - appList.at(0)->height());
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 1; i < appList.count(); i++)
|
||||
{
|
||||
AbstractDockItem *fromItem = appList.at(i - 1);
|
||||
AbstractDockItem *toItem = appList.at(i);
|
||||
toItem->move(fromItem->x() - itemSpacing - toItem->width(),0);
|
||||
switch (m_verticalAlignment)
|
||||
{
|
||||
case DockLayout::AlignTop:
|
||||
toItem->move(fromItem->x() - itemSpacing - toItem->width(),0);
|
||||
break;
|
||||
case DockLayout::AlignVCenter:
|
||||
toItem->move(fromItem->x() - itemSpacing - toItem->width(),(height() - toItem->height()) / 2);
|
||||
break;
|
||||
case DockLayout::AlignBottom:
|
||||
toItem->move(fromItem->x() - itemSpacing - toItem->width(),height() - toItem->height());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,12 @@ public:
|
||||
RightToLeft
|
||||
};
|
||||
|
||||
enum VerticalAlignment {
|
||||
AlignTop,
|
||||
AlignVCenter,
|
||||
AlignBottom
|
||||
};
|
||||
|
||||
explicit DockLayout(QWidget *parent = 0);
|
||||
|
||||
void addItem(AbstractDockItem * item);
|
||||
@ -28,6 +34,7 @@ public:
|
||||
void removeItem(int index);
|
||||
void moveItem(int from, int to);
|
||||
void setSpacing(qreal spacing);
|
||||
void setVerticalAlignment(DockLayout::VerticalAlignment value);
|
||||
void setSortDirection(DockLayout::Direction value);
|
||||
int indexOf(AbstractDockItem * item);
|
||||
int indexOf(int x,int y);
|
||||
@ -68,6 +75,7 @@ private:
|
||||
QMap<AbstractDockItem *,int> tmpAppMap;//only one item inside
|
||||
DBusDockedAppManager *m_ddam = new DBusDockedAppManager(this);
|
||||
|
||||
DockLayout::VerticalAlignment m_verticalAlignment = DockLayout::AlignVCenter;
|
||||
DockLayout::Direction sortDirection = DockLayout::LeftToRight;
|
||||
qreal itemSpacing = 10;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user