2 #include "mytabreportdialog.h"
10 MyTabReportDialog::MyTabReportDialog(QWidget
*parent
)
13 std::cout
<< "MyTabReportDialog::MyTabReportDialog()\n";
17 connect(this->unitComboBox
, SIGNAL(currentIndexChanged(int )),
18 this, SLOT(updateLineEdits()));
24 MyTabReportDialog::~MyTabReportDialog()
26 std::cout
<< "MyTabReportDialog::~MyTabReportDialog()\n";
29 void MyTabReportDialog::paintEvent(QPaintEvent
*event
)
31 std::cout
<< "MyTabReportDialog::paintEvent()\n";
33 if (pixmapChanged
== true) {
34 labelGraphics
->setScaledContents(true);
35 labelGraphics
->setPixmap(m_piePixmap
);
37 labelRank
->setScaledContents(true);
38 labelRank
->setPixmap(m_rankPixmap
);
40 pixmapChanged
= false;
44 void MyTabReportDialog::resizeEvent(QResizeEvent
*event
)
46 std::cout
<< "MyTabReportDialog::resizeEvent()\n";
51 void MyTabReportDialog::drawMyPie(QPainter
*painter
)
53 std::cout
<< "MyTabReportDialog::drawMyPie()\n";
56 painter
->setBrush(QBrush(Qt::red
, Qt::SolidPattern
));
57 painter
->drawPie(0, 0,
58 labelGraphics
->size().width(),
59 labelGraphics
->size().height(),
61 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360);
64 painter
->setBrush(QBrush(Qt::blue
, Qt::SolidPattern
));
65 painter
->drawPie(0, 0,
66 labelGraphics
->size().width(),
67 labelGraphics
->size().height(),
68 ((float) m_daysLeft
/ m_totalDays
) * 16 * 360,
69 ((float) m_daysOff
/ m_totalDays
) * 16 * 360);
71 // Days that have been served
72 painter
->setBrush(QBrush(Qt::green
, Qt::SolidPattern
));
73 painter
->drawPie(0, 0,
74 labelGraphics
->size().width(),
75 labelGraphics
->size().height(),
76 ((float) (m_daysLeft
+ m_daysOff
) / m_totalDays
) * 16 * 360,
77 ((float) (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
) * 16 * 360);
80 void MyTabReportDialog::drawMyLegend(QPainter
*painter
)
83 float percentDaysServed
;
84 float percentDaysLeft
;
87 std::cout
<< "MyTabReportDialog::drawMyLabel\n";
89 // Calculate percentages
90 percentDaysServed
= 100.0 * (m_totalDays
- m_daysLeft
- m_daysOff
) / m_totalDays
;
91 percentDaysLeft
= 100.0 * m_daysLeft
/ m_totalDays
;
92 percentDaysOff
= 100.0 * m_daysOff
/ m_totalDays
;
94 // Print percentages into a string using a text stream
95 QTextStream
out(&resultStr
);
96 out
.setRealNumberPrecision(3);
98 out
<< QString::fromUtf8("Υπηρετήθηκε = ") << percentDaysServed
<< "%\n";
99 out
<< QString::fromUtf8("Και σήμερα = ") << percentDaysLeft
<< "%\n";
100 out
<< QString::fromUtf8("Άδεια = ") << percentDaysOff
<< "%\n";
103 painter
->setPen(QPen(Qt::white
));
104 painter
->drawText(QRect(0, 0,
105 labelGraphics
->size().width(),
106 labelGraphics
->size().height()),
107 Qt::AlignCenter
, resultStr
);
110 void MyTabReportDialog::drawMyRank(QPainter
*painter
)
112 std::cout
<< "MyTabReportDialog::drawMyRank()\n";
115 m_image
= QImage(m_rank
.getImageFileName());
116 if (m_image
.isNull()) {
117 std::cout
<< "MyTabReportDialog::drawMyRank(): "
118 << "the loading of the image failed\n";
123 painter
->drawImage(QPoint((labelRank
->size().width() - m_image
.width()) / 2,
124 (labelRank
->size().height() - m_image
.height()) / 2),
128 void MyTabReportDialog::drawPixmaps(void)
130 // Create the pixmaps
131 m_piePixmap
= QPixmap(labelGraphics
->size());
132 m_rankPixmap
= QPixmap(labelRank
->size());
134 m_piePixmap
.fill(this, 0, 0);
135 m_rankPixmap
.fill(this, 0, 0);
137 // Create a QPainter to draw on the pixmap
138 QPainter
piePainter(&m_piePixmap
);
139 QPainter
rankPainter(&m_rankPixmap
);
141 // Set the painter's pen and backround to be the same as the parent window
142 piePainter
.initFrom(this);
143 rankPainter
.initFrom(this);
145 // Enable antialiasing mode
146 piePainter
.setRenderHint(QPainter::Antialiasing
, true);
147 rankPainter
.setRenderHint(QPainter::Antialiasing
, true);
150 drawMyPie(&piePainter
);
153 drawMyLegend(&piePainter
);
156 drawMyRank(&rankPainter
);
158 // This function won't invoke an immediate repaint,
159 // instead it will schedule a paint event that will be processed,
160 // whenever Qt returns to the main event loop.
164 void MyTabReportDialog::updateLineEdits(void)
168 std::cout
<< "MyTabReportDialog::updateLineEdits()\n";
170 // Get current selection regarding time unit
171 currentIndex
= unitComboBox
->currentIndex();
172 if (currentIndex
== -1) {
173 // XXX: No current item is set or the combobox is empty
177 std::cout
<< "Current index = " << currentIndex
<< std::endl
;
179 servedLineEdit
->setText(QString::number(getTime(m_totalDays
- m_daysLeft
- m_daysOff
, currentIndex
)));
180 leftLineEdit
->setText(QString::number(getTime(m_daysLeft
, currentIndex
)));
181 daysoffLineEdit
->setText(QString::number(getTime(m_daysOff
, currentIndex
)));
184 void MyTabReportDialog::setDaysLeft(unsigned int daysLeft
)
186 std::cout
<< "MyTabReportDialog::setDaysLeft()\n";
188 m_daysLeft
= daysLeft
;
191 void MyTabReportDialog::setDaysOff(unsigned int daysOff
)
193 std::cout
<< "MyTabReportDialog::setDaysOff()\n";
198 void MyTabReportDialog::setDaysTotal(unsigned int totalDays
)
200 std::cout
<< "MyTabReportDialog::setDaysTotal()\n";
202 m_totalDays
= totalDays
;
205 void MyTabReportDialog::setRank(MyRank rank
)
207 std::cout
<< "MyTabReportDialog::setRank()\n";
212 unsigned int getTime(unsigned int nDays
, int toWhat
)
216 std::cout
<< "getTime():\tnDays = " << nDays
<< "\ttoWhat = " << toWhat
;
231 ret
= nDays
* 24 * 60;
234 ret
= nDays
* 24 * 60 * 60;
240 std::cout
<< "\tret = " << ret
<< std::endl
;