Drag the icon

This commit is contained in:
杨万青 2015-06-25 15:34:49 +08:00
parent 6d1f869fd8
commit fb97508ea7
24 changed files with 420 additions and 10 deletions

View File

@ -6,13 +6,17 @@ Panel::Panel(QWidget *parent) : QWidget(parent)
leftLayout->resize(1024,50);
leftLayout->move(0,0);
for (int i = 0; i < 5; i ++)
{
AppItem * tmpButton = new AppItem("App" + QString::number(i),":/test/Resources/images/google-chrome.png");
tmpButton->resize(50,50);
AppItem * b1 = new AppItem("App",":/test/Resources/images/brasero.png");b1->resize(50,50);
AppItem * b2 = new AppItem("App",":/test/Resources/images/crossover.png");b2->resize(50,50);
AppItem * b3 = new AppItem("App",":/test/Resources/images/gcr-gnupg.png");b3->resize(50,50);
AppItem * b4 = new AppItem("App",":/test/Resources/images/display-im6.q16.png");b4->resize(50,50);
AppItem * b5 = new AppItem("App",":/test/Resources/images/eog.png");b5->resize(50,50);
leftLayout->addItem(tmpButton);
}
leftLayout->addItem(b1);
leftLayout->addItem(b2);
leftLayout->addItem(b3);
leftLayout->addItem(b4);
leftLayout->addItem(b5);
}
void Panel::resize(const QSize &size)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,278 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="32"
height="32"
id="svg6860"
inkscape:version="0.48.4 r9939"
sodipodi:docname="multitasking-view.svg">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1440"
inkscape:window-height="845"
id="namedview46"
showgrid="true"
inkscape:zoom="9.921875"
inkscape:cx="20.08189"
inkscape:cy="16"
inkscape:window-x="0"
inkscape:window-y="30"
inkscape:window-maximized="1"
inkscape:current-layer="svg6860">
<inkscape:grid
type="xygrid"
id="grid3316" />
</sodipodi:namedview>
<defs
id="defs6862">
<linearGradient
id="linearGradient3924-0">
<stop
id="stop3926-6"
style="stop-color:#ffffff;stop-opacity:1"
offset="0" />
<stop
id="stop3928-3"
style="stop-color:#ffffff;stop-opacity:0.23529412"
offset="0.06316455" />
<stop
id="stop3930-2"
style="stop-color:#ffffff;stop-opacity:0.15686275"
offset="0.95056331" />
<stop
id="stop3932-62"
style="stop-color:#ffffff;stop-opacity:0.39215687"
offset="1" />
</linearGradient>
<radialGradient
cx="4.9929786"
cy="43.5"
r="2.5"
fx="4.9929786"
fy="43.5"
id="radialGradient2976"
xlink:href="#linearGradient3688-166-749-6"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.003784,0,0,1.4,27.98813,-17.4)" />
<linearGradient
id="linearGradient3688-166-749-6">
<stop
id="stop2883-8"
style="stop-color:#181818;stop-opacity:1"
offset="0" />
<stop
id="stop2885-3"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<radialGradient
cx="4.9929786"
cy="43.5"
r="2.5"
fx="4.9929786"
fy="43.5"
id="radialGradient2978"
xlink:href="#linearGradient3688-464-309-7"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.003784,0,0,1.4,-20.01187,-104.4)" />
<linearGradient
id="linearGradient3688-464-309-7">
<stop
id="stop2889-0"
style="stop-color:#181818;stop-opacity:1"
offset="0" />
<stop
id="stop2891-66"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<linearGradient
x1="25.058096"
y1="47.027729"
x2="25.058096"
y2="39.999443"
id="linearGradient2980"
xlink:href="#linearGradient3702-501-757-3"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3702-501-757-3">
<stop
id="stop2895-3"
style="stop-color:#181818;stop-opacity:0"
offset="0" />
<stop
id="stop2897-28"
style="stop-color:#181818;stop-opacity:1"
offset="0.5" />
<stop
id="stop2899-8"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<linearGradient
id="linearGradient5803-6-2">
<stop
id="stop5805-7-1"
style="stop-color:#ffffff;stop-opacity:1;"
offset="0" />
<stop
id="stop5807-8-5"
style="stop-color:#e6f4f8;stop-opacity:1;"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3924-0"
id="linearGradient3215"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.62162164,0,0,0.62162164,1.0810794,2.0810903)"
x1="23.99999"
y1="4.999989"
x2="23.99999"
y2="43" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-8-3-5-6-6-5"
id="radialGradient3275-7"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0,3.8461954,-7.4743331,0,90.95547,-34.119923)"
cx="7.7392125"
cy="9.9571075"
fx="7.2089825"
fy="9.9571075"
r="12.671875" />
<linearGradient
id="linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-8-3-5-6-6-5">
<stop
id="stop3750-1-0-6-9-9-6"
style="stop-color:#90dbec;stop-opacity:1"
offset="0" />
<stop
id="stop3752-3-7-8-3-5-6"
style="stop-color:#55c1ec;stop-opacity:1"
offset="0.26238" />
<stop
id="stop3754-1-8-5-8-5-6"
style="stop-color:#3689e6;stop-opacity:1"
offset="0.704952" />
<stop
id="stop3756-1-6-3-7-3-1"
style="stop-color:#2b63a0;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5803-6-2"
id="linearGradient3324"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.4265442,0,0,0.41469579,-54.033003,2.5228637)"
x1="167.98311"
y1="13.398731"
x2="167.98311"
y2="54.780239" />
</defs>
<metadata
id="metadata6865">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
style="display:inline"
id="g2036-2"
transform="matrix(0.6999997,0,0,0.3333336,-0.8000002,15.33333)">
<g
style="opacity:0.4"
id="g3712-3"
transform="matrix(1.052632,0,0,1.285713,-1.263158,-13.42854)">
<rect
style="fill:url(#radialGradient2976);fill-opacity:1;stroke:none"
id="rect2801-0"
y="40"
x="38"
height="7"
width="5" />
<rect
style="fill:url(#radialGradient2978);fill-opacity:1;stroke:none"
id="rect3696-2"
transform="scale(-1,-1)"
y="-47"
x="-10"
height="7"
width="5" />
<rect
style="fill:url(#linearGradient2980);fill-opacity:1;stroke:none"
id="rect3700-1"
y="40"
x="10"
height="7.0000005"
width="28" />
</g>
</g>
<rect
style="color:#000000;fill:url(#radialGradient3275-7);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999994000000003;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5505"
y="4.5"
x="3.4999993"
ry="2"
rx="2"
height="25"
width="25" />
<rect
style="opacity:0.5;fill:none;stroke:url(#linearGradient3215);stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect6741-7-4"
y="5.5"
x="4.499999"
ry="1"
rx="1"
height="23"
width="23" />
<rect
style="opacity:0.40000000000000002;color:#000000;fill:none;stroke:#003164;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5505-6"
y="4.5"
x="3.4999993"
ry="2"
rx="2"
height="25"
width="25" />
<path
sodipodi:type="inkscape:offset"
inkscape:radius="0.9900791"
inkscape:original="M 6.59375 9 C 6.2613505 9 6 9.2705839 6 9.59375 L 6 15.40625 C 6 15.729417 6.2613505 16 6.59375 16 L 14.40625 16 C 14.73865 16 15 15.729417 15 15.40625 L 15 9.59375 C 15 9.2705839 14.73865 9 14.40625 9 L 6.59375 9 z M 18.53125 10 C 18.235784 10 18 10.303704 18 10.65625 L 18 16.34375 C 18 16.696297 18.235784 17 18.53125 17 L 25.46875 17 C 25.764216 17 26 16.696297 26 16.34375 L 26 10.65625 C 26 10.303704 25.764216 10 25.46875 10 L 18.53125 10 z M 10.71875 19 C 10.312483 19 10 19.347091 10 19.75 L 10 26.25 C 10 26.652909 10.312483 27 10.71875 27 L 20.28125 27 C 20.687518 27 21 26.652909 21 26.25 L 21 19.75 C 21 19.347091 20.687518 19 20.28125 19 L 10.71875 19 z "
style="opacity:0.14999999999999999;color:#000000;fill:#0974ae;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path3400"
d="M 6.59375,8 C 5.7240463,8 5,8.7367868 5,9.59375 l 0,5.8125 C 5,16.263213 5.7240481,17 6.59375,17 l 7.8125,0 C 15.275952,17 16,16.263212 16,15.40625 l 0,-5.8125 C 16,8.7367879 15.275953,8 14.40625,8 l -7.8125,0 z m 11.9375,1 C 17.557328,9 17,9.8622584 17,10.65625 l 0,5.6875 C 17,17.137741 17.55733,18 18.53125,18 l -7.8125,0 C 9.7485722,18 9,18.835176 9,19.75 l 0,6.5 C 9,27.164824 9.7485722,28 10.71875,28 l 9.5625,0 C 21.251427,28 22,27.164823 22,26.25 l 0,-6.5 C 22,18.835177 21.251427,18 20.28125,18 l 5.1875,0 C 26.44267,18 27,17.137741 27,16.34375 l 0,-5.6875 C 27,9.8622584 26.442672,9 25.46875,9 l -6.9375,0 z" />
<path
inkscape:connector-curvature="0"
style="color:#000000;fill:#0935ae;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;opacity:0.29999999999999999"
d="M 6.59375,9 C 6.2613505,9 6,9.2705839 6,9.59375 l 0,5.8125 C 6,15.729417 6.2613505,16 6.59375,16 l 7.8125,0 C 14.73865,16 15,15.729417 15,15.40625 l 0,-5.8125 C 15,9.2705839 14.73865,9 14.40625,9 l -7.8125,0 z m 11.9375,1 C 18.235784,10 18,10.303704 18,10.65625 l 0,5.6875 C 18,16.696297 18.235784,17 18.53125,17 l 6.9375,0 C 25.764216,17 26,16.696297 26,16.34375 l 0,-5.6875 C 26,10.303704 25.764216,10 25.46875,10 l -6.9375,0 z m -7.8125,9 C 10.312483,19 10,19.347091 10,19.75 l 0,6.5 c 0,0.402909 0.312483,0.75 0.71875,0.75 l 9.5625,0 C 20.687518,27 21,26.652909 21,26.25 l 0,-6.5 C 21,19.347091 20.687518,19 20.28125,19 l -9.5625,0 z"
id="path3322-2" />
<path
style="color:#000000;fill:url(#linearGradient3324);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 6.59375 8 C 6.2613505 8 6 8.2705839 6 8.59375 L 6 14.40625 C 6 14.729417 6.2613505 15 6.59375 15 L 14.40625 15 C 14.73865 15 15 14.729417 15 14.40625 L 15 8.59375 C 15 8.2705839 14.73865 8 14.40625 8 L 6.59375 8 z M 18.53125 9 C 18.235784 9 18 9.303704 18 9.65625 L 18 15.34375 C 18 15.696297 18.235784 16 18.53125 16 L 25.46875 16 C 25.764216 16 26 15.696297 26 15.34375 L 26 9.65625 C 26 9.303704 25.764216 9 25.46875 9 L 18.53125 9 z M 10.71875 18 C 10.312483 18 10 18.347091 10 18.75 L 10 25.25 C 10 25.652909 10.312483 26 10.71875 26 L 20.28125 26 C 20.687518 26 21 25.652909 21 25.25 L 21 18.75 C 21 18.347091 20.687518 18 20.28125 18 L 10.71875 18 z "
id="path3322" />
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

View File

@ -37,7 +37,6 @@ void AppItem::setIcon(const QString &iconPath, int size)
{
appIcon = new AppIcon(iconPath,this);
appIcon->resize(size,size);
// appIcon->setIcon(iconPath);
appIcon->move(this->width() / 2, this->height() / 2);
}
@ -73,6 +72,22 @@ int AppItem::getIndex()
return this->itemIndex;
}
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 (appIcon != NULL)
@ -97,12 +112,13 @@ void AppItem::initBackground()
void AppItem::mousePressEvent(QMouseEvent * event)
{
qWarning() << "press...";
// qWarning() << "mouse press...";
emit mousePress(event->globalX(), event->globalY(),this);
}
void AppItem::mouseReleaseEvent(QMouseEvent * event)
{
// qWarning() << "mouse release...";
emit mouseRelease(event->globalX(), event->globalY(),this);
}
@ -116,6 +132,16 @@ void AppItem::mouseDoubleClickEvent(QMouseEvent * event)
emit mouseDoubleClick(this);
}
void AppItem::enterEvent(QEvent *event)
{
emit mouseEntered(this);
}
void AppItem::leaveEvent(QEvent *event)
{
emit mouseExited(this);
}
AppItem::~AppItem()
{

View File

@ -15,6 +15,7 @@
class AppItem : public QFrame
{
Q_OBJECT
Q_PROPERTY(QPoint pos READ pos WRITE move)
public:
AppItem(QWidget *parent = 0);
AppItem(QString title, QWidget *parent = 0);
@ -29,14 +30,21 @@ public:
bool getMoveable();
void setIndex(int value);
int getIndex();
QPoint getNextPos();
void setNextPos(const QPoint &value);
void setNextPos(int x, int y);
protected:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void mouseDoubleClickEvent(QMouseEvent *);
void enterEvent(QEvent * event);
void leaveEvent(QEvent * event);
signals:
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 mouseMove(int x, int y, AppItem *item);
@ -49,6 +57,7 @@ private:
private:
AppBackground * appBackground = NULL;
AppIcon * appIcon = NULL;
QPoint nextPos;
int itemIndex;
bool itemMoveable = true;

View File

@ -23,6 +23,9 @@ void DockLayout::insertItem(AppItem *item, int index)
appList.insert(index,item);
connect(item, SIGNAL(mouseMove(int,int,AppItem*)),this,SLOT(slotItemDrag(int,int,AppItem*)));
connect(item,SIGNAL(mouseRelease(int,int,AppItem*)),this,SLOT(slotItemRelease(int,int,AppItem*)));
connect(item,SIGNAL(mouseEntered(AppItem*)),this,SLOT(slotItemEntered(AppItem*)));
connect(item, SIGNAL(mouseExited(AppItem*)),this,SLOT(slotItemExited(AppItem*)));
relayout();
}
@ -103,6 +106,42 @@ void DockLayout::relayout()
}
}
void DockLayout::dragoutFromLayout(int index)
{
AppItem * tmpItem = appList.takeAt(index);
tmpItem->setVisible(false);
if (index == appList.count())//note,target hast been remove before
{
qWarning() << "out of range...";
return;//at the end of list
}
//move follow item,note,target hast been remove before
AppItem * followItem = appList.at(index);
followItem->setNextPos(followItem->x() - tmpItem->width() - itemSpacing,0);
//move last item
for (int i = index + 1; i < appList.count(); i ++)
{
AppItem * frontItem = appList.at(i - 1);
AppItem * targetItem = appList.at(i);
targetItem->setNextPos(frontItem->getNextPos().x() + frontItem->width() + itemSpacing,0);
}
for (int i = index; i < appList.count(); i ++)
{
AppItem *button= appList.at(i);
QPropertyAnimation *animation = new QPropertyAnimation(button, "pos");
animation->setStartValue(button->pos());
animation->setEndValue(button->getNextPos());
animation->setDuration(500 + i * 100);
animation->setEasingCurve(QEasingCurve::InOutBack);
animation->start();
}
}
void DockLayout::sortLeftToRight()
{
if (appList.count() <= 0)
@ -134,7 +173,7 @@ void DockLayout::sortBottomToTop()
int DockLayout::indexOf(AppItem *item)
{
return appList.indexOf(item);
return appList.indexOf(item);
}
int DockLayout::indexOf(int x, int y)
@ -145,5 +184,32 @@ int DockLayout::indexOf(int x, int y)
void DockLayout::slotItemDrag(int x, int y, AppItem *item)
{
qWarning() << "Item draging..."<<x<<y<<item;
// qWarning() << "Item draging..."<<x<<y<<item;
int tmpIndex = indexOf(item);
if (tmpIndex != -1)
{
dragoutFromLayout(tmpIndex);
}
}
void DockLayout::slotItemRelease(int x, int y, AppItem *item)
{
//outside frame,destroy it
//inside frame,insert it
item->setVisible(true);
if (indexOf(item) == -1)
{
qWarning() << "---------" << lastHoverIndex;
insertItem(item,lastHoverIndex);
}
}
void DockLayout::slotItemEntered(AppItem *item)
{
this->lastHoverIndex = indexOf(item);
}
void DockLayout::slotItemExited(AppItem *item)
{
}

View File

@ -3,6 +3,8 @@
#include <QWidget>
#include <QList>
#include <QMap>
#include <QPropertyAnimation>
#include "appitem.h"
class DockLayout : public QWidget
@ -36,6 +38,7 @@ public:
void setSpacing(qreal spacing);
void setSortDirection(DockLayout::Direction value);
void relayout();
void dragoutFromLayout(int index);
int indexOf(AppItem * item);
int indexOf(int x,int y);
@ -45,6 +48,9 @@ public slots:
private slots:
void slotItemDrag(int x,int y,AppItem *item);
void slotItemRelease(int x, int y, AppItem *item);
void slotItemEntered(AppItem *item);
void slotItemExited(AppItem *item);
private:
void sortLeftToRight();
@ -54,6 +60,7 @@ private:
private:
QList<AppItem *> appList;
QMap<AppItem *,int> tmpAppMap;//only one item inside
DockLayout::Direction sortDirection = DockLayout::LeftToRight;
qreal itemSpacing = 10;
@ -61,6 +68,8 @@ private:
qreal rightMargin = 0;
qreal topMargin = 0;
qreal bottomMargin = 0;
int lastHoverIndex = 0;
};
#endif // DOCKLAYOUT_H

View File

@ -1,5 +1,23 @@
<RCC>
<qresource prefix="/test">
<file>Resources/images/google-chrome.png</file>
<file>Resources/images/brasero.png</file>
<file>Resources/images/crossover.png</file>
<file>Resources/images/d-feet.png</file>
<file>Resources/images/deepin-multitasking-view.svg</file>
<file>Resources/images/display-im6.q16.png</file>
<file>Resources/images/eog.png</file>
<file>Resources/images/file-roller.png</file>
<file>Resources/images/gcr-gnupg.png</file>
<file>Resources/images/gcr-key-pair.png</file>
<file>Resources/images/gcr-key.png</file>
<file>Resources/images/gcr-password.png</file>
<file>Resources/images/gcr-smart-card.png</file>
<file>Resources/images/gparted.png</file>
<file>Resources/images/inkscape.png</file>
<file>Resources/images/QtProject-qtcreator.png</file>
<file>Resources/images/remmina.png</file>
<file>Resources/images/terminator.png</file>
<file>Resources/images/vim.png</file>
</qresource>
</RCC>