summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-08-30 14:02:39 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-03 02:40:54 +0200
commitec57b20b65a3c5fa6fa0b225f4b52cfebf053194 (patch)
treefadab8431b26bd234bef5109c0a332db11dd2ea9
parent8c1cb66712a339b09988d8ef2b15ce39678178a6 (diff)
Properly reflect format changes in calendarwidget example.
This patch ensures that May 1st and the first Friday of each month also have their formats updated when the corresponding checkboxes are unchecked instead of just checked. Task-number: QTBUG-26936 Change-Id: Ib5f77daf8d9000eeb18663b2e07e4842a70d22b6 Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
-rw-r--r--examples/widgets/doc/calendarwidget.qdoc10
-rw-r--r--examples/widgets/widgets/calendarwidget/window.cpp34
2 files changed, 30 insertions, 14 deletions
diff --git a/examples/widgets/doc/calendarwidget.qdoc b/examples/widgets/doc/calendarwidget.qdoc
index ad15bbaa0c..c6e86d1668 100644
--- a/examples/widgets/doc/calendarwidget.qdoc
+++ b/examples/widgets/doc/calendarwidget.qdoc
@@ -280,12 +280,12 @@
In \c reformatCalendarPage(), we set the text format of the first
Friday in the month and May 1 in the current year. The text
formats that are actually used depend on which check boxes are
- checked.
+ checked and what the weekday/weekend formats are.
QCalendarWidget lets us set the text format of individual dates
with the \l{QCalendarWidget::}{setDateTextFormat()}. We chose to
- set the dates when the calendar page changes, i.e., a new month is
- displayed. We check which of the \c mayFirstCheckBox and \c
- firstDayCheckBox, if any, are checked
- and set the text formats accordingly.
+ set the date formats when the calendar page changes - i.e. a new month is
+ displayed - and when the weekday/weekend format is changed.
+ We check which of the \c mayFirstCheckBox and \c firstDayCheckBox, if any,
+ are checked and set the text formats accordingly.
*/
diff --git a/examples/widgets/widgets/calendarwidget/window.cpp b/examples/widgets/widgets/calendarwidget/window.cpp
index 8ba044bf11..b0afb1e61d 100644
--- a/examples/widgets/widgets/calendarwidget/window.cpp
+++ b/examples/widgets/widgets/calendarwidget/window.cpp
@@ -169,22 +169,34 @@ void Window::reformatHeaders()
//! [8]
void Window::reformatCalendarPage()
{
+ QTextCharFormat mayFirstFormat;
+ const QDate mayFirst(calendar->yearShown(), 5, 1);
+
+ QTextCharFormat firstFridayFormat;
+ QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1);
+ while (firstFriday.dayOfWeek() != Qt::Friday)
+ firstFriday = firstFriday.addDays(1);
+
if (firstFridayCheckBox->isChecked()) {
- QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1);
- while (firstFriday.dayOfWeek() != Qt::Friday)
- firstFriday = firstFriday.addDays(1);
- QTextCharFormat firstFridayFormat;
firstFridayFormat.setForeground(Qt::blue);
- calendar->setDateTextFormat(firstFriday, firstFridayFormat);
+ } else { // Revert to regular colour for this day of the week.
+ Qt::DayOfWeek dayOfWeek(static_cast<Qt::DayOfWeek>(firstFriday.dayOfWeek()));
+ firstFridayFormat.setForeground(calendar->weekdayTextFormat(dayOfWeek).foreground());
}
- //May First in Red takes precedence
+ calendar->setDateTextFormat(firstFriday, firstFridayFormat);
+
+ // When it is checked, "May First in Red" always takes precedence over "First Friday in Blue".
if (mayFirstCheckBox->isChecked()) {
- const QDate mayFirst(calendar->yearShown(), 5, 1);
- QTextCharFormat mayFirstFormat;
mayFirstFormat.setForeground(Qt::red);
- calendar->setDateTextFormat(mayFirst, mayFirstFormat);
+ } else if (!firstFridayCheckBox->isChecked() || firstFriday != mayFirst) {
+ // We can now be certain we won't be resetting "May First in Red" when we restore
+ // may 1st's regular colour for this day of the week.
+ Qt::DayOfWeek dayOfWeek(static_cast<Qt::DayOfWeek>(mayFirst.dayOfWeek()));
+ calendar->setDateTextFormat(mayFirst, calendar->weekdayTextFormat(dayOfWeek));
}
+
+ calendar->setDateTextFormat(mayFirst, mayFirstFormat);
}
//! [8]
@@ -418,8 +430,12 @@ void Window::createTextFormatsGroupBox()
//! [17] //! [18]
connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(weekdayFormatChanged()));
+ connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(reformatCalendarPage()));
connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(weekendFormatChanged()));
+ connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(reformatCalendarPage()));
connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)),
this, SLOT(reformatHeaders()));
connect(firstFridayCheckBox, SIGNAL(toggled(bool)),