Commit e79ced31 authored by Volker Krause's avatar Volker Krause

Port navigation away from KCalendarSystem.

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