forked from sjg20/paperman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
318 lines (246 loc) · 7.06 KB
/
mainwindow.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
/*
License: GPL-2
An electronic filing cabinet: scan, print, stack, arrange
Copyright (C) 2009 Simon Glass, chch-kiwi@users.sourceforge.net
.
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 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.
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in the /usr/share/common-licenses/GPL file.
*/
#include <QtGui>
#include <QSettings>
#include <qvariant.h>
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include "qstatusbar.h"
#include "qstring.h"
#include "config.h"
#include "ui_about.h"
#include "desktopmodel.h"
#include "desktopundo.h"
#include "desktopwidget.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "pagewidget.h"
/*
* Constructs a Mainwindow as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
*/
Mainwindow::Mainwindow(QWidget* parent, const char* name, Qt::WindowFlags fl)
: QMainWindow(parent, name, fl)
{
_progress = 0;
_label = 0;
setupUi(this);
init();
_welcome_shown = false;
_desktop = _main->getDesktop ();
QSettings qs;
setWindowState(windowState() ^ Qt::WindowFullScreen);
setWindowState(windowState() ^ Qt::WindowMaximized);
restoreGeometry(qs.value("mainwindow/geometry").toByteArray());
restoreState(qs.value("mainwindow/state").toByteArray());
// to stop the status bar rising all the time, set its maximum size
QSize size = QSize (5000, 20);
statusBar ()->setMaximumSize (size);
connect (_main->getDesktop (), SIGNAL (updateDone ()),
this, SLOT (welcome ()));
connect (_main->getDesktop (), SIGNAL (undoChanged ()),
this, SLOT (undoChanged ()));
undoChanged ();
}
/*
* Destroys the object and frees any allocated resources
*/
Mainwindow::~Mainwindow()
{
// no need to delete child widgets, Qt does it all for us
}
void Mainwindow::undoChanged ()
{
Desktopundostack *undo = _main->getDesktop ()->getModel ()->getUndoStack ();
delete actionUndo;
delete actionRedo;
actionUndo = undo->createUndoAction (menuEdit);
actionRedo = undo->createRedoAction (menuEdit);
actionUndo->setShortcut (tr ("Ctrl+Z"));
actionRedo->setShortcut (tr ("Ctrl+Shift+Z"));
menuEdit->insertAction (actionFind, actionUndo);
menuEdit->insertAction (actionFind, actionRedo);
}
void Mainwindow::welcome ()
{
if (!_welcome_shown)
{
statusBar()->showMessage (tr ("Welcome to Maxview, a scanning and filing application to help you manage your paper mountain"), 5000);
_welcome_shown = true;
}
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Mainwindow::languageChange()
{
retranslateUi(this);
}
void Mainwindow::saveSettings ()
{
QSettings settings;
settings.setValue("mainwindow/geometry", saveGeometry());
settings.setValue("mainwindow/state", saveState());
_main->closing ();
}
void Mainwindow::closeEvent(QCloseEvent *event)
{
saveSettings ();
QMainWindow::closeEvent(event);
}
void Mainwindow::init ()
{
connect (_main->getPage (), SIGNAL (newContents (QString)),
this, SLOT (statusUpdate (QString)));
connect (_main, SIGNAL (newContents (QString)),
this, SLOT (statusUpdate (QString)));
connect (_main->getDesktop (), SIGNAL (newContents (QString)),
this, SLOT (statusUpdate (QString)));
}
void Mainwindow::on_actionPrint_activated()
{
_main->print ();
}
void Mainwindow::on_actionExit_activated()
{
saveSettings ();
qApp->quit ();
}
void Mainwindow::on_actionAbout_activated()
{
Ui::About about;
QDialog *widget = new QDialog;
about.setupUi(widget);
about.version->setText (QString ("Version %1: %2, %3").arg (CONFIG_version_str)
.arg (__DATE__).arg (__TIME__));
widget->show ();
widget->exec ();
}
void Mainwindow::on_actionFind_activated()
{
getDesktop()->activateFind ();
}
void Mainwindow::on_actionFullScreen_activated()
{
setWindowState(windowState() ^ Qt::WindowFullScreen);
}
Desktopwidget * Mainwindow::getDesktop()
{
return _main->getDesktop ();
}
void Mainwindow::on_actionSwap_activated()
{
_main->swapDesktop ();
}
void Mainwindow::statusUpdate (QString str)
{
statusBar()->message (str);
}
void Mainwindow::setProgress (int percent, QString name)
{
// initialise
if (percent == -1)
{
statusBar()->clearMessage ();
// printf ("new op '%s'\n", name.latin1 ());
_label = new QLabel (name);
_progress = new QProgressBar ();
_progress->setRange (0, 100);
_progress->setTextVisible (false);
statusBar()->addWidget (_label, false);
statusBar()->addWidget (_progress, true);
QSize size = _progress->sizeHint ();
size = QSize (5000, 20);
_progress->setMaximumSize (size);
size = _progress->sizeHint ();
_progress->show ();
_label->show ();
}
// destroy
else if (percent == -2)
{
delete _progress;
delete _label;
_progress = 0;
}
else if (_progress)
_progress->setValue (percent);
}
void Mainwindow::on_actionScango_activated()
{
_main->scan ();
}
void Mainwindow::on_actionPscan_activated()
{
_main->pscan ();
}
void Mainwindow::on_actionSelectall_activated()
{
_main->selectAll ();
}
void Mainwindow::on_actionByPosition_activated()
{
_main->arrangeBy (Mainwidget::byPosition);
}
void Mainwindow::on_actionByDate_activated()
{
_main->arrangeBy (Mainwidget::byDate);
}
void Mainwindow::on_actionByName_activated()
{
_main->arrangeBy (Mainwidget::byName);
}
void Mainwindow::on_actionResize_all_activated()
{
_main->resizeAll ();
}
void Mainwindow::on_actionRleft_activated()
{
_main->rotate (-90);
}
void Mainwindow::on_actionRright_activated()
{
_main->rotate (90);
}
void Mainwindow::on_actionHflip_activated()
{
_main->flip (1);
}
void Mainwindow::on_actionVflip_activated()
{
_main->flip (0);
}
void Mainwindow::on_actionOptions_activated()
{
_main->options ();
}