From 3b18cfe7fae56bd0b16b277cd2fb8b9591394d82 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Wed, 9 Oct 2019 14:00:35 +0200 Subject: [PATCH] initial commit --- cmonthlyitemdelegate.cpp | 6 +- cmonthlyview.cpp | 52 ++++++- cmonthlyview.ui | 305 ++++++++++++++++++++++++++++++++++++--- common.h | 8 + cpublicholiday.cpp | 35 ++++- cpublicholiday.h | 53 ++++++- 6 files changed, 431 insertions(+), 28 deletions(-) diff --git a/cmonthlyitemdelegate.cpp b/cmonthlyitemdelegate.cpp index 6bf9441..58cffa6 100644 --- a/cmonthlyitemdelegate.cpp +++ b/cmonthlyitemdelegate.cpp @@ -30,6 +30,9 @@ QWidget* cMonthlyItemDelegate::createEditor( QWidget *parent, const QStyleOption } case COL_CODE: { + if(index.data(Qt::UserRole+1).toBool()) + return(nullptr); + QComboBox* lpComboBox = new QComboBox(parent); for(QMap::const_iterator i = m_code.constBegin();i != m_code.constEnd();i++) @@ -93,7 +96,8 @@ void cMonthlyItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *m QTimeEdit* lpTimeEdit = qobject_cast(editor); if(!lpTimeEdit->time().hour() && !lpTimeEdit->time().minute() && - !lpTimeEdit->time().second()) + !lpTimeEdit->time().second() && + index.column() != COL_BREAK) model->setData(index, "", Qt::EditRole); else model->setData(index, lpTimeEdit->time().toString(), Qt::EditRole); diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp index 7b487cd..70e039f 100644 --- a/cmonthlyview.cpp +++ b/cmonthlyview.cpp @@ -23,6 +23,15 @@ cMonthlyView::cMonthlyView(const QDate& date, QWidget *parent) : ui->m_lpMonthlyList->setItemDelegate(new cMonthlyItemDelegate(m_code)); + ui->m_lpGleitzeitLabel->setAutoFillBackground(true); + ui->m_lpGleitzeitLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_GLEITZEIT.red()).arg(COLOR_GLEITZEIT.green()).arg(COLOR_GLEITZEIT.blue())); + ui->m_lpKrankLabel->setAutoFillBackground(true); + ui->m_lpKrankLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_KRANK.red()).arg(COLOR_KRANK.green()).arg(COLOR_KRANK.blue())); + ui->m_lpUrlaubLabel->setAutoFillBackground(true); + ui->m_lpUrlaubLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_URLAUB.red()).arg(COLOR_URLAUB.green()).arg(COLOR_URLAUB.blue())); + ui->m_lpSonderurlaubLabel->setAutoFillBackground(true); + ui->m_lpSonderurlaubLabel->setStyleSheet(QString("QLabel { background-color: rgba(%1, %2, %3, 255); }").arg(COLOR_SONDERURLAUB.red()).arg(COLOR_SONDERURLAUB.green()).arg(COLOR_SONDERURLAUB.blue())); + setDate(date); connect(static_cast(ui->m_lpMonthlyList->itemDelegate()), &cMonthlyItemDelegate::timeChanged, this, &cMonthlyView::onTimeChanged); @@ -53,9 +62,9 @@ void cMonthlyView::setDate(const QDate& date) items[COL_CODE]->setText(""); items[COL_IS]->setText("00:00:00"); items[COL_SHOULD]->setText("00:00:00"); - items[COL_DIFF]->setText("00:00:00"); + items[COL_DIFF]->setText("+00:00:00"); items[COL_INFORMATION]->setText(""); - items[COL_CURRENT]->setText("00:00:00"); + items[COL_CURRENT]->setText("+00:00:00"); items[COL_HOURS_DEC]->setText("0.0"); items[COL_DAY2]->setText("99"); @@ -66,6 +75,7 @@ void cMonthlyView::setDate(const QDate& date) m_lpMonthlyListModel->removeRows(0, 1); + QBrush weekend = QBrush(COLOR_WEEKEND); QDate date1 = date; date1.setDate(date.year(), date.month(), 1); @@ -112,10 +122,27 @@ void cMonthlyView::setDate(const QDate& date) items[COL_HOURS_DEC]->setTextAlignment(Qt::AlignRight); items[COL_DAY2]->setTextAlignment(Qt::AlignLeft); + for(int z = 0;z < items.count();z++) + { + if(date1.dayOfWeek() >= 6) + { + items[z]->setData(QVariant::fromValue(true), Qt::UserRole+1); + items[z]->setBackground(weekend); + } + else + items[z]->setData(QVariant::fromValue(false), Qt::UserRole+1); + } + m_lpMonthlyListModel->appendRow(items); } ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY1); ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY2); + + ui->m_lpUebertragLabel->setText(QString(tr("Übertrag %1:")).arg(date.addMonths(-1).toString("MMMM yyyy"))); + ui->m_lpShouldLabel->setText(QString(tr("SOLL Arbeitszeit (%1):")).arg(date.toString("MMMM yyyy"))); + ui->m_lpIsLabel->setText(QString(tr("IST Arbeitszeit (%1):")).arg(date.toString("MMMM yyyy"))); + ui->m_lpResturlaubLabel->setText(QString(tr("Resturlaub %1:")).arg(date.addMonths(-1).toString("MMMM yyyy"))); + ui->m_lpRestSonderurlaubLabel->setText(QString(tr("Sonderurlaub %1:")).arg(date.addMonths(-1).toString("MMMM yyyy"))); } cMonthlyView::~cMonthlyView() @@ -135,4 +162,25 @@ void cMonthlyView::onTextChanged(const int day, const int field, const QString& qDebug() << "Day: " << day; qDebug() << "field: " << field; qDebug() << "time: " << text; + + if(field == COL_CODE) + { + QBrush brush; + QString code = m_code.key(text); + + if(code == "G") + brush = QBrush(COLOR_GLEITZEIT); + else if(code == "U") + brush = QBrush(COLOR_URLAUB); + else if(code == "K") + brush = QBrush(COLOR_KRANK); + else if(code == "SU") + brush = QBrush(COLOR_SONDERURLAUB); + + for(int x = 0;x < m_lpMonthlyListModel->columnCount();x++) + { + QStandardItem* lpItem = m_lpMonthlyListModel->item(day-1, x); + lpItem->setBackground(brush); + } + } } diff --git a/cmonthlyview.ui b/cmonthlyview.ui index 1e32c4f..09546b9 100644 --- a/cmonthlyview.ui +++ b/cmonthlyview.ui @@ -6,42 +6,303 @@ 0 0 - 996 + 883 525 Form - + - - - true - - - - - 0 - 0 - 976 - 505 - - - + + + + + true + + + + + 0 + 0 + 861 + 241 + + + + + + + true + + + false + + + + + + + + + + + + + Resturlaub: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + - - + + + + + + + + + true - - false + + + + + + true + + + + + + + true + + + + + + + ausbezahlte Überstunden: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Übertrag nächster Monat: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + + + + IST: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Sonderurlaub: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Übertrag Urlaub: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Saldo: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + + + + Gleitzeit + + + + + + + Krank + + + + + + + SOLL: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Urlaub + + + + + + + true + + + + + + + Übertrag: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + + + + true + + + + + + + Sonderurlaub + + + + + + + Übertrag Sonderurlaub: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + HH:mm:ss + + + + + + + - - + + diff --git a/common.h b/common.h index 1818e6f..763df28 100644 --- a/common.h +++ b/common.h @@ -2,6 +2,9 @@ #define COMMON_H +#include + + #define COL_DAY1 0 #define COL_PUBLIC_HOLIDAY 1 #define COL_COME1 2 @@ -20,5 +23,10 @@ #define COL_HOURS_DEC 15 #define COL_DAY2 16 +#define COLOR_GLEITZEIT QColor(191, 191, 255) +#define COLOR_URLAUB QColor(127, 127, 255) +#define COLOR_SONDERURLAUB QColor(127, 127, 255) +#define COLOR_KRANK QColor(Qt::yellow) +#define COLOR_WEEKEND QColor(255, 165, 0) #endif // COMMON_H diff --git a/cpublicholiday.cpp b/cpublicholiday.cpp index 2f6cb9e..0858e47 100644 --- a/cpublicholiday.cpp +++ b/cpublicholiday.cpp @@ -1,7 +1,38 @@ #include "cpublicholiday.h" +#include -cPublicHoliday::cPublicHoliday() + +cPublicHoliday::cPublicHoliday(qint16 year) : + m_year(year) { - + m_holidays.insert(ostersonntag(), QObject::tr("Ostersonntag")); +} + +bool cPublicHoliday::isPublicHoliday(const QDate& date) +{ + return(m_holidays.contains(date)); +} + +QString cPublicHoliday::name(const QDate& date) +{ + return(m_holidays.value(date, "")); +} + +QDate cPublicHoliday::ostersonntag() +{ + int a = m_year % 19; + int b = m_year / 100; + int c = m_year % 100; + int e = b % 4; + int f = (b + 8) / 25; + int g = (b - f + 1) / 3; + int h = (19 * a + b - (b/4) - g + 15) % 30; + int k = c % 4; + int l = (32 + 2 * e + 2 * (c / 4) - h - k) % 7; + int m = (a + 11 * h + 22 * l) / 451; + int nMonth = (h + l - 7 * m + 114) / 31; + int nDay = (h + l - 7 * m + 114) % 31 + 1; + + return(QDate(m_year, nMonth, nDay)); } diff --git a/cpublicholiday.h b/cpublicholiday.h index af06d8c..99162e4 100644 --- a/cpublicholiday.h +++ b/cpublicholiday.h @@ -2,10 +2,61 @@ #define CPUBLICHOLIDAY_H +#include +#include + +#include + + class cPublicHoliday { public: - cPublicHoliday(); + cPublicHoliday(qint16 year); + + bool isPublicHoliday(const QDate& date); + QString name(const QDate& date); + +private: + qint16 m_year; + QMap m_holidays; + + QDate neujahr(); + QDate heilige3Koenige(); + QDate karfreitag(); + QDate ostersonntag(); + QDate ostermontag(); + QDate staatsfeiertag1(); + QDate christiHimmelfahrt(); + QDate pfingstsonntag(); + QDate pfingstMontag(); + QDate fronleichnam(); + QDate mariaHimmelfahrt(); + QDate staatsfeiertag(); + QDate allerheiligen(); + QDate silvester(); }; +/* +1,1,jahr, "Neujahr (18 Uhr)" +6,1,jahr, "Hl. Drei Könige" +14,7,jahr, "Sel. Bernhard" +15,8,jahr, "Mariä Himmelfahrt" +1,11,jahr, "Allerheiligen" +8,12,jahr, "Maria Empfängnis" +24,12,jahr, "Heilig Abend" +25,12,jahr, "1.Weihnachtsfeiertag" +26,12,jahr, "2.Weihnachtsfeiertag" +// von Ostern abhängige Feiertage +Ostern-46, "Aschermittwoch" +Ostern-7, "Palmsonntag" +Ostern-3, "Gründonnerstag" +Ostern-2, "Karfreitag" +Ostern-1, "Karsamstag" +Ostern, "Ostersonntag" +Ostern+1, "Ostermontag" +Ostern+39, "Christi Himmelfahrt" +Ostern+49, "Pfingstsonntag" +Ostern+50, "Pfingstmontag" +Ostern+60, "Fronleichnam" +*/ #endif // CPUBLICHOLIDAY_H