Merge pull request #353 from pyjamasam/drag_and_drop

Support dragging and dropping of files onto app icon
This commit is contained in:
Collin Kidder
2021-05-25 18:48:58 -04:00
committed by GitHub
6 changed files with 123 additions and 4 deletions
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>${ASSETCATALOG_COMPILER_APPICON_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>${QMAKE_PKGINFO_TYPEINFO}</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>asc</string>
<string>avc</string>
<string>blf</string>
<string>can</string>
<string>crt</string>
<string>crtd</string>
<string>csv</string>
<string>evc</string>
<string>log</string>
<string>qcc</string>
<string>trace</string>
<string>trc</string>
<string>txt</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>
+3
View File
@@ -16,6 +16,9 @@ DEFINES += QCUSTOMPLOT_USE_OPENGL
TARGET = SavvyCAN
TEMPLATE = app
QMAKE_INFO_PLIST = Info.plist.template
ICON = icons/SavvyIcon.icns
SOURCES += main.cpp\
connections/mqtt_bus.cpp \
mqtt/qmqtt_client.cpp \
Binary file not shown.
+29 -4
View File
@@ -1,9 +1,30 @@
#include "mainwindow.h"
#include <QApplication>
class SavvyCANApplication : public QApplication
{
public:
MainWindow *mainWindow;
SavvyCANApplication(int &argc, char **argv) : QApplication(argc, argv)
{
}
bool event(QEvent *event) override
{
if (event->type() == QEvent::FileOpen)
{
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event);
mainWindow->handleDroppedFile(openEvent->file());
}
return QApplication::event(event);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SavvyCANApplication a(argc, argv);
//Add a local path for Qt extensions, to allow for per-application extensions.
a.addLibraryPath("plugins");
@@ -14,7 +35,7 @@ int main(int argc, char *argv[])
a.setOrganizationDomain("evtv.me");
QSettings::setDefaultFormat(QSettings::IniFormat);
MainWindow w;
a.mainWindow = new MainWindow();
QSettings settings;
int fontSize = settings.value("Main/FontSize", 9).toUInt();
@@ -22,7 +43,11 @@ int main(int argc, char *argv[])
sysFont.setPointSize(fontSize);
a.setFont(sysFont);
w.show();
a.mainWindow->show();
return a.exec();
int retCode = a.exec();
delete a.mainWindow; a.mainWindow = NULL;
return retCode;
}
+44
View File
@@ -807,6 +807,50 @@ void MainWindow::handleLoadFile()
}
}
void MainWindow::handleDroppedFile(const QString &filename)
{
QProgressDialog progress(qApp->activeWindow());
progress.setWindowModality(Qt::WindowModal);
progress.setLabelText("Loading file...");
progress.setCancelButton(nullptr);
progress.setRange(0,0);
progress.setMinimumDuration(0);
progress.show();
QVector<CANFrame> loadedFrames;
bool loadResult = FrameFileIO::autoDetectLoadFile(filename, &loadedFrames);
progress.cancel();
if (!loadResult)
{
if (loadedFrames.count() > 0) //only ask if at least one frame was decoded.
{
QMessageBox::StandardButton confirmDialog = QMessageBox::question(this, "Error Loading", "Do you want to salvage what could be loaded?",
QMessageBox::Yes|QMessageBox::No);
if (confirmDialog == QMessageBox::Yes)
{
loadResult = true;
}
}
}
if (loadResult)
{
ui->canFramesView->scrollToTop();
model->clearFrames();
model->insertFrames(loadedFrames);
loadedFileName = filename;
model->recalcOverwrite();
ui->lbNumFrames->setText(QString::number(model->rowCount()));
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
updateFileStatus();
emit framesUpdated(-1);
}
}
void MainWindow::handleSaveFile()
{
QString filename;
+2
View File
@@ -54,6 +54,8 @@ public:
CANFrameModel * getCANFrameModel();
~MainWindow();
void handleDroppedFile(const QString &filename);
private slots:
void handleLoadFile();
void handleSaveFile();