2
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
4
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
#ifndef SCREENWINDOW_H
23
#define SCREENWINDOW_H
26
#include <QtCore/QObject>
27
#include <QtCore/QPoint>
28
#include <QtCore/QRect>
31
#include "Character.h"
39
* Provides a window onto a section of a terminal screen.
40
* This window can then be rendered by a terminal display widget ( TerminalDisplay ).
42
* To use the screen window, create a new ScreenWindow() instance and associated it with
43
* a terminal screen using setScreen().
44
* Use the scrollTo() method to scroll the window up and down on the screen.
45
* Call the getImage() method to retrieve the character image which is currently visible in the window.
47
* setTrackOutput() controls whether the window moves to the bottom of the associated screen when new
48
* lines are added to it.
50
* Whenever the output from the underlying screen is changed, the notifyOutputChanged() slot should
51
* be called. This in turn will update the window's position and emit the outputChanged() signal
54
class ScreenWindow : public QObject
60
* Constructs a new screen window with the given parent.
61
* A screen must be specified by calling setScreen() before calling getImage() or getLineProperties().
63
* You should not call this constructor directly, instead use the Emulation::createWindow() method
64
* to create a window on the emulation which you wish to view. This allows the emulation
65
* to notify the window when the associated screen has changed and synchronize selection updates
66
* between all views on a session.
68
ScreenWindow( QObject* parent = 0 );
69
virtual ~ScreenWindow();
71
/** Sets the screen which this window looks onto */
72
void setScreen( Screen* screen );
73
/** Returns the screen which this window looks onto */
74
Screen* screen() const;
77
* Returns the image of characters which are currently visible through this window
80
* The buffer is managed by the ScreenWindow instance and does not need to be
81
* deleted by the caller.
83
Character* getImage();
86
* Returns the line attributes associated with the lines of characters which
87
* are currently visible through this window
89
QVector<LineProperty> getLineProperties();
92
* Returns the number of lines which the region of the window
93
* specified by scrollRegion() has been scrolled by since the last call
94
* to resetScrollCount(). scrollRegion() is in most cases the
95
* whole window, but will be a smaller area in, for example, applications
96
* which provide split-screen facilities.
98
* This is not guaranteed to be accurate, but allows views to optimise
99
* rendering by reducing the amount of costly text rendering that
100
* needs to be done when the output is scrolled.
102
int scrollCount() const;
105
* Resets the count of scrolled lines returned by scrollCount()
107
void resetScrollCount();
110
* Returns the area of the window which was last scrolled, this is
111
* usually the whole window area.
113
* Like scrollCount(), this is not guaranteed to be accurate,
114
* but allows views to optimise rendering.
116
QRect scrollRegion() const;
119
* Sets the start of the selection to the given @p line and @p column within
122
void setSelectionStart( int column , int line , bool columnMode );
124
* Sets the end of the selection to the given @p line and @p column within
127
void setSelectionEnd( int column , int line );
129
* Retrieves the start of the selection within the window.
131
void getSelectionStart( int& column , int& line );
133
* Retrieves the end of the selection within the window.
135
void getSelectionEnd( int& column , int& line );
137
* Returns true if the character at @p line , @p column is part of the selection.
139
bool isSelected( int column , int line );
141
* Clears the current selection
143
void clearSelection();
145
/** Sets the number of lines in the window */
146
void setWindowLines( int lines );
147
/** Returns the number of lines in the window */
148
int windowLines() const;
149
/** Returns the number of columns in the window */
150
int windowColumns() const;
152
/** Returns the total number of lines in the screen */
153
int lineCount() const;
154
/** Returns the total number of columns in the screen */
155
int columnCount() const;
157
/** Returns the index of the line which is currently at the top of this window */
158
int currentLine() const;
161
* Returns the position of the cursor
164
QPoint cursorPosition() const;
167
* Convenience method. Returns true if the window is currently at the bottom
170
bool atEndOfOutput() const;
172
/** Scrolls the window so that @p line is at the top of the window */
173
void scrollTo( int line );
175
enum RelativeScrollMode
182
* Scrolls the window relative to its current position on the screen.
184
* @param mode Specifies whether @p amount refers to the number of lines or the number
185
* of pages to scroll.
186
* @param amount The number of lines or pages ( depending on @p mode ) to scroll by. If
187
* this number is positive, the view is scrolled down. If this number is negative, the view
190
void scrollBy( RelativeScrollMode mode , int amount );
193
* Specifies whether the window should automatically move to the bottom
194
* of the screen when new output is added.
196
* If this is set to true, the window will be moved to the bottom of the associated screen ( see
197
* screen() ) when the notifyOutputChanged() method is called.
199
void setTrackOutput( bool trackOutput );
201
* Returns whether the window automatically moves to the bottom of the screen as
202
* new output is added. See setTrackOutput()
204
bool trackOutput() const;
207
* Returns the text which is currently selected.
209
* @param preserveLineBreaks See Screen::selectedText()
211
QString selectedText( bool preserveLineBreaks ) const;
215
* Notifies the window that the contents of the associated terminal screen have changed.
216
* This moves the window to the bottom of the screen if trackOutput() is true and causes
217
* the outputChanged() signal to be emitted.
219
void notifyOutputChanged();
223
* Emitted when the contents of the associated terminal screen ( see screen() ) changes.
225
void outputChanged();
228
* Emitted when the screen window is scrolled to a different position.
230
* @param line The line which is now at the top of the window.
232
void scrolled( int line );
235
* Emitted when the selection is changed.
237
void selectionChanged();
240
int endWindowLine() const;
241
void fillUnusedArea();
243
Screen* _screen; // see setScreen() , screen()
244
Character* _windowBuffer;
245
int _windowBufferSize;
246
bool _bufferNeedsUpdate;
249
int _currentLine; // see scrollTo() , currentLine()
250
bool _trackOutput; // see setTrackOutput() , trackOutput()
251
int _scrollCount; // count of lines which the window has been scrolled by since
252
// the last call to resetScrollCount()
256
#endif // SCREENWINDOW_H