指令添加拖入功能

This commit is contained in:
hm
2021-04-23 16:09:26 +08:00
parent d7f21fcb74
commit efdc426f39
3 changed files with 59 additions and 58 deletions
+51 -55
View File
@@ -10,6 +10,8 @@ CommandUI::CommandUI(QWidget *parent) :
{
ui->setupUi(this);
this->setAcceptDrops(true);
m_parent = parent;
//检测文件夹,如果不存在,那么就新建一个,这里存着所有的qml文件
QDir *Dir = new QDir;
@@ -59,11 +61,30 @@ CommandUI::~CommandUI()
delete ui;
}
void CommandUI::wheelEvent(QWheelEvent *e)
void CommandUI::wheelEvent(QWheelEvent *event)
{
int max = ui->tabWidget_Command->count();
int current = ui->tabWidget_Command->currentIndex();
if(event->delta() < 0)
{
if(current < (max - 1))
{
current++;
ui->tabWidget_Command->setCurrentIndex(current);
}
}
else if(event->delta() > 0)
{
if(current > 0)
{
current--;
ui->tabWidget_Command->setCurrentIndex(current);
}
}
}
void CommandUI::keyPressEvent(QKeyEvent *event) //键盘按下事件
{
switch(event->key())
@@ -76,6 +97,35 @@ void CommandUI::keyPressEvent(QKeyEvent *event) //键盘按下事件
}
}
void CommandUI::dragEnterEvent(QDragEnterEvent *event)
{
if(!event->mimeData()->urls()[0].fileName().right(5).compare(tr(".json")))
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}
void CommandUI::dropEvent(QDropEvent *event)
{
const QMimeData *qm = event->mimeData();
QString fileName = qm->urls()[0].toLocalFile();
if(fileName.right(5) == ".json")
{
setCommandFile(fileName);
}
}
void CommandUI::mousePressEvent(QMouseEvent *event)
{
@@ -149,26 +199,6 @@ void CommandUI::updateUI(void)
CommandButton *btn = new CommandButton(ui->tabWidget_Command->widget(info.toObject().find(_PageJsonKey).value().toInt()));
/*
QVariant notice = binfo.toObject().find(_noticeJsonKey).value();
QVariant row = binfo.toObject().find(_colunmJsonKey).value();
QVariant column = binfo.toObject().find(_param7JsonKey).value();
QVariant notice = binfo.toObject().find(_param7JsonKey).value();
QVariant command= binfo.toObject().find(_param7JsonKey).value();
QVariant confirm= binfo.toObject().find(_param7JsonKey).value();
QVariant page = binfo.toObject().find(_param7JsonKey).value();
QVariant dialog = binfo.toObject().find(_param7JsonKey).value();
QVariant param1 = binfo.toObject().find(_param7JsonKey).value();
QVariant param2 = binfo.toObject().find(_param7JsonKey).value();
QVariant param3 = binfo.toObject().find(_param7JsonKey).value();
QVariant param4 = binfo.toObject().find(_param7JsonKey).value();
QVariant param5 = binfo.toObject().find(_param7JsonKey).value();
QVariant param6 = binfo.toObject().find(_param7JsonKey).value();
QVariant param7 = binfo.toObject().find(_param7JsonKey).value();
*/
btn->setParameters(binfo.toObject().find(_rowJsonKey).value().toVariant(),
binfo.toObject().find(_colunmJsonKey).value().toVariant(),
binfo.toObject().find(_noticeJsonKey).value().toVariant(),
@@ -184,25 +214,6 @@ void CommandUI::updateUI(void)
binfo.toObject().find(_param6JsonKey).value().toVariant(),
binfo.toObject().find(_param7JsonKey).value().toVariant());
/*
btn->setParameters(binfo.toObject().find(_rowJsonKey).value().toInt(),
binfo.toObject().find(_colunmJsonKey).value().toInt(),
binfo.toObject().find(_noticeJsonKey).value().toInt(),
binfo.toObject().find(_commandJsonKey).value().toInt(),
binfo.toObject().find(_confirmJsonKey).value().toInt(),
info.toObject().find(_PageJsonKey).value().toInt(),
binfo.toObject().find(_dialogJsonKey).value().toInt(),
binfo.toObject().find(_param1JsonKey).value().toInt(),
binfo.toObject().find(_param2JsonKey).value().toInt(),
binfo.toObject().find(_param3JsonKey).value().toInt(),
binfo.toObject().find(_param4JsonKey).value().toInt(),
binfo.toObject().find(_param5JsonKey).value().toInt(),
binfo.toObject().find(_param6JsonKey).value().toInt(),
binfo.toObject().find(_param7JsonKey).value().toInt());
*/
btn->show();
btn->raise();
@@ -469,21 +480,6 @@ void CommandUI::setSecondValue(QVariant value)
void CommandUI::on_commandClicked()
{
//qDebug() << "clicked";
/*
if(m_command == 0)
{
QMessageBox *msg = new QMessageBox();
msg->setWindowTitle(tr("Notice"));
msg->setText(tr("please set command first ,command :%1").arg(m_command));
msg->show();
return;
}
*/
//找到消息的发送者
CommandButton *btn = qobject_cast<CommandButton *>(sender());
+7 -2
View File
@@ -38,7 +38,9 @@
#include "Config/Config.h"
#include "QDragEnterEvent"
#include "QDropEvent"
#include "QMimeData"
#include "QMessageBox"
namespace Ui {
@@ -61,11 +63,14 @@ public:
~CommandUI();
protected:
void wheelEvent(QWheelEvent *e);
void wheelEvent(QWheelEvent *event);
void mousePressEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void loadCommandJson(const QString& jsonFilename);
public slots:
+1 -1
View File
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>422</width>
<height>348</height>
<height>414</height>
</rect>
</property>
<property name="windowTitle">