forked from Tulon/scantailor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.h
305 lines (216 loc) · 7.85 KB
/
MainWindow.h
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
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program 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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
#include "ui_MainWindow.h"
#include "FilterUiInterface.h"
#include "NonCopyable.h"
#include "AbstractCommand.h"
#include "IntrusivePtr.h"
#include "BackgroundTask.h"
#include "FilterResult.h"
#include "ThumbnailSequence.h"
#include "OutputFileNameGenerator.h"
#include "PageId.h"
#include "PageView.h"
#include "PageRange.h"
#include "SelectedPage.h"
#include "BeforeOrAfter.h"
#include <boost/function.hpp>
#include <QMainWindow>
#include <QString>
#include <QPointer>
#include <QObjectCleanupHandler>
#include <QSizeF>
#include <memory>
#include <vector>
#include <set>
class AbstractFilter;
class AbstractRelinker;
class ThumbnailPixmapCache;
class ProjectPages;
class PageSequence;
class StageSequence;
class PageOrderProvider;
class PageSelectionAccessor;
class FilterOptionsWidget;
class ProcessingIndicationWidget;
class ImageInfo;
class PageInfo;
class QStackedLayout;
class WorkerThread;
class ProjectReader;
class DebugImages;
class ContentBoxPropagator;
class PageOrientationPropagator;
class ProjectCreationContext;
class ProjectOpeningContext;
class CompositeCacheDrivenTask;
class TabbedDebugImages;
class ProcessingTaskQueue;
class FixDpiDialog;
class OutOfMemoryDialog;
class QLineF;
class QRectF;
class QLayout;
class MainWindow :
public QMainWindow,
private FilterUiInterface,
private Ui::MainWindow
{
DECLARE_NON_COPYABLE(MainWindow)
Q_OBJECT
public:
MainWindow();
virtual ~MainWindow();
PageSequence allPages() const;
std::set<PageId> selectedPages() const;
std::vector<PageRange> selectedRanges() const;
protected:
virtual void closeEvent(QCloseEvent* event);
virtual void timerEvent(QTimerEvent* event);
public slots:
void openProject(QString const& project_file);
private:
enum MainAreaAction { UPDATE_MAIN_AREA, CLEAR_MAIN_AREA };
private slots:
void goFirstPage();
void goLastPage();
void goNextPage();
void goPrevPage();
void goToPage(PageId const& page_id);
void currentPageChanged(
PageInfo const& page_info, QRectF const& thumb_rect,
ThumbnailSequence::SelectionFlags flags);
void pageContextMenuRequested(
PageInfo const& page_info, QPoint const& screen_pos, bool selected);
void pastLastPageContextMenuRequested(QPoint const& screen_pos);
void thumbViewFocusToggled(bool checked);
void thumbViewScrolled();
void filterSelectionChanged(QItemSelection const& selected);
void pageOrderingChanged(int idx);
void reloadRequested();
void startBatchProcessing();
void stopBatchProcessing(MainAreaAction main_area = UPDATE_MAIN_AREA);
void invalidateThumbnail(PageId const& page_id);
void invalidateThumbnail(PageInfo const& page_info);
void invalidateAllThumbnails();
void showRelinkingDialog();
void filterResult(
BackgroundTaskPtr const& task,
FilterResultPtr const& result);
void debugToggled(bool enabled);
void fixDpiDialogRequested();
void fixedDpiSubmitted();
void saveProjectTriggered();
void saveProjectAsTriggered();
void newProject();
void newProjectCreated(ProjectCreationContext* context);
void openProject();
void projectOpened(ProjectOpeningContext* context);
void closeProject();
void openSettingsDialog();
void showAboutDialog();
void handleOutOfMemorySituation();
private:
class PageSelectionProviderImpl;
enum SavePromptResult { SAVE, DONT_SAVE, CANCEL };
typedef IntrusivePtr<AbstractFilter> FilterPtr;
virtual void setOptionsWidget(
FilterOptionsWidget* widget, Ownership ownership);
virtual void setImageWidget(
QWidget* widget, Ownership ownership,
DebugImages* debug_images = 0);
virtual IntrusivePtr<AbstractCommand0<void> > relinkingDialogRequester();
void switchToNewProject(
IntrusivePtr<ProjectPages> const& pages,
QString const& out_dir,
QString const& project_file_path = QString(),
ProjectReader const* project_reader = 0);
IntrusivePtr<ThumbnailPixmapCache> createThumbnailCache();
void setupThumbView();
void showNewOpenProjectPanel();
SavePromptResult promptProjectSave();
static bool compareFiles(QString const& fpath1, QString const& fpath2);
IntrusivePtr<PageOrderProvider const> currentPageOrderProvider() const;
void updateSortOptions();
void resetThumbSequence(
IntrusivePtr<PageOrderProvider const> const& page_order_provider);
void removeWidgetsFromLayout(QLayout* layout);
void removeFilterOptionsWidget();
void removeImageWidget();
void updateProjectActions();
bool isBatchProcessingInProgress() const;
bool isProjectLoaded() const;
bool isBelowSelectContent() const;
bool isBelowSelectContent(int filter_idx) const;
bool isBelowFixOrientation(int filter_idx) const;
bool isOutputFilter() const;
bool isOutputFilter(int filter_idx) const;
PageView getCurrentView() const;
void updateMainArea();
bool checkReadyForOutput(PageId const* ignore = 0) const;
void loadPageInteractive(PageInfo const& page);
void updateWindowTitle();
bool closeProjectInteractive();
void closeProjectWithoutSaving();
bool saveProjectWithFeedback(QString const& project_file);
void showInsertFileDialog(
BeforeOrAfter before_or_after, ImageId const& existig);
void showRemovePagesDialog(std::set<PageId> const& pages);
void insertImage(ImageInfo const& new_image,
BeforeOrAfter before_or_after, ImageId existing);
void removeFromProject(std::set<PageId> const& pages);
void eraseOutputFiles(std::set<PageId> const& pages);
BackgroundTaskPtr createCompositeTask(
PageInfo const& page, int last_filter_idx, bool batch, bool debug);
IntrusivePtr<CompositeCacheDrivenTask>
createCompositeCacheDrivenTask(int last_filter_idx);
void createBatchProcessingWidget();
void updateDisambiguationRecords(PageSequence const& pages);
void performRelinking(IntrusivePtr<AbstractRelinker> const& relinker);
PageSelectionAccessor newPageSelectionAccessor();
QSizeF m_maxLogicalThumbSize;
IntrusivePtr<ProjectPages> m_ptrPages;
IntrusivePtr<StageSequence> m_ptrStages;
QString m_projectFile;
OutputFileNameGenerator m_outFileNameGen;
IntrusivePtr<ThumbnailPixmapCache> m_ptrThumbnailCache;
std::auto_ptr<ThumbnailSequence> m_ptrThumbSequence;
std::auto_ptr<WorkerThread> m_ptrWorkerThread;
std::auto_ptr<ProcessingTaskQueue> m_ptrBatchQueue;
std::auto_ptr<ProcessingTaskQueue> m_ptrInteractiveQueue;
QStackedLayout* m_pImageFrameLayout;
QStackedLayout* m_pOptionsFrameLayout;
QPointer<FilterOptionsWidget> m_ptrOptionsWidget;
QPointer<FixDpiDialog> m_ptrFixDpiDialog;
std::auto_ptr<TabbedDebugImages> m_ptrTabbedDebugImages;
std::auto_ptr<ContentBoxPropagator> m_ptrContentBoxPropagator;
std::auto_ptr<PageOrientationPropagator> m_ptrPageOrientationPropagator;
std::auto_ptr<QWidget> m_ptrBatchProcessingWidget;
std::auto_ptr<ProcessingIndicationWidget> m_ptrProcessingIndicationWidget;
boost::function<bool()> m_checkBeepWhenFinished;
SelectedPage m_selectedPage;
QObjectCleanupHandler m_optionsWidgetCleanup;
QObjectCleanupHandler m_imageWidgetCleanup;
std::auto_ptr<OutOfMemoryDialog> m_ptrOutOfMemoryDialog;
int m_curFilter;
int m_ignoreSelectionChanges;
int m_ignorePageOrderingChanges;
bool m_debug;
bool m_closing;
bool m_beepOnBatchProcessingCompletion;
};
#endif