More identation fixes
[agianapa.git] / qt / leleja / myreportdialog.cpp
blobe8901f5e3e444dac867d85169a7ccb41745de2ac
1 #include <iostream>
2 #include "myreportdialog.h"
3 #include "myrank.h"
5 #include <QPainter>
6 #include <QPixmap>
7 #include <QString>
8 #include <QTextStream>
10 MyReportDialog::MyReportDialog(QWidget *parent)
11 : QDialog(parent)
13 std::cout << "MyReportDialog::MyReportDialog()\n";
16 MyReportDialog::~MyReportDialog()
18 std::cout << "MyReportDialog::~MyReportDialog()\n";
21 void MyReportDialog::paintEvent(QPaintEvent *event)
23 std::cout << "MyReportDialog::paintEvent()\n";
25 QPainter painter(this);
26 painter.drawPixmap(0, 0, m_pixmap);
29 void MyReportDialog::resizeEvent(QResizeEvent *event)
31 std::cout << "MyReportDialog::resizeEvent()\n";
33 drawPixmap();
36 void MyReportDialog::drawMyPie(QPainter *painter)
38 std::cout << "MyReportDialog::drawMyPie()\n";
40 // Days remaining
41 painter->setBrush(QBrush(Qt::red, Qt::SolidPattern));
42 painter->drawPie(0, 0,
43 this->size().width(),
44 this->size().height() / 2,
46 ((float) m_daysLeft / m_totalDays) * 16 * 360);
48 // Days off
49 painter->setBrush(QBrush(Qt::blue, Qt::SolidPattern));
50 painter->drawPie(0, 0,
51 this->size().width(),
52 this->size().height() / 2,
53 ((float) m_daysLeft / m_totalDays) * 16 * 360,
54 ((float) m_daysOff / m_totalDays) * 16 * 360);
56 // Days that have been served
57 painter->setBrush(QBrush(Qt::green, Qt::SolidPattern));
58 painter->drawPie(0, 0,
59 this->size().width(),
60 this->size().height() / 2,
61 ((float) (m_daysLeft + m_daysOff) / m_totalDays) * 16 * 360,
62 ((float) (m_totalDays - m_daysLeft - m_daysOff) / m_totalDays) * 16 * 360);
65 void MyReportDialog::drawMyLegend(QPainter *painter)
67 float percentDaysServed;
68 float percentDaysLeft;
69 float percentDaysOff;
71 std::cout << "MyReportDialog::drawMyLabel\n";
73 percentDaysServed = 100.0 * (m_totalDays - m_daysLeft - m_daysOff) / m_totalDays;
74 percentDaysLeft = 100.0 * m_daysLeft / m_totalDays;
75 percentDaysOff = 100.0 * m_daysOff / m_totalDays;
77 QString result;
78 QTextStream out(&result);
79 out.setRealNumberPrecision(2);
81 out << QString::fromUtf8("Υπηρετήθηκε = ") << percentDaysServed << "%\n";
82 out << QString::fromUtf8("Και σήμερα = ") << percentDaysLeft << "%\n";
83 out << QString::fromUtf8("Άδεια = ") << percentDaysOff << "%\n";
85 painter->setPen(QPen(Qt::white));
86 painter->drawText(QRect(0, 0, size().width(), size().height() / 2),
87 Qt::AlignCenter, result);
90 void MyReportDialog::drawMyRank(QPainter *painter)
92 unsigned int i;
94 std::cout << "MyReportDialog::drawMyRank()\n";
96 // Load rank image
97 m_image = QImage(m_rank.getImageFileName());
98 if (m_image.isNull()) {
99 std::cout << "MyReportDialog::drawMyRank(): the loading of the image failed\n";
100 // return;
103 // Draw image
104 painter->drawImage(QPoint((size().width() - m_image.width()) / 2,
105 size().height() / 2),
106 m_image);
109 void MyReportDialog::drawPixmap(void)
111 // Create a pixmap
112 m_pixmap = QPixmap(size());
113 m_pixmap.fill(this, 0, 0);
115 // Create a QPainter to draw on the pixmap
116 QPainter painter(&m_pixmap);
118 // Set the painter's pen and backround to be the same as the parent window
119 painter.initFrom(this);
121 // Enable antialiasing mode
122 painter.setRenderHint(QPainter::Antialiasing, true);
124 // Draw pie
125 drawMyPie(&painter);
127 // Draw label
128 drawMyLegend(&painter);
130 // Draw rank image
131 drawMyRank(&painter);
133 // This function won't invoke an immediate repaint,
134 // instead it will schedule a paint event that will be processed,
135 // whenever Qt returns to the main event loop.
136 update();
139 void MyReportDialog::setDaysLeft(unsigned int daysLeft)
141 m_daysLeft = daysLeft;
144 void MyReportDialog::setDaysOff(unsigned int daysOff)
146 m_daysOff = daysOff;
149 void MyReportDialog::setDaysTotal(unsigned int totalDays)
151 m_totalDays = totalDays;
154 void MyReportDialog::setRank(MyRank rank)
156 m_rank = rank;