From f1258a029e83314e738a3243d760613553667d50 Mon Sep 17 00:00:00 2001 From: Stathis Kamperis Date: Wed, 23 Jul 2008 01:43:42 +0300 Subject: [PATCH] Track tab report dialog files --- qt/leleja/mytabreportdialog.cpp | 173 ++++++++++++++++++++++++++++++++++++++++ qt/leleja/mytabreportdialog.h | 54 +++++++++++++ qt/leleja/tabReportDialog.ui | 22 +++-- 3 files changed, 242 insertions(+), 7 deletions(-) create mode 100644 qt/leleja/mytabreportdialog.cpp create mode 100644 qt/leleja/mytabreportdialog.h diff --git a/qt/leleja/mytabreportdialog.cpp b/qt/leleja/mytabreportdialog.cpp new file mode 100644 index 0000000..0749353 --- /dev/null +++ b/qt/leleja/mytabreportdialog.cpp @@ -0,0 +1,173 @@ +#include +#include "mytabreportdialog.h" +#include "myrank.h" + +#include +#include +#include +#include + +MyTabReportDialog::MyTabReportDialog(QWidget *parent) + : QDialog(parent) +{ + std::cout << "MyTabReportDialog::MyTabReportDialog()\n"; + + setupUi(this); +} + +MyTabReportDialog::~MyTabReportDialog() +{ + std::cout << "MyTabReportDialog::~MyTabReportDialog()\n"; +} + +void MyTabReportDialog::paintEvent(QPaintEvent *event) +{ + std::cout << "MyTabReportDialog::paintEvent()\n"; + + // QPainter painter(labelGraphics->pixmap()); + // painter.drawPixmap(0, 0, m_pixmap); + labelGraphics->setScaledContents(true); + labelGraphics->setPixmap(m_piePixmap); + + labelRank->setScaledContents(true); + labelRank->setPixmap(m_rankPixmap); +} + +void MyTabReportDialog::resizeEvent(QResizeEvent *event) +{ + std::cout << "MyTabReportDialog::resizeEvent()\n"; + + drawPixmaps(); +} + +void MyTabReportDialog::drawMyPie(QPainter *painter) +{ + std::cout << "MyTabReportDialog::drawMyPie()\n"; + + // Days remaining + painter->setBrush(QBrush(Qt::red, Qt::SolidPattern)); + painter->drawPie(0, 0, + labelGraphics->size().width(), + labelGraphics->size().height(), + 0, + ((float) m_daysLeft / m_totalDays) * 16 * 360); + + // Days off + painter->setBrush(QBrush(Qt::blue, Qt::SolidPattern)); + painter->drawPie(0, 0, + labelGraphics->size().width(), + labelGraphics->size().height(), + ((float) m_daysLeft / m_totalDays) * 16 * 360, + ((float) m_daysOff / m_totalDays) * 16 * 360); + + // Days that have been served + painter->setBrush(QBrush(Qt::green, Qt::SolidPattern)); + painter->drawPie(0, 0, + labelGraphics->size().width(), + labelGraphics->size().height(), + ((float) (m_daysLeft + m_daysOff) / m_totalDays) * 16 * 360, + ((float) (m_totalDays - m_daysLeft - m_daysOff) / m_totalDays) * 16 * 360); +} + +void MyTabReportDialog::drawMyLegend(QPainter *painter) +{ + QString resultStr; + float percentDaysServed; + float percentDaysLeft; + float percentDaysOff; + + std::cout << "MyTabReportDialog::drawMyLabel\n"; + + // Calculate percentages + percentDaysServed = 100.0 * (m_totalDays - m_daysLeft - m_daysOff) / m_totalDays; + percentDaysLeft = 100.0 * m_daysLeft / m_totalDays; + percentDaysOff = 100.0 * m_daysOff / m_totalDays; + + // Print percentages into a string using a text stream + QTextStream out(&resultStr); + out.setRealNumberPrecision(3); + + out << QString::fromUtf8("Υπηρετήθηκε = ") << percentDaysServed << "%\n"; + out << QString::fromUtf8("Και σήμερα = ") << percentDaysLeft << "%\n"; + out << QString::fromUtf8("Άδεια = ") << percentDaysOff << "%\n"; + + // Draw string + painter->setPen(QPen(Qt::white)); + painter->drawText(QRect(0, 0, size().width(), size().height() / 2), + Qt::AlignCenter, resultStr); +} + +void MyTabReportDialog::drawMyRank(QPainter *painter) +{ + unsigned int i; + + std::cout << "MyTabReportDialog::drawMyRank()\n"; + + // Load rank image + m_image = QImage(m_rank.getImageFileName()); + if (m_image.isNull()) { + std::cout << "MyTabReportDialog::drawMyRank(): the loading of the image failed\n"; + // return; + } + + // Draw rank image + painter->drawImage(QPoint((labelRank->size().width() - m_image.width()) / 2, + (labelRank->size().height() - m_image.height()) / 2), + m_image); +} + +void MyTabReportDialog::drawPixmaps(void) +{ + // Create the pixmaps + m_piePixmap = QPixmap(labelGraphics->size()); + m_rankPixmap = QPixmap(labelRank->size()); + + m_piePixmap.fill(this, 0, 0); + m_rankPixmap.fill(this, 0, 0); + + // Create a QPainter to draw on the pixmap + QPainter piePainter(&m_piePixmap); + QPainter rankPainter(&m_rankPixmap); + + // Set the painter's pen and backround to be the same as the parent window + piePainter.initFrom(this); + rankPainter.initFrom(this); + + // Enable antialiasing mode + piePainter.setRenderHint(QPainter::Antialiasing, true); + rankPainter.setRenderHint(QPainter::Antialiasing, true); + + // Draw pie + drawMyPie(&piePainter); + + // Draw label + drawMyLegend(&piePainter); + + // Draw rank image + drawMyRank(&rankPainter); + + // This function won't invoke an immediate repaint, + // instead it will schedule a paint event that will be processed, + // whenever Qt returns to the main event loop. + update(); +} + +void MyTabReportDialog::setDaysLeft(unsigned int daysLeft) +{ + m_daysLeft = daysLeft; +} + +void MyTabReportDialog::setDaysOff(unsigned int daysOff) +{ + m_daysOff = daysOff; +} + +void MyTabReportDialog::setDaysTotal(unsigned int totalDays) +{ + m_totalDays = totalDays; +} + +void MyTabReportDialog::setRank(MyRank rank) +{ + m_rank = rank; +} diff --git a/qt/leleja/mytabreportdialog.h b/qt/leleja/mytabreportdialog.h new file mode 100644 index 0000000..ad73368 --- /dev/null +++ b/qt/leleja/mytabreportdialog.h @@ -0,0 +1,54 @@ +#ifndef MYTABREPORTDIALOG_H +#define MYTABREPORTDIALOG_H + +#include +#include + +#include "ui_tabReportDialog.h" + +#include "myrank.h" + +class MyTabReportDialog : public QDialog, public Ui::tabReportDialog +{ + Q_OBJECT + +public: + MyTabReportDialog(QWidget *parent = 0); + ~MyTabReportDialog(); + + void setDaysLeft(unsigned int daysleft); + void setDaysOff(unsigned int daysOff); + void setDaysTotal(unsigned int totaldays); + + void setRank(MyRank rank); + +public slots: + void redrawContent(void) { drawPixmaps(); } + +protected: + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + void drawMyLegend(QPainter *painter); + void drawMyPie(QPainter *painter); + void drawMyRank(QPainter *painter); + void drawPixmaps(void); + + // Off screen image representation that can be used as a paint device + QPixmap m_piePixmap; + QPixmap m_rankPixmap; + + // Holds information regarding the rank (mark, name, etc) + MyRank m_rank; + + bool rankChanged; + + QImage m_image; + + unsigned int m_daysLeft; + unsigned int m_daysOff; + unsigned int m_totalDays; +}; + +#endif // MYTABREPORTDIALOG_H diff --git a/qt/leleja/tabReportDialog.ui b/qt/leleja/tabReportDialog.ui index 06c778e..99d6829 100644 --- a/qt/leleja/tabReportDialog.ui +++ b/qt/leleja/tabReportDialog.ui @@ -6,7 +6,7 @@ 0 0 417 - 228 + 308 @@ -18,11 +18,11 @@ 10 10 401 - 211 + 291 - 0 + 2 @@ -30,7 +30,7 @@ 0 0 397 - 184 + 264 @@ -158,7 +158,7 @@ 0 0 397 - 184 + 264 @@ -170,7 +170,7 @@ 10 10 381 - 161 + 241 @@ -182,6 +182,14 @@ + + + 0 + 0 + 397 + 264 + + Βαθμός @@ -191,7 +199,7 @@ 10 10 381 - 161 + 241 -- 2.11.4.GIT