20 #include "FdMainWindow.hpp"
22 #include <QMdiSubWindow>
23 #include <QFileDialog>
25 #include "FdSubWindow.hpp"
26 #include "FdDialogBkgProperties.hpp"
35 QString file = QString::fromUtf8(qApp->argv()[1]);
37 FdMainWindow::self =
this;
41 settings.beginGroup(
"MainWindow");
42 resize(settings.value(
"size", QSize(1000, 650)).toSize());
43 move(settings.value(
"pos", QPoint(200, 200)).toPoint());
44 QStringList files = settings.value(
"RecentFilesOpened").toStringList();
48 for(
int i = 0; i < files.size(); ++i)
49 mRecentOpenedFiles << createOpenRecentFileAction(files[i]);
51 menuOpenRecent->addActions(mRecentOpenedFiles);
53 menuOpenRecent->setEnabled(
false);
58 menuOpenRecent->setIcon(QIcon::fromTheme(
"document-open-recent",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-open-recent.png")));
61 actionNew->setIcon(QIcon::fromTheme(
"document-new",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-new.png")));
62 actionOpen->setIcon(QIcon::fromTheme(
"document-open",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-open.png")));
63 actionSave->setIcon(QIcon::fromTheme(
"document-save",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-save.png")));
64 actionSaveAs->setIcon(QIcon::fromTheme(
"document-save-as",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-save-as.png")));
65 actionPrint->setIcon(QIcon::fromTheme(
"document-print",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-print.png")));
66 actionClose->setIcon(QIcon::fromTheme(
"window-close",QIcon(DIR_PREFIX +
"/share/freedebks/icons/window-close.png")));
67 actionQuit->setIcon(QIcon::fromTheme(
"application-exit",QIcon(DIR_PREFIX +
"/share/freedebks/icons/application-exit.png")));
70 actionAddLine->setIcon(QIcon::fromTheme(
"list-add",QIcon(DIR_PREFIX +
"/share/freedebks/icons/list-add.png")));
71 actionRemoveSelected->setIcon(QIcon::fromTheme(
"list-remove",QIcon(DIR_PREFIX +
"/share/freedebks/icons/list-remove.png")));
72 actionCopy->setIcon(QIcon::fromTheme(
"edit-copy",QIcon(DIR_PREFIX +
"/share/freedebks/icons/edit-copy.png")));
73 actionFindNext->setIcon(QIcon::fromTheme(
"system-search",QIcon(DIR_PREFIX +
"/share/freedebks/icons/system-search.png")));
75 actionOrderByDate->setIcon(QIcon::fromTheme(
"view-sort-ascending",QIcon(DIR_PREFIX +
"/share/freedebks/icons/view-sort-ascending.png")));
76 actionCopyPreviousLine->setIcon(QIcon::fromTheme(
"go-bottom",QIcon(DIR_PREFIX +
"/share/freedebks/icons/go-bottom.png")));
78 actionEditProperties->setIcon(QIcon::fromTheme(
"document-properties",QIcon(DIR_PREFIX +
"/share/freedebks/icons/document-properties.png")));
79 actionRecomputeAll->setIcon(QIcon::fromTheme(
"view-refresh",QIcon(DIR_PREFIX +
"/share/freedebks/icons/view-refresh.png")));
82 actionHelp->setIcon(QIcon::fromTheme(
"help-contents",QIcon(DIR_PREFIX +
"/share/freedebks/icons/help-contents.png")));
83 actionAbout->setIcon(QIcon::fromTheme(
"help-about",QIcon(DIR_PREFIX +
"/share/freedebks/icons/help-about.png")));
85 menuOpenRecent->setIcon(QIcon::fromTheme(
"document-open-recent",QIcon(
":/buttons/document-open-recent")));
88 actionNew->setIcon(QIcon::fromTheme(
"document-new",QIcon(
":/buttons/document-new")));
89 actionOpen->setIcon(QIcon::fromTheme(
"document-open",QIcon(
":/buttons/document-open")));
90 actionSave->setIcon(QIcon::fromTheme(
"document-save",QIcon(
":/buttons/document-save")));
91 actionSaveAs->setIcon(QIcon::fromTheme(
"document-save-as",QIcon(
":/buttons/document-save-as")));
92 actionPrint->setIcon(QIcon::fromTheme(
"document-print",QIcon(
":/buttons/document-print")));
93 actionClose->setIcon(QIcon::fromTheme(
"window-close",QIcon(
":/buttons/window-close")));
94 actionQuit->setIcon(QIcon::fromTheme(
"application-exit",QIcon(
":/buttons/application-exit")));
96 actionAddLine->setIcon(QIcon::fromTheme(
"list-add",QIcon(
":/buttons/list-add")));
97 actionRemoveSelected->setIcon(QIcon::fromTheme(
"list-remove",QIcon(
":/buttons/list-remove")));
98 actionCopy->setIcon(QIcon::fromTheme(
"edit-copy",QIcon(
":/buttons/edit-copy")));
99 actionFindNext->setIcon(QIcon::fromTheme(
"system-search",QIcon(
":/buttons/system-search")));
101 actionOrderByDate->setIcon(QIcon::fromTheme(
"view-sort-ascending",QIcon(
":/buttons/view-sort-ascending")));
102 actionCopyPreviousLine->setIcon(QIcon::fromTheme(
"go-bottom",QIcon(
":/buttons/go-bottom")));
104 actionEditProperties->setIcon(QIcon::fromTheme(
"document-properties",QIcon(
":/buttons/document-properties")));
105 actionRecomputeAll->setIcon(QIcon::fromTheme(
"view-refresh",QIcon(
":/buttons/view-refresh")));
108 actionHelp->setIcon(QIcon::fromTheme(
"help-contents",QIcon(
":/buttons/help-contents")));
109 actionAbout->setIcon(QIcon::fromTheme(
"help-about",QIcon(
":/buttons/help-about")));
113 actionNew->setShortcut(QKeySequence::New);
114 actionOpen->setShortcut(QKeySequence::Open);
115 actionSave->setShortcut(QKeySequence::Save);
116 actionSaveAs->setShortcut(QKeySequence::SaveAs);
117 actionPrint->setShortcut(QKeySequence::Print);
118 actionClose->setShortcut(QKeySequence::Close);
119 actionQuit->setShortcut(QKeySequence::Quit);
120 actionCopy->setShortcut(QKeySequence::Copy);
121 actionFindNext->setShortcut(QKeySequence::FindNext);
122 actionRecomputeAll->setShortcut(QKeySequence::Refresh);
124 menuHelp->addAction(QWhatsThis::createAction());
127 mContextMenuActionsEdit << actionAddLine << actionRemoveSelected << actionCopy;
128 mContextMenuActionsCoa << actionRecomputeAll << actionShowAccount;
129 mContextMenuActionsJournal << actionOrderByDate << actionCopyPreviousLine << actionShowAccount << actionRecomputeAll;
130 mContextMenuActionsResults << actionRecomputeAll;
131 mContextMenuActionsAccount << actionCopy << actionShowAccount << actionShowEntry << actionRecomputeAll;
142 actionSave->setEnabled(value);
147 actionRemoveSelected->setEnabled(value);
152 actionShowAccount->setEnabled(value);
157 actionShowEntry->setEnabled(value);
191 text = tr(
"<b>Welcome in FreeDebks !</b>");
193 dockContent->setText(text);
201 int size = mdiArea->subWindowList().size();
203 for(
int i = 0; i < size; ++i)
205 mdiArea->activateNextSubWindow();
217 for(
int i = 0; i < max; ++i)
221 settings.beginGroup(
"MainWindow");
222 settings.setValue(
"size", this->size());
223 settings.setValue(
"pos", pos());
224 settings.setValue(
"RecentFilesOpened", files);
233 QAction* action =
new QAction(
this);
234 action->setText(QFileInfo(file).fileName());
235 action->setData(file);
236 connect(action, SIGNAL(triggered()),
this, SLOT(
openRecentFile()));
258 menuOpenRecent->clear();
260 menuOpenRecent->setEnabled(
true);
276 QString file = QFileDialog::getOpenFileName(
this, QObject::tr(
"Select a file to open"), QDir::homePath(),
277 QObject::tr(
"FreeDebks files (*.fds);;XML files (*.xml);;Any type (*.*)",
"File format, so leave (*.fds), (*.xml) and (*.*) unchanged."));
284 QFile* file =
new QFile(filePath);
293 QMessageBox::warning(
this, tr(
"File not found",
"File to open not found."),
294 tr(
"Impossible to open the file you requested. Please make sure it exists."));
300 QAction *action = qobject_cast<QAction *>(sender());
302 open(action->data().toString());
308 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->save();
313 QString file = QFileDialog::getSaveFileName(qobject_cast<QWidget*>(parent()),
314 QObject::tr(
"Enter a new file name or select an existing file"),
315 QDir::homePath(), QObject::tr(
"FreeDebks files (*.fds);;XML files (*.xml)",
"File format, so leave (*.fds) and (*.xml) unchanged."));
318 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->saveAs(file);
325 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->print();
330 return qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow())->close();
344 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->addLine();
349 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->removeSelected();
354 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->copy();
359 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->findNext();
364 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->recomputeAll();
386 connect(&dialog, SIGNAL(rejected()), newYear, SLOT(deleteLater()));
392 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->journalCopyFromPreviousLine();
401 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->journalOrderByDate();
406 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->showAccount();
411 (qobject_cast<
FdSubWindow*>(mdiArea->currentSubWindow()))->showEntry();
416 QString locale = QLocale::system().name().section(
'_', 0, 0);
419 url = DIR_PREFIX+
"/share/freedebks/documentation/doc_"+locale+
".pdf";
421 url =
"documentation/doc_"+locale+
".pdf";
423 if(QFile(url).exists())
424 QDesktopServices::openUrl(url);
426 QDesktopServices::openUrl(QUrl(
"http://freedebks.sourceforge.net/documentation/en/"));
432 QMessageBox::about(
this,
"About FreeDebks", QString(
"<b>FreeDebks version %1</b><br />"
433 "Distributed under GPLv3.<br />"
434 "Copyright (c) Mathieu Schopfer (mathieus@users.sourceforge.net)<br />"
435 "Visit the application website at <a href = %2>%2</a>."
436 ).arg(qApp->applicationVersion(), qApp->organizationDomain()));
446 mdiArea->addSubWindow(subwindow);
447 subwindow->showMaximized();
460 actionAddLine->setEnabled(
true);
461 actionOrderByDate->setEnabled(
false);
462 actionCopyPreviousLine->setEnabled(
false);
463 actionShowEntry->setEnabled(
false);
466 actionAddLine->setEnabled(
true);
467 actionOrderByDate->setEnabled(
true);
468 actionCopyPreviousLine->setEnabled(
true);
469 actionShowEntry->setEnabled(
false);
472 actionAddLine->setEnabled(
true);
473 actionOrderByDate->setEnabled(
false);
474 actionCopyPreviousLine->setEnabled(
false);
475 actionShowEntry->setEnabled(
false);
478 actionAddLine->setEnabled(
false);
479 actionOrderByDate->setEnabled(
false);
480 actionCopyPreviousLine->setEnabled(
false);
485 actionSaveAs->setEnabled(
true);
486 actionPrint->setEnabled(
true);
487 actionClose->setEnabled(
true);
489 actionCopy->setEnabled(
true);
490 actionFindNext->setEnabled(
true);
492 actionRecomputeAll->setEnabled(
true);
493 actionEditProperties->setEnabled(
true);
494 actionCreateNewYear->setEnabled(
true);
500 actionSaveAs->setDisabled(
true);
501 actionPrint->setDisabled(
true);
502 actionClose->setDisabled(
true);
504 actionAddLine->setDisabled(
true);
505 actionRemoveSelected->setDisabled(
true);
506 actionCopy->setDisabled(
true);
507 actionFindNext->setDisabled(
true);
509 actionOrderByDate->setDisabled(
true);
510 actionCopyPreviousLine->setDisabled(
true);
512 actionRecomputeAll->setDisabled(
true);
513 actionEditProperties->setDisabled(
true);
514 actionCreateNewYear->setDisabled(
true);
516 actionShowAccount->setDisabled(
true);
517 actionShowEntry->setDisabled(
true);
519 undo->setDisabled(
true);
520 redo->setDisabled(
true);
523 toolBarUndoRedo->clear();
524 undo->setIcon(QIcon::fromTheme(
"edit-undo",QIcon(
":/buttons/edit-undo")));
525 undo->setShortcut(QKeySequence::Undo);
526 redo->setIcon(QIcon::fromTheme(
"edit-redo",QIcon(
":/buttons/edit-redo")));
527 redo->setShortcut(QKeySequence::Redo);
528 toolBarUndoRedo->addAction(undo);
529 toolBarUndoRedo->addAction(redo);
541 if(!mdiArea->subWindowList().size()-1)