1 #ifndef MAINWINDOW_HPP 2 #define MAINWINDOW_HPP 3 /* 4 Copyright © 2008-13 Qtrac Ltd. All rights reserved. 5 This program or module is free software: you can redistribute it 6 and/or modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation, either version 2 of 8 the License, or (at your option) any later version. This program is 9 distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 for more details. 13 */ 14 15 #include "generic.hpp" 16 #include "saveform.hpp" 17 #if QT_VERSION >= 0x040600 18 #include <QSharedPointer> 19 #else 20 #include <tr1/memory> 21 #endif 22 #include <poppler-qt5.h> 23 #include <QBrush> 24 #include <QList> 25 #include <QMainWindow> 26 #include <QPen> 27 28 class AboutForm; 29 class HelpForm; 30 class Label; 31 class LineEdit; 32 class QBoxLayout; 33 class QCheckBox; 34 class QComboBox; 35 class QGroupBox; 36 class QLabel; 37 class QLineEdit; 38 class QPlainTextEdit; 39 class QPushButton; 40 class QRadioButton; 41 class QScrollArea; 42 class QSpinBox; 43 class QSplitter; 44 45 46 class MainWindow : public QMainWindow 47 { 48 Q_OBJECT 49 50 public: 51 MainWindow(const Debug debug, 52 const InitialComparisonMode comparisonMode, 53 const QString &filename1, const QString &filename2, 54 const QString &language, QWidget *parent=0); 55 56 protected: 57 void closeEvent(QCloseEvent *event); 58 bool eventFilter(QObject *object, QEvent *event); 59 60 private slots: 61 void setFile1(QString filename=QString()); 62 void setFile2(QString filename=QString()); 63 void setFiles1(const QStringList &filenames); 64 void setFiles2(const QStringList &filenames); 65 void compare(); 66 void options(); 67 void save(); 68 void about(); 69 void help(); 70 void initialize(const QString &filename1, const QString &filename2); 71 void updateUi(); 72 void updateViews(int index=-1); 73 void controlDockLocationChanged(Qt::DockWidgetArea area); 74 void actionDockLocationChanged(Qt::DockWidgetArea area); 75 void zoningDockLocationChanged(Qt::DockWidgetArea area); 76 void marginsDockLocationChanged(Qt::DockWidgetArea area); 77 void controlTopLevelChanged(bool floating); 78 void actionTopLevelChanged(bool floating); 79 void zoningTopLevelChanged(bool floating); 80 void marginsTopLevelChanged(bool floating); 81 void logTopLevelChanged(bool floating); 82 void previousPages(); 83 void nextPages(); 84 void showZones(); 85 void showMargins(); 86 void setAMargin(const QPoint &pos); 87 88 private: 89 enum Difference {NoDifference, TextualDifference, VisualDifference}; 90 91 void createWidgets(const QString &filename1, const QString &filename2); 92 void createCentralArea(); 93 void createDockWidgets(); 94 void createConnections(); 95 const QPair<int, int> comparePages(const QString &filename1, 96 const PdfDocument &pdf1, const QString &filename2, 97 const PdfDocument &pdf2); 98 void comparePrepareUi(); 99 void compareUpdateUi(const QPair<int, int> &pair, const int millisec); 100 int writeFileInfo(const QString &filename); 101 void writeLine(const QString &text); 102 void writeError(const QString &text); 103 PdfDocument getPdf(const QString &filename); 104 QList<int> getPageList(int which, PdfDocument pdf); 105 Difference getTheDifference(PdfPage page1, PdfPage page2); 106 void paintOnImage(const QPainterPath &path, QImage *image); 107 const QPair<QPixmap, QPixmap> populatePixmaps(const PdfDocument &pdf1, 108 const PdfPage &page1, const PdfDocument &pdf2, 109 const PdfPage &page2, bool hasVisualDifference, 110 const QString &key1, const QString &key2); 111 void computeTextHighlights(QPainterPath *highlighted1, 112 QPainterPath *highlighted2, const PdfPage &page1, 113 const PdfPage &page2, const int DPI); 114 void computeVisualHighlights(QPainterPath *highlighted1, 115 QPainterPath *highlighted2, const QImage &plainImage1, 116 const QImage &plainImage2); 117 void addHighlighting(QRectF *bigRect, QPainterPath *highlighted, 118 const QRectF wordOrCharRect, const int OVERLAP, const int DPI, 119 const bool COMBINE=true); 120 const QPair<QString, QString> cacheKeys(const int index, 121 const PagePair &pair) const; 122 const TextBoxList zoneYxOrdered(const TextBoxList &list); 123 void showZones(const int Width, const TextBoxList &list, 124 QLabel *label); 125 void showMargins(QLabel *label); 126 void saveAsPdf(const int start, const int end, const PdfDocument &pdf1, 127 const PdfDocument &pdf2, const QString &header); 128 bool paintSaveAs(QPainter *painter, const int index, 129 const PdfDocument &pdf1, const PdfDocument &pdf2, 130 const QString &header, const QRect &rect, 131 const QRect &leftRect, const QRect &rightRect); 132 void saveAsImages(const int start, const int end, 133 const PdfDocument &pdf1, const PdfDocument &pdf2, 134 const QString &header); 135 void computeImageOffsets(const QSize &size, int *x, int *y, 136 int *width, int *height); 137 QRectF pointRectForMargins(const QSize &size); 138 QRect pixelRectForMargins(const QSize &size); 139 140 QPushButton *setFile1Button; 141 LineEdit *filename1LineEdit; 142 QLabel *comparePages1Label; 143 QLineEdit *pages1LineEdit; 144 Label *page1Label; 145 QScrollArea *area1; 146 QPushButton *setFile2Button; 147 LineEdit *filename2LineEdit; 148 QLabel *comparePages2Label; 149 QLineEdit *pages2LineEdit; 150 Label *page2Label; 151 QScrollArea *area2; 152 QComboBox *compareComboBox; 153 QLabel *compareLabel; 154 QLabel *viewDiffLabel; 155 QPushButton *compareButton; 156 QComboBox *viewDiffComboBox; 157 QPushButton *previousButton; 158 QPushButton *nextButton; 159 QLabel *statusLabel; 160 QLabel *zoomLabel; 161 QSpinBox *zoomSpinBox; 162 QLabel *showLabel; 163 QComboBox *showComboBox; 164 QPushButton *optionsButton; 165 QPushButton *saveButton; 166 QPushButton *aboutButton; 167 QPushButton *helpButton; 168 QPushButton *quitButton; 169 QPlainTextEdit *logEdit; 170 QSplitter *splitter; 171 QBoxLayout *controlLayout; 172 QDockWidget *controlDockWidget; 173 QBoxLayout *actionLayout; 174 QDockWidget *actionDockWidget; 175 QDockWidget *logDockWidget; 176 QBoxLayout *compareLayout; 177 QGroupBox *zoningGroupBox; 178 QLabel *columnsLabel; 179 QSpinBox *columnsSpinBox; 180 QLabel *toleranceRLabel; 181 QSpinBox *toleranceRSpinBox; 182 QLabel *toleranceYLabel; 183 QSpinBox *toleranceYSpinBox; 184 QCheckBox *showZonesCheckBox; 185 QBoxLayout *zoningLayout; 186 QDockWidget *zoningDockWidget; 187 QGroupBox *marginsGroupBox; 188 QLabel *topMarginLabel; 189 QSpinBox *topMarginSpinBox; 190 QLabel *bottomMarginLabel; 191 QSpinBox *bottomMarginSpinBox; 192 QLabel *leftMarginLabel; 193 QSpinBox *leftMarginSpinBox; 194 QLabel *rightMarginLabel; 195 QSpinBox *rightMarginSpinBox; 196 QBoxLayout *marginsLayout; 197 QDockWidget *marginsDockWidget; 198 199 QBrush brush; 200 QPen pen; 201 QString currentPath; 202 Qt::DockWidgetArea controlDockArea; 203 Qt::DockWidgetArea actionDockArea; 204 Qt::DockWidgetArea marginsDockArea; 205 Qt::DockWidgetArea zoningDockArea; 206 Qt::DockWidgetArea logDockArea; 207 bool cancel; 208 bool showToolTips; 209 bool combineTextHighlighting; 210 QString saveFilename; 211 bool saveAll; 212 SavePages savePages; 213 const QString language; 214 Debug debug; 215 AboutForm *aboutForm; 216 HelpForm *helpForm; 217 }; 218 219 #endif // MAINWINDOW_HPP 220 221