00001 #include <QComboBox>
00002 #include <QProgressBar>
00003 #include <QSignalMapper>
00004 #include <QPushButton>
00005 #include <QWidget>
00006 #include <QGraphicsView>
00007 #include <QGraphicsScene>
00008 #include <QGraphicsProxyWidget>
00009 #include <QTextEdit>
00010 #include <QRectF>
00011 #include <QTableView>
00012 #include <QTableWidgetItem>
00013 #include <QSplitter>
00014 #include <QVBoxLayout>
00015 #include <QDomDocument>
00016 #include <QItemEditorCreatorBase>
00017 #include <QStandardItemEditorCreator>
00018 #include <QDebug>
00019
00020 #include "mainwindow.h"
00021 #include "../Data/project.h"
00022 #include "../Dialogs/aboutdialog.h"
00023 #include "../Dialogs/projectinformationdialog.h"
00024 #include "../Printing/printdialog.h"
00025 #include "../Dialogs/settingsdialog.h"
00026 #include "../Dialogs/updaterdialog.h"
00027 #include "../Dialogs/accountstabledialog.h"
00028 #include "../Dialogs/bugreportdialog.h"
00029 #include "../Dialogs/selecttableofaccountdialog.h"
00030 #include "../Data/datadefinitions.h"
00031 #include "../Data/dataproject.h"
00032 #include "../Models/accountmodel.h"
00033 #include "../Views/descriptionwidget.h"
00034 #include "../Views/accountingrecordwidget.h"
00035 #include "../Models/accountingmodel.h"
00036 #include "pupilactions.h"
00037 #include "pupilstartactions.h"
00038 #include "teacheractions.h"
00039 #include "teacherstartactions.h"
00040 #include "startactions.h"
00041 #include "../Dialogs/newdocumentdialog.h"
00042 #include "../Dialogs/helpbrowserdialog.h"
00043 #include "../Styles/accountstyle.h"
00044 #include "../Data/aboutdata.h"
00045 #include "../Updater/updatermanifestthread.h"
00046
00047 MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
00048 {
00049 setupUi(this);
00050
00051
00052 settings.setMainWindow(this);
00053 settings.read();
00054
00055
00056 rec->setSettings(&settings);
00057 sol->setSettings(&settings);
00058
00059
00060 accountsView->setShown(!settings.teacher());
00061
00062
00063 setEncoding();
00064
00065 init();
00066 applyQtHacks();
00067 applyApplicationName();
00068
00069
00070 initUpdateControls();
00071 checkForUpdates();
00072 }
00073
00074 void MainWindow::applyApplicationName()
00075 {
00076 QCoreApplication::setApplicationName("Allevo");
00077 QCoreApplication::setApplicationVersion("1.5.0.0");
00078 QCoreApplication::setOrganizationName("FrieSoft");
00079 QCoreApplication::setOrganizationDomain("II");
00080
00081 aboutData = new AboutData("Allevo II", "Allevo II", "Allevo II", QCoreApplication::applicationVersion().toAscii(), "Opensource Lernprogramm zur Doppelten Buchhaltung", "Copyleft (c) 2009 FrieSoft", "Allevo II ist Teil einer Rechnungswesen Suite, wobei der 2te Teil sich um das Erlernen der doppelten Buchhaltung dreht. Allevo I stellt ein Kostenrechnungsprogramm für den Einsatz in Unternehmen dar.", "http://allevo.sourceforge.net", "allevo.bugs@gmx.at");
00082
00083 aboutData->addAuthor("Bernhard Friedreich", "Projektgründer und Entwicklungsleiter", "friesoft@gmail.com", "http://friesoft.wordpress.com");
00084 aboutData->addAuthor("Richard Lagler", "Projektleiter und Entwickler", "richard.lagler@gmx.at", "");
00085 aboutData->addAuthor("Christian Fleck", "Entwickler", "chr.off50@gmx.net", "");
00086 aboutData->addAuthor("Peter Nirschl", "Entwickler", "peter.nirschl@gmail.com", "");
00087 aboutData->addAuthor("David Madl", "Entwickler", "david@madlnet.net", "");
00088 aboutData->addAuthor("Oliver Elias", "Dokumentation", "olli.elias@gmail.com", "");
00089
00090 QList<AboutPerson> people = aboutData->authors();
00091 aboutData->addCredit("HTBLVA Spengergasse", "Inspiration und Coaching");
00092 aboutData->addCredit("Sourceforge", "Hosting (Homepage, Source, Mailinglists, ...)", "", "http://sourceforge.net");
00093 aboutData->addCredit("KDE", "Code/Coding styles/Philosophie/Inspiration, ...", "", "http://kde.org");
00094 aboutData->addCredit("Subversion", "Versionsverwaltung", "", "http://subversion.tigris.org");
00095 aboutData->addCredit("Qt-forum.de/org", "Qt Forum", "", "http://qt-forum.de");
00096 aboutData->addCredit("#qt", "Qt IRC Channel");
00097 aboutData->addCredit("qt-interest mailing list", "", "qt-interest@trolltech.com");
00098 aboutData->addCredit("Qt Creator", "Großartige IDE + Code Inspiration");
00099 aboutData->addCredit("Qt Software/Trolls", "Nur ein Wort: DANKE!");
00100
00101 setWindowTitle();
00102 }
00103
00104 void MainWindow::init()
00105 {
00106 currentProject = NULL;
00107 currentAccountModel = NULL;
00108 currentExercise = NULL;
00109
00110 currentScaleFactor = -1;
00111 accountingRecodIsDrawn = false;
00112 solutionIsDrawn = false;
00113 scene = new QGraphicsScene();
00114
00115 startActions = NULL;
00116 pupilActions = NULL;
00117 teacherActions = NULL;
00118 currentProject = NULL;
00119
00120 printer = NULL;
00121
00122 clearEverything();
00123 createSideBar();
00124 labelInstructions->hide();
00125
00126 createActions();
00127
00128 calendar = new DateCalendar(this);
00129 calendar->setMainWindow(this);
00130 Project::setDateCalendar(calendar);
00131
00132 changeEntryStates(false);
00133 }
00134
00135 void MainWindow::applyQtHacks()
00136 {
00137
00138
00139
00140
00141 #if QT_VERSION < 0x040501
00142 sidebar->setContentsMargins(0,0,0,0);
00143 #endif
00144 }
00145
00146 void MainWindow::setWindowTitle()
00147 {
00148 QString title = QCoreApplication::organizationName() + " " + QCoreApplication::applicationName() + " " + QCoreApplication::organizationDomain() + " - Doppelte Buchhaltung - " + QCoreApplication::applicationVersion();
00149 if(Project::name() != QString())
00150 {
00151 title += " - " + Project::name();
00152 }
00153 QMainWindow::setWindowTitle(title);
00154 }
00155
00156 void MainWindow::setEncoding()
00157 {
00158 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
00159 QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
00160 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
00161 }
00162
00163 void MainWindow::createActions()
00164 {
00165 connect(actionNewFile, SIGNAL(triggered()), this, SLOT(showNewFileDialog()));
00166 connect(actionOpenFile, SIGNAL(triggered()), this, SLOT(openFile()));
00167 connect(actionCloseFile, SIGNAL(triggered()), this, SLOT(closeFile()));
00168 connect(actionSaveFile, SIGNAL(triggered()), this, SLOT(saveFile()));
00169 connect(actionSaveFileAs, SIGNAL(triggered()), this, SLOT(saveFileAs()));
00170 connect(actionProjectProperties, SIGNAL(triggered()), this, SLOT(showProjectInformation()));
00171
00172 connect(actionPrintPreview, SIGNAL(triggered()), this, SLOT(printPreview()));
00173 connect(actionPrint, SIGNAL(triggered()), this, SLOT(print()));
00174
00175 connect(actionReportBug, SIGNAL(triggered()), this, SLOT(reportBugs()));
00176 connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
00177 connect(actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(showUpdaterDialog()));
00178 connect(actionHelp, SIGNAL(triggered()), this, SLOT(openHelpBrowser()));
00179
00180 connect(actionAboutAllevo, SIGNAL(triggered()), this, SLOT(about()));
00181 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00182
00183 connect(actionExit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
00184 connect(rec, SIGNAL(actualizeAccountsAfterSaving()), this, SLOT(drawAccounts()));
00185 connect(rec, SIGNAL(forwardErrorMesssage(QString)), this, SLOT(printErrorMessage(QString)));
00186
00187 connect(&mailerThread, SIGNAL(mailSent()), this, SLOT(bugReportSent()));
00188 connect(&mailerThread, SIGNAL(sendMailError(QString)), this, SLOT(bugReportSendError(QString)));
00189 }
00190
00191 void MainWindow::clearEverything()
00192 {
00193 workspaceArea->setBackgroundRole(QPalette::Base);
00194
00195 currentExerciseName->hide();
00196 buttonExpandDescriptionWidget->hide();
00197 buttonExpandAccountingRecord->hide();
00198 buttonExpandSolution->hide();
00199 buttonExpandOpeningStock->hide();
00200 labelDescription->hide();
00201 labelAccountingRecord->hide();
00202 labelSolution->hide();
00203 labelOpeningStock->hide();
00204 desc->hide();
00205 rec->hide();
00206 sol->hide();
00207 openingStockWidget->hide();
00208
00209 actionNewFile->setVisible(settings.teacher());
00210
00211 if(teacherActions)
00212 {
00213 delete teacherActions;
00214 teacherActions = NULL;
00215 }
00216
00217 if(currentProject)
00218 {
00219 ExerciseModel *exerciseModel = new ExerciseModel(false);
00220 if(pupilActions)
00221 {
00222 disconnect(exerciseModel, SIGNAL(resetView()), 0, 0);
00223 connect(exerciseModel, SIGNAL(resetView()), pupilActions->exerciseSelectionView, SLOT(resetView()));
00224 connect(exerciseModel, SIGNAL(resetView()), pupilActions->exerciseCompletionPieChart, SLOT(reset()));
00225
00226 pupilActions->exerciseSelectionView->setModel(exerciseModel);
00227 pupilActions->exerciseCompletionPieChart->setModel(exerciseModel);
00228 }
00229 if(teacherActions)
00230 {
00231 disconnect(exerciseModel, SIGNAL(resetView()), 0, 0);
00232 connect(exerciseModel, SIGNAL(resetView()), teacherActions->exerciseSelectionView, SLOT(resetView()));
00233 }
00234
00235 delete currentProject;
00236 currentProject = NULL;
00237 }
00238
00239 if(currentAccountModel)
00240 {
00241 delete currentAccountModel;
00242 currentAccountModel = NULL;
00243 }
00244
00245 p_accountList.clear();
00246 p_accountProxyWidgetList.clear();
00247 p_accountListPosition.clear();
00248 p_accountListSize.clear();
00249
00250 accountingRecodIsDrawn = false;
00251 solutionIsDrawn = false;
00252
00253 if(pupilActions)
00254 {
00255 for(int i = 0; i < 3; i++)
00256 {
00257 pupilActions->tableWidgetState->setItem(0, i, new QTableWidgetItem(""));
00258 }
00259 }
00260 scene->clear();
00261 }
00262
00263 void MainWindow::createSideBar()
00264 {
00265 sidebarTabWidget->clear();
00266
00267 if(startActions != NULL)
00268 {
00269 disconnect(startActions, 0, 0, 0);
00270 }
00271
00272 if(settings.teacher())
00273 {
00274 if(startActions != NULL)
00275 {
00276 delete startActions;
00277 }
00278 startActions = new TeacherStartActions(sidebarTabWidget);
00279 sidebarTabWidget->addTab(startActions, tr("Aktionen"));
00280
00281 if(teacherActions == NULL)
00282 {
00283 teacherActions = new TeacherActions(sidebarTabWidget);
00284 }
00285 sidebarTabWidget->addTab(teacherActions, tr("Professor"));
00286
00287 disconnect(teacherActions, 0, 0, 0);
00288
00289
00290 connect(startActions, SIGNAL(newFile()), this, SLOT(showNewFileDialog()));
00291 connect(teacherActions, SIGNAL(showErrorMessage(QString)), this, SLOT(printErrorMessage(QString)));
00292 connect(teacherActions, SIGNAL(createTree(QModelIndex)), this, SLOT(createTeacherTree(QModelIndex)));
00293 }
00294 else
00295 {
00296 if(startActions != NULL)
00297 {
00298 delete startActions;
00299 }
00300 startActions = new PupilStartActions(sidebarTabWidget);
00301 sidebarTabWidget->addTab(startActions, tr("Aktionen"));
00302
00303 if(pupilActions == NULL)
00304 {
00305 pupilActions = new PupilActions(sidebarTabWidget);
00306 }
00307 sidebarTabWidget->addTab(pupilActions, tr("Schüler"));
00308
00309 disconnect(pupilActions, 0, 0, 0);
00310
00311
00312 connect(pupilActions, SIGNAL(createTree(QModelIndex)), this, SLOT(createPupilTree(QModelIndex)));
00313 connect(pupilActions->exerciseCompletionPieChart, SIGNAL(exerciseStatesChanged(QList<int>)), this, SLOT(setExerciseStates(QList<int>)));
00314 }
00315
00316
00317 connect(startActions, SIGNAL(openFile()), this, SLOT(openFile()));
00318 connect(startActions, SIGNAL(closeFile()), this, SLOT(closeFile()));
00319 connect(startActions, SIGNAL(showHelp()), this, SLOT(openHelpBrowser()));
00320
00321 sidebar->setWidget(sidebarTabWidget);
00322 }
00323
00324 void MainWindow::showNewFileDialog()
00325 {
00326 NewDocumentDialog *dialog = new NewDocumentDialog(settings, this);
00327 dialog->show();
00328
00329 connect(dialog, SIGNAL(createFile(FileType::Type, QString)), this, SLOT(createFile(FileType::Type, QString)));
00330 }
00331
00332 void MainWindow::createFile(FileType::Type fileType, QString fileName)
00333 {
00334 path = fileName;
00335 f_type = fileType;
00336
00337 if(fileType == FileType::Task || fileType == FileType::Exercise)
00338 {
00339 createStudentDocument();
00340 }
00341 else if(fileType == FileType::TableOfAccounts)
00342 {
00343 path = settings.workspace().absolutePath() + QDir::separator() + fileName + ".dbkk";
00344 openTableOfAccounts();
00345 }
00346 else
00347 {
00348 QMessageBox::critical(this, "Fehler", "Fehler beim Erstellen des Dokuments!");
00349 }
00350 }
00351
00352 void MainWindow::createStudentDocument()
00353 {
00354 SelectTableOfAccountDialog *tableAccountsSelectionDialog = new SelectTableOfAccountDialog(settings, this);
00355 tableAccountsSelectionDialog->show();
00356
00357
00358 connect(tableAccountsSelectionDialog, SIGNAL(tableOfAccountsChoosen(QString)), this, SLOT(finishStudentDocumentCreation(QString)));
00359 }
00360
00361 void MainWindow::finishStudentDocumentCreation(const QString &tableOfAccountsPath)
00362 {
00363 qDebug()<<"table of accounts has been created/choosen: " << tableOfAccountsPath;
00364
00365 currentAccountModel = new AccountModel(tableOfAccountsPath);
00366 currentProject = new DataProject();
00367
00368
00369 Project::setName(QFileInfo(path).baseName());
00370
00371
00372 QString temppath = settings.workspace().absolutePath();
00373 temppath += QDir::separator();
00374 temppath += path;
00375 path = temppath;
00376
00377 if(!teacherActions)
00378 {
00379 createSideBar();
00380 }
00381 if(f_type == FileType::Task)
00382 {
00383 currentProject = new DataProject();
00384 currentProject->setProjectType(FileType::Task);
00385 teacherActions->createTask(currentProject);
00386 }
00387 else if(f_type == FileType::Exercise)
00388 {
00389 currentProject = new DataProject();
00390 currentProject->setProjectType(FileType::Exercise);
00391 teacherActions->createExercise(currentProject);
00392 }
00393 else
00394 {
00395 return;
00396 }
00397 createSideBar();
00398 sidebarTabWidget->setCurrentIndex(1);
00399 setWindowTitle();
00400 changeEntryStates(true);
00401 }
00402
00403 void MainWindow::openFile()
00404 {
00405 QFileDialog dialog(this);
00406 path = dialog.getOpenFileName(this, tr("Datei öffnen"), settings.workspace().absolutePath(), tr("Alle Dateien (*);;Allevo II Aufgabe (*.dbka);;Allevo II Übung (*.dbku);;Allevo II Kontenplan (*.dbkk)"));
00407 QFileInfo pInfo(path);
00408 if(pInfo.exists())
00409 {
00410 if(pInfo.suffix() == "dbku")
00411 {
00412 f_type = FileType::Exercise;
00413 openStudentDocument();
00414 }
00415 else if(pInfo.suffix() == "dbka")
00416 {
00417 f_type = FileType::Task;
00418 openStudentDocument();
00419 }
00420 else if(pInfo.suffix() == "dbkk")
00421 {
00422 f_type = FileType::TableOfAccounts;
00423 openTableOfAccounts();
00424 }
00425 else
00426 {
00427 QMessageBox::critical(this, "Fehler", "Die Datei hat einen Allevo II unbekannten Dateityp!");
00428 }
00429 }
00430 else
00431 {
00432 if(path != "")
00433 {
00434 QMessageBox::critical(this, "Fehler", "Auf die Datei kann nicht zugegriffen werden!");
00435 }
00436 }
00437 }
00438
00439 void MainWindow::openStudentDocument()
00440 {
00441 createSideBar();
00442 sidebarTabWidget->setCurrentIndex(1);
00443
00444 currentProject = new DataProject();
00445 currentProject->loadXml(path);
00446 currentAccountModel = new AccountModel(currentProject->getAccounts());
00447
00448 if(!settings.teacher())
00449 {
00450 if(f_type == FileType::Exercise)
00451 {
00452 currentProject->setProjectType(f_type);
00453 pupilActions->readExercise(currentProject);
00454 }
00455 else
00456 {
00457 currentProject->setProjectType(f_type);
00458 pupilActions->readTask(currentProject);
00459 }
00460 pupilActions->exerciseCompletionPieChart->setModel(pupilActions->model);
00461 labelInstructions->show();
00462 }
00463 else
00464 {
00465 if(f_type == FileType::Exercise)
00466 {
00467 currentProject->setProjectType(f_type);
00468 teacherActions->readExercise(currentProject);
00469 }
00470 else
00471 {
00472 currentProject->setProjectType(f_type);
00473 teacherActions->readTask(currentProject);
00474 }
00475 }
00476
00477 setWindowTitle();
00478
00479 changeEntryStates(true);
00480 }
00481
00482 void MainWindow::openTableOfAccounts()
00483 {
00484 AccountsTableDialog *dialog = new AccountsTableDialog(path, settings, this);
00485 dialog->show();
00486 }
00487
00488 void MainWindow::closeAndCleanup()
00489 {
00490 Project::clear();
00491 qDebug()<<"project cleared";
00492
00493 changeEntryStates(false);
00494
00495 setCurrentSidebarTab(0);
00496
00497 clearEverything();
00498 qDebug()<<"after sidebar has been cleared";
00499
00500 createSideBar();
00501 qDebug()<<"after createsidebar";
00502
00503 startActions->setProjectOpen(false);
00504 setWindowTitle();
00505 }
00506
00507 int MainWindow::askCloseFile()
00508 {
00509 int ret = QMessageBox::No;
00510
00511 if(currentProject)
00512 {
00513 if(currentProject->hasChanged())
00514 {
00515 QMessageBox msgBox;
00516 QString infoText;
00517 msgBox.setIcon(QMessageBox::Warning);
00518 msgBox.setText(tr("Sie möchten die Mappe schließen."));
00519 infoText = tr("Wollen Sie die Änderungen an der aktuellen Mappe speichern?\n\n");
00520 infoText += tr("Ja: Speichern und Mappe schließen\n");
00521 infoText += tr("Nein: VERWERFEN und Mappe schließen\n");
00522 infoText += tr("Abbrechen: Nichts unternehmen");
00523 msgBox.setInformativeText(infoText);
00524 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
00525 msgBox.setDefaultButton(QMessageBox::Yes);
00526 ret = msgBox.exec();
00527 }
00528 }
00529 if(ret == QMessageBox::Yes)
00530 {
00531 saveFile();
00532 }
00533 if(ret != QMessageBox::Cancel)
00534 {
00535 closeAndCleanup();
00536 }
00537
00538 return ret;
00539 }
00540
00541 void MainWindow::closeFile()
00542 {
00543 askCloseFile();
00544 }
00545
00546 void MainWindow::saveFile()
00547 {
00548 while(path.isEmpty())
00549 {
00550 QFileDialog dialog(this);
00551 path = dialog.getSaveFileName(this, tr("Datei speichern unter"), settings.workspace().absolutePath(), tr("Alle Dateien (*);;Allevo II Aufgabe (*.dbka);;Allevo II Ăbung (*.dbku);;Allevo II Kontenplan (*.dbkk)"));
00552 }
00553 if(!path.isEmpty())
00554 {
00555 if(currentProject)
00556 {
00557 saveAccountingRecordsIntoDataStructures();
00558 if(settings.teacher())
00559 {
00560 openingStockWidget->saveIntoExercise();
00561 }
00562 currentAccountModel->saveIntoProject(currentProject);
00563 currentProject->saveXml(path);
00564 }
00565 }
00566 }
00567
00568 void MainWindow::saveFileAs()
00569 {
00570 QFileDialog dialog(this);
00571 QString newPath = dialog.getSaveFileName(this, tr("Datei speichern unter"), settings.workspace().absolutePath(), tr("Alle Dateien (*);;Allevo II Aufgabe (*.dbka);;Allevo II Ăbung (*.dbku);;Allevo II Kontenplan (*.dbkk)"));
00572 if(!path.isEmpty())
00573 {
00574 path = newPath;
00575 saveAccountingRecordsIntoDataStructures();
00576 openingStockWidget->saveIntoExercise();
00577 currentProject->saveXml(path);
00578 }
00579 }
00580
00581 void MainWindow::createTeacherTree(QModelIndex index)
00582 {
00583 if(index.parent().isValid())
00584 {
00585 if(currentProject)
00586 {
00587 currentExercise = currentProject->exercise(index.parent().data(Qt::DisplayRole).toString(), index.data(Qt::DisplayRole).toString());
00588 if(!currentExercise)
00589 {
00590 currentExercise = new DataExercise();
00591 currentExercise->setExerciseName(index.data(0).toString());
00592 currentProject->chapter(index.parent().data(0).toString())->addExercise(currentExercise);
00593 }
00594 }
00595 currentAccountModel->saveIntoProject(currentProject);
00596
00597 currentExercise->setExerciseName(index.data(0).toString());
00598 currentExerciseName->setText(index.data(0).toString());
00599 currentExerciseName->show();
00600
00601 buttonExpandDescriptionWidget->show();
00602 connect(buttonExpandDescriptionWidget, SIGNAL(clicked(bool)), this, SLOT(changeButtonAndDescriptionWidget(bool)));
00603 descriptionIsDrawn = false;
00604 labelDescription->show();
00605 desc->show();
00606
00607
00608 if(f_type == FileType::Exercise)
00609 {
00610 buttonExpandAccountingRecord->show();
00611 labelAccountingRecord->setText("Lösung:");
00612 connect(buttonExpandAccountingRecord, SIGNAL(clicked(bool)), this, SLOT(changeButtonAndAccountingRecordWidget(bool)));
00613 labelAccountingRecord->show();
00614 accountingRecodIsDrawn = false;
00615 }
00616
00617 buttonExpandOpeningStock->show();
00618 labelOpeningStock->show();
00619 connect(buttonExpandOpeningStock, SIGNAL(clicked(bool)), this, SLOT(changeButtonAndOpeningStockWidget(bool)));
00620 openingStockIsDrawn = false;
00621
00622 buttonExpandDescriptionWidget->setChecked(false);
00623 buttonExpandOpeningStock->setChecked(false);
00624 buttonExpandDescriptionWidget->click();
00625 buttonExpandOpeningStock->click();
00626 if(f_type == FileType::Exercise)
00627 {
00628 buttonExpandAccountingRecord->setChecked(false);
00629 buttonExpandAccountingRecord->click();
00630 }
00631 }
00632 }
00633
00634 void MainWindow::createPupilTree(QModelIndex index)
00635 {
00636 if(index.parent().isValid())
00637 {
00638 labelInstructions->hide();
00639 DataExercise *ex = currentProject->exercise(index.parent().data(Qt::DisplayRole).toString(), index.data(Qt::DisplayRole).toString());
00640 currentExercise = ex;
00641 drawAccounts();
00642
00643
00644 currentExerciseName->setText(ex->name());
00645 currentExerciseName->show();
00646
00647
00648 buttonExpandDescriptionWidget->show();
00649
00650 disconnect(buttonExpandDescriptionWidget, SIGNAL(clicked(bool)));
00651 connect(buttonExpandDescriptionWidget, SIGNAL(clicked(bool)), this, SLOT(changeButtonAndDescriptionWidget(bool)));
00652
00653 labelDescription->show();
00654 descriptionIsDrawn = false;
00655
00656
00657
00658 buttonExpandAccountingRecord->show();
00659 labelAccountingRecord->setText("Buchungssätze: ");
00660 disconnect(buttonExpandAccountingRecord, SIGNAL(clicked(bool)));
00661 connect(buttonExpandAccountingRecord, SIGNAL(clicked(bool)), this, SLOT(changeButtonAndAccountingRecordWidget(bool)));
00662
00663 labelAccountingRecord->show();
00664 accountingRecodIsDrawn = false;
00665
00666 disconnect(rec, SIGNAL(finishAccountingRecord()));
00667 disconnect(rec, SIGNAL(changeState(QString,int,DataExerciseStatus)));
00668
00669 connect(rec, SIGNAL(finishAccountingRecord()), this, SLOT(showSolution()));
00670 connect(rec, SIGNAL(changeState(QString, int, DataExerciseStatus)), pupilActions, SLOT(changeStateInModel(QString, int, DataExerciseStatus)));
00671
00672
00673
00674
00675 if(ex->solutionRecords()->size() != 0 && f_type == FileType::Exercise)
00676 {
00677 buttonExpandSolution->show();
00678 buttonExpandSolution->setEnabled(false);
00679 labelSolution->show();
00680 solutionIsDrawn = false;
00681 disconnect(sol, SIGNAL(backToAccountingRecord()));
00682 connect(sol, SIGNAL(backToAccountingRecord()), this, SLOT(hideSolution()));
00683 }
00684
00685
00686
00687 hideSolution();
00688
00689
00690
00691 buttonExpandDescriptionWidget->setChecked(false);
00692 buttonExpandAccountingRecord->setChecked(false);
00693 buttonExpandDescriptionWidget->click();
00694 buttonExpandAccountingRecord->click();
00695
00696 }
00697 }
00698
00699 void MainWindow::changeButtonAndDescriptionWidget(bool check)
00700 {
00701 if(check)
00702 {
00703 buttonExpandDescriptionWidget->setIcon(QIcon(":/misc/Remove"));
00704 if(!descriptionIsDrawn)
00705 {
00706 if(settings.teacher())
00707 {
00708 desc->createWidgetForTeacher(currentExercise);
00709 }
00710 else
00711 {
00712 desc->createWidgetForPupil(currentExercise);
00713 }
00714 descriptionIsDrawn = true;
00715 }
00716 desc->show();
00717 }
00718 else
00719 {
00720 buttonExpandDescriptionWidget->setIcon(QIcon(":/misc/Add"));
00721 desc->hide();
00722 }
00723 }
00724
00725 void MainWindow::changeButtonAndAccountingRecordWidget(bool check)
00726 {
00727 if(check)
00728 {
00729 if(!accountingRecodIsDrawn)
00730 {
00731 if(f_type == FileType::Exercise)
00732 {
00733 if(settings.teacher())
00734 {
00735 rec->makeWidgetForTask(true, currentAccountModel, currentExercise, true);
00736
00737
00738 }
00739 else
00740 {
00741 rec->makeWidgetForExercise(true, currentAccountModel, currentExercise);
00742
00743
00744 }
00745 }
00746 else if(f_type == FileType::Task)
00747 {
00748 rec->makeWidgetForTask(true, currentAccountModel, currentExercise);
00749
00750
00751 }
00752 accountingRecodIsDrawn = true;
00753 }
00754 buttonExpandAccountingRecord->setIcon(QIcon(":/misc/Remove"));
00755 rec->show();
00756 }
00757 else
00758 {
00759 buttonExpandAccountingRecord->setIcon(QIcon(":/misc/Add"));
00760 rec->hide();
00761 }
00762 }
00763
00764 void MainWindow::changeButtonAndSolutionWidget(bool check)
00765 {
00766 if(check)
00767 {
00768 qDebug()<<"changeButtonAndSolutionWidget, solutionIsDrawn: " << check;
00769 if(!solutionIsDrawn)
00770 {
00771 if(settings.teacher())
00772 {
00773 sol->makeWidgetForExercise(true, currentAccountModel, currentExercise);
00774 }
00775 else
00776 {
00777 sol->makeWidgetForExercise(false, currentAccountModel, currentExercise);
00778 }
00779 solutionIsDrawn = true;
00780 }
00781 buttonExpandSolution->setIcon(QIcon(":/misc/Remove"));
00782 sol->show();
00783 }
00784 else
00785 {
00786 buttonExpandSolution->setIcon(QIcon(":/misc/Add"));
00787 sol->hide();
00788 }
00789 }
00790
00791 void MainWindow::changeButtonAndOpeningStockWidget(bool check)
00792 {
00793 if(check)
00794 {
00795 buttonExpandOpeningStock->setIcon(QIcon(":/misc/Remove"));
00796 if(!openingStockIsDrawn)
00797 {
00798 openingStockWidget->createWidget(currentExercise, currentAccountModel);
00799 disconnect(openingStockWidget, SIGNAL(printErrorMessage(QString)), 0, 0);
00800 connect(openingStockWidget, SIGNAL(printErrorMessage(QString)), this, SLOT(printErrorMessage(QString)));
00801 }
00802 openingStockWidget->show();
00803 }
00804 else
00805 {
00806 buttonExpandOpeningStock->setIcon(QIcon(":/misc/Add"));
00807 openingStockWidget->hide();
00808 }
00809 }
00810
00811 void MainWindow::showSolution()
00812 {
00813 changeButtonAndDescriptionWidget(false);
00814 changeButtonAndAccountingRecordWidget(false);
00815 changeButtonAndSolutionWidget(true);
00816 buttonExpandDescriptionWidget->setEnabled(false);
00817 buttonExpandAccountingRecord->setEnabled(false);
00818 buttonExpandSolution->setEnabled(true);
00819 }
00820
00821 void MainWindow::hideSolution()
00822 {
00823 changeButtonAndDescriptionWidget(true);
00824 changeButtonAndAccountingRecordWidget(true);
00825 changeButtonAndSolutionWidget(false);
00826 buttonExpandDescriptionWidget->setEnabled(true);
00827 buttonExpandAccountingRecord->setEnabled(true);
00828 buttonExpandSolution->setEnabled(false);
00829 }
00830
00831 void MainWindow::printErrorMessage(QString error)
00832 {
00833 QMessageBox::critical(this, tr("Fehler"), error, QMessageBox::Ok);
00834 }
00835
00836 bool MainWindow::existsDialogInSizePositionList(QString title)
00837 {
00838 for(int i = 0; i < p_accountListPosition.size(); i++)
00839 {
00840 if(p_accountListPosition.value(i).first == title)
00841 {
00842 return true;
00843 }
00844 }
00845 return false;
00846 }
00847
00848 int MainWindow::positionInSizePositionList(QString title)
00849 {
00850 for(int i = 0; i < p_accountListPosition.size(); i++)
00851 {
00852 if(title == p_accountListPosition.value(i).first)
00853 {
00854 return i;
00855 }
00856 }
00857 return -1;
00858 }
00859
00860 AccountDialog* MainWindow::makeAccountDialog(AccountingModel *model, QString title)
00861 {
00862 AccountDialog *dialog = new AccountDialog();
00863 dialog->setWindowTitle(title);
00864 dialog->setGeometry(0, 0, 50, 50);
00865 dialog->accountTableView->setModel(model);
00866
00867 QPair<QPointer<AccountDialog>, QPointer<AccountingModel> > pair;
00868 pair.first = dialog;
00869 pair.second = model;
00870 model->disconnect(SIGNAL(dataChanged(QModelIndex,QModelIndex)));
00871 connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), dialog, SLOT(recalculateSums()));
00872 p_accountList.append(pair);
00873
00874 dialog->accountTableView->resizeColumnsToContents();
00875 dialog->accountTableView->resizeRowsToContents();
00876
00877 return dialog;
00878 }
00879
00880 void MainWindow::drawAccounts()
00881 {
00882 for(int i = 0; i < p_accountList.size(); i++)
00883 {
00884 if(existsDialogInSizePositionList(p_accountList.value(i).first->windowTitle()))
00885 {
00886 QPair<QString, QPointF> pos;
00887 pos.first = p_accountList.value(i).first->windowTitle();
00888 pos.second = p_accountProxyWidgetList.value(i).second.data()->scenePos();
00889 p_accountListPosition.replace(i, pos);
00890
00891
00892 QPair<QString, QSize> size;
00893 size.first = p_accountList.value(i).first->windowTitle();
00894 size.second = p_accountList.value(i).first.data()->size();
00895 p_accountListSize.replace(i, size);
00896 }
00897 else
00898 {
00899 QPair<QString, QPointF> pos;
00900 pos.first = p_accountList.value(i).first->windowTitle();
00901 pos.second = p_accountProxyWidgetList.value(i).second.data()->scenePos();
00902 p_accountListPosition.append(pos);
00903
00904
00905 QPair<QString, QSize> size;
00906 size.first = p_accountList.value(i).first->windowTitle();
00907 size.second = p_accountList.value(i).first.data()->size();
00908 p_accountListSize.append(size);
00909 }
00910 }
00911 refreshOpeningStocks();
00912 refreshExistingAccountingRecords();
00913 }
00914
00915 void MainWindow::refreshOpeningStocks()
00916 {
00917 scene->clear();
00918 if(p_accountList.size() != 0)
00919 {
00920 p_accountList.clear();
00921 p_accountProxyWidgetList.clear();;
00922 }
00923 for(int i = 0; i < currentExercise->accounts()->size(); i++)
00924 {
00925 AccountingModel *model = new AccountingModel();
00926 AccountDialog *dialog = makeAccountDialog(model, currentAccountModel->getFullNameByNumber(currentExercise->accounts()->value(i)->accountNumber()));
00927
00928 AccountGraphicsProxyWidget *proxy = new AccountGraphicsProxyWidget(0, Qt::Window);
00929 proxy->setWidget(dialog);
00930 proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
00931 scene->addItem(proxy);
00932
00933 proxy->setPos(i * (dialog->width()), 100);
00934
00935 QPair<QString, QPointer<AccountGraphicsProxyWidget> > pair;
00936 pair.first = currentAccountModel->getFullNameByNumber(currentExercise->accounts()->value(i)->accountNumber());
00937 pair.second = proxy;
00938 p_accountProxyWidgetList.append(pair);
00939
00940 model->addRow("S01", currentExercise->accounts()->value(i)->openingDate(), "EBK", QString::number(currentExercise->accounts()->value(i)->openingStockDebit(), 'f', 2), QString::number(currentExercise->accounts()->value(i)->openingStockCredit(), 'f', 2));
00941
00942 if(existsDialogInSizePositionList(dialog->windowTitle()))
00943 {
00944 proxy->setPos(p_accountListPosition.value(positionInSizePositionList(dialog->windowTitle())).second);
00945 dialog->resize(p_accountListSize.value(positionInSizePositionList(dialog->windowTitle())).second);
00946 }
00947 else
00948 {
00949 QPair<QString, QPointF> pos;
00950 pos.first = dialog->windowTitle();
00951 pos.second = proxy->scenePos();
00952 p_accountListPosition.append(pos);
00953
00954 QPair<QString, QSize> size;
00955 size.first = dialog->windowTitle();
00956 size.second = dialog->size();
00957 p_accountListSize.append(size);
00958 }
00959 }
00960 scene->setSceneRect(scene->itemsBoundingRect());
00961
00962
00963 accountsView->setScene(scene);
00964 if(currentScaleFactor == -1)
00965 {
00966 currentScaleFactor = 0.8;
00967 accountsView->scale(currentScaleFactor, currentScaleFactor);
00968 accountsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
00969 accountsView->setCacheMode(QGraphicsView::CacheBackground);
00970 accountsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
00971 }
00972 }
00973
00974 void MainWindow::refreshExistingAccountingRecords()
00975 {
00976 QList<DataAccountingRecord *> *records = currentExercise->accountingRecords();
00977 for(int i = 0; i != records->size(); i++)
00978 {
00979 for(int j = 0; j != records->value(i)->debits()->size(); j++)
00980 {
00981 bool makeNewDialog = false;
00982 AccountingModel *currentModel;
00983 if(existAccountByNumber(normalizedAccountNumber(records->value(i)->debits()->value(j)->first)))
00984 {
00985 currentModel = p_accountList.value(positionInAccountListByAccountNumber(QString::number(records->value(i)->debits()->value(j)->first))).second;
00986 makeNewDialog = false;
00987 }
00988 else
00989 {
00990 currentModel = new AccountingModel();
00991 makeNewDialog = true;
00992 }
00993 QString contraAccount = "";
00994 if(records->value(i)->credits()->size() != 0)
00995 {
00996 contraAccount += normalizedAccountNumber(records->value(i)->credits()->value(0)->first);
00997 for(int k = 1; k != records->value(i)->credits()->size(); k++)
00998 {
00999 if(records->value(i)->credits()->value(k)->first<1000)
01000 contraAccount += ", 0" + QString::number(records->value(i)->credits()->value(k)->first);
01001 else
01002 contraAccount += ", " + QString::number(records->value(i)->credits()->value(k)->first);
01003 }
01004 }
01005 if(makeNewDialog)
01006 {
01007 AccountDialog *dialog = makeAccountDialog(currentModel, currentAccountModel->getFullNameByNumber(records->value(i)->debits()->value(j)->first));
01008 AccountGraphicsProxyWidget *proxy = new AccountGraphicsProxyWidget(0, Qt::Window);
01009 proxy->setWidget(dialog);
01010 proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
01011 scene->addItem(proxy);
01012
01013 QPair<QString, QPointer<AccountGraphicsProxyWidget> > gprox;
01014 gprox.first = dialog->windowTitle();
01015 gprox.second = proxy;
01016 p_accountProxyWidgetList.append(gprox);
01017 }
01018
01019 if(existsDialogInSizePositionList(currentAccountModel->getFullNameByNumber(records->value(i)->debits()->value(j)->first)))
01020 {
01021 QString normalizedAccount = normalizedAccountNumber(records->value(i)->debits()->value(j)->first);
01022 int elementNumber = positionInAccountListByAccountNumber(normalizedAccount);
01023 if(p_accountList.count() > 0)
01024 {
01025 AccountDialog *dialog = p_accountList.value(elementNumber).first;
01026 AccountGraphicsProxyWidget *proxy = p_accountProxyWidgetList.value(elementNumber).second;
01027
01028 dialog->resize(p_accountListSize.value(positionInSizePositionList(dialog->windowTitle())).second);
01029 proxy->setPos(p_accountListPosition.value(positionInSizePositionList(dialog->windowTitle())).second);
01030 }
01031 }
01032 else
01033 {
01034 AccountDialog *dialog = p_accountList.value(p_accountList.size()-1).first;
01035 AccountGraphicsProxyWidget *proxy = p_accountProxyWidgetList.value(p_accountProxyWidgetList.size()-1).second;
01036 QPair<QString, QSize> size;
01037 size.first = dialog->windowTitle();
01038 size.second = dialog->size();
01039 p_accountListSize.append(size);
01040
01041 QPair<QString, QPointF> pos;
01042 pos.first = dialog->windowTitle();
01043 pos.second = proxy->scenePos();
01044 p_accountListPosition.append(pos);
01045 }
01046 currentModel->addRow(records->value(i)->documentNumber(), records->value(i)->date().toString("dd.MM.yyyy"), contraAccount, QString::number(records->value(i)->debits()->value(j)->second), "0.00");
01047 }
01048
01049 for(int j = 0; j != records->value(i)->credits()->size(); j++)
01050 {
01051 bool makeNewDialog = false;
01052 AccountingModel *currentModel;
01053 if(existAccountByNumber(QString::number(records->value(i)->credits()->value(j)->first)))
01054 {
01055 currentModel = p_accountList.value(positionInAccountListByAccountNumber(QString::number(records->value(i)->credits()->value(j)->first))).second;
01056 makeNewDialog = false;
01057 }
01058 else
01059 {
01060 currentModel = new AccountingModel();
01061 makeNewDialog = true;
01062 }
01063 QString contraAccount = "";
01064 if(records->value(i)->debits()->size() != 0)
01065 {
01066 for(int k = 0; k != records->value(i)->debits()->size(); k++)
01067 {
01068 contraAccount += normalizedAccountNumber((records->value(i)->debits()->value(k)->first));
01069 }
01070 }
01071 if(makeNewDialog)
01072 {
01073 AccountDialog *dialog = makeAccountDialog(currentModel, currentAccountModel->getFullNameByNumber(records->value(i)->credits()->value(j)->first));
01074 AccountGraphicsProxyWidget *proxy = new AccountGraphicsProxyWidget(0, Qt::Window);
01075 proxy->setWidget(dialog);
01076 proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
01077 scene->addItem(proxy);
01078
01079 QPair<QString, QPointer<AccountGraphicsProxyWidget> > gprox;
01080 gprox.first = dialog->windowTitle();
01081 gprox.second = proxy;
01082 p_accountProxyWidgetList.append(gprox);
01083 }
01084
01085 if(existsDialogInSizePositionList(currentAccountModel->getFullNameByNumber(records->value(i)->credits()->value(j)->first)))
01086 {
01087 AccountDialog *dialog = p_accountList.value(positionInAccountListByAccountNumber(QString::number(records->value(i)->credits()->value(j)->first))).first;
01088 AccountGraphicsProxyWidget *proxy = p_accountProxyWidgetList.value((positionInAccountListByAccountNumber(QString::number(records->value(i)->credits()->value(j)->first)))).second;
01089 dialog->resize(p_accountListSize.value(positionInSizePositionList(dialog->windowTitle())).second);
01090 proxy->setPos(p_accountListPosition.value(positionInSizePositionList(dialog->windowTitle())).second);
01091 }
01092 else
01093 {
01094 AccountDialog *dialog = p_accountList.value(p_accountList.size()-1).first;
01095 AccountGraphicsProxyWidget *proxy = p_accountProxyWidgetList.value(p_accountProxyWidgetList.size()-1).second;
01096 QPair<QString, QSize> size;
01097 size.first = dialog->windowTitle();
01098 size.second = dialog->size();
01099 p_accountListSize.append(size);
01100
01101 QPair<QString, QPointF> pos;
01102 pos.first = dialog->windowTitle();
01103 pos.second = proxy->scenePos();
01104 p_accountListPosition.append(pos);
01105 }
01106 currentModel->addRow(records->value(i)->documentNumber(), records->value(i)->date().toString("dd.MM.yyyy"), contraAccount, "0.00", QString::number(records->value(i)->credits()->value(j)->second));
01107 }
01108 }
01109 }
01110
01111 bool MainWindow::existAccountByNumber(QString number)
01112 {
01113 for(int i = 0; i < p_accountList.size(); i++)
01114 {
01115 if(p_accountList.value(i).first->windowTitle().contains(number, Qt::CaseInsensitive))
01116 {
01117 return true;
01118 }
01119 }
01120 return false;
01121 }
01122
01123 int MainWindow::positionInAccountListByAccountNumber(QString number)
01124 {
01125 for(int i = 0; i != p_accountList.size(); i++)
01126 {
01127 if(p_accountList.value(i).first->windowTitle().contains(number, Qt::CaseInsensitive))
01128 {
01129 return i;
01130 }
01131 }
01132 return -1;
01133 }
01134
01135 void MainWindow::setExerciseStates(QList<int> items)
01136 {
01137 if(pupilActions)
01138 {
01139 for(int i = 0; i < items.count(); i++)
01140 {
01141 int item = items.value(i);
01142 QTableWidgetItem *tab = new QTableWidgetItem(QString::number(item));
01143 pupilActions->tableWidgetState->setItem(0, i, tab);
01144 }
01145 }
01146 }
01147
01148 void MainWindow::restoreLastGemoetry(QByteArray geo)
01149 {
01150 restoreGeometry(geo);
01151 }
01152
01153 void MainWindow::initializePrinter()
01154 {
01155
01156 printer = new QPrinter();
01157
01158 printer->setOutputFormat(QPrinter::NativeFormat);
01159 }
01160
01161 void MainWindow::closeEvent(QCloseEvent *event)
01162 {
01163 if(askCloseFile() != QMessageBox::Cancel)
01164 {
01165 settings.write();
01166 event->accept();
01167 }
01168 else
01169 {
01170 event->ignore();
01171 }
01172 }
01173
01174 void MainWindow::changeEntryStates(bool en)
01175 {
01176 actionCloseFile->setEnabled(en);
01177 startActions->setProjectOpen(en);
01178 actionProjectProperties->setEnabled(en);
01179 actionSaveFile->setEnabled(en);
01180 actionSaveFileAs->setEnabled(en);
01181 actionOpenFile->setEnabled(!en);
01182 actionPrint->setEnabled(en);
01183 actionPrintPreview->setEnabled(en);
01184 actionNewFile->setEnabled(!en);
01185 }
01186
01187 void MainWindow::reportBugs()
01188 {
01189 BugReportDialog *dialog = new BugReportDialog(settings, &mailerThread, this);
01190 dialog->show();
01191 }
01192
01193 void MainWindow::bugReportSent()
01194 {
01195 QMessageBox::information(this, "Fehlerbericht erfolgreich gesendet!", "Vielen Dank, dass Sie Ihren Beitrag dazu geleistet haben Allevo zu verbessern!");
01196 }
01197
01198 void MainWindow::bugReportSendError(QString message)
01199 {
01200 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);
01201 }
01202
01203 void MainWindow::about()
01204 {
01205 AboutDialog *dialog = new AboutDialog(aboutData, this);
01206 dialog->show();
01207 }
01208
01209 void MainWindow::setCurrentSidebarTab(int index)
01210 {
01211 sidebarTabWidget->setCurrentIndex(index);
01212 }
01213
01214 void MainWindow::showUpdaterDialog()
01215 {
01216 UpdaterDialog *dialog = new UpdaterDialog(settings, this);
01217 dialog->show();
01218 }
01219
01220 void MainWindow::showSettingsDialog()
01221 {
01222 SettingsDialog *dialog = new SettingsDialog(settings, this);
01223 connect(dialog, SIGNAL(teacherPupilSwitch()), this, SLOT(teacherPupilSwitch()));
01224 dialog->show();
01225 }
01226
01227 void MainWindow::teacherPupilSwitch()
01228 {
01229 int ret;
01230
01231 if(currentProject)
01232 {
01233
01234 if(currentProject->hasChanged())
01235 {
01236 QMessageBox msgBox;
01237 QString infoText;
01238 msgBox.setIcon(QMessageBox::Warning);
01239 msgBox.setText(tr("Sie haben den Programm-Modus geändert (Schüler/Lehrer)"));
01240 infoText = tr("Wollen Sie die Änderungen an der aktuellen Mappe speichern?\n\n");
01241 infoText += tr("Ja: Speichern und Modus ändern\n");
01242 infoText += tr("Nein: VERWERFEN und Modus ändern\n");
01243 infoText += tr("Abbrechen: Einstellungen ändern und Modus beibehalten");
01244 msgBox.setInformativeText(infoText);
01245 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
01246 msgBox.setDefaultButton(QMessageBox::Yes);
01247 ret = msgBox.exec();
01248 }
01249 else
01250 {
01251 ret = QMessageBox::No;
01252 }
01253
01254 switch(ret)
01255 {
01256 case QMessageBox::Yes:
01257 {
01258 saveFile();
01259 switchApplicationMode();
01260 }
01261 break;
01262 case QMessageBox::No:
01263 {
01264 switchApplicationMode();
01265 }
01266 break;
01267 case QMessageBox::Cancel:
01268 {
01269 settings.setTeacher(!settings.teacher());
01270 }
01271 break;
01272 default:
01273 {
01274 break;
01275 }
01276 }
01277 }
01278 else
01279 {
01280 switchApplicationMode();
01281 }
01282 }
01283
01284 void MainWindow::switchApplicationMode()
01285 {
01286 closeAndCleanup();
01287
01288
01289 accountsView->setShown(!settings.teacher());
01290 }
01291
01292 void MainWindow::showProjectInformation()
01293 {
01294 if(!currentProject)
01295 {
01296 qDebug() << "no currentProject (is NULL), thus no project info to show :-(";
01297 return;
01298 }
01299 ProjectInformationDialog *info = new ProjectInformationDialog(this, currentProject, settings.teacher());
01300 info->show();
01301 }
01302
01303 void MainWindow::openHelpBrowser()
01304 {
01305 HelpBrowserDialog *browser = new HelpBrowserDialog(aboutData, this);
01306 browser->show();
01307 }
01308
01309 void MainWindow::print()
01310 {
01311 ExerciseModel *model = NULL;
01312
01313 if(!printer)
01314 {
01315 initializePrinter();
01316 }
01317
01318 if(settings.teacher())
01319 {
01320 model = teacherActions->model;
01321 }
01322 else
01323 {
01324 model = pupilActions->model;
01325 }
01326
01327 if(model)
01328 {
01329 PrintDialog *dialog = new PrintDialog(printer, settings, model, currentProject, currentAccountModel, this);
01330 dialog->show();
01331 }
01332 }
01333
01334 void MainWindow::printPreview()
01335 {
01336
01337
01338 }
01339
01340 void MainWindow::initUpdateControls()
01341 {
01342 updateInfo = new QLabel(" ", this);
01343 updateInfo->setMinimumWidth(200);
01344
01345 statusBar()->addWidget(updateInfo);
01346 }
01347
01348
01349 void MainWindow::checkForUpdates()
01350 {
01351 if(settings.automaticCheckForUpdates())
01352 {
01353 connect(&(this->updaterManifestThread), SIGNAL(manifestReady()), this, SLOT(manifestParsed()));
01354 connect(&(this->updaterManifestThread), SIGNAL(errorOccured()), this, SLOT(mainfestErrorOccured()));
01355 this->updaterManifestThread.start();
01356
01357
01358 updateInfo->setText("UPDATER: Updates werden gesucht...");
01359 updateInfo->show();
01360 }
01361 }
01362
01363 void MainWindow::manifestParsed()
01364 {
01365
01366
01367 updateInfo->setText("Update Informationen erfolgreich geholt");
01368 }
01369
01370 void MainWindow::mainfestErrorOccured()
01371 {
01372 updateInfo->setText("Fehler beim Beziehen der Update Informationen!");
01373 }
01374
01375 void MainWindow::saveAccountingRecordsIntoDataStructures()
01376 {
01377 if(settings.teacher())
01378 {
01379 QList<AccountingRecord*> accountingRecords = sol->accountingRecordList();
01380 for(int i = 0; i < accountingRecords.size(); i++)
01381 {
01382 accountingRecords.value(i)->save();
01383 }
01384 }
01385 else
01386 {
01387 QList<AccountingRecord*> accountingRecords = rec->accountingRecordList();
01388 for(int i = 0; i < accountingRecords.size(); i++)
01389 {
01390 accountingRecords.value(i)->save();
01391 }
01392 }
01393 }