mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 06:26:49 +00:00
Qt: improve VFS dialog a bit
- use normal selection instead of doubleclick - move SaveSettings out of the tabs to reduce file access - translate EmptyPath as well - some other minor refactors to reduce lines of code
This commit is contained in:
parent
4c6ceeff11
commit
bda466c3bd
4 changed files with 31 additions and 61 deletions
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <QFileDialog>
|
||||
#include <QCoreApplication>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
|
||||
|
||||
|
|
@ -13,27 +11,29 @@ vfs_dialog_tab::vfs_dialog_tab(const vfs_settings_info& settingsInfo, std::share
|
|||
m_dirList = new QListWidget(this);
|
||||
|
||||
QStringList alldirs = m_gui_settings->GetValue(m_info.listLocation).toStringList();
|
||||
const QString current_dir = qstr(m_info.cfg_node->to_string());
|
||||
|
||||
QListWidgetItem* selected_item = nullptr;
|
||||
|
||||
// We must show the currently selected config.
|
||||
if (alldirs.contains(EmuConfigDir()) == false)
|
||||
{
|
||||
new QListWidgetItem(EmuConfigDir(), m_dirList);
|
||||
}
|
||||
for (const QString& dir : alldirs)
|
||||
{
|
||||
new QListWidgetItem(dir, m_dirList);
|
||||
QListWidgetItem* item = new QListWidgetItem(dir, m_dirList);
|
||||
if (dir == current_dir)
|
||||
selected_item = item;
|
||||
}
|
||||
|
||||
// We must show the currently selected config.
|
||||
if (!selected_item)
|
||||
selected_item = new QListWidgetItem(current_dir, m_dirList);
|
||||
|
||||
selected_item->setSelected(true);
|
||||
|
||||
m_dirList->setMinimumWidth(m_dirList->sizeHintForColumn(0));
|
||||
|
||||
QHBoxLayout* selectedConfigLayout = new QHBoxLayout;
|
||||
QLabel* selectedMessage = new QLabel(m_info.name + " directory:");
|
||||
m_selectedConfigLabel = new QLabel();
|
||||
m_selectedConfigLabel->setText(EmuConfigDir());
|
||||
if (m_selectedConfigLabel->text() == "")
|
||||
{
|
||||
m_selectedConfigLabel->setText(EmptyPath);
|
||||
}
|
||||
m_selectedConfigLabel->setText(current_dir.isEmpty() ? EmptyPath : current_dir);
|
||||
selectedConfigLayout->addWidget(selectedMessage);
|
||||
selectedConfigLayout->addWidget(m_selectedConfigLabel);
|
||||
selectedConfigLayout->addStretch();
|
||||
|
|
@ -44,52 +44,34 @@ vfs_dialog_tab::vfs_dialog_tab(const vfs_settings_info& settingsInfo, std::share
|
|||
|
||||
setLayout(vbox);
|
||||
|
||||
connect(m_dirList, &QListWidget::itemDoubleClicked, [this](QListWidgetItem* item)
|
||||
connect(m_dirList, &QListWidget::currentItemChanged, [this](QListWidgetItem* current, QListWidgetItem*)
|
||||
{
|
||||
if (item->text() == "")
|
||||
{
|
||||
m_selectedConfigLabel->setText(EmptyPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_selectedConfigLabel->setText(item->text());
|
||||
}
|
||||
m_selectedConfigLabel->setText(current->text().isEmpty() ? EmptyPath : current->text());
|
||||
});
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::SaveSettings()
|
||||
void vfs_dialog_tab::SetSettings()
|
||||
{
|
||||
QStringList allDirs;
|
||||
for (int i = 0; i < m_dirList->count(); ++i)
|
||||
{
|
||||
allDirs += m_dirList->item(i)->text();
|
||||
}
|
||||
|
||||
m_gui_settings->SetValue(m_info.listLocation, allDirs);
|
||||
if (m_selectedConfigLabel->text() == EmptyPath)
|
||||
{
|
||||
m_info.cfg_node->from_string("");
|
||||
m_emu_settings->SetSetting(m_info.settingLoc, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_info.cfg_node->from_string(sstr(m_selectedConfigLabel->text()));
|
||||
m_emu_settings->SetSetting(m_info.settingLoc, sstr(m_selectedConfigLabel->text()));
|
||||
}
|
||||
m_emu_settings->SaveSettings();
|
||||
|
||||
const std::string new_dir = m_selectedConfigLabel->text() == EmptyPath ? "" : sstr(m_selectedConfigLabel->text());
|
||||
m_info.cfg_node->from_string(new_dir);
|
||||
m_emu_settings->SetSetting(m_info.settingLoc, new_dir);
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::Reset()
|
||||
{
|
||||
const QString current_dir = qstr(m_info.cfg_node->to_string());
|
||||
m_dirList->clear();
|
||||
m_info.cfg_node->from_default();
|
||||
m_selectedConfigLabel->setText(EmuConfigDir());
|
||||
if (m_selectedConfigLabel->text() == "")
|
||||
{
|
||||
m_selectedConfigLabel->setText(EmptyPath);
|
||||
}
|
||||
m_dirList->addItem(new QListWidgetItem(EmuConfigDir()));
|
||||
m_gui_settings->SetValue(m_info.listLocation, QStringList(EmuConfigDir()));
|
||||
m_selectedConfigLabel->setText(current_dir.isEmpty() ? EmptyPath : current_dir);
|
||||
m_dirList->addItem(new QListWidgetItem(current_dir));
|
||||
m_gui_settings->SetValue(m_info.listLocation, QStringList(current_dir));
|
||||
}
|
||||
|
||||
void vfs_dialog_tab::AddNewDirectory()
|
||||
|
|
@ -102,8 +84,3 @@ void vfs_dialog_tab::AddNewDirectory()
|
|||
m_selectedConfigLabel->setText(dir);
|
||||
}
|
||||
}
|
||||
|
||||
QString vfs_dialog_tab::EmuConfigDir()
|
||||
{
|
||||
return qstr(m_info.cfg_node->to_string());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue