153 lines
3.1 KiB
C++
153 lines
3.1 KiB
C++
#include "DragButton.h"
|
|
|
|
DragButton::DragButton(QWidget *parent) :
|
|
QPushButton(parent)
|
|
{
|
|
this->setText(tr("Command"));
|
|
|
|
this->setAcceptDrops(true);
|
|
|
|
ischanged = true;
|
|
isCanDrag = true;
|
|
isCanEdit = true;
|
|
}
|
|
|
|
DragButton::~DragButton()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void DragButton::keyPressEvent(QKeyEvent* event)
|
|
{
|
|
QWidget::keyPressEvent(event);
|
|
}
|
|
void DragButton::keyReleaseEvent(QKeyEvent* event)
|
|
{
|
|
QWidget::keyReleaseEvent(event);
|
|
}
|
|
|
|
|
|
void DragButton::mousePressEvent(QMouseEvent *event)
|
|
{
|
|
emit pressed();
|
|
if (event->button() == Qt::LeftButton) {
|
|
if(isCanDrag)
|
|
{
|
|
m_point = event->globalPos() - pos();
|
|
event->accept();
|
|
}
|
|
}
|
|
else if (event->button() == Qt::RightButton) {
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
QAction *pAction = new QAction("del",this);
|
|
|
|
|
|
connect(pAction,&QAction::triggered,
|
|
this,&DragButton::deleteLater);
|
|
|
|
|
|
|
|
menu->addAction(pAction);
|
|
menu->move(cursor().pos());
|
|
menu->show();
|
|
|
|
event->accept();
|
|
}
|
|
|
|
}
|
|
|
|
void DragButton::mouseReleaseEvent(QMouseEvent *event)
|
|
{
|
|
emit released();
|
|
event->accept();
|
|
}
|
|
|
|
void DragButton::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
if (event->buttons() & Qt::LeftButton) {
|
|
if(isCanDrag)
|
|
{
|
|
move(event->globalPos() - m_point);
|
|
event->accept();
|
|
}
|
|
}
|
|
}
|
|
|
|
void DragButton::mouseDoubleClickEvent(QMouseEvent *event)
|
|
{
|
|
QLineEdit *l = new QLineEdit(this);
|
|
|
|
l->setAlignment(Qt::AlignHCenter);
|
|
l->setText(this->text());
|
|
l->selectAll();
|
|
l->setFocus();
|
|
|
|
connect(l,&QLineEdit::textChanged,
|
|
this,&DragButton::setText);
|
|
|
|
connect(l,&QLineEdit::textChanged,
|
|
this,&DragButton::TextChanged);
|
|
|
|
connect(l,&QLineEdit::editingFinished,
|
|
l,&QLineEdit::deleteLater);
|
|
|
|
l->resize(this->width()-2,this->height()-2);
|
|
l->move(1,1);
|
|
l->show();
|
|
|
|
event->accept();
|
|
}
|
|
|
|
|
|
void DragButton::setParameters(QVariant row,
|
|
QVariant column,
|
|
QVariant notice,
|
|
QVariant command,
|
|
QVariant confirm,
|
|
QVariant param1,
|
|
QVariant param2,
|
|
QVariant param3,
|
|
QVariant param4,
|
|
QVariant param5,
|
|
QVariant param6,
|
|
QVariant param7)
|
|
{
|
|
m_row = row;
|
|
m_column = column;
|
|
m_notice = notice;
|
|
m_command = command;
|
|
m_confirm = confirm;
|
|
m_param1 = param1;
|
|
m_param2 = param2;
|
|
m_param3 = param3;
|
|
m_param4 = param4;
|
|
m_param5 = param5;
|
|
m_param6 = param6;
|
|
m_param7 = param7;
|
|
|
|
setChanged(true);
|
|
}
|
|
|
|
/*
|
|
bool DragButton::setProperty(const char *name, const QVariant &value)
|
|
{
|
|
return QPushButton::setProperty(name,value);
|
|
}
|
|
*/
|
|
|
|
void DragButton::setChanged(bool flag)
|
|
{
|
|
ischanged = flag;
|
|
/*
|
|
if(this->text().right(1) != tr("*"))
|
|
{
|
|
this->setText(this->text().append(tr("*")));
|
|
}
|
|
*/
|
|
|
|
}
|
|
|