Provides a window onto a section of a terminal screen. More...
#include "ScreenWindow.h"
Public Types | |
enum | RelativeScrollMode { ScrollLines , ScrollPages } |
Public Slots | |
void | notifyOutputChanged () |
Notifies the window that the contents of the associated terminal screen have changed. More... | |
Signals | |
void | outputChanged () |
Emitted when the contents of the associated terminal screen ( see screen() ) changes. More... | |
void | scrolled (int line) |
Emitted when the screen window is scrolled to a different position. More... | |
void | selectionChanged () |
Emitted when the selection is changed. More... | |
Public Member Functions | |
ScreenWindow (QObject *parent=nullptr) | |
Constructs a new screen window with the given parent. More... | |
virtual | ~ScreenWindow () |
bool | atEndOfOutput () const |
Convenience method. More... | |
void | clearSelection () |
Clears the current selection. More... | |
int | columnCount () const |
Returns the total number of columns in the screen. More... | |
int | currentLine () const |
Returns the index of the line which is currently at the top of this window. More... | |
QPoint | cursorPosition () const |
Returns the position of the cursor within the window. More... | |
Character * | getImage () |
Returns the image of characters which are currently visible through this window onto the screen. More... | |
QVector< LineProperty > | getLineProperties () |
Returns the line attributes associated with the lines of characters which are currently visible through this window. More... | |
void | getSelectionEnd (int &column, int &line) |
Retrieves the end of the selection within the window. More... | |
void | getSelectionStart (int &column, int &line) |
Retrieves the start of the selection within the window. More... | |
bool | isSelected (int column, int line) |
Returns true if the character at line , column is part of the selection. More... | |
int | lineCount () const |
Returns the total number of lines in the screen. More... | |
void | resetScrollCount () |
Resets the count of scrolled lines returned by scrollCount() More... | |
Screen * | screen () const |
Returns the screen which this window looks onto. More... | |
void | scrollBy (RelativeScrollMode mode, int amount) |
Scrolls the window relative to its current position on the screen. More... | |
int | scrollCount () const |
Returns the number of lines which the region of the window specified by scrollRegion() has been scrolled by since the last call to resetScrollCount(). More... | |
QRect | scrollRegion () const |
Returns the area of the window which was last scrolled, this is usually the whole window area. More... | |
void | scrollTo (int line) |
Scrolls the window so that line is at the top of the window. More... | |
QString | selectedText (bool preserveLineBreaks) const |
Returns the text which is currently selected. More... | |
void | setScreen (Screen *screen) |
Sets the screen which this window looks onto. More... | |
void | setSelectionEnd (int column, int line) |
Sets the end of the selection to the given line and column within the window. More... | |
void | setSelectionStart (int column, int line, bool columnMode) |
Sets the start of the selection to the given line and column within the window. More... | |
void | setTrackOutput (bool trackOutput) |
Specifies whether the window should automatically move to the bottom of the screen when new output is added. More... | |
void | setWindowLines (int lines) |
Sets the number of lines in the window. More... | |
bool | trackOutput () const |
Returns whether the window automatically moves to the bottom of the screen as new output is added. More... | |
int | windowColumns () const |
Returns the number of columns in the window. More... | |
int | windowLines () const |
Returns the number of lines in the window. More... | |
Private Member Functions | |
int | endWindowLine () const |
void | fillUnusedArea () |
Private Attributes | |
bool | _bufferNeedsUpdate |
int | _currentLine |
Screen * | _screen |
int | _scrollCount |
bool | _trackOutput |
Character * | _windowBuffer |
int | _windowBufferSize |
int | _windowLines |
Provides a window onto a section of a terminal screen.
This window can then be rendered by a terminal display widget ( TerminalDisplay ).
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.
Definition at line 51 of file ScreenWindow.h.
Enumerator | |
---|---|
ScrollLines | |
ScrollPages |
Definition at line 172 of file ScreenWindow.h.
ScreenWindow::ScreenWindow | ( | QObject * | parent = nullptr | ) |
Constructs a new screen window with the given parent.
A screen must be specified by calling setScreen() before calling getImage() or getLineProperties().
You should not call this constructor directly, instead use the Emulation::createWindow() method to create a window on the emulation which you wish to view. This allows the emulation to notify the window when the associated screen has changed and synchronize selection updates between all views on a session.
Definition at line 31 of file ScreenWindow.cpp.
|
virtual |
Definition at line 43 of file ScreenWindow.cpp.
References _windowBuffer.
bool ScreenWindow::atEndOfOutput | ( | ) | const |
Convenience method.
Returns true if the window is currently at the bottom of the screen.
Definition at line 214 of file ScreenWindow.cpp.
References currentLine(), lineCount(), and windowLines().
Referenced by scrollRegion().
void ScreenWindow::clearSelection | ( | ) |
Clears the current selection.
Definition at line 155 of file ScreenWindow.cpp.
References _screen, Screen::clearSelection(), and selectionChanged().
int ScreenWindow::columnCount | ( | ) | const |
Returns the total number of columns in the screen.
Definition at line 182 of file ScreenWindow.cpp.
References _screen, and Screen::getColumns().
int ScreenWindow::currentLine | ( | ) | const |
Returns the index of the line which is currently at the top of this window.
Definition at line 197 of file ScreenWindow.cpp.
References _currentLine, lineCount(), and windowLines().
Referenced by atEndOfOutput(), endWindowLine(), fillUnusedArea(), getImage(), getLineProperties(), getSelectionEnd(), getSelectionStart(), isSelected(), scrollBy(), setSelectionEnd(), and setSelectionStart().
QPoint ScreenWindow::cursorPosition | ( | ) | const |
Returns the position of the cursor within the window.
Definition at line 187 of file ScreenWindow.cpp.
References _screen, Screen::getCursorX(), and Screen::getCursorY().
|
private |
Definition at line 104 of file ScreenWindow.cpp.
References currentLine(), lineCount(), and windowLines().
Referenced by getImage(), getLineProperties(), isSelected(), setSelectionEnd(), and setSelectionStart().
|
private |
Definition at line 86 of file ScreenWindow.cpp.
References _screen, _windowBuffer, _windowBufferSize, currentLine(), Screen::fillWithDefaultChar(), Screen::getHistLines(), Screen::getLines(), windowColumns(), and windowLines().
Referenced by getImage().
Character * ScreenWindow::getImage | ( | ) |
Returns the image of characters which are currently visible through this window onto the screen.
The buffer is managed by the ScreenWindow instance and does not need to be deleted by the caller.
Definition at line 59 of file ScreenWindow.cpp.
References _bufferNeedsUpdate, _screen, _windowBuffer, _windowBufferSize, currentLine(), endWindowLine(), fillUnusedArea(), Screen::getImage(), windowColumns(), and windowLines().
QVector< LineProperty > ScreenWindow::getLineProperties | ( | ) |
Returns the line attributes associated with the lines of characters which are currently visible through this window.
Definition at line 109 of file ScreenWindow.cpp.
References _screen, currentLine(), endWindowLine(), Screen::getLineProperties(), and windowLines().
void ScreenWindow::getSelectionEnd | ( | int & | column, |
int & | line | ||
) |
Retrieves the end of the selection within the window.
Definition at line 129 of file ScreenWindow.cpp.
References _screen, currentLine(), and Screen::getSelectionEnd().
void ScreenWindow::getSelectionStart | ( | int & | column, |
int & | line | ||
) |
Retrieves the start of the selection within the window.
Definition at line 124 of file ScreenWindow.cpp.
References _screen, currentLine(), and Screen::getSelectionStart().
bool ScreenWindow::isSelected | ( | int | column, |
int | line | ||
) |
Returns true if the character at line
, column
is part of the selection.
Definition at line 150 of file ScreenWindow.cpp.
References _screen, currentLine(), endWindowLine(), and Screen::isSelected().
int ScreenWindow::lineCount | ( | ) | const |
Returns the total number of lines in the screen.
Definition at line 177 of file ScreenWindow.cpp.
References _screen, Screen::getHistLines(), and Screen::getLines().
Referenced by atEndOfOutput(), currentLine(), endWindowLine(), and scrollTo().
|
slot |
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.
Definition at line 266 of file ScreenWindow.cpp.
References _bufferNeedsUpdate, _currentLine, _screen, _scrollCount, _trackOutput, Screen::droppedLines(), Screen::getHistLines(), Screen::getLines(), outputChanged(), Screen::scrolledLines(), and windowLines().
|
signal |
Emitted when the contents of the associated terminal screen ( see screen() ) changes.
Referenced by notifyOutputChanged().
void ScreenWindow::resetScrollCount | ( | ) |
Resets the count of scrolled lines returned by scrollCount()
Definition at line 251 of file ScreenWindow.cpp.
References _scrollCount.
Screen * ScreenWindow::screen | ( | ) | const |
Returns the screen which this window looks onto.
Definition at line 54 of file ScreenWindow.cpp.
References _screen.
Referenced by setScreen().
void ScreenWindow::scrollBy | ( | RelativeScrollMode | mode, |
int | amount | ||
) |
Scrolls the window relative to its current position on the screen.
mode | Specifies whether amount refers to the number of lines or the number of pages to scroll. |
amount | The number of lines or pages ( depending on mode ) to scroll by. If this number is positive, the view is scrolled down. If this number is negative, the view is scrolled up. |
Definition at line 202 of file ScreenWindow.cpp.
References currentLine(), ScrollLines, ScrollPages, scrollTo(), and windowLines().
int ScreenWindow::scrollCount | ( | ) | const |
Returns the number of lines which the region of the window specified by scrollRegion() has been scrolled by since the last call to resetScrollCount().
scrollRegion() is in most cases the whole window, but will be a smaller area in, for example, applications which provide split-screen facilities.
This is not guaranteed to be accurate, but allows views to optimise rendering by reducing the amount of costly text rendering that needs to be done when the output is scrolled.
Definition at line 246 of file ScreenWindow.cpp.
References _scrollCount.
|
signal |
Emitted when the screen window is scrolled to a different position.
line | The line which is now at the top of the window. |
Referenced by scrollTo().
QRect ScreenWindow::scrollRegion | ( | ) | const |
Returns the area of the window which was last scrolled, this is usually the whole window area.
Like scrollCount(), this is not guaranteed to be accurate, but allows views to optimise rendering.
Definition at line 256 of file ScreenWindow.cpp.
References _screen, atEndOfOutput(), Screen::getLines(), Screen::lastScrolledRegion(), windowColumns(), and windowLines().
void ScreenWindow::scrollTo | ( | int | line | ) |
Scrolls the window so that line
is at the top of the window.
Definition at line 219 of file ScreenWindow.cpp.
References _bufferNeedsUpdate, _currentLine, _scrollCount, lineCount(), scrolled(), and windowLines().
Referenced by scrollBy().
QString ScreenWindow::selectedText | ( | bool | preserveLineBreaks | ) | const |
Returns the text which is currently selected.
preserveLineBreaks | See Screen::selectedText() |
Definition at line 119 of file ScreenWindow.cpp.
References _screen, and Screen::selectedText().
|
signal |
Emitted when the selection is changed.
Referenced by clearSelection(), setSelectionEnd(), and setSelectionStart().
void ScreenWindow::setScreen | ( | Screen * | screen | ) |
Sets the screen which this window looks onto.
Definition at line 47 of file ScreenWindow.cpp.
References _screen, and screen().
Referenced by Emulation::createWindow().
void ScreenWindow::setSelectionEnd | ( | int | column, |
int | line | ||
) |
Sets the end of the selection to the given line
and column
within the window.
Definition at line 142 of file ScreenWindow.cpp.
References _bufferNeedsUpdate, _screen, currentLine(), endWindowLine(), selectionChanged(), and Screen::setSelectionEnd().
void ScreenWindow::setSelectionStart | ( | int | column, |
int | line, | ||
bool | columnMode | ||
) |
Sets the start of the selection to the given line
and column
within the window.
Definition at line 134 of file ScreenWindow.cpp.
References _bufferNeedsUpdate, _screen, currentLine(), endWindowLine(), selectionChanged(), and Screen::setSelectionStart().
void ScreenWindow::setTrackOutput | ( | bool | trackOutput | ) |
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.
Definition at line 236 of file ScreenWindow.cpp.
References _trackOutput, and trackOutput().
void ScreenWindow::setWindowLines | ( | int | lines | ) |
Sets the number of lines in the window.
Definition at line 162 of file ScreenWindow.cpp.
References _windowLines.
Referenced by TerminalView::setScreenWindow().
bool ScreenWindow::trackOutput | ( | ) | const |
Returns whether the window automatically moves to the bottom of the screen as new output is added.
See setTrackOutput()
Definition at line 241 of file ScreenWindow.cpp.
References _trackOutput.
Referenced by setTrackOutput().
int ScreenWindow::windowColumns | ( | ) | const |
Returns the number of columns in the window.
Definition at line 172 of file ScreenWindow.cpp.
References _screen, and Screen::getColumns().
Referenced by fillUnusedArea(), getImage(), and scrollRegion().
int ScreenWindow::windowLines | ( | ) | const |
Returns the number of lines in the window.
Definition at line 167 of file ScreenWindow.cpp.
References _windowLines.
Referenced by atEndOfOutput(), currentLine(), endWindowLine(), fillUnusedArea(), getImage(), getLineProperties(), notifyOutputChanged(), scrollBy(), scrollRegion(), and scrollTo().
|
private |
Definition at line 243 of file ScreenWindow.h.
Referenced by getImage(), notifyOutputChanged(), scrollTo(), setSelectionEnd(), and setSelectionStart().
|
private |
Definition at line 246 of file ScreenWindow.h.
Referenced by currentLine(), notifyOutputChanged(), and scrollTo().
|
private |
Definition at line 240 of file ScreenWindow.h.
Referenced by clearSelection(), columnCount(), cursorPosition(), fillUnusedArea(), getImage(), getLineProperties(), getSelectionEnd(), getSelectionStart(), isSelected(), lineCount(), notifyOutputChanged(), screen(), scrollRegion(), selectedText(), setScreen(), setSelectionEnd(), setSelectionStart(), and windowColumns().
|
private |
Definition at line 248 of file ScreenWindow.h.
Referenced by notifyOutputChanged(), resetScrollCount(), scrollCount(), and scrollTo().
|
private |
Definition at line 247 of file ScreenWindow.h.
Referenced by notifyOutputChanged(), setTrackOutput(), and trackOutput().
|
private |
Definition at line 241 of file ScreenWindow.h.
Referenced by ~ScreenWindow(), fillUnusedArea(), and getImage().
|
private |
Definition at line 242 of file ScreenWindow.h.
Referenced by fillUnusedArea(), and getImage().
|
private |
Definition at line 245 of file ScreenWindow.h.
Referenced by setWindowLines(), and windowLines().