2 #include "mytabreportdialog.h"
10 MyTabReportDialog::MyTabReportDialog(QWidget
*parent
)
13 std::cout
<< "MyTabReportDialog::MyTabReportDialog()\n";
18 MyTabReportDialog::~MyTabReportDialog()
20 std::cout
<< "MyTabReportDialog::~MyTabReportDialog()\n";
23 void MyTabReportDialog::paintEvent(QPaintEvent
*event
)
25 std::cout
<< "MyTabReportDialog::paintEvent()\n";
27 // QPainter painter(labelGraphics->pixmap());
28 // painter.drawPixmap(0, 0, m_pixmap);
29 labelGraphics
->setScaledContents(true);
30 labelGraphics
->setPixmap(m_piePixmap
);
32 labelRank
->setScaledContents(true);
33 labelRank
->setPixmap(m_rankPixmap
);
36 void MyTabReportDialog::resizeEvent(QResizeEvent
*event
)
38 std::cout
<< "MyTabReportDialog::resizeEvent()\n";
43 void MyTabReportDialog::drawMyPie(QPainter
*painter
)
45 std::cout
<< "MyTabReportDialog::drawMyPie()\n";
48 painter
->setBrush(QBrush(Qt::red
, Qt::SolidPattern
));
49 painter
->drawPie(0, 0,
50 labelGraphics
->size().width(),
51 labelGraphics
->size().height(),
53 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360);
56 painter
->setBrush(QBrush(Qt::blue
, Qt::SolidPattern
));
57 painter
->drawPie(0, 0,
58 labelGraphics
->size().width(),
59 labelGraphics
->size().height(),
60 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360,
61 ((float) m_daysOff
/ m_totalDays
) * 16 * 360);
63 // Days that have been served
64 painter
->setBrush(QBrush(Qt::green
, Qt::SolidPattern
));
65 painter
->drawPie(0, 0,
66 labelGraphics
->size().width(),
67 labelGraphics
->size().height(),
68 ((float) (m_daysLeft
+ m_daysOff
) / m_totalDays
) * 16 * 360,
69 ((float) (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
) * 16 * 360);
72 void MyTabReportDialog::drawMyLegend(QPainter
*painter
)
75 float percentDaysServed
;
76 float percentDaysLeft
;
79 std::cout
<< "MyTabReportDialog::drawMyLabel\n";
81 // Calculate percentages
82 percentDaysServed
= 100.0 * (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
;
83 percentDaysLeft
= 100.0 * m_daysLeft
/ m_totalDays
;
84 percentDaysOff
= 100.0 * m_daysOff
/ m_totalDays
;
86 // Print percentages into a string using a text stream
87 QTextStream
out(&resultStr
);
88 out
.setRealNumberPrecision(3);
90 out
<< QString::fromUtf8("Υπηρετήθηκε = ") << percentDaysServed
<< "%\n";
91 out
<< QString::fromUtf8("Και σήμερα = ") << percentDaysLeft
<< "%\n";
92 out
<< QString::fromUtf8("Άδεια = ") << percentDaysOff
<< "%\n";
95 painter
->setPen(QPen(Qt::white
));
96 painter
->drawText(QRect(0, 0, size().width(), size().height() / 2),
97 Qt::AlignCenter
, resultStr
);
100 void MyTabReportDialog::drawMyRank(QPainter
*painter
)
104 std::cout
<< "MyTabReportDialog::drawMyRank()\n";
107 m_image
= QImage(m_rank
.getImageFileName());
108 if (m_image
.isNull()) {
109 std::cout
<< "MyTabReportDialog::drawMyRank(): the loading of the image failed\n";
114 painter
->drawImage(QPoint((labelRank
->size().width() - m_image
.width()) / 2,
115 (labelRank
->size().height() - m_image
.height()) / 2),
119 void MyTabReportDialog::drawPixmaps(void)
121 // Create the pixmaps
122 m_piePixmap
= QPixmap(labelGraphics
->size());
123 m_rankPixmap
= QPixmap(labelRank
->size());
125 m_piePixmap
.fill(this, 0, 0);
126 m_rankPixmap
.fill(this, 0, 0);
128 // Create a QPainter to draw on the pixmap
129 QPainter
piePainter(&m_piePixmap
);
130 QPainter
rankPainter(&m_rankPixmap
);
132 // Set the painter's pen and backround to be the same as the parent window
133 piePainter
.initFrom(this);
134 rankPainter
.initFrom(this);
136 // Enable antialiasing mode
137 piePainter
.setRenderHint(QPainter::Antialiasing
, true);
138 rankPainter
.setRenderHint(QPainter::Antialiasing
, true);
141 drawMyPie(&piePainter
);
144 drawMyLegend(&piePainter
);
147 drawMyRank(&rankPainter
);
149 // This function won't invoke an immediate repaint,
150 // instead it will schedule a paint event that will be processed,
151 // whenever Qt returns to the main event loop.
155 void MyTabReportDialog::setDaysLeft(unsigned int daysLeft
)
157 m_daysLeft
= daysLeft
;
160 void MyTabReportDialog::setDaysOff(unsigned int daysOff
)
165 void MyTabReportDialog::setDaysTotal(unsigned int totalDays
)
167 m_totalDays
= totalDays
;
170 void MyTabReportDialog::setRank(MyRank rank
)