mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:28:03 +02:00
Changed import dialog UI
This commit is contained in:
parent
7bce649080
commit
0ed7b959d7
2 changed files with 97 additions and 93 deletions
|
@ -16,14 +16,13 @@
|
||||||
|
|
||||||
const QString WINDOW_NAME = QObject::tr("Import Voxels");
|
const QString WINDOW_NAME = QObject::tr("Import Voxels");
|
||||||
const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
|
const QString IMPORT_BUTTON_NAME = QObject::tr("Import");
|
||||||
|
const QString LOADING_BUTTON_NAME = QObject::tr("Loading ...");
|
||||||
|
const QString PLACE_BUTTON_NAME = QObject::tr("Place voxels");
|
||||||
const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels");
|
const QString IMPORT_INFO = QObject::tr("<b>Import</b> %1 as voxels");
|
||||||
const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel");
|
const QString CANCEL_BUTTON_NAME = QObject::tr("Cancel");
|
||||||
const QString INFO_LABEL_TEXT = QObject::tr("<div style='line-height:20px;'>"
|
|
||||||
"This will load the selected file into Hifi and allow you<br/>"
|
|
||||||
"to place it with %1-V; you must be in select or<br/>"
|
|
||||||
"add mode (S or V keys will toggle mode) to place.</div>");
|
|
||||||
|
|
||||||
const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
|
||||||
|
const QString DOWNLOAD_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||||
const int SHORT_FILE_EXTENSION = 4;
|
const int SHORT_FILE_EXTENSION = 4;
|
||||||
const int SECOND_INDEX_LETTER = 1;
|
const int SECOND_INDEX_LETTER = 1;
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ QIcon HiFiIconProvider::icon(const QFileInfo &info) const {
|
||||||
if (info.isDir()) {
|
if (info.isDir()) {
|
||||||
if (info.absoluteFilePath() == QDir::homePath()) {
|
if (info.absoluteFilePath() == QDir::homePath()) {
|
||||||
return QIcon("resources/icons/home.svg");
|
return QIcon("resources/icons/home.svg");
|
||||||
} else if (info.absoluteFilePath() == DESKTOP_LOCATION) {
|
} else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)) {
|
||||||
return QIcon("resources/icons/desktop.svg");
|
return QIcon("resources/icons/desktop.svg");
|
||||||
} else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)) {
|
} else if (info.absoluteFilePath() == QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)) {
|
||||||
return QIcon("resources/icons/documents.svg");
|
return QIcon("resources/icons/documents.svg");
|
||||||
|
@ -95,10 +94,11 @@ QString HiFiIconProvider::type(const QFileInfo &info) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportDialog::ImportDialog(QWidget* parent) :
|
ImportDialog::ImportDialog(QWidget* parent) :
|
||||||
QFileDialog(parent, WINDOW_NAME, DESKTOP_LOCATION, NULL),
|
QFileDialog(parent, WINDOW_NAME, DOWNLOAD_LOCATION, NULL),
|
||||||
|
_progressBar(this),
|
||||||
_importButton(IMPORT_BUTTON_NAME, this),
|
_importButton(IMPORT_BUTTON_NAME, this),
|
||||||
_cancelButton(CANCEL_BUTTON_NAME, this),
|
_cancelButton(CANCEL_BUTTON_NAME, this),
|
||||||
fileAccepted(false) {
|
_mode(importMode) {
|
||||||
|
|
||||||
setOption(QFileDialog::DontUseNativeDialog, true);
|
setOption(QFileDialog::DontUseNativeDialog, true);
|
||||||
setFileMode(QFileDialog::ExistingFile);
|
setFileMode(QFileDialog::ExistingFile);
|
||||||
|
@ -107,96 +107,89 @@ ImportDialog::ImportDialog(QWidget* parent) :
|
||||||
setImportTypes();
|
setImportTypes();
|
||||||
setLayout();
|
setLayout();
|
||||||
|
|
||||||
connect(&_importButton, SIGNAL(pressed()), SLOT(import()));
|
_progressBar.setRange(0, 100);
|
||||||
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
|
||||||
|
|
||||||
connect(&_cancelButton, SIGNAL(pressed()), SLOT(close()));
|
|
||||||
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportDialog::~ImportDialog() {
|
|
||||||
deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportDialog::import() {
|
|
||||||
fileAccepted = true;
|
|
||||||
emit accepted();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportDialog::accept() {
|
|
||||||
// do nothing if import is not enable
|
|
||||||
if (!_importButton.isEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fileAccepted) {
|
connect(&_importButton, SIGNAL(pressed()), SLOT(accept()));
|
||||||
fileAccepted = true;
|
connect(&_cancelButton, SIGNAL(pressed()), SIGNAL(canceled()));
|
||||||
emit accepted();
|
connect(this, SIGNAL(currentChanged(QString)), SLOT(saveCurrentFile(QString)));
|
||||||
} else {
|
|
||||||
QFileDialog::accept();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportDialog::reject() {
|
|
||||||
QFileDialog::reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ImportDialog::exec() {
|
|
||||||
// deselect selected file
|
|
||||||
selectFile(" ");
|
|
||||||
return QFileDialog::exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::reset() {
|
void ImportDialog::reset() {
|
||||||
_importButton.setEnabled(false);
|
setMode(importMode);
|
||||||
|
_progressBar.setValue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::saveCurrentFile(QString filename) {
|
void ImportDialog::setMode(dialogMode mode) {
|
||||||
if (!filename.isEmpty() && QFileInfo(filename).isFile()) {
|
_mode = mode;
|
||||||
_currentFile = filename;
|
|
||||||
_importButton.setEnabled(true);
|
switch (_mode) {
|
||||||
} else {
|
case loadingMode:
|
||||||
_currentFile.clear();
|
_importButton.setEnabled(false);
|
||||||
_importButton.setEnabled(false);
|
_importButton.setText(LOADING_BUTTON_NAME);
|
||||||
|
findChild<QWidget*>("sidebar")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("treeView")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("backButton")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("forwardButton")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("toParentButton")->setEnabled(false);
|
||||||
|
break;
|
||||||
|
case placeMode:
|
||||||
|
_progressBar.setValue(100);
|
||||||
|
_importButton.setEnabled(true);
|
||||||
|
_importButton.setText(PLACE_BUTTON_NAME);
|
||||||
|
findChild<QWidget*>("sidebar")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("treeView")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("backButton")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("forwardButton")->setEnabled(false);
|
||||||
|
findChild<QWidget*>("toParentButton")->setEnabled(false);
|
||||||
|
break;
|
||||||
|
case importMode:
|
||||||
|
default:
|
||||||
|
_progressBar.setValue(0);
|
||||||
|
_importButton.setEnabled(true);
|
||||||
|
_importButton.setText(IMPORT_BUTTON_NAME);
|
||||||
|
findChild<QWidget*>("sidebar")->setEnabled(true);
|
||||||
|
findChild<QWidget*>("treeView")->setEnabled(true);
|
||||||
|
findChild<QWidget*>("backButton")->setEnabled(true);
|
||||||
|
findChild<QWidget*>("forwardButton")->setEnabled(true);
|
||||||
|
findChild<QWidget*>("toParentButton")->setEnabled(true);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImportDialog::setProgressBarValue(int value) {
|
||||||
|
_progressBar.setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportDialog::accept() {
|
||||||
|
emit accepted();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportDialog::saveCurrentFile(QString filename) {
|
||||||
|
_currentFile = QFileInfo(filename).isFile() ? filename : "";
|
||||||
|
}
|
||||||
|
#include <iostream>
|
||||||
void ImportDialog::setLayout() {
|
void ImportDialog::setLayout() {
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
QString cmdString = ("Command");
|
|
||||||
#else
|
|
||||||
QString cmdString = ("Control");
|
|
||||||
#endif
|
|
||||||
QLabel* infoLabel = new QLabel(QString(INFO_LABEL_TEXT).arg(cmdString));
|
|
||||||
infoLabel->setObjectName("infoLabel");
|
|
||||||
|
|
||||||
QGridLayout* gridLayout = (QGridLayout*) layout();
|
QGridLayout* gridLayout = (QGridLayout*) layout();
|
||||||
gridLayout->addWidget(infoLabel, 2, 0, 2, 1);
|
gridLayout->addWidget(&_progressBar, 2, 0, 2, 1);
|
||||||
gridLayout->addWidget(&_cancelButton, 2, 1, 2, 1);
|
gridLayout->addWidget(&_cancelButton, 2, 1, 2, 1);
|
||||||
gridLayout->addWidget(&_importButton, 2, 2, 2, 1);
|
gridLayout->addWidget(&_importButton, 2, 2, 2, 1);
|
||||||
|
|
||||||
// set ObjectName used in qss for styling
|
// set ObjectName used in qss for styling
|
||||||
|
_progressBar.setObjectName("progressBar");
|
||||||
_importButton.setObjectName("importButton");
|
_importButton.setObjectName("importButton");
|
||||||
_cancelButton.setObjectName("cancelButton");
|
_cancelButton.setObjectName("cancelButton");
|
||||||
|
|
||||||
// set fixed size
|
// set fixed size
|
||||||
_importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
_importButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
_cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
_cancelButton.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
_progressBar.setFixedHeight(7);
|
||||||
|
_progressBar.setTextVisible(false);
|
||||||
|
|
||||||
// hide unused embedded widgets in QFileDialog
|
// hide unused embedded widgets in QFileDialog
|
||||||
QWidget* widget = findChild<QWidget*>("lookInCombo");
|
QWidget* widget = findChild<QWidget*>("lookInCombo");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
widget = findChild<QWidget*>("backButton");
|
|
||||||
widget->hide();
|
|
||||||
|
|
||||||
widget = findChild<QWidget*>("forwardButton");
|
|
||||||
widget->hide();
|
|
||||||
|
|
||||||
widget = findChild<QWidget*>("toParentButton");
|
|
||||||
widget->hide();
|
|
||||||
|
|
||||||
widget = findChild<QWidget*>("newFolderButton");
|
widget = findChild<QWidget*>("newFolderButton");
|
||||||
widget->hide();
|
widget->hide();
|
||||||
|
|
||||||
|
@ -230,8 +223,18 @@ void ImportDialog::setLayout() {
|
||||||
|
|
||||||
widget = findChild<QWidget*>("treeView");
|
widget = findChild<QWidget*>("treeView");
|
||||||
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
widget->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
|
|
||||||
switchToResourcesParentIfRequired();
|
switchToResourcesParentIfRequired();
|
||||||
|
|
||||||
|
QIcon icon = QIcon("resources/icons/backButton.svg");
|
||||||
|
QPushButton* button = (QPushButton*) findChild<QWidget*>("backButton");
|
||||||
|
//button->setIcon(icon);
|
||||||
|
|
||||||
|
button = (QPushButton*) findChild<QWidget*>("forwardButton");
|
||||||
|
button = (QPushButton*) findChild<QWidget*>("toParentButton");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QFile styleSheet("resources/styles/import_dialog.qss");
|
QFile styleSheet("resources/styles/import_dialog.qss");
|
||||||
if (styleSheet.open(QIODevice::ReadOnly)) {
|
if (styleSheet.open(QIODevice::ReadOnly)) {
|
||||||
setStyleSheet(styleSheet.readAll());
|
setStyleSheet(styleSheet.readAll());
|
||||||
|
@ -281,11 +284,6 @@ void ImportDialog::setImportTypes() {
|
||||||
setIconProvider(new HiFiIconProvider(iconsMap));
|
setIconProvider(new HiFiIconProvider(iconsMap));
|
||||||
setNameFilter(importFormatsFilterList);
|
setNameFilter(importFormatsFilterList);
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
QString cmdString = ("Command");
|
|
||||||
#else
|
|
||||||
QString cmdString = ("Control");
|
|
||||||
#endif
|
|
||||||
setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo));
|
setLabelText(QFileDialog::LookIn, QString(IMPORT_INFO).arg(importFormatsInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QProgressBar>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
@ -26,37 +27,42 @@ public:
|
||||||
QHash<QString, QString> iconsMap;
|
QHash<QString, QString> iconsMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum dialogMode {
|
||||||
|
importMode,
|
||||||
|
loadingMode,
|
||||||
|
placeMode
|
||||||
|
};
|
||||||
|
|
||||||
class ImportDialog : public QFileDialog {
|
class ImportDialog : public QFileDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImportDialog(QWidget* parent = NULL);
|
ImportDialog(QWidget* parent = NULL);
|
||||||
~ImportDialog();
|
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
QString getCurrentFile() const { return _currentFile; }
|
QString getCurrentFile() const { return _currentFile; }
|
||||||
|
dialogMode getMode() const { return _mode; }
|
||||||
|
void setMode(dialogMode mode);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void accepted();
|
void canceled();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int exec();
|
void setProgressBarValue(int value);
|
||||||
void import();
|
|
||||||
void accept();
|
|
||||||
void reject();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void saveCurrentFile(QString);
|
void accept();
|
||||||
|
void saveCurrentFile(QString filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _currentFile;
|
QString _currentFile;
|
||||||
|
QProgressBar _progressBar;
|
||||||
QPushButton _importButton;
|
QPushButton _importButton;
|
||||||
QPushButton _cancelButton;
|
QPushButton _cancelButton;
|
||||||
|
dialogMode _mode;
|
||||||
|
|
||||||
void setLayout();
|
void setLayout();
|
||||||
void setImportTypes();
|
void setImportTypes();
|
||||||
bool fileAccepted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__ImportDialog__) */
|
#endif /* defined(__hifi__ImportDialog__) */
|
||||||
|
|
Loading…
Reference in a new issue