forked from OpenModelica/OpenModelica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputcell.cpp
1295 lines (1129 loc) · 32.2 KB
/
inputcell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define QT_NO_DEBUG_OUTPUT
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
* PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
* For more information about the Qt-library visit TrollTech's webpage
* regarding the Qt licence: http://www.trolltech.com/products/qt/licensing.html
*/
/*!
* \file inputcell.cpp
* \author Ingemar Axelsson and Anders Fernström
* \date 2005-10-27 (update)
*
* \brief Describes an inputcell.
*/
//STD Headers
#include <exception>
#include <stdexcept>
#include <sstream>
//QT Headers
#include <QtGlobal>
#include <QtWidgets>
//IAEX Headers
#include "inputcell.h"
#include "treeview.h"
#include "stylesheet.h"
#include "commandcompletion.h"
#include "omcinteractiveenvironment.h"
namespace IAEX
{
/*!
* \class MyTextEdit
* \author Anders Ferström
* \date 2005-11-01
*
* \brief Extends QTextEdit. Mostly so I can catch when a user
* clicks on the editor
*/
MyTextEdit::MyTextEdit(QWidget *parent)
: QTextBrowser(parent),
inCommand(false)
{
}
MyTextEdit::~MyTextEdit()
{
}
/*!
* \author Anders Fernström
* \date 2005-11-01
* \date 2005-12-15 (update)
*
* Needed a signal to be emited when the user click on the cell.
*
* 2005-12-15 AF, set inCommand to false when clicking on the cell,
* otherwise the commandcompletion class want be reseted when
* changing inputcells by clicking.
*/
void MyTextEdit::mousePressEvent(QMouseEvent *event)
{
inCommand = false;
QTextBrowser::mousePressEvent(event);
if( event->modifiers() == Qt::ShiftModifier ||
textCursor().hasSelection() )
{
return;
}
emit clickOnCell();
}
/*!
* \author Anders Fernström
* \date 2005-11-28
*
* \brief Handles mouse wheel events, ignore them and send the up
* in the cell hierarchy
*/
void MyTextEdit::wheelEvent(QWheelEvent * event)
{
// ignore event and send it up in the event hierarchy
event->ignore();
emit wheelMove( event );
}
/*!
* \author Anders Fernström
* \date 2005-12-15
* \date 2006-01-30 (update)
*
* \brief Handles key event, check if command completion or eval,
* otherwise send them to the textbrowser
*
* 2006-01-30 AF, added ignore to 'Alt+Enter'
*/
void MyTextEdit::keyPressEvent(QKeyEvent *event )
{
// EVAL, key: SHIFT + RETURN || SHIFT + ENTER
if( event->modifiers() == Qt::ShiftModifier &&
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) )
{
inCommand = false;
event->accept();
emit eval();
}
// COMMAND COMPLETION, key: SHIFT + TAB (= BACKTAB) || CTRL + SPACE
else if( (event->modifiers() == Qt::ShiftModifier && event->key() == Qt::Key_Backtab ) ||
(event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_Space) )
{
event->accept();
if( inCommand )
{
emit nextCommand();
}
else
{
inCommand = true;
emit command();
}
}
// COMMAND COMPLETION- NEXT FIELD, key: CTRL + TAB
else if( event->modifiers() == Qt::ControlModifier &&
event->key() == Qt::Key_Tab )
{
event->accept();
inCommand = false;
emit nextField();
}
// BACKSPACE, DELETE
else if( event->key() == Qt::Key_Backspace ||
event->key() == Qt::Key_Delete )
{
inCommand = false;
QTextBrowser::keyPressEvent( event );
}
// ALT+ENTER (ignore)
else if( event->modifiers() == Qt::AltModifier &&
( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return ))
{
inCommand = false;
event->ignore();
}
// PAGE UP (ignore)
else if( event->key() == Qt::Key_PageUp )
{
inCommand = false;
event->ignore();
}
// PAGE DOWN (ignore)
else if( event->key() == Qt::Key_PageDown )
{
inCommand = false;
event->ignore();
}
// CTRL+C
else if( event->modifiers() == Qt::ControlModifier &&
event->key() == Qt::Key_C )
{
inCommand = false;
event->ignore();
emit forwardAction( 1 );
}
// CTRL+X
else if( event->modifiers() == Qt::ControlModifier &&
event->key() == Qt::Key_X )
{
inCommand = false;
event->ignore();
emit forwardAction( 2 );
}
// CTRL+V
else if( event->modifiers() == Qt::ControlModifier &&
event->key() == Qt::Key_V )
{
inCommand = false;
event->ignore();
emit forwardAction( 3 );
}
// TAB
else if( event->key() == Qt::Key_Tab )
{
inCommand = false;
textCursor().insertText( " " );
}
else
{
inCommand = false;
QTextBrowser::keyPressEvent( event );
}
}
/*!
* \author Anders Fernström
* \date 2006-01-23
*
* \brief If the mimedata that should be insertet contain text,
* create a new mimedata object that only contains text, otherwise
* text format is insertet also - don't want that for inputcells.
*/
void MyTextEdit::insertFromMimeData(const QMimeData *source)
{
if( source->hasText() )
{
QMimeData *newSource = new QMimeData();
newSource->setText( source->text() );
QTextBrowser::insertFromMimeData( newSource );
delete newSource;
}
else
QTextBrowser::insertFromMimeData( source );
}
/*!
* \class InputCell
* \author Ingemar Axelsson and Anders Fernström
*
* \brief Describes how an inputcell works.
*
* Input cells is places where the user can do input. To evaluate
* the content of an inputcell just press shift+enter. It will
* throw an exception if it cant find OMC. Start OMC with
* following commandline:
*
* # omc +d=interactiveCorba
*
*
* \todo Make it possiblee to add and change syntax coloring of code.(Ingemar Axelsson)
*/
int InputCell::numEvals_ = 1;
/*!
* \author Ingemar Axelsson and Anders Fernström
* \date 2005-11-23 (update)
*
* \brief The class constructor
*
* 2005-10-27 AF, updated the method due to porting from Q3Support
* to pure QT4 classes.
* 2005-11-23 AF, added document to the constructor, because need
* the document to insert images to the output part if ploting.
*/
InputCell::InputCell(Document *doc, QWidget *parent)
: Cell(parent),
evaluated_(false),
closed_(true),
delegate_(0),
oldHeight_( 0 ),
document_(doc)
{
QWidget *main = new QWidget(this);
setMainWidget(main);
layout_ = new QGridLayout(mainWidget());
layout_->setContentsMargins(0, 0, 0, 0);
layout_->setSpacing(0);
setTreeWidget(new InputTreeView(this));
//2005-10-07 AF, Porting, change from 'QWidget::' to 'Qt::'
setFocusPolicy(Qt::NoFocus);
createInputCell();
createOutputCell();
//setBackgroundColor(QColor(200,200,255));
}
/*!
* \author Ingemar Axelsson and Anders Fernström
*
* \brief The class destructor
*/
InputCell::~InputCell()
{
delete input_;
delete output_;
}
/*!
* \author Anders Fernström and Ingemar Axelsson
* \date 2006-03-02 (update)
*
* \brief Creates the QTextEdit for the input part of the
* inputcell
*
* 2005-10-27 AF, Large part of this function was changes due to
* porting to QT4 (changes from Q3TextEdit to QTextEdit).
* 2005-12-15 AF, Added more connections to the editor, mostly for
* commandcompletion, but also for eval. invoking eval have moved
* from the eventfilter on this cell to the reimplemented key event
* handler in the editor
* 2006-03-02 AF, Added call to createChapterCounter();
*/
void InputCell::createInputCell()
{
input_ = new MyTextEdit( mainWidget() );
mpModelicaTextHighlighter = new ModelicaTextHighlighter(input_->document());
layout_->addWidget( input_, 1, 1 );
// 2006-03-02 AF, Add a chapter counter
createChapterCounter();
//input_->setReadOnly( false );
input_->setReadOnly( true );
input_->setUndoRedoEnabled( true );
//input_->setFrameStyle( QFrame::NoFrame );
input_->setFrameShape( QFrame::Box );
input_->setAutoFormatting( QTextEdit::AutoNone );
input_->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
input_->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
// input_->setContextMenuPolicy( Qt::NoContextMenu );
QPalette palette;
palette.setColor(input_->backgroundRole(), QColor(200,200,255));
input_->setPalette(palette);
// is this needed, don't know /AF
input_->installEventFilter(this);
connect( input_, SIGNAL( textChanged() ),
this, SLOT( contentChanged() ));
connect( input_, SIGNAL( clickOnCell() ),
this, SLOT( clickEvent() ));
connect( input_, SIGNAL( wheelMove(QWheelEvent*) ),
this, SLOT( wheelEvent(QWheelEvent*) ));
// 2005-12-15 AF, new connections
connect( input_, SIGNAL( eval() ),
this, SLOT( eval() ));
connect( input_, SIGNAL( command() ),
this, SLOT( command() ));
connect( input_, SIGNAL( nextCommand() ),
this, SLOT( nextCommand() ));
connect( input_, SIGNAL( nextField() ),
this, SLOT( nextField() ));
//2005-12-29 AF
connect( input_, SIGNAL( textChanged() ),
this, SLOT( addToHighlighter() ));
// 2006-01-17 AF, new...
connect( input_, SIGNAL( currentCharFormatChanged(const QTextCharFormat &) ),
this, SLOT( charFormatChanged(const QTextCharFormat &) ));
// 2006-04-27 AF,
connect( input_, SIGNAL( forwardAction(int) ),
this, SIGNAL( forwardAction(int) ));
contentChanged();
}
/*!
* \author Anders Fernström and Ingemar Axelsson
* \date 2005-10-28 (update)
*
* \brief Creates the QTextEdit for the output part of the
* inputcell
*
* Large part of this function was changes due to porting
* to QT4 (changes from Q3TextEdit to QTextEdit).
*/
void InputCell::createOutputCell()
{
output_ = new MyTextEdit( mainWidget() );
layout_->addWidget( output_, 2, 1 );
output_->setReadOnly( true );
//output_->setFrameShape( QFrame::Panel );
output_->setFrameShape( QFrame::Box );
output_->setAutoFormatting( QTextEdit::AutoNone );
output_->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
output_->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
// output_->setContextMenuPolicy( Qt::NoContextMenu );
connect( output_, SIGNAL( textChanged() ),
this, SLOT(contentChanged()));
connect( output_, SIGNAL( clickOnCell() ),
this, SLOT( clickEventOutput() ));
connect( output_, SIGNAL( wheelMove(QWheelEvent*) ),
this, SLOT( wheelEvent(QWheelEvent*) ));
connect(output_, SIGNAL(forwardAction(int)), this, SIGNAL(forwardAction(int)));
setOutputStyle();
output_->hide();
}
/*!
* \author Anders Fernström
* \date 2006-04-21
*
* \brief Set the output style
*/
void InputCell::setOutputStyle()
{
// Set the correct style for the QTextEdit output_
output_->selectAll();
Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" );
CellStyle style = sheet->getStyle( "Output" );
if( style.name() != "null" )
{
output_->setAlignment( (Qt::AlignmentFlag)style.alignment() );
output_->mergeCurrentCharFormat( (*style.textCharFormat()) );
output_->document()->rootFrame()->setFrameFormat( (*style.textFrameFormat()) );
}
else
{
// 2006-01-30 AF, add message box
QMessageBox::warning( 0, tr("Warning"), tr("No Output style defined, please define an Output style in stylesheet.xml"), "OK" );
}
QTextCursor cursor = output_->textCursor();
cursor.clearSelection();
output_->setTextCursor( cursor );
}
/*!
* \author Anders Fernström
* \date 2006-03-02
*
* \brief Creates the chapter counter
*/
void InputCell::createChapterCounter()
{
chaptercounter_ = new MyTextEdit(this);
chaptercounter_->setFrameStyle( QFrame::NoFrame );
chaptercounter_->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
chaptercounter_->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
chaptercounter_->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
chaptercounter_->setContextMenuPolicy( Qt::NoContextMenu );
chaptercounter_->setFixedWidth(50);
chaptercounter_->setReadOnly( true );
connect( chaptercounter_, SIGNAL( clickOnCell() ),
this, SLOT( clickEvent() ));
addChapterCounter( chaptercounter_ );
}
/*!
* \author Anders Fernström
* \date 2005-10-27
*
* \brief Returns the text (as plain text) fromthe cell
*
* \return The text, as plain text
*/
QString InputCell::text()
{
return input_->toPlainText();
}
/*!
* \author Anders Fernström
* \date 2005-10-27
*
* \brief Return the text inside the cell as Html code
*
* \return Html code
*/
QString InputCell::textHtml()
{
return input_->toHtml();
}
/*!
* \author Anders Fernström
* \date 2005-11-23
*
* \brief Return the text inside the output part of the cell
* as plain text
*
* \return output text
*/
QString InputCell::textOutput()
{
return output_->toPlainText();
}
/*!
* \author Anders Fernström
* \date 2005-11-23
*
* \brief Return the text inside the output part of the cell
* as html code
*
* \return html code
*/
QString InputCell::textOutputHtml()
{
return output_->toHtml();
}
/*!
* \author Anders Fernström
* \date 2005-10-27
*
* \brief Return the text cursor to the QTextEdit that make up
* the inputpart of the inputcell
*
* \return Text cursor to the cell
*/
QTextCursor InputCell::textCursor()
{
return input_->textCursor();
}
/*!
* \author Anders Fernström
* \date 2006-01-05
*
* \brief Return the input texteditor
*
* \return Texteditor for the inputpart of the inputcell
*/
QTextEdit *InputCell::textEdit()
{
return input_;
}
/*!
* \author Anders Fernström
* \date 2006-02-03
*
* \brief Return the output texteditor
*
* \return Texteditor for the output part of the inputcell
*/
QTextEdit* InputCell::textEditOutput()
{
return output_;
}
/*!
* \author Ingemar Axelsson and Anders Fernström
* \date 2005-12-16 (update)
*
* \brief Set text to the cell
*
* \param text The text that should be placed inside the cell
*
* 2005-10-04 AF, added some code for removing/replacing some text
* 2005-10-27 AF, updated the function due to porting from qt3 to qt4
* 2005-12-08 AF, added code that removed any <span style tags added
* in the parser.
* 2005-12-16 AF, block signlas so syntax highligher isn't done more
* than once.
*/
void InputCell::setText(QString text)
{
// 2005-12-16 AF, block signals
input_->document()->blockSignals(true);
// 2005-10-04 AF, added some code to replace/remove
QString tmp = text.replace("<br>", "\n");
tmp.replace( " ", " " );
// 2005-12-08 AF, remove any <span style tag
QRegularExpression spanEnd("</span>");
tmp.remove( spanEnd );
int pos = 0;
while( true )
{
int startpos = tmp.indexOf( "<span", pos, Qt::CaseInsensitive );
if( startpos >= 0 )
{
int endpos = tmp.indexOf( "\">", startpos );
if( endpos >= 0 )
{
endpos += 2;
tmp.remove( startpos, endpos - startpos );
}
else
break;
}
else
break;
pos = startpos;
}
// set the text
input_->setPlainText( tmp );
// 2005-12-16 AF, unblock signals and tell highlighter to highlight
input_->document()->blockSignals(false);
// input_->document()->setHtml( input_->toHtml() );
// input_->document()->setPlainText( input_->toPlainText() ); // This causes a crash with Qt >= 4.2
input_->document()->rootFrame()->setFrameFormat( (*style_.textFrameFormat()) );
contentChanged();
}
/*!
* \author Anders Fernström
* \date 2005-11-01
*
* \brief Sets the visible text using html code.
*
* Sets the text that should be visible using html code. Can change
* the cellheight if the text is very long.
*
* \param html Html code that should be visible as normal text inside the cell mainarea.
*/
void InputCell::setTextHtml(QString html)
{
input_->setHtml( html );
setStyle( style_ );
contentChanged();
}
/*!
* \author Anders Fernström
* \date 2005-11-23
*
* \brief Set text to the output part of the cell
*
* \param text The text that should be placed inside the output part
*/
void InputCell::setTextOutput(QString text)
{
if( !text.isNull() && !text.isEmpty() )
{
output_->setPlainText( text );
evaluated_ = true;
//setClosed( false );
contentChanged();
}
}
/*!
* \author Anders Fernström
* \date 2005-11-23
*
* \brief Sets the output text using html code.
*
* Sets the text that should be visible in the output part of the
* cell using html code. Can change the cellheight if the text is
* very long.
*
* \param html Html code that should be visible as normal text inside the cell mainarea.
*/
void InputCell::setTextOutputHtml(QString html)
{
if( !html.isNull() && !html.isEmpty() )
{
output_->setHtml( html );
evaluated_ = true;
//setClosed( false );
contentChanged();
}
}
/*!
* \author Anders Fernström
* \date 2005-10-28
*
* \brief Set cell style
*
* IMPORTANT: User shouldn't be able to change style on inputcells
* so this function always use "Input" as style.
*
* \param stylename The style name of the style that is to be applyed to the cell
*/
void InputCell::setStyle(const QString &)
{
Cell::setStyle( "Input" );
}
/*!
* \author Anders Fernström
* \date 2005-10-27
* \date 2006-03-02 (update)
*
* \brief Set cell style
*
* IMPORTANT: User shouldn't be able to change style on inputcells
* so this function always use "Input" as style.
*
* 2005-11-03 AF, updated so the text is selected when the style
* is changed, after the text is unselected.
* 2006-03-02 AF, set chapter style
*
* \param style The cell style that is to be applyed to the cell
*/
void InputCell::setStyle(CellStyle style)
{
if( style.name() == "Input" )
{
Cell::setStyle( style );
// select all the text
input_->selectAll();
// set the new style settings
input_->setAlignment( (Qt::AlignmentFlag)style_.alignment() );
input_->mergeCurrentCharFormat( (*style_.textCharFormat()) );
input_->document()->rootFrame()->setFrameFormat( (*style_.textFrameFormat()) );
// unselect the text
QTextCursor cursor( input_->textCursor() );
cursor.clearSelection();
input_->setTextCursor( cursor );
// 2006-03-02 AF, set chapter counter style
chaptercounter_->selectAll();
chaptercounter_->mergeCurrentCharFormat( (*style_.textCharFormat()) );
QTextFrameFormat format = chaptercounter_->document()->rootFrame()->frameFormat();
format.setMargin( style_.textFrameFormat()->margin() +
style_.textFrameFormat()->border() +
style_.textFrameFormat()->padding() );
chaptercounter_->document()->rootFrame()->setFrameFormat( format );
chaptercounter_->setAlignment( (Qt::AlignmentFlag)Qt::AlignRight );
cursor = chaptercounter_->textCursor();
cursor.clearSelection();
chaptercounter_->setTextCursor( cursor );
}
else
{
setStyle( "Input" );
}
}
/*!
* \author Anders Fernström
* \date 2006-03-02
*
* \brief set the chapter counter
*/
void InputCell::setChapterCounter( QString number )
{
chaptercounter_->selectAll();
chaptercounter_->setPlainText( number );
chaptercounter_->setAlignment( (Qt::AlignmentFlag)Qt::AlignRight );
QTextFrameFormat format = chaptercounter_->document()->rootFrame()->frameFormat();
format.setMargin( style_.textFrameFormat()->margin() +
style_.textFrameFormat()->border() +
style_.textFrameFormat()->padding() );
chaptercounter_->document()->rootFrame()->setFrameFormat( format );
}
/*!
* \author Anders Fernström
* \date 2006-03-02
*
* \brief return the value of the chapter counter, as plain text.
* Returns null if the counter is empty
*/
QString InputCell::ChapterCounter()
{
if( chaptercounter_->toPlainText().isEmpty() )
return QString();
return chaptercounter_->toPlainText();
}
/*!
* \author Anders Fernström
* \date 2006-03-03
*
* \brief return the value of the chapter counter, as html code.
* Returns null if the counter is empty
*/
QString InputCell::ChapterCounterHtml()
{
if( chaptercounter_->toPlainText().isEmpty() )
return QString();
return chaptercounter_->toHtml();
}
/*!
* \author Anders Fernström
* \date 2005-11-01
* \date 2006-03-02 (update)
*
* \brief Set readonly value on the texteditor
*
* \param readonly The boolean value of readonly property
*
* 2006-03-02 AF, clear text selection in chapter counter
*/
void InputCell::setReadOnly(const bool readonly)
{
if( readonly )
{
QTextCursor cursor = input_->textCursor();
cursor.clearSelection();
input_->setTextCursor( cursor );
cursor = output_->textCursor();
cursor.clearSelection();
output_->setTextCursor( cursor );
// 2006-03-02 AF, clear selection in chapter counter
cursor = chaptercounter_->textCursor();
cursor.clearSelection();
chaptercounter_->setTextCursor( cursor );
}
input_->setReadOnly(readonly);
}
/*!
* \author Anders Fernström
* \date 2006-01-16
*
* \brief Set evaluated value on the texteditor
*
* \param evaluated The boolean value of evaluated property
*/
void InputCell::setEvaluated(const bool evaluated)
{
evaluated_ = evaluated;
}
/*!
* \author Ingemar Axelsson (and Anders Fernström)
* \date 2005-11-01 (update)
*
* \brief Set if the output part of the cell shoud be
* closed(hidden) or not.
*
* 2005-11-01 AF, Made some small changes to how the function
* calculate the new height, to reflect the changes made when
* porting from Q3TextEdit to QTextEdit.
*/
void InputCell::setClosed(const bool closed, bool update)
{
if( closed )
output_->hide();
else
{
if( evaluated_ )
output_->show();
}
closed_ = closed;
contentChanged();
}
/*!
* \author Ingemar Axelsson and Anders Fernström
*/
void InputCell::setFocus(const bool focus)
{
if(focus)
input_->setFocus();
}
/*!
* \author Anders Fernström
*/
void InputCell::setFocusOutput(const bool focus)
{
if(focus)
output_->setFocus();
}
/*!
* \author Ingemar Axelsson and Anders Fernström
*/
void InputCell::clickEvent()
{
//if( input_->isReadOnly() )
emit clicked(this);
}
/*!
* \author Anders Fernström
*/
void InputCell::clickEventOutput()
{
emit clickedOutput(this);
}
/*!
* \author Anders Fernström and Ingemar Axelsson
* \date 2006-04-10 (update)
*
* \brief Recalculates height.
*
* 2005-10-31 AF, Large part of this function was changes due to
* porting to QT4 (changes from Q3TextBrowser to QTextBrowser).
* 2006-04-10 AF, emits heightChanged if the height changes
*/
void InputCell::contentChanged()
{
int height = input_->document()->documentLayout()->documentSize().toSize().height();
if( height < 0 )
height = 30;
// add a little extra, just in case /AF
input_->setMinimumHeight( height + 3 );
if( evaluated_ && !closed_ )
{
int outHeight = output_->document()->documentLayout()->documentSize().toSize().height();
if( outHeight < 0 )
outHeight = 30;
output_->setMinimumHeight( outHeight );
height += outHeight;
}
// add a little extra, just in case, emit 'heightChanged()' if height
// have chagned /AF
setHeight( height + 3 );
emit textChanged();
if( oldHeight_ != (height + 3) )
emit heightChanged();
oldHeight_ = height + 3;
}
/*!
* \author Anders Fernström
* \date 2006-01-17
*
* \brief Returns true if inputcell is closed, otherwise the method
* returns false.
*
* \return State of inputcell (closed or not)
*/
bool InputCell::isClosed()
{
return closed_;
}
/*!
* \author Anders Fernström
* \date 2005-10-27
*
* \brief Function for telling if the user is allowed to change
* the text settings for the text inside the cell. User isn't
* allowed to change the text settings for inputcell so this
* function always return false.
*