mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-19 06:45:39 +00:00
Qt: Implement drag/drop file on main window
This commit is contained in:
parent
eca0b51008
commit
4685d66a2b
|
@ -22,6 +22,7 @@
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtCore/QMimeData>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtGui/QCursor>
|
#include <QtGui/QCursor>
|
||||||
#include <QtGui/QWindowStateChangeEvent>
|
#include <QtGui/QWindowStateChangeEvent>
|
||||||
|
@ -609,26 +610,7 @@ void MainWindow::onGameListEntrySelected(const GameListEntry* entry)
|
||||||
|
|
||||||
void MainWindow::onGameListEntryDoubleClicked(const GameListEntry* entry)
|
void MainWindow::onGameListEntryDoubleClicked(const GameListEntry* entry)
|
||||||
{
|
{
|
||||||
// if we're not running, boot the system, otherwise swap discs
|
startGameOrChangeDiscs(entry->path);
|
||||||
QString path = QString::fromStdString(entry->path);
|
|
||||||
if (!m_emulation_running)
|
|
||||||
{
|
|
||||||
if (!entry->code.empty() && m_host_interface->GetBoolSettingValue("Main", "SaveStateOnExit", true) &&
|
|
||||||
!m_host_interface->IsCheevosChallengeModeActive())
|
|
||||||
{
|
|
||||||
m_host_interface->resumeSystemFromState(path, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_host_interface->bootSystem(std::make_shared<const SystemBootParameters>(path.toStdString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_host_interface->changeDisc(path);
|
|
||||||
m_host_interface->pauseSystem(false);
|
|
||||||
switchToEmulationView();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameListEntry* entry)
|
void MainWindow::onGameListContextMenuRequested(const QPoint& point, const GameListEntry* entry)
|
||||||
|
@ -952,6 +934,34 @@ void MainWindow::switchToEmulationView()
|
||||||
m_display_widget->setFocus();
|
m_display_widget->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::startGameOrChangeDiscs(const std::string& path)
|
||||||
|
{
|
||||||
|
// if we're not running, boot the system, otherwise swap discs
|
||||||
|
if (!m_emulation_running)
|
||||||
|
{
|
||||||
|
if (m_host_interface->GetBoolSettingValue("Main", "SaveStateOnExit", true) &&
|
||||||
|
!m_host_interface->IsCheevosChallengeModeActive())
|
||||||
|
{
|
||||||
|
const GameListEntry* entry = m_host_interface->getGameList()->GetEntryForPath(path.c_str());
|
||||||
|
if ((entry && !entry->code.empty()) || !System::GetGameCodeForPath(path.c_str(), true).empty())
|
||||||
|
{
|
||||||
|
m_host_interface->resumeSystemFromState(QString::fromStdString(path), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_host_interface->bootSystem(std::make_shared<const SystemBootParameters>(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_host_interface->changeDisc(QString::fromStdString(path));
|
||||||
|
m_host_interface->pauseSystem(false);
|
||||||
|
switchToEmulationView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::connectSignals()
|
void MainWindow::connectSignals()
|
||||||
{
|
{
|
||||||
updateEmulationActions(false, false, m_host_interface->IsCheevosChallengeModeActive());
|
updateEmulationActions(false, false, m_host_interface->IsCheevosChallengeModeActive());
|
||||||
|
@ -1418,6 +1428,39 @@ void MainWindow::changeEvent(QEvent* event)
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string getFilenameFromMimeData(const QMimeData* md)
|
||||||
|
{
|
||||||
|
std::string filename;
|
||||||
|
if (md->hasUrls())
|
||||||
|
{
|
||||||
|
// only one url accepted
|
||||||
|
const QList<QUrl> urls(md->urls());
|
||||||
|
if (urls.size() == 1)
|
||||||
|
filename = urls.front().toLocalFile().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
||||||
|
{
|
||||||
|
const std::string filename(getFilenameFromMimeData(event->mimeData()));
|
||||||
|
if (!System::IsLoadableFilename(filename.c_str()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::dropEvent(QDropEvent* event)
|
||||||
|
{
|
||||||
|
const std::string filename(getFilenameFromMimeData(event->mimeData()));
|
||||||
|
if (!System::IsLoadableFilename(filename.c_str()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
|
startGameOrChangeDiscs(filename);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::startupUpdateCheck()
|
void MainWindow::startupUpdateCheck()
|
||||||
{
|
{
|
||||||
if (!m_host_interface->GetBoolSettingValue("AutoUpdater", "CheckAtStartup", true))
|
if (!m_host_interface->GetBoolSettingValue("AutoUpdater", "CheckAtStartup", true))
|
||||||
|
|
|
@ -111,6 +111,8 @@ private Q_SLOTS:
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent* event) override;
|
void closeEvent(QCloseEvent* event) override;
|
||||||
void changeEvent(QEvent* event) override;
|
void changeEvent(QEvent* event) override;
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupAdditionalUi();
|
void setupAdditionalUi();
|
||||||
|
@ -120,6 +122,7 @@ private:
|
||||||
bool isShowingGameList() const;
|
bool isShowingGameList() const;
|
||||||
void switchToGameListView();
|
void switchToGameListView();
|
||||||
void switchToEmulationView();
|
void switchToEmulationView();
|
||||||
|
void startGameOrChangeDiscs(const std::string& path);
|
||||||
void saveStateToConfig();
|
void saveStateToConfig();
|
||||||
void restoreStateFromConfig();
|
void restoreStateFromConfig();
|
||||||
void saveDisplayWindowGeometryToConfig();
|
void saveDisplayWindowGeometryToConfig();
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
<iconset resource="resources/resources.qrc">
|
<iconset resource="resources/resources.qrc">
|
||||||
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
|
<normaloff>:/icons/duck.png</normaloff>:/icons/duck.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<widget class="QStackedWidget" name="mainContainer">
|
<widget class="QStackedWidget" name="mainContainer">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
|
Loading…
Reference in a new issue