/
notebook.cpp
4211 lines (3682 loc) · 115 KB
/
notebook.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 notebook.h
* \author Ingemar Axelsson and Anders Fernström
* \date 2005-02-07
*/
//STD Headers
#include <exception>
#include <stdexcept>
#include <fstream>
#include <algorithm>
//QT Headers
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#else
#include <QtCore/QTimer>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QClipboard>
#include <QtGui/QColorDialog>
#include <QtGui/QFileDialog>
#include <QtGui/QFontDatabase>
#include <QtGui/QFontDialog>
#include <QtGui/QImageReader>
#include <QtGui/QKeyEvent>
#include <QtGui/QMenuBar>
#include <QtGui/QMessageBox>
#include <QtGui/QPrinter>
#include <QtGui/QPrintDialog>
#include <QtGui/QStatusBar>
#include <QtGui/QTextCursor>
#include <QtGui/QTextEdit>
#include <QtGui/QTextFrame>
#include <QtGui/QToolBar>
#include <QtGui/QLabel>
#include <QtGui/QMouseEvent>
#include <QDebug>
#include <QSettings>
#include <QToolButton>
#include <QObject>
#endif
#include <QDir>
//IAEX Headers
#include "command.h"
#include "cellcommands.h"
#include "celldocument.h"
#include "cursorcommands.h"
#include "imagesizedlg.h"
#include "notebook.h"
#include "notebookcommands.h"
#include "otherdlg.h"
#include "stylesheet.h"
#include "searchform.h"
#include "xmlparser.h"
#include "removehighlightervisitor.h"
#include "omcinteractiveenvironment.h"
using namespace std;
namespace IAEX
{
/*!
* \class NotebookWindow
* \author Ingemar Axelsson and Anders Fernström
*
* \brief This class describes a mainwindow using the CellDocument
*
* This is the main applicationwindow. It contains of a menu, a
* toolbar, a statusbar and a workspace. The workspace will contain a
* celldocument view.
*
*
* \todo implement a timer that saves a document every 5 minutes
* or so.
*
*/
// 2006-03-01 AF, Open, Save, Image and Link dir
QString NotebookWindow::openDir_ = QString::null;
QString NotebookWindow::saveDir_ = QString::null;
QString NotebookWindow::imageDir_ = QString::null;
QString NotebookWindow::linkDir_ = QString::null;
/*!
* \author Ingemar Axelsson and Anders Fernström
* \date 2006-01-17 (update)
*
* \brief The class constructor
*
* 2006-01-16 AF, Added an icon to the window
* Also made som other updates /AF
*/
NotebookWindow::NotebookWindow(Document *subject,
const QString filename, QWidget *parent)
: DocumentView(parent),
subject_(subject),
filename_(filename),
closing_(false),
app_( subject->application() ), //AF
findForm_( 0 ) //AF
{
if( filename_ != QString::null )
qDebug( filename_.toStdString().c_str() );
// subject_->attach(this);
// setMinimumSize( 150, 220 ); //AF
toolBar = new QToolBar("Show toolbar", this);
posIndicator = new QLabel("");
posIndicator->setMinimumWidth(75);
stateIndicator = new QLabel("");
stateIndicator->setMinimumWidth(60);
statusBar()->insertPermanentWidget(0,posIndicator);
statusBar()->insertPermanentWidget(0,stateIndicator);
createFileMenu();
createEditMenu();
createCellMenu();
createFormatMenu();
createInsertMenu();
createWindowMenu();
createAboutMenu();
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
toolBar->addWidget(spacer);
toolBar->addSeparator();
toolBar->addAction(quitWindowAction);
addToolBar(toolBar); //Add icons, update the edit menu etc.
subject_->attach(this);
setMinimumSize( 150, 220 ); //AF
// 2006-01-16 AF, Added an icon to the window
setWindowIcon( QIcon(":/Resources/OMNotebook_icon.svg"));
statusBar()->showMessage("Ready");
resize(800, 600);
connect( subject_->getCursor(), SIGNAL( changedPosition() ),
this, SLOT( updateMenus() ));
connect( subject_, SIGNAL( contentChanged() ),
this, SLOT( updateWindowTitle() ));
connect( subject_, SIGNAL( hoverOverFile(QString) ),
this, SLOT( setStatusMessage(QString) ));
// 2006-04-27 AF
connect( subject_, SIGNAL( forwardAction(int) ),
this, SLOT( forwardedAction(int) ));
connect( subject_, SIGNAL(updatePos(int, int)), this, SLOT(setPosition(int, int)));
connect( subject_, SIGNAL(newState(QString)), this, SLOT(setState(QString)));
connect( subject_, SIGNAL(setStatusMenu(QList<QAction*>)), this, SLOT(setStatusMenu(QList<QAction*>)));
updateWindowTitle();//
updateChapterCounters();
update();
//Intializing sketch application
window = new Tools(subject_,this);
window->resize(1200,800);
window->setWindowTitle("OMSketch");
isShown=false;
//int count=0;
Cell *current = subject_->getMainCell()->child();
cells.clear();
/**find and inserts all the present cells in document in a vector**/
cells=SearchCells(current);
window->readXml(subject_->getFilename());
}
/*!
* \author Ingemar Axelsson and Anders Fernström
* \date 2006-08-24 (update)
*
* \brief The class destructor
*
* 2005-11-03/04/07 AF, added som things that should be deleted.
* 2006-01-05 AF, added code so all inputcells are added to the
* removelist in the highlighter
* 2006-01-27 AF, remove this notebook window from the list of
* notebook windows in the main application
* 2006-08-24 AF, delete replace action
*/
NotebookWindow::~NotebookWindow()
{
//2006-01-27 AF, remove document view from application lsit
application()->removeDocumentView( this );
//2006-01-05 AF, add all inputcell to removelist on highlighter
RemoveHighlighterVisitor visitor;
subject_->runVisitor( visitor );
subject_->detach(this);
delete subject_;
//subject_ = 0;
// 2005-11-03/04/07 AF, remova all created QAction
map<QString, QAction*>::iterator s_iter = styles_.begin();
while( s_iter != styles_.end() )
{
delete (*s_iter).second;
++s_iter;
}
QHash<QString, QAction*>::iterator f_iter = fonts_.begin();
while( f_iter != fonts_.end() )
{
delete f_iter.value();
++f_iter;
}
QHash<QAction*, QColor*>::iterator c_iter = colors_.begin();
while( c_iter != colors_.end() )
{
delete c_iter.value();
++c_iter;
}
QHash<QAction*, DocumentView*>::iterator w_iter = windows_.begin();
while( w_iter != windows_.end() )
{
delete w_iter.key();
++w_iter;
}
delete stylesgroup;
delete fontsgroup;
delete sizesgroup;
delete stretchsgroup;
delete colorsgroup;
delete alignmentsgroup;
delete verticalAlignmentsgroup;
delete bordersgroup;
delete marginsgroup;
delete paddingsgroup;
delete newAction;
delete openFileAction;
delete saveAsAction;
delete saveAction;
delete printAction;
delete pdfAction;
delete closeFileAction;
delete quitWindowAction;
delete undoAction;
delete redoAction;
delete cutAction;
delete copyAction;
delete pasteAction;
delete findAction;
delete replaceAction;
delete showExprAction;
//delete cutCellAction;
//delete copyCellAction;
//delete pasteCellAction;
delete addCellAction;
delete ungroupCellAction;
delete splitCellAction;
delete deleteCellAction;
delete nextCellAction;
delete previousCellAction;
delete groupAction;
delete inputAction;
delete latexAction;
delete textAction;
delete aboutAction;
delete helpAction;
delete aboutQtAction;
delete facePlain;
delete faceBold;
delete faceItalic;
delete faceUnderline;
delete sizeSmaller;
delete sizeLarger;
delete size8pt;
delete size9pt;
delete size10pt;
delete size12pt;
delete size14pt;
delete size16pt;
delete size18pt;
delete size20pt;
delete size24pt;
delete size36pt;
delete size72pt;
delete sizeOther;
delete stretchUltraCondensed;
delete stretchExtraCondensed;
delete stretchCondensed;
delete stretchSemiCondensed;
delete stretchUnstretched;
delete stretchSemiExpanded;
delete stretchExpanded;
delete stretchExtraExpanded;
delete stretchUltraExpanded;
delete colorBlack;
delete colorWhite;
delete color10Gray;
delete color33Gray;
delete color50Gray;
delete color66Gray;
delete color90Gray;
delete colorRed;
delete colorGreen;
delete colorBlue;
delete colorCyan;
delete colorMagenta;
delete colorYellow;
delete colorOther;
delete chooseFont;
delete alignmentLeft;
delete alignmentRight;
delete alignmentCenter;
delete alignmentJustify;
delete verticalNormal;
delete verticalSub;
delete verticalSuper;
delete borderOther;
delete marginOther;
delete paddingOther;
delete insertImageAction;
delete insertLinkAction;
delete importOldFile;
delete exportPureText;
// 2006-08-24 AF, delete findForm if it exists
if( findForm_ )
delete findForm_;
delete toolBar;
delete posIndicator;
delete stateIndicator;
}
/*!
* \author Ingemar Axelsson
*/
void NotebookWindow::update()
{
QFrame *mainWidget = subject_->getState();
mainWidget->setParent(this);
mainWidget->move( QPoint(0,0) );
setCentralWidget(mainWidget);
// mainWidget->setMaximumHeight(250);
mainWidget->show();
}
/*!
* \author Anders Fernström
* \date 2005-11-30
*
* \brief Return the notebook windons document
*/
Document* NotebookWindow::document()
{
return subject_;
}
/*!
* \author Ingemar Axelsson
*/
CellApplication *NotebookWindow::application()
{
return subject_->application();
}
/*!
* \author Anders Fernström
* \date 2005-12-01 (update)
*
* \brief Method for creating file nemu.
*
* 2005-10-07 AF, Updated/Remade the function when porting to QT4.
* 2005-11-21 AF, Added a export menu
* 2005-12-01 AF, Added a import menu
*/
void NotebookWindow::createFileMenu()
{
// NEW
newAction = new QAction( tr("&New"), this );
newAction->setShortcut( QKeySequence("Ctrl+N") );
newAction->setStatusTip( tr("Create a new document") );
connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
newAction->setIcon(QIcon(":/Resources/toolbarIcons/filenew.png"));
toolBar->addAction(newAction);
recentMenu = new QMenu(tr("Recent &Files"), this);
// OPEN FILE
openFileAction = new QAction( tr("&Open"), this );
openFileAction->setShortcut( QKeySequence("Ctrl+O") );
openFileAction->setStatusTip( tr("Open a file") );
connect(openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
openFileAction->setIcon(QIcon(":/Resources/toolbarIcons/fileopen.png"));
QToolButton *b = new QToolButton(this);
b->setDefaultAction(openFileAction);
b->setMenu(recentMenu);
b->setPopupMode(QToolButton::MenuButtonPopup);
// toolBar->addAction(openFileAction);
toolBar->addWidget(b);
// SAVE AS
saveAsAction = new QAction( tr("Save &As..."), this );
saveAsAction->setShortcut( QKeySequence("Ctrl+Shift+S") );
saveAsAction->setStatusTip( tr("Save the document as a new file") );
connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveas()));
// SAVE
saveAction = new QAction( tr("&Save"), this );
saveAction->setShortcut( QKeySequence("Ctrl+S") );
saveAction->setStatusTip( tr("Save the document") );
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
saveAction->setIcon(QIcon(":/Resources/toolbarIcons/filesave.png"));
toolBar->addAction(saveAction);
toolBar->addSeparator();
// CLOSE FILE
closeFileAction = new QAction( tr("&Close"), this );
closeFileAction->setShortcut( QKeySequence("Ctrl+W") );
closeFileAction->setStatusTip( tr("Close the window") );
connect(closeFileAction, SIGNAL(triggered()), this, SLOT(closeFile()));
// PRINT
printAction = new QAction( tr("&Print"), this );
printAction->setShortcut( QKeySequence("Ctrl+P") );
printAction->setStatusTip( tr("Print the document") );
connect(printAction, SIGNAL(triggered()), this, SLOT(print()));
printAction->setIcon(QIcon(":/Resources/toolbarIcons/fileprint.png"));
toolBar->addAction(printAction);
toolBar->addSeparator();
// QUIT WINDOW
quitWindowAction = new QAction( tr("&Quit"), this );
quitWindowAction->setShortcut( QKeySequence("Ctrl+Q") );
quitWindowAction->setStatusTip( tr("Quit OMNotebook") );
quitWindowAction->setMenuRole(QAction::QuitRole);
quitWindowAction->setIcon(QIcon(":/Resources/toolbarIcons/exit.png"));
connect(quitWindowAction, SIGNAL(triggered()), this, SLOT(quitOMNotebook()));
// CREATE MENU
fileMenu = menuBar()->addMenu( tr("&File") );
fileMenu->addAction( newAction );
fileMenu->addAction( openFileAction );
fileMenu->addAction( saveAction );
fileMenu->addAction( saveAsAction );
fileMenu->addAction( closeFileAction );
fileMenu->addSeparator();
fileMenu->addAction( printAction );
fileMenu->addSeparator();
// RECENT FILES
// recentMenu = fileMenu->addMenu("Recent &Files");
fileMenu->addMenu(recentMenu);
QSettings s(QSettings::IniFormat, QSettings::UserScope, "openmodelica", "omnotebook");
QString recentFile;
for(int i = 0; i < 8; ++i)
{
if((recentFile = s.value(QString("Recent")+QString(i), QString()).toString()) != QString())
{
QAction* tmpAction = recentMenu->addAction(recentFile);
connect(tmpAction, SIGNAL(triggered()), this, SLOT(recentTriggered()));
}
}
fileMenu->addSeparator();
importMenu = fileMenu->addMenu( tr("&Import") );
exportMenu = fileMenu->addMenu( tr("E&xport") );
fileMenu->addSeparator();
fileMenu->addAction( quitWindowAction );
// IMPORT MENU
// Added 2005-12-01
importOldFile = new QAction( tr("&Old OMNotebook file"), this );
importOldFile->setStatusTip( tr("Import an old OMNotebook file") );
connect( importOldFile, SIGNAL( triggered() ),
this, SLOT( openOldFile() ));
importMenu->addAction( importOldFile );
// EXPORT MENU
// Added 2005-11-21
exportPureText = new QAction( tr("&Pure text"), this );
exportPureText->setStatusTip( tr("Export the document content to pure text") );
connect( exportPureText, SIGNAL( triggered() ),
this, SLOT( pureText() ));
exportMenu->addAction( exportPureText );
// PDF
pdfAction = new QAction( tr("P&DF"), this );
pdfAction->setStatusTip( tr("Export the document to PDF") );
connect(pdfAction, SIGNAL(triggered()), this, SLOT(pdf()));
exportMenu->addAction(pdfAction);
}
/*!
* \author Anders Fernström
* \date 2006-08-24 (update)
*
* \brief Method for creating edit nemu.
*
* 2005-10-07 AF, Remade the function when porting to QT4.
* 2006-02-03 AF, Made undo, redo, cut, copy and paste actions for the editor
* 2006-08-24 AF, added a replace action, renamed search action to find action
*/
void NotebookWindow::createEditMenu()
{
undoAction = new QAction( tr("&Undo"), this);
undoAction->setShortcut( QKeySequence("Ctrl+Z") );
undoAction->setStatusTip( tr("Undo last action") );
connect( undoAction, SIGNAL( triggered() ),
this, SLOT( undoEdit() ));
undoAction->setEnabled(false);
undoAction->setIcon(QIcon(":/Resources/toolbarIcons/undo.png"));
toolBar->addAction(undoAction);
redoAction = new QAction( tr("&Redo"), this);
redoAction->setShortcut( QKeySequence("Ctrl+Y") );
redoAction->setStatusTip( tr("Redo last action") );
connect( redoAction, SIGNAL( triggered() ),
this, SLOT( redoEdit() ));
redoAction->setEnabled(false);
redoAction->setIcon(QIcon(":/Resources/toolbarIcons/redo.png"));
toolBar->addAction(redoAction);
toolBar->addSeparator();
// CUT
cutAction = new QAction( tr("Cu&t"), this);
cutAction->setShortcut( QKeySequence("Ctrl+X") );
cutAction->setStatusTip( tr("Cut selected text") );
connect( cutAction, SIGNAL( triggered() ),
this, SLOT( cutEdit() ));
cutAction->setEnabled(false);
cutAction->setIcon(QIcon(":/Resources/toolbarIcons/editcut.png"));
toolBar->addAction(cutAction);
// COPY
copyAction = new QAction( tr("&Copy"), this);
copyAction->setShortcut( QKeySequence("Ctrl+C") );
copyAction->setStatusTip( tr("Copy selected text") );
connect( copyAction, SIGNAL( triggered() ),
this, SLOT( copyEdit() ));
copyAction->setEnabled(false);
copyAction->setIcon(QIcon(":/Resources/toolbarIcons/editcopy.png"));
toolBar->addAction(copyAction);
// PASTE
pasteAction = new QAction( tr("&Paste"), this);
pasteAction->setShortcut( QKeySequence("Ctrl+V") );
pasteAction->setStatusTip( tr("Paste text from clipboard") );
connect( pasteAction, SIGNAL( triggered() ),
this, SLOT( pasteEdit() ));
pasteAction->setIcon(QIcon(":/Resources/toolbarIcons/editpaste.png"));
toolBar->addAction(pasteAction);
toolBar->addSeparator();
// FIND
findAction = new QAction( tr("&Find"), this);
findAction->setShortcut( QKeySequence("Ctrl+F") );
findAction->setStatusTip( tr("Search through the document") );
connect( findAction, SIGNAL( triggered() ),
this, SLOT( findEdit() ));
findAction->setIcon(QIcon(":/Resources/toolbarIcons/find.png"));
toolBar->addAction(findAction);
toolBar->addSeparator();
// REPLACE, added 2006-08-24 AF
replaceAction = new QAction( tr("Re&place"), this);
replaceAction->setShortcut( QKeySequence("Ctrl+H") );
replaceAction->setStatusTip( tr("Search through the document and replace") );
connect( replaceAction, SIGNAL( triggered() ),
this, SLOT( replaceEdit() ));
showExprAction = new QAction( tr("&View Raw Text"), this);
showExprAction->setStatusTip( tr("View the raw text in the cell") );
showExprAction->setCheckable(true);
showExprAction->setChecked(false);
connect(showExprAction, SIGNAL(toggled(bool)), subject_, SLOT(showHTML(bool)));
//Edit Sketch image,and view the attributes added by jhansi
editSketchImage = new QAction( tr("&EditSketchImage"), this );
editSketchImage->setShortcut( QKeySequence("Ctrl+E") );
editSketchImage->setStatusTip( tr("Sketch Image Edit") );
connect( editSketchImage, SIGNAL( triggered() ),
this, SLOT( sketchImageEdit() ));
editSketchImage->setIcon(QIcon(":/Resources/toolbarIcons/editimage.png"));
toolBar->addAction(editSketchImage);
toolBar->addSeparator();
editMenu = menuBar()->addMenu( tr("&Edit") );
editMenu->addAction( undoAction );
editMenu->addAction( redoAction );
editMenu->addSeparator();
editMenu->addAction( cutAction );
editMenu->addAction( copyAction );
editMenu->addAction( pasteAction );
editMenu->addSeparator();
editMenu->addAction( findAction );
editMenu->addAction( replaceAction );
editMenu->addSeparator();
editMenu->addAction( showExprAction );
editMenu->addAction(editSketchImage);
}
/*!
* \author Anders Fernström
* \date 2006-04-27 (update)
*
* \brief Method for creating cell nemu.
*
* 2006-04-26 AF, Added UNGROUP and SPLIT CELL
* 2006-04-27 AF, remove cut,copy,paste cell from menu
*/
void NotebookWindow::createCellMenu()
{
addCellAction = new QAction( tr("&Add Cell (previous cell style)"), this);
addCellAction->setShortcut( QKeySequence("Alt+Enter") );
addCellAction->setStatusTip( tr("Add a new textcell with the previuos cells style") );
connect(addCellAction, SIGNAL(triggered()), this, SLOT(createNewCell()));
inputAction = new QAction( tr("Add &Inputcell"), this);
inputAction->setShortcut( QKeySequence("Ctrl+Shift+I") );
inputAction->setStatusTip( tr("Add an input cell") );
connect(inputAction, SIGNAL(triggered()), this, SLOT(inputCellsAction()));
latexAction = new QAction( tr("Add &Latexcell"), this);
latexAction->setShortcut( QKeySequence("Ctrl+Shift+E") );
latexAction->setStatusTip( tr("Add Latex cell") );
connect(latexAction, SIGNAL(triggered()), this, SLOT(latexCellsAction()));
/// fjass
textAction = new QAction( tr("Add &Textcell"), this);
textAction->setShortcut( QKeySequence("Ctrl+Shift+T") );
textAction->setStatusTip( tr("Add a text cell") );
connect(textAction, SIGNAL(triggered()), this, SLOT(textCellsAction()));
// \fjass
groupAction = new QAction( tr("&Groupcell"), this);
groupAction->setShortcut( QKeySequence("Ctrl+Shift+G") );
groupAction->setStatusTip( tr("Groupcell") );
connect( groupAction, SIGNAL( triggered() ),
this, SLOT( groupCellsAction() ));
// 2006-04-26 AF, UNGROUP
ungroupCellAction = new QAction( tr("&Ungroup groupcell"), this);
ungroupCellAction->setShortcut( QKeySequence("Ctrl+Shift+U") );
ungroupCellAction->setStatusTip( tr("Ungroup the selected groupcell in the tree view") );
connect( ungroupCellAction, SIGNAL( triggered() ),
this, SLOT( ungroupCell() ));
// 2006-04-26 AF, SPLIT CELL
splitCellAction = new QAction( tr("&Split cell"), this);
splitCellAction->setShortcut( QKeySequence("Ctrl+Shift+P") );
splitCellAction->setStatusTip( tr("Split selected cell") );
connect( splitCellAction, SIGNAL( triggered() ),
this, SLOT( splitCell() ));
deleteCellAction = new QAction( tr("&Delete Cell"), this);
deleteCellAction->setShortcut( QKeySequence("Ctrl+Shift+D") );
deleteCellAction->setStatusTip( tr("Delete selected cell") );
connect(deleteCellAction, SIGNAL(triggered()), this, SLOT(deleteCurrentCell()));
nextCellAction = new QAction( tr("&Next Cell"), this);
nextCellAction->setStatusTip( tr("Move to next cell") );
nextCellAction->setShortcut( QKeySequence("Alt+Down") );
connect(nextCellAction, SIGNAL(triggered()), this, SLOT(moveCursorDown()));
previousCellAction = new QAction( tr("P&revious Cell"), this);
previousCellAction->setShortcut( QKeySequence("Alt+Up") );
previousCellAction->setStatusTip( tr("Move to previous cell") );
connect(previousCellAction, SIGNAL(triggered()), this, SLOT(moveCursorUp()));
// 2006-04-27 AF, remove cut,copy,paste cell from menu
cellMenu = menuBar()->addMenu( tr("&Cell") );
//cellMenu->addAction( cutCellAction );
//cellMenu->addAction( copyCellAction );
//cellMenu->addAction( pasteCellAction );
//cellMenu->addSeparator();
cellMenu->addAction( addCellAction );
cellMenu->addAction( inputAction );
cellMenu->addAction(latexAction);
cellMenu->addAction( textAction );
cellMenu->addAction( groupAction );
cellMenu->addAction( ungroupCellAction );
cellMenu->addAction( splitCellAction );
cellMenu->addAction( deleteCellAction );
cellMenu->addSeparator();
cellMenu->addAction( nextCellAction );
cellMenu->addAction( previousCellAction );
QObject::connect(cellMenu, SIGNAL(aboutToShow()),
this, SLOT(updateCellMenu()));
}
/*!
* \author Anders Fernström
* \date 2005-10-07
* \date 2005-11-03 (update)
*
* \brief Method for creating format nemu.
*
* 2005-11-03 AF, Updated this function with functionality for
* changes text settings.
*/
void NotebookWindow::createFormatMenu()
{
// 2005-10-03 AF, get the stylesheet instance
Stylesheet *sheet = Stylesheet::instance("stylesheet.xml");
// Create the style actions //AF
stylesgroup = new QActionGroup( this );
formatMenu = menuBar()->addMenu( tr("&Format") );
styleMenu = formatMenu->addMenu( tr("&Styles") );
vector<QString> styles = sheet->getAvailableStyleNames();
vector<QString>::iterator i = styles.begin();
for(;i != styles.end(); ++i)
{
if ((*i != "Latex") && (*i != "Graph") && (*i != "Input"))
{
QAction *tmp = new QAction( tr( (*i).toStdString().c_str() ), this );
tmp->setCheckable( true );
styleMenu->addAction( tmp );
stylesgroup->addAction( tmp );
styles_[(*i)] = tmp;
}
}
connect( styleMenu, SIGNAL(triggered(QAction*)), this, SLOT(changeStyle(QAction*)));
// FONT
// -----------------------------------------------------
// Code for creating the font menu
formatMenu->addSeparator();
fontsgroup = new QActionGroup( this );
fontMenu = formatMenu->addMenu( tr("&Font") );
QFontDatabase fontDatabase;
QStringList fonts = fontDatabase.families( QFontDatabase::Latin );
for( int index = 0; index < fonts.count(); ++index )
{
QAction *tmp = new QAction( fonts[index], this );
tmp->setCheckable( true );
fontMenu->addAction( tmp );
fontsgroup->addAction( tmp );
fonts_.insert( fonts[index], tmp );
}
connect( fontMenu, SIGNAL( triggered(QAction*) ),
this, SLOT( changeFont(QAction*) ));
connect( fontMenu, SIGNAL( aboutToShow() ),
this, SLOT( updateFontMenu() ));
// -----------------------------------------------------
// END: FONT
// FACE
// -----------------------------------------------------
// Code for creating the face menu
faceMenu = formatMenu->addMenu( tr("Fa&ce") );
facePlain = new QAction( tr("&Plain"), this);
facePlain->setWhatsThis("Plain");
facePlain->setCheckable( false );
facePlain->setStatusTip( tr("Set font face to Plain") );
faceBold = new QAction( tr("&Bold"), this);
faceBold->setWhatsThis("Bold");
faceBold->setShortcut( QKeySequence("Ctrl+B") );
faceBold->setCheckable( true );
faceBold->setStatusTip( tr("Set font face to Bold") );
faceItalic = new QAction( tr("&Italic"), this);
faceItalic->setWhatsThis("Italic");
faceItalic->setShortcut( QKeySequence("Ctrl+I") );
faceItalic->setCheckable( true );
faceItalic->setStatusTip( tr("Set font face to Italic") );
faceUnderline = new QAction( tr("&Underline"), this);
faceUnderline->setWhatsThis("Underline");
faceUnderline->setShortcut( QKeySequence("Ctrl+U") );
faceUnderline->setCheckable( true );
faceUnderline->setStatusTip( tr("Set font face to Underline") );
connect( faceMenu, SIGNAL( aboutToShow() ),
this, SLOT( updateFontFaceMenu() ));
connect( faceMenu, SIGNAL( triggered(QAction*) ),
this, SLOT( changeFontFace(QAction*) ));
faceMenu->addAction( facePlain );
faceMenu->addAction( faceBold );
faceMenu->addAction( faceItalic );
faceMenu->addAction( faceUnderline );
// -----------------------------------------------------
// END: FONT
// SIZE
// -----------------------------------------------------
// Code for creating the size menu
sizeMenu = formatMenu->addMenu( tr("Si&ze") );
sizesgroup = new QActionGroup( this );
sizeSmaller = new QAction( tr("&Smaller"), this);
sizeSmaller->setWhatsThis("Smaller");
sizeSmaller->setShortcut( QKeySequence("Ctrl+-") );
sizeSmaller->setCheckable( false );
sizeSmaller->setStatusTip( tr("Set font size smaller") );
sizeLarger = new QAction( tr("&Larger"), this);
sizeLarger->setWhatsThis("Larger");
sizeLarger->setShortcut( QKeySequence("Ctrl++") );
sizeLarger->setCheckable( false );
sizeLarger->setStatusTip( tr("Set font size larger") );
size8pt = new QAction( "8", this);
size8pt->setCheckable( true );
sizes_.insert( "8", size8pt );
sizesgroup->addAction( size8pt );
size9pt = new QAction( "9", this);
size9pt->setCheckable( true );
sizes_.insert( "9", size9pt );
sizesgroup->addAction( size9pt );
size10pt = new QAction( "10", this);
size10pt->setCheckable( true );
sizes_.insert( "10", size10pt );
sizesgroup->addAction( size10pt );
size12pt = new QAction( "12", this);
size12pt->setCheckable( true );
sizes_.insert( "12", size12pt );
sizesgroup->addAction( size12pt );
size14pt = new QAction( "14", this);
size14pt->setCheckable( true );
sizes_.insert( "14", size14pt );
sizesgroup->addAction( size14pt );
size16pt = new QAction( "16", this);
size16pt->setCheckable( true );
sizes_.insert( "16", size16pt );
sizesgroup->addAction( size16pt );
size18pt = new QAction( "18", this);
size18pt->setCheckable( true );
sizes_.insert( "18", size18pt );
sizesgroup->addAction( size18pt );
size20pt = new QAction( "20", this);
size20pt->setCheckable( true );
sizes_.insert( "20", size20pt );
sizesgroup->addAction( size20pt );
size24pt = new QAction( "24", this);
size24pt->setCheckable( true );
sizes_.insert( "24", size24pt );
sizesgroup->addAction( size24pt );
size36pt = new QAction( "36", this);
size36pt->setCheckable( true );
sizes_.insert( "36", size36pt );
sizesgroup->addAction( size36pt );
size72pt = new QAction( "72", this);
size72pt->setCheckable( true );
sizes_.insert( "72", size72pt );
sizesgroup->addAction( size72pt );
sizeOther = new QAction( tr("&Other..."), this);
sizeOther->setWhatsThis("Other");
sizeOther->setCheckable( true );
sizeOther->setStatusTip( tr("Select font size") );
connect( sizeMenu, SIGNAL( aboutToShow() ),
this, SLOT( updateFontSizeMenu() ));
connect( sizeMenu, SIGNAL( triggered(QAction*) ),
this, SLOT( changeFontSize(QAction*) ));
sizeMenu->addAction( sizeSmaller );
sizeMenu->addAction( sizeLarger );
sizeMenu->addSeparator();
sizeMenu->addAction( size8pt );
sizeMenu->addAction( size9pt );
sizeMenu->addAction( size10pt );
sizeMenu->addAction( size12pt );
sizeMenu->addAction( size14pt );
sizeMenu->addAction( size16pt );
sizeMenu->addAction( size18pt );
sizeMenu->addAction( size20pt );
sizeMenu->addAction( size24pt );
sizeMenu->addAction( size36pt );
sizeMenu->addAction( size72pt );
sizeMenu->addSeparator();
sizeMenu->addAction( sizeOther );
// -----------------------------------------------------
// END: Size
// STRETCH
// -----------------------------------------------------