summaryrefslogtreecommitdiffstats
path: root/qt-ui/simplewidgets.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-06-19 13:42:49 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-20 15:41:38 -0700
commita08d4ec790328248e2f9408ff074f530b502419a (patch)
tree58ac98f42845b1ec2b8318fc9d4aeaf168fed993 /qt-ui/simplewidgets.cpp
parent867d9f13910b04c2023a98db75152f16837c9e35 (diff)
downloadsubsurface-a08d4ec790328248e2f9408ff074f530b502419a.tar.gz
Added a Partly Functional Date Picker widget.
This widget shows a date in a better way that it was done in the old widget, much more elegantly. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/simplewidgets.cpp')
-rw-r--r--qt-ui/simplewidgets.cpp46
1 files changed, 46 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);
+
+}