-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlpub.cpp
More file actions
executable file
·977 lines (804 loc) · 28.8 KB
/
lpub.cpp
File metadata and controls
executable file
·977 lines (804 loc) · 28.8 KB
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
/****************************************************************************
**
** Copyright (C) 2007-2009 Kevin Clague. All rights reserved.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <QSizePolicy>
#include <QFileDialog>
#include <QComboBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QCloseEvent>
#include <QUndoStack>
#include <QTextStream>
#include "lpub.h"
#include "editwindow.h"
#include "name.h"
#include "paths.h"
#include "globals.h"
#include "resolution.h"
#include "lpub_preferences.h"
#include "render.h"
#include "metaitem.h"
Gui *gui;
void clearPliCache()
{
gui->clearPLICache();
}
void clearCsiCache()
{
gui->clearCSICache();
}
/****************************************************************************
*
* The Gui constructor and destructor are at the bottom of the file with
* the code that creates the basic GUI framekwork
*
***************************************************************************/
void Gui::insertCoverPage()
{
MetaItem mi;
mi.insertCoverPage();
}
void Gui::appendCoverPage()
{
MetaItem mi;
mi.appendCoverPage();
countPages();
++displayPageNum;
displayPage(); // display the page we just added
}
void Gui::insertNumberedPage()
{
MetaItem mi;
mi.insertNumberedPage();
}
void Gui::appendNumberedPage()
{
MetaItem mi;
mi.appendNumberedPage();
//countPages();
//++displayPageNum;
//displayPage(); // display the page we just added
}
void Gui::deletePage()
{
MetaItem mi;
mi.deletePage();
}
void Gui::addPicture()
{
MetaItem mi;
mi.insertPicture();
}
void Gui::addText()
{
MetaItem mi;
mi.insertText();
}
void Gui::addBom()
{
MetaItem mi;
mi.insertBOM();
}
void Gui::removeLPubFormatting()
{
MetaItem mi;
mi.removeLPubFormatting();
displayPageNum = 1;
displayPage();
}
void Gui::displayPage()
{
if (macroNesting == 0) {
clearPage(KpageView,KpageScene);
page.coverPage = false;
drawPage(KpageView,KpageScene,false);
enableActions2();
}
}
void Gui::nextPage()
{
countPages();
if (displayPageNum < maxPages) {
++displayPageNum;
displayPage();
} else {
statusBarMsg("You're on the last page");
}
}
void Gui::prevPage()
{
if (displayPageNum > 1) {
displayPageNum--;
displayPage();
}
}
void Gui::firstPage()
{
displayPageNum = 1;
displayPage();
}
void Gui::clearAndRedrawPage()
{
clearCSICache();
clearPLICache();
displayPage();
}
void Gui::lastPage()
{
countPages();
displayPageNum = maxPages;
displayPage();
}
void Gui::setPage()
{
QString string = setPageLineEdit->displayText();
QRegExp rx("^(\\d+)\\s+.*$");
if (string.contains(rx)) {
bool ok;
int inputPage;
inputPage = rx.cap(1).toInt(&ok);
if (ok) {
countPages();
if (inputPage <= maxPages) {
if (inputPage != displayPageNum) {
displayPageNum = inputPage;
displayPage();
return;
}
}
}
}
string = QString("%1 of %2") .arg(displayPageNum) .arg(maxPages);
setPageLineEdit->setText(string);
}
void Gui::fitWidth()
{
fitWidth(pageview());
}
void Gui::fitWidth(
LGraphicsView *view)
{
view->scale(1.0,1.0);
QRectF rect(0,0,page.meta.LPub.page.size.valuePixels(0),page.meta.LPub.page.size.valuePixels(1));
QRectF unity = view->matrix().mapRect(QRectF(0,0,1,1));
view->scale(1/unity.width(), 1 / unity.height());
int margin = 2;
QRectF viewRect = view->viewport()->rect().adjusted(margin, margin, -margin, -margin);
QRectF sceneRect = view->matrix().mapRect(rect);
qreal xratio = viewRect.width() / sceneRect.width();
view->scale(xratio,xratio);
view->centerOn(rect.center());
fitMode = FitWidth;
}
void Gui::fitVisible()
{
fitVisible(pageview());
}
void Gui::fitVisible(
LGraphicsView *view)
{
view->scale(1.0,1.0);
QRectF rect(0,0,page.meta.LPub.page.size.valuePixels(0),page.meta.LPub.page.size.valuePixels(1));
QRectF unity = view->matrix().mapRect(QRectF(0,0,1,1));
view->scale(1/unity.width(), 1 / unity.height());
int margin = 2;
QRectF viewRect = view->viewport()->rect().adjusted(margin, margin, -margin, -margin);
QRectF sceneRect = view->matrix().mapRect(rect);
qreal xratio = viewRect.width() / sceneRect.width();
qreal yratio = viewRect.height() / sceneRect.height();
xratio = yratio = qMin(xratio,yratio);
view->scale(xratio,yratio);
view->centerOn(rect.center());
fitMode = FitVisible;
}
void Gui::actualSize()
{
actualSize(pageview());
}
void Gui::actualSize(
LGraphicsView *view)
{
view->resetMatrix();
fitMode = FitNone;
}
void Gui::zoomIn()
{
zoomIn(pageview());
}
void Gui::zoomIn(
LGraphicsView *view)
{
fitMode = FitNone;
view->scale(1.1,1.1);
}
void Gui::zoomOut()
{
zoomOut(pageview());
}
void Gui::zoomOut(
LGraphicsView *view)
{
fitMode = FitNone;
view->scale(1.0/1.1,1.0/1.1);
}
void Gui::statusBarMsg(QString msg)
{
statusBar()->showMessage(msg);
}
void Gui::displayFile(
LDrawFile *ldrawFile,
const QString &modelName)
{
// if (force || modelName != curSubFile) {
for (int i = 0; i < mpdCombo->count(); i++) {
if (mpdCombo->itemText(i) == modelName) {
mpdCombo->setCurrentIndex(i);
break;
}
}
curSubFile = modelName;
displayFileSig(ldrawFile, modelName);
// }
}
/*-----------------------------------------------------------------------------*/
void Gui::mpdComboChanged(int index)
{
index = index;
QString newSubFile = mpdCombo->currentText();
if (curSubFile != newSubFile) {
curSubFile = newSubFile;
displayFileSig(&ldrawFile, curSubFile);
}
}
void Gui::clearPLICache()
{
QString dirName = QDir::currentPath() + "/" + Paths::partsDir;
QDir dir(dirName);
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); i++) {
QFileInfo fileInfo = list.at(i);
QFile file(dirName + "/" + fileInfo.fileName());
file.remove();
}
}
void Gui::clearCSICache()
{
QString dirName = QDir::currentPath() + "/" + Paths::assemDir;
QDir dir(dirName);
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); i++) {
QFileInfo fileInfo = list.at(i);
QFile file(dirName + "/" + fileInfo.fileName());
file.remove();
}
}
/***************************************************************************
* These are infrequently used functions for basic environment
* configuration stuff
**************************************************************************/
void Gui::pageSetup()
{
GlobalPageDialog::getPageGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::assemSetup()
{
GlobalAssemDialog::getAssemGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::pliSetup()
{
GlobalPliDialog::getPliGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::bomSetup()
{
GlobalPliDialog::getBomGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::calloutSetup()
{
GlobalCalloutDialog::getCalloutGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::multiStepSetup()
{
GlobalMultiStepDialog::getMultiStepGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::projectSetup()
{
GlobalProjectDialog::getProjectGlobals(ldrawFile.topLevelFile(),page.meta);
}
void Gui::preferences()
{
if (Preferences::getPreferences()) {
Meta meta;
page.meta = meta;
QString renderer = Render::getRenderer();
Render::setRenderer(Preferences::preferredRenderer);
if (Render::getRenderer() != renderer) {
gui->clearCSICache();
gui->clearPLICache();
}
displayPage();
}
}
/*******************************************************************************
*
* This is all the initialization stuff. It is used once when the program
* starts up
*
******************************************************************************/
Gui::Gui()
{
Preferences::lpubPreferences();
Preferences::renderPreferences();
Preferences::lgeoPreferences();
Preferences::pliPreferences();
displayPageNum = 1;
editWindow = new EditWindow();
KpageScene = new QGraphicsScene(this);
KpageScene->setBackgroundBrush(Qt::lightGray);
KpageView = new LGraphicsView(KpageScene);
KpageView->pageBackgroundItem = NULL;
KpageView->setRenderHints(QPainter::Antialiasing |
QPainter::TextAntialiasing |
QPainter::SmoothPixmapTransform);
setCentralWidget(KpageView);
mpdCombo = new QComboBox;
mpdCombo->setEditable(false);
mpdCombo->setMinimumContentsLength(20);
mpdCombo->setInsertPolicy(QComboBox::InsertAtBottom);
mpdCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
connect(mpdCombo,SIGNAL(activated(int)),
this, SLOT(mpdComboChanged(int)));
createActions();
createMenus();
createToolBars();
createStatusBar();
createDockWindows();
readSettings();
undoStack = new QUndoStack();
macroNesting = 0;
connect(this, SIGNAL(displayFileSig(LDrawFile *, const QString &)),
editWindow, SLOT( displayFile (LDrawFile *, const QString &)));
connect(this, SIGNAL(showLineSig(int)),
editWindow, SLOT( showLine( int)));
connect(editWindow, SIGNAL(contentsChange(const QString &,int,int,const QString &)),
this, SLOT( contentsChange(const QString &,int,int,const QString &)));
connect(editWindow, SIGNAL(redrawSig()),
this, SLOT( clearAndRedrawPage()));
connect(undoStack, SIGNAL(canRedoChanged(bool)),
this, SLOT( canRedoChanged(bool)));
connect(undoStack, SIGNAL(canUndoChanged(bool)),
this, SLOT( canUndoChanged(bool)));
connect(undoStack, SIGNAL(cleanChanged(bool)),
this, SLOT( cleanChanged(bool)));
#ifdef WATCHER
connect(&watcher, SIGNAL(fileChanged(const QString &)),
this, SLOT( fileChanged(const QString &)));
#endif
setCurrentFile("");
// Jaco: This sets the initial size of the main window
resize(800,600);
gui = this;
fitMode = FitVisible;
#ifdef __APPLE__
extern void qt_mac_set_native_menubar(bool);
qt_mac_set_native_menubar(true);
#endif
Preferences::getRequireds();
Render::setRenderer(Preferences::preferredRenderer);
}
Gui::~Gui()
{
delete KpageScene;
delete KpageView;
delete editWindow;
}
void Gui::closeEvent(QCloseEvent *event)
{
writeSettings();
if (maybeSave()) {
event->accept();
} else {
event->ignore();
}
}
void Gui::about()
{
QMessageBox::about(this, tr("About LPub"),
tr("<b>LPub 4.0.0.14</b> is a proud member of the LDraw "
"family of tools. LPub is a WYSIWYG tool for creating "
"LEGO(c) style building instructions. "
"LPub4 source code and application can be found on "
"www.sourceforge.net/projects/lpub4/files.<br>"
"Copyright 2000-2011 Kevin Clague "
"kevin.clague@gmail.com<br>"
"2014 - Daniele Benedettelli"));
}
// Begin Jaco's code
// Danny: web url changed, as it pointed nowhere
#include <QDesktopServices>
#include <QUrl>
void Gui::onlineManual()
{
QDesktopServices::openUrl(QUrl("http://sites.google.com/site/workingwithlpub/"));
}
// End Jaco's code
void Gui::meta()
{
Meta meta;
QStringList doc;
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Metacommands Save File Name"),
QDir::currentPath() + "/metacommands.txt",
tr("txt (*.txt)"));
if (fileName == "") {
return;
}
meta.doc(doc);
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(NULL,
QMessageBox::tr(LPUB),
QMessageBox::tr("Cannot write file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return;
}
QTextStream out(&file);
for (int i = 0; i < doc.size(); i++) {
out << doc[i] << endl;
}
file.close();
}
void Gui::createActions()
{
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openAct->setShortcut(tr("Ctrl+O"));
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
saveAct->setShortcut(tr("Ctrl+S"));
saveAct->setStatusTip(tr("Save the document to disk"));
saveAct->setEnabled(false);
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
saveAsAct = new QAction(tr("Save &As..."), this);
saveAsAct->setStatusTip(tr("Save the document under a new name"));
saveAsAct->setEnabled(false);
connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
printToFileAct = new QAction(QIcon(":/images/pdf_logo.png"), tr("Print to &File"), this);
printToFileAct->setShortcut(tr("Ctrl+F"));
printToFileAct->setStatusTip(tr("Print your document to a file"));
printToFileAct->setEnabled(false);
connect(printToFileAct, SIGNAL(triggered()), this, SLOT(printToFile()));
exportPngAct = new QAction(tr("Export As &PNG Images"), this);
exportPngAct->setShortcut(tr("Ctrl+Shift+P"));
exportPngAct->setStatusTip(tr("Export your document as a sequence of PNG images"));
exportPngAct->setEnabled(false);
connect(exportPngAct, SIGNAL(triggered()), this, SLOT(exportAsPng()));
exportJpgAct = new QAction(tr("Export As &JPEG Images"), this);
exportJpgAct->setShortcut(tr("Ctrl+J"));
exportJpgAct->setStatusTip(tr("Export your document as a sequence of JPEG images"));
exportJpgAct->setEnabled(false);
connect(exportJpgAct, SIGNAL(triggered()), this, SLOT(exportAsJpg()));
exportBmpAct = new QAction(tr("Export As &Bitmap Images"), this);
exportBmpAct->setShortcut(tr("Ctrl+B"));
exportBmpAct->setStatusTip(tr("Export your document as a sequence of bitmap images"));
exportBmpAct->setEnabled(false);
connect(exportBmpAct, SIGNAL(triggered()), this, SLOT(exportAsBmp()));
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcut(tr("Ctrl+Q"));
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
for (int i = 0; i < MaxRecentFiles; i++) {
recentFilesActs[i] = new QAction(this);
recentFilesActs[i]->setVisible(false);
connect(recentFilesActs[i], SIGNAL(triggered()), this,
SLOT(openRecentFile()));
}
// undo/redo
undoAct = new QAction(QIcon(":/images/editundo.png"), tr("Undo"), this);
undoAct->setShortcut(tr("Ctrl+Z"));
undoAct->setStatusTip(tr("Undo last change"));
connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));
redoAct = new QAction(QIcon(":/images/editredo.png"), tr("Redo"), this);
#ifdef __APPLE__
redoAct->setShortcut(tr("Ctrl+Shift+Z"));
#else
redoAct->setShortcut(tr("Ctrl+Y"));
#endif
redoAct->setStatusTip(tr("Redo last change"));
connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));
insertCoverPageAct = new QAction(tr("Insert Cover Page"),this);
insertCoverPageAct->setStatusTip(tr("Insert an unnumbered page"));
insertCoverPageAct->setEnabled(false);
connect(insertCoverPageAct, SIGNAL(triggered()), this, SLOT(insertCoverPage()));
appendCoverPageAct = new QAction(tr("Append Cover Page"),this);
appendCoverPageAct->setStatusTip(tr("Append a numbered page"));
appendCoverPageAct->setEnabled(false);
connect(appendCoverPageAct, SIGNAL(triggered()), this, SLOT(appendCoverPage()));
insertNumberedPageAct = new QAction(tr("Insert Page"),this);
insertNumberedPageAct->setStatusTip(tr("Insert a numbered page"));
insertNumberedPageAct->setEnabled(false);
connect(insertNumberedPageAct, SIGNAL(triggered()), this, SLOT(insertNumberedPage()));
appendNumberedPageAct = new QAction(tr("Append Page"),this);
appendNumberedPageAct->setStatusTip(tr("Append a numbered page"));
appendNumberedPageAct->setEnabled(false);
connect(appendNumberedPageAct, SIGNAL(triggered()), this, SLOT(appendNumberedPage()));
deletePageAct = new QAction(tr("Delete Page"),this);
deletePageAct->setStatusTip(tr("Delete this page"));
deletePageAct->setEnabled(false);
connect(deletePageAct, SIGNAL(triggered()), this, SLOT(deletePage()));
addPictureAct = new QAction(tr("Add Picture"),this);
addPictureAct->setStatusTip(tr("Add a picture to this page"));
addPictureAct->setEnabled(false);
connect(addPictureAct, SIGNAL(triggered()), this, SLOT(addPicture()));
addTextAct = new QAction(tr("Add Text"),this);
addTextAct->setStatusTip(tr("Add text to this page"));
addTextAct->setEnabled(false);
connect(addTextAct, SIGNAL(triggered()), this, SLOT(addText()));
addBomAct = new QAction(tr("Add Bill of Materials"),this);
addBomAct->setStatusTip(tr("Add Bill of Materials to this page"));
addBomAct->setEnabled(false);
connect(addBomAct, SIGNAL(triggered()), this, SLOT(addBom()));
removeLPubFormattingAct = new QAction(tr("Remove LPub Formatting"),this);
removeLPubFormattingAct->setStatusTip(tr("Remove all LPub metacommands from all files"));
removeLPubFormattingAct->setEnabled(false);
connect(removeLPubFormattingAct, SIGNAL(triggered()), this, SLOT(removeLPubFormatting()));
// fitWidth,fitVisible,actualSize
fitWidthAct = new QAction(QIcon(":/images/fitWidth.png"), tr("Fit Width"), this);
fitWidthAct->setShortcut(tr("Ctrl+W"));
fitWidthAct->setStatusTip(tr("Fit document to width"));
connect(fitWidthAct, SIGNAL(triggered()), this, SLOT(fitWidth()));
fitVisibleAct = new QAction(QIcon(":/images/fitVisible.png"), tr("Fit Visible"), this);
fitVisibleAct->setShortcut(tr("Ctrl+I"));
fitVisibleAct->setStatusTip(tr("Fit document so whole page is visible"));
connect(fitVisibleAct, SIGNAL(triggered()), this, SLOT(fitVisible()));
actualSizeAct = new QAction(QIcon(":/images/actual.png"),tr("Actual Size"), this);
actualSizeAct->setShortcut(tr("Ctrl+A"));
actualSizeAct->setStatusTip(tr("Show document actual size"));
connect(actualSizeAct, SIGNAL(triggered()), this, SLOT(actualSize()));
// zoomIn,zoomOut
zoomInAct = new QAction(QIcon(":/images/zoomin.png"), tr("&Zoom In"), this);
zoomInAct->setShortcut(tr("Ctrl++"));
zoomInAct->setStatusTip(tr("Zoom in"));
connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
zoomOutAct = new QAction(QIcon(":/images/zoomout.png"),tr("Zoom &Out"),this);
zoomOutAct->setShortcut(tr("Ctrl+-"));
zoomOutAct->setStatusTip(tr("Zoom out"));
connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
// firstPage,lastPage,nextPage,previousPage
firstPageAct = new QAction(QIcon(":/images/first.png"),tr("First Page"), this);
firstPageAct->setShortcut(tr("Ctrl+F"));
firstPageAct->setStatusTip(tr("Go to first page of document"));
connect(firstPageAct, SIGNAL(triggered()), this, SLOT(firstPage()));
lastPageAct = new QAction(QIcon(":/images/last.png"),tr("Last Page"), this);
lastPageAct->setShortcut(tr("Ctrl+L"));
lastPageAct->setStatusTip(tr("Go to last page of document"));
connect(lastPageAct, SIGNAL(triggered()), this, SLOT(lastPage()));
nextPageAct = new QAction(QIcon(":/images/next.png"),tr("&Next Page"),this);
nextPageAct->setShortcut(tr("Ctrl+N"));
nextPageAct->setStatusTip(tr("Go to next page of document"));
connect(nextPageAct, SIGNAL(triggered()), this, SLOT(nextPage()));
previousPageAct = new QAction(QIcon(":/images/prev.png"),tr("&Previous Page"),this);
previousPageAct->setShortcut(tr("Ctrl+P"));
previousPageAct->setStatusTip(tr("Go to previous page of document"));
connect(previousPageAct, SIGNAL(triggered()), this, SLOT(prevPage()));
QString pageString = "";
setPageLineEdit = new QLineEdit(pageString,this);
QSize size = setPageLineEdit->sizeHint();
size.setWidth(size.width()/3);
setPageLineEdit->setMinimumSize(size);
connect(setPageLineEdit, SIGNAL(returnPressed()), this, SLOT(setPage()));
clearPLICacheAct = new QAction(tr("Clear Parts List Cache"), this);
clearPLICacheAct->setStatusTip(tr("Erase the parts list image cache"));
connect(clearPLICacheAct, SIGNAL(triggered()), this, SLOT(clearPLICache()));
clearCSICacheAct = new QAction(tr("Clear Assembly Image Cache"), this);
clearCSICacheAct->setStatusTip(tr("Erase the assembly image cache"));
connect(clearCSICacheAct, SIGNAL(triggered()), this, SLOT(clearCSICache()));
// Config menu
pageSetupAct = new QAction(tr("Page Setup"), this);
pageSetupAct->setEnabled(false);
pageSetupAct->setStatusTip(tr("Default values for your project's pages"));
connect(pageSetupAct, SIGNAL(triggered()), this, SLOT(pageSetup()));
assemSetupAct = new QAction(tr("Assembly Setup"), this);
assemSetupAct->setEnabled(false);
assemSetupAct->setStatusTip(tr("Default values for your project's assembly images"));
connect(assemSetupAct, SIGNAL(triggered()), this, SLOT(assemSetup()));
pliSetupAct = new QAction(tr("Parts List Setup"), this);
pliSetupAct->setEnabled(false);
pliSetupAct->setStatusTip(tr("Default values for your project's parts lists"));
connect(pliSetupAct, SIGNAL(triggered()), this, SLOT(pliSetup()));
bomSetupAct = new QAction(tr("Bill of Materials Setup"), this);
bomSetupAct->setEnabled(false);
bomSetupAct->setStatusTip(tr("Default values for your project's bill of materials"));
connect(bomSetupAct, SIGNAL(triggered()), this, SLOT(bomSetup()));
calloutSetupAct = new QAction(tr("Callout Setup"), this);
calloutSetupAct->setEnabled(false);
calloutSetupAct->setStatusTip(tr("Default values for your project's callouts"));
connect(calloutSetupAct, SIGNAL(triggered()), this, SLOT(calloutSetup()));
multiStepSetupAct = new QAction(tr("Step Group Setup"), this);
multiStepSetupAct->setEnabled(false);
multiStepSetupAct->setStatusTip(tr("Default values for your project's step groups"));
connect(multiStepSetupAct, SIGNAL(triggered()), this, SLOT(multiStepSetup()));
projectSetupAct = new QAction(tr("Project Setup"), this);
projectSetupAct->setEnabled(false);
projectSetupAct->setStatusTip(tr("Default values for your project"));
connect(projectSetupAct, SIGNAL(triggered()), this, SLOT(projectSetup()));
preferencesAct = new QAction(tr("Preferences"), this);
preferencesAct->setStatusTip(tr("Set your preferences for LPub"));
connect(preferencesAct, SIGNAL(triggered()), this, SLOT(preferences()));
// Help
aboutAct = new QAction(tr("&About"), this);
aboutAct->setStatusTip(tr("Show the application's About box"));
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
// Begin Jaco's code
onlineManualAct = new QAction(tr("&Online manual"), this);
onlineManualAct->setStatusTip(tr("Visit the Online Manual Website."));
connect(onlineManualAct, SIGNAL(triggered()), this, SLOT(onlineManual()));
// End Jaco's code
metaAct = new QAction(tr("&Save LPub Metacommands to File"), this);
metaAct->setStatusTip(tr("Save a list of the known LPub meta commands to a file"));
connect(metaAct, SIGNAL(triggered()), this, SLOT(meta()));
}
void Gui::enableActions()
{
saveAct->setEnabled(true);
saveAsAct->setEnabled(true);
printToFileAct->setEnabled(true);
exportPngAct->setEnabled(true);
exportJpgAct->setEnabled(true);
exportBmpAct->setEnabled(true);
pageSetupAct->setEnabled(true);
assemSetupAct->setEnabled(true);
pliSetupAct->setEnabled(true);
bomSetupAct->setEnabled(true);
calloutSetupAct->setEnabled(true);
multiStepSetupAct->setEnabled(true);
projectSetupAct->setEnabled(true);
addPictureAct->setEnabled(true);
removeLPubFormattingAct->setEnabled(true);
}
void Gui::enableActions2()
{
MetaItem mi;
insertCoverPageAct->setEnabled(mi.okToInsertCoverPage());
appendCoverPageAct->setEnabled(mi.okToAppendCoverPage());
bool frontCover = mi.okToInsertNumberedPage();
insertNumberedPageAct->setEnabled(frontCover);
bool backCover = mi.okToAppendNumberedPage();
appendNumberedPageAct->setEnabled(backCover);
deletePageAct->setEnabled(page.list.size() == 0);
addBomAct->setEnabled(frontCover||backCover);
addTextAct->setEnabled(true);
}
void Gui::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);
fileMenu->addAction(saveAsAct);
QMenu *exportMenu = fileMenu->addMenu("Export As...");
exportMenu->addAction(exportPngAct);
exportMenu->addAction(exportJpgAct);
exportMenu->addAction(exportBmpAct);
#ifndef __APPLE__
exportMenu->addAction(exportBmpAct);
#endif
fileMenu->addAction(printToFileAct);
separatorAct = fileMenu->addSeparator();
for (int i = 0; i < MaxRecentFiles; i++) {
fileMenu->addAction(recentFilesActs[i]);
}
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
menuBar()->addSeparator();
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(undoAct);
editMenu->addAction(redoAct);
editMenu->addAction(insertCoverPageAct);
editMenu->addAction(appendCoverPageAct);
editMenu->addAction(insertNumberedPageAct);
editMenu->addAction(appendNumberedPageAct);
editMenu->addAction(deletePageAct);
editMenu->addAction(addPictureAct);
editMenu->addAction(addTextAct);
editMenu->addAction(addBomAct);
editMenu->addAction(removeLPubFormattingAct);
viewMenu = menuBar()->addMenu(tr("&View"));
viewMenu->addAction(fitWidthAct);
viewMenu->addAction(fitVisibleAct);
viewMenu->addAction(actualSizeAct);
viewMenu->addAction(zoomInAct);
viewMenu->addAction(zoomOutAct);
viewMenu->addSeparator();
toolsMenu = menuBar()->addMenu(tr("&Tools"));
toolsMenu->addAction(firstPageAct);
toolsMenu->addAction(previousPageAct);
toolsMenu->addAction(nextPageAct);
toolsMenu->addAction(lastPageAct);
toolsMenu->addSeparator();
toolsMenu->addAction(clearPLICacheAct);
toolsMenu->addAction(clearCSICacheAct);
configMenu = menuBar()->addMenu(tr("&Configuration"));
configMenu->addAction(pageSetupAct);
configMenu->addAction(assemSetupAct);
configMenu->addAction(pliSetupAct);
configMenu->addAction(bomSetupAct);
configMenu->addAction(calloutSetupAct);
configMenu->addAction(multiStepSetupAct);
configMenu->addAction(projectSetupAct);
configMenu->addSeparator();
configMenu->addAction(preferencesAct);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
// Begin Jaco's code
helpMenu->addAction(onlineManualAct);
// End Jaco's code
helpMenu->addAction(metaAct);
}
void Gui::createToolBars()
{
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(openAct);
fileToolBar->addAction(saveAct);
fileToolBar->addAction(printToFileAct);
editToolBar = addToolBar(tr("Edit"));
editToolBar->addAction(undoAct);
editToolBar->addAction(redoAct);
navigationToolBar = addToolBar(tr("Navigation"));
navigationToolBar->addAction(firstPageAct);
navigationToolBar->addAction(previousPageAct);
navigationToolBar->addWidget(setPageLineEdit);
navigationToolBar->addAction(nextPageAct);
navigationToolBar->addAction(lastPageAct);
mpdToolBar = addToolBar(tr("MPD"));
mpdToolBar->addWidget(mpdCombo);
zoomToolBar = addToolBar(tr("Zoom"));
zoomToolBar->addAction(fitVisibleAct);
zoomToolBar->addAction(fitWidthAct);
// Jaco add actual size icon. Was missing.
zoomToolBar->addAction(actualSizeAct);
zoomToolBar->addAction(zoomInAct);
zoomToolBar->addAction(zoomOutAct);
}
void Gui::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void Gui::createDockWindows()
{
QDockWidget *dock = new QDockWidget(tr("LDraw File"), this);
dock->setAllowedAreas(
Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea |
Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
dock->setWidget(editWindow);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());
}
void Gui::readSettings()
{
QSettings settings(LPUB, "LEGO Building Instruction Tool");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
resize(size);
move(pos);
}
void Gui::writeSettings()
{
QSettings settings(LPUB, SETTINGS);
settings.setValue("pos", pos());
settings.setValue("size", size());
}