diff options
-rw-r--r-- | qt-ui/simplewidgets.cpp | 46 | ||||
-rw-r--r-- | qt-ui/simplewidgets.h | 15 | ||||
-rw-r--r-- | subsurface.qrc | 1 |
3 files changed, 62 insertions, 0 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index bb6d2ff2d..04b6d1f07 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -298,3 +298,49 @@ bool isGnome3Session() return !p_stdout.isEmpty(); #endif } + +DateWidget::DateWidget(QWidget *parent) : QWidget(parent) +{ + setDate(QDate::currentDate()); +} + +void DateWidget::setDate(const QDate& date) +{ + mDate = date; + update(); +} + +QDate DateWidget::date() const +{ + return mDate; +} + +void DateWidget::paintEvent(QPaintEvent *event) +{ + static QPixmap pix = QPixmap(":/calendar").scaled(64,64); + static int pixRedTag = 18; /* calculated using a ruler. */ + + QPainter painter(this); + painter.drawPixmap(QPoint(0,0), pix); + + QString month = mDate.toString("MMM"); + QString year = mDate.toString("yyyy"); + QString day = mDate.toString("dd"); + + + QFont font = QFont("monospace", 5); + QFontMetrics metrics = QFontMetrics(font); + painter.setFont(font); + painter.setPen(QPen(QBrush(Qt::white), 0)); + painter.setBrush(QBrush(Qt::white)); + painter.drawText(QPoint(4, metrics.height() + 3), month); + painter.drawText(QPoint(64 - metrics.width(year) -6, 14), year); + + font.setPointSize(14); + metrics = QFontMetrics(font); + painter.setPen(QPen(QBrush(Qt::black),0)); + painter.setBrush(Qt::black); + painter.setFont(font); + painter.drawText(QPoint(32 - metrics.width(day)/2, 45), day); + +} diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h index c7d18bb35..eea3fca30 100644 --- a/qt-ui/simplewidgets.h +++ b/qt-ui/simplewidgets.h @@ -88,6 +88,21 @@ private: time_t dcImageEpoch; }; +class DateWidget : public QWidget { + Q_OBJECT +public: + DateWidget(QWidget *parent = 0); + void setDate(const QDate& date); + QDate date() const; + +protected: + void paintEvent(QPaintEvent *event); + +private: + QDate mDate; + +}; + bool isGnome3Session(); #endif // SIMPLEWIDGETS_H diff --git a/subsurface.qrc b/subsurface.qrc index d074ea324..47a8ce414 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -53,5 +53,6 @@ <file alias="icon_ceiling_dc">icons/pc.png</file> <file alias="icon_ead">icons/ead.png</file> <file alias="icon_HR">icons/icon-HR.png</file> + <file alias="calendar">icons/calendarbg.png</file> </qresource> </RCC> |