Added the calendar widget to change the calendar date.

Added a popup widget to change the calendar date, just like
the old QDateTimeEdit.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-19 15:42:05 -03:00 committed by Dirk Hohndel
parent 1fc22c6653
commit 70c8bbcc91
2 changed files with 25 additions and 5 deletions

View file

@ -15,6 +15,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QDateTime> #include <QDateTime>
#include <QShortcut> #include <QShortcut>
#include <QCalendarWidget>
#include "exif.h" #include "exif.h"
#include "dive.h" #include "dive.h"
#include "file.h" #include "file.h"
@ -299,16 +300,24 @@ bool isGnome3Session()
#endif #endif
} }
DateWidget::DateWidget(QWidget *parent) : QWidget(parent) DateWidget::DateWidget(QWidget *parent) : QWidget(parent),
calendarWidget(new QCalendarWidget())
{ {
setDate(QDate::currentDate()); setDate(QDate::currentDate());
setMinimumSize(QSize(64,64)); setMinimumSize(QSize(64,64));
calendarWidget->setWindowFlags(Qt::FramelessWindowHint);
connect(calendarWidget, SIGNAL(activated(QDate)), calendarWidget, SLOT(hide()));
connect(calendarWidget, SIGNAL(clicked(QDate)), calendarWidget, SLOT(hide()));
connect(calendarWidget, SIGNAL(activated(QDate)), this, SLOT(setDate(QDate)));
connect(calendarWidget, SIGNAL(clicked(QDate)), this, SLOT(setDate(QDate)));
} }
void DateWidget::setDate(const QDate& date) void DateWidget::setDate(const QDate& date)
{ {
mDate = date; mDate = date;
update(); update();
emit dateChanged(mDate);
} }
QDate DateWidget::date() const QDate DateWidget::date() const
@ -343,5 +352,11 @@ void DateWidget::paintEvent(QPaintEvent *event)
painter.setBrush(Qt::black); painter.setBrush(Qt::black);
painter.setFont(font); painter.setFont(font);
painter.drawText(QPoint(32 - metrics.width(day)/2, 45), day); painter.drawText(QPoint(32 - metrics.width(day)/2, 45), day);
} }
void DateWidget::mousePressEvent(QMouseEvent *event)
{
calendarWidget->move(event->globalPos());
calendarWidget->show();
}

View file

@ -88,18 +88,23 @@ private:
time_t dcImageEpoch; time_t dcImageEpoch;
}; };
class QCalendarWidget;
class DateWidget : public QWidget { class DateWidget : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
DateWidget(QWidget *parent = 0); DateWidget(QWidget *parent = 0);
void setDate(const QDate& date);
QDate date() const; QDate date() const;
public slots:
void setDate(const QDate& date);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
signals:
void dateChanged(const QDate& date);
private: private:
QDate mDate; QDate mDate;
QCalendarWidget *calendarWidget;
}; };
bool isGnome3Session(); bool isGnome3Session();