Skip to content

Commit

Permalink
libshell: Removing Qt dependencies; using Observers instead of signals
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent e71e509 commit 9ce7d3a
Show file tree
Hide file tree
Showing 56 changed files with 956 additions and 976 deletions.
15 changes: 7 additions & 8 deletions doomsday/libs/shell/include/de/shell/abstractlineeditor.h
Expand Up @@ -21,6 +21,7 @@

#include "libshell.h"
#include "ITextEditor"
#include "KeyEvent"
#include <de/libcore.h>
#include <de/String>
#include <de/Vector>
Expand Down Expand Up @@ -71,10 +72,10 @@ class LIBSHELL_PUBLIC AbstractLineEditor : public ITextEditor

Vec2i lineCursorPos() const { return linePos(cursor()); }

bool isSuggestingCompletion() const;
Rangei completionRange() const;
QStringList suggestedCompletions() const;
void acceptCompletion();
bool isSuggestingCompletion() const;
Rangei completionRange() const;
StringList suggestedCompletions() const;
void acceptCompletion();

/**
* Defines the terms and rules for auto-completion.
Expand All @@ -97,9 +98,9 @@ class LIBSHELL_PUBLIC AbstractLineEditor : public ITextEditor
EchoMode echoMode() const;

enum KeyModifier { Unmodified = 0, Shift = 0x1, Control = 0x2, Alt = 0x4, Meta = 0x8 };
Q_DECLARE_FLAGS(KeyModifiers, KeyModifier)
using KeyModifiers = Flags;

virtual bool handleControlKey(int qtKey, KeyModifiers const &mods = Unmodified);
virtual bool handleControlKey(Key key, KeyModifiers const &mods = Unmodified);

/**
* Inserts a fragment of text at the cursor position. The cursor moves
Expand Down Expand Up @@ -131,8 +132,6 @@ class LIBSHELL_PUBLIC AbstractLineEditor : public ITextEditor
DE_PRIVATE(d)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractLineEditor::KeyModifiers)

}} // namespace de::shell

#endif // LIBSHELL_ABSTRACTLINEEDITOR_H
19 changes: 5 additions & 14 deletions doomsday/libs/shell/include/de/shell/abstractlink.h
Expand Up @@ -24,7 +24,6 @@
#include <de/Socket>
#include <de/Time>
#include <de/Transmitter>
#include <QObject>

namespace de { namespace shell {

Expand All @@ -36,11 +35,8 @@ namespace de { namespace shell {
* @ingroup shell
*/
class LIBSHELL_PUBLIC AbstractLink
: public QObject
, public Transmitter
: public Transmitter
{
Q_OBJECT

public:
enum Status { Disconnected, Connecting, Connected };

Expand Down Expand Up @@ -110,15 +106,10 @@ class LIBSHELL_PUBLIC AbstractLink
*/
virtual void initiateCommunications() = 0;

protected slots:
void socketConnected();
void socketDisconnected();

signals:
void addressResolved();
void connected();
void disconnected();
void packetsReady();
DE_DEFINE_AUDIENCE2(AddressResolved, void addressResolved())
DE_DEFINE_AUDIENCE2(Connected, void connected())
DE_DEFINE_AUDIENCE2(Disconnected, void disconnected())
DE_DEFINE_AUDIENCE2(PacketsReady, void packetsReady())

private:
DE_PRIVATE(d)
Expand Down
29 changes: 11 additions & 18 deletions doomsday/libs/shell/include/de/shell/action.h
Expand Up @@ -21,7 +21,6 @@

#include "KeyEvent"
#include <de/Action>
#include <QObject>

namespace de { namespace shell {

Expand All @@ -30,20 +29,21 @@ namespace de { namespace shell {
*
* @ingroup textUi
*/
class Action
: public QObject
, public de::Action
class Action : public de::Action
{
Q_OBJECT
public:
using Func = std::function<void()>;

public:
Action(String const &label);
Action(const String &label);

Action(const String &label, const Func &func);

Action(String const &label, QObject *target, char const *slot = 0);
// Action(String const &label, QObject *target, char const *slot = 0);

Action(String const &label, KeyEvent const &event, QObject *target = 0, char const *slot = 0);
Action(const String &label, const KeyEvent &event, const Func &func = {});

Action(KeyEvent const &event, QObject *target = 0, char const *slot = 0);
// Action(KeyEvent const &event, QObject *target = 0, char const *slot = 0);

void setLabel(String const &label);

Expand All @@ -58,19 +58,12 @@ class Action
*/
bool tryTrigger(KeyEvent const &ev);

void trigger();

signals:
void triggered();

protected:
~Action();

private:
KeyEvent _event;
String _label;
QObject * _target;
char const *_slot;
KeyEvent _event;
String _label;
};

}} // namespace de::shell
Expand Down
23 changes: 8 additions & 15 deletions doomsday/libs/shell/include/de/shell/choicewidget.h
Expand Up @@ -19,8 +19,8 @@
#ifndef LIBSHELL_CHOICEWIDGET_H
#define LIBSHELL_CHOICEWIDGET_H

#include "LabelWidget"
#include <QList>
#include "LabelTextWidget"
#include <de/List>

namespace de { namespace shell {

Expand All @@ -29,27 +29,21 @@ namespace de { namespace shell {
*
* @ingroup textUi
*/
class LIBSHELL_PUBLIC ChoiceWidget : public LabelWidget
class LIBSHELL_PUBLIC ChoiceTextWidget : public LabelTextWidget
{
Q_OBJECT

public:
typedef QList<String> Items;
typedef StringList Items;

public:
ChoiceWidget(String const &name = String());
ChoiceTextWidget(String const &name = String());

void setItems(Items const &items);

void setPrompt(String const &prompt);

Items items() const;

void select(int pos);

int selection() const;

QList<int> selections() const;
Items items() const;
int selection() const;
List<int> selections() const;

/**
* Determines if the selection menu is currently visible.
Expand All @@ -64,7 +58,6 @@ class LIBSHELL_PUBLIC ChoiceWidget : public LabelWidget
void draw();
bool handleEvent(Event const &event);

protected slots:
void updateSelectionFromMenu();
void menuClosed();

Expand Down
12 changes: 5 additions & 7 deletions doomsday/libs/shell/include/de/shell/commandlinewidget.h
Expand Up @@ -19,7 +19,7 @@
#ifndef LIBSHELL_COMMANDLINEWIDGET_H
#define LIBSHELL_COMMANDLINEWIDGET_H

#include "LineEditWidget"
#include "LineEditTextWidget"

namespace de { namespace shell {

Expand All @@ -28,17 +28,15 @@ namespace de { namespace shell {
*
* @ingroup textUi
*/
class LIBSHELL_PUBLIC CommandLineWidget : public LineEditWidget
class LIBSHELL_PUBLIC CommandLineTextWidget : public LineEditTextWidget
{
Q_OBJECT
public:
DE_DEFINE_AUDIENCE2(Command, void commandEntered(de::String command))

public:
CommandLineWidget(String const &name = String());
CommandLineTextWidget(String const &name = String());
bool handleEvent(Event const &event);

signals:
void commandEntered(de::String command);

protected:
void autoCompletionBegan(String const &wordBase);

Expand Down
13 changes: 5 additions & 8 deletions doomsday/libs/shell/include/de/shell/dialogwidget.h
Expand Up @@ -28,12 +28,14 @@ namespace de { namespace shell {
*
* @ingroup textUi
*/
class LIBSHELL_PUBLIC DialogWidget : public TextWidget
class LIBSHELL_PUBLIC DialogTextWidget : public TextWidget
{
Q_OBJECT
public:
DE_DEFINE_AUDIENCE2(Accept, void accepted(int result))
DE_DEFINE_AUDIENCE2(Reject, void rejected(int result))

public:
DialogWidget(String const &name = String());
DialogTextWidget(String const &name = String());

/**
* Shows the dialog and gives it focus. Execution is blocked until the
Expand All @@ -50,7 +52,6 @@ class LIBSHELL_PUBLIC DialogWidget : public TextWidget
void draw();
bool handleEvent(Event const &event);

public slots:
void accept(int result = 1);
void reject(int result = 0);

Expand All @@ -70,10 +71,6 @@ public slots:
*/
virtual void finish(int result);

signals:
void accepted(int result);
void rejected(int result);

private:
DE_PRIVATE(d)
};
Expand Down
22 changes: 12 additions & 10 deletions doomsday/libs/shell/include/de/shell/doomsdayinfo.h
Expand Up @@ -22,7 +22,6 @@
#include "libshell.h"
#include <de/String>
#include <de/NativePath>
#include <QList>

namespace de { namespace shell {

Expand Down Expand Up @@ -55,26 +54,29 @@ class LIBSHELL_PUBLIC DoomsdayInfo
{}
};

OptionType type;
String title;
String command; // e.g., "setmap %1"
Value defaultValue;
QList<Value> allowedValues;
OptionType type;
String title;
String command; // e.g., "setmap %1"
Value defaultValue;
List<Value> allowedValues;

GameOption(OptionType type, String title, String command, Value defaultValue = Value(),
QList<Value> allowedValues = QList<Value>());
GameOption(OptionType type,
String title,
String command,
Value defaultValue = Value(),
const List<Value> &allowedValues = List<Value>());
};

/**
* Returns a list containing all the supported games with the
* human-presentable titles plus game mode identifiers (for the @c -game
* option).
*/
static QList<Game> allGames();
static List<Game> allGames();

static String titleForGame(String const &gameId);

static QList<GameOption> gameOptions(String const &gameId);
static List<GameOption> gameOptions(String const &gameId);

static NativePath defaultServerRuntimeFolder();
};
Expand Down
9 changes: 5 additions & 4 deletions doomsday/libs/shell/include/de/shell/editorhistory.h
Expand Up @@ -20,6 +20,7 @@
#define LIBSHELL_EDITORHISTORY_H

#include "ITextEditor"
#include "KeyEvent"

namespace de { namespace shell {

Expand All @@ -32,7 +33,7 @@ namespace de { namespace shell {
class LIBSHELL_PUBLIC EditorHistory
{
public:
EditorHistory(ITextEditor *editor = 0);
EditorHistory(ITextEditor *editor = nullptr);

void setEditor(ITextEditor &editor);
ITextEditor &editor();
Expand All @@ -59,11 +60,11 @@ class LIBSHELL_PUBLIC EditorHistory
/**
* Handles a key. History control keys include navigation in the history.
*
* @param qtKey Qt key code.
* @param key Key code.
*
* @return @c true, if key was handled.
*/
bool handleControlKey(int qtKey);
bool handleControlKey(Key key);

/**
* Returns the history contents.
Expand All @@ -72,7 +73,7 @@ class LIBSHELL_PUBLIC EditorHistory
*/
StringList fullHistory(int maxCount = 0) const;

void setFullHistory(StringList history);
void setFullHistory(const StringList& history);

private:
DE_PRIVATE(d)
Expand Down
20 changes: 10 additions & 10 deletions doomsday/libs/shell/include/de/shell/inputdialog.h
Expand Up @@ -19,27 +19,27 @@
#ifndef LIBSHELL_INPUTDIALOG_H
#define LIBSHELL_INPUTDIALOG_H

#include "DialogWidget"
#include "DialogTextWidget"

namespace de { namespace shell {

class LabelWidget;
class LineEditWidget;
class MenuWidget;
class LabelTextWidget;
class LineEditTextWidget;
class MenuTextWidget;

/**
* Dialog for querying text from the user.
*
* @ingroup textUi
*/
class InputDialog : public de::shell::DialogWidget
class InputDialogTextWidget : public DialogTextWidget
{
public:
InputDialog(de::String const &name = de::String());
InputDialogTextWidget(const String &name = {});

LabelWidget & label();
LineEditWidget &lineEdit();
MenuWidget & menu();
LabelTextWidget & label();
LineEditTextWidget &lineEdit();
MenuTextWidget & menu();

/**
* Sets the width of the dialog. The default width is 50.
Expand All @@ -61,7 +61,7 @@ class InputDialog : public de::shell::DialogWidget
* Returns the text that the user entered in the dialog. If the dialog
* was rejected, the returned string is empy.
*/
de::String text() const;
String text() const;

/**
* Returns the result from the DialogWidget.
Expand Down

0 comments on commit 9ce7d3a

Please sign in to comment.