source: trunk/tools/designer/editor/viewmanager.cpp

Last change on this file was 197, checked in by rudi, 14 years ago

Added QtDesigner

File size: 8.7 KB
Line 
1 /**********************************************************************
2** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
3**
4** This file is part of Qt Designer.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12** licenses may use this file in accordance with the Qt Commercial License
13** Agreement provided with the Software.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18** See http://www.trolltech.com/gpl/ for GPL licensing information.
19** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20** information about Qt Commercial License Agreements.
21**
22** Contact info@trolltech.com if any conditions of this licensing are
23** not clear to you.
24**
25**********************************************************************/
26
27#include "viewmanager.h"
28#include "editor.h"
29#include "markerwidget.h"
30#include <qlayout.h>
31#include <private/qrichtext_p.h>
32#include "paragdata.h"
33#include <qobjectlist.h>
34#include <qlabel.h>
35#include <qtimer.h>
36
37ViewManager::ViewManager( QWidget *parent, const char *name )
38 : QWidget( parent, name ), curView( 0 )
39{
40 QHBoxLayout *l = new QHBoxLayout( this );
41 markerWidget = new MarkerWidget( this, "editor_markerwidget" );
42 connect( markerWidget, SIGNAL( markersChanged() ),
43 this, SIGNAL( markersChanged() ) );
44 connect( markerWidget, SIGNAL( collapseFunction( QTextParagraph * ) ),
45 this, SIGNAL( collapseFunction( QTextParagraph * ) ) );
46 connect( markerWidget, SIGNAL( expandFunction( QTextParagraph * ) ),
47 this, SIGNAL( expandFunction( QTextParagraph * ) ) );
48 connect( markerWidget, SIGNAL( collapse( bool ) ),
49 this, SIGNAL( collapse( bool ) ) );
50 connect( markerWidget, SIGNAL( expand( bool ) ),
51 this, SIGNAL( expand( bool ) ) );
52 connect( markerWidget, SIGNAL( editBreakPoints() ),
53 this, SIGNAL( editBreakPoints() ) );
54 connect( markerWidget, SIGNAL( isBreakpointPossible( bool&, const QString &, int ) ),
55 this, SIGNAL( isBreakpointPossible( bool&, const QString &, int ) ) );
56 connect( markerWidget, SIGNAL( showMessage( const QString & ) ),
57 this, SLOT( showMessage( const QString & ) ) );
58 messageTimer = new QTimer( this );
59 connect( messageTimer, SIGNAL( timeout() ), this, SLOT( clearStatusBar() ) );
60 markerWidget->setFixedWidth( fontMetrics().width( "0000" ) + 20 );
61 l->addWidget( markerWidget );
62 layout = new QVBoxLayout( l );
63}
64
65void ViewManager::addView( QWidget *view )
66{
67 layout->addWidget( view );
68 curView = view;
69 connect( ( (Editor*)curView )->verticalScrollBar(), SIGNAL( valueChanged( int ) ),
70 markerWidget, SLOT( doRepaint() ) );
71 connect( (Editor*)curView, SIGNAL( textChanged() ),
72 markerWidget, SLOT( doRepaint() ) );
73 connect( (Editor*)curView, SIGNAL( clearErrorMarker() ),
74 this, SLOT( clearErrorMarker() ) );
75 posLabel = new QLabel( this, "editor_poslabel" );
76 posLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
77 posLabel->setText( " Line: 1 Col: 1" );
78 posLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
79 posLabel->setLineWidth( 1 );
80 posLabel->setFixedHeight( posLabel->fontMetrics().height() );
81 layout->addWidget( posLabel );
82 connect( curView, SIGNAL( cursorPositionChanged( int, int ) ),
83 this, SLOT( cursorPositionChanged( int, int ) ) );
84}
85
86QWidget *ViewManager::currentView() const
87{
88 return curView;
89}
90
91void ViewManager::childEvent( QChildEvent *e )
92{
93 if ( e->type() == QEvent::ChildInserted && ::qt_cast<Editor*>(e->child()) )
94 addView( (QWidget*)e->child() );
95 QWidget::childEvent( e );
96}
97
98void ViewManager::setError( int line )
99{
100 QTextParagraph *p = ( (Editor*)curView )->document()->paragAt( line );
101 if ( p ) {
102 ( (Editor*)curView )->setErrorSelection( line );
103 ( (Editor*)curView )->setCursorPosition( line, 0 );
104 ( (Editor*)curView )->viewport()->setFocus();
105 ( (Editor*)curView )->makeFunctionVisible( p );
106 ParagData *paragData = (ParagData*)p->extraData();
107 if ( !paragData )
108 paragData = new ParagData;
109 paragData->marker = ParagData::Error;
110 p->setExtraData( paragData );
111 markerWidget->doRepaint();
112 }
113}
114
115void ViewManager::setStep( int line )
116{
117 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
118 while ( p ) {
119 if ( p->extraData() )
120 ( (ParagData*)p->extraData() )->step = FALSE;
121 p = p->next();
122 }
123 p = ( (Editor*)curView )->document()->paragAt( line );
124 if ( p ) {
125 ( (Editor*)curView )->setStepSelection( line );
126 ( (Editor*)curView )->setCursorPosition( line, 0 );
127 ( (Editor*)curView )->viewport()->setFocus();
128 ( (Editor*)curView )->makeFunctionVisible( p );
129 ParagData *paragData = (ParagData*)p->extraData();
130 if ( !paragData )
131 paragData = new ParagData;
132 paragData->step = TRUE;
133 p->setExtraData( paragData );
134 markerWidget->doRepaint();
135 }
136}
137
138void ViewManager::clearStep()
139{
140 ( (Editor*)curView )->clearStepSelection();
141 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
142 while ( p ) {
143 if ( p->extraData() )
144 ( (ParagData*)p->extraData() )->step = FALSE;
145 p = p->next();
146 }
147 markerWidget->doRepaint();
148}
149
150void ViewManager::setStackFrame( int line )
151{
152 QTextParagraph *p = ( (Editor*)curView )->document()->paragAt( line );
153 if ( p ) {
154 ( (Editor*)curView )->sync();
155 ( (Editor*)curView )->setCursorPosition( line, 0 );
156 ( (Editor*)curView )->ensureCursorVisible();
157 ( (Editor*)curView )->viewport()->setFocus();
158 ( (Editor*)curView )->makeFunctionVisible( p );
159 ParagData *paragData = (ParagData*)p->extraData();
160 if ( !paragData )
161 paragData = new ParagData;
162 paragData->stackFrame = TRUE;
163 p->setExtraData( paragData );
164 markerWidget->doRepaint();
165 }
166}
167
168void ViewManager::clearStackFrame()
169{
170 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
171 while ( p ) {
172 if ( p->extraData() ) {
173 ( (ParagData*)p->extraData() )->stackFrame = FALSE;
174 if ( ( (ParagData*)p->extraData() )->marker == ParagData::Error )
175 ( (ParagData*)p->extraData() )->marker = ParagData::NoMarker;
176 }
177 p = p->next();
178 }
179 markerWidget->doRepaint();
180}
181
182void ViewManager::resizeEvent( QResizeEvent *e )
183{
184 QWidget::resizeEvent( e );
185 markerWidget->doRepaint();
186}
187
188void ViewManager::clearErrorMarker()
189{
190 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
191 while ( p ) {
192 if ( p->extraData() )
193 ( (ParagData*)p->extraData() )->marker = ParagData::NoMarker;
194 p = p->next();
195 }
196 markerWidget->doRepaint();
197}
198
199void ViewManager::setBreakPoints( const QValueList<uint> &l )
200{
201 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
202 int i = 0;
203 while ( p ) {
204 if ( l.find( i ) != l.end() ) {
205 if ( !p->extraData() ) {
206 ParagData *data = new ParagData;
207 p->setExtraData( data );
208 }
209 ParagData *data = (ParagData*)p->extraData();
210 data->marker = ParagData::Breakpoint;
211 } else if ( p->extraData() ) {
212 ParagData *data = (ParagData*)p->extraData();
213 data->marker = ParagData::NoMarker;
214 }
215 p = p->next();
216 ++i;
217 }
218 markerWidget->doRepaint();
219}
220
221QValueList<uint> ViewManager::breakPoints() const
222{
223 QValueList<uint> l;
224 int i = 0;
225 QTextParagraph *p = ( (Editor*)curView )->document()->firstParagraph();
226 while ( p ) {
227 if ( p->extraData() &&
228 ( (ParagData*)p->extraData() )->marker == ParagData::Breakpoint )
229 l << i;
230 p = p->next();
231 ++i;
232 }
233 return l;
234}
235
236void ViewManager::showMarkerWidget( bool b )
237{
238 if ( b )
239 markerWidget->show();
240 else
241 markerWidget->hide();
242}
243
244void ViewManager::emitMarkersChanged()
245{
246 emit markersChanged();
247}
248
249void ViewManager::cursorPositionChanged( int row, int col )
250{
251 posLabel->setText( QString( " Line: %1 Col: %2" ).arg( row + 1 ).arg( col + 1 ) );
252}
253
254void ViewManager::showMessage( const QString &msg )
255{
256 int row;
257 int col;
258 ( (QTextEdit*)currentView() )->getCursorPosition( &row, &col );
259 posLabel->setText( msg );
260 messageTimer->start( 1000, TRUE );
261}
262
263void ViewManager::clearStatusBar()
264{
265 int row;
266 int col;
267 ( (QTextEdit*)currentView() )->getCursorPosition( &row, &col );
268 posLabel->setText( QString( " Line: %1 Col: %2" ).arg( row + 1 ).arg( col + 1 ) );
269}
Note: See TracBrowser for help on using the repository browser.