Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2501 lines (2329 loc) · 102 KB
/
Copy pathmainwindow.cpp
File metadata and controls
2501 lines (2329 loc) · 102 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
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright © 2008-13 Qtrac Ltd. All rights reserved.
This program or module is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 2 of
the License, or (at your option) any later version. This program is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
*/
#include "aboutform.hpp"
#include "generic.hpp"
#include "helpform.hpp"
#include "label.hpp"
#include "lineedit.hpp"
#include "marginspinbox.hpp"
#include "optionsform.hpp"
#include "mainwindow.hpp"
#include "sequence_matcher.hpp"
#include "textitem.hpp"
#include <QElapsedTimer>
#include <QRegularExpression>
#ifdef DEBUG
#include <QtDebug>
#endif
#include <QApplication>
#include <QBoxLayout>
#include <QCheckBox>
#include <QComboBox>
#include <QDir>
#include <QDockWidget>
#include <QEvent>
#include <QFileDialog>
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QContextMenuEvent>
#include <QMenu>
#include <QMessageBox>
#include <QPainter>
#include <QPixmapCache>
#include <QPlainTextEdit>
#include <QPrinter>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollArea>
#include <QScrollBar>
#include <QSettings>
#include <QShortcut>
#include <QSignalBlocker>
#include <QSpinBox>
#include <QSplitter>
#include <QToolButton>
#include <QUrl>
MainWindow::MainWindow(const Debug debug,
const InitialComparisonMode comparisonMode,
const QString &filename1, const QString &filename2,
const QString &language, StartupParameters *startupParameters, Status *status, QWidget *parent)
: QMainWindow(parent),
controlDockArea(Qt::RightDockWidgetArea),
actionDockArea(Qt::RightDockWidgetArea),
marginsDockArea(Qt::RightDockWidgetArea),
zoningDockArea(Qt::RightDockWidgetArea),
cancel(false), comparing(false),
saveAll(true), savePages(SaveBothPages), language(language),
debug(debug), aboutForm(0), helpForm(0)
{
_startupParameters = startupParameters ;
currentCompareIndex = comparisonMode ;
_status = status ;
currentPath = QDir::homePath();
QSettings settings;
// The stored preference only. --any-extension is for this run, so it
// is applied in filesMustBePdf() rather than folded in here: mixing
// the two meant the Options dialog showed the flag's effect as though
// it were the preference, and saved it back as one.
requirePdfExtension = settings.value("RequirePdfExtension", true)
.toBool();
pen.setStyle(Qt::NoPen);
pen.setColor(Qt::red);
pen = settings.value("Outline", pen).value<QPen>();
brush.setColor(pen.color());
brush.setStyle(Qt::SolidPattern);
brush = settings.value("Fill", brush).value<QBrush>();
showToolTips = settings.value("ShowToolTips", true).toBool();
combineTextHighlighting = settings.value("CombineTextHighlighting",
true).toBool();
QPixmapCache::setCacheLimit(1000 *
qBound(1, settings.value("CacheSizeMB", 25).toInt(), 100));
createWidgets(filename1, filename2);
createCentralArea();
createDockWidgets();
createConnections();
createShortcuts();
restoreGeometry(settings.value("MainWindow/Geometry").toByteArray());
restoreState(settings.value("MainWindow/State").toByteArray());
controlDockLocationChanged(static_cast<Qt::DockWidgetArea>(
settings.value("MainWindow/ControlDockArea",
static_cast<int>(controlDockArea)).toInt()));
actionDockLocationChanged(static_cast<Qt::DockWidgetArea>(
settings.value("MainWindow/ActionDockArea",
static_cast<int>(actionDockArea)).toInt()));
zoningDockLocationChanged(static_cast<Qt::DockWidgetArea>(
settings.value("MainWindow/ZoningDockArea",
static_cast<int>(zoningDockArea)).toInt()));
marginsDockLocationChanged(static_cast<Qt::DockWidgetArea>(
settings.value("MainWindow/MarginsDockArea",
static_cast<int>(marginsDockArea)).toInt()));
controlDockWidget->resize(controlDockWidget->minimumSizeHint());
actionDockWidget->resize(actionDockWidget->minimumSizeHint());
zoningDockWidget->resize(zoningDockWidget->minimumSizeHint());
marginsDockWidget->resize(marginsDockWidget->minimumSizeHint());
//logDockWidget->resize(logDockWidget->minimumSizeHint());
setWindowTitle(AboutForm::ProgramName);
setWindowIcon(QIcon(":/icon.png"));
compareComboBox->setCurrentIndex(comparisonMode);
QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection,
Q_ARG(QString, filename1),
Q_ARG(QString, filename2));
}
// The window's keyboard shortcuts (see createShortcuts()), here so that
// the tooltips can name them
static QKeySequence previousPairKey() { return Qt::CTRL | Qt::Key_Up; }
static QKeySequence nextPairKey() { return Qt::CTRL | Qt::Key_Down; }
static QKeySequence zoomInKey() { return Qt::CTRL | Qt::Key_Plus; }
static QKeySequence zoomOutKey() { return Qt::CTRL | Qt::Key_Minus; }
static QKeySequence zoomResetKey() { return Qt::CTRL | Qt::Key_0; }
static QString keyName(const QKeySequence &key)
{
return key.toString(QKeySequence::NativeText);
}
// A checkable group box set straight into a dock widget has its checkbox
// on the line under the dock's title, where it reads as part of that
// line and is easily missed -- macOS draws the two touching. This puts
// the box in a widget whose layout margins leave room around it.
static QWidget *spacedFromTitleBar(QGroupBox *groupBox)
{
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout(widget);
layout->addWidget(groupBox);
return widget;
}
void MainWindow::createWidgets(const QString &filename1,
const QString &filename2)
{
setFile1Button = new QPushButton(tr("File #&1..."));
setFile1Button->setToolTip(tr("<p>Choose the first (left hand) file "
"to be compared."));
filename1LineEdit = new LineEdit;
filename1LineEdit->setToolTip(tr("The first (left hand) file."));
filename1LineEdit->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
filename1LineEdit->setMinimumWidth(100);
filename1LineEdit->setText(filename1);
setFile2Button = new QPushButton(tr("File #&2..."));
setFile2Button->setToolTip(tr("<p>Choose the second (right hand) file "
"to be compared."));
filename2LineEdit = new LineEdit;
filename2LineEdit->setToolTip(tr("The second (right hand) file."));
filename2LineEdit->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
filename2LineEdit->setMinimumWidth(100);
filename2LineEdit->setText(filename2);
comparePages1Label = new QLabel(tr("Pa&ges:"));
pages1LineEdit = new QLineEdit;
comparePages1Label->setBuddy(pages1LineEdit);
pages1LineEdit->setToolTip(tr("<p>Pages can be specified using ranges "
"such as 1-10, and multiple ranges can be used, e.g., "
"1-10, 12-15, 20, 22, 35-39. This makes it "
"straighforward to compare similar documents where one "
"has one or more additional pages.<p>For example, if "
"file1.pdf has pages 1-30 and file2.pdf has pages 1-31 "
"with the extra page being page 14, the two page ranges "
"would be set to 1-30 for file1.pdf and 1-13, 15-31 for "
"file2.pdf."));
comparePages2Label = new QLabel(tr("&Pages:"));
pages2LineEdit = new QLineEdit;
comparePages2Label->setBuddy(pages2LineEdit);
pages2LineEdit->setToolTip(pages1LineEdit->toolTip());
auto makeStepButton = [](Qt::ArrowType arrow, const QString &toolTip) {
QToolButton *button = new QToolButton;
button->setArrowType(arrow);
button->setToolTip(toolTip);
button->setEnabled(false);
return button;
};
previousPage1Button = makeStepButton(Qt::LeftArrow,
tr("<p>Show the previous page of file #1 beside the same "
"page of file #2. This changes the page <b>Offset</b>."));
nextPage1Button = makeStepButton(Qt::RightArrow,
tr("<p>Show the next page of file #1 beside the same page "
"of file #2. This changes the page <b>Offset</b>."));
previousPage2Button = makeStepButton(Qt::LeftArrow,
tr("<p>Show the previous page of file #2 beside the same "
"page of file #1. This changes the page <b>Offset</b>."));
nextPage2Button = makeStepButton(Qt::RightArrow,
tr("<p>Show the next page of file #2 beside the same page "
"of file #1. This changes the page <b>Offset</b>."));
compareButton = new QPushButton(tr("&Compare"));
compareButton->setEnabled(false);
compareButton->setDefault(true);
compareButton->setAutoDefault(true);
compareButton->setToolTip(tr("<p>Click to compare (or re-compare) "
"the documents—or to cancel a comparison that's "
"in progress."));
compareComboBox = new QComboBox;
compareComboBox->addItems(QStringList() << tr("Appearance")
<< tr("Characters") << tr("Words"));
compareComboBox->setToolTip(
tr("<p>If the <b>Words</b> comparison "
"mode is chosen, then each page's text is compared "
"word by word (best for alphabetic languages like "
"English). "
"If the <b>Characters</b> comparison mode is chosen, "
"then each page's text is compared character by "
"character (best for logographic languages like Chinese "
"and Japanese). "
"If the <b>Appearance</b> comparison mode is chosen "
"then each page's visual appearance is compared. "
"Comparing appearance can be slow for large documents "
"and can also produce false positives—but is "
"absolutely precise."));
compareLabel = new QLabel(tr("Co&mpare:"));
compareLabel->setBuddy(compareComboBox);
viewDiffLabel = new QLabel(tr("&View:"));
viewDiffLabel->setToolTip(tr("<p>Shows each pair of pages which "
"are different. The comparison is textual unless the "
"<b>Appearance</b> comparison mode is chosen, in "
"which case the comparison is done visually. "
"Visual differences can occur if a paragraph is "
"formated differently or if an embedded diagram or "
"image has changed."));
viewDiffComboBox = new QComboBox;
viewDiffComboBox->addItem(tr("(Not viewing)"));
viewDiffLabel->setBuddy(viewDiffComboBox);
viewDiffComboBox->setToolTip(viewDiffLabel->toolTip());
showLabel = new QLabel(tr("S&how:"));
showLabel->setToolTip(tr("<p>In show <b>Highlighting</b> mode the "
"pages are shown side by side with their differences "
"highlighted. All the other modes are composition "
"modes which show the first PDF as-is and the "
"composition (blend) of the two PDFs."));
showComboBox = new QComboBox;
showComboBox->addItem(tr("%1Highlighting%2")
.arg(QChar(0xAB)).arg(QChar(0xBB)), -1);
showComboBox->addItem(tr("Not Src Xor Dest"),
QPainter::RasterOp_NotSourceXorDestination);
showComboBox->addItem(tr("Difference"),
QPainter::CompositionMode_Difference);
showComboBox->addItem(tr("Exclusion"),
QPainter::CompositionMode_Exclusion);
showComboBox->addItem(tr("Src Xor Dest"),
QPainter::RasterOp_SourceXorDestination);
showLabel->setBuddy(showComboBox);
showComboBox->setToolTip(showLabel->toolTip());
previousButton = new QPushButton(tr("Previo&us"));
previousButton->setToolTip(tr("<p>Navigate to the previous pair of "
"pages (%1).").arg(keyName(previousPairKey())));
previousButton->setIcon(QIcon(":/left.png"));
nextButton = new QPushButton(tr("Ne&xt"));
nextButton->setToolTip(tr("<p>Navigate to the next pair of pages "
"(%1).").arg(keyName(nextPairKey())));
nextButton->setIcon(QIcon(":/right.png"));
offsetLabel = new QLabel(tr("Offset:"));
offsetLabel->setToolTip(tr("<p>Pairs each page of file #1 with the "
"page that many pages further on in file #2 (or back, "
"if negative), counting within the page ranges. Use "
"this when material added to one file shifts the "
"pages of the other. The arrow buttons beside each "
"file's page range change it one page at a time. "
"Pages already compared are remembered, so changing "
"the offset is quick."));
offsetSpinBox = new QSpinBox;
offsetLabel->setBuddy(offsetSpinBox);
offsetSpinBox->setRange(-9999, 9999);
offsetSpinBox->setKeyboardTracking(false);
offsetSpinBox->setToolTip(offsetLabel->toolTip());
zoomLabel = new QLabel(tr("&Zoom:"));
zoomLabel->setToolTip(tr("<p>Determines the scale at which the "
"pages are shown. %1 and %2 zoom in and out, and %3 goes "
"back to 100%.").arg(keyName(zoomInKey()),
keyName(zoomOutKey()), keyName(zoomResetKey())));
zoomSpinBox = new QSpinBox;
zoomLabel->setBuddy(zoomSpinBox);
zoomSpinBox->setRange(20, 800);
zoomSpinBox->setSuffix(tr(" %"));
zoomSpinBox->setSingleStep(5);
QSettings settings;
zoomSpinBox->setValue(settings.value("Zoom", 100).toInt());
zoomSpinBox->setToolTip(zoomLabel->toolTip());
zoningGroupBox = new QGroupBox(tr("Zo&ning"));
zoningGroupBox->setToolTip(tr("<p>Zoning is a computationally "
"expensive experimental mode that can reduce or "
"eliminate false positives particularly for pages "
"that have tables or that mix alphabetic and "
"logographic languages—it can also increase "
"false positives! Zoning only applies to text "
"comparisons."));
zoningGroupBox->setCheckable(true);
// The one control of this dock that did not persist: Columns and the
// tolerances did, and both READMEs list a GUI control for it, but
// the checkbox was hardcoded off and closeEvent() never saved it
zoningGroupBox->setChecked(
settings.value("Zoning/Enable", false).toBool());
columnsLabel = new QLabel(tr("Co&lumns:"));
columnsSpinBox = new QSpinBox;
columnsSpinBox->setRange(1, 16);
columnsSpinBox->setValue(settings.value("Columns", 1).toInt());
columnsSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
columnsSpinBox->setToolTip(tr("<p>Use this to tell %1 how "
"many columns the page has; this should improve the "
"zoning.").arg(AboutForm::ProgramName));
columnsLabel->setBuddy(columnsSpinBox);
toleranceRLabel = new QLabel(tr("Tolerance/&R:"));
toleranceRSpinBox = new QSpinBox;
toleranceRSpinBox->setRange(4, 144);
toleranceRSpinBox->setValue(settings.value("Tolerance/R", 8).toInt());
toleranceRSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
toleranceRSpinBox->setToolTip(tr("<p>This is the maximum distance "
"between text (word) rectangles for the rectangles to "
"appear in the same zone."));
toleranceRLabel->setBuddy(toleranceRSpinBox);
toleranceYLabel = new QLabel(tr("Tolerance/&Y:"));
toleranceYSpinBox = new QSpinBox;
toleranceYSpinBox->setRange(0, 32);
toleranceYSpinBox->setValue(settings.value("Tolerance/Y", 10).toInt());
toleranceYSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
toleranceYSpinBox->setToolTip(tr("<p>Text position <i>y</i> "
"coordinates are rounded to the nearest Tolerance/Y "
"value when zoning."));
toleranceYLabel->setBuddy(toleranceYSpinBox);
showZonesCheckBox = new QCheckBox(tr("Sho&w Zones"));
showZonesCheckBox->setToolTip(tr("<p>This shows the zones that are "
"being used and may be helpful when adjusting "
"tolerances. (Its original purpose was for debugging.)"));
marginsGroupBox = new QGroupBox(tr("&Exclude Margins"));
marginsGroupBox->setToolTip(tr("<p>If this is checked, anything "
"outside non-zero margins is ignored when comparing."));
marginsGroupBox->setCheckable(true);
marginsGroupBox->setChecked(settings.value("Margins/Exclude",
false).toBool());
topMarginLabel = new QLabel(tr("&Top:"));
topMarginSpinBox = new MarginSpinBox;
// Room for any saved value: QSpinBox's default maximum of 99 cut a
// larger one before a file had set the range (updateMarginRanges())
topMarginSpinBox->setRange(0, 9999);
topMarginSpinBox->setValue(settings.value("Margins/Top", 0).toInt());
topMarginSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
topMarginSpinBox->setToolTip(tr("<p>The top margin, in the "
"unit chosen below. Anything above this will be "
"ignored."));
topMarginLabel->setBuddy(topMarginSpinBox);
bottomMarginLabel = new QLabel(tr("&Bottom:"));
bottomMarginSpinBox = new MarginSpinBox;
bottomMarginSpinBox->setRange(0, 9999);
bottomMarginSpinBox->setValue(settings.value("Margins/Bottom", 0)
.toInt());
bottomMarginSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
bottomMarginSpinBox->setToolTip(tr("<p>The bottom margin, in the "
"unit chosen below. Anything below this will be "
"ignored."));
bottomMarginLabel->setBuddy(bottomMarginSpinBox);
leftMarginLabel = new QLabel(tr("Le&ft:"));
leftMarginSpinBox = new MarginSpinBox;
leftMarginSpinBox->setRange(0, 9999);
leftMarginSpinBox->setValue(settings.value("Margins/Left", 0).toInt());
leftMarginSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
leftMarginSpinBox->setToolTip(tr("<p>The left margin, in the "
"unit chosen below. Anything left of this will be "
"ignored."));
leftMarginLabel->setBuddy(leftMarginSpinBox);
rightMarginLabel = new QLabel(tr("R&ight:"));
rightMarginSpinBox = new MarginSpinBox;
rightMarginSpinBox->setRange(0, 9999);
rightMarginSpinBox->setValue(settings.value("Margins/Right", 0)
.toInt());
rightMarginSpinBox->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
rightMarginSpinBox->setToolTip(tr("<p>The right margin, in the "
"unit chosen below. Anything right of this will be "
"ignored."));
rightMarginLabel->setBuddy(rightMarginSpinBox);
// The margins are held, saved and compared in whole points; the unit
// is only how the four boxes show them and read what is typed
marginUnitLabel = new QLabel(tr("Unit:"));
marginUnitComboBox = new QComboBox;
marginUnitComboBox->addItem(tr("Points (pt)"),
MarginSpinBox::unitName(MarginSpinBox::Points));
marginUnitComboBox->addItem(tr("Millimetres (mm)"),
MarginSpinBox::unitName(MarginSpinBox::Millimetres));
marginUnitComboBox->setCurrentIndex(qMax(0,
marginUnitComboBox->findData(settings.value("Margins/Unit",
"pt").toString())));
marginUnitComboBox->setToolTip(tr("<p>The unit the margins are shown "
"and typed in. They are kept in whole points whichever is "
"chosen, so a margin typed in millimetres goes to the "
"nearest point (20 mm is 57 pt, shown as 20.1 mm)."));
marginUnitLabel->setToolTip(marginUnitComboBox->toolTip());
marginUnitLabel->setBuddy(marginUnitComboBox);
marginUnitChanged();
resetMarginsButton = new QPushButton(tr("Reset to &0"));
resetMarginsButton->setToolTip(tr("<p>Sets all four margins to 0."));
pageBoxLabel = new QLabel(tr("Page bo&undary:"));
pageBoxComboBox = new QComboBox;
pageBoxComboBox->addItem(tr("Whole page"), pageBoxName(PageBox::None));
for (PageBox box : {PageBox::Media, PageBox::Crop, PageBox::Bleed,
PageBox::Trim, PageBox::Art})
pageBoxComboBox->addItem(QString("%1Box").arg(
pageBoxName(box).left(1).toUpper() + pageBoxName(box).mid(1)),
pageBoxName(box));
pageBoxComboBox->setToolTip(tr("<p>Compare only what is inside this "
"page boundary (ISO 32000-2, 14.11.2). A page without it "
"uses its default: the CropBox for the BleedBox, TrimBox "
"and ArtBox, the MediaBox for the CropBox. The pages are "
"lined up on the boundary's top left corner, and the rest "
"of each page is shown dimmed."));
pageBoxLabel->setBuddy(pageBoxComboBox);
boxClipLabel = new QLabel(tr("Clippe&d to:"));
boxClipComboBox = new QComboBox;
boxClipComboBox->addItem(tr("MediaBox"), boxClipName(BoxClip::Media));
boxClipComboBox->addItem(tr("MediaBox and CropBox"),
boxClipName(BoxClip::Crop));
boxClipComboBox->addItem(tr("Nothing (as written)"),
boxClipName(BoxClip::None));
boxClipComboBox->setToolTip(tr("<p>What the page boundary is clipped "
"to: the MediaBox, as ISO 32000-2 requires; the MediaBox "
"and the CropBox, i.e. only what a viewer shows; or "
"nothing, so that all of it is compared, even outside the "
"MediaBox."));
boxClipLabel->setBuddy(boxClipComboBox);
{
// --box and --box-clip are used for this run, but not saved
PageBox box = PageBox::None;
parsePageBox(settings.value("PageBox/Box").toString(), &box);
BoxClip clip = BoxClip::Media;
parseBoxClip(settings.value("PageBox/Clip").toString(), &clip);
pageBoxFromCommandLine = _startupParameters->pageBoxGiven();
if (pageBoxFromCommandLine)
box = _startupParameters->pageBox();
boxClipFromCommandLine = _startupParameters->boxClipGiven();
if (boxClipFromCommandLine)
clip = _startupParameters->boxClip();
pageBoxComboBox->setCurrentIndex(
pageBoxComboBox->findData(pageBoxName(box)));
boxClipComboBox->setCurrentIndex(
boxClipComboBox->findData(boxClipName(clip)));
}
defaultPageBoxButton = new QPushButton(tr("Restore Default"));
defaultPageBoxButton->setToolTip(tr("<p>Compare whole pages again."));
statusLabel = new QLabel(tr("Choose files..."));
statusLabel->setFrameStyle(QFrame::StyledPanel|QFrame::Sunken);
statusLabel->setMaximumHeight(statusLabel->minimumSizeHint().height());
optionsButton = new QPushButton(tr("&Options..."));
optionsButton->setToolTip(tr("Click to customize the application."));
saveButton = new QPushButton(tr("&Save As..."));
saveButton->setToolTip(tr("Save the differences."));
helpButton = new QPushButton(tr("Help"));
helpButton->setShortcut(tr("F1"));
helpButton->setToolTip(tr("Click for basic help."));
aboutButton = new QPushButton(tr("&About"));
aboutButton->setToolTip(tr("Click for copyright and credits."));
quitButton = new QPushButton(tr("&Quit"));
quitButton->setToolTip(tr("Click to terminate the application."));
page1Label = new Label;
page1Label->setAlignment(Qt::AlignTop|Qt::AlignLeft);
page1Label->setToolTip(tr("<p>Shows the first (left hand) document's "
"page that corresponds to the page shown in the "
"View Difference combobox."));
page2Label = new Label;
page2Label->setAlignment(Qt::AlignTop|Qt::AlignLeft);
page2Label->setToolTip(tr("<p>Shows the second (right hand) "
"document's page that corresponds to the page shown in "
"the View Difference combobox."));
logEdit = new QPlainTextEdit;
QList<QWidget*> widgets;
widgets << setFile1Button << filename1LineEdit << pages1LineEdit
<< page1Label << setFile2Button << filename2LineEdit
<< pages2LineEdit << page2Label << compareButton
<< compareComboBox << viewDiffLabel << viewDiffComboBox
<< showLabel << showComboBox << zoomLabel << zoomSpinBox
<< optionsButton << zoningGroupBox << columnsLabel
<< columnsSpinBox << toleranceRLabel << toleranceRSpinBox
<< toleranceYLabel << toleranceYSpinBox << marginsGroupBox
<< topMarginLabel << topMarginSpinBox << bottomMarginSpinBox
<< bottomMarginLabel << leftMarginLabel << leftMarginSpinBox
<< rightMarginLabel << rightMarginSpinBox << pageBoxComboBox
<< boxClipComboBox << defaultPageBoxButton << saveButton
<< helpButton << aboutButton << quitButton << logEdit
<< previousButton << nextButton << showZonesCheckBox
<< previousPage1Button << nextPage1Button
<< previousPage2Button << nextPage2Button << offsetLabel
<< offsetSpinBox;
for (QWidget *widget : widgets)
if (!widget->toolTip().isEmpty())
widget->installEventFilter(this);
}
void MainWindow::createCentralArea()
{
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(setFile1Button);
topLeftLayout->addWidget(filename1LineEdit, 3);
topLeftLayout->addWidget(comparePages1Label);
topLeftLayout->addWidget(pages1LineEdit, 2);
topLeftLayout->addWidget(previousPage1Button);
topLeftLayout->addWidget(nextPage1Button);
area1 = new QScrollArea;
area1->setWidget(page1Label);
area1->setWidgetResizable(true);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(area1, 1);
QWidget *leftWidget = new QWidget;
leftWidget->setLayout(leftLayout);
QHBoxLayout *topRightLayout = new QHBoxLayout;
topRightLayout->addWidget(setFile2Button);
topRightLayout->addWidget(filename2LineEdit, 3);
topRightLayout->addWidget(comparePages2Label);
topRightLayout->addWidget(pages2LineEdit, 2);
topRightLayout->addWidget(previousPage2Button);
topRightLayout->addWidget(nextPage2Button);
area2 = new QScrollArea;
area2->setWidget(page2Label);
area2->setWidgetResizable(true);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addLayout(topRightLayout);
rightLayout->addWidget(area2, 1);
QWidget *rightWidget = new QWidget;
rightWidget->setLayout(rightLayout);
splitter = new QSplitter(Qt::Horizontal);
splitter->addWidget(leftWidget);
splitter->addWidget(rightWidget);
QSettings settings;
splitter->restoreState(settings.value("MainWindow/ViewSplitter")
.toByteArray());
setCentralWidget(splitter);
}
void MainWindow::createDockWidgets()
{
setTabPosition(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea,
QTabWidget::North);
setTabPosition(Qt::TopDockWidgetArea|Qt::BottomDockWidgetArea,
QTabWidget::West);
QDockWidget::DockWidgetFeatures features =
QDockWidget::DockWidgetMovable|
QDockWidget::DockWidgetFloatable;
controlDockWidget = new QDockWidget(tr("Controls"), this);
controlDockWidget->setObjectName("Controls");
controlDockWidget->setFeatures(features);
controlLayout = new QBoxLayout(QBoxLayout::TopToBottom);
compareLayout = new QHBoxLayout;
compareLayout->addWidget(compareLabel);
compareLayout->addWidget(compareComboBox, 1);
controlLayout->addLayout(compareLayout);
QHBoxLayout *viewLayout = new QHBoxLayout;
viewLayout->addWidget(viewDiffLabel);
viewLayout->addWidget(viewDiffComboBox, 1);
controlLayout->addLayout(viewLayout);
QHBoxLayout *showLayout = new QHBoxLayout;
showLayout->addWidget(showLabel);
showLayout->addWidget(showComboBox, 1);
controlLayout->addLayout(showLayout);
QHBoxLayout *navigationLayout = new QHBoxLayout;
navigationLayout->addWidget(previousButton);
navigationLayout->addWidget(nextButton);
controlLayout->addLayout(navigationLayout);
QHBoxLayout *offsetLayout = new QHBoxLayout;
offsetLayout->addWidget(offsetLabel);
offsetLayout->addWidget(offsetSpinBox);
controlLayout->addLayout(offsetLayout);
QHBoxLayout *zoomLayout = new QHBoxLayout;
zoomLayout->addWidget(zoomLabel);
zoomLayout->addWidget(zoomSpinBox);
controlLayout->addLayout(zoomLayout);
controlLayout->addWidget(statusLabel);
controlLayout->addStretch();
QWidget *widget = new QWidget;
widget->setLayout(controlLayout);
controlDockWidget->setWidget(widget);
// For clicks that give the keyboard back to the View box (see
// eventFilter())
controlDockWidget->installEventFilter(this);
widget->installEventFilter(this);
addDockWidget(controlDockArea, controlDockWidget);
actionDockWidget = new QDockWidget(tr("Actions"), this);
actionDockWidget->setObjectName("Actions");
actionDockWidget->setFeatures(features);
actionLayout = new QBoxLayout(QBoxLayout::TopToBottom);
actionLayout->addWidget(compareButton);
QHBoxLayout *optionLayout = new QHBoxLayout;
optionLayout->addWidget(optionsButton);
optionLayout->addWidget(saveButton);
actionLayout->addLayout(optionLayout);
QHBoxLayout *helpLayout = new QHBoxLayout;
helpLayout->addWidget(helpButton);
helpLayout->addWidget(aboutButton);
actionLayout->addLayout(helpLayout);
actionLayout->addWidget(quitButton);
actionLayout->addStretch();
widget = new QWidget;
widget->setLayout(actionLayout);
actionDockWidget->setWidget(widget);
addDockWidget(actionDockArea, actionDockWidget);
marginsDockWidget = new QDockWidget(tr("Margins"), this);
marginsDockWidget->setObjectName("Margins");
marginsDockWidget->setFeatures(features|
QDockWidget::DockWidgetClosable);
marginsLayout = new QBoxLayout(QBoxLayout::TopToBottom);
QHBoxLayout *topMarginLayout = new QHBoxLayout;
topMarginLayout->addWidget(topMarginLabel);
topMarginLayout->addWidget(topMarginSpinBox);
marginsLayout->addLayout(topMarginLayout);
QHBoxLayout *bottomMarginLayout = new QHBoxLayout;
bottomMarginLayout->addWidget(bottomMarginLabel);
bottomMarginLayout->addWidget(bottomMarginSpinBox);
marginsLayout->addLayout(bottomMarginLayout);
QHBoxLayout *leftMarginLayout = new QHBoxLayout;
leftMarginLayout->addWidget(leftMarginLabel);
leftMarginLayout->addWidget(leftMarginSpinBox);
marginsLayout->addLayout(leftMarginLayout);
QHBoxLayout *rightMarginLayout = new QHBoxLayout;
rightMarginLayout->addWidget(rightMarginLabel);
rightMarginLayout->addWidget(rightMarginSpinBox);
marginsLayout->addLayout(rightMarginLayout);
QHBoxLayout *marginUnitLayout = new QHBoxLayout;
marginUnitLayout->addWidget(marginUnitLabel);
marginUnitLayout->addWidget(marginUnitComboBox, 1);
marginsLayout->addLayout(marginUnitLayout);
QHBoxLayout *resetMarginsLayout = new QHBoxLayout;
resetMarginsLayout->addStretch();
resetMarginsLayout->addWidget(resetMarginsButton);
marginsLayout->addLayout(resetMarginsLayout);
marginsLayout->addStretch();
marginsGroupBox->setLayout(marginsLayout);
marginsDockWidget->setWidget(spacedFromTitleBar(marginsGroupBox));
addDockWidget(marginsDockArea, marginsDockWidget);
pageBoxDockWidget = new QDockWidget(tr("Page Box"), this);
pageBoxDockWidget->setObjectName("PageBox");
pageBoxDockWidget->setFeatures(features|
QDockWidget::DockWidgetClosable);
QGridLayout *pageBoxLayout = new QGridLayout;
pageBoxLayout->addWidget(pageBoxLabel, 0, 0);
pageBoxLayout->addWidget(pageBoxComboBox, 0, 1);
pageBoxLayout->addWidget(boxClipLabel, 1, 0);
pageBoxLayout->addWidget(boxClipComboBox, 1, 1);
pageBoxLayout->addWidget(defaultPageBoxButton, 2, 1);
pageBoxLayout->setRowStretch(3, 1);
widget = new QWidget;
widget->setLayout(pageBoxLayout);
pageBoxDockWidget->setWidget(widget);
addDockWidget(marginsDockArea, pageBoxDockWidget);
zoningDockWidget = new QDockWidget(tr("Zoning"), this);
zoningDockWidget->setObjectName("Zoning");
zoningDockWidget->setFeatures(features|
QDockWidget::DockWidgetClosable);
zoningLayout = new QBoxLayout(QBoxLayout::TopToBottom);
QHBoxLayout *columnLayout = new QHBoxLayout;
columnLayout->addWidget(columnsLabel);
columnLayout->addWidget(columnsSpinBox);
zoningLayout->addLayout(columnLayout);
QHBoxLayout *toleranceLayout1 = new QHBoxLayout;
toleranceLayout1->addWidget(toleranceRLabel);
toleranceLayout1->addWidget(toleranceRSpinBox);
zoningLayout->addLayout(toleranceLayout1);
QHBoxLayout *toleranceLayout2 = new QHBoxLayout;
toleranceLayout2->addWidget(toleranceYLabel);
toleranceLayout2->addWidget(toleranceYSpinBox);
zoningLayout->addLayout(toleranceLayout2);
zoningLayout->addWidget(showZonesCheckBox);
zoningLayout->addStretch();
zoningGroupBox->setLayout(zoningLayout);
zoningDockWidget->setWidget(spacedFromTitleBar(zoningGroupBox));
addDockWidget(zoningDockArea, zoningDockWidget);
logDockWidget = new QDockWidget(tr("Log"), this);
logDockWidget->setObjectName("Log");
logDockWidget->setFeatures(features|QDockWidget::DockWidgetClosable);
logDockWidget->setWidget(logEdit);
addDockWidget(Qt::RightDockWidgetArea, logDockWidget);
tabifyDockWidget(marginsDockWidget, controlDockWidget);
tabifyDockWidget(marginsDockWidget, pageBoxDockWidget);
tabifyDockWidget(logDockWidget, zoningDockWidget);
tabifyDockWidget(zoningDockWidget, actionDockWidget);
}
void MainWindow::createConnections()
{
connect(area1->verticalScrollBar(), SIGNAL(valueChanged(int)),
area2->verticalScrollBar(), SLOT(setValue(int)));
connect(area2->verticalScrollBar(), SIGNAL(valueChanged(int)),
area1->verticalScrollBar(), SLOT(setValue(int)));
connect(area1->horizontalScrollBar(), SIGNAL(valueChanged(int)),
area2->horizontalScrollBar(), SLOT(setValue(int)));
connect(area2->horizontalScrollBar(), SIGNAL(valueChanged(int)),
area1->horizontalScrollBar(), SLOT(setValue(int)));
connect(filename1LineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(updateUi()));
connect(filename1LineEdit,
SIGNAL(filenamesDropped(const QStringList&)),
this, SLOT(setFiles1(const QStringList&)));
connect(filename2LineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(updateUi()));
connect(filename2LineEdit,
SIGNAL(filenamesDropped(const QStringList&)),
this, SLOT(setFiles2(const QStringList&)));
connect(page1Label, SIGNAL(filenamesDropped(const QStringList&)),
this, SLOT(setFiles1(const QStringList&)));
connect(page2Label, SIGNAL(filenamesDropped(const QStringList&)),
this, SLOT(setFiles2(const QStringList&)));
connect(compareComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateUi()));
connect(compareComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateViews()));
connect(viewDiffComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateViews(int)));
connect(viewDiffComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateUi()));
connect(showComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateViews()));
connect(previousButton, &QPushButton::clicked, this, &MainWindow::previousPages);
connect(nextButton, &QPushButton::clicked, this, &MainWindow::nextPages);
connect(setFile1Button, &QPushButton::clicked, this, [this]() { setFile1(); });
connect(setFile2Button, &QPushButton::clicked, this, [this]() { setFile2(); });
connect(compareButton, &QPushButton::clicked, this, &MainWindow::compare);
connect(previousPage1Button, &QAbstractButton::clicked,
this, [this] { stepPage(1, -1); });
connect(nextPage1Button, &QAbstractButton::clicked,
this, [this] { stepPage(1, 1); });
connect(previousPage2Button, &QAbstractButton::clicked,
this, [this] { stepPage(2, -1); });
connect(nextPage2Button, &QAbstractButton::clicked,
this, [this] { stepPage(2, 1); });
connect(offsetSpinBox, qOverload<int>(&QSpinBox::valueChanged),
this, &MainWindow::offsetChanged);
connect(zoomSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(zoningGroupBox, SIGNAL(toggled(bool)),
this, SLOT(updateUi()));
connect(zoningGroupBox, SIGNAL(toggled(bool)),
this, SLOT(updateViews()));
connect(columnsSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(toleranceRSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(toleranceYSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(showZonesCheckBox, SIGNAL(toggled(bool)),
this, SLOT(updateViews()));
connect(marginsGroupBox, SIGNAL(toggled(bool)),
this, SLOT(updateUi()));
connect(marginsGroupBox, SIGNAL(toggled(bool)),
this, SLOT(updateViews()));
connect(leftMarginSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(rightMarginSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(topMarginSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(bottomMarginSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(updateViews()));
connect(marginUnitComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(marginUnitChanged()));
connect(resetMarginsButton, &QPushButton::clicked,
this, &MainWindow::resetMargins);
connect(pageBoxComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(pageBoxChanged()));
connect(boxClipComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(pageBoxChanged()));
connect(defaultPageBoxButton, &QPushButton::clicked,
this, &MainWindow::restoreDefaultPageBox);
connect(page1Label, SIGNAL(clicked(const QPoint&)),
this, SLOT(setAMargin(const QPoint&)));
connect(page2Label, SIGNAL(clicked(const QPoint&)),
this, SLOT(setAMargin(const QPoint&)));
connect(optionsButton, &QPushButton::clicked, this, &MainWindow::options);
connect(saveButton, &QPushButton::clicked, this, &MainWindow::save);
connect(helpButton, &QPushButton::clicked, this, &MainWindow::help);
connect(aboutButton, &QPushButton::clicked, this, &MainWindow::about);
connect(quitButton, &QPushButton::clicked, this, &MainWindow::close);
connect(controlDockWidget,
SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
this, SLOT(controlDockLocationChanged(Qt::DockWidgetArea)));
connect(actionDockWidget,
SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
this, SLOT(actionDockLocationChanged(Qt::DockWidgetArea)));
connect(zoningDockWidget,
SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
this, SLOT(zoningDockLocationChanged(Qt::DockWidgetArea)));
connect(marginsDockWidget,
SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
this, SLOT(marginsDockLocationChanged(Qt::DockWidgetArea)));
connect(controlDockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(controlTopLevelChanged(bool)));
connect(actionDockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(actionTopLevelChanged(bool)));
connect(zoningDockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(zoningTopLevelChanged(bool)));
connect(marginsDockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(marginsTopLevelChanged(bool)));
connect(logDockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(logTopLevelChanged(bool)));
}
void MainWindow::initialize(const QString &filename1,
const QString &filename2)
{
if (!filename1.isEmpty()) {
setFile1(filename1);
setFile2Button->setFocus();
if (!filename2.isEmpty()) {
setFile2(filename2);
compare();
}
}
else
updateUi();
}
void MainWindow::updateUi()
{
currentCompareIndex = compareComboBox->currentIndex();
// While comparing the button is Cancel, so it stays live until it has
// been pressed -- otherwise clearing a file name would take away the
// only way to stop a long comparison
compareButton->setEnabled(comparing
? !cancel
: (!filename1LineEdit->text().isEmpty() &&
!filename2LineEdit->text().isEmpty()));
// Choosing a file or changing the settings during a comparison would
// discard the results the workers are still writing into. Changing
// the mode would not reach the running comparison but would reach
// the highlighting afterwards, so pairs found in Appearance would be
// drawn with the highlighting of Words, which finds nothing in them;
// and the offset box would come to show one the comparison did not
// use.
setFile1Button->setEnabled(!comparing);
setFile2Button->setEnabled(!comparing);
optionsButton->setEnabled(!comparing);
compareComboBox->setEnabled(!comparing);
offsetSpinBox->setEnabled(!comparing);
pageBoxComboBox->setEnabled(!comparing);
boxClipComboBox->setEnabled(!comparing && pageBox() != PageBox::None);
defaultPageBoxButton->setEnabled(!comparing &&
pageBox() != PageBox::None);
saveButton->setEnabled(viewDiffComboBox->count() > 1);
if (!showZonesCheckBox->isEnabled())
showZonesCheckBox->setChecked(false);
if (currentCompareIndex != CompareAppearance)
showComboBox->setCurrentIndex(0);
showComboBox->setEnabled(currentCompareIndex ==
CompareAppearance);
QPushButton *button = qobject_cast<QPushButton*>(focusWidget());
bool enableNavigationButton = (button == previousButton ||
button == nextButton);
if (viewDiffComboBox->currentIndex() == 0 && viewedPairIndex >= 0) {
// Viewing a pair that is not in the list of differing pairs
previousButton->setEnabled(
differingPairNear(viewedPairIndex, false) > 0);
nextButton->setEnabled(
differingPairNear(viewedPairIndex, true) > 0);
}
else {
previousButton->setEnabled(viewDiffComboBox->count() > 1 &&
viewDiffComboBox->currentIndex() > 0);
nextButton->setEnabled(viewDiffComboBox->count() > 1 &&
viewDiffComboBox->currentIndex() + 1 <
viewDiffComboBox->count());
}
{
// Stepping one file's page moves from the viewed pair, or from
// the first pair compared
const bool compared = !comparedPages1.isEmpty() && !comparing;
int index1 = viewedPairIndex;
if (index1 < 0)
index1 = qMax(0, -comparedOffset);
const int index2 = index1 + comparedOffset;
previousPage1Button->setEnabled(compared && index1 > 0 &&
index2 >= 0 && index2 < comparedPages2.count());
nextPage1Button->setEnabled(compared &&
index1 + 1 < comparedPages1.count() &&
index2 >= 0 && index2 < comparedPages2.count());
previousPage2Button->setEnabled(compared && index2 > 0 &&
index2 <= comparedPages2.count() &&
index1 < comparedPages1.count());
nextPage2Button->setEnabled(compared &&
index2 + 1 < comparedPages2.count() && index2 + 1 >= 0 &&
index1 < comparedPages1.count());
}
if (enableNavigationButton && !(previousButton->isEnabled() &&
nextButton->isEnabled())) {
if (previousButton->isEnabled())
previousButton->setFocus();
else
nextButton->setFocus();
}
if (marginsGroupBox->isChecked()) {
page1Label->setCursor(Qt::PointingHandCursor);
page2Label->setCursor(Qt::PointingHandCursor);
}
else {
page1Label->setCursor(Qt::ArrowCursor);
page2Label->setCursor(Qt::ArrowCursor);
}
}
void MainWindow::controlDockLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::TopDockWidgetArea ||
area == Qt::BottomDockWidgetArea) {
controlLayout->setDirection(QBoxLayout::LeftToRight);
}
else {
controlLayout->setDirection(QBoxLayout::TopToBottom);
}
controlDockArea = area;
}
void MainWindow::actionDockLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::TopDockWidgetArea ||
area == Qt::BottomDockWidgetArea)
actionLayout->setDirection(QBoxLayout::LeftToRight);
else
actionLayout->setDirection(QBoxLayout::TopToBottom);
actionDockArea = area;
}
void MainWindow::zoningDockLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::TopDockWidgetArea ||
area == Qt::BottomDockWidgetArea)
zoningLayout->setDirection(QBoxLayout::LeftToRight);
else
zoningLayout->setDirection(QBoxLayout::TopToBottom);
zoningDockArea = area;
}
void MainWindow::marginsDockLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::TopDockWidgetArea ||
area == Qt::BottomDockWidgetArea)
marginsLayout->setDirection(QBoxLayout::LeftToRight);
else
marginsLayout->setDirection(QBoxLayout::TopToBottom);
marginsDockArea = area;
}
void MainWindow::controlTopLevelChanged(bool floating)
{
controlLayout->setDirection(floating ? QBoxLayout::TopToBottom
: QBoxLayout::LeftToRight);
if (QWidget *widget = static_cast<QWidget*>(controlLayout->parent()))
widget->setFixedSize(floating ? widget->minimumSizeHint()
: QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
controlDockWidget->setWindowTitle(floating ? tr("%1 — Controls").arg(AboutForm::ProgramName)
: tr("Controls"));
}
void MainWindow::actionTopLevelChanged(bool floating)
{
actionLayout->setDirection(floating ? QBoxLayout::TopToBottom
: QBoxLayout::LeftToRight);