2 #include "myreportdialog.h"
9 MyReportDialog::MyReportDialog(QWidget
*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";
35 void MyReportDialog::drawMyPie(QPainter
*painter
)
37 std::cout
<< "MyReportDialog::drawMyPie()\n";
40 painter
->setBrush(QBrush(Qt::red
, Qt::SolidPattern
));
41 painter
->drawPie(0, 0,
43 this->size().height(),
45 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360);
48 painter
->setBrush(QBrush(Qt::blue
, Qt::SolidPattern
));
49 painter
->drawPie(0, 0,
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,
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
;
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
;
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)
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);
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.
114 void MyReportDialog::setDaysLeft(unsigned int daysLeft
)
116 m_daysLeft
= daysLeft
;
119 void MyReportDialog::setDaysOff(unsigned int daysOff
)
124 void MyReportDialog::setDaysTotal(unsigned int totalDays
)
126 m_totalDays
= totalDays
;