From 5e63328f3bcd8b1d1cc7d59350f92cc4185df7c0 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Fri, 1 Jul 2011 17:26:12 +0000 Subject: * gui/conversation.h (OutputTextArea): Now inherit from QTextEditor, for the nth time. (OutputTextArea::sizeHint): Declare as override. * gui/conversation.cc (OutputTextArea::OutputTextArea): Make the output text editor read only. Disallow vertical scroll bars. (OutputTextArea::sizeHint): Give a tight estimate. (OutputTextArea::add_paragraph): Tidy. (OutputTextArea::add_text): Likewise. (Exchange::reply_to_query): Toggle the mouse in busy state after submitting query. (Conversation::read_reply): Untoggle mouse' busy state if last output text was read. --- src/ChangeLog | 15 +++++++++++++++ src/gui/conversation.cc | 26 +++++++++++++++++++++++--- src/gui/conversation.h | 10 ++++++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b1ec2b77..dc33a80c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2011-07-01 Gabriel Dos Reis + + * gui/conversation.h (OutputTextArea): Now inherit from + QTextEditor, for the nth time. + (OutputTextArea::sizeHint): Declare as override. + * gui/conversation.cc (OutputTextArea::OutputTextArea): Make the + output text editor read only. Disallow vertical scroll bars. + (OutputTextArea::sizeHint): Give a tight estimate. + (OutputTextArea::add_paragraph): Tidy. + (OutputTextArea::add_text): Likewise. + (Exchange::reply_to_query): Toggle the mouse in busy state + after submitting query. + (Conversation::read_reply): Untoggle mouse' busy state if last + output text was read. + 2011-06-30 Gabriel Dos Reis * sman/sman.c (main): Don't start Hyperdoc if no X11 server is running. diff --git a/src/gui/conversation.cc b/src/gui/conversation.cc index 0293b494..c3357e0f 100644 --- a/src/gui/conversation.cc +++ b/src/gui/conversation.cc @@ -35,6 +35,7 @@ #include #include +#include #include "conversation.h" #include "debate.h" @@ -64,11 +65,27 @@ namespace OpenAxiom { // -------------------- OutputTextArea::OutputTextArea(QWidget* p) : Base(p) { + setReadOnly(true); // this is a output only area. + setLineWrapMode(NoWrap); // for the time being, mess with nothing. setFont(p->font()); + setViewportMargins(0, 0, 0, 0); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + // We do not want to see scroll bars. Usually disallowing vertical + // scroll bars and allocating enough horizontal space is sufficient + // to ensure that we don't see any horizontal scrollbar. + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setLineWidth(1); } + // This overriding implementation is so that we can control the + // amount of vertical space in the read-only editor viewport allocated + // for the display of output text. In particular we do not want + // scrollbars. + QSize + OutputTextArea::sizeHint() const { + return QSize(width(), document()->lineCount() * fontMetrics().height()); + } + // Concatenate two paragraphs. static QString accumulate_paragaphs(const QString& before, const QString& after) { @@ -78,7 +95,7 @@ namespace OpenAxiom { } void OutputTextArea::add_paragraph(const QString& s) { - setText(accumulate_paragaphs(text(), s)); + setPlainText(accumulate_paragaphs(toPlainText(), s)); QSize sz = sizeHint(); sz.setWidth(parentWidget()->width() - our_margin(this)); resize(sz); @@ -87,7 +104,7 @@ namespace OpenAxiom { } void OutputTextArea::add_text(const QString& s) { - setText(text() + s); + setPlainText(toPlainText() + s); QSize sz = sizeHint(); const int w = parentWidget()->width() - 2 * frameWidth(); if (w > sz.width()) @@ -228,6 +245,7 @@ namespace OpenAxiom { if (empty_string(input)) return; topic()->submit_query(input); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } void Exchange::resizeEvent(QResizeEvent* e) { @@ -393,8 +411,10 @@ namespace OpenAxiom { exchange()->updateGeometry(); if (empty_string(output.prompt)) ensure_visibility(debate(), exchange()); - else + else { ensure_visibility(debate(), next(exchange())); + QApplication::restoreOverrideCursor(); + } } } diff --git a/src/gui/conversation.h b/src/gui/conversation.h index 85220122..8f379f8d 100644 --- a/src/gui/conversation.h +++ b/src/gui/conversation.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -57,10 +57,12 @@ namespace OpenAxiom { // -------------------- // An output text area is a widget where we output text. // The texts are accumulated, as opposed to overwritten. - class OutputTextArea : public QLabel { - typedef QLabel Base; + class OutputTextArea : public QTextEdit { + typedef QTextEdit Base; public: explicit OutputTextArea(QWidget*); + // the metrics of this output area + QSize sizeHint() const; // Add a new paragraph to existing texts. Paragraghs are // separated by the newline character. void add_paragraph(const QString&); @@ -123,7 +125,7 @@ namespace OpenAxiom { // Conversion number int number() const { return no; } - // Reimplement positiion management. + // Reimplement position management. QSize sizeHint() const; protected: -- cgit v1.2.3