mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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:
parent
1fc22c6653
commit
70c8bbcc91
2 changed files with 25 additions and 5 deletions
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue