Commit e79ced31 authored by Volker Krause's avatar Volker Krause

Port navigation away from KCalendarSystem.

parent dc6dae11
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "koglobals.h" #include "koglobals.h"
#include "korganizer_debug.h" #include "korganizer_debug.h"
#include <KCalendarSystem>
#include <QDate> #include <QDate>
#include <KLocalizedString> #include <KLocalizedString>
...@@ -114,7 +113,7 @@ void DateNavigator::selectWeek() ...@@ -114,7 +113,7 @@ void DateNavigator::selectWeek()
void DateNavigator::selectWeek(const QDate &d, const QDate &preferredMonth) void DateNavigator::selectWeek(const QDate &d, const QDate &preferredMonth)
{ {
const int dayOfWeek = KOGlobals::self()->calendarSystem()->dayOfWeek(d); const int dayOfWeek = d.dayOfWeek();
const int weekStart = QLocale().firstDayOfWeek(); const int weekStart = QLocale().firstDayOfWeek();
QDate firstDate = d.addDays(weekStart - dayOfWeek); QDate firstDate = d.addDays(weekStart - dayOfWeek);
...@@ -134,7 +133,7 @@ void DateNavigator::selectWorkWeek() ...@@ -134,7 +133,7 @@ void DateNavigator::selectWorkWeek()
void DateNavigator::selectWorkWeek(const QDate &d) void DateNavigator::selectWorkWeek(const QDate &d)
{ {
const int weekStart = QLocale().firstDayOfWeek(); const int weekStart = QLocale().firstDayOfWeek();
const int dayOfWeek = KOGlobals::self()->calendarSystem()->dayOfWeek(d); const int dayOfWeek = d.dayOfWeek();
QDate currentDate = d.addDays(weekStart - dayOfWeek); QDate currentDate = d.addDays(weekStart - dayOfWeek);
if (weekStart != 1 && dayOfWeek < weekStart) { if (weekStart != 1 && dayOfWeek < weekStart) {
...@@ -172,7 +171,7 @@ void DateNavigator::selectPreviousYear() ...@@ -172,7 +171,7 @@ void DateNavigator::selectPreviousYear()
{ {
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
int weekDay = firstSelected.dayOfWeek(); int weekDay = firstSelected.dayOfWeek();
firstSelected = KOGlobals::self()->calendarSystem()->addYears(firstSelected, -1); firstSelected = firstSelected.addYears(-1);
selectWeekByDay(weekDay, firstSelected); selectWeekByDay(weekDay, firstSelected);
} }
...@@ -191,7 +190,7 @@ void DateNavigator::selectPreviousWeek() ...@@ -191,7 +190,7 @@ void DateNavigator::selectPreviousWeek()
{ {
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
const int weekDay = firstSelected.dayOfWeek(); const int weekDay = firstSelected.dayOfWeek();
firstSelected = KOGlobals::self()->calendarSystem()->addDays(firstSelected, -7); firstSelected = firstSelected.addDays(-7);
selectWeekByDay(weekDay, firstSelected); selectWeekByDay(weekDay, firstSelected);
} }
...@@ -201,7 +200,7 @@ void DateNavigator::selectNextWeek() ...@@ -201,7 +200,7 @@ void DateNavigator::selectNextWeek()
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
const int weekDay = firstSelected.dayOfWeek(); const int weekDay = firstSelected.dayOfWeek();
firstSelected = KOGlobals::self()->calendarSystem()->addDays(firstSelected, 7); firstSelected = firstSelected.addDays(7);
selectWeekByDay(weekDay, firstSelected); selectWeekByDay(weekDay, firstSelected);
} }
...@@ -211,18 +210,15 @@ void DateNavigator::shiftMonth(const QDate &currentMonth, ...@@ -211,18 +210,15 @@ void DateNavigator::shiftMonth(const QDate &currentMonth,
const QDate &selectionUpperLimit, const QDate &selectionUpperLimit,
int offset) int offset)
{ {
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
const int weekDay = firstSelected.dayOfWeek(); const int weekDay = firstSelected.dayOfWeek();
firstSelected = calSys->addMonths(firstSelected, offset); firstSelected = firstSelected.addMonths(offset);
/* Don't trust firstSelected to calculate the nextMonth. firstSelected /* Don't trust firstSelected to calculate the nextMonth. firstSelected
can belong to a month other than currentMonth because KDateNavigator can belong to a month other than currentMonth because KDateNavigator
displays 7*6 days. firstSelected should only be used for selection displays 7*6 days. firstSelected should only be used for selection
purposes */ purposes */
const QDate nextMonth = currentMonth.isValid() ? const QDate nextMonth = currentMonth.isValid() ? currentMonth.addMonths(offset) : firstSelected;
calSys->addMonths(currentMonth, offset) : firstSelected;
/* When firstSelected doesn't belong to currentMonth it can happen /* When firstSelected doesn't belong to currentMonth it can happen
that the new selection won't be visible on our KDateNavigators that the new selection won't be visible on our KDateNavigators
...@@ -252,7 +248,7 @@ void DateNavigator::selectNextYear() ...@@ -252,7 +248,7 @@ void DateNavigator::selectNextYear()
{ {
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
int weekDay = firstSelected.dayOfWeek(); int weekDay = firstSelected.dayOfWeek();
firstSelected = KOGlobals::self()->calendarSystem()->addYears(firstSelected, 1); firstSelected = firstSelected.addYears(1);
selectWeekByDay(weekDay, firstSelected); selectWeekByDay(weekDay, firstSelected);
} }
...@@ -279,22 +275,20 @@ void DateNavigator::selectNext() ...@@ -279,22 +275,20 @@ void DateNavigator::selectNext()
void DateNavigator::selectMonth(int month) void DateNavigator::selectMonth(int month)
{ {
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
// always display starting at the first week of the specified month // always display starting at the first week of the specified month
QDate firstSelected = QDate(mSelectedDates.first().year(), month, 1); QDate firstSelected = QDate(mSelectedDates.first().year(), month, 1);
int day = calSys->day(firstSelected); int day = firstSelected.day();
calSys->setDate(firstSelected, calSys->year(firstSelected), month, 1); firstSelected.setDate(firstSelected.year(), month, 1);
int days = calSys->daysInMonth(firstSelected); int days = firstSelected.daysInMonth();
// As day we use either the selected date, or if the month has less days // As day we use either the selected date, or if the month has less days
// than that, we use the max day of that month // than that, we use the max day of that month
if (day > days) { if (day > days) {
day = days; day = days;
} }
QDate requestedMonth; QDate requestedMonth;
calSys->setDate(firstSelected, calSys->year(firstSelected), month, day); firstSelected.setDate(firstSelected.year(), month, day);
calSys->setDate(requestedMonth, calSys->year(firstSelected), month, 1); requestedMonth.setDate(firstSelected.year(), month, 1);
selectWeekByDay(1, firstSelected, requestedMonth); selectWeekByDay(1, firstSelected, requestedMonth);
} }
...@@ -302,8 +296,8 @@ void DateNavigator::selectMonth(int month) ...@@ -302,8 +296,8 @@ void DateNavigator::selectMonth(int month)
void DateNavigator::selectYear(int year) void DateNavigator::selectYear(int year)
{ {
QDate firstSelected = mSelectedDates.first(); QDate firstSelected = mSelectedDates.first();
const int deltaYear = year - KOGlobals::self()->calendarSystem()->year(firstSelected); const int deltaYear = year - firstSelected.year();
firstSelected = KOGlobals::self()->calendarSystem()->addYears(firstSelected, deltaYear); firstSelected = firstSelected.addYears(deltaYear);
const int weekDay = firstSelected.dayOfWeek(); const int weekDay = firstSelected.dayOfWeek();
selectWeekByDay(weekDay, firstSelected); selectWeekByDay(weekDay, firstSelected);
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "koglobals.h" #include "koglobals.h"
#include "widgets/navigatorbar.h" #include "widgets/navigatorbar.h"
#include <KCalendarSystem> #include <KLocalizedString>
#include <QTimer> #include <QTimer>
...@@ -175,13 +175,9 @@ void DateNavigatorContainer::selectDates(const KCalCore::DateList &dateList, ...@@ -175,13 +175,9 @@ void DateNavigatorContainer::selectDates(const KCalCore::DateList &dateList,
navsecond = navfirst; navsecond = navfirst;
} }
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
// If the datelist crosses months we won't know which month to show // If the datelist crosses months we won't know which month to show
// so we read what's in preferredMonth // so we read what's in preferredMonth
const bool changingMonth = const bool changingMonth = preferredMonth.isValid() && mNavigatorView->month().month() != preferredMonth.month();
(preferredMonth.isValid() &&
calSys->month(mNavigatorView->month()) != calSys->month(preferredMonth));
if (start < navfirst || // <- start should always be visible if (start < navfirst || // <- start should always be visible
// end is not visible and we have a spare month at the beginning: // end is not visible and we have a spare month at the beginning:
...@@ -214,7 +210,7 @@ void DateNavigatorContainer::setBaseDates(const QDate &start) ...@@ -214,7 +210,7 @@ void DateNavigatorContainer::setBaseDates(const QDate &start)
} }
foreach (KDateNavigator *n, mExtraViews) { foreach (KDateNavigator *n, mExtraViews) {
baseDate = KOGlobals::self()->calendarSystem()->addMonths(baseDate, 1); baseDate = baseDate.addMonths(1);
if (!mIgnoreNavigatorUpdates) { if (!mIgnoreNavigatorUpdates) {
n->setBaseDate(baseDate); n->setBaseDate(baseDate);
} }
...@@ -351,7 +347,6 @@ void DateNavigatorContainer::goPrevMonth() ...@@ -351,7 +347,6 @@ void DateNavigatorContainer::goPrevMonth()
QPair<QDate, QDate> DateNavigatorContainer::dateLimits(int offset) const QPair<QDate, QDate> DateNavigatorContainer::dateLimits(int offset) const
{ {
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
QDate firstMonth, lastMonth; QDate firstMonth, lastMonth;
if (mExtraViews.isEmpty()) { if (mExtraViews.isEmpty()) {
lastMonth = mNavigatorView->month(); lastMonth = mNavigatorView->month();
...@@ -359,8 +354,8 @@ QPair<QDate, QDate> DateNavigatorContainer::dateLimits(int offset) const ...@@ -359,8 +354,8 @@ QPair<QDate, QDate> DateNavigatorContainer::dateLimits(int offset) const
lastMonth = mExtraViews.last()->month(); lastMonth = mExtraViews.last()->month();
} }
firstMonth = calSys->addMonths(mNavigatorView->month(), offset); firstMonth = mNavigatorView->month().addMonths(offset);
lastMonth = calSys->addMonths(lastMonth, offset); lastMonth = lastMonth.addMonths(offset);
QPair<QDate, QDate> firstMonthBoundary = KODayMatrix::matrixLimits(firstMonth); QPair<QDate, QDate> firstMonthBoundary = KODayMatrix::matrixLimits(firstMonth);
QPair<QDate, QDate> lastMonthBoundary = KODayMatrix::matrixLimits(lastMonth); QPair<QDate, QDate> lastMonthBoundary = KODayMatrix::matrixLimits(lastMonth);
......
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
#include "navigatorbar.h" #include "navigatorbar.h"
#include "koglobals.h" #include "koglobals.h"
#include <KCalendarSystem>
#include <KIconLoader> #include <KIconLoader>
#include <KLocalizedString>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLocale>
#include <QMenu> #include <QMenu>
#include <QToolButton> #include <QToolButton>
...@@ -126,23 +127,16 @@ void NavigatorBar::selectDates(const KCalCore::DateList &dateList) ...@@ -126,23 +127,16 @@ void NavigatorBar::selectDates(const KCalCore::DateList &dateList)
if (dateList.count() > 0) { if (dateList.count() > 0) {
mDate = dateList.first(); mDate = dateList.first();
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
// set the label text at the top of the navigator // set the label text at the top of the navigator
mMonth->setText(i18nc("monthname", "%1", calSys->monthName(mDate))); mMonth->setText(i18nc("monthname", "%1", QLocale().monthName(mDate.month(), QLocale::LongFormat)));
mYear->setText(i18nc("4 digit year", "%1", mYear->setText(i18nc("4 digit year", "%1", QLocale().toString(mDate, QLatin1String("yyyy"))));
calSys->formatDate(mDate, KLocale::Year, KLocale::LongNumber)));
} }
} }
void NavigatorBar::selectMonthFromMenu() void NavigatorBar::selectMonthFromMenu()
{ {
// every year can have different month names (in some calendar systems) int month = mDate.month();
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); const int months = 12;
int month = calSys->month(mDate);
int year = calSys->year(mDate);
int months = calSys->monthsInYear(mDate);
QMenu *menu = new QMenu(mMonth); QMenu *menu = new QMenu(mMonth);
QList<QAction *> act; QList<QAction *> act;
...@@ -150,7 +144,7 @@ void NavigatorBar::selectMonthFromMenu() ...@@ -150,7 +144,7 @@ void NavigatorBar::selectMonthFromMenu()
QAction *activateAction = Q_NULLPTR; QAction *activateAction = Q_NULLPTR;
act.reserve(months); act.reserve(months);
for (int i = 1; i <= months; ++i) { for (int i = 1; i <= months; ++i) {
QAction *monthAction = menu->addAction(calSys->monthName(i, year)); QAction *monthAction = menu->addAction(QLocale().monthName(i, QLocale::LongFormat));
act.append(monthAction); act.append(monthAction);
if (i == month) { if (i == month) {
activateAction = monthAction; activateAction = monthAction;
...@@ -179,9 +173,7 @@ void NavigatorBar::selectMonthFromMenu() ...@@ -179,9 +173,7 @@ void NavigatorBar::selectMonthFromMenu()
void NavigatorBar::selectYearFromMenu() void NavigatorBar::selectYearFromMenu()
{ {
const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); int year = mDate.year();
int year = calSys->year(mDate);
int years = 11; // odd number (show a few years ago -> a few years from now) int years = 11; // odd number (show a few years ago -> a few years from now)
int minYear = year - (years / 3); int minYear = year - (years / 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment