From bd9b8cb09d23ae2e41e2962d646c9ad2c93e8853 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Sat, 2 Dec 2017 11:43:38 +0100 Subject: [PATCH] Added strips --- mainwindow.cpp | 70 +++++++++++++++++------- mainwindow.h | 11 ++-- mainwindow.ui | 9 +++- strips/buchungstrip.cpp | 33 ++++++++++++ strips/buchungstrip.h | 22 ++++++++ strips/buchungstrip.ui | 72 +++++++++++++++++++++++++ strips/kontierungstrip.cpp | 39 ++++++++++++++ strips/kontierungstrip.h | 24 +++++++++ strips/kontierungstrip.ui | 108 +++++++++++++++++++++++++++++++++++++ zeiterfassung.pro | 12 +++-- 10 files changed, 372 insertions(+), 28 deletions(-) create mode 100644 strips/buchungstrip.cpp create mode 100644 strips/buchungstrip.h create mode 100644 strips/buchungstrip.ui create mode 100644 strips/kontierungstrip.cpp create mode 100644 strips/kontierungstrip.h create mode 100644 strips/kontierungstrip.ui diff --git a/mainwindow.cpp b/mainwindow.cpp index aa47820..8a20671 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,6 +14,8 @@ #include "dialogs/aboutmedialog.h" #include "dialogs/buchungdialog.h" #include "dialogs/kontierungdialog.h" +#include "strips/buchungstrip.h" +#include "strips/kontierungstrip.h" #include "models/buchungenmodel.h" #include "models/kontierungenmodel.h" @@ -79,6 +81,28 @@ MainWindow::~MainWindow() delete ui; } +int MainWindow::timeToSeconds(const QTime &time) +{ + return QTime(0, 0).secsTo(time); +} + +QTime MainWindow::timeBetween(const QTime &l, const QTime &r) +{ + Q_ASSERT(l <= r); + return QTime(0, 0).addSecs(l.secsTo(r)); +} + +QTime MainWindow::timeAdd(const QTime &l, const QTime &r) +{ + Q_ASSERT(timeToSeconds(l) + timeToSeconds(r) < 86400); + return l.addSecs(QTime(0, 0).secsTo(r)); +} + +QTime MainWindow::timeNormalise(const QTime &time) +{ + return time.addSecs(-time.second()); +} + void MainWindow::refresh() { ui->actionToday->setEnabled(false); @@ -119,6 +143,8 @@ void MainWindow::refresh() ui->actionRefresh->setEnabled(true); ui->dateEditDate->setReadOnly(false); } + + clearStrips(); } void MainWindow::getProjekteFinished(bool success, const QString &message, const QVector &projekte) @@ -215,6 +241,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewBuchungen->setEnabled(false); + clearStrips(); + if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_buchungenModel, &BuchungenModel::refreshFinished, @@ -263,6 +291,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewBuchungen->setEnabled(false); + clearStrips(); + if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_buchungenModel, &BuchungenModel::refreshFinished, @@ -315,6 +345,8 @@ void MainWindow::contextMenuBuchung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewBuchungen->setEnabled(false); + clearStrips(); + if(m_buchungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_buchungenModel, &BuchungenModel::refreshFinished, @@ -385,6 +417,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewKontierungen->setEnabled(false); + clearStrips(); + if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_kontierungenModel, &KontierungenModel::refreshFinished, @@ -433,6 +467,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewKontierungen->setEnabled(false); + clearStrips(); + if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_kontierungenModel, &KontierungenModel::refreshFinished, @@ -485,6 +521,8 @@ void MainWindow::contextMenuKontierung(const QPoint &pos) ui->pushButtonEnd->setEnabled(false); ui->treeViewKontierungen->setEnabled(false); + clearStrips(); + if(m_kontierungenModel->refresh(m_userInfo.userId, ui->dateEditDate->date(), ui->dateEditDate->date())) { connect(m_kontierungenModel, &KontierungenModel::refreshFinished, @@ -718,6 +756,7 @@ void MainWindow::validateEntries() } m_lastKontierungStart = startBuchung.time; + ui->verticalLayout2->addWidget(new BuchungStrip(startBuchung.time, startBuchung.type, ui->scrollAreaWidgetContents)); if(kontierungenIter == m_kontierungenModel->constEnd()) { @@ -737,6 +776,9 @@ void MainWindow::validateEntries() return; } + ui->verticalLayout2->addWidget(new KontierungStrip(QTime(0, 0), kontierung.timespan, kontierung.projekt, + kontierung.subprojekt, kontierung.workpackage, kontierung.text)); + if(kontierung.timespan == QTime(0, 0)) { if(buchungenIter != m_buchungenModel->constEnd()) @@ -876,6 +918,8 @@ void MainWindow::validateEntries() m_kontierungTime = timeAdd(m_kontierungTime, kontierung.timespan); } } + + ui->verticalLayout2->addWidget(new BuchungStrip(endBuchung.time, endBuchung.type, ui->scrollAreaWidgetContents)); } } } @@ -955,24 +999,12 @@ void MainWindow::updateComboboxes() } } -int MainWindow::timeToSeconds(const QTime &time) +void MainWindow::clearStrips() { - return QTime(0, 0).secsTo(time); -} - -QTime MainWindow::timeBetween(const QTime &l, const QTime &r) -{ - Q_ASSERT(l <= r); - return QTime(0, 0).addSecs(l.secsTo(r)); -} - -QTime MainWindow::timeAdd(const QTime &l, const QTime &r) -{ - Q_ASSERT(timeToSeconds(l) + timeToSeconds(r) < 86400); - return l.addSecs(QTime(0, 0).secsTo(r)); -} - -QTime MainWindow::timeNormalise(const QTime &time) -{ - return time.addSecs(-time.second()); + QLayoutItem *item; + while(item = ui->verticalLayout2->takeAt(0)) + { + item->widget()->deleteLater(); + delete item; + } } diff --git a/mainwindow.h b/mainwindow.h index 65eaa87..3eb7b8d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,6 +19,11 @@ public: explicit MainWindow(QSettings &settings, Zeiterfassung &erfassung, const Zeiterfassung::UserInfo &userInfo, QWidget *parent = 0); ~MainWindow(); + static int timeToSeconds(const QTime &time); + static QTime timeBetween(const QTime &l, const QTime &r); + static QTime timeAdd(const QTime &l, const QTime &r); + static QTime timeNormalise(const QTime &time); + private Q_SLOTS: void refresh(); void getProjekteFinished(bool success, const QString &message, const QVector &projekte); @@ -34,11 +39,7 @@ private Q_SLOTS: private: void validateEntries(); void updateComboboxes(); - - static int timeToSeconds(const QTime &time); - static QTime timeBetween(const QTime &l, const QTime &r); - static QTime timeAdd(const QTime &l, const QTime &r); - static QTime timeNormalise(const QTime &time); + void clearStrips(); Ui::MainWindow *ui; QSettings &m_settings; diff --git a/mainwindow.ui b/mainwindow.ui index 8ebe0f3..805b48e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -176,10 +176,17 @@ 0 - + + + true + Optimized view + + + + diff --git a/strips/buchungstrip.cpp b/strips/buchungstrip.cpp new file mode 100644 index 0000000..ed0c8b9 --- /dev/null +++ b/strips/buchungstrip.cpp @@ -0,0 +1,33 @@ +#include "buchungstrip.h" +#include "ui_buchungstrip.h" + +#include + +BuchungStrip::BuchungStrip(const QTime &time, const QString &type, QWidget *parent) : + QFrame(parent), + ui(new Ui::BuchungStrip) +{ + ui->setupUi(this); + + ui->labelTime->setText(time.toString("HH:mm")); + if(type == QStringLiteral("K")) + { + setStyleSheet("background-color: #7FFF7F;"); + ui->labelType->setText(tr("KOMMEN")); + } + else if(type == QStringLiteral("G")) + { + setStyleSheet("background-color: #FF7F7F;"); + ui->labelType->setText(tr("GEHEN")); + } + else + { + setStyleSheet("background-color: #FFFF7F;"); + ui->labelType->setText(tr("UNKNOWN")); + } +} + +BuchungStrip::~BuchungStrip() +{ + delete ui; +} diff --git a/strips/buchungstrip.h b/strips/buchungstrip.h new file mode 100644 index 0000000..894a214 --- /dev/null +++ b/strips/buchungstrip.h @@ -0,0 +1,22 @@ +#ifndef BUCHUNGSTRIP_H +#define BUCHUNGSTRIP_H + +#include + +class QTime; + +namespace Ui { class BuchungStrip; } + +class BuchungStrip : public QFrame +{ + Q_OBJECT + +public: + explicit BuchungStrip(const QTime &time, const QString &type, QWidget *parent = 0); + ~BuchungStrip(); + +private: + Ui::BuchungStrip *ui; +}; + +#endif // BUCHUNGSTRIP_H diff --git a/strips/buchungstrip.ui b/strips/buchungstrip.ui new file mode 100644 index 0000000..2bd6c2d --- /dev/null +++ b/strips/buchungstrip.ui @@ -0,0 +1,72 @@ + + + BuchungStrip + + + + 0 + 0 + 500 + 50 + + + + + 0 + 50 + + + + + 16777215 + 50 + + + + Form + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 20 + + + + + + 20 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + TextLabel + + + + + + + + 20 + + + + TextLabel + + + + + + + + diff --git a/strips/kontierungstrip.cpp b/strips/kontierungstrip.cpp new file mode 100644 index 0000000..607fb43 --- /dev/null +++ b/strips/kontierungstrip.cpp @@ -0,0 +1,39 @@ +#include "kontierungstrip.h" +#include "ui_kontierungstrip.h" + +#include +#include + +#include "mainwindow.h" + +KontierungStrip::KontierungStrip(const QTime &startTime, const QTime &endTime, const QString &projekt, + const QString &subprojekt, const QString &workpackage, const QString &text, + QWidget *parent) : + QFrame(parent), + ui(new Ui::KontierungStrip) +{ + ui->setupUi(this); + + setStyleSheet("background-color: #7FFFFF;"); + + if(endTime == QTime(0, 0)) + { + ui->labelTime->setText(QStringLiteral("%0 - ???").arg(startTime.toString("HH:mm"))); + ui->labelDuration->setText(QStringLiteral("(???h)")); + } + else + { + ui->labelTime->setText(startTime.toString("HH:mm") % " - " % endTime.toString("HH:mm")); + ui->labelDuration->setText("(" % MainWindow::timeBetween(startTime, endTime).toString("HH:mm") % "h)"); + } + + ui->labelProjekt->setText(projekt); + ui->labelSubprojekt->setText(subprojekt); + ui->labelWorkpackage->setText(workpackage); + ui->labelText->setText(text); +} + +KontierungStrip::~KontierungStrip() +{ + delete ui; +} diff --git a/strips/kontierungstrip.h b/strips/kontierungstrip.h new file mode 100644 index 0000000..e777a9c --- /dev/null +++ b/strips/kontierungstrip.h @@ -0,0 +1,24 @@ +#ifndef KONTIERUNGSTRIP_H +#define KONTIERUNGSTRIP_H + +#include + +class QTime; + +namespace Ui { class KontierungStrip; } + +class KontierungStrip : public QFrame +{ + Q_OBJECT + +public: + explicit KontierungStrip(const QTime &startTime, const QTime &endTime, const QString &projekt, + const QString &subprojekt, const QString &workpackage, const QString &text, + QWidget *parent = 0); + ~KontierungStrip(); + +private: + Ui::KontierungStrip *ui; +}; + +#endif // KONTIERUNGSTRIP_H diff --git a/strips/kontierungstrip.ui b/strips/kontierungstrip.ui new file mode 100644 index 0000000..445cc18 --- /dev/null +++ b/strips/kontierungstrip.ui @@ -0,0 +1,108 @@ + + + KontierungStrip + + + + 0 + 0 + 500 + 102 + + + + + 0 + 100 + + + + + 16777215 + 102 + + + + Form + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 20 + + + + + + + + 20 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + TextLabel + + + + + + + + 20 + + + + TextLabel + + + + + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + + + + diff --git a/zeiterfassung.pro b/zeiterfassung.pro index 72e140b..89ba250 100755 --- a/zeiterfassung.pro +++ b/zeiterfassung.pro @@ -23,7 +23,9 @@ SOURCES += main.cpp \ models/buchungenmodel.cpp \ dialogs/kontierungdialog.cpp \ models/kontierungenmodel.cpp \ - eventloopwithstatus.cpp + eventloopwithstatus.cpp \ + strips/buchungstrip.cpp \ + strips/kontierungstrip.cpp HEADERS += \ zeiterfassung.h \ @@ -34,7 +36,9 @@ HEADERS += \ models/buchungenmodel.h \ dialogs/kontierungdialog.h \ models/kontierungenmodel.h \ - eventloopwithstatus.h + eventloopwithstatus.h \ + strips/buchungstrip.h \ + strips/kontierungstrip.h RESOURCES += \ resources.qrc @@ -44,4 +48,6 @@ FORMS += \ dialogs/aboutmedialog.ui \ dialogs/authenticationdialog.ui \ dialogs/buchungdialog.ui \ - dialogs/kontierungdialog.ui + dialogs/kontierungdialog.ui \ + strips/buchungstrip.ui \ + strips/kontierungstrip.ui