From 1aa96896fa8a5ccdeb6370bba3ff2f121f81bef8 Mon Sep 17 00:00:00 2001 From: birkeh Date: Tue, 25 Sep 2018 19:20:57 +0200 Subject: [PATCH] added scene date --- coptionsdialog.cpp | 2 +- cscenewindow.cpp | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/coptionsdialog.cpp b/coptionsdialog.cpp index 835ee10..f4c0bed 100644 --- a/coptionsdialog.cpp +++ b/coptionsdialog.cpp @@ -71,7 +71,7 @@ cOptionsDialog::cOptionsDialog(QWidget *parent) : ui->m_lpLanguage->setCurrentText(szCur); connect(ui->m_lpLanguage, QOverload::of(&QComboBox::currentIndexChanged), this, &cOptionsDialog::onLanguageIndexChanged); - connect(ui->m_lpButtonBox, QDialogButtonBox::clicked, this, &cOptionsDialog::onButtonClicked); + connect(ui->m_lpButtonBox, &QDialogButtonBox::clicked, this, &cOptionsDialog::onButtonClicked); retranslateUI(); } diff --git a/cscenewindow.cpp b/cscenewindow.cpp index 36e15cb..440df5b 100644 --- a/cscenewindow.cpp +++ b/cscenewindow.cpp @@ -262,6 +262,29 @@ void cSceneWindow::onSceneDateChanged(const QDateTime& dateTime) { m_lpScene->setSceneDate(dateTime); m_lpMainWindow->somethingChanged(); + + QList characterList = m_lpScene->characterList(); + + for(int x = 0;x < characterList.count();x++) + { + cCharacterDescription* lpCharacterDescription = characterList[x]; + cCharacter* lpCharacter = lpCharacterDescription->character(); + + if(m_lpScene->sceneDate() != QDateTime(QDate(1900, 1, 1)) && + lpCharacter->dateOfBirth() != QDate(1900, 1, 1)) + { + qint32 years = m_lpScene->sceneDate().date().year() - lpCharacter->dateOfBirth().year(); + if(lpCharacter->dateOfBirth().month() < m_lpScene->sceneDate().date().year()) + years--; + else if(lpCharacter->dateOfBirth().month() == m_lpScene->sceneDate().date().month() && + lpCharacter->dateOfBirth().day() > m_lpScene->sceneDate().date().day()) + years--; + + ui->m_lpCharacterList->setItemText(x, QString("%1 (age: %2 years)").arg(lpCharacter->name()).arg(years)); + } + else + ui->m_lpCharacterList->setItemText(x, lpCharacter->name()); + } } void cSceneWindow::onTextChanged() @@ -440,7 +463,20 @@ void cSceneWindow::fillCharacterList(cCharacter* lpCharacterNew) cCharacterDescription* lpCharacterDescription = characterList[x]; cCharacter* lpCharacter = lpCharacterDescription->character(); - ui->m_lpCharacterList->addItem(lpCharacter->name(), QVariant::fromValue(lpCharacterDescription)); + if(m_lpScene->sceneDate() != QDateTime(QDate(1900, 1, 1)) && + lpCharacter->dateOfBirth() != QDate(1900, 1, 1)) + { + qint32 years = m_lpScene->sceneDate().date().year() - lpCharacter->dateOfBirth().year(); + if(lpCharacter->dateOfBirth().month() < m_lpScene->sceneDate().date().year()) + years--; + else if(lpCharacter->dateOfBirth().month() == m_lpScene->sceneDate().date().month() && + lpCharacter->dateOfBirth().day() > m_lpScene->sceneDate().date().day()) + years--; + + ui->m_lpCharacterList->addItem(QString("%1 (age: %2 years)").arg(lpCharacter->name()).arg(years), QVariant::fromValue(lpCharacterDescription)); + } + else + ui->m_lpCharacterList->addItem(lpCharacter->name(), QVariant::fromValue(lpCharacterDescription)); cTextEdit* lpTextEdit = new cTextEdit(ui->m_lpCharacterDetails); lpTextEdit->setDocument(lpCharacterDescription->description()); ui->m_lpCharacterDetails->addWidget(lpTextEdit);