• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • sources
  • kde-4.12
  • applications
  • konsole
  • src
ScreenWindow.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA.
18 */
19 
20 // Own
21 #include "ScreenWindow.h"
22 
23 // Konsole
24 #include "Screen.h"
25 
26 using namespace Konsole;
27 
28 ScreenWindow::ScreenWindow(QObject* parent)
29  : QObject(parent)
30  , _windowBuffer(0)
31  , _windowBufferSize(0)
32  , _bufferNeedsUpdate(true)
33  , _windowLines(1)
34  , _currentLine(0)
35  , _currentResultLine(-1)
36  , _trackOutput(true)
37  , _scrollCount(0)
38 {
39 }
40 
41 ScreenWindow::~ScreenWindow()
42 {
43  delete[] _windowBuffer;
44 }
45 void ScreenWindow::setScreen(Screen* screen)
46 {
47  Q_ASSERT(screen);
48 
49  _screen = screen;
50 }
51 
52 Screen* ScreenWindow::screen() const
53 {
54  return _screen;
55 }
56 
57 Character* ScreenWindow::getImage()
58 {
59  // reallocate internal buffer if the window size has changed
60  int size = windowLines() * windowColumns();
61  if (_windowBuffer == 0 || _windowBufferSize != size) {
62  delete[] _windowBuffer;
63  _windowBufferSize = size;
64  _windowBuffer = new Character[size];
65  _bufferNeedsUpdate = true;
66  }
67 
68  if (!_bufferNeedsUpdate)
69  return _windowBuffer;
70 
71  _screen->getImage(_windowBuffer, size,
72  currentLine(), endWindowLine());
73 
74  // this window may look beyond the end of the screen, in which
75  // case there will be an unused area which needs to be filled
76  // with blank characters
77  fillUnusedArea();
78 
79  _bufferNeedsUpdate = false;
80  return _windowBuffer;
81 }
82 
83 void ScreenWindow::fillUnusedArea()
84 {
85  int screenEndLine = _screen->getHistLines() + _screen->getLines() - 1;
86  int windowEndLine = currentLine() + windowLines() - 1;
87 
88  int unusedLines = windowEndLine - screenEndLine;
89 
90  // stop when unusedLines is negative; there is an issue w/ charsToFill
91  // being greater than an int can hold
92  if (unusedLines <= 0)
93  return;
94 
95  int charsToFill = unusedLines * windowColumns();
96 
97  Screen::fillWithDefaultChar(_windowBuffer + _windowBufferSize - charsToFill, charsToFill);
98 }
99 
100 // return the index of the line at the end of this window, or if this window
101 // goes beyond the end of the screen, the index of the line at the end
102 // of the screen.
103 //
104 // when passing a line number to a Screen method, the line number should
105 // never be more than endWindowLine()
106 //
107 int ScreenWindow::endWindowLine() const
108 {
109  return qMin(currentLine() + windowLines() - 1,
110  lineCount() - 1);
111 }
112 QVector<LineProperty> ScreenWindow::getLineProperties()
113 {
114  QVector<LineProperty> result = _screen->getLineProperties(currentLine(), endWindowLine());
115 
116  if (result.count() != windowLines())
117  result.resize(windowLines());
118 
119  return result;
120 }
121 
122 QString ScreenWindow::selectedText(bool preserveLineBreaks, bool trimTrailingSpaces) const
123 {
124  return _screen->selectedText(preserveLineBreaks, trimTrailingSpaces);
125 }
126 
127 void ScreenWindow::getSelectionStart(int& column , int& line)
128 {
129  _screen->getSelectionStart(column, line);
130  line -= currentLine();
131 }
132 void ScreenWindow::getSelectionEnd(int& column , int& line)
133 {
134  _screen->getSelectionEnd(column, line);
135  line -= currentLine();
136 }
137 void ScreenWindow::setSelectionStart(int column , int line , bool columnMode)
138 {
139  _screen->setSelectionStart(column , line + currentLine() , columnMode);
140 
141  _bufferNeedsUpdate = true;
142  emit selectionChanged();
143 }
144 
145 void ScreenWindow::setSelectionEnd(int column , int line)
146 {
147  _screen->setSelectionEnd(column , line + currentLine());
148 
149  _bufferNeedsUpdate = true;
150  emit selectionChanged();
151 }
152 
153 void ScreenWindow::setSelectionByLineRange(int start, int end)
154 {
155  clearSelection();
156 
157  _screen->setSelectionStart(0 , start , false);
158  _screen->setSelectionEnd(windowColumns() , end);
159 
160  _bufferNeedsUpdate = true;
161  emit selectionChanged();
162 }
163 
164 bool ScreenWindow::isSelected(int column , int line)
165 {
166  return _screen->isSelected(column , qMin(line + currentLine(), endWindowLine()));
167 }
168 
169 void ScreenWindow::clearSelection()
170 {
171  _screen->clearSelection();
172 
173  emit selectionChanged();
174 }
175 
176 void ScreenWindow::setWindowLines(int lines)
177 {
178  Q_ASSERT(lines > 0);
179  _windowLines = lines;
180 }
181 int ScreenWindow::windowLines() const
182 {
183  return _windowLines;
184 }
185 
186 int ScreenWindow::windowColumns() const
187 {
188  return _screen->getColumns();
189 }
190 
191 int ScreenWindow::lineCount() const
192 {
193  return _screen->getHistLines() + _screen->getLines();
194 }
195 
196 int ScreenWindow::columnCount() const
197 {
198  return _screen->getColumns();
199 }
200 
201 QPoint ScreenWindow::cursorPosition() const
202 {
203  QPoint position;
204 
205  position.setX(_screen->getCursorX());
206  position.setY(_screen->getCursorY());
207 
208  return position;
209 }
210 
211 int ScreenWindow::currentLine() const
212 {
213  return qBound(0, _currentLine, lineCount() - windowLines());
214 }
215 
216 int ScreenWindow::currentResultLine() const
217 {
218  return _currentResultLine;
219 }
220 
221 void ScreenWindow::setCurrentResultLine(int line)
222 {
223  if (_currentResultLine == line) {
224  return;
225  }
226 
227  _currentResultLine = line;
228  emit currentResultLineChanged();
229 }
230 
231 void ScreenWindow::scrollBy(RelativeScrollMode mode, int amount, bool fullPage)
232 {
233  if (mode == ScrollLines) {
234  scrollTo(currentLine() + amount);
235  } else if (mode == ScrollPages) {
236  if (fullPage)
237  scrollTo(currentLine() + amount * (windowLines()));
238  else
239  scrollTo(currentLine() + amount * (windowLines() / 2));
240  }
241 }
242 
243 bool ScreenWindow::atEndOfOutput() const
244 {
245  return currentLine() == (lineCount() - windowLines());
246 }
247 
248 void ScreenWindow::scrollTo(int line)
249 {
250  int maxCurrentLineNumber = lineCount() - windowLines();
251  line = qBound(0, line, maxCurrentLineNumber);
252 
253  const int delta = line - _currentLine;
254  _currentLine = line;
255 
256  // keep track of number of lines scrolled by,
257  // this can be reset by calling resetScrollCount()
258  _scrollCount += delta;
259 
260  _bufferNeedsUpdate = true;
261 
262  emit scrolled(_currentLine);
263 }
264 
265 void ScreenWindow::setTrackOutput(bool trackOutput)
266 {
267  _trackOutput = trackOutput;
268 }
269 
270 bool ScreenWindow::trackOutput() const
271 {
272  return _trackOutput;
273 }
274 
275 int ScreenWindow::scrollCount() const
276 {
277  return _scrollCount;
278 }
279 
280 void ScreenWindow::resetScrollCount()
281 {
282  _scrollCount = 0;
283 }
284 
285 QRect ScreenWindow::scrollRegion() const
286 {
287  bool equalToScreenSize = windowLines() == _screen->getLines();
288 
289  if (atEndOfOutput() && equalToScreenSize)
290  return _screen->lastScrolledRegion();
291  else
292  return QRect(0, 0, windowColumns(), windowLines());
293 }
294 
295 void ScreenWindow::notifyOutputChanged()
296 {
297  // move window to the bottom of the screen and update scroll count
298  // if this window is currently tracking the bottom of the screen
299  if (_trackOutput) {
300  _scrollCount -= _screen->scrolledLines();
301  _currentLine = qMax(0, _screen->getHistLines() - (windowLines() - _screen->getLines()));
302  } else {
303  // if the history is not unlimited then it may
304  // have run out of space and dropped the oldest
305  // lines of output - in this case the screen
306  // window's current line number will need to
307  // be adjusted - otherwise the output will scroll
308  _currentLine = qMax(0, _currentLine -
309  _screen->droppedLines());
310 
311  // ensure that the screen window's current position does
312  // not go beyond the bottom of the screen
313  _currentLine = qMin(_currentLine , _screen->getHistLines());
314  }
315 
316  _bufferNeedsUpdate = true;
317 
318  emit outputChanged();
319 }
320 
321 #include "ScreenWindow.moc"
Konsole::Screen::droppedLines
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:741
Konsole::ScreenWindow::scrollRegion
QRect scrollRegion() const
Returns the area of the window which was last scrolled, this is usually the whole window area...
Definition: ScreenWindow.cpp:285
Konsole::Screen::lastScrolledRegion
QRect lastScrolledRegion() const
Returns the region of the image which was last scrolled.
Definition: Screen.cpp:761
Konsole::Screen::selectedText
QString selectedText(bool preserveLineBreaks, bool trimTrailingSpaces=false) const
Convenience method.
Definition: Screen.cpp:1110
Konsole::ScreenWindow::currentResultLine
int currentResultLine() const
Definition: ScreenWindow.cpp:216
Konsole::ScreenWindow::setSelectionEnd
void setSelectionEnd(int column, int line)
Sets the end of the selection to the given line and column within the window.
Definition: ScreenWindow.cpp:145
Konsole::Screen::getLines
int getLines() const
Return the number of lines.
Definition: Screen.h:382
Konsole::ScreenWindow::notifyOutputChanged
void notifyOutputChanged()
Notifies the window that the contents of the associated terminal screen have changed.
Definition: ScreenWindow.cpp:295
Konsole::ScreenWindow::clearSelection
void clearSelection()
Clears the current selection.
Definition: ScreenWindow.cpp:169
Konsole::ScreenWindow::getLineProperties
QVector< LineProperty > getLineProperties()
Returns the line attributes associated with the lines of characters which are currently visible throu...
Definition: ScreenWindow.cpp:112
Konsole::ScreenWindow::currentLine
int currentLine() const
Returns the index of the line which is currently at the top of this window.
Definition: ScreenWindow.cpp:211
Konsole::Screen::getImage
void getImage(Character *dest, int size, int startLine, int endLine) const
Returns the current screen image.
Definition: Screen.cpp:450
Screen.h
Konsole::ScreenWindow::trackOutput
bool trackOutput() const
Returns whether the window automatically moves to the bottom of the screen as new output is added...
Definition: ScreenWindow.cpp:270
Konsole::Screen::getColumns
int getColumns() const
Return the number of columns.
Definition: Screen.h:386
QObject
Konsole::ScreenWindow::columnCount
int columnCount() const
Returns the total number of columns in the screen.
Definition: ScreenWindow.cpp:196
Konsole::Screen::fillWithDefaultChar
static void fillWithDefaultChar(Character *dest, int count)
Fills the buffer dest with count instances of the default (ie.
Definition: Screen.cpp:1383
Konsole::ScreenWindow::scrollBy
void scrollBy(RelativeScrollMode mode, int amount, bool fullPage)
Scrolls the window relative to its current position on the screen.
Definition: ScreenWindow.cpp:231
Konsole::ScreenWindow::ScreenWindow
ScreenWindow(QObject *parent=0)
Constructs a new screen window with the given parent.
Definition: ScreenWindow.cpp:28
Konsole::ScreenWindow::setSelectionByLineRange
void setSelectionByLineRange(int start, int end)
Sets the selection as the range specified by line start and line end in the whole history...
Definition: ScreenWindow.cpp:153
Konsole::ScreenWindow::cursorPosition
QPoint cursorPosition() const
Returns the position of the cursor within the window.
Definition: ScreenWindow.cpp:201
Konsole::ScreenWindow::selectedText
QString selectedText(bool preserveLineBreaks, bool trimTrailingSpaces=false) const
Returns the text which is currently selected.
Definition: ScreenWindow.cpp:122
Konsole::ScreenWindow::scrollCount
int scrollCount() const
Returns the number of lines which the region of the window specified by scrollRegion() has been scrol...
Definition: ScreenWindow.cpp:275
Konsole::Character
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:77
Konsole::ScreenWindow::atEndOfOutput
bool atEndOfOutput() const
Convenience method.
Definition: ScreenWindow.cpp:243
Konsole::ScreenWindow::outputChanged
void outputChanged()
Emitted when the contents of the associated terminal screen (see screen()) changes.
Konsole::Screen
An image of characters with associated attributes.
Definition: Screen.h:74
Konsole::Screen::scrolledLines
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:737
Konsole::ScreenWindow::scrollTo
void scrollTo(int line)
Scrolls the window so that line is at the top of the window.
Definition: ScreenWindow.cpp:248
Konsole::ScreenWindow::windowColumns
int windowColumns() const
Returns the number of columns in the window.
Definition: ScreenWindow.cpp:186
Konsole::ScreenWindow::~ScreenWindow
virtual ~ScreenWindow()
Definition: ScreenWindow.cpp:41
Konsole::Screen::clearSelection
void clearSelection()
Clears the current selection.
Definition: Screen.cpp:1029
Konsole::ScreenWindow::getSelectionEnd
void getSelectionEnd(int &column, int &line)
Retrieves the end of the selection within the window.
Definition: ScreenWindow.cpp:132
Konsole::ScreenWindow::isSelected
bool isSelected(int column, int line)
Returns true if the character at line , column is part of the selection.
Definition: ScreenWindow.cpp:164
Konsole::ScreenWindow::getSelectionStart
void getSelectionStart(int &column, int &line)
Retrieves the start of the selection within the window.
Definition: ScreenWindow.cpp:127
Konsole::Screen::getSelectionStart
void getSelectionStart(int &column, int &line) const
Retrieves the start of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1036
Konsole::ScreenWindow::getImage
Character * getImage()
Returns the image of characters which are currently visible through this window onto the screen...
Definition: ScreenWindow.cpp:57
Konsole::ScreenWindow::setCurrentResultLine
void setCurrentResultLine(int line)
What line the next search will start from.
Definition: ScreenWindow.cpp:221
Konsole::Screen::isSelected
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:1098
Konsole::Screen::getSelectionEnd
void getSelectionEnd(int &column, int &line) const
Retrieves the end of the selection or the cursor position if there is no selection.
Definition: Screen.cpp:1046
Konsole::ScreenWindow::resetScrollCount
void resetScrollCount()
Resets the count of scrolled lines returned by scrollCount()
Definition: ScreenWindow.cpp:280
Konsole::Screen::getCursorX
int getCursorX() const
Returns the column which the cursor is positioned at.
Definition: Screen.cpp:830
Konsole::ScreenWindow::screen
Screen * screen() const
Returns the screen which this window looks onto.
Definition: ScreenWindow.cpp:52
Konsole::ScreenWindow::setSelectionStart
void setSelectionStart(int column, int line, bool columnMode)
Sets the start of the selection to the given line and column within the window.
Definition: ScreenWindow.cpp:137
Konsole::Screen::getCursorY
int getCursorY() const
Returns the line which the cursor is positioned on.
Definition: Screen.cpp:835
Konsole::Screen::setSelectionEnd
void setSelectionEnd(const int column, const int line)
Sets the end of the current selection.
Definition: Screen.cpp:1067
Konsole::ScreenWindow::selectionChanged
void selectionChanged()
Emitted when the selection is changed.
Konsole::ScreenWindow::currentResultLineChanged
void currentResultLineChanged()
Konsole::ScreenWindow::setWindowLines
void setWindowLines(int lines)
Sets the number of lines in the window.
Definition: ScreenWindow.cpp:176
Konsole::ScreenWindow::scrolled
void scrolled(int line)
Emitted when the screen window is scrolled to a different position.
Konsole::ScreenWindow::RelativeScrollMode
RelativeScrollMode
Describes the units which scrollBy() moves the window by.
Definition: ScreenWindow.h:193
Konsole::Screen::setSelectionStart
void setSelectionStart(const int column, const int line, const bool blockSelectionMode)
Sets the start of the selection.
Definition: Screen.cpp:1056
Konsole::Screen::getHistLines
int getHistLines() const
Return the number of lines in the history buffer.
Definition: Screen.cpp:1348
Konsole::ScreenWindow::setScreen
void setScreen(Screen *screen)
Sets the screen which this window looks onto.
Definition: ScreenWindow.cpp:45
ScreenWindow.h
Konsole::ScreenWindow::lineCount
int lineCount() const
Returns the total number of lines in the screen.
Definition: ScreenWindow.cpp:191
Konsole::ScreenWindow::setTrackOutput
void setTrackOutput(bool trackOutput)
Specifies whether the window should automatically move to the bottom of the screen when new output is...
Definition: ScreenWindow.cpp:265
Konsole::ScreenWindow::ScrollPages
Scroll the window down by a given number of pages, where one page is windowLines() lines...
Definition: ScreenWindow.h:200
Konsole::Screen::getLineProperties
QVector< LineProperty > getLineProperties(int startLine, int endLine) const
Returns the additional attributes associated with lines in the image.
Definition: Screen.cpp:485
Konsole::ScreenWindow::windowLines
int windowLines() const
Returns the number of lines in the window.
Definition: ScreenWindow.cpp:181
Konsole::ScreenWindow::ScrollLines
Scroll the window down by a given number of lines.
Definition: ScreenWindow.h:195
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal