11#include " stylingparams.h"
22#include < QPainter>
3- #include < KMessageBox>
43#include < QDebug>
54#include < QMouseEvent>
65#include < QTimer>
76#include < QApplication>
87#include < QGridLayout>
8+ #include < QDrag>
9+ #include < QMimeData>
10+ #include < QMimeData>
11+
912#include < KRun>
13+ #include < KService>
14+ #include < KDesktopFile>
1015
1116#include " icongriditemcanvas.h"
1217#include " kapplication.h"
1318#include " stylingparams.h"
19+ #include " tools/rocketconfigmanager.h"
1420
1521IconGridItemCanvas::IconGridItemCanvas (QWidget *parent, KApplication application)
1622{
1723 m_icon = application.icon ();
1824 m_application = application;
1925 setMouseTracking (true );
26+ setAcceptDrops (true );
2027
2128 // QPalette p;
2229 // setAutoFillBackground(true);
@@ -41,13 +48,40 @@ void IconGridItemCanvas::mousePressEvent(QMouseEvent *event)
4148 {
4249 m_clicked = true ;
4350 m_pressPos = QCursor::pos ();
44- QTimer * timer = new QTimer ();
45- connect (timer,&QTimer::timeout,this ,&IconGridItemCanvas::longpressanimation);
46- timer->start (1000 );
47- timer->setSingleShot (true );
48- event->ignore ();
51+ m_longclicktimer = new QTimer ();
52+ connect (m_longclicktimer,&QTimer::timeout,this ,&IconGridItemCanvas::m_starticondragging);
53+ m_longclicktimer->setSingleShot (true );
54+ // m_longclicktimer->start(1000);
4955 }
50- event->accept ();
56+ event->ignore ();
57+ }
58+
59+ void IconGridItemCanvas::setDraggable (bool draggable)
60+ {
61+ m_draggable = draggable;
62+ }
63+
64+ void IconGridItemCanvas::m_starticondragging ()
65+ {
66+ if (!m_draggable)
67+ {
68+ return ;
69+ }
70+ if (m_clicked) // i.e. cursor has not moved a lot
71+ {
72+ iconDraggingOn (true );
73+ QDrag *drag = new QDrag (this );
74+ QMimeData *mime = new QMimeData;
75+ mime->setText (m_application.name ());
76+ drag->setMimeData (mime);
77+ drag->setPixmap (m_application.icon ().pixmap (size ()));
78+ drag->setHotSpot (QPoint (drag->pixmap ().width ()/2 ,drag->pixmap ().height ()/2 ));
79+ Qt::DropAction dropAction = drag->exec ();
80+ }
81+ else {
82+ iconDraggingOn (false );
83+ }
84+ m_clicked = false ;
5185}
5286
5387void IconGridItemCanvas::mouseMoveEvent (QMouseEvent *event)
@@ -56,6 +90,7 @@ void IconGridItemCanvas::mouseMoveEvent(QMouseEvent *event)
5690 int dy = QCursor::pos ().y ()-m_pressPos.y ();
5791 if (dx*dx+dy*dy>=RocketStyle::click_tolerance && m_clicked)
5892 {
93+ m_longclicktimer->stop ();
5994 m_clicked = false ;
6095 }
6196 event->ignore ();
@@ -67,35 +102,51 @@ void IconGridItemCanvas::mouseReleaseEvent(QMouseEvent *event)
67102 {
68103 m_clicked = false ;
69104 QList<QUrl> urls;
70- if (m_application.terminal ())
105+ KDesktopFile d (m_application.entrypath ());
106+ KService s (&d,m_application.entrypath ());
107+ if (KRun::run (s,urls,nullptr ))
71108 {
72- if (KRun::run (" konsole -e " +m_application.exec (),urls,nullptr ,m_application.name (),m_application.iconname ()))
73- {
74- qApp->exit ();
75- }
76- }
77- else {
78- if (KRun::run (m_application.exec (),urls,nullptr ,m_application.name (),m_application.iconname ())) {
79- qApp->exit ();
80- }
109+ qApp->exit ();
81110 }
82-
111+ event-> accept ();
83112 }
84113 else
85114 {
86115 event->ignore ();
87116 }
88117}
118+ /*
119+ void IconGridItemCanvas::dragEnterEvent(QDragEnterEvent *event)
120+ {
121+ qDebug() << "dragging into" << m_application.name();
122+ event->acceptProposedAction();
123+ }
89124
90- void IconGridItemCanvas::longpressanimation ( )
125+ void IconGridItemCanvas::dropEvent(QDropEvent *event )
91126{
92- if (m_clicked)
127+ qDebug() << "dropped" << event->mimeData()->text() << "on"<< m_application.name();
128+ iconDraggingOn(false);
129+ event->acceptProposedAction();
130+ }
131+
132+ void IconGridItemCanvas::dragMoveEvent(QDragMoveEvent *event)
133+ {
134+ //qDebug() << "dragMoveIconGriditem";
135+ if (event->source()!=this)
93136 {
94- KMessageBox::information (nullptr ," move_animation" );
95- m_clicked = false ;
137+ move(pos().x()+(width()/2-event->pos().x())*0.1,pos().y());
96138 }
139+ event->accept();
97140}
98141
142+ void IconGridItemCanvas::dragLeaveEvent(QDragLeaveEvent *event)
143+ {
144+ qDebug() << "dragging left";
145+ iconDraggingOn(false);
146+ update();
147+ event->ignore();
148+ }
149+ */
99150void IconGridItemCanvas::resizeEvent (QResizeEvent *event)
100151{
101152
0 commit comments