mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Merge pull request #2573 from jfmherokiller/dragndrop
Added drag and drop feature to the code
This commit is contained in:
		
						commit
						0c28f5dea6
					
				
					 2 changed files with 41 additions and 1 deletions
				
			
		|  | @ -54,7 +54,7 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); | |||
| 
 | ||||
| GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { | ||||
|     Pica::g_debug_context = Pica::DebugContext::Construct(); | ||||
| 
 | ||||
|     setAcceptDrops(true); | ||||
|     ui.setupUi(this); | ||||
|     statusBar()->hide(); | ||||
| 
 | ||||
|  | @ -625,6 +625,40 @@ void GMainWindow::closeEvent(QCloseEvent* event) { | |||
|     QWidget::closeEvent(event); | ||||
| } | ||||
| 
 | ||||
| bool IsSingleFileDropEvent(QDropEvent* event) { | ||||
|     const QMimeData* mimeData = event->mimeData(); | ||||
|     return mimeData->hasUrls() && mimeData->urls().length() == 1; | ||||
| } | ||||
| 
 | ||||
| void GMainWindow::dropEvent(QDropEvent* event) { | ||||
|     if (IsSingleFileDropEvent(event) && ConfirmChangeGame()) { | ||||
|         const QMimeData* mimeData = event->mimeData(); | ||||
|         QString filename = mimeData->urls().at(0).toLocalFile(); | ||||
|         BootGame(filename.toStdString()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GMainWindow::dragEnterEvent(QDragEnterEvent* event) { | ||||
|     if (IsSingleFileDropEvent(event)) { | ||||
|         event->acceptProposedAction(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GMainWindow::dragMoveEvent(QDragMoveEvent* event) { | ||||
|     event->acceptProposedAction(); | ||||
| } | ||||
| 
 | ||||
| bool GMainWindow::ConfirmChangeGame() { | ||||
|     if (emu_thread == nullptr) | ||||
|         return true; | ||||
| 
 | ||||
|     auto answer = QMessageBox::question( | ||||
|         this, tr("Citra"), | ||||
|         tr("Are you sure you want to stop the emulation? Any unsaved progress will be lost."), | ||||
|         QMessageBox::Yes | QMessageBox::No, QMessageBox::No); | ||||
|     return answer != QMessageBox::No; | ||||
| } | ||||
| 
 | ||||
| #ifdef main | ||||
| #undef main | ||||
| #endif | ||||
|  |  | |||
|  | @ -110,6 +110,7 @@ private: | |||
|      * @return true if the user confirmed | ||||
|      */ | ||||
|     bool ConfirmClose(); | ||||
|     bool ConfirmChangeGame(); | ||||
|     void closeEvent(QCloseEvent* event) override; | ||||
| 
 | ||||
| private slots: | ||||
|  | @ -155,6 +156,11 @@ private: | |||
|     WaitTreeWidget* waitTreeWidget; | ||||
| 
 | ||||
|     QAction* actions_recent_files[max_recent_files_item]; | ||||
| 
 | ||||
| protected: | ||||
|     void dropEvent(QDropEvent* event) override; | ||||
|     void dragEnterEvent(QDragEnterEvent* event) override; | ||||
|     void dragMoveEvent(QDragMoveEvent* event) override; | ||||
| }; | ||||
| 
 | ||||
| #endif // _CITRA_QT_MAIN_HXX_
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue