Track tab report dialog files
[agianapa.git] / qt / leleja / mytabreportdialog.cpp
blob07493534fcb5dbd575589f21a17d1008b238b391
1 #include <iostream>
2 #include "mytabreportdialog.h"
3 #include "myrank.h"
5 #include <QPainter>
6 #include <QPixmap>
7 #include <QString>
8 #include <QTextStream>
10 MyTabReportDialog::MyTabReportDialog(QWidget *parent)
11 : QDialog(parent)
13 std::cout << "MyTabReportDialog::MyTabReportDialog()\n";
15 setupUi(this);
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";
40 drawPixmaps();
43 void MyTabReportDialog::drawMyPie(QPainter *painter)
45 std::cout << "MyTabReportDialog::drawMyPie()\n";
47 // Days remaining
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);
55 // Days off
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)
74 QString resultStr;
75 float percentDaysServed;
76 float percentDaysLeft;
77 float percentDaysOff;
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";
94 // Draw string
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)
102 unsigned int i;
104 std::cout << "MyTabReportDialog::drawMyRank()\n";
106 // Load rank image
107 m_image = QImage(m_rank.getImageFileName());
108 if (m_image.isNull()) {
109 std::cout << "MyTabReportDialog::drawMyRank(): the loading of the image failed\n";
110 // return;
113 // Draw rank image
114 painter->drawImage(QPoint((labelRank->size().width() - m_image.width()) / 2,
115 (labelRank->size().height() - m_image.height()) / 2),
116 m_image);
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);
140 // Draw pie
141 drawMyPie(&piePainter);
143 // Draw label
144 drawMyLegend(&piePainter);
146 // Draw rank image
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.
152 update();
155 void MyTabReportDialog::setDaysLeft(unsigned int daysLeft)
157 m_daysLeft = daysLeft;
160 void MyTabReportDialog::setDaysOff(unsigned int daysOff)
162 m_daysOff = daysOff;
165 void MyTabReportDialog::setDaysTotal(unsigned int totalDays)
167 m_totalDays = totalDays;
170 void MyTabReportDialog::setRank(MyRank rank)
172 m_rank = rank;