1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Adds drag-and-drop snapshot support for Qt.

This commit is contained in:
Thomas Harte 2021-06-13 21:41:20 -04:00
parent 56c30e1651
commit 1c1719e561
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> &&);