20 #include "FdSubWindow.hpp"
22 #include "FdMainWindow.hpp"
23 #include "FdDialogPrintOptions.hpp"
24 #include "../data/FdModelCoa.hpp"
25 #include "../data/FdModelJournal.hpp"
26 #include "../data/FdModelResults.hpp"
27 #include "widgets/FdViewCoa.hpp"
28 #include "widgets/FdViewJournal.hpp"
29 #include "widgets/FdViewResults.hpp"
30 #include "widgets/FdViewAccountSummary.hpp"
31 #include "../data/FdItemCoa.hpp"
45 mInitialDate(initialDate),
46 mFinalDate(finalDate),
47 mCorporation(corporation),
49 mAccountant(accountant)
70 QDomDocument document(
"freedebks");
71 mFile->open(QIODevice::ReadOnly | QIODevice::Text);
72 document.setContent(mFile);
75 QDomElement accounting = document.namedItem(
"Accounting").toElement();
76 setLabel(accounting.attribute(
"Label"));
77 mCurrency = accounting.attribute(
"Currency");
78 mInitialDate = QDate().fromString(accounting.attribute(
"InitialDate"),
"yyyy.MM.dd");
79 mFinalDate = QDate().fromString(accounting.attribute(
"FinalDate"),
"yyyy.MM.dd");
80 mCorporation = accounting.attribute(
"Corporation");
81 mLogo = accounting.attribute(
"Logo");
82 mAccountant = accounting.attribute(
"Accountant");
84 QDomElement coa = accounting.namedItem(
"Coa").toElement();
85 QDomElement journal = accounting.namedItem(
"Journal").toElement();
86 QDomElement results = accounting.namedItem(
"Results").toElement();
105 setLabel(previousYear->
label());
106 mCurrency = previousYear->
currency();
108 mInitialDate = QDate(initial.year()+1, initial.month(), initial.day());
110 mFinalDate = QDate(
final.year()+1,
final.month(),
final.day());
111 mLogo = previousYear->
logo();
129 mViewCoa->setProperty(
"TabRole", TabRole(CoaRole));
130 mViewJournal->setProperty(
"TabRole", TabRole(JournalRole));
131 mViewResults->setProperty(
"TabRole", TabRole(ResultsRole));
135 mTab =
new QTabWidget;
136 mTab->setTabsClosable(
true);
137 connect(
mTab, SIGNAL(tabCloseRequested(
int)),
this, SLOT(
closeTab(
int)));
138 mTab->addTab(
mViewCoa, tr(
"Chart of accounts",
"Tab title."));
143 connect(
this, SIGNAL(aboutToActivate()),
this, SLOT(
newActiveTab()));
167 setWindowTitle(
mLabel+
"[*]");
237 if(
mFile->fileName() ==
"")
241 QDomDocument document(
"freedebks");
243 QDomElement accounting = document.createElement(
"Accounting");
244 accounting.setAttribute(
"Label",
mLabel);
245 accounting.setAttribute(
"Currency", mCurrency);
246 accounting.setAttribute(
"InitialDate",
mInitialDate.toString(
"yyyy.MM.dd"));
247 accounting.setAttribute(
"FinalDate",
mFinalDate.toString(
"yyyy.MM.dd"));
249 accounting.setAttribute(
"Logo",
mLogo);
250 accounting.setAttribute(
"Accountant",
mAccountant);
251 document.appendChild(accounting);
254 accounting.appendChild(coa);
256 QDomElement journal = mJournal->
toXml(document);
257 accounting.appendChild(journal);
260 accounting.appendChild(results);
262 mFile->open(QIODevice::WriteOnly | QIODevice::Text);
263 QTextStream stream(
mFile);
264 document.save(stream, 4);
269 setWindowModified(
false);
275 mFile->setFileName(file);
281 QPrinter printer(QPrinter::HighResolution);
282 QPrintDialog dialog(&printer,
this);
283 dialog.setOption(QAbstractPrintDialog::PrintPageRange,
false);
285 if(dialog.exec() == QDialog::Accepted)
289 if(options.exec() == QDialog::Accepted)
291 QStringList elements = options.selectedElements();
294 printer.setPageMargins(10,10,10,10, QPrinter::Millimeter);
296 if((elements[PrintJournal].toInt() || elements[PrintAccounts].toInt()) && !elements[PrintCoa].toInt() && !elements[PrintResults].toInt())
297 printer.setOrientation(QPrinter::Landscape);
299 printer.setOrientation(QPrinter::Portrait);
301 painter.begin(&printer);
309 if(elements[PrintCoa].toInt())
310 pageNumber =
mViewCoa->
print(printer, painter, area, remainingArea);
313 if(elements[PrintResults].toInt())
316 if((elements[PrintCoa].toInt() || elements[PrintResults].toInt()) && (elements[PrintJournal].toInt() || elements[PrintAccounts].toInt()))
318 printer.setOrientation(QPrinter::Landscape);
324 if(elements[PrintJournal].toInt())
328 if(elements[PrintAccounts].toInt())
331 remainingArea = area;
332 if(elements[PrintCoa].toInt() || elements[PrintResults].toInt() || elements[PrintResults].toInt())
335 FdSubWindow::printTitle(painter, remainingArea, tr(
"Accounts summaries",
"Accounts summaries title on printed page."));
339 for(
int i = 4; i < elements.size(); ++i)
343 if(mJournal->isUsed(account))
346 pageNumber = accountView->
print(printer, painter, area, remainingArea,
this, pageNumber);
347 accountView->deleteLater();
360 int x = printer.pageRect().x();
361 int y = printer.pageRect().y();
362 int width = printer.pageRect().width()-2*x;
363 int height = printer.pageRect().height()-2*y;
364 return QRect(x, y+700, width, height-700);
371 int x = printer.pageRect().x();
372 int y = printer.pageRect().y();
373 int width = printer.pageRect().width()-2*x;
374 int height = printer.pageRect().height()-2*y;
375 QRect header(x, y-300, width, 600);
376 QRect footer(x, y+height+200, width, 200);
380 QFont textFont = painter.font();
381 textFont.setPointSize(10);
382 textFont.setBold(
true);
383 painter.setFont(textFont);
384 painter.setPen(Qt::black);
393 logo.load(QFileInfo(*mFile).path()+
"/"+
mLogo);
397 logo = logo.scaledToHeight(header.height(), Qt::SmoothTransformation);
398 logoWidth = logo.size().width();
399 rect.setRect(header.right()-logoWidth, header.y(), logoWidth, header.height());
400 painter.drawImage(rect, logo);
404 rect.setRect(header.x(), header.y(), header.width()-logoWidth-100, rowHeight);
406 rect.setRect(header.x(), header.y()+rowHeight, header.width()-logoWidth-100, rowHeight);
407 painter.drawText(rect, Qt::AlignRight,
mLabel);
408 rect.setRect(header.x(), header.y()+2*rowHeight, header.width()-logoWidth-100, rowHeight);
409 painter.drawText(rect, Qt::AlignRight,
mAccountant);
411 textFont.setBold(
false);
412 painter.setFont(textFont);
414 painter.drawText(footer, Qt::AlignLeft, document);
415 painter.drawText(footer, Qt::AlignRight, QString::number(page));
426 QFont font = painter.font();
427 font.setPointSize(24);
431 painter.setFont(font);
432 painter.setPen(Qt::black);
433 painter.drawText(QRect(x, y, area.width(), area.height()), Qt::AlignLeft, title);
435 area.setRect(x, y+800, area.width(), area.height()-800);
443 QFont font = painter.font();
444 font.setPointSize(16);
448 painter.setFont(font);
449 painter.setPen(Qt::black);
450 painter.drawText(QRect(x, y, area.width(), area.height()), Qt::AlignLeft, subtitle);
453 area.setRect(x, y+350, area.width(), area.height()-350);
462 QFont font = painter.font();
463 font.setPointSize(10);
465 painter.setFont(font);
467 QRect rect(x, y, area.width(), rowHeight);
468 painter.fillRect(rect, QColor(Qt::lightGray));
470 for(
int i = 0; i < elements.size(); ++i)
472 rect.setRect(x, y, elements[i]->width, rowHeight);
473 painter.drawText(rect, elements[i]->alignement, elements[i]->text);
474 x += elements[i]->width;
477 area.setRect(area.x(), area.y()+rowHeight, area.width(), area.height()-rowHeight);
486 QFont font = painter.font();
487 font.setPointSize(10);
489 painter.setFont(font);
491 painter.setPen(Qt::black);
492 painter.drawLine(x, y+rowHeight, x+area.width(), y+rowHeight);
495 for(
int i = 0; i < elements.size(); ++i)
497 rect.setRect(x, y, elements[i]->width, rowHeight);
498 painter.setPen(elements[i]->color);
499 painter.drawText(rect, elements[i]->alignement, elements[i]->text);
500 x += elements[i]->width;
503 area.setRect(area.x(), area.y()+rowHeight, area.width(), area.height()-rowHeight);
504 if(area.height() < rowHeight)
513 if(isWindowModified())
515 int ret = QMessageBox::question(
this,
516 tr(
"%1 has been modified.",
"Text displayed in a message box when trying to close an unsaved subwindow. The argument is a subwindow title, ie a bookkeeping label.").arg(
mLabel),
517 tr(
"Do you want to save your changes ?"),
518 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
529 setWindowModified(
false);
557 else if(role == JournalRole)
562 else if(role == ResultsRole)
596 text = mJournal->
data(
mViewCoa->currentIndex()).toString();
603 text = view->model()->data(view->currentIndex()).toString();
607 QApplication::clipboard()->setText(text);
642 account = mJournal->selectedAccount(
mViewJournal->currentIndex());
650 mTab->addTab(tab, QString(account->displayLabel()));
651 mTab->setCurrentIndex(
mTab->indexOf(tab));
659 mTab->setCurrentIndex(1);
672 mJournal->orderByDate();
683 mJournal->orderByDate();
694 if(selected.isValid())
696 mJournal->copyFromPreviousLine(selected);
701 mJournal->addEntry();
704 mJournal->copyFromPreviousLine(
mViewJournal->currentIndex());
714 QWidget* tab =
mTab->widget(
mTab->currentIndex());
715 return TabRole(tab->property(
"TabRole").toInt());
737 redo = mJournal->
redo();
738 undo = mJournal->
undo();
752 redo =
new QAction(0);
753 undo =
new QAction(0);
754 redo->setDisabled(
true);
755 undo->setDisabled(
true);
760 mainWindow->activeTabChanged(role, undo, redo, isWindowModified());
768 TabRole role = TabRole(
mTab->widget(index)->property(
"TabRole").toInt());
773 mTab->widget(index)->deleteLater();
774 mTab->removeTab(index);
786 if(!isWindowModified() && !clean)
788 setWindowModified(
true);