1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
* datedialog.cpp
*
* (c) 2009-2010 by Jeremy Bowman <jmbowman@alum.mit.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/** @file datedialog.cpp
* Source file for DateDialog
*/
#include <QCalendarWidget>
#include <QDialogButtonBox>
#include <QLayout>
#include <QPushButton>
#include <QSettings>
#include <QTextCharFormat>
#include "datedialog.h"
/**
* Constructor.
*
* @param date The date to initially select in the calendar
* @param parent This dialog's parent widget
*/
DateDialog::DateDialog(const QDate &date, QWidget *parent)
#if defined(Q_WS_HILDON)
: PBDialog(tr("Select a date"), parent, true), noneSelected(false)
#else
: PBDialog(tr("Select a date"), parent), noneSelected(false)
#endif
{
if (!date.isValid()) {
reject();
}
calendar = new QCalendarWidget(this);
#if defined(Q_WS_MAEMO_5)
calendar->setStyleSheet("alternate-background-color: darkblue");
#endif
// date limits are for backwards compatibility
calendar->setMinimumDate(QDate(1752, 9, 15));
calendar->setMaximumDate(QDate(7000, 12, 31));
calendar->setGridVisible(true);
calendar->setSelectedDate(date);
QDate today = QDate::currentDate();
QTextCharFormat format = calendar->dateTextFormat(today);
format.setBackground(Qt::cyan);
calendar->setDateTextFormat(QDate::currentDate(), format);
QSettings settings;
if (settings.value("DateTime/MONDAY", false).toBool()) {
calendar->setFirstDayOfWeek(Qt::Monday);
}
connect(calendar, SIGNAL(activated(QDate)), this, SLOT(accept()));
connect(calendar, SIGNAL(clicked(QDate)), this, SLOT(accept()));
vbox->addWidget(calendar);
QDialogButtonBox *buttonBox = finishLayout();
QPushButton *todayButton = new QPushButton(tr("Today"));
buttonBox->addButton(todayButton, QDialogButtonBox::ActionRole);
connect(todayButton, SIGNAL(clicked()), this, SLOT(gotoToday()));
QPushButton *noneButton = new QPushButton(tr("None"));
buttonBox->addButton(noneButton, QDialogButtonBox::ActionRole);
connect(noneButton, SIGNAL(clicked()), this, SLOT(selectNone()));
}
/**
* Get the currently selected date.
*
* @return The selected date
*/
QDate DateDialog::selectedDate()
{
if (noneSelected) {
return QDate(1752, 9, 14);
}
else {
return calendar->selectedDate();
}
}
/**
* Select today's date on the calendar. Called when the "Today" button is
* clicked.
*/
void DateDialog::gotoToday()
{
calendar->setSelectedDate(QDate::currentDate());
accept();
}
/**
* Select the "None" date and close the dialog. Called when the "None" button
* is clicked.
*/
void DateDialog::selectNone()
{
noneSelected = true;
accept();
}
|