diff options
author | dos-reis <gdr@axiomatics.org> | 2011-05-29 17:32:37 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2011-05-29 17:32:37 +0000 |
commit | 1224be2008ce7116ab0e7cc49aa99cabdf853bbf (patch) | |
tree | 94d9d1f3ed8a957978e31b1a30b03d1fbf2293b8 /src/gui | |
parent | 33d71198a65f2c45274a15408223113770d4042c (diff) | |
download | open-axiom-1224be2008ce7116ab0e7cc49aa99cabdf853bbf.tar.gz |
more gui code tweaking
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/conversation.cc | 69 | ||||
-rw-r--r-- | src/gui/conversation.h | 2 | ||||
-rw-r--r-- | src/gui/debate.cc | 6 |
3 files changed, 49 insertions, 28 deletions
diff --git a/src/gui/conversation.cc b/src/gui/conversation.cc index 0c5ec778..d80e891c 100644 --- a/src/gui/conversation.cc +++ b/src/gui/conversation.cc @@ -45,6 +45,15 @@ namespace OpenAxiom { return QSize(fm.width(QLatin1Char('m')), fm.height()); } + // Return true if the QString `s' is morally an empty string. + // QT makes a difference between a null string and an empty string. + // That distinction is largely pedantic and without difference + // for most of our practical purposes. + static bool + empty_string(const QString& s) { + return s.isNull() or s.isEmpty(); + } + // -------------------- // -- OutputTextArea -- // -------------------- @@ -58,27 +67,29 @@ namespace OpenAxiom { // Concatenate two paragraphs. static QString accumulate_paragaphs(const QString& before, const QString& after) { - if (before.isNull() or before.isEmpty()) + if (empty_string(before)) return after; return before + "\n" + after; } void OutputTextArea::add_paragraph(const QString& s) { setText(accumulate_paragaphs(text(), s)); - adjustSize(); + QSize sz = sizeHint(); const int w = parentWidget()->width() - 2 * frameWidth(); - if (w > width()) - resize(w, height()); + if (w > sz.width()) + sz.setWidth(w); + resize(sz); show(); updateGeometry(); } void OutputTextArea::add_text(const QString& s) { setText(text() + s); - adjustSize(); - const int w = parentWidget()->width(); - if (w < width()) - resize(w, height()); + QSize sz = sizeHint(); + const int w = parentWidget()->width() - 2 * frameWidth(); + if (w > sz.width()) + sz.setWidth(w); + resize(sz); show(); updateGeometry(); } @@ -153,7 +164,6 @@ namespace OpenAxiom { static void finish_exchange_make_up(Conversation& conv, Exchange* e) { e->setAutoFillBackground(true); - //e->setBackgroundRole(e->question()->backgroundRole()); e->move(conv.bottom_left()); } @@ -184,10 +194,9 @@ namespace OpenAxiom { void Exchange::reply_to_query() { QString input = question()->text().trimmed(); - if (input.isEmpty()) + if (empty_string(input)) return; - topic()->oracle()->write(input.toAscii()); - topic()->oracle()->write("\n"); + topic()->submit_query(input); } void Exchange::resizeEvent(QResizeEvent* e) { @@ -225,18 +234,14 @@ namespace OpenAxiom { // messes with it. Indicate we can make use of more space. Conversation::Conversation(Debate& parent) : group(parent), greatings(this), cur_ex(), cur_out(&greatings) { - setBackgroundRole(QPalette::Base); setFont(monospace_font()); - // setMinimumSize(minimum_preferred_size(this)); - // setSizePolicy(QSizePolicy::MinimumExpanding, - // QSizePolicy::MinimumExpanding); + setBackgroundRole(QPalette::Base); + greatings.setFont(font()); oracle()->setProcessChannelMode(QProcess::MergedChannels); connect(oracle(), SIGNAL(readyReadStandardOutput()), this, SLOT(read_reply())); // connect(oracle(), SIGNAL(readyReadStandardError()), // this, SLOT(read_reply())); - // connect(oracle(), SIGNAL(started()), - // this, SLOT(read_reply())); } Conversation::~Conversation() { @@ -313,11 +318,6 @@ namespace OpenAxiom { QString prompt; }; - static bool - empty_string(const QString& s) { - return s.isNull() or s.isEmpty(); - } - static OracleOutput read_output(QProcess& proc) { OracleOutput output; @@ -338,13 +338,20 @@ namespace OpenAxiom { return output; } + static bool + empty(const OracleOutput& out) { + return empty_string(out.result) and empty_string(out.prompt); + } + void Conversation::read_reply() { OracleOutput output = read_output(proc); - if (empty_string(output.result)) + if (empty(output)) return; - std::cerr << output.result.toStdString() << std::endl; - cur_out->add_paragraph(output.result); + if (not empty_string(output.result)) { + cur_out->add_paragraph(output.result); + adjustSize(); + } if (length() == 0) { if (not empty_string(output.prompt)) ensure_visibility(debate(), new_topic()); @@ -353,8 +360,16 @@ namespace OpenAxiom { exchange()->adjustSize(); exchange()->update(); exchange()->updateGeometry(); - if (not empty_string(output.prompt)) + if (empty_string(output.prompt)) + ensure_visibility(debate(), exchange()); + else ensure_visibility(debate(), next(exchange())); } } + + void + Conversation::submit_query(const QString& s) { + oracle()->write(s.toAscii()); + oracle()->write("\n"); + } } diff --git a/src/gui/conversation.h b/src/gui/conversation.h index 374dda16..2a174e58 100644 --- a/src/gui/conversation.h +++ b/src/gui/conversation.h @@ -180,6 +180,8 @@ namespace OpenAxiom { // Return the parent engine widget. Debate* debate() const { return const_cast<Debate*>(&group); } + void submit_query(const QString&); + public slots: // Return the topic following a given topic in this set of conversations Exchange* next(Exchange*); diff --git a/src/gui/debate.cc b/src/gui/debate.cc index ba58c522..24608c0f 100644 --- a/src/gui/debate.cc +++ b/src/gui/debate.cc @@ -38,8 +38,12 @@ namespace OpenAxiom { static void start_interpreter(Conversation* conv) { QStringList args; - args << "--no-server" << "--role=slave"; + args << "--no-server" << "--role=server"; conv->oracle()->start("open-axiom",args); + // When invoked in a --role=server mode, OpenAxiom would + // wait to be pinged before displayed a prompt. This is + // an unfortunate result of a rather awkward hack. + conv->submit_query(""); } Debate::Debate(QWidget* parent) |