Skip to content

Commit

Permalink
Shell|GUI: Added Preferences, FolderSelection widget, various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 12, 2013
1 parent 6e54aa9 commit 3da2d75
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 58 deletions.
1 change: 1 addition & 0 deletions doomsday/tools/shell/shell-gui/res/shell.qrc
Expand Up @@ -2,5 +2,6 @@
<qresource prefix="/images">
<file>shell.png</file>
<file>shell@2x.png</file>
<file>toolbar_placeholder.png</file>
</qresource>
</RCC>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions doomsday/tools/shell/shell-gui/shell-gui.pro
Expand Up @@ -69,3 +69,15 @@ else {
INSTALLS += target
target.path = $$DENG_BIN_DIR
}

HEADERS += \
src/folderselection.h

SOURCES += \
src/folderselection.cpp

HEADERS += \
src/preferences.h

SOURCES += \
src/preferences.cpp
87 changes: 87 additions & 0 deletions doomsday/tools/shell/shell-gui/src/folderselection.cpp
@@ -0,0 +1,87 @@
/** @file folderselection.cpp Widget for selecting a folder.
*
* @authors Copyright © 2013 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>
*/

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

DENG2_PIMPL(FolderSelection)
{
QString prompt;
QLineEdit *edit;
QPushButton *button;

Instance(Public &i) : Base(i),
edit(0),
button(0)
{
/*
// What's up with the extra spacing?
QPalette pal = self.palette();
pal.setColor(self.backgroundRole(), Qt::red);
self.setPalette(pal);
self.setAutoFillBackground(true);
*/

QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
self.setLayout(layout);

edit = new QLineEdit;
edit->setMinimumWidth(280);
button = new QPushButton(tr("..."));

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

FolderSelection::FolderSelection(QString const &prompt, QWidget *parent)
: QWidget(parent), d(new Instance(*this))
{
d->prompt = prompt;

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

FolderSelection::~FolderSelection()
{
delete d;
}

void FolderSelection::setPath(de::NativePath const &path)
{
d->edit->setText(path.toString());
}

de::NativePath FolderSelection::path() const
{
return d->edit->text();
}

void FolderSelection::selectFolder()
{
QString dir = QFileDialog::getExistingDirectory(0, d->prompt, d->edit->text());
if(!dir.isEmpty())
{
d->edit->setText(dir);
emit selected();
}
}
52 changes: 52 additions & 0 deletions doomsday/tools/shell/shell-gui/src/folderselection.h
@@ -0,0 +1,52 @@
/** @file folderselection.h Widget for selecting a folder.
*
* @authors Copyright © 2013 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 FOLDERSELECTION_H
#define FOLDERSELECTION_H

#include <de/libdeng2.h>
#include <de/NativePath>
#include <QWidget>

/**
* Widget for selecting a folder.
*/
class FolderSelection : public QWidget
{
Q_OBJECT

public:
explicit FolderSelection(QString const &prompt, QWidget *parent = 0);
virtual ~FolderSelection();

void setPath(de::NativePath const &path);

de::NativePath path() const;

signals:
void selected();

public slots:
void selectFolder();

private:
struct Instance;
Instance *d;
};

#endif // FOLDERSELECTION_H
29 changes: 28 additions & 1 deletion doomsday/tools/shell/shell-gui/src/guishellapp.cpp
Expand Up @@ -21,6 +21,7 @@
#include "opendialog.h"
#include "aboutdialog.h"
#include "localserverdialog.h"
#include "preferences.h"
#include <de/shell/LocalServer>
#include <de/shell/ServerFinder>
#include <QMenuBar>
Expand All @@ -42,6 +43,11 @@ struct GuiShellApp::Instance
#endif
QList<LinkWindow *> windows;

Preferences *prefs;

Instance() : prefs(0)
{}

~Instance()
{
foreach(LinkWindow *win, windows)
Expand Down Expand Up @@ -87,7 +93,8 @@ GuiShellApp::GuiShellApp(int &argc, char **argv)

connect(svMenu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));

// This will appear in the application menu:
// These will appear in the application menu:
menu->addAction(tr("Preferences..."), this, SLOT(showPreferences()), QKeySequence(tr("Ctrl+,")));
menu->addAction(tr("About"), this, SLOT(aboutShell()));
#endif

Expand Down Expand Up @@ -248,6 +255,26 @@ void GuiShellApp::aboutShell()
AboutDialog().exec();
}

void GuiShellApp::showPreferences()
{
if(!d->prefs)
{
d->prefs = new Preferences;
connect(d->prefs, SIGNAL(finished(int)), this, SLOT(preferencesDone()));
d->prefs->open();
}
else
{
d->prefs->activateWindow();
}
}

void GuiShellApp::preferencesDone()
{
d->prefs->deleteLater();
d->prefs = 0;
}

void GuiShellApp::updateMenu()
{
#ifdef MACOSX
Expand Down
2 changes: 2 additions & 0 deletions doomsday/tools/shell/shell-gui/src/guishellapp.h
Expand Up @@ -48,6 +48,8 @@ public slots:
void stopServer();
void updateLocalServerMenu();
void aboutShell();
void showPreferences();
void preferencesDone();
void updateMenu();

protected slots:
Expand Down
9 changes: 8 additions & 1 deletion doomsday/tools/shell/shell-gui/src/linkwindow.cpp
Expand Up @@ -149,6 +149,7 @@ LinkWindow::LinkWindow(QWidget *parent)

#ifndef MACOSX
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(tr("&Settings..."), app, SLOT(showPreferences()));
fileMenu->addAction(tr("&Quit"), app, SLOT(quit()), QKeySequence(tr("Ctrl+Q")));

// Menus are window-specific on non-Mac platforms.
Expand Down Expand Up @@ -201,9 +202,13 @@ LinkWindow::LinkWindow(QWidget *parent)
statusBar()->addPermanentWidget(d->currentHost);
statusBar()->addPermanentWidget(d->timeCounter);

QIcon icon(":/images/toolbar_placeholder.png");

QToolBar *tools = addToolBar(tr("View"));

d->statusButton = new QToolButton;
d->statusButton->setIcon(icon);
//d->statusButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
d->statusButton->setFocusPolicy(Qt::NoFocus);
d->statusButton->setText(tr("Status"));
d->statusButton->setCheckable(true);
Expand All @@ -212,6 +217,8 @@ LinkWindow::LinkWindow(QWidget *parent)
tools->addWidget(d->statusButton);

d->consoleButton = new QToolButton;
d->consoleButton->setIcon(icon);
//d->consoleButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
d->consoleButton->setFocusPolicy(Qt::NoFocus);
d->consoleButton->setText(tr("Console"));
d->consoleButton->setCheckable(true);
Expand Down Expand Up @@ -264,7 +271,7 @@ void LinkWindow::closeEvent(QCloseEvent *event)
if(QMessageBox::question(
this,
tr("Close Connection?"),
tr("Connection is still open. Do you want to close it?"),
tr("Connection is still open. Do you want to close the window regardless?"),
QMessageBox::Close | QMessageBox::Cancel) == QMessageBox::Cancel)
{
event->ignore();
Expand Down

0 comments on commit 3da2d75

Please sign in to comment.