This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoolbutton.cpp
69 lines (55 loc) · 1.71 KB
/
toolbutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "toolbutton.h"
#include "mainwindow.h"
ToolButton::ToolButton(QGridLayout* layout, int numero, MainWindow* main ) : QToolButton(), gridLayout( layout ), numeroDansLaListe( numero ), mainWindow( main )
{
setAcceptDrops( true );
}
void ToolButton::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton )
{
startDragPosition = event->pos();
}
QToolButton::mousePressEvent(event);
}
void ToolButton::mouseMoveEvent(QMouseEvent *event )
{
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
if( (event->pos() - startDragPosition).manhattanLength() < QApplication::startDragDistance() )
{
return;
}
/* gridLayout->removeWidget( this );
gridLayout->update();
qDebug() << "test";*/
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setText( "Drag and Drop" );
mimeData->setData( "number", QString::number( numeroDansLaListe ).toUtf8() );
drag->setMimeData( mimeData );
drag->setPixmap( this->icon().pixmap( 64, 64 ) );
event->accept();
drag->exec(Qt::MoveAction);
mainWindow->updateProduit();
}
void ToolButton::dropEvent(QDropEvent *event)
{
int numeroActuel = event->mimeData()->data( "number" ).toInt();
int numeroCible = numeroDansLaListe;
QList<int> liste = Settings::getBoutonList();
int memoire = liste.at( numeroActuel );
liste.removeAt( numeroActuel );
liste.insert( numeroCible, memoire );
Settings::setBoutonList( liste );
event->acceptProposedAction();
}
void ToolButton::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("text/plain"))
{
event->acceptProposedAction();
}
}