Skip to content

Commit

Permalink
UI|Client: Only allow selecting soundfont files in Audio Settings
Browse files Browse the repository at this point in the history
Also clarified the language used in the dialog a little.

IssueID #1951
  • Loading branch information
skyjake committed Jan 27, 2015
1 parent 63939ea commit d1479d1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
18 changes: 18 additions & 0 deletions doomsday/client/include/ui/widgets/cvarnativepathwidget.h
Expand Up @@ -32,6 +32,24 @@ class CVarNativePathWidget : public de::AuxButtonWidget, public ICVarWidget
public:
CVarNativePathWidget(char const *cvarPath);

/**
* Sets all the file types that can be selected using the widget. Each entry in
* the list should be formatted as "Description (*.ext *.ext2)".
*
* The default is "All files (*)".
*
* @param filters Allowed file types.
*/
void setFilters(de::StringList const &filters);

/**
* Sets the text that is shown as the current selection when nothing has been
* selected.
*
* @param text Blank text placeholder.
*/
void setBlankText(de::String const &text);

char const *cvarPath() const;

public slots:
Expand Down
8 changes: 7 additions & 1 deletion doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp
Expand Up @@ -59,6 +59,12 @@ DENG_GUI_PIMPL(AudioSettingsDialog)
area.add(musicSource = new CVarChoiceWidget ("music-source"));
area.add(musicSoundfont = new CVarNativePathWidget("music-soundfont"));

musicSoundfont->setBlankText(tr("System default"));
musicSoundfont->setFilters(StringList()
<< "SF2 soundfonts (*.sf2)"
<< "DLS soundfonts (*.dls)"
<< "All files (*)");

// Display volumes on a 0...100 scale.
sfxVolume ->setDisplayFactor(100.0 / 255.0);
musicVolume->setDisplayFactor(100.0 / 255.0);
Expand Down Expand Up @@ -111,7 +117,7 @@ AudioSettingsDialog::AudioSettingsDialog(String const &name)
<< new ChoiceItem(tr("External files"), MUSP_EXT)
<< new ChoiceItem(tr("CD"), MUSP_CD);

auto *sfLabel = LabelWidget::newWithText(tr("Sound Font:"), &area());
auto *sfLabel = LabelWidget::newWithText(tr("MIDI Sound Font:"), &area());

// Layout.
GridLayout layout(area().contentRule().left(), area().contentRule().top());
Expand Down
26 changes: 23 additions & 3 deletions doomsday/client/src/ui/widgets/cvarnativepathwidget.cpp
Expand Up @@ -28,6 +28,8 @@ DENG2_PIMPL_NOREF(CVarNativePathWidget)
{
char const *cvar;
NativePath path;
QStringList filters;
String blankText = "(not set)";

cvar_t *var() const
{
Expand All @@ -40,7 +42,7 @@ DENG2_PIMPL_NOREF(CVarNativePathWidget)
{
if(path.isEmpty())
{
return String(_E(l)) + tr("(not set)") + _E(.);
return String(_E(l)) + blankText + _E(.);
}
return path.fileName();
}
Expand All @@ -54,10 +56,23 @@ CVarNativePathWidget::CVarNativePathWidget(char const *cvarPath)

auxiliary().setText(tr("Browse"));

//connect(this, SIGNAL(pressed()), this, SLOT(chooseUsingNativeFileDialog()));
connect(&auxiliary(), SIGNAL(pressed()), this, SLOT(chooseUsingNativeFileDialog()));
}

void CVarNativePathWidget::setFilters(StringList const &filters)
{
d->filters.clear();
for(auto const &f : filters)
{
d->filters << f;
}
}

void CVarNativePathWidget::setBlankText(String const &text)
{
d->blankText = text;
}

char const *CVarNativePathWidget::cvarPath() const
{
return d->cvar;
Expand All @@ -74,7 +89,8 @@ void CVarNativePathWidget::chooseUsingNativeFileDialog()
auto &win = ClientWindow::main();

#ifndef MACOSX
// Switch temporarily to windowed mode.
// Switch temporarily to windowed mode. Not needed on OS X because the display mode
// is never changed on that platform.
win.saveState();
int windowedMode[] = {
ClientWindow::Fullscreen, false,
Expand All @@ -87,6 +103,10 @@ void CVarNativePathWidget::chooseUsingNativeFileDialog()
QDir dir(d->path);
if(d->path.isEmpty()) dir = QDir::home();
QFileDialog dlg(&win, tr("Select File for \"%1\"").arg(d->cvar), dir.absolutePath());
if(!d->filters.isEmpty())
{
dlg.setNameFilters(d->filters);
}
dlg.setFileMode(QFileDialog::ExistingFile);
dlg.setOption(QFileDialog::ReadOnly, true);
dlg.setLabelText(QFileDialog::Accept, tr("Select"));
Expand Down

0 comments on commit d1479d1

Please sign in to comment.