Remove whitespace
[agianapa.git] / qt / leleja / myreportdialog.cpp
blob5d309bd3add753661771816c5c71c8260ba698f7
1 #include <iostream>
2 #include "myreportdialog.h"
4 #include <QPainter>
5 #include <QPixmap>
6 #include <QString>
7 #include <QTextStream>
9 MyReportDialog::MyReportDialog(QWidget *parent)
10 : QDialog(parent)
12 std::cout << "MyReportDialog::MyReportDialog()\n";
15 MyReportDialog::~MyReportDialog()
17 std::cout << "MyReportDialog::~MyReportDialog()\n";
20 void MyReportDialog::paintEvent(QPaintEvent *event)
22 std::cout << "MyReportDialog::paintEvent()\n";
24 QPainter painter(this);
25 painter.drawPixmap(0, 0, m_pixmap);
28 void MyReportDialog::resizeEvent(QResizeEvent *event)
30 std::cout << "MyReportDialog::resizeEvent()\n";
32 drawPixmap();
35 void MyReportDialog::drawMyPie(QPainter *painter)
37 std::cout << "MyReportDialog::drawMyPie()\n";
39 // Days remaining
40 painter->setBrush(QBrush(Qt::red, Qt::SolidPattern));
41 painter->drawPie(0, 0,
42 this->size().width(),
43 this->size().height(),
45 ((float) m_daysLeft / m_totalDays) * 16 * 360);
47 // Days off
48 painter->setBrush(QBrush(Qt::blue, Qt::SolidPattern));
49 painter->drawPie(0, 0,
50 this->size().width(),
51 this->size().height(),
52 ((float) m_daysLeft / m_totalDays) * 16 * 360,
53 ((float) m_daysOff / m_totalDays) * 16 * 360);
55 // Days that have been served
56 painter->setBrush(QBrush(Qt::green, Qt::SolidPattern));
57 painter->drawPie(0, 0,
58 this->size().width(),
59 this->size().height(),
60 ((float) (m_daysLeft + m_daysOff) / m_totalDays) * 16 * 360,
61 ((float) (m_totalDays - m_daysLeft - m_daysOff) / m_totalDays) * 16 * 360);
64 void MyReportDialog::drawMyLegend(QPainter *painter)
66 float percentDaysServed;
67 float percentDaysLeft;
68 float percentDaysOff;
70 std::cout << "MyReportDialog::drawMyLabel\n";
72 percentDaysServed = (float) (m_totalDays - m_daysLeft) / m_totalDays;
73 percentDaysLeft = (float) m_daysLeft / m_totalDays;
74 percentDaysOff = (float) m_daysOff / m_totalDays;
76 QString result;
77 QTextStream out(&result);
78 out.setRealNumberPrecision(2);
79 out << "Days served = " << percentDaysServed << "%\n";
80 out << "Days left = " << percentDaysLeft << "%\n";
81 out << "Days off = " << percentDaysOff << "%\n";
83 painter->setPen(QPen(Qt::white));
84 painter->drawText(contentsRect(), Qt::AlignCenter, result);
87 void MyReportDialog::drawPixmap(void)
89 // Create a pixmap
90 m_pixmap = QPixmap(size());
91 m_pixmap.fill(this, 0, 0);
93 // Create a QPainter to draw on the pixmap
94 QPainter painter(&m_pixmap);
96 // Set the painter's pen and backround to be the same as the parent window
97 painter.initFrom(this);
99 // Enable antialiasing mode
100 painter.setRenderHint(QPainter::Antialiasing, true);
102 // Draw pie
103 drawMyPie(&painter);
105 // Draw label
106 drawMyLegend(&painter);
108 // This function won't invoke an immediate repaint,
109 // instead it will schedule a paint event that will be processed,
110 // whenever Qt returns to the main event loop.
111 update();
114 void MyReportDialog::setDaysLeft(unsigned int daysLeft)
116 m_daysLeft = daysLeft;
119 void MyReportDialog::setDaysOff(unsigned int daysOff)
121 m_daysOff = daysOff;
124 void MyReportDialog::setDaysTotal(unsigned int totalDays)
126 m_totalDays = totalDays;