mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 11:09:41 +00:00
Merge remote branch 'pvdk/filedialog'
This commit is contained in:
commit
4a726f272b
7 changed files with 150 additions and 43 deletions
|
@ -8,6 +8,7 @@ set(LAUNCHER
|
||||||
playpage.cpp
|
playpage.cpp
|
||||||
pluginsmodel.cpp
|
pluginsmodel.cpp
|
||||||
pluginsview.cpp
|
pluginsview.cpp
|
||||||
|
filedialog.cpp
|
||||||
|
|
||||||
launcher.rc
|
launcher.rc
|
||||||
)
|
)
|
||||||
|
@ -22,6 +23,7 @@ set(LAUNCHER_HEADER
|
||||||
playpage.hpp
|
playpage.hpp
|
||||||
pluginsmodel.hpp
|
pluginsmodel.hpp
|
||||||
pluginsview.hpp
|
pluginsview.hpp
|
||||||
|
filedialog.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Headers that must be pre-processed
|
# Headers that must be pre-processed
|
||||||
|
@ -34,6 +36,7 @@ set(LAUNCHER_HEADER_MOC
|
||||||
playpage.hpp
|
playpage.hpp
|
||||||
pluginsmodel.hpp
|
pluginsmodel.hpp
|
||||||
pluginsview.hpp
|
pluginsview.hpp
|
||||||
|
filedialog.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER} ${LAUNCHER_HEADER_MOC})
|
source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER} ${LAUNCHER_HEADER_MOC})
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "datafilespage.hpp"
|
#include "datafilespage.hpp"
|
||||||
#include "lineedit.hpp"
|
#include "lineedit.hpp"
|
||||||
|
#include "filedialog.hpp"
|
||||||
#include "naturalsort.hpp"
|
#include "naturalsort.hpp"
|
||||||
#include "pluginsmodel.hpp"
|
#include "pluginsmodel.hpp"
|
||||||
#include "pluginsview.hpp"
|
#include "pluginsview.hpp"
|
||||||
|
@ -203,8 +204,7 @@ void DataFilesPage::setupDataFiles()
|
||||||
mCfgMgr.readConfiguration(variables, desc);
|
mCfgMgr.readConfiguration(variables, desc);
|
||||||
|
|
||||||
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
||||||
Files::PathContainer dataDirs(variables["data"].as<Files::PathContainer>());
|
mDataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
|
||||||
mDataDirs = dataDirs;
|
|
||||||
|
|
||||||
// std::string local = variables["data-local"].as<std::string>();
|
// std::string local = variables["data-local"].as<std::string>();
|
||||||
// if (!local.empty()) {
|
// if (!local.empty()) {
|
||||||
|
@ -212,36 +212,42 @@ void DataFilesPage::setupDataFiles()
|
||||||
// dataDirs.push_back(Files::PathContainer::value_type(local));
|
// dataDirs.push_back(Files::PathContainer::value_type(local));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (dataDirs.size()>1)
|
if (mDataDirs.size()>1)
|
||||||
dataDirs.resize (1);
|
mDataDirs.resize (1);
|
||||||
|
|
||||||
mCfgMgr.processPaths(dataDirs);
|
mCfgMgr.processPaths(mDataDirs);
|
||||||
|
|
||||||
while (dataDirs.empty()) {
|
|
||||||
// No valid data files directory found
|
|
||||||
|
|
||||||
|
while (mDataDirs.empty()) {
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setWindowTitle("Error detecting Morrowind installation");
|
msgBox.setWindowTitle("Error detecting Morrowind installation");
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
msgBox.setStandardButtons(QMessageBox::Cancel);
|
msgBox.setStandardButtons(QMessageBox::Cancel);
|
||||||
msgBox.setText(tr("<br><b>Could not find the Data Files location</b><br><br> \
|
msgBox.setText(tr("<br><b>Could not find the Data Files location</b><br><br> \
|
||||||
The directory containing the data files was not found.<br><br> \
|
The directory containing the data files was not found.<br><br> \
|
||||||
Press \"Browse...\" to specify the location manually.<br>"));
|
Press \"Browse...\" to specify the location manually.<br>"));
|
||||||
|
|
||||||
QAbstractButton *dirSelectButton =
|
QAbstractButton *dirSelectButton =
|
||||||
msgBox.addButton(tr("B&rowse..."), QMessageBox::ActionRole);
|
msgBox.addButton(tr("B&rowse..."), QMessageBox::ActionRole);
|
||||||
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
if (msgBox.clickedButton() == dirSelectButton) {
|
if (msgBox.clickedButton() == dirSelectButton) {
|
||||||
|
|
||||||
QString dataDir = QFileDialog::getExistingDirectory(
|
// Show a custom dir selection dialog which only accepts valid dirs
|
||||||
this, tr("Select Data Files Directory"),
|
QString selectedDir = FileDialog::getExistingDirectory(
|
||||||
"/home",
|
this, tr("Select Data Files Directory"),
|
||||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
QDir::currentPath(),
|
||||||
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||||
|
|
||||||
|
// Add the user selected data directory
|
||||||
|
if (!selectedDir.isEmpty()) {
|
||||||
|
mDataDirs.push_back(Files::PathContainer::value_type(selectedDir.toStdString()));
|
||||||
|
mCfgMgr.processPaths(mDataDirs);
|
||||||
|
} else {
|
||||||
|
// Cancel from within the dir selection dialog
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
dataDirs.push_back(Files::PathContainer::value_type(dataDir.toStdString()));
|
|
||||||
mDataDirs.push_back(Files::PathContainer::value_type(dataDir.toStdString()));
|
|
||||||
} else {
|
} else {
|
||||||
// Cancel
|
// Cancel
|
||||||
break;
|
break;
|
||||||
|
@ -249,13 +255,13 @@ void DataFilesPage::setupDataFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if cancel was clicked because we can't exit from while loop
|
// Check if cancel was clicked because we can't exit from while loop
|
||||||
if (dataDirs.empty()) {
|
if (mDataDirs.empty()) {
|
||||||
QApplication::exit(1);
|
QApplication::exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a file collection for the dataDirs
|
// Create a file collection for the data dirs
|
||||||
Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as<bool>());
|
Files::Collections fileCollections(mDataDirs, !variables["fs-strict"].as<bool>());
|
||||||
|
|
||||||
// First we add all the master files
|
// First we add all the master files
|
||||||
const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm");
|
const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm");
|
||||||
|
|
57
apps/launcher/filedialog.cpp
Normal file
57
apps/launcher/filedialog.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#include "filedialog.hpp"
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
FileDialog::FileDialog(QWidget *parent)
|
||||||
|
: QFileDialog(parent)
|
||||||
|
{
|
||||||
|
// Remove the default Choose button to prevent it being updated elsewhere
|
||||||
|
QDialogButtonBox *box = qFindChild<QDialogButtonBox*>(this);
|
||||||
|
Q_ASSERT(box);
|
||||||
|
box->removeButton(box->button(QDialogButtonBox::Open));
|
||||||
|
|
||||||
|
// Add our own button so we can disable/enable it
|
||||||
|
mChooseButton = new QPushButton(tr("&Choose"));
|
||||||
|
mChooseButton->setIcon(QIcon::fromTheme("document-open"));
|
||||||
|
mChooseButton->setEnabled(false);
|
||||||
|
box->addButton(mChooseButton, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
|
connect(this, SIGNAL(directoryEntered(const QString&)), this, SLOT(updateChooseButton(const QString&)));
|
||||||
|
emit directoryEntered(directory().absolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileDialog::getExistingDirectory(QWidget *parent,
|
||||||
|
const QString &caption,
|
||||||
|
const QString &dir,
|
||||||
|
Options options)
|
||||||
|
{
|
||||||
|
// create a non-native file dialog
|
||||||
|
FileDialog dialog;
|
||||||
|
dialog.setFileMode(DirectoryOnly);
|
||||||
|
dialog.setOptions(options & DontUseNativeDialog | ShowDirsOnly);
|
||||||
|
|
||||||
|
if (!caption.isEmpty())
|
||||||
|
dialog.setWindowTitle(caption);
|
||||||
|
|
||||||
|
if (!dir.isEmpty())
|
||||||
|
dialog.setDirectory(dir);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
|
return dialog.selectedFiles().value(0);
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDialog::updateChooseButton(const QString &directory)
|
||||||
|
{
|
||||||
|
QDir currentDir = QDir(directory);
|
||||||
|
currentDir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
|
||||||
|
currentDir.setNameFilters(QStringList() << "*.esm" << "*.esp");
|
||||||
|
|
||||||
|
if (!currentDir.entryList().isEmpty()) {
|
||||||
|
// There are data files in the current dir
|
||||||
|
mChooseButton->setEnabled(true);
|
||||||
|
} else {
|
||||||
|
mChooseButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
50
apps/launcher/filedialog.hpp
Normal file
50
apps/launcher/filedialog.hpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef FILEDIALOG_HPP
|
||||||
|
#define FILEDIALOG_HPP
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
|
||||||
|
struct FileDialogArgs
|
||||||
|
{
|
||||||
|
FileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {}
|
||||||
|
QWidget *parent;
|
||||||
|
QString caption;
|
||||||
|
QString directory;
|
||||||
|
QString selection;
|
||||||
|
QString filter;
|
||||||
|
QFileDialog::FileMode mode;
|
||||||
|
QFileDialog::Options options;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileDialog : public QFileDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileDialog(QWidget *parent = 0);
|
||||||
|
// FileDialog(QWidget *parent, Qt::WindowFlags f);
|
||||||
|
|
||||||
|
//QString getExistingDirectory();
|
||||||
|
static QString getExistingDirectory(QWidget *parent = 0,
|
||||||
|
const QString &caption = QString(),
|
||||||
|
const QString &dir = QString(),
|
||||||
|
Options options = ShowDirsOnly);
|
||||||
|
//FileDialog mDirectoryDialog;
|
||||||
|
|
||||||
|
bool initialized;
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
// void updateOkButton(const QString &text);
|
||||||
|
void updateChooseButton(const QString &directory);
|
||||||
|
//void
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPushButton *mChooseButton;
|
||||||
|
//QFileDialog *mDirectoryDialog;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FILEDIALOG_HPP
|
|
@ -1,12 +1,3 @@
|
||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
|
|
||||||
**
|
|
||||||
** Use, modification and distribution is allowed without limitation,
|
|
||||||
** warranty, liability or support of any kind.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "lineedit.hpp"
|
#include "lineedit.hpp"
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
|
@ -14,33 +5,33 @@
|
||||||
LineEdit::LineEdit(QWidget *parent)
|
LineEdit::LineEdit(QWidget *parent)
|
||||||
: QLineEdit(parent)
|
: QLineEdit(parent)
|
||||||
{
|
{
|
||||||
clearButton = new QToolButton(this);
|
mClearButton = new QToolButton(this);
|
||||||
QPixmap pixmap(":images/clear.png");
|
QPixmap pixmap(":images/clear.png");
|
||||||
clearButton->setIcon(QIcon(pixmap));
|
mClearButton->setIcon(QIcon(pixmap));
|
||||||
clearButton->setIconSize(pixmap.size());
|
mClearButton->setIconSize(pixmap.size());
|
||||||
clearButton->setCursor(Qt::ArrowCursor);
|
mClearButton->setCursor(Qt::ArrowCursor);
|
||||||
clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
mClearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
|
||||||
clearButton->hide();
|
mClearButton->hide();
|
||||||
connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear()));
|
||||||
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
|
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
|
||||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
|
setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(mClearButton->sizeHint().width() + frameWidth + 1));
|
||||||
QSize msz = minimumSizeHint();
|
QSize msz = minimumSizeHint();
|
||||||
setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2),
|
setMinimumSize(qMax(msz.width(), mClearButton->sizeHint().height() + frameWidth * 2 + 2),
|
||||||
qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
|
qMax(msz.height(), mClearButton->sizeHint().height() + frameWidth * 2 + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::resizeEvent(QResizeEvent *)
|
void LineEdit::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
QSize sz = clearButton->sizeHint();
|
QSize sz = mClearButton->sizeHint();
|
||||||
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
|
||||||
clearButton->move(rect().right() - frameWidth - sz.width(),
|
mClearButton->move(rect().right() - frameWidth - sz.width(),
|
||||||
(rect().bottom() + 1 - sz.height())/2);
|
(rect().bottom() + 1 - sz.height())/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineEdit::updateCloseButton(const QString& text)
|
void LineEdit::updateCloseButton(const QString& text)
|
||||||
{
|
{
|
||||||
clearButton->setVisible(!text.isEmpty());
|
mClearButton->setVisible(!text.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ private slots:
|
||||||
void updateCloseButton(const QString &text);
|
void updateCloseButton(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QToolButton *clearButton;
|
QToolButton *mClearButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIENEDIT_H
|
#endif // LIENEDIT_H
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Loading…
Reference in a new issue