Skip to content

Commit

Permalink
Shell: Continuing work on UI widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 4c52716 commit 6afcfa2
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 236 deletions.
77 changes: 44 additions & 33 deletions doomsday/tools/shell/src/folderselection.cpp
Expand Up @@ -17,49 +17,56 @@
*/

#include "folderselection.h"
//#include "utils.h"
//#include <QLineEdit>
//#include <QPushButton>
//#include <QHBoxLayout>
//#include <QFileDialog>
//#include <QLabel>

#include <de/ButtonWidget>
#include <de/FileDialog>
#include <de/LineEditWidget>

using namespace de;

DE_PIMPL(FolderSelection)
{
String prompt;
// QLineEdit *edit;
// QPushButton *button;
LineEditWidget *edit;
ButtonWidget *button;

Impl(Public *i, String extraLabel)
Impl(Public *i)
: Base(i)
// , edit(0)
// , button(0)
{
// QHBoxLayout *layout = new QHBoxLayout;
// layout->setContentsMargins(0, 0, 0, 0);
// self().setLayout(layout);

// if (!extraLabel.isEmpty())
// {
// QLabel *lab = new QLabel(extraLabel);
// layout->addWidget(lab, 0);
// }

// edit = new QLineEdit;
// edit->setMinimumWidth(280);
//#ifdef WIN32
// button = new QPushButton(tr("&Browse..."));
//#else
// button = new QPushButton(tr("..."));
//#endif
// button->setAutoDefault(false);

// layout->addWidget(edit, 1);
// layout->addWidget(button, 0);
edit = &i->addNew<LineEditWidget>();

button = &i->addNew<ButtonWidget>();
button->setSizePolicy(ui::Expand, ui::Expand);
button->setText("Browse...");

edit->rule()
.setInput(Rule::Width, i->rule().width() - button->rule().width())
.setInput(Rule::Top, i->rule().top())
.setInput(Rule::Left, i->rule().left());

button->rule()
.setInput(Rule::Top, i->rule().top())
.setInput(Rule::Right, i->rule().right());

// if (!extraLabel.isEmpty())
// {
// QLabel *lab = new QLabel(extraLabel);
// layout->addWidget(lab, 0);
// }

// edit = new QLineEdit;
// edit->setMinimumWidth(280);
//#ifdef WIN32
// button = new QPushButton(tr("&Browse..."));
//#else
// button = new QPushButton(tr("..."));
//#endif
// button->setAutoDefault(false);

// layout->addWidget(edit, 1);
// layout->addWidget(button, 0);
}
};

Expand All @@ -71,14 +78,18 @@ DE_PIMPL(FolderSelection)
// connect(d->edit, SIGNAL(textEdited(QString)), this, SIGNAL(selected()));
//}

FolderSelection::FolderSelection(const String &prompt, const String &extraLabel)
: d(new Impl(this, extraLabel))
FolderSelection::FolderSelection(const String &prompt)
: GuiWidget("folderselection")
, d(new Impl(this))
{
d->prompt = prompt;

rule().setInput(Rule::Height, d->edit->rule().height());

// connect(d->button, SIGNAL(clicked()), this, SLOT(selectFolder()));
}

void FolderSelection::setPath(de::NativePath const &path)
void FolderSelection::setPath(const NativePath &path)
{
// d->edit->setText(QString::fromUtf8(path));
}
Expand Down
9 changes: 3 additions & 6 deletions doomsday/tools/shell/src/folderselection.h
Expand Up @@ -19,26 +19,23 @@
#ifndef FOLDERSELECTION_H
#define FOLDERSELECTION_H

#include <de/String>
#include <de/GuiWidget>
#include <de/NativePath>
#include <de/AuxButtonWidget>

/**
* Widget for selecting a folder.
*/
class FolderSelection : public de::AuxButtonWidget
class FolderSelection : public de::GuiWidget
{
public:
explicit FolderSelection(const de::String &prompt, const de::String &extraLabel = {});
explicit FolderSelection(const de::String &prompt);

void setPath(de::NativePath const &path);
void setEnabled(bool yes);
void setDisabled(bool yes) { setEnabled(!yes); }

de::NativePath path() const;

//signals:
// void selected();
DE_AUDIENCE(Selection, void folderSelected(const de::NativePath &))

void selectFolder();
Expand Down
104 changes: 57 additions & 47 deletions doomsday/tools/shell/src/guishellapp.cpp
Expand Up @@ -28,8 +28,10 @@
#include <de/EscapeParser>
#include <de/FileSystem>
#include <de/Id>
#include <doomsday/network/LocalServer>
#include <de/Config>
#include <de/ServerFinder>
#include <doomsday/network/LocalServer>
#include <SDL_messagebox.h>
//#include <QMenuBar>
//#include <QMessageBox>
//#include <QUrl>
Expand All @@ -40,6 +42,7 @@
//Q_DECLARE_METATYPE(de::Address)

using namespace de;
using namespace network;

DE_PIMPL(GuiShellApp)
{
Expand All @@ -54,7 +57,7 @@ DE_PIMPL(GuiShellApp)
// QAction *disconnectAction;
#endif
// QList<LinkWindow *> windows;
// QHash<int, LocalServer *> localServers; // port as key
Hash<int, LocalServer *> localServers; // port as key
// QTimer localCheckTimer;

Preferences *prefs;
Expand Down Expand Up @@ -155,21 +158,18 @@ void GuiShellApp::initialize()
LinkWindow *GuiShellApp::newOrReusedConnectionWindow()
{
LinkWindow *found = nullptr;
// QWidget *other = activeWindow(); // for positioning a new window

// // Look for a window with a closed connection.
// foreach (LinkWindow *win, d->windows)
// {
// if (!win->isConnected())
// {
// found = win;
// found->raise();
// found->activateWindow();
// d->windows.removeOne(win);
// break;
// }
// if (!other) other = win;
// }
// Look for a window with a closed connection.
d->winSys->forAll([&found](BaseWindow *w) {
auto &win = w->as<LinkWindow>();
if (!win.isConnected())
{
found = &win;
found->raise();
return LoopAbort;
}
return LoopContinue;
});

if (!found)
{
Expand Down Expand Up @@ -256,44 +256,48 @@ void GuiShellApp::startLocalServer()
try
{
#ifdef MACOSX
// // App folder randomization means we can't find Doomsday.app on our own.
// if (!QSettings().contains("Preferences/appFolder"))
// {
// showPreferences();
// return;
// }
// App folder randomization means we can't find Doomsday.app on our own.
if (!Config::get().has("Preferences.appFolder"))
{
showPreferences();
return;
}
#endif
// LocalServerDialog dlg;
// if (dlg.exec() == QDialog::Accepted)
// {
// QStringList opts = dlg.additionalOptions();
// if (!Preferences::iwadFolder().isEmpty())
// {
// opts << "-iwad" << convert(Preferences::iwadFolder());
// }

// auto *sv = new LocalServer;
// sv->setApplicationPath(convert(QSettings().value("Preferences/appFolder").toString()));
// if (!dlg.name().isEmpty())
// {
// sv->setName(convert(dlg.name()));
// }
// sv->start(dlg.port(),
// convert(dlg.gameMode()),
// map<StringList>(opts, convertToString), //[](const QString &s) { return convert(s); }),
// dlg.runtimeFolder());
// d->localServers[dlg.port()] = sv;

// newOrReusedConnectionWindow()->waitForLocalConnection
// (dlg.port(), sv->errorLogPath(), dlg.name());
// }
auto *win = d->winSys->focusedWindow();
LocalServerDialog dlg;
if (dlg.exec(win->root()))
{
StringList opts = dlg.additionalOptions();
if (!Preferences::iwadFolder().isEmpty())
{
opts << "-iwad" << Preferences::iwadFolder();
}

auto *sv = new LocalServer;
sv->setApplicationPath(Config::get().gets("Preferences.appFolder"));
if (!dlg.name().isEmpty())
{
sv->setName(dlg.name());
}
sv->start(dlg.port(),
dlg.gameMode(),
opts,
dlg.runtimeFolder());
d->localServers[dlg.port()] = sv;

newOrReusedConnectionWindow()->waitForLocalConnection
(dlg.port(), sv->errorLogPath(), dlg.name());
}
}
catch (const Error &er)
{
EscapeParser esc;
esc.parse(er.asText());

// QMessageBox::critical(0, tr("Failed to Start Server"), esc.plainText().c_str());
SDL_MessageBoxData mbox{};
mbox.title = "Failed to Start Server";
mbox.message = esc.plainText();
SDL_ShowMessageBox(&mbox, nullptr);

showPreferences();
}
Expand Down Expand Up @@ -348,6 +352,12 @@ void GuiShellApp::openWebAddress(const String &url)

void GuiShellApp::showPreferences()
{
LinkWindow *win = d->winSys->focusedWindow();

auto *prefs = new Preferences;
prefs->setDeleteAfterDismissed(true);
prefs->exec(win->root());

// if (!d->prefs)
// {
// d->prefs = new Preferences;
Expand Down
6 changes: 6 additions & 0 deletions doomsday/tools/shell/src/linkwindow.cpp
Expand Up @@ -29,6 +29,7 @@
#include <de/Garbage>
#include <de/EventLoop>
#include <de/Timer>
#include <de/KeyActions>
#include <de/NativeFile>
#include <de/LogWidget>
#include <de/CommandWidget>
Expand Down Expand Up @@ -114,6 +115,11 @@ DE_PIMPL(LinkWindow)

waitTimeout.setSingleShot(false);
waitTimeout.setInterval(1.0);

auto *keys = new KeyActions;
keys->add(KeyEvent(KeyEvent::Pressed, ',', 0, 0, "", KeyEvent::Control),
[]() { GuiShellApp::app().showPreferences(); });
root.add(keys);
}

~Impl() override
Expand Down

0 comments on commit 6afcfa2

Please sign in to comment.