Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI|Client|AudioSettings: Select soundfont using native file picker
Added the class CVarNativePathWidget (based on aux button) for choosing a native file. IssueID #1907
- Loading branch information
Showing
5 changed files
with
195 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** @file cvarnativepathwidget.h Console variable native path widget. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef DENG_CLIENT_CVARNATIVEPATHWIDGET_H | ||
#define DENG_CLIENT_CVARNATIVEPATHWIDGET_H | ||
|
||
#include <de/AuxButtonWidget> | ||
#include "icvarwidget.h" | ||
|
||
/** | ||
* Console variable that contains a native path. | ||
*/ | ||
class CVarNativePathWidget : public de::AuxButtonWidget, public ICVarWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
CVarNativePathWidget(char const *cvarPath); | ||
|
||
char const *cvarPath() const; | ||
|
||
public slots: | ||
void updateFromCVar(); | ||
void chooseUsingNativeFileDialog(); | ||
|
||
protected slots: | ||
void setCVarValueFromWidget(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
#endif // DENG_CLIENT_CVARNATIVEPATHWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
doomsday/client/src/ui/widgets/cvarnativepathwidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** @file cvarnativepathwidget.cpp Console variable with a native path. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* LGPL: http://www.gnu.org/licenses/lgpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
* General Public License for more details. You should have received a copy of | ||
* the GNU Lesser General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "ui/widgets/cvarnativepathwidget.h" | ||
#include "ui/clientwindow.h" | ||
|
||
#include <doomsday/console/var.h> | ||
#include <QFileDialog> | ||
|
||
using namespace de; | ||
|
||
DENG2_PIMPL_NOREF(CVarNativePathWidget) | ||
{ | ||
char const *cvar; | ||
NativePath path; | ||
|
||
cvar_t *var() const | ||
{ | ||
cvar_t *cv = Con_FindVariable(cvar); | ||
DENG2_ASSERT(cv != 0); | ||
return cv; | ||
} | ||
|
||
String labelText() const | ||
{ | ||
if(path.isEmpty()) | ||
{ | ||
return String(_E(l)) + tr("(not set)") + _E(.); | ||
} | ||
return path.fileName(); | ||
} | ||
}; | ||
|
||
CVarNativePathWidget::CVarNativePathWidget(char const *cvarPath) | ||
: d(new Instance) | ||
{ | ||
d->cvar = cvarPath; | ||
updateFromCVar(); | ||
|
||
auxiliary().setText(tr("Browse")); | ||
|
||
//connect(this, SIGNAL(pressed()), this, SLOT(chooseUsingNativeFileDialog())); | ||
connect(&auxiliary(), SIGNAL(pressed()), this, SLOT(chooseUsingNativeFileDialog())); | ||
} | ||
|
||
char const *CVarNativePathWidget::cvarPath() const | ||
{ | ||
return d->cvar; | ||
} | ||
|
||
void CVarNativePathWidget::updateFromCVar() | ||
{ | ||
d->path = CVar_String(d->var()); | ||
setText(d->labelText()); | ||
} | ||
|
||
void CVarNativePathWidget::chooseUsingNativeFileDialog() | ||
{ | ||
auto &win = ClientWindow::main(); | ||
|
||
#ifndef MACOSX | ||
// Switch temporarily to windowed mode. | ||
win.saveState(); | ||
int windowedMode[] = { | ||
ClientWindow::Fullscreen, false, | ||
ClientWindow::End | ||
}; | ||
win.changeAttributes(windowedMode); | ||
#endif | ||
|
||
// Use a native dialog to pick the path. | ||
QDir dir(d->path); | ||
if(d->path.isEmpty()) dir = QDir::home(); | ||
QFileDialog dlg(&win, tr("Select File for \"%1\"").arg(d->cvar), dir.absolutePath()); | ||
dlg.setFileMode(QFileDialog::ExistingFile); | ||
dlg.setOption(QFileDialog::ReadOnly, true); | ||
dlg.setLabelText(QFileDialog::Accept, tr("Select")); | ||
if(dlg.exec()) | ||
{ | ||
d->path = dlg.selectedFiles().at(0); | ||
setCVarValueFromWidget(); | ||
setText(d->labelText()); | ||
} | ||
|
||
#ifndef MACOSX | ||
win.restoreState(); | ||
#endif | ||
} | ||
|
||
void CVarNativePathWidget::setCVarValueFromWidget() | ||
{ | ||
CVar_SetString(d->var(), d->path.toString().toUtf8()); | ||
} |