Support dragging files

pull/2/head
wh201906 5 years ago
parent e34c36e572
commit 2b8e31e452

@ -14,18 +14,30 @@ int main(int argc, char *argv[])
QVariant lang = settings->value("lang", "null"); QVariant lang = settings->value("lang", "null");
if(lang == "null") if(lang == "null")
{ {
#ifdef Q_OS_WIN
lang = "lang/en_US.qm"; lang = "lang/en_US.qm";
#else
lang = "lang/en_US.ts";
#endif
QStringList langList; QStringList langList;
langList.append("English"); langList.append("English");
langList.append("简体中文"); langList.append("简体中文");
QString seletedText = QInputDialog::getItem(&w, "", "Choose a language:", langList, 0, false); QString seletedText = QInputDialog::getItem(&w, "", "Choose a language:", langList, 0, false);
if(seletedText == "English") if(seletedText == "English")
{ {
#ifdef Q_OS_WIN
lang = "lang/en_US.qm"; lang = "lang/en_US.qm";
#else
lang = "lang/en_US.ts";
#endif
} }
else if(seletedText == "简体中文") else if(seletedText == "简体中文")
{ {
#ifdef Q_OS_WIN
lang = "lang/zh_CN.qm"; lang = "lang/zh_CN.qm";
#else
lang = "lang/zh_CN.ts";
#endif
} }
} }
QTranslator* translator = new QTranslator(&w); QTranslator* translator = new QTranslator(&w);

@ -522,6 +522,9 @@ void MainWindow::uiInit()
typeBtnGroup->addButton(ui->MF_Type_4kButton, 4); typeBtnGroup->addButton(ui->MF_Type_4kButton, 4);
connect(typeBtnGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MainWindow::MF_onTypeChanged); connect(typeBtnGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MainWindow::MF_onTypeChanged);
ui->MF_keyWidget->installEventFilter(this);
ui->MF_dataWidget->installEventFilter(this);
on_Raw_CMDHistoryBox_stateChanged(Qt::Unchecked); on_Raw_CMDHistoryBox_stateChanged(Qt::Unchecked);
on_PM3_refreshPortButton_clicked(); on_PM3_refreshPortButton_clicked();
} }
@ -554,4 +557,46 @@ void MainWindow::setTableItem(QTableWidget* widget, int row, int column, const Q
widget->setItem(row, column, new QTableWidgetItem()); widget->setItem(row, column, new QTableWidgetItem());
widget->item(row, column)->setText(text); widget->item(row, column)->setText(text);
} }
bool MainWindow::eventFilter(QObject *watched, QEvent *event) // drag support
{
if(event->type() == QEvent::DragEnter)
{
QDragEnterEvent* dragEvent = static_cast<QDragEnterEvent*>(event);
dragEvent->acceptProposedAction();
return true;
}
else if(event->type() == QEvent::Drop)
{
QDropEvent* dropEvent = static_cast<QDropEvent*>(event);
if(watched == ui->MF_keyWidget)
{
const QMimeData* mime = dropEvent->mimeData();
if(mime->hasUrls())
{
QList<QUrl> urls = mime->urls();
if(urls.length() == 1)
{
mifare->data_loadKeyFile(urls[0].toLocalFile());
return true;
}
}
}
else if(watched == ui->MF_dataWidget)
{
const QMimeData* mime = dropEvent->mimeData();
if(mime->hasUrls())
{
QList<QUrl> urls = mime->urls();
if(urls.length() == 1)
{
mifare->data_loadDataFile(urls[0].toLocalFile());
return true;
}
}
}
}
return QMainWindow::eventFilter(watched, event);
}
// *********************************************** // ***********************************************

@ -13,6 +13,7 @@
#include <QFontDialog> #include <QFontDialog>
#include <QtSerialPort/QSerialPortInfo> #include <QtSerialPort/QSerialPortInfo>
#include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPort>
#include <QMimeData>
#include "common/pm3process.h" #include "common/pm3process.h"
#include "module/mifare.h" #include "module/mifare.h"
@ -33,6 +34,7 @@ public:
~MainWindow(); ~MainWindow();
void initUI(); void initUI();
bool eventFilter(QObject *watched, QEvent *event);
public slots: public slots:
void refreshOutput(const QString &output); void refreshOutput(const QString &output);
void refreshCMD(const QString &cmd); void refreshCMD(const QString &cmd);

@ -144,6 +144,9 @@
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
@ -284,6 +287,9 @@
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>

Loading…
Cancel
Save