aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2013-04-08 02:59:02 +0000
committerdos-reis <gdr@axiomatics.org>2013-04-08 02:59:02 +0000
commit5c8f501196981142b3b2a4f5c896e08d90792130 (patch)
tree709da7ab5e404f0026eac69d7f4e5fa1c6918545
parenta81374ddea280fa56d1bcbb287f41d1ea248c5f7 (diff)
downloadopen-axiom-5c8f501196981142b3b2a4f5c896e08d90792130.tar.gz
misc gui cleanup
-rw-r--r--src/ChangeLog12
-rw-r--r--src/gui/conversation.cc36
-rw-r--r--src/gui/conversation.h14
-rw-r--r--src/gui/debate.cc6
-rw-r--r--src/gui/debate.h2
-rw-r--r--src/gui/gui.pro.in2
-rw-r--r--src/gui/widget.h51
7 files changed, 46 insertions, 77 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 67db9210..59b3b342 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,9 +1,21 @@
2013-04-07 Gabriel Dos Reis <gdr@integrable-solutions.net>
+ * gui/widget.h: Remove. Qt's meta object system does no play nice
+ with modern C++ idioms.
+
+2013-04-07 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
* utils/command.cc (args_count): New.
(execute_core): Use it. Tidy.
(Arguments::Arguments): Tidy.
+2013-04-06 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * gui/server.h: New.
+ * gui/server.cc: Likewise..
+ * gui/gui.pro.in (HEADERS): Update.
+ (SOURCES): Likewise.
+
2013-04-05 Gabriel Dos Reis <gdr@integrable-solutions.net>
* include/token.H: New.
diff --git a/src/gui/conversation.cc b/src/gui/conversation.cc
index 4cca97df..d3301d79 100644
--- a/src/gui/conversation.cc
+++ b/src/gui/conversation.cc
@@ -119,7 +119,7 @@ namespace OpenAxiom {
// --------------
// -- Question --
// --------------
- Question::Question(Exchange* e) : super(e) {
+ Question::Question(Exchange* e) : QLineEdit(e) {
setBackgroundRole(QPalette::AlternateBase);
setFrame(true);
}
@@ -127,19 +127,19 @@ namespace OpenAxiom {
void Question::focusInEvent(QFocusEvent* e) {
setFrame(true);
update();
- super::focusInEvent(e);
+ QLineEdit::focusInEvent(e);
}
void Question::enterEvent(QEvent* e) {
setFrame(true);
update();
- super::enterEvent(e);
+ QLineEdit::enterEvent(e);
}
// ------------
// -- Answer --
// ------------
- Answer::Answer(Exchange* e) : super(e) {
+ Answer::Answer(Exchange* e) : OutputTextArea(e) {
setFrameStyle(StyledPanel | Raised);
}
@@ -168,6 +168,10 @@ namespace OpenAxiom {
return sz;
}
+ Server* Exchange::server() const {
+ return win->debate()->server();
+ }
+
// Dress the query area with initial properties.
static void
prepare_query_widget(Conversation* conv, Exchange* e) {
@@ -200,7 +204,7 @@ namespace OpenAxiom {
}
Exchange::Exchange(Conversation* conv, int n)
- : super(conv), no(n), query(this), reply(this) {
+ : QFrame(conv), win(conv), no(n), query(this), reply(this) {
setLineWidth(1);
setFont(conv->font());
prepare_query_widget(conv, this);
@@ -233,7 +237,7 @@ namespace OpenAxiom {
QString input = question()->text().trimmed();
if (empty_string(input))
return;
- parent()->parent()->server()->input(input);
+ server()->input(input);
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
}
@@ -270,13 +274,13 @@ namespace OpenAxiom {
// Set a minimum preferred widget size, so no layout manager
// messes with it. Indicate we can make use of more space.
- Conversation::Conversation(Debate* debate)
- : super(debate), greatings(this), cur_ex(), cur_out(&greatings) {
+ Conversation::Conversation(Debate* d)
+ : QWidget(d), win(d), greatings(this), cur_ex(), cur_out(&greatings) {
setFont(monospace_font());
setBackgroundRole(QPalette::Base);
greatings.setFont(font());
- // connect(parent()->server(), SIGNAL(readyReadStandardOutput()),
- // this, SLOT(read_reply()));
+ connect(win->server(), SIGNAL(readyReadStandardOutput()),
+ this, SLOT(read_reply()));
}
Conversation::~Conversation() {
@@ -302,7 +306,7 @@ namespace OpenAxiom {
const int n = length();
if (n == 0)
return minimum_preferred_size(this);
- const int view_height = parent()->viewport()->height();
+ const int view_height = debate()->viewport()->height();
QSize sz = greatings.size();
for (int i = 0; i < n; ++i)
sz.rheight() += children[i]->height();
@@ -310,7 +314,7 @@ namespace OpenAxiom {
}
void Conversation::resizeEvent(QResizeEvent* e) {
- super::resizeEvent(e);
+ QWidget::resizeEvent(e);
setMinimumSize(size());
const QSize sz = size();
if (e->oldSize() == sz)
@@ -378,7 +382,7 @@ namespace OpenAxiom {
void
Conversation::read_reply() {
- OracleOutput output = read_output(parent()->server());
+ OracleOutput output = read_output(debate()->server());
if (empty(output))
return;
if (not empty_string(output.result)) {
@@ -387,16 +391,16 @@ namespace OpenAxiom {
}
if (length() == 0) {
if (not empty_string(output.prompt))
- ensure_visibility(parent(), new_topic());
+ ensure_visibility(debate(), new_topic());
}
else {
exchange()->adjustSize();
exchange()->update();
exchange()->updateGeometry();
if (empty_string(output.prompt))
- ensure_visibility(parent(), exchange());
+ ensure_visibility(debate(), exchange());
else {
- ensure_visibility(parent(), next(exchange()));
+ ensure_visibility(debate(), next(exchange()));
QApplication::restoreOverrideCursor();
}
}
diff --git a/src/gui/conversation.h b/src/gui/conversation.h
index d25960a1..90f461a7 100644
--- a/src/gui/conversation.h
+++ b/src/gui/conversation.h
@@ -40,7 +40,6 @@
#include <QEvent>
#include <QResizeEvent>
#include <QPaintEvent>
-#include "widget.h"
#include "server.h"
namespace OpenAxiom {
@@ -77,7 +76,7 @@ namespace OpenAxiom {
// -- Question --
// ---------------
// A question is just a one-liner query area.
- struct Question : managed_by<QLineEdit, Exchange> {
+ struct Question : QLineEdit {
explicit Question(Exchange*);
protected:
@@ -88,14 +87,14 @@ namespace OpenAxiom {
// ------------
// -- Answer --
// ------------
- struct Answer : managed_by<OutputTextArea, Exchange> {
+ struct Answer : OutputTextArea {
explicit Answer(Exchange*);
};
// --------------
// -- Exchange --
// --------------
- class Exchange : public managed_by<QFrame, Conversation> {
+ class Exchange : public QFrame {
Q_OBJECT;
public:
Exchange(Conversation*, int);
@@ -103,6 +102,7 @@ namespace OpenAxiom {
// The widget holding the query area
Question* question() { return &query; }
const Question* question() const { return &query; }
+ Server* server() const;
// The widget holding the reply area.
Answer* answer() { return &reply; }
@@ -118,6 +118,7 @@ namespace OpenAxiom {
void resizeEvent(QResizeEvent*);
private:
+ Conversation* const win;
const int no;
Question query;
Answer reply;
@@ -137,12 +138,14 @@ namespace OpenAxiom {
// -- We remember and number each topic so that we
// -- can go back in the conversation set and reevaluate
// -- queries.
- class Conversation : public managed_by<QWidget, Debate> {
+ class Conversation : public QWidget {
Q_OBJECT;
public:
explicit Conversation(Debate*);
~Conversation();
+ Debate* debate() const { return win; }
+
// Holds if this conversation just started.
bool fresh() const { return children.empty(); }
@@ -179,6 +182,7 @@ namespace OpenAxiom {
private:
typedef std::vector<Exchange*> Children;
+ Debate* const win;
Banner greatings;
Children children;
Exchange* cur_ex;
diff --git a/src/gui/debate.cc b/src/gui/debate.cc
index ebc7cb7b..1554bcb2 100644
--- a/src/gui/debate.cc
+++ b/src/gui/debate.cc
@@ -36,8 +36,8 @@
namespace OpenAxiom {
- Debate::Debate(MainWindow* win)
- : QScrollArea(win), conv(this) {
+ Debate::Debate(MainWindow* w)
+ : QScrollArea(w), win(w), conv(this) {
setWidget(&conv);
setViewportMargins(0, 0, 0, 0);
viewport()->setAutoFillBackground(true);
@@ -51,7 +51,7 @@ namespace OpenAxiom {
Server*
Debate::server() const {
- return qobject_cast<MainWindow*>(parent())->server();
+ return win->server();
}
void Debate::resizeEvent(QResizeEvent* e) {
diff --git a/src/gui/debate.h b/src/gui/debate.h
index c485fa37..64bba63d 100644
--- a/src/gui/debate.h
+++ b/src/gui/debate.h
@@ -37,7 +37,6 @@
#include <QScrollArea>
#include <QResizeEvent>
#include "open-axiom.h"
-#include "widget.h"
#include "conversation.h"
namespace OpenAxiom {
@@ -55,6 +54,7 @@ namespace OpenAxiom {
void resizeEvent(QResizeEvent*);
private:
+ MainWindow* const win;
Conversation conv;
};
}
diff --git a/src/gui/gui.pro.in b/src/gui/gui.pro.in
index 491b0a9c..30e70349 100644
--- a/src/gui/gui.pro.in
+++ b/src/gui/gui.pro.in
@@ -27,7 +27,7 @@ TARGET = gui
VPATH += @srcdir@
## Our headers
-HEADERS += widget.h server.h conversation.h main-window.h debate.h
+HEADERS += server.h conversation.h main-window.h debate.h
INCLUDEPATH += $$OA_INC
INCLUDEPATH += @srcdir@
INCLUDEPATH += @top_srcdir@/src/include
diff --git a/src/gui/widget.h b/src/gui/widget.h
deleted file mode 100644
index 1ccf8573..00000000
--- a/src/gui/widget.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (C) 2013, Gabriel Dos Reis.
-// All rights reserved.
-// Written by Gabriel Dos Reis.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// - Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//
-// - Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in
-// the documentation and/or other materials provided with the
-// distribution.
-//
-// - Neither the name of OpenAxiom. nor the names of its contributors
-// may be used to endorse or promote products derived from this
-// software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef OPENAXIOM_WIDGET_included
-#define OPENAXIOM_WIDGET_included
-
-#include <QWidget>
-
-namespace OpenAxiom {
- template<typename S, typename T>
- struct managed_by : S {
- using super = managed_by<S, T>;
- managed_by(T* t) : S(t) { }
- T* parent() const { return qobject_cast<T*>(S::parent()); }
- };
-}
-
-#endif // OPENAXIOM_WIDGET_included
-
-// Local Variables:
-// mode: c++
-// End: