diff options
author | dos-reis <gdr@axiomatics.org> | 2011-05-27 02:35:11 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2011-05-27 02:35:11 +0000 |
commit | 62eada33ca1078387a8744344d933fb7ada76348 (patch) | |
tree | 142af41701eaa66e1c2aba65e38730dfb6acbb93 /src/gui | |
parent | 2ffc3883061b8d61a387bcff63a1cae1756afff4 (diff) | |
download | open-axiom-62eada33ca1078387a8744344d933fb7ada76348.tar.gz |
more gui codes
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/conversation.C | 38 | ||||
-rw-r--r-- | src/gui/conversation.h | 5 | ||||
-rw-r--r-- | src/gui/debate.C | 9 | ||||
-rw-r--r-- | src/gui/debate.h | 4 | ||||
-rw-r--r-- | src/gui/main-window.C | 6 | ||||
-rw-r--r-- | src/gui/main-window.h | 4 |
6 files changed, 49 insertions, 17 deletions
diff --git a/src/gui/conversation.C b/src/gui/conversation.C index e15facf0..df30f619 100644 --- a/src/gui/conversation.C +++ b/src/gui/conversation.C @@ -39,6 +39,11 @@ #include "debate.h" namespace OpenAxiom { + static void debug_size(const char* s, const QSize& sz) { + std::cerr << s << " == " + << sz.width() << ", " << sz.height() << std::endl; + } + // Measurement in pixel of the em unit in the given font `f'. static QSize em_metrics(const QWidget* w) { const QFontMetrics fm = w->fontMetrics(); @@ -46,15 +51,17 @@ namespace OpenAxiom { } // -- Question -- - Question::Question(Exchange& e) : QLineEdit(&e), parent(&e) { } + Question::Question(Exchange& e) : Base(&e), parent(&e) { } void Question::enterEvent(QEvent* e) { - QLineEdit::enterEvent(e); + Base::enterEvent(e); setFocus(Qt::OtherFocusReason); } // -- Answer -- - Answer::Answer(Exchange& e) : QLabel(&e), parent(&e) { } + Answer::Answer(Exchange& e) : Base(&e), parent(&e) { + setReadOnly(true); + } // -- Exchange -- // Amount of pixel spacing between the query and reply areas. @@ -77,7 +84,6 @@ namespace OpenAxiom { // -- an output area with its own decoration accounted for. QSize Exchange::sizeHint() const { QSize sz = question()->frameSize(); - sz.rwidth() += 2 * margin(this); if (not answer()->isHidden()) sz.rheight() += answer()->frameSize().height() + spacing; return sz; @@ -97,7 +103,7 @@ namespace OpenAxiom { // Place the reply widget right below the frame containing // the query widget; make both of the same width, of course. static void - prepare_reply_widget(Conversation& conv, Exchange* e) { + prepare_reply_widget(Exchange* e) { Answer* a = e->answer(); Question* q = e->question(); const QPoint pt = e->question()->frameGeometry().bottomLeft(); @@ -120,7 +126,7 @@ namespace OpenAxiom { setLineWidth(1); setFont(conv.font()); prepare_query_widget(conv, this); - prepare_reply_widget(conv, this); + prepare_reply_widget(this); finish_exchange_make_up(conv, this); connect(question(), SIGNAL(returnPressed()), this, SLOT(reply_to_query())); @@ -134,16 +140,14 @@ namespace OpenAxiom { } static void ensure_visibility(Debate* debate, Exchange* e) { - const int y = e->frameGeometry().y(); + const int y = e->frameGeometry().bottomLeft().y(); QScrollBar* vbar = debate->verticalScrollBar(); const int value = vbar->value(); int new_value = y - vbar->pageStep(); if (y < value) vbar->setValue(std::max(new_value, 0)); - else if (new_value > value) { - new_value += 3 * vbar->singleStep(); + else if (new_value > value) vbar->setValue(std::min(new_value, vbar->maximum())); - } e->question()->setFocus(Qt::OtherFocusReason); } @@ -181,9 +185,11 @@ namespace OpenAxiom { static QSize minimum_preferred_size(const Conversation* conv) { const QSize em = em_metrics(conv); - return QSize(columns * em.width(), 25 * em.height()); + return QSize(columns * em.width(), 2 * lines * em.height()); } - + + // Set a minimum preferred widget size, so no layout manager + // messes with it. Indicate we can make use of more space. Conversation::Conversation(Debate& parent) : group(parent) { setFont(monospace_font()); setMinimumSize(minimum_preferred_size(this)); @@ -210,14 +216,17 @@ namespace OpenAxiom { sz.setWidth(s.width()); sz.rheight() += s.height(); } - int view_height = debate()->viewport()->width(); + int view_height = debate()->viewport()->height(); if (view_height == 0) - view_height = lines * em_metrics(this).height(); + view_height = 2 * lines * em_metrics(this).height(); const int n = (sz.height() + view_height) / view_height; return QSize(sz.width(), n * view_height); } void Conversation::resizeEvent(QResizeEvent* e) { + std::cerr << "-- Conversation::resizeEvent --" << std::endl; + debug_size("viewport.size", debate()->viewport()->size()); + debug_size("conv.size", size()); const QSize sz = size(); if (e->oldSize() == sz) return; @@ -225,7 +234,6 @@ namespace OpenAxiom { Exchange* e = children[i]; e->resize(sz.width(), e->height()); } - debate()->updateGeometry(); } void Conversation::paintEvent(QPaintEvent* e) { diff --git a/src/gui/conversation.h b/src/gui/conversation.h index abe6d4c2..50f19b0c 100644 --- a/src/gui/conversation.h +++ b/src/gui/conversation.h @@ -35,6 +35,7 @@ #include <vector> #include <QFrame> #include <QLineEdit> +#include <QTextEdit> #include <QLabel> #include <QFont> #include <QEvent> @@ -53,6 +54,7 @@ namespace OpenAxiom { // -- A question is just a one-liner query. class Question : public QLineEdit { + typedef QLineEdit Base; public: explicit Question(Exchange&); Exchange* exchange() const { return parent; } @@ -65,7 +67,8 @@ namespace OpenAxiom { Exchange* const parent; }; - class Answer : public QLabel { + class Answer : public QTextEdit { + typedef QTextEdit Base; public: explicit Answer(Exchange&); Exchange* exchange() const { return parent; } diff --git a/src/gui/debate.C b/src/gui/debate.C index 9df68484..8e0bb25e 100644 --- a/src/gui/debate.C +++ b/src/gui/debate.C @@ -41,9 +41,16 @@ namespace OpenAxiom { setViewportMargins(0, 0, 0, 0); viewport()->setAutoFillBackground(true); viewport()->setBackgroundRole(conv.backgroundRole()); - // setWidgetResizable(true); + //resize(conv.size()); + adjustSize(); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); } Debate::~Debate() { } + void Debate::resizeEvent(QResizeEvent* e) { + QScrollArea::resizeEvent(e); + conv.resize(viewport()->size()); + } + } diff --git a/src/gui/debate.h b/src/gui/debate.h index 236967b3..cf645880 100644 --- a/src/gui/debate.h +++ b/src/gui/debate.h @@ -35,6 +35,7 @@ #include <QWidget> #include <QFontMetrics> #include <QScrollArea> +#include <QResizeEvent> #include "conversation.h" namespace OpenAxiom { @@ -46,6 +47,9 @@ namespace OpenAxiom { Conversation* exchanges() { return &conv; } + protected: + void resizeEvent(QResizeEvent*); + private: Conversation conv; }; diff --git a/src/gui/main-window.C b/src/gui/main-window.C index b4097197..21571532 100644 --- a/src/gui/main-window.C +++ b/src/gui/main-window.C @@ -37,6 +37,11 @@ namespace OpenAxiom { + static void + try_to_honor_widget_size(MainWindow* w, Debate* debate) { + w->resize(debate->size()); + } + MainWindow::MainWindow() : tabs(this) { setCentralWidget(&tabs); Debate* debate = new Debate(&tabs); @@ -46,6 +51,7 @@ namespace OpenAxiom { file->addAction(action); action->setShortcut(tr("Ctrl+Q")); connect(action, SIGNAL(triggered()), this, SLOT(close())); + try_to_honor_widget_size(this, debate); } MainWindow::~MainWindow() { diff --git a/src/gui/main-window.h b/src/gui/main-window.h index af9d3d87..1d94e3ea 100644 --- a/src/gui/main-window.h +++ b/src/gui/main-window.h @@ -51,3 +51,7 @@ namespace OpenAxiom { #endif // OPENAXIOM_GUI_MAIN_WINDOW_INCLUDED + +// Local Variables: +// mode: c++ +// End: |