-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovablebutton.cpp
More file actions
54 lines (46 loc) · 2.44 KB
/
movablebutton.cpp
File metadata and controls
54 lines (46 loc) · 2.44 KB
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
#include "movablebutton.h"
#include <iostream>
void MovableButton::mouseMoveEvent( QMouseEvent *event )
{
if( event->buttons() & Qt::LeftButton )
{
being_moved=true;
std::cout << event->globalPos().x() << "parent x: "<<parentWidget()->whatsThis().toStdString()<<std::endl;
std::cout << parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).x() << std::endl;
if(event->globalPos().y()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).y() <= (parentWidget()->size().height()-this->height()) &&
event->globalPos().y()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).y() >= 0 &&
event->globalPos().x()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).x() >= 0)
{
move( event->globalPos().x()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).x(),
event->globalPos().y()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).y());
std::cout << "IF VALUES: "<<event->globalPos().y()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).y() <<std::endl;
std::cout << (parentWidget()->size().height()-this->height()) <<std::endl;
}
//porta oltre e smette di muovere. e quindi non aggiorna la minwidth. bottone sembra sparire invece è solo out of scope.
}
//rifare e invece che tenere come termine di paragone curr width settare ext button.
}
void MovableButton::mousePressEvent(QMouseEvent* e)
{
QAbstractButton::mousePressEvent(e);
}
void MovableButton::mouseReleaseEvent(QMouseEvent* event)
{
if (!being_moved)
{
QAbstractButton::mouseReleaseEvent(event);
}
else
{
being_moved = false;
std::cout<<"before: "<< parentWidget()->size().width()<<std::endl;
std::cout<<parentWidget()->size().height()<<std::endl;
std::cout<<"aaaa: "<< event->globalPos().x()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).x()<<std::endl;
std::cout<<event->globalPos().y()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).y()<<std::endl;
//parentWidget()->adjustSize();
parentWidget()->setMinimumWidth(std::max(event->globalPos().x()-parentWidget()->mapToGlobal(parentWidget()->rect().topLeft()).x()+this->width(), parentWidget()->size().width()));
std::cout<<"after:" <<parentWidget()->size().width()<<std::endl;
std::cout<<parentWidget()->size().height()<<std::endl;
}
}
#include "movablebutton.moc"