2 #include "mytabreportdialog.h"
10 MyTabReportDialog::MyTabReportDialog(QWidget
*parent
)
13 std::cout
<< "MyTabReportDialog::MyTabReportDialog()\n";
17 connect(this->unitComboBox
, SIGNAL(currentIndexChanged(int )), this, SLOT(updateLineEdits()));
23 MyTabReportDialog::~MyTabReportDialog()
25 std::cout
<< "MyTabReportDialog::~MyTabReportDialog()\n";
28 void MyTabReportDialog::paintEvent(QPaintEvent
*event
)
30 std::cout
<< "MyTabReportDialog::paintEvent()\n";
32 if (pixmapChanged
== true) {
33 labelGraphics
->setScaledContents(true);
34 labelGraphics
->setPixmap(m_piePixmap
);
36 labelRank
->setScaledContents(true);
37 labelRank
->setPixmap(m_rankPixmap
);
39 pixmapChanged
= false;
43 void MyTabReportDialog::resizeEvent(QResizeEvent
*event
)
45 std::cout
<< "MyTabReportDialog::resizeEvent()\n";
50 void MyTabReportDialog::drawMyPie(QPainter
*painter
)
52 std::cout
<< "MyTabReportDialog::drawMyPie()\n";
55 painter
->setBrush(QBrush(Qt::red
, Qt::SolidPattern
));
56 painter
->drawPie(0, 0,
57 labelGraphics
->size().width(),
58 labelGraphics
->size().height(),
60 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360);
63 painter
->setBrush(QBrush(Qt::blue
, Qt::SolidPattern
));
64 painter
->drawPie(0, 0,
65 labelGraphics
->size().width(),
66 labelGraphics
->size().height(),
67 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360,
68 ((float) m_daysOff
/ m_totalDays
) * 16 * 360);
70 // Days that have been served
71 painter
->setBrush(QBrush(Qt::green
, Qt::SolidPattern
));
72 painter
->drawPie(0, 0,
73 labelGraphics
->size().width(),
74 labelGraphics
->size().height(),
75 ((float) (m_daysLeft
+ m_daysOff
) / m_totalDays
) * 16 * 360,
76 ((float) (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
) * 16 * 360);
79 void MyTabReportDialog::drawMyLegend(QPainter
*painter
)
82 float percentDaysServed
;
83 float percentDaysLeft
;
86 std::cout
<< "MyTabReportDialog::drawMyLabel\n";
88 // Calculate percentages
89 percentDaysServed
= 100.0 * (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
;
90 percentDaysLeft
= 100.0 * m_daysLeft
/ m_totalDays
;
91 percentDaysOff
= 100.0 * m_daysOff
/ m_totalDays
;
93 // Print percentages into a string using a text stream
94 QTextStream
out(&resultStr
);
95 out
.setRealNumberPrecision(3);
97 out
<< QString::fromUtf8("Υπηρετήθηκε = ") << percentDaysServed
<< "%\n";
98 out
<< QString::fromUtf8("Και σήμερα = ") << percentDaysLeft
<< "%\n";
99 out
<< QString::fromUtf8("Άδεια = ") << percentDaysOff
<< "%\n";
102 painter
->setPen(QPen(Qt::white
));
103 painter
->drawText(QRect(0, 0,
104 labelGraphics
->size().width(),
105 labelGraphics
->size().height()),
106 Qt::AlignCenter
, resultStr
);
109 void MyTabReportDialog::drawMyRank(QPainter
*painter
)
111 std::cout
<< "MyTabReportDialog::drawMyRank()\n";
114 m_image
= QImage(m_rank
.getImageFileName());
115 if (m_image
.isNull()) {
116 std::cout
<< "MyTabReportDialog::drawMyRank(): the loading of the image failed\n";
121 painter
->drawImage(QPoint((labelRank
->size().width() - m_image
.width()) / 2,
122 (labelRank
->size().height() - m_image
.height()) / 2),
126 void MyTabReportDialog::drawPixmaps(void)
128 // Create the pixmaps
129 m_piePixmap
= QPixmap(labelGraphics
->size());
130 m_rankPixmap
= QPixmap(labelRank
->size());
132 m_piePixmap
.fill(this, 0, 0);
133 m_rankPixmap
.fill(this, 0, 0);
135 // Create a QPainter to draw on the pixmap
136 QPainter
piePainter(&m_piePixmap
);
137 QPainter
rankPainter(&m_rankPixmap
);
139 // Set the painter's pen and backround to be the same as the parent window
140 piePainter
.initFrom(this);
141 rankPainter
.initFrom(this);
143 // Enable antialiasing mode
144 piePainter
.setRenderHint(QPainter::Antialiasing
, true);
145 rankPainter
.setRenderHint(QPainter::Antialiasing
, true);
148 drawMyPie(&piePainter
);
151 drawMyLegend(&piePainter
);
154 drawMyRank(&rankPainter
);
156 // This function won't invoke an immediate repaint,
157 // instead it will schedule a paint event that will be processed,
158 // whenever Qt returns to the main event loop.
162 void MyTabReportDialog::updateLineEdits(void)
166 std::cout
<< "MyTabReportDialog::updateLineEdits()\n";
168 // Get current selection regarding time unit
169 currentIndex
= unitComboBox
->currentIndex();
170 if (currentIndex
== -1) {
171 // XXX: No current item is set or the combobox is empty
172 std::cout
<< "HAHA\n" << std::endl
;
176 std::cout
<< "Current index = " << currentIndex
<< std::endl
;
178 servedLineEdit
->setText(QString::number(getTime(m_totalDays
- m_daysLeft
- m_daysOff
, currentIndex
)));
179 leftLineEdit
->setText(QString::number(getTime(m_daysLeft
, currentIndex
)));
180 daysoffLineEdit
->setText(QString::number(getTime(m_daysOff
, currentIndex
)));
183 void MyTabReportDialog::setDaysLeft(unsigned int daysLeft
)
185 std::cout
<< "MyTabReportDialog::setDaysLeft()\n";
187 m_daysLeft
= daysLeft
;
190 void MyTabReportDialog::setDaysOff(unsigned int daysOff
)
192 std::cout
<< "MyTabReportDialog::setDaysOff()\n";
197 void MyTabReportDialog::setDaysTotal(unsigned int totalDays
)
199 std::cout
<< "MyTabReportDialog::setDaysTotal()\n";
201 m_totalDays
= totalDays
;
204 void MyTabReportDialog::setRank(MyRank rank
)
206 std::cout
<< "MyTabReportDialog::setRank()\n";
211 unsigned int getTime(unsigned int nDays
, int toWhat
)
215 std::cout
<< "getTime(): nDays = " << nDays
<< " toWhat = " << toWhat
<< "\n";
231 ret
= nDays
* 24 * 60;
234 ret
= nDays
* 24 * 60 * 60;
240 std::cout
<< "ret = " << ret
<< std::endl
;