2018-07-07 13:39:53 +03:00
|
|
|
#include "Config.h"
|
2018-09-30 13:24:36 +03:00
|
|
|
#include "InfoMessage.h"
|
2018-07-07 13:39:53 +03:00
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPen>
|
|
|
|
|
|
|
|
constexpr int VPadding = 6;
|
|
|
|
constexpr int HPadding = 12;
|
|
|
|
constexpr int HMargin = 20;
|
|
|
|
|
|
|
|
InfoMessage::InfoMessage(QWidget *parent)
|
|
|
|
: QWidget{parent}
|
|
|
|
{
|
2018-09-30 13:24:36 +03:00
|
|
|
initFont();
|
2018-07-07 13:39:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
InfoMessage::InfoMessage(QString msg, QWidget *parent)
|
|
|
|
: QWidget{parent}
|
|
|
|
, msg_{msg}
|
|
|
|
{
|
2018-09-30 13:24:36 +03:00
|
|
|
initFont();
|
2018-07-07 13:39:53 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFontMetrics fm{font()};
|
2018-07-07 13:39:53 +03:00
|
|
|
width_ = fm.width(msg_) + HPadding * 2;
|
|
|
|
height_ = fm.ascent() + 2 * VPadding;
|
|
|
|
|
|
|
|
setFixedHeight(height_ + 2 * HMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InfoMessage::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QPainter p(this);
|
|
|
|
p.setRenderHint(QPainter::Antialiasing);
|
2018-09-30 13:24:36 +03:00
|
|
|
p.setFont(font());
|
2018-07-07 13:39:53 +03:00
|
|
|
|
|
|
|
// Center the box horizontally & vertically.
|
|
|
|
auto textRegion = QRectF(width() / 2 - width_ / 2, HMargin, width_, height_);
|
|
|
|
|
|
|
|
QPainterPath ppath;
|
|
|
|
ppath.addRoundedRect(textRegion, height_ / 2, height_ / 2);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.fillPath(ppath, boxColor());
|
|
|
|
p.drawPath(ppath);
|
|
|
|
|
|
|
|
p.setPen(QPen(textColor()));
|
|
|
|
p.drawText(textRegion, Qt::AlignCenter, msg_);
|
|
|
|
}
|
|
|
|
|
|
|
|
DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent)
|
|
|
|
: InfoMessage{parent}
|
|
|
|
{
|
2018-09-30 13:24:36 +03:00
|
|
|
auto now = QDateTime::currentDateTime();
|
2018-07-07 13:39:53 +03:00
|
|
|
|
|
|
|
QString fmt;
|
|
|
|
|
|
|
|
if (now.date().year() != datetime.date().year())
|
|
|
|
fmt = QString("ddd d MMMM yy");
|
|
|
|
else
|
|
|
|
fmt = QString("ddd d MMMM");
|
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
msg_ = datetime.toString(fmt);
|
2018-07-07 13:39:53 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFontMetrics fm{font()};
|
2018-07-07 13:39:53 +03:00
|
|
|
width_ = fm.width(msg_) + HPadding * 2;
|
|
|
|
height_ = fm.ascent() + 2 * VPadding;
|
|
|
|
|
|
|
|
setFixedHeight(height_ + 2 * HMargin);
|
|
|
|
}
|