Commit b94c0601 authored by Robert Knight's avatar Robert Knight
Browse files

More work on the screen window concept. Scroll view when new output is added...

More work on the screen window concept.  Scroll view when new output is added unless an older part of the history is being viewed by dragging the scrollbar.  Add API documentation.  Fix mistakes in field renaming from previous commit.

svn path=/branches/work/konsole-split-view/; revision=640768
parent d746c96c
......@@ -24,15 +24,16 @@
#include "TEScreen.h"
#include "ScreenWindow.h"
ScreenWindow::ScreenWindow()
: _currentLine(0)
ScreenWindow::ScreenWindow(QObject* parent)
: QObject(parent)
, _currentLine(0)
, _trackOutput(true)
{
}
void ScreenWindow::setScreen(TEScreen* screen)
{
Q_ASSERT( _screen );
Q_ASSERT( screen );
_screen = screen;
}
......@@ -136,3 +137,14 @@ void ScreenWindow::resetScrollCount()
_scrollCount = 0;
}
void ScreenWindow::notifyOutputChanged()
{
if ( _trackOutput )
{
scrollTo( _screen->getHistLines() );
}
emit outputChanged();
}
#include "ScreenWindow.moc"
......@@ -29,11 +29,28 @@ class TEScreen;
* Provides a window onto a section of a terminal screen.
* This window can then be rendered by a terminal display widget ( TEWidget ).
*
* To use the screen window, create a new ScreenWindow() instance and associated it with
* a terminal screen using setScreen().
* Use the scrollTo() method to scroll the window up and down on the screen.
* Call the getImage() method to retrieve the character image which is currently visible in the window.
*
* setTrackOutput() controls whether the window moves to the bottom of the associated screen when new
* lines are added to it.
*
* Whenever the output from the underlying screen is changed, the notifyOutputChanged() slot should
* be called. This in turn will update the window's position and emit the outputChanged() signal
* if necessary.
*/
class ScreenWindow //: public QObject
class ScreenWindow : public QObject
{
Q_OBJECT
public:
ScreenWindow();
/**
* Constructs a new screen window with the given parent.
* A screen must be specified by calling setScreen() before calling getImage() or getLineProperties()
*/
ScreenWindow(QObject* parent = 0);
/** Sets the screen which this window looks onto */
void setScreen(TEScreen* screen);
......@@ -48,6 +65,11 @@ public:
* copies the characters from the appropriate part of the screen into the buffer.
* It is the caller's responsibility to free the buffer when they have finished using
* it.
*
* TODO: Fix this and use new[] / delete[] to allocate/free this buffer.
*
* The buffer is allocated using malloc() and must therefore be freed using the free()
* call as opposed to delete[]
*/
Character* getImage();
/**
......@@ -106,11 +128,14 @@ public:
/**
* Specifies whether the window should automatically move to the bottom
* of the screen when new output is added.
*
* If this is set to true, the window will be moved to the bottom of the associated screen ( see
* screen() ) when the notifyOutputChanged() method is called.
*/
void setTrackOutput(bool trackOutput);
/**
* Returns whether the window automatically moves to the bottom of the screen as
* new output is added
* new output is added. See setTrackOutput()
*/
bool trackOutput() const;
......@@ -121,11 +146,19 @@ public:
*/
QString selectedText( bool preserveLineBreaks ) const;
//signals:
public slots:
/**
* Notifies the window that the contents of the associated terminal screen have changed.
* This moves the window to the bottom of the screen if trackOutput() is true and causes
* the outputChanged() signal to be emitted.
*/
void notifyOutputChanged();
signals:
/**
* Emitted when the number of lines or columns in the associated screen changes
* Emitted when the contents of the associated terminal screen ( see screen() ) changes.
*/
// void screenSizeChanged();
void outputChanged();
private:
TEScreen* _screen; // see setScreen() , screen()
......
......@@ -138,7 +138,17 @@ ScreenWindow* TEWidget::screenWindow() const
}
void TEWidget::setScreenWindow(ScreenWindow* window)
{
// disconnect existing screen window if any
if ( _screenWindow )
{
disconnect( _screenWindow , 0 , this , 0 );
}
_screenWindow = window;
#warning "The order here is not specified - does it matter whether updateImage or updateLineProperties comes first?"
connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateImage()) );
connect( _screenWindow , SIGNAL(outputChanged()) , this , SLOT(updateLineProperties()) );
}
void TEWidget::setDefaultBackColor(const QColor& color)
......@@ -1536,6 +1546,11 @@ void TEWidget::hideEvent(QHideEvent*)
void TEWidget::scrollChanged(int)
{
_screenWindow->scrollTo( scrollbar->value() );
const bool atEndOfOutput = (scrollbar->value() == scrollbar->maximum());
_screenWindow->setTrackOutput( atEndOfOutput );
updateImage();
//emit changedHistoryCursor(scrollbar->value()); //expose
}
......
......@@ -131,6 +131,9 @@ ScreenWindow* TEmulation::createWindow()
ScreenWindow* window = new ScreenWindow();
window->setScreen(currentScreen);
_windows << window;
connect(this , SIGNAL(updateViews()),
window , SLOT(notifyOutputChanged()) );
return window;
}
......@@ -140,10 +143,10 @@ ScreenWindow* TEmulation::createWindow()
void TEmulation::connectView(TEWidget* view)
{
#warning "Temporary - ideally the emulation should not be responsible for connecting its updateViews notification to the views themselves."
QObject::connect(this,SIGNAL(updateViews()),
view,SLOT(updateImage()));
QObject::connect(this,SIGNAL(updateViews()),
view,SLOT(updateLineProperties()));
//QObject::connect(this,SIGNAL(updateViews()),
// view,SLOT(updateImage()));
//QObject::connect(this,SIGNAL(updateViews()),
// view,SLOT(updateLineProperties()));
QObject::connect(view,SIGNAL(keyPressedSignal(QKeyEvent*)),
this,SLOT(onKeyPress(QKeyEvent*)));
......
......@@ -78,7 +78,11 @@ public:
*/
virtual void removeView(TEWidget* widget);
//TODO Document me
/**
* Creates a new window onto the output from this emulation. The contents
* of the window are then rendered by views which are set to use this window using the
* TEWidget::setScreenWindow() method.
*/
ScreenWindow* createWindow();
public:
......
......@@ -36,7 +36,7 @@ static Q_UINT32 charVal(QChar val)
static Q_UINT32 readGlyphLine(QTextStream& input)
{
QString line = input.renditioneadLine();
QString line = input.readLine();
while (line.length() < 5)
line += ' ';
......@@ -78,7 +78,7 @@ int main(int argc, char **argv)
while (!input.atEnd())
{
QString line = input.renditioneadLine();
QString line = input.readLine();
line = line.trimmed();
if (line.isEmpty())
continue; //Skip empty lines
......
......@@ -96,7 +96,7 @@ void KWrited::block_in(int fd)
if (len <= 0)
return;
insertPlainText( QString::fromLocal8Bit( buf, len ).renditionemove('\r') );
insertPlainText( QString::fromLocal8Bit( buf, len ).remove('\r') );
show();
raise();
}
......
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