00001 #include "mainwindow.h"
00002
00003 #include "../Dialogs/newprojectwizard.h"
00004 #include "../Dialogs/newdocumentdialog.h"
00005 #include "../Dialogs/projectinformationdialog.h"
00006 #include "../Dialogs/aboutdialog.h"
00007 #include "../Dialogs/owncapitalcalculationdialog.h"
00008 #include "../Dialogs/settingsdialog.h"
00009 #include "../Dialogs/updaterdialog.h"
00010 #include "../Dialogs/documentchooser.h"
00011 #include "../Dialogs/manageprojectdialog.h"
00012 #include "../Dialogs/bugreportdialog.h"
00013
00014 #include "../Printing/printpreview.h"
00015
00016 #include "../Models/abstractmodel.h"
00017 #include "../Models/documentchoosermodel.h"
00018
00019 #include "../Data/datadefinitions.h"
00020 #include "../Data/project.h"
00021 #include "../Data/aboutdata.h"
00022
00023 #include "../IO/projectfile.h"
00024
00025 #include "../Childwindows/childwindow.h"
00026 #include "../Childwindows/costtypechild.h"
00027 #include "../Childwindows/costcentrechild.h"
00028 #include "../Childwindows/costunitchild.h"
00029 #include "../Childwindows/pricecomparisonchild.h"
00030
00031 #include "actionstab.h"
00032 #include "costtypetab.h"
00033 #include "costcentretab.h"
00034 #include "costunittab.h"
00035 #include "pricecomparisontab.h"
00036
00037 #include "../Updater/manifestdata.h"
00038
00039 MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
00040 {
00041 setupUi(this);
00042
00043
00044 settings.setMainWindow(this);
00045 settings.read();
00046
00047
00048 setEncoding();
00049
00050 init();
00051 applyQtHacks();
00052 applyApplicationName();
00053
00054
00055 initUpdateControls();
00056 checkForUpdates();
00057 }
00058
00059 void MainWindow::init()
00060 {
00061 modelListModel = new DocumentChooserModel();
00062 treeViewDocuments->setModel(modelListModel);
00063
00064 createActions();
00065 createSideBar();
00066 createMdiArea();
00067 initializePrinter();
00068 connect(menuWindowList, SIGNAL(aboutToShow()), this, SLOT(updateWindowMenu()));
00069 updateMenus();
00070
00071 changeEntryStates(false);
00072 }
00073
00074 void MainWindow::applyQtHacks()
00075 {
00076
00077
00078
00079
00080 #if QT_VERSION < 0x040501
00081 actionSidebar->setContentsMargins(0,0,0,0);
00082 #endif
00083 }
00084
00085 void MainWindow::applyApplicationName()
00086 {
00087 QCoreApplication::setApplicationName("Allevo");
00088 QCoreApplication::setApplicationVersion("1.9.0.0");
00089 QCoreApplication::setOrganizationName("FrieSoft");
00090 QCoreApplication::setOrganizationDomain("I");
00091
00092 aboutData = new AboutData("Allevo I", "Allevo I", "Allevo I", QCoreApplication::applicationVersion().toAscii(), "Opensource Kostenrechnungsprogramm für Kleinunternehmer", "Copyleft (c) 2009 FrieSoft", "Allevo I ist Teil einer Rechnungswesen Suite, wobei der 1te Teil ein Kostenrechnungsprogramm für den Einsatz in Unternehmen darstellt. Allevo II ist ein Programm zur Erlernung der doppelten Buchhaltung.", "http://allevo.sourceforge.net", "allevo.bugs@gmx.at");
00093
00094 aboutData->addAuthor("Bernhard Friedreich", "Projektgründer und Entwicklungsleiter", "friesoft@gmail.com", "http://friesoft.wordpress.com");
00095 aboutData->addAuthor("Richard Lagler", "Projektleiter und Entwickler", "richard.lagler@gmx.at", "");
00096 aboutData->addAuthor("Christian Fleck", "Entwickler", "chr.off50@gmx.net", "");
00097 aboutData->addAuthor("Peter Nirschl", "Entwickler", "peter.nirschl@gmail.com", "");
00098 aboutData->addAuthor("David Madl", "Entwickler", "david@madlnet.net", "");
00099 aboutData->addAuthor("Oliver Elias", "Dokumentation", "olli.elias@gmail.com", "");
00100
00101 QList<AboutPerson> people = aboutData->authors();
00102 aboutData->addCredit("HTBLVA Spengergasse", "Inspiration und Coaching");
00103 aboutData->addCredit("Sourceforge", "Hosting (Homepage, Source, Mailinglists, ...)", "", "http://sourceforge.net");
00104 aboutData->addCredit("KDE", "Code/Coding styles/Philosophie/Inspiration, ...", "", "http://kde.org");
00105 aboutData->addCredit("Subversion", "Versionsverwaltung", "", "http://subversion.tigris.org");
00106 aboutData->addCredit("Qt-forum.de/org", "Qt Forum", "", "http://qt-forum.de");
00107 aboutData->addCredit("#qt", "Qt IRC Channel");
00108 aboutData->addCredit("qt-interest mailing list", "", "qt-interest@trolltech.com");
00109 aboutData->addCredit("Qt Creator", "Großartige IDE + Code Inspiration");
00110 aboutData->addCredit("Qt Software/Trolls", "Nur ein Wort: DANKE!");
00111
00112 setWindowTitle();
00113 }
00114
00115 void MainWindow::setWindowTitle()
00116 {
00117 QString title = QCoreApplication::organizationName() + " " + QCoreApplication::applicationName() + " " + QCoreApplication::organizationDomain() + " - Kostenrechnung - " + QCoreApplication::applicationVersion();
00118 if(Project::name() != "")
00119 {
00120 title += " - " + Project::name();
00121 }
00122 QMainWindow::setWindowTitle(title);
00123 }
00124
00125 void MainWindow::restoreLastGemoetry(QByteArray geo)
00126 {
00127 restoreGeometry(geo);
00128 }
00129
00130 QList<QDomElement> MainWindow::documentNodes()
00131 {
00132 QList<QDomElement> documentList;
00133
00134 DocumentItem *item = modelListModel->rootItem();
00135 for(int i = 0; i < item->childCount(); i++)
00136 {
00137 DocumentItem *documentType = item->child(i);
00138 for(int documents = 0; documents < documentType->childCount(); documents++)
00139 {
00140 DocumentItem *document = documentType->child(documents);
00141 QDomElement doc = document->model()->documentNode();
00142
00143 if(!doc.isNull())
00144 {
00145 documentList << doc;
00146 }
00147 }
00148 }
00149
00150 return documentList;
00151 }
00152
00153 QDomElement MainWindow::categoryNodes()
00154 {
00155 return costtypetab->userCategories();
00156 }
00157
00158 void MainWindow::initializePrinter()
00159 {
00160 printer = new QPrinter(QPrinter::HighResolution);
00161 }
00162
00163 void MainWindow::createMdiArea()
00164 {
00165 windowMapper = new QSignalMapper(this);
00166 connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow *)), this, SLOT(updateMenus()));
00167 connect(windowMapper, SIGNAL(mapped(QWidget *)),this, SLOT(setActiveSubWindow(QWidget *)));
00168 }
00169
00170 void MainWindow::setEncoding()
00171 {
00172 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
00173 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
00174 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
00175 }
00176
00177 void MainWindow::closeEvent(QCloseEvent *event)
00178 {
00179 closeProject();
00180 if(currentWindow())
00181 {
00182 event->ignore();
00183 }
00184 else
00185 {
00186 settings.write();
00187 event->accept();
00188 }
00189 }
00190
00191 void MainWindow::createNewDocument(WindowType::Type type, QString name)
00192 {
00193 int fileid = Project::highestFileID();
00194 fileid++;
00195 Project::setHighestFileID(fileid);
00196
00197 switch(type)
00198 {
00199 case WindowType::CostType:
00200 {
00201 newCostTypeFile(fileid, name);
00202 break;
00203 }
00204 case WindowType::CostCentre:
00205 {
00206 newCostCentreFile(fileid, name);
00207 break;
00208 }
00209 case WindowType::CostUnit:
00210 {
00211 newCostUnitFile(fileid, name);
00212 break;
00213 }
00214 case WindowType::PriceComparison:
00215 {
00216 newPriceComparisonFile(fileid, name);
00217 break;
00218 }
00219 default:
00220 {
00221 QMessageBox::critical(this, tr("Fehler"), tr("Es trat ein Fehler beim erstellen des Dokuments auf! Der Dateityp ist nicht gültig!"));
00222 break;
00223 }
00224 }
00225 }
00226
00227 void MainWindow::newCostTypeFile(int id, QString name, QDomElement file)
00228 {
00229 CostTypeModel *model = new CostTypeModel((uint)id, (uint)WindowType::CostType, name, this);
00230 modelListModel->addDocument(model);
00231
00232 openCostTypeFile(model, file);
00233 }
00234
00235 void MainWindow::openCostTypeFile(CostTypeModel *model, QDomElement file)
00236 {
00237 CostTypeChild *child = createCostTypeChild();
00238 child->setModel(model);
00239 child->newFile();
00240 if(file.childNodes().count() != 0)
00241 {
00242 child->loadDocument(file);
00243 }
00244 child->show();
00245 connect(child, SIGNAL(destroyed(QObject*)), this, SLOT(cleanUpSidebar()));
00246 connect(child, SIGNAL(editInformationAvailable(const CostTypeModel *, const QModelIndexList)), costtypetab, SLOT(enterEditPositionInformation(const CostTypeModel*, const QModelIndexList)));
00247 connect(child, SIGNAL(setMdiAreaEnabled(bool)), mdiArea, SLOT(setEnabled(bool)));
00248 connect(child->ownCapitalDialog, SIGNAL(sendingData(QString)), costtypetab->groupBoxCompleteCosts->textOperatingAssets, SLOT(setText(QString)));
00249 }
00250
00251 void MainWindow::newCostCentreFile(int id, QString name, QDomElement file)
00252 {
00253 DocumentChooser *chooser = new DocumentChooser(WindowType::CostType, id, name, file, modelListModel, this);
00254 chooser->show();
00255 connect(chooser, SIGNAL(documentSelected(DocumentItem, int, QString, QDomElement)), this, SLOT(openCostCentreModel(DocumentItem, int, QString, QDomElement)));
00256 }
00257
00258 void MainWindow::openCostCentreFromProjectFile(int id, QString name, QDomElement file)
00259 {
00260 CostCentreModel *model = new CostCentreModel((uint)id, (uint)WindowType::CostCentre, name, this);
00261 modelListModel->addDocument(model);
00262
00263 openCostCentreFile(model, NULL, id, name, file);
00264 }
00265
00266 void MainWindow::openCostCentreModel(DocumentItem callByValueItem, int id, QString name, QDomElement file)
00267 {
00268 DocumentItem *item = referenceFromItem(callByValueItem);
00269 if(item != NULL)
00270 {
00271 qDebug()<<"FIXME: check should be added here if conversion is valid";
00272 openCostCentreFile(NULL, (CostTypeModel*)item->model(), id, name, file);
00273 }
00274 }
00275
00276 void MainWindow::openCostCentreFile(CostCentreModel *model, CostTypeModel *costtype, int id, QString name, QDomElement file)
00277 {
00278 if(!model)
00279 {
00280 model = new CostCentreModel((uint)id, (uint)WindowType::CostCentre, name, this);
00281 modelListModel->addDocument(model);
00282 }
00283
00284 CostCentreChild *child = createCostCentreChild();
00285
00286 child->setModel(model);
00287
00288 child->newFile();
00289 if(file.childNodes().count() != 0)
00290 {
00291 child->loadDocument(file);
00292 }
00293
00294 if(costtype != NULL)
00295 {
00296 child->setCostTypeModel(costtype);
00297 }
00298 else
00299 {
00300 int costTypeFileId = child->model()->costTypeFileIdentification();
00301 CostTypeModel *costtypemodel = modelListModel->costTypeModelById(costTypeFileId);
00302 child->setCostTypeModel(costtypemodel);
00303 }
00304
00305 child->show();
00306 connect(child, SIGNAL(destroyed(QObject*)), this, SLOT(cleanUpSidebar()));
00307 }
00308
00309 void MainWindow::newCostUnitFile(int id, QString name, QDomElement file)
00310 {
00311 qDebug()<<"id: " << id << "Costunit: " << WindowType::CostUnit << "Name: " << name;
00312 CostUnitModel *model = new CostUnitModel(settings, (uint)id, (uint)WindowType::CostUnit, name, this);
00313 modelListModel->addDocument(model);
00314
00315 openCostUnitFile(model, file);
00316 }
00317
00318 void MainWindow::openCostUnitFile(CostUnitModel *model, QDomElement file)
00319 {
00320 CostUnitChild *child = createCostUnitChild();
00321
00322 child->setModel(model);
00323 child->newFile();
00324 if(file.childNodes().count() != 0)
00325 {
00326 child->loadDocument(file);
00327 }
00328 child->show();
00329
00330 connect(child, SIGNAL(destroyed(QObject*)), this, SLOT(cleanUpSidebar()));
00331
00332 }
00333
00334 void MainWindow::newPriceComparisonFile(int id, QString name, QDomElement file)
00335 {
00336 AbstractModel *model = new AbstractModel(id, WindowType::PriceComparison, name);
00337 modelListModel->addDocument(model);
00338
00339 openPriceComparisonFile(model, file);
00340 }
00341
00342 void MainWindow::openPriceComparisonFile(AbstractModel *model, QDomElement file)
00343 {
00344 PriceComparisonChild *child = createPriceComparisonChild();
00345 child->setDocumentInfoModel(model);
00346 child->setModelList(modelListModel);
00347
00348 if(file.childNodes().count() != 0)
00349 {
00350 child->loadDocument(file);
00351 }
00352 child->show();
00353 }
00354
00355 CostTypeChild* MainWindow::createCostTypeChild()
00356 {
00357 CostTypeChild *child = new CostTypeChild;
00358 mdiArea->addSubWindow(child);
00359 return child;
00360 }
00361
00362 CostCentreChild* MainWindow::createCostCentreChild()
00363 {
00364 CostCentreChild *child = new CostCentreChild;
00365 mdiArea->addSubWindow(child);
00366 return child;
00367 }
00368
00369 CostUnitChild* MainWindow::createCostUnitChild()
00370 {
00371 CostUnitChild *child = new CostUnitChild(settings);
00372 mdiArea->addSubWindow(child);
00373 return child;
00374 }
00375
00376 PriceComparisonChild* MainWindow::createPriceComparisonChild()
00377 {
00378 PriceComparisonChild *child = new PriceComparisonChild(settings);
00379 mdiArea->addSubWindow(child);
00380 return child;
00381 }
00382
00383 DocumentItem* MainWindow::referenceFromItem(DocumentItem callByValueItem)
00384 {
00385 AbstractModel *model = callByValueItem.model();
00386 if(model->fileId() != -1 && model->fileName() != "" && model->type() != -1)
00387 {
00388
00389 return modelListModel->documentItem(model->fileId(), model->type());
00390 }
00391 else
00392 {
00393 return NULL;
00394 }
00395 }
00396
00397 void MainWindow::openDocument(const QModelIndex &index)
00398 {
00399 DocumentItem *item = referenceFromItem(index.data(32).value<DocumentItem>());
00400 if(item != NULL)
00401 {
00402 AbstractModel *model = item->model();
00403 if(!modelIsAlreadyOpened(model))
00404 {
00405 qDebug()<<"FIXME: add checks if the documenttype is correct and if the cast will be successful -- otherwise it will crash! -- evaluate QSharedPointer";
00406 switch(model->type())
00407 {
00408 case WindowType::CostType:
00409 {
00410 openCostTypeFile((CostTypeModel*)model);
00411 break;
00412 }
00413 case WindowType::CostCentre:
00414 {
00415 openCostCentreFile((CostCentreModel*)model);
00416 break;
00417 }
00418 case WindowType::CostUnit:
00419 {
00420 openCostUnitFile((CostUnitModel*)model);
00421 break;
00422 }
00423 case WindowType::PriceComparison:
00424 {
00425 openPriceComparisonFile(model);
00426 break;
00427 }
00428 }
00429 }
00430 else
00431 {
00432
00433 switchChildWindowByModel(model);
00434 }
00435 }
00436 }
00437
00438 void MainWindow::closeDocumentWindow(const QString name)
00439 {
00440 qDebug()<<"document to close (name): " << name;
00441 QMdiSubWindow *window = childWindowByName(name);
00442 qDebug()<<"window to close: " << window;
00443 if(window != NULL)
00444 {
00445 mdiArea->setActiveSubWindow(window);
00446 mdiArea->closeActiveSubWindow();
00447 }
00448 }
00449
00450 bool MainWindow::modelIsAlreadyOpened(AbstractModel *model)
00451 {
00452 if(childWindowByModel(model) == NULL)
00453 {
00454 return false;
00455 }
00456 else
00457 {
00458 return true;
00459 }
00460 }
00461
00462 QMdiSubWindow* MainWindow::childWindowByName(const QString &name)
00463 {
00464 DocumentItem *root = modelListModel->rootItem();
00465 for(int i = 0; i < root->childCount(); i++)
00466 {
00467 qDebug()<<"types: " << i;
00468 DocumentItem *cat = root->child(i);
00469 for(int j = 0; j < cat->childCount(); j++)
00470 {
00471 qDebug()<<"docs: " << j;
00472 DocumentItem *doc = cat->child(j);
00473 qDebug()<<"doc->fileName(): " << doc->fileName();
00474 qDebug()<<"name: " << name;
00475 if(QString::compare(doc->fileName(), name, Qt::CaseInsensitive) == 0)
00476 {
00477 AbstractModel *model = doc->model();
00478 qDebug()<<"model by name: " << name << " model: " << model;
00479 if(model != NULL)
00480 {
00481 return childWindowByModel(model);
00482 }
00483 }
00484 }
00485 }
00486 return NULL;
00487 }
00488
00489 QMdiSubWindow* MainWindow::childWindowByModel(AbstractModel *model)
00490 {
00491 qDebug()<<"switchChildWindowByModel";
00492 QMdiSubWindow *window = NULL;
00493 foreach(window, mdiArea->subWindowList())
00494 {
00495 qDebug()<<"window: " << window;
00496 qDebug()<<"window->widget(): " << window->widget();
00497 ChildWindow *child = qobject_cast<ChildWindow*>(window->widget());
00498 qDebug()<<"child: " << child;
00499 if(child)
00500 {
00501 AbstractModel *childWindowModel = NULL;
00502 if(child->type() == WindowType::CostType)
00503 {
00504 CostTypeChild *cost = qobject_cast<CostTypeChild*>(child);
00505 childWindowModel = cost->model();
00506 }
00507 else if(child->type() == WindowType::CostCentre)
00508 {
00509 CostCentreChild *coce = qobject_cast<CostCentreChild*>(child);
00510 childWindowModel = coce->model();
00511 }
00512 else if(child->type() == WindowType::CostUnit)
00513 {
00514 CostUnitChild *coun = qobject_cast<CostUnitChild*>(child);
00515 childWindowModel = coun->model();
00516 }
00517 else if(child->type() == WindowType::PriceComparison)
00518 {
00519 PriceComparisonChild *prco = qobject_cast<PriceComparisonChild*>(child);
00520 childWindowModel = prco->model();
00521 }
00522 if(childWindowModel != NULL)
00523 {
00524 if(QString::compare(model->fileName(), childWindowModel->fileName(), Qt::CaseInsensitive) == 0)
00525 {
00526 return window;
00527 }
00528 }
00529 }
00530 else
00531 {
00532 qDebug()<<"child not valid";
00533 }
00534 }
00535 return NULL;
00536 }
00537
00538 void MainWindow::switchChildWindowByModel(AbstractModel *model)
00539 {
00540 QMdiSubWindow *window = childWindowByModel(model);
00541 if(window != NULL)
00542 {
00543 mdiArea->setActiveSubWindow(window);
00544 }
00545 }
00546
00547 void MainWindow::openProject()
00548 {
00549 QFileDialog dialog(this);
00550 QString path = dialog.getOpenFileName(this, tr("Projekt öffnen"), settings.workspace().absolutePath(), tr("Allevo I Kostenrechnungs Projekt") + " (*.cst)");
00551 if(!path.isEmpty() && QFile(path).exists())
00552 {
00553 qDebug()<<"openProject: " << path;
00554 Project::setPath(path);
00555 openProject(path);
00556 }
00557 }
00558
00559 void MainWindow::openProject(QString path)
00560 {
00561 ProjectFile *project = new ProjectFile();
00562 connect(project, SIGNAL(createCostTypeFile(int,QString,QDomElement)), this, SLOT(newCostTypeFile(int, QString, QDomElement)));
00563 connect(project, SIGNAL(createCostCentreFile(int,QString,QDomElement)), this, SLOT(openCostCentreFromProjectFile(int, QString, QDomElement)));
00564 connect(project, SIGNAL(createCostUnitFile(int, QString, QDomElement)), this, SLOT(newCostUnitFile(int, QString, QDomElement)));
00565 connect(project, SIGNAL(loadUserCategory(QDomElement)), costtypetab, SLOT(loadUserCategories(QDomElement)));
00566
00567 costtypetab->readCostPositions();
00568
00569 if(!project->readProject() && Project::locked() == 1)
00570 {
00571
00572 return ;
00573 }
00574
00575 setWindowTitle();
00576 changeEntryStates(true);
00577
00578 Project::setLocked(true);
00579 saveProject();
00580 }
00581
00582 void MainWindow::openProject(QAction *action)
00583 {
00584
00585 }
00586
00587 void MainWindow::changeEntryStates(bool en)
00588 {
00589 actionCloseProject->setEnabled(en);
00590 actionNewDocument->setEnabled(en);
00591
00592 actionstab->setProjectOpen(en);
00593
00594 actionProjectProperties->setEnabled(en);
00595 actionSaveProject->setEnabled(en);
00596 actionManageDocuments->setEnabled(en);
00597 menuWindowList->setEnabled(en);
00598
00599 actionOpenProject->setEnabled(!en);
00600 actionNewProject->setEnabled(!en);
00601 }
00602
00603 void MainWindow::closeProject()
00604 {
00605 Project::setLocked(false);
00606 saveProject();
00607 mdiArea->closeAllSubWindows();
00608
00609 QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
00610 if(windows.count() == 0)
00611 {
00612
00613 modelListModel->clear();
00614
00615 Project::clear();
00616
00617 changeEntryStates(false);
00618
00619 setCurrentSidebarTab(0);
00620 costtypetab->clearEntries();
00621
00622 setWindowTitle();
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 }
00633 }
00634
00635 void MainWindow::createNewProject()
00636 {
00637 NewProjectWizard *wizard = new NewProjectWizard(settings);
00638
00639 connect(wizard, SIGNAL(createdProject()), this, SLOT(openNewProject()));
00640
00641 wizard->show();
00642 }
00643
00644 void MainWindow::openNewProject()
00645 {
00646 qDebug()<<"openNewProject: " << Project::path();
00647 openProject(Project::path());
00648 }
00649
00650 void MainWindow::saveProject()
00651 {
00652 ProjectFile *project = new ProjectFile();
00653 qDebug()<<"saveProject: " << Project::path();
00654 project->writeProject(documentNodes(), categoryNodes());
00655 }
00656
00657 void MainWindow::reportBugs()
00658 {
00659 BugReportDialog *dialog = new BugReportDialog(settings, &mailerThread, this);
00660 dialog->show();
00661 }
00662
00663 void MainWindow::bugReportSent()
00664 {
00665 QMessageBox::information(this, "Fehlerbericht erfolgreich gesendet!", "Vielen Dank, dass Sie Ihren Beitrag dazu geleistet haben Allevo zu verbessern!");
00666 }
00667
00668 void MainWindow::bugReportSendError(QString message)
00669 {
00670 QMessageBox::critical(this, "Fehler beim Senden", "Leider trat ein Fehler beim Senden des Fehlerberichts auf! Möglicherweise lässt Ihre Firewall keinen SMTP Zugriff zu :-(\r\nMeldung:\r\n" + message);
00671 }
00672
00673 void MainWindow::about()
00674 {
00675 AboutDialog *about = new AboutDialog(aboutData, this);
00676 about->show();
00677 }
00678
00679 void MainWindow::updateMenus()
00680 {
00681 bool hasMdiChild = (currentWindow() != 0);
00682
00683
00684 windowChanged();
00685
00686 actionSaveProject->setEnabled(hasMdiChild);
00687 actionClose->setEnabled(hasMdiChild);
00688 actionCloseAll->setEnabled(hasMdiChild);
00689 actionSplitWindows->setEnabled(hasMdiChild);
00690 actionAdjustWindowsOnGrid->setEnabled(hasMdiChild);
00691 actionNextWindow->setEnabled(hasMdiChild);
00692 actionLastWindow->setEnabled(hasMdiChild);
00693 actionPrintPreview->setEnabled(hasMdiChild);
00694 actionPrint->setEnabled(hasMdiChild);
00695
00696
00697
00698 }
00699
00700 void MainWindow::updateWindowMenu()
00701 {
00702 menuWindowList->clear();
00703
00704 QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
00705
00706 for (int i = 0; i < windows.size(); ++i)
00707 {
00708 ChildWindow *childwindow = qobject_cast<ChildWindow *>(windows.value(i)->widget());
00709 QString text;
00710 if(i < 9)
00711 {
00712 if(childwindow->type() == WindowType::CostType)
00713 {
00714 text = tr("&%1 %2 - Kostenartenrechnung").arg(i + 1).arg(qobject_cast<CostTypeChild *>(childwindow)->windowTitle());
00715 }
00716 else if(childwindow->type() == WindowType::CostCentre)
00717 {
00718 text = tr("&%1 %2 - Kostenstellenrechnung").arg(i + 1).arg(qobject_cast<CostCentreChild *>(childwindow)->windowTitle());
00719 }
00720 else if(childwindow->type() == WindowType::CostUnit)
00721 {
00722 text = tr("&%1 %2 - Kostenträgerrechnung").arg(i + 1).arg(qobject_cast<CostUnitChild *>(childwindow)->windowTitle());
00723 }
00724 else if(childwindow->type() == WindowType::PriceComparison)
00725 {
00726 text = tr("&%1 %2 - Preisvergleich").arg(i + 1).arg(qobject_cast<PriceComparisonChild *>(childwindow)->windowTitle());
00727 }
00728 }
00729 else
00730 {
00731 if(childwindow->type() == WindowType::CostType)
00732 {
00733 text = tr("%1 %2 - Kostenartenrechnung").arg(i + 1).arg(qobject_cast<CostTypeChild *>(childwindow)->windowTitle());
00734 }
00735 else if(childwindow->type() == WindowType::CostCentre)
00736 {
00737 text = tr("%1 %2 - Kostenstellenrechnung").arg(i + 1).arg(qobject_cast<CostCentreChild *>(childwindow)->windowTitle());
00738 }
00739 else if(childwindow->type() == WindowType::CostUnit)
00740 {
00741 text = tr("%1 %2 - Kostenträgerrechnung").arg(i + 1).arg(qobject_cast<CostUnitChild *>(childwindow)->windowTitle());
00742 }
00743 else if(childwindow->type() == WindowType::PriceComparison)
00744 {
00745 text = tr("%1 %2 - Preisvergleich").arg(i + 1).arg(qobject_cast<PriceComparisonChild *>(childwindow)->windowTitle());
00746 }
00747 }
00748 QAction *action = menuWindowList->addAction(text);
00749 action->setCheckable(true);
00750 action->setChecked(childwindow == currentWindow());
00751 connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
00752 windowMapper->setMapping(action, windows.value(i));
00753 }
00754 }
00755
00756 void MainWindow::createSideBar()
00757 {
00758 actionstab = new ActionsTab();
00759 costtypetab = new CostTypeTab(mdiArea);
00760 costcentretab = new CostCentreTab(settings, mdiArea);
00761 costunittab = new CostUnitTab();
00762 pricecomparisontab = new PriceComparisonTab();
00763
00764 sidebarTabWidget->clear();
00765 sidebarTabWidget->addTab(actionstab, tr("Allgemein"));
00766 actionSidebar->setWidget(sidebarTabWidget);
00767
00768 connect(actionstab, SIGNAL(createProject()), this, SLOT(createNewProject()));
00769 connect(actionstab, SIGNAL(openProject()), this, SLOT(openProject()));
00770 connect(actionstab, SIGNAL(closeProject()), this, SLOT(closeProject()));
00771 connect(actionstab, SIGNAL(newDocument()), this, SLOT(newDocumentDialog()));
00772 connect(actionstab, SIGNAL(importDocuments()), this, SLOT(importFile()));
00773 }
00774
00775 void MainWindow::setCurrentSidebarTab(int index)
00776 {
00777 sidebarTabWidget->setCurrentIndex(index);
00778 }
00779
00780 void MainWindow::cleanUpSidebar()
00781 {
00782 sidebarTabWidget->clear();
00783 sidebarTabWidget->addTab(actionstab, tr("Allgemein"));
00784 }
00785
00786 void MainWindow::changeCurrentDocumentSidebarTab(ChildWindow *child, int type)
00787 {
00788 cleanUpSidebar();
00789
00790 switch(type)
00791 {
00792 case WindowType::CostType:
00793 {
00794 sidebarTabWidget->addTab(costtypetab, tr("Kostenartenrechnung"));
00795
00796 CostTypeChild *costtypechild = qobject_cast<CostTypeChild*>(child);
00797 OwnCapitalCalculationDialog *ownCapitalDialog = costtypechild->ownCapitalDialog;
00798 costtypechild->model()->setOwnCapitalModel(costtypechild->ownCapitalDialog->model);
00799
00800
00801 disconnect(costtypetab->groupBoxCompleteCosts, 0, 0, 0);
00802
00803 connect(costtypetab->groupBoxCompleteCosts, SIGNAL(showOwnCapitalCalculationDialog()), ownCapitalDialog, SLOT(show()));
00804 break;
00805 }
00806 case WindowType::CostCentre:
00807 {
00808 sidebarTabWidget->addTab(costcentretab, tr("Kostenstellenrechnung"));
00809 costcentretab->setModel(((CostCentreChild*)currentWindow())->costTypeModel());
00810
00811 break;
00812 }
00813 case WindowType::CostUnit:
00814 {
00815 sidebarTabWidget->addTab(costunittab, tr("Kostenträgerrechnung"));
00816
00817 CostUnitChild *tempChild = qobject_cast<CostUnitChild*>(child);
00818
00819
00820 disconnect(costunittab, 0, 0, 0);
00821
00822 connect(costunittab, SIGNAL(additionalChargesChangedCostUnit(QList<int>)), tempChild, SLOT(setAdditionalCharges(QList<int>)));
00823 connect(costunittab, SIGNAL(addProductCostUnit(QString, QString, QString, QString, QString, QString, QString)), tempChild, SLOT(setProduct(QString, QString, QString, QString, QString, QString, QString)));
00824 break;
00825 }
00826 case WindowType::PriceComparison:
00827 {
00828 PriceComparisonChild *price = qobject_cast<PriceComparisonChild*>(child);
00829 sidebarTabWidget->addTab(pricecomparisontab, tr("Preisvergleich"));
00830 break;
00831 }
00832 default:
00833 {
00834 break;
00835 }
00836 }
00837 if(sidebarTabWidget->count() > 1)
00838 {
00839 sidebarTabWidget->setCurrentIndex(1);
00840 }
00841 else
00842 {
00843 sidebarTabWidget->setCurrentIndex(0);
00844 }
00845 }
00846
00847 void MainWindow::newDocumentDialog()
00848 {
00849 NewDocumentDialog *dialog = new NewDocumentDialog(modelListModel, this);
00850 dialog->show();
00851 connect(dialog, SIGNAL(createDocument(WindowType::Type, QString)), this, SLOT(createNewDocument(WindowType::Type, QString)));
00852 }
00853
00854 void MainWindow::createActions()
00855 {
00856 connect(actionNewProject, SIGNAL(triggered()), this, SLOT(createNewProject()));
00857 connect(actionCloseProject, SIGNAL(triggered()), this, SLOT(closeProject()));
00858 connect(actionNewDocument, SIGNAL(triggered()), this, SLOT(newDocumentDialog()));
00859 connect(actionOpenProject, SIGNAL(triggered()), this, SLOT(openProject()));
00860 connect(actionProjectProperties, SIGNAL(triggered()), this, SLOT(showProjectInformation()));
00861 connect(actionSaveProject, SIGNAL(triggered()), this, SLOT(saveProject()));
00862 connect(actionExit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
00863 connect(actionClose, SIGNAL(triggered()), mdiArea, SLOT(closeActiveSubWindow()));
00864 connect(actionCloseAll, SIGNAL(triggered()), mdiArea, SLOT(closeAllSubWindows()));
00865 connect(actionPrintPreview, SIGNAL(triggered()), this, SLOT(printPreview()));
00866 connect(actionPrint, SIGNAL(triggered()), this, SLOT(print()));
00867 connect(actionAdjustWindowsOnGrid, SIGNAL(triggered()), mdiArea, SLOT(tileSubWindows()));
00868 connect(actionSplitWindows, SIGNAL(triggered()), mdiArea, SLOT(cascadeSubWindows()));
00869 connect(actionNextWindow, SIGNAL(triggered()),mdiArea, SLOT(activateNextSubWindow()));
00870 connect(actionLastWindow, SIGNAL(triggered()),mdiArea, SLOT(activatePreviousSubWindow()));
00871 connect(actionReportBug, SIGNAL(triggered()), this, SLOT(reportBugs()));
00872 connect(actionManageDocuments, SIGNAL(triggered()),this, SLOT(manageProject()));
00873 connect(actionWorkspaceSettings, SIGNAL(triggered()), this, SLOT(openWorkspaceSettings()));
00874 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
00875 connect(actionAboutAllevo, SIGNAL(triggered()), this, SLOT(about()));
00876 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00877 connect(actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
00878 connect(actionHelp, SIGNAL(triggered()), this, SLOT(openHelpBrowser()));
00879 connect(treeViewDocuments, SIGNAL(doubleClicked(const QModelIndex)), this, SLOT(openDocument(const QModelIndex)));
00880
00881
00882 connect(&mailerThread, SIGNAL(mailSent()), this, SLOT(bugReportSent()));
00883 connect(&mailerThread, SIGNAL(sendMailError(QString)), this, SLOT(bugReportSendError(QString)));
00884 }
00885
00886 void MainWindow::manageProject()
00887 {
00888 ManageProjectDialog *dialog = new ManageProjectDialog(modelListModel, this);
00889 connect(dialog, SIGNAL(deleteDocumentWindow(const QString)), this, SLOT(closeDocumentWindow(const QString)));
00890 dialog->show();
00891 }
00892
00893 void MainWindow::openWorkspaceSettings()
00894 {
00895 showSettingsDialog(1);
00896 }
00897
00898
00899 void MainWindow::initUpdateControls()
00900 {
00901 updateInfo = new QLabel(" ", this);
00902 updateInfo->setMinimumWidth(200);
00903
00904 statusBar()->addWidget(updateInfo);
00905 }
00906
00907
00908 void MainWindow::checkForUpdates()
00909 {
00910 if(settings.automaticCheckForUpdates())
00911 {
00912 connect(&(this->updaterManifestThread), SIGNAL(manifestReady()), this, SLOT(manifestParsed()));
00913 connect(&(this->updaterManifestThread), SIGNAL(errorOccured()), this, SLOT(mainfestErrorOccured()));
00914 this->updaterManifestThread.start();
00915
00916
00917 updateInfo->setText("UPDATER: Updates werden gesucht...");
00918 updateInfo->show();
00919 }
00920 }
00921
00922 void MainWindow::manifestParsed()
00923 {
00924
00925
00926 updateInfo->setText("Update Informationen erfolgreich geholt");
00927 }
00928
00929 void MainWindow::mainfestErrorOccured()
00930 {
00931 updateInfo->setText("Fehler beim Beziehen der Update Informationen!");
00932 }
00933
00934 void MainWindow::showSettingsDialog()
00935 {
00936 SettingsDialog *configuration = new SettingsDialog(settings, this);
00937 configuration->show();
00938 }
00939
00940 void MainWindow::showSettingsDialog(int page)
00941 {
00942 SettingsDialog *configuration = new SettingsDialog(settings, this);
00943 configuration->setActivePage(page);
00944 configuration->show();
00945 }
00946
00947 ChildWindow* MainWindow::currentWindow()
00948 {
00949 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00950 {
00951 return qobject_cast<ChildWindow*>(activeSubWindow->widget());
00952 }
00953 return 0;
00954 }
00955
00956 void MainWindow::windowChanged()
00957 {
00958 if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
00959 {
00960 ChildWindow *child = qobject_cast<ChildWindow*>(activeSubWindow->widget());
00961 if(child != NULL)
00962 {
00963 changeCurrentDocumentSidebarTab(child, child->type());
00964 }
00965 }
00966 }
00967
00968 QMdiSubWindow *MainWindow::findChild(const QString &fileName)
00969 {
00970 QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
00971
00972 foreach(QMdiSubWindow *window, mdiArea->subWindowList())
00973 {
00974 if((qobject_cast<ChildWindow*>(window->widget()))->type() == WindowType::CostType)
00975 {
00976 CostTypeChild *child = qobject_cast<CostTypeChild *>(window->widget());
00977 if(child->windowTitle() == canonicalFilePath)
00978 {
00979 return window;
00980 }
00981 }
00982 else if((qobject_cast<ChildWindow*>(window->widget()))->type() == WindowType::CostCentre)
00983 {
00984 CostCentreChild *child = qobject_cast<CostCentreChild *>(window->widget());
00985 if(child->windowTitle() == canonicalFilePath)
00986 {
00987 return window;
00988 }
00989 }
00990 else if((qobject_cast<ChildWindow*>(window->widget()))->type() == WindowType::CostUnit)
00991 {
00992 CostUnitChild *child = qobject_cast<CostUnitChild *>(window->widget());
00993 if(child->windowTitle() == canonicalFilePath)
00994 {
00995 return window;
00996 }
00997 }
00998 else if((qobject_cast<ChildWindow*>(window->widget()))->type() == WindowType::PriceComparison)
00999 {
01000 PriceComparisonChild *child = qobject_cast<PriceComparisonChild *>(window->widget());
01001 if(child->windowTitle() == canonicalFilePath)
01002 {
01003 return window;
01004 }
01005 }
01006 }
01007 return 0;
01008 }
01009
01010 void MainWindow::setActiveSubWindow(QWidget *window)
01011 {
01012 if(!window)
01013 {
01014 return;
01015 }
01016 mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
01017 }
01018
01019 void MainWindow::showProjectInformation()
01020 {
01021 ProjectInformationDialog *info = new ProjectInformationDialog(this);
01022 info->show();
01023 }
01024
01025 void MainWindow::openHelpBrowser()
01026 {
01027 HelpBrowserDialog *browser = new HelpBrowserDialog(aboutData);
01028 browser->show();
01029 }
01030
01031 void MainWindow::importFile()
01032 {
01033 qDebug()<<"FIXME: Let the user choose which documents of another project he wants to import";
01034 }
01035
01036 void MainWindow::print()
01037 {
01038 ChildWindow *child = currentWindow();
01039 if(child->type() == WindowType::CostType)
01040 {
01041 CostTypeChild *koat = qobject_cast<CostTypeChild*>(child);
01042 PrintPreviewDialog *dialog = new PrintPreviewDialog(koat->windowTitle(), koat->tableViewWidget(), printer, this);
01043 dialog->print();
01044 delete dialog;
01045 }
01046 else if(child->type() == WindowType::CostCentre)
01047 {
01048 CostCentreChild *kost = qobject_cast<CostCentreChild*>(child);
01049 PrintPreviewDialog *dialog = new PrintPreviewDialog(kost->windowTitle(), kost->tableViewWidget(), printer, this);
01050
01051 dialog->print();
01052 delete dialog;
01053 }
01054 else if(child->type() == WindowType::CostUnit)
01055 {
01056 CostUnitChild *kotr = qobject_cast<CostUnitChild*>(child);
01057 PrintPreviewDialog *dialog = new PrintPreviewDialog(kotr->windowTitle(), kotr->tableViewWidget(), printer, this);
01058 dialog->print();
01059 delete dialog;
01060 }
01061 else if(child->type() == WindowType::PriceComparison)
01062 {
01063
01064
01065
01066
01067 }
01068 }
01069
01070 void MainWindow::printPreview()
01071 {
01072 ChildWindow *child = currentWindow();
01073
01074 if(child->type() == WindowType::CostType)
01075 {
01076 CostTypeChild *koat = qobject_cast<CostTypeChild*>(child);
01077 PrintPreviewDialog *dialog = new PrintPreviewDialog(koat->windowTitle(), koat->tableViewWidget(), printer, this);
01078 dialog->exec();
01079 delete dialog;
01080 }
01081 else if(child->type() == WindowType::CostCentre)
01082 {
01083 CostCentreChild *kost = qobject_cast<CostCentreChild*>(child);
01084 PrintPreviewDialog *dialog = new PrintPreviewDialog(kost->windowTitle(), kost->tableViewWidget(), printer, this);
01085 dialog->exec();
01086 delete dialog;
01087 }
01088 else if(child->type() == WindowType::CostUnit)
01089 {
01090 CostUnitChild *kotr = qobject_cast<CostUnitChild*>(child);
01091 PrintPreviewDialog *dialog = new PrintPreviewDialog(kotr->windowTitle(), kotr->tableViewWidget(), printer, this);
01092 dialog->exec();
01093 delete dialog;
01094 }
01095 else if(child->type() == WindowType::PriceComparison)
01096 {
01097
01098
01099
01100
01101 }
01102 }