GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ScreenWindow.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2007, 2013 by Robert Knight <robertknight@gmail.com>
3
4 Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
5
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.
10
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.
15
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
19 02110-1301 USA.
20*/
21
22// Own
23#include "unix/ScreenWindow.h"
24
25// Qt
26#include <QtCore>
27
28// Konsole
29#include "unix/Screen.h"
30
32 : QObject(parent)
33 , _windowBuffer(nullptr)
34 , _windowBufferSize(0)
35 , _bufferNeedsUpdate(true)
36 , _windowLines(1)
37 , _currentLine(0)
38 , _trackOutput(true)
39 , _scrollCount(0)
40{
41}
42
44{
45 delete[] _windowBuffer;
46}
48{
49 Q_ASSERT( screen );
50
52}
53
55{
56 return _screen;
57}
58
60{
61 // reallocate internal buffer if the window size has changed
62 int size = windowLines() * windowColumns();
63 if (_windowBuffer == nullptr || _windowBufferSize != size)
64 {
65 delete[] _windowBuffer;
66 _windowBufferSize = size;
67 _windowBuffer = new Character[size];
68 _bufferNeedsUpdate = true;
69 }
70
72 return _windowBuffer;
73
76
77 // this window may look beyond the end of the screen, in which
78 // case there will be an unused area which needs to be filled
79 // with blank characters
81
82 _bufferNeedsUpdate = false;
83 return _windowBuffer;
84}
85
87{
88 int screenEndLine = _screen->getHistLines() + _screen->getLines() - 1;
89 int windowEndLine = currentLine() + windowLines() - 1;
90
91 int unusedLines = windowEndLine - screenEndLine;
92 int charsToFill = unusedLines * windowColumns();
93
95}
96
97// return the index of the line at the end of this window, or if this window
98// goes beyond the end of the screen, the index of the line at the end
99// of the screen.
100//
101// when passing a line number to a Screen method, the line number should
102// never be more than endWindowLine()
103//
105{
106 return qMin(currentLine() + windowLines() - 1,
107 lineCount() - 1);
108}
109QVector<LineProperty> ScreenWindow::getLineProperties()
110{
111 QVector<LineProperty> result = _screen->getLineProperties(currentLine(),endWindowLine());
112
113 if (result.count() != windowLines())
114 result.resize(windowLines());
115
116 return result;
117}
118
119QString ScreenWindow::selectedText( bool preserveLineBreaks ) const
120{
121 return _screen->selectedText( preserveLineBreaks );
122}
123
124void ScreenWindow::getSelectionStart( int& column , int& line )
125{
126 _screen->getSelectionStart(column,line);
127 line -= currentLine();
128}
129void ScreenWindow::getSelectionEnd( int& column , int& line )
130{
131 _screen->getSelectionEnd(column,line);
132 line -= currentLine();
133}
134void ScreenWindow::setSelectionStart( int column , int line , bool columnMode )
135{
136 _screen->setSelectionStart( column , qMin(line + currentLine(),endWindowLine()) , columnMode);
137
138 _bufferNeedsUpdate = true;
139 emit selectionChanged();
140}
141
142void ScreenWindow::setSelectionEnd( int column , int line )
143{
144 _screen->setSelectionEnd( column , qMin(line + currentLine(),endWindowLine()) );
145
146 _bufferNeedsUpdate = true;
147 emit selectionChanged();
148}
149
150bool ScreenWindow::isSelected( int column , int line )
151{
152 return _screen->isSelected( column , qMin(line + currentLine(),endWindowLine()) );
153}
154
156{
158
159 emit selectionChanged();
160}
161
163{
164 Q_ASSERT(lines > 0);
165 _windowLines = lines;
166}
168{
169 return _windowLines;
170}
171
173{
174 return _screen->getColumns();
175}
176
178{
179 return _screen->getHistLines() + _screen->getLines();
180}
181
183{
184 return _screen->getColumns();
185}
186
188{
189 QPoint position;
190
191 position.setX( _screen->getCursorX() );
192 position.setY( _screen->getCursorY() );
193
194 return position;
195}
196
198{
199 return qBound(0,_currentLine,lineCount()-windowLines());
200}
201
203{
204 if ( mode == ScrollLines )
205 {
206 scrollTo( currentLine() + amount );
207 }
208 else if ( mode == ScrollPages )
209 {
210 scrollTo( currentLine() + amount * ( windowLines() / 2 ) );
211 }
212}
213
215{
216 return currentLine() == (lineCount()-windowLines());
217}
218
220{
221 int maxCurrentLineNumber = lineCount() - windowLines();
222 line = qBound(0,line,maxCurrentLineNumber);
223
224 const int delta = line - _currentLine;
225 _currentLine = line;
226
227 // keep track of number of lines scrolled by,
228 // this can be reset by calling resetScrollCount()
229 _scrollCount += delta;
230
231 _bufferNeedsUpdate = true;
232
234}
235
236void ScreenWindow::setTrackOutput(bool trackOutput)
237{
239}
240
242{
243 return _trackOutput;
244}
245
247{
248 return _scrollCount;
249}
250
252{
253 _scrollCount = 0;
254}
255
257{
258 bool equalToScreenSize = windowLines() == _screen->getLines();
259
260 if ( atEndOfOutput() && equalToScreenSize )
261 return _screen->lastScrolledRegion();
262 else
263 return QRect(0,0,windowColumns(),windowLines());
264}
265
267{
268 // move window to the bottom of the screen and update scroll count
269 // if this window is currently tracking the bottom of the screen
270 if ( _trackOutput )
271 {
274 }
275 else
276 {
277 // if the history is not unlimited then it may
278 // have run out of space and dropped the oldest
279 // lines of output - in this case the screen
280 // window's current line number will need to
281 // be adjusted - otherwise the output will scroll
282 _currentLine = qMax(0,_currentLine -
284
285 // ensure that the screen window's current position does
286 // not go beyond the bottom of the screen
288 }
289
290 _bufferNeedsUpdate = true;
291
292 emit outputChanged();
293}
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:56
void fillUnusedArea()
Character * getImage()
Returns the image of characters which are currently visible through this window onto the screen.
void setSelectionStart(int column, int line, bool columnMode)
Sets the start of the selection to the given line and column within the window.
void setSelectionEnd(int column, int line)
Sets the end of the selection to the given line and column within the window.
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection within the window.
void setTrackOutput(bool trackOutput)
Specifies whether the window should automatically move to the bottom of the screen when new output is...
QRect scrollRegion() const
Returns the area of the window which was last scrolled, this is usually the whole window area.
int windowLines() const
Returns the number of lines in the window.
void scrolled(int line)
Emitted when the screen window is scrolled to a different position.
int currentLine() const
Returns the index of the line which is currently at the top of this window.
bool atEndOfOutput() const
Convenience method.
bool _bufferNeedsUpdate
Definition: ScreenWindow.h:243
bool isSelected(int column, int line)
Returns true if the character at line , column is part of the selection.
int lineCount() const
Returns the total number of lines in the screen.
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection within the window.
int columnCount() const
Returns the total number of columns in the screen.
void clearSelection()
Clears the current selection.
QString selectedText(bool preserveLineBreaks) const
Returns the text which is currently selected.
int endWindowLine() const
Character * _windowBuffer
Definition: ScreenWindow.h:241
int windowColumns() const
Returns the number of columns in the window.
Screen * _screen
Definition: ScreenWindow.h:240
int _windowBufferSize
Definition: ScreenWindow.h:242
bool trackOutput() const
Returns whether the window automatically moves to the bottom of the screen as new output is added.
ScreenWindow(QObject *parent=nullptr)
Constructs a new screen window with the given parent.
void setScreen(Screen *screen)
Sets the screen which this window looks onto.
void notifyOutputChanged()
Notifies the window that the contents of the associated terminal screen have changed.
QPoint cursorPosition() const
Returns the position of the cursor within the window.
void selectionChanged()
Emitted when the selection is changed.
void scrollBy(RelativeScrollMode mode, int amount)
Scrolls the window relative to its current position on the screen.
int scrollCount() const
Returns the number of lines which the region of the window specified by scrollRegion() has been scrol...
void scrollTo(int line)
Scrolls the window so that line is at the top of the window.
void resetScrollCount()
Resets the count of scrolled lines returned by scrollCount()
Screen * screen() const
Returns the screen which this window looks onto.
void outputChanged()
Emitted when the contents of the associated terminal screen ( see screen() ) changes.
QVector< LineProperty > getLineProperties()
Returns the line attributes associated with the lines of characters which are currently visible throu...
virtual ~ScreenWindow()
void setWindowLines(int lines)
Sets the number of lines in the window.
An image of characters with associated attributes.
Definition: Screen.h:76
int getCursorY() const
Returns the line which the cursor is positioned on.
Definition: Screen.cpp:945
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
Definition: Screen.cpp:564
int getColumns()
Return the number of columns.
Definition: Screen.h:379
QString selectedText(bool preserveLineBreaks)
Convenience method.
Definition: Screen.cpp:1281
int getHistLines()
Return the number of lines in the history buffer.
Definition: Screen.cpp:1522
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
Definition: Screen.cpp:1562
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
Definition: Screen.cpp:1240
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1201
int getCursorX() const
Returns the column which the cursor is positioned at.
Definition: Screen.cpp:940
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1214
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
Definition: Screen.cpp:867
int scrolledLines() const
Returns the number of lines that the image has been scrolled up or down by, since the last call to re...
Definition: Screen.cpp:834
void clearSelection()
Clears the current selection.
Definition: Screen.cpp:1194
bool isSelected(const int column, const int line) const
Returns true if the character at (column, line) is part of the current selection.
Definition: Screen.cpp:1261
void setSelectionStart(const int column, const int line, const bool columnmode)
Sets the start of the selection.
Definition: Screen.cpp:1227
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
Definition: Screen.cpp:602
int droppedLines() const
Returns the number of lines of output which have been dropped from the history since the last call to...
Definition: Screen.cpp:838
int getLines()
Return the number of lines.
Definition: Screen.h:377