Commit 2f793bd4 authored by Tomas Mecir's avatar Tomas Mecir

layouting fixes

parent 0740e87d
......@@ -24,6 +24,7 @@
#include <QAction>
#include <QFontDatabase>
#include <QGraphicsTextItem>
#include <QScrollBar>
#include <QTextCursor>
#include <QTextDocument>
......@@ -60,9 +61,40 @@ class KMUDDY_EXPORT cHistoryBuffer {
cTextChunk **buffer;
};
class cTextOutputItem : public QGraphicsTextItem {
public:
cTextOutputItem(bool sec) {
isSecondary = sec;
percentHeight = sec ? 25 : 0;
}
virtual QRectF boundingRect() const override {
QGraphicsScene *sc = scene();
if (sc->views().isEmpty()) return QRectF (0, 0, 0, 0);
QGraphicsView *view = sc->views().first();
double w = view->viewport()->width();
double h = view->viewport()->height();
if (isSecondary) h = h * percentHeight / 100;
else h = max (h, document()->pageSize().height());
return QRectF (0, 0, w, h);
}
void setPercentHeight (int ph) {
percentHeight = ph; updateSize();
}
void updateSize () {
prepareGeometryChange();
}
protected:
bool isSecondary;
int percentHeight;
};
class cConsole::Private {
QGraphicsScene scene;
QGraphicsTextItem *mainText, *scrollText;
cTextOutputItem *mainText, *scrollText;
QTextDocument *text;
QColor bgcolor;
......@@ -84,6 +116,18 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
d->charHeight = 12;
d->wantNewLine = false;
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
//and connect() slider so that aconsole is shown/hidden as needed
connect (verticalScrollBar (), SIGNAL (sliderMoved (int)), this, SLOT (sliderChanged (int)));
connect (verticalScrollBar (), SIGNAL (valueChanged (int)), this, SLOT (sliderChanged (int)));
//size policy
QSizePolicy qsp (QSizePolicy::Expanding, QSizePolicy::Expanding);
setSizePolicy (qsp);
viewport()->setSizePolicy (qsp);
d->text = new QTextDocument;
QString stylesheet = "body { color: " + QColor (Qt::lightGray).name() + "; } ";
d->text->setDefaultStyleSheet (stylesheet);
......@@ -91,13 +135,14 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
opt.setWrapMode (QTextOption::WrapAtWordBoundaryOrAnywhere);
d->text->setDefaultTextOption (opt);
d->mainText = new QGraphicsTextItem;
d->scrollText = new QGraphicsTextItem;
d->mainText = new cTextOutputItem (false);
d->scrollText = new cTextOutputItem (true);
d->scene.addItem (d->mainText);
d->scene.addItem (d->scrollText);
d->mainText->setDocument (d->text);
d->mainText->setFiltersChildEvents (true);
d->mainText->setPos (0, 0);
d->scrollText->setDocument (d->text);
d->scrollText->setParentItem (d->mainText);
......@@ -115,10 +160,6 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
setPalette (pal);
setBackgroundRole (QPalette::Base);
//size policy
QSizePolicy qsp (QSizePolicy::Expanding, QSizePolicy::Expanding);
setSizePolicy (qsp);
//context menu
setContextMenuPolicy (Qt::ActionsContextMenu);
KActionCollection *acol = cActionManager::self()->getACol();
......@@ -188,9 +229,17 @@ void cConsole::setScrollTextVisible (bool vis)
d->scrollText->setVisible (vis);
}
void cConsole::sliderChanged (int val)
{
int maxval = verticalScrollBar()->maximum ();
bool vis = (val < maxval);
setScrollTextVisible (vis);
}
void cConsole::setScrollTextSize (int aconsize)
{
// TODO
d->scrollText->setPercentHeight (aconsize);
}
void cConsole::setIndentation (int val) {
......@@ -301,7 +350,8 @@ void cConsole::resizeEvent (QResizeEvent *)
void cConsole::fixupOutput ()
{
d->text->setTextWidth (d->scene.width());
d->mainText->updateSize();
d->scrollText->updateSize();
forceEmitSize ();
}
......
......@@ -107,6 +107,9 @@ signals:
void sendCommand (const QString &command);
void promptCommand (const QString &command);
protected slots:
void sliderChanged (int val);
protected:
void resizeEvent (QResizeEvent *e) override;
/** called when resizing and when changing font */
......
......@@ -28,15 +28,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ctextchunk.h"
#include <QScrollBar>
#include <QVBoxLayout>
#include <kapplication.h>
#include <KLocalizedString>
#include <krandom.h>
cOutput::cOutput (int sess, QWidget *parent) : QScrollArea (parent), cActionBase ("output", sess)
cOutput::cOutput (int sess, QWidget *parent) : QWidget(parent), cActionBase ("output", sess)
{
con = new cConsole (this);
setWidget (con);
QVBoxLayout *layout = new QVBoxLayout (this);
layout->addWidget (con);
con->setSession (sess);
echocolor = Qt::yellow;
......@@ -45,10 +48,6 @@ cOutput::cOutput (int sess, QWidget *parent) : QScrollArea (parent), cActionBase
setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
// enable vertical scrollbar, disable the other one
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
// connect cConsole to us ...
connect (con, SIGNAL (dimensionsChanged (int, int)), this,
SLOT (dimensionsChanged (int, int)));
......@@ -57,10 +56,6 @@ cOutput::cOutput (int sess, QWidget *parent) : QScrollArea (parent), cActionBase
connect (con, SIGNAL (promptCommand (const QString &)), this,
SLOT (promptCommand (const QString &)));
//and connect() slider so that aconsole is shown/hidden as needed
connect (verticalScrollBar (), SIGNAL (sliderMoved (int)), this, SLOT (sliderChanged (int)));
connect (verticalScrollBar (), SIGNAL (valueChanged (int)), this, SLOT (sliderChanged (int)));
// react on events
addEventHandler ("display-line", 20, PT_TEXTCHUNK);
addEventHandler ("display-prompt", 20, PT_TEXTCHUNK);
......@@ -100,7 +95,7 @@ void cOutput::eventNothingHandler (QString event, int /*session*/)
con->setRepaintCount (gs->getInt ("force-redraw"));
//changing font often causes view to move - move to the very bottom
verticalScrollBar()->setValue (verticalScrollBar()->maximum());
con->verticalScrollBar()->setValue (con->verticalScrollBar()->maximum());
con->tryUpdateHistorySize ();
}
......@@ -134,13 +129,6 @@ void cOutput::dimensionsChanged (int x, int y)
invokeEvent ("dimensions-changed", sess(), x, y);
}
void cOutput::sliderChanged (int val)
{
int maxval = verticalScrollBar()->maximum ();
bool vis = (val < maxval);
con->setScrollTextVisible (vis);
}
void cOutput::sendCommand (const QString &command)
{
// we send the command directly, with no parsing, because these commands
......
......@@ -38,7 +38,7 @@ It also handles scrollbars.
@author Tomas Mecir
*/
class KMUDDY_EXPORT cOutput : public QScrollArea, public cActionBase
class KMUDDY_EXPORT cOutput : public QWidget, public cActionBase
{
Q_OBJECT
public:
......@@ -80,7 +80,6 @@ protected slots:
void dimensionsChanged (int x, int y);
void sendCommand (const QString &command);
void promptCommand (const QString &command);
void sliderChanged (int);
protected:
virtual void eventStringHandler (QString event, int, QString &par1, const QString &) override;
virtual void eventChunkHandler (QString event, int, cTextChunk *chunk) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment