~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/plugins/grass/qtermwidget/ScreenWindow.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2007 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
#ifndef SCREENWINDOW_H
 
23
#define SCREENWINDOW_H
 
24
 
 
25
// Qt
 
26
#include <QtCore/QObject>
 
27
#include <QtCore/QPoint>
 
28
#include <QtCore/QRect>
 
29
 
 
30
// Konsole
 
31
#include "Character.h"
 
32
 
 
33
namespace Konsole
 
34
{
 
35
 
 
36
  class Screen;
 
37
 
 
38
  /**
 
39
   * Provides a window onto a section of a terminal screen.
 
40
   * This window can then be rendered by a terminal display widget ( TerminalDisplay ).
 
41
   *
 
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.
 
46
   *
 
47
   * setTrackOutput() controls whether the window moves to the bottom of the associated screen when new
 
48
   * lines are added to it.
 
49
   *
 
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
 
52
   * if necessary.
 
53
   */
 
54
  class ScreenWindow : public QObject
 
55
  {
 
56
      Q_OBJECT
 
57
 
 
58
    public:
 
59
      /**
 
60
       * Constructs a new screen window with the given parent.
 
61
       * A screen must be specified by calling setScreen() before calling getImage() or getLineProperties().
 
62
       *
 
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.
 
67
       */
 
68
      ScreenWindow( QObject* parent = 0 );
 
69
      virtual ~ScreenWindow();
 
70
 
 
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;
 
75
 
 
76
      /**
 
77
       * Returns the image of characters which are currently visible through this window
 
78
       * onto the screen.
 
79
       *
 
80
       * The buffer is managed by the ScreenWindow instance and does not need to be
 
81
       * deleted by the caller.
 
82
       */
 
83
      Character* getImage();
 
84
 
 
85
      /**
 
86
       * Returns the line attributes associated with the lines of characters which
 
87
       * are currently visible through this window
 
88
       */
 
89
      QVector<LineProperty> getLineProperties();
 
90
 
 
91
      /**
 
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.
 
97
       *
 
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.
 
101
       */
 
102
      int scrollCount() const;
 
103
 
 
104
      /**
 
105
       * Resets the count of scrolled lines returned by scrollCount()
 
106
       */
 
107
      void resetScrollCount();
 
108
 
 
109
      /**
 
110
       * Returns the area of the window which was last scrolled, this is
 
111
       * usually the whole window area.
 
112
       *
 
113
       * Like scrollCount(), this is not guaranteed to be accurate,
 
114
       * but allows views to optimise rendering.
 
115
       */
 
116
      QRect scrollRegion() const;
 
117
 
 
118
      /**
 
119
       * Sets the start of the selection to the given @p line and @p column within
 
120
       * the window.
 
121
       */
 
122
      void setSelectionStart( int column , int line , bool columnMode );
 
123
      /**
 
124
       * Sets the end of the selection to the given @p line and @p column within
 
125
       * the window.
 
126
       */
 
127
      void setSelectionEnd( int column , int line );
 
128
      /**
 
129
       * Retrieves the start of the selection within the window.
 
130
       */
 
131
      void getSelectionStart( int& column , int& line );
 
132
      /**
 
133
       * Retrieves the end of the selection within the window.
 
134
       */
 
135
      void getSelectionEnd( int& column , int& line );
 
136
      /**
 
137
       * Returns true if the character at @p line , @p column is part of the selection.
 
138
       */
 
139
      bool isSelected( int column , int line );
 
140
      /**
 
141
       * Clears the current selection
 
142
       */
 
143
      void clearSelection();
 
144
 
 
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;
 
151
 
 
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;
 
156
 
 
157
      /** Returns the index of the line which is currently at the top of this window */
 
158
      int currentLine() const;
 
159
 
 
160
      /**
 
161
       * Returns the position of the cursor
 
162
       * within the window.
 
163
       */
 
164
      QPoint cursorPosition() const;
 
165
 
 
166
      /**
 
167
       * Convenience method. Returns true if the window is currently at the bottom
 
168
       * of the screen.
 
169
       */
 
170
      bool atEndOfOutput() const;
 
171
 
 
172
      /** Scrolls the window so that @p line is at the top of the window */
 
173
      void scrollTo( int line );
 
174
 
 
175
      enum RelativeScrollMode
 
176
      {
 
177
        ScrollLines,
 
178
        ScrollPages
 
179
      };
 
180
 
 
181
      /**
 
182
       * Scrolls the window relative to its current position on the screen.
 
183
       *
 
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
 
188
       * is scrolled up.
 
189
       */
 
190
      void scrollBy( RelativeScrollMode mode , int amount );
 
191
 
 
192
      /**
 
193
       * Specifies whether the window should automatically move to the bottom
 
194
       * of the screen when new output is added.
 
195
       *
 
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.
 
198
       */
 
199
      void setTrackOutput( bool trackOutput );
 
200
      /**
 
201
       * Returns whether the window automatically moves to the bottom of the screen as
 
202
       * new output is added.  See setTrackOutput()
 
203
       */
 
204
      bool trackOutput() const;
 
205
 
 
206
      /**
 
207
       * Returns the text which is currently selected.
 
208
       *
 
209
       * @param preserveLineBreaks See Screen::selectedText()
 
210
       */
 
211
      QString selectedText( bool preserveLineBreaks ) const;
 
212
 
 
213
    public slots:
 
214
      /**
 
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.
 
218
       */
 
219
      void notifyOutputChanged();
 
220
 
 
221
    signals:
 
222
      /**
 
223
       * Emitted when the contents of the associated terminal screen ( see screen() ) changes.
 
224
       */
 
225
      void outputChanged();
 
226
 
 
227
      /**
 
228
       * Emitted when the screen window is scrolled to a different position.
 
229
       *
 
230
       * @param line The line which is now at the top of the window.
 
231
       */
 
232
      void scrolled( int line );
 
233
 
 
234
      /**
 
235
       * Emitted when the selection is changed.
 
236
       */
 
237
      void selectionChanged();
 
238
 
 
239
    private:
 
240
      int endWindowLine() const;
 
241
      void fillUnusedArea();
 
242
 
 
243
      Screen* _screen; // see setScreen() , screen()
 
244
      Character* _windowBuffer;
 
245
      int _windowBufferSize;
 
246
      bool _bufferNeedsUpdate;
 
247
 
 
248
      int  _windowLines;
 
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()
 
253
  };
 
254
 
 
255
}
 
256
#endif // SCREENWINDOW_H