1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-05 10:28:58 +00:00

Merge pull request #949 from TomHarte/QtSnapshotDragAndDrop

Adds drag-and-drop snapshot support for Qt.
This commit is contained in:
Thomas Harte 2021-06-13 21:48:42 -04:00 committed by GitHub
commit 423fbc9ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -207,14 +207,15 @@ QString MainWindow::getFilename(const char *title) {
return fileName;
}
void MainWindow::insertFile(const QString &fileName) {
if(!machine) return;
bool MainWindow::insertFile(const QString &fileName) {
if(!machine) return false;
auto mediaTarget = machine->media_target();
if(!mediaTarget) return;
if(!mediaTarget) return false;
Analyser::Static::Media media = Analyser::Static::GetMedia(fileName.toStdString());
mediaTarget->insert_media(media);
const Analyser::Static::Media media = Analyser::Static::GetMedia(fileName.toStdString());
if(media.empty()) return false;
return mediaTarget->insert_media(media);
}
bool MainWindow::launchFile(const QString &fileName) {
@ -732,7 +733,10 @@ void MainWindow::dropEvent(QDropEvent* event) {
case UIPhase::RunningMachine: {
// Attempt to insert into the running machine.
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
insertFile(fileName);
if(!insertFile(fileName)) {
deleteMachine();
launchFile(fileName);
}
} break;
// TODO: permit multiple files dropped at once in both of the above cases.

View File

@ -104,7 +104,7 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
} keyboardInputMode;
QAction *insertAction = nullptr;
void insertFile(const QString &fileName);
bool insertFile(const QString &fileName);
bool launchFile(const QString &fileName);
void launchTarget(std::unique_ptr<Analyser::Static::Target> &&);