diff --git a/calendarviews/prefs.cpp b/calendarviews/prefs.cpp index ba25d9c174..9f46e60d1e 100644 --- a/calendarviews/prefs.cpp +++ b/calendarviews/prefs.cpp @@ -1,1115 +1,1119 @@ /* Copyright (c) 2001,2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Author: Kevin Krammer, krake@kdab.com 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "prefs.h" #include "prefs_base.h" #include #include using namespace EventViews; QSet iconArrayToSet( const QByteArray &array ) { QSet set; for ( int i=0; i= EventViews::EventView::IconCount ) { kWarning() << "Icon array is too big: " << array.count(); return set; } if ( array[i] != 0 ) { set.insert( static_cast( i ) ); } } return set; } QByteArray iconSetToArray( const QSet &set ) { QByteArray array; for ( int i=0; i( i ) ); array.append( contains ? 1 : 0 ) ; } return array; } QByteArray agendaViewIconDefaults() { QByteArray iconDefaults; iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1; iconDefaults[EventViews::EventView::TaskIcon] = 1; iconDefaults[EventViews::EventView::JournalIcon] = 1; iconDefaults[EventViews::EventView::RecurringIcon] = 1; iconDefaults[EventViews::EventView::ReminderIcon] = 1; iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1; iconDefaults[EventViews::EventView::ReplyIcon] = 0; return iconDefaults; } QByteArray monthViewIconDefaults() { QByteArray iconDefaults; iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1; iconDefaults[EventViews::EventView::TaskIcon] = 1; iconDefaults[EventViews::EventView::JournalIcon] = 1; iconDefaults[EventViews::EventView::RecurringIcon] = 0; iconDefaults[EventViews::EventView::ReminderIcon] = 0; iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1; iconDefaults[EventViews::EventView::ReplyIcon] = 0; return iconDefaults; } class BaseConfig : public PrefsBase { public: BaseConfig(); void setResourceColor( const QString &resource, const QColor &color ); void setTimeScaleTimezones( const QStringList &timeZones ); QStringList timeScaleTimezones() const; public: QHash mResourceColors; QColor mDefaultResourceColor; QFont mDefaultMonthViewFont; QFont mDefaultAgendaTimeLabelsFont; KDateTime::Spec mTimeSpec; QStringList mTimeScaleTimeZones; QSet mAgendaViewIcons; QSet mMonthViewIcons; protected: void usrSetDefaults(); void usrReadConfig(); void usrWriteConfig(); void setTimeZoneDefault(); }; BaseConfig::BaseConfig() : PrefsBase() { mDefaultResourceColor = QColor(); //Default is a color invalid mDefaultAgendaTimeLabelsFont = KGlobalSettings::generalFont(); // make a large default time bar font, at least 16 points. mDefaultAgendaTimeLabelsFont.setPointSize( qMax( mDefaultAgendaTimeLabelsFont.pointSize() + 4, 16 ) ); mDefaultMonthViewFont = KGlobalSettings::generalFont(); // make it a bit smaller mDefaultMonthViewFont.setPointSize( qMax( mDefaultMonthViewFont.pointSize() - 2, 6 ) ); agendaTimeLabelsFontItem()->setDefaultValue( mDefaultAgendaTimeLabelsFont ); agendaTimeLabelsFontItem()->setDefault(); monthViewFontItem()->setDefaultValue( mDefaultMonthViewFont ); monthViewFontItem()->setDefault(); } void BaseConfig::setResourceColor( const QString &resource, const QColor &color ) { mResourceColors.insert( resource, color ); } void BaseConfig::setTimeScaleTimezones( const QStringList &list ) { mTimeScaleTimeZones = list; } QStringList BaseConfig::timeScaleTimezones() const { return mTimeScaleTimeZones; } void BaseConfig::usrSetDefaults() { setAgendaTimeLabelsFont( mDefaultAgendaTimeLabelsFont ); setMonthViewFont( mDefaultMonthViewFont ); setTimeZoneDefault(); PrefsBase::usrSetDefaults(); } void BaseConfig::usrReadConfig() { KConfigGroup generalConfig( config(), "General" ); // Note that the [Category Colors] group was removed after 3.2 due to // an algorithm change. That's why we now use [Category Colors2] // Resource colors KConfigGroup rColorsConfig( config(), "Resources Colors" ); const QStringList colorKeyList = rColorsConfig.keyList(); QStringList::ConstIterator it3; for ( it3 = colorKeyList.begin(); it3 != colorKeyList.end(); ++it3 ) { QColor color = rColorsConfig.readEntry( *it3, mDefaultResourceColor ); //kDebug() << "key:" << (*it3) << "value:" << color; setResourceColor( *it3, color ); } if ( !mTimeSpec.isValid() ) { setTimeZoneDefault(); } #if 0 config()->setGroup( "FreeBusy" ); if ( mRememberRetrievePw ) { mRetrievePassword = KStringHandler::obscure( config()->readEntry( "Retrieve Server Password" ) ); } #endif KConfigGroup defaultCalendarConfig( config(), "Calendar" ); KConfigGroup timeScaleConfig( config(), "Timescale" ); setTimeScaleTimezones( timeScaleConfig.readEntry( "Timescale Timezones", QStringList() ) ); KConfigGroup monthViewConfig( config(), "Month View" ); KConfigGroup agendaViewConfig( config(), "Agenda View" ); const QByteArray agendaIconArray = agendaViewConfig.readEntry( "agendaViewItemIcons", agendaViewIconDefaults() ); const QByteArray monthIconArray = monthViewConfig.readEntry( "monthViewItemIcons", monthViewIconDefaults() ); mAgendaViewIcons = iconArrayToSet( agendaIconArray ); mMonthViewIcons = iconArrayToSet( monthIconArray ); KConfigSkeleton::usrReadConfig(); } void BaseConfig::usrWriteConfig() { KConfigGroup generalConfig( config(), "General" ); KConfigGroup rColorsConfig( config(), "Resources Colors" ); QHash::const_iterator i = mResourceColors.constBegin(); while ( i != mResourceColors.constEnd() ) { rColorsConfig.writeEntry( i.key(), i.value() ); ++i; } #if 0 if ( mRememberRetrievePw ) { config()->writeEntry( "Retrieve Server Password", KStringHandler::obscure( mRetrievePassword ) ); } else { config()->deleteEntry( "Retrieve Server Password" ); } #endif KConfigGroup timeScaleConfig( config(), "Timescale" ); timeScaleConfig.writeEntry( "Timescale Timezones", timeScaleTimezones() ); KConfigGroup monthViewConfig( config(), "Month View" ); KConfigGroup agendaViewConfig( config(), "Agenda View" ); const QByteArray agendaIconArray = iconSetToArray( mAgendaViewIcons ); const QByteArray monthIconArray = iconSetToArray( mMonthViewIcons ); agendaViewConfig.writeEntry( "agendaViewItemIcons", agendaIconArray ); monthViewConfig.writeEntry( "monthViewItemIcons", monthIconArray ); KConfigSkeleton::usrWriteConfig(); } void BaseConfig::setTimeZoneDefault() { KTimeZone zone = KSystemTimeZones::local(); if ( !zone.isValid() ) { kError() << "KSystemTimeZones::local() return 0"; return; } kDebug () << "----- time zone:" << zone.name(); mTimeSpec = zone; } class Prefs::Private { public: Private( Prefs *parent ) : mAppConfig( 0 ), q( parent ) {} Private( Prefs *parent, KCoreConfigSkeleton *appConfig ) : mAppConfig( appConfig ), q( parent ) {} void setTimeZoneDefault(); KConfigSkeletonItem *appConfigItem( const KConfigSkeletonItem *baseConfigItem ) const; void setBool( KCoreConfigSkeleton::ItemBool *baseConfigItem, bool value ); bool getBool( const KCoreConfigSkeleton::ItemBool *baseConfigItem ) const; void setInt( KCoreConfigSkeleton::ItemInt *baseConfigItem, int value ); int getInt( const KCoreConfigSkeleton::ItemInt *baseConfigItem ) const; void setString( KCoreConfigSkeleton::ItemString *baseConfigItem, const QString &value ); QString getString( const KCoreConfigSkeleton::ItemString *baseConfigItem ) const; void setDateTime( KCoreConfigSkeleton::ItemDateTime *baseConfigItem, const QDateTime &value ); QDateTime getDateTime( const KCoreConfigSkeleton::ItemDateTime *baseConfigItem ) const; void setStringList( KCoreConfigSkeleton::ItemStringList *baseConfigItem, const QStringList &value ); QStringList getStringList( const KCoreConfigSkeleton::ItemStringList *baseConfigItem ) const; void setColor( KConfigSkeleton::ItemColor *baseConfigItem, const QColor &value ); QColor getColor( const KConfigSkeleton::ItemColor *baseConfigItem ) const; void setFont( KConfigSkeleton::ItemFont *baseConfigItem, const QFont &value ); QFont getFont( const KConfigSkeleton::ItemFont *baseConfigItem ) const; public: BaseConfig mBaseConfig; KCoreConfigSkeleton *mAppConfig; private: Prefs *q; }; KConfigSkeletonItem *Prefs::Private::appConfigItem( const KConfigSkeletonItem *baseConfigItem ) const { Q_ASSERT( baseConfigItem ); if ( mAppConfig ) { return mAppConfig->findItem( baseConfigItem->name() ); } return 0; } void Prefs::Private::setBool( KCoreConfigSkeleton::ItemBool *baseConfigItem, bool value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemBool *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type Bool"; } } else { baseConfigItem->setValue( value ); } } bool Prefs::Private::getBool( const KCoreConfigSkeleton::ItemBool *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemBool *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type Bool"; } return baseConfigItem->value(); } void Prefs::Private::setInt( KCoreConfigSkeleton::ItemInt *baseConfigItem, int value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemInt *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type Int"; } } else { baseConfigItem->setValue( value ); } } int Prefs::Private::getInt( const KCoreConfigSkeleton::ItemInt *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemInt *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type Int"; } return baseConfigItem->value(); } void Prefs::Private::setString( KCoreConfigSkeleton::ItemString *baseConfigItem, const QString &value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemString *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type String"; } } else { baseConfigItem->setValue( value ); } } QString Prefs::Private::getString( const KCoreConfigSkeleton::ItemString *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemString *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type String"; } return baseConfigItem->value(); } void Prefs::Private::setDateTime( KCoreConfigSkeleton::ItemDateTime *baseConfigItem, const QDateTime &value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemDateTime *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type DateTime"; } } else { baseConfigItem->setValue( value ); } } QDateTime Prefs::Private::getDateTime( const KCoreConfigSkeleton::ItemDateTime *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemDateTime *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type DateTime"; } return baseConfigItem->value(); } void Prefs::Private::setStringList( KCoreConfigSkeleton::ItemStringList *baseConfigItem, const QStringList &value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemStringList *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type StringList"; } } else { baseConfigItem->setValue( value ); } } QStringList Prefs::Private::getStringList( const KCoreConfigSkeleton::ItemStringList *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KCoreConfigSkeleton::ItemStringList *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type StringList"; } return baseConfigItem->value(); } void Prefs::Private::setColor( KConfigSkeleton::ItemColor *baseConfigItem, const QColor &value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KConfigSkeleton::ItemColor *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type Color"; } } else { baseConfigItem->setValue( value ); } } QColor Prefs::Private::getColor( const KConfigSkeleton::ItemColor *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KConfigSkeleton::ItemColor *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type Color"; } return baseConfigItem->value(); } void Prefs::Private::setFont( KConfigSkeleton::ItemFont *baseConfigItem, const QFont &value ) { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KConfigSkeleton::ItemFont *item = dynamic_cast( appItem ); if ( item ) { item->setValue( value ); } else { kError() << "Application config item" << appItem->name() << "is not of type Font"; } } else { baseConfigItem->setValue( value ); } } QFont Prefs::Private::getFont( const KConfigSkeleton::ItemFont *baseConfigItem ) const { KConfigSkeletonItem *appItem = appConfigItem( baseConfigItem ); if ( appItem ) { KConfigSkeleton::ItemFont *item = dynamic_cast( appItem ); if ( item ) { return item->value(); } kError() << "Application config item" << appItem->name() << "is not of type Font"; } return baseConfigItem->value(); } Prefs::Prefs() : d( new Private( this ) ) { } Prefs::Prefs( KCoreConfigSkeleton *appConfig ) : d( new Private( this, appConfig ) ) { } Prefs::~Prefs() { delete d; } void Prefs::readConfig() { d->mBaseConfig.readConfig(); if ( d->mAppConfig ) { d->mAppConfig->readConfig(); } } void Prefs::writeConfig() { d->mBaseConfig.writeConfig(); if ( d->mAppConfig ) { d->mAppConfig->writeConfig(); } } void Prefs::setMarcusBainsShowSeconds( bool showSeconds ) { d->setBool( d->mBaseConfig.marcusBainsShowSecondsItem(), showSeconds ); } bool Prefs::marcusBainsShowSeconds() const { return d->getBool( d->mBaseConfig.marcusBainsShowSecondsItem() ); } void Prefs::setAgendaMarcusBainsLineLineColor( const QColor &color ) { d->setColor( d->mBaseConfig.agendaMarcusBainsLineLineColorItem(), color ); } QColor Prefs::agendaMarcusBainsLineLineColor() const { return d->getColor( d->mBaseConfig.agendaMarcusBainsLineLineColorItem() ); } void Prefs::setMarcusBainsEnabled( bool enabled ) { d->setBool( d->mBaseConfig.marcusBainsEnabledItem(), enabled ); } bool Prefs::marcusBainsEnabled() const { return d->getBool( d->mBaseConfig.marcusBainsEnabledItem() ); } void Prefs::setAgendaMarcusBainsLineFont( const QFont &font ) { d->setFont( d->mBaseConfig.agendaMarcusBainsLineFontItem(), font ); } QFont Prefs::agendaMarcusBainsLineFont() const { return d->getFont( d->mBaseConfig.agendaMarcusBainsLineFontItem() ); } void Prefs::setHourSize( int size ) { d->setInt( d->mBaseConfig.hourSizeItem(), size ); } int Prefs::hourSize() const { return d->getInt( d->mBaseConfig.hourSizeItem() ); } void Prefs::setDayBegins( const QDateTime &dateTime ) { d->setDateTime( d->mBaseConfig.dayBeginsItem(), dateTime ); } QDateTime Prefs::dayBegins() const { return d->getDateTime( d->mBaseConfig.dayBeginsItem() ); } void Prefs::setWorkingHoursStart( const QDateTime &dateTime ) { d->setDateTime( d->mBaseConfig.workingHoursStartItem(), dateTime ); } QDateTime Prefs::workingHoursStart() const { return d->getDateTime( d->mBaseConfig.workingHoursStartItem() ); } void Prefs::setWorkingHoursEnd( const QDateTime &dateTime ) { d->setDateTime( d->mBaseConfig.workingHoursEndItem(), dateTime ); } QDateTime Prefs::workingHoursEnd() const { return d->getDateTime( d->mBaseConfig.workingHoursEndItem() ); } void Prefs::setSelectionStartsEditor( bool startEditor ) { d->setBool( d->mBaseConfig.selectionStartsEditorItem(), startEditor ); } bool Prefs::selectionStartsEditor() const { return d->getBool( d->mBaseConfig.selectionStartsEditorItem() ); } void Prefs::setAgendaGridWorkHoursBackgroundColor( const QColor &color ) { d->setColor( d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem(), color ); } QColor Prefs::agendaGridWorkHoursBackgroundColor() const { return d->getColor( d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem() ); } void Prefs::setAgendaGridHighlightColor( const QColor &color ) { d->setColor( d->mBaseConfig.agendaGridHighlightColorItem(), color ); } QColor Prefs::agendaGridHighlightColor() const { return d->getColor( d->mBaseConfig.agendaGridHighlightColorItem() ); } void Prefs::setAgendaGridBackgroundColor( const QColor &color ) { d->setColor( d->mBaseConfig.agendaGridBackgroundColorItem(), color ); } QColor Prefs::agendaGridBackgroundColor() const { return d->getColor( d->mBaseConfig.agendaGridBackgroundColorItem() ); } void Prefs::setEnableAgendaItemIcons( bool enable ) { d->setBool( d->mBaseConfig.enableAgendaItemIconsItem(), enable ); } bool Prefs::enableAgendaItemIcons() const { return d->getBool( d->mBaseConfig.enableAgendaItemIconsItem() ); } void Prefs::setTodosUseCategoryColors( bool useColors ) { d->setBool( d->mBaseConfig.todosUseCategoryColorsItem(), useColors ); } bool Prefs::todosUseCategoryColors() const { return d->getBool( d->mBaseConfig.todosUseCategoryColorsItem() ); } void Prefs::setAgendaHolidaysBackgroundColor( const QColor &color ) const { d->setColor( d->mBaseConfig.agendaHolidaysBackgroundColorItem(), color ); } QColor Prefs::agendaHolidaysBackgroundColor() const { return d->getColor( d->mBaseConfig.agendaHolidaysBackgroundColorItem() ); } void Prefs::setAgendaViewColors( int colors ) { d->setInt( d->mBaseConfig.agendaViewColorsItem(), colors ); } int Prefs::agendaViewColors() const { return d->getInt( d->mBaseConfig.agendaViewColorsItem() ); } void Prefs::setAgendaViewFont( const QFont &font ) { d->setFont( d->mBaseConfig.agendaViewFontItem(), font ); } QFont Prefs::agendaViewFont() const { return d->getFont( d->mBaseConfig.agendaViewFontItem() ); } void Prefs::setMonthViewFont( const QFont &font ) { d->setFont( d->mBaseConfig.monthViewFontItem(), font ); } QFont Prefs::monthViewFont() const { return d->getFont( d->mBaseConfig.monthViewFontItem() ); } QColor Prefs::monthGridBackgroundColor() const { return d->getColor( d->mBaseConfig.monthGridBackgroundColorItem() ); } void Prefs::setMonthGridBackgroundColor( const QColor &color ) { d->setColor( d->mBaseConfig.monthGridBackgroundColorItem(), color ); } QColor Prefs::monthGridWorkHoursBackgroundColor() const { return d->getColor( d->mBaseConfig.monthGridWorkHoursBackgroundColorItem() ); } void Prefs::monthGridWorkHoursBackgroundColor( const QColor &color ) { d->setColor( d->mBaseConfig.monthGridWorkHoursBackgroundColorItem(), color ); } int Prefs::monthViewColors() const { return d->getInt( d->mBaseConfig.monthViewColorsItem() ); } void Prefs::setMonthViewColors( int colors ) const { d->setInt( d->mBaseConfig.monthViewColorsItem(), colors ); } void Prefs::setEnableMonthItemIcons( bool enable ) { d->setBool( d->mBaseConfig.enableMonthItemIconsItem(), enable ); } bool Prefs::enableMonthItemIcons() const { return d->getBool( d->mBaseConfig.enableMonthItemIconsItem() ); } bool Prefs::showTimeInMonthView() const { return d->getBool( d->mBaseConfig.showTimeInMonthViewItem() ); } void Prefs::setShowTimeInMonthView( bool show ) { d->setBool( d->mBaseConfig.showTimeInMonthViewItem(), show ); } bool Prefs::showTodosMonthView() const { return d->getBool( d->mBaseConfig.showTodosMonthViewItem() ); } void Prefs::setShowTodosMonthView( bool enable ) { d->setBool( d->mBaseConfig.showTodosMonthViewItem(), enable ); } bool Prefs::showJournalsMonthView() const { return d->getBool( d->mBaseConfig.showJournalsMonthViewItem() ); } void Prefs::setShowJournalsMonthView( bool enable ) { d->setBool( d->mBaseConfig.showJournalsMonthViewItem(), enable ); } bool Prefs::fullViewMonth() const { return d->getBool( d->mBaseConfig.fullViewMonthItem() ); } void Prefs::setFullViewMonth( bool fullView ) { d->setBool( d->mBaseConfig.fullViewMonthItem(), fullView ); } bool Prefs::sortCompletedTodosSeparately() const { return d->getBool( d->mBaseConfig.sortCompletedTodosSeparatelyItem() ); } void Prefs::setSortCompletedTodosSeparately( bool enable ) { d->setBool( d->mBaseConfig.sortCompletedTodosSeparatelyItem(), enable ); } void Prefs::setEnableToolTips( bool enable ) { d->setBool( d->mBaseConfig.enableToolTipsItem(), enable ); } bool Prefs::enableToolTips() const { return d->getBool( d->mBaseConfig.enableToolTipsItem() ); } void Prefs::setShowTodosAgendaView( bool show ) { d->setBool( d->mBaseConfig.showTodosAgendaViewItem(), show ); } bool Prefs::showTodosAgendaView() const { return d->getBool( d->mBaseConfig.showTodosAgendaViewItem() ); } void Prefs::setAgendaTimeLabelsFont( const QFont &font ) { d->setFont( d->mBaseConfig.agendaTimeLabelsFontItem(), font ); } QFont Prefs::agendaTimeLabelsFont() const { return d->getFont( d->mBaseConfig.agendaTimeLabelsFontItem() ); } KDateTime::Spec Prefs::timeSpec() const { return KSystemTimeZones::local(); } void Prefs::setTimeSpec( const KDateTime::Spec &spec ) { d->mBaseConfig.mTimeSpec = spec; } bool Prefs::colorAgendaBusyDays() const { return d->getBool( d->mBaseConfig.colorBusyDaysEnabledItem() ); } bool Prefs::colorMonthBusyDays() const { return d->getBool( d->mBaseConfig.colorMonthBusyDaysEnabledItem() ); } QColor Prefs::viewBgBusyColor() const { return d->getColor( d->mBaseConfig.viewBgBusyColorItem() ); } void Prefs::setViewBgBusyColor( const QColor &color ) { d->mBaseConfig.mViewBgBusyColor = color; } QColor Prefs::holidayColor() const { return d->getColor( d->mBaseConfig.holidayColorItem() ); } void Prefs::setHolidayColor( const QColor &color ) { d->mBaseConfig.mHolidayColor = color; } QColor Prefs::agendaViewBackgroundColor() const { return d->getColor( d->mBaseConfig.agendaBgColorItem() ); } void Prefs::setAgendaViewBackgroundColor( const QColor &color ) { d->mBaseConfig.mAgendaBgColor = color; } QColor Prefs::workingHoursColor() const { return d->getColor( d->mBaseConfig.workingHoursColorItem() ); } void Prefs::setWorkingHoursColor( const QColor &color ) { d->mBaseConfig.mWorkingHoursColor = color; } QColor Prefs::todoDueTodayColor() const { return d->getColor( d->mBaseConfig.todoDueTodayColorItem() ); } void Prefs::setTodoDueTodayColor( const QColor &color ) { d->mBaseConfig.mTodoDueTodayColor = color; } QColor Prefs::todoOverdueColor() const { return d->getColor( d->mBaseConfig.todoOverdueColorItem() ); } void Prefs::setTodoOverdueColor( const QColor &color ) { d->mBaseConfig.mTodoOverdueColor = color; } void Prefs::setColorAgendaBusyDays( bool enable ) { d->mBaseConfig.mColorBusyDaysEnabled = enable; } void Prefs::setColorMonthBusyDays( bool enable ) { d->mBaseConfig.mColorMonthBusyDaysEnabled = enable; } void Prefs::setResourceColor ( const QString &cal, const QColor &color ) { d->mBaseConfig.setResourceColor( cal, color ); } -QColor Prefs::resourceColor( const QString &cal ) +QColor Prefs::resourceColorKnown(const QString &cal) { QColor color; - if ( !cal.isEmpty() ) { - if ( d->mBaseConfig.mResourceColors.contains( cal ) ) { + if ( !cal.isEmpty() && + d->mBaseConfig.mResourceColors.contains( cal ) ) { color = d->mBaseConfig.mResourceColors.value( cal ); - if ( !color.isValid() ) { - return color; - } - } - } else { + } + return color; +} + +QColor Prefs::resourceColor( const QString &cal ) +{ + if ( cal.isEmpty() ) { return d->mBaseConfig.mDefaultResourceColor; } + QColor color = resourceColorKnown(cal); + // assign default color if enabled - if ( !cal.isEmpty() && !color.isValid() && + if ( !color.isValid() && d->getBool( d->mBaseConfig.assignDefaultResourceColorsItem() ) ) { QColor defColor( 0x37, 0x7A, 0xBC ); const int seed = d->getInt( d->mBaseConfig.defaultResourceColorSeedItem() ); const QStringList colors = d->getStringList( d->mBaseConfig.defaultResourceColorsItem() ); if ( seed > 0 && seed - 1 < (int)colors.size() ) { defColor = QColor( colors[seed-1] ); } else { int h, s, v; defColor.getHsv( &h, &s, &v ); h = ( seed % 12 ) * 30; s -= s * static_cast( ( ( seed / 12 ) % 2 ) * 0.5 ); defColor.setHsv( h, s, v ); } d->setInt( d->mBaseConfig.defaultResourceColorSeedItem(), ( seed + 1 ) ); d->mBaseConfig.setResourceColor( cal, defColor ); color = d->mBaseConfig.mResourceColors[cal]; } if ( color.isValid() ) { return color; } else { return d->mBaseConfig.mDefaultResourceColor; } } QStringList Prefs::timeScaleTimezones() const { return d->mBaseConfig.timeScaleTimezones(); } void Prefs::setTimeScaleTimezones( const QStringList &list ) { d->mBaseConfig.setTimeScaleTimezones( list ); } KConfigSkeleton::ItemFont *Prefs::fontItem( const QString &name ) const { KConfigSkeletonItem *item = d->mAppConfig ? d->mAppConfig->findItem( name ) : 0; if ( !item ) { item = d->mBaseConfig.findItem( name ); } return dynamic_cast( item ); } QStringList Prefs::selectedPlugins() const { return d->mBaseConfig.mSelectedPlugins; } QStringList Prefs::decorationsAtAgendaViewTop() const { return d->mBaseConfig.decorationsAtAgendaViewTop(); } QStringList Prefs::decorationsAtAgendaViewBottom() const { return d->mBaseConfig.decorationsAtAgendaViewBottom(); } void Prefs::setSelectedPlugins( const QStringList &plugins ) { d->mBaseConfig.setSelectedPlugins( plugins ); } void Prefs::setDecorationsAtAgendaViewTop( const QStringList &decorations ) { d->mBaseConfig.setDecorationsAtAgendaViewTop( decorations ); } void Prefs::setDecorationsAtAgendaViewBottom( const QStringList &decorations ) { d->mBaseConfig.setDecorationsAtAgendaViewBottom( decorations ); } QSet Prefs::agendaViewIcons() const { return d->mBaseConfig.mAgendaViewIcons; } void Prefs::setAgendaViewIcons( const QSet &icons ) { d->mBaseConfig.mAgendaViewIcons = icons; } QSet Prefs::monthViewIcons() const { return d->mBaseConfig.mMonthViewIcons; } void Prefs::setMonthViewIcons( const QSet &icons ) { d->mBaseConfig.mMonthViewIcons = icons; } void Prefs::setFlatListTodo( bool enable ) { d->mBaseConfig.mFlatListTodo = enable; } bool Prefs::flatListTodo() const { return d->mBaseConfig.mFlatListTodo; } void Prefs::setFullViewTodo( bool enable ) { d->mBaseConfig.mFullViewTodo = enable; } bool Prefs::fullViewTodo() const { return d->mBaseConfig.mFullViewTodo; } bool Prefs::enableTodoQuickSearch() const { return d->mBaseConfig.mEnableTodoQuickSearch; } void Prefs::setEnableTodoQuickSearch( bool enable ) { d->mBaseConfig.mEnableTodoQuickSearch = enable; } bool Prefs::enableQuickTodo() const { return d->mBaseConfig.mEnableQuickTodo; } void Prefs::setEnableQuickTodo( bool enable ) { d->mBaseConfig.mEnableQuickTodo = enable; } bool Prefs::highlightTodos() const { return d->mBaseConfig.mHighlightTodos; } void Prefs::setHighlightTodos( bool highlight ) { d->mBaseConfig.mHighlightTodos = highlight; } KConfig *Prefs::config() const { return d->mAppConfig ? d->mAppConfig->config() : d->mBaseConfig.config(); } diff --git a/calendarviews/prefs.h b/calendarviews/prefs.h index c210bd51b5..1c0aa032d9 100644 --- a/calendarviews/prefs.h +++ b/calendarviews/prefs.h @@ -1,231 +1,232 @@ /* Copyright (c) 2000,2001 Cornelius Schumacher Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net Author: Kevin Krammer, krake@kdab.com 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef EVENTVIEWS_PREFS_H #define EVENTVIEWS_PREFS_H #include "eventviews_export.h" #include "eventview.h" #include #include namespace boost { template class shared_ptr; } namespace EventViews { class EVENTVIEWS_EXPORT Prefs { public: /** Creates an instance of Prefs with just base config */ Prefs(); /** Creates an instance of Prefs with base config and application override config The passed @p appConfig will be queried for matching items whenever one of the accessors is called. If one is found it is used for setting/getting the value otherwise the one from the eventviews base config is used. */ explicit Prefs( KCoreConfigSkeleton *appConfig ); ~Prefs(); void readConfig(); void writeConfig(); public: void setMarcusBainsShowSeconds( bool showSeconds ); bool marcusBainsShowSeconds() const; void setAgendaMarcusBainsLineLineColor( const QColor &color ); QColor agendaMarcusBainsLineLineColor() const; void setMarcusBainsEnabled( bool enabled ); bool marcusBainsEnabled() const; void setAgendaMarcusBainsLineFont( const QFont &font ); QFont agendaMarcusBainsLineFont() const; void setHourSize( int size ); int hourSize() const; void setDayBegins( const QDateTime &dateTime ); QDateTime dayBegins() const; void setWorkingHoursStart( const QDateTime &dateTime ); QDateTime workingHoursStart() const; void setWorkingHoursEnd( const QDateTime &dateTime ); QDateTime workingHoursEnd() const; void setSelectionStartsEditor( bool startEditor ); bool selectionStartsEditor() const; void setAgendaGridWorkHoursBackgroundColor( const QColor &color ); QColor agendaGridWorkHoursBackgroundColor() const; void setAgendaGridHighlightColor( const QColor &color ); QColor agendaGridHighlightColor() const; void setAgendaGridBackgroundColor( const QColor &color ); QColor agendaGridBackgroundColor() const; void setEnableAgendaItemIcons( bool enable ); bool enableAgendaItemIcons() const; void setTodosUseCategoryColors( bool useColors ); bool todosUseCategoryColors() const; void setAgendaHolidaysBackgroundColor( const QColor &color ) const; QColor agendaHolidaysBackgroundColor() const; void setAgendaViewColors( int colors ); int agendaViewColors() const; void setAgendaViewFont( const QFont &font ); QFont agendaViewFont() const; void setMonthViewFont( const QFont &font ); QFont monthViewFont() const; QColor monthGridBackgroundColor() const; void setMonthGridBackgroundColor( const QColor &color ); QColor monthGridWorkHoursBackgroundColor() const; void monthGridWorkHoursBackgroundColor( const QColor &color ); void setMonthViewColors( int colors ) const; int monthViewColors() const; bool enableMonthItemIcons() const; void setEnableMonthItemIcons( bool enable ); bool showTimeInMonthView() const; void setShowTimeInMonthView( bool show ); bool showTodosMonthView() const; void setShowTodosMonthView( bool show ); bool showJournalsMonthView() const; void setShowJournalsMonthView( bool show ); bool fullViewMonth() const; void setFullViewMonth( bool fullView ); bool sortCompletedTodosSeparately() const; void setSortCompletedTodosSeparately( bool sort ); void setEnableToolTips( bool enable ); bool enableToolTips() const; void setShowTodosAgendaView( bool show ); bool showTodosAgendaView() const; void setAgendaTimeLabelsFont( const QFont &font ); QFont agendaTimeLabelsFont() const; KConfigSkeleton::ItemFont *fontItem( const QString &name ) const; void setResourceColor ( const QString &, const QColor & ); QColor resourceColor( const QString & ); + QColor resourceColorKnown( const QString & ); void setTimeSpec( const KDateTime::Spec &spec ); KDateTime::Spec timeSpec() const; QStringList timeScaleTimezones() const; void setTimeScaleTimezones( const QStringList &list ); QStringList selectedPlugins() const; void setSelectedPlugins( const QStringList &); QStringList decorationsAtAgendaViewTop() const; void setDecorationsAtAgendaViewTop( const QStringList & ); QStringList decorationsAtAgendaViewBottom() const; void setDecorationsAtAgendaViewBottom( const QStringList & ); bool colorAgendaBusyDays() const; void setColorAgendaBusyDays( bool enable ); bool colorMonthBusyDays() const; void setColorMonthBusyDays( bool enable ); QColor viewBgBusyColor() const; void setViewBgBusyColor( const QColor & ); QColor holidayColor() const; void setHolidayColor( const QColor &color ); QColor agendaViewBackgroundColor() const; void setAgendaViewBackgroundColor( const QColor &color ); QColor workingHoursColor() const; void setWorkingHoursColor( const QColor &color ); QColor todoDueTodayColor() const; void setTodoDueTodayColor( const QColor &color ); QColor todoOverdueColor() const; void setTodoOverdueColor( const QColor &color ); QSet agendaViewIcons() const; void setAgendaViewIcons( const QSet &icons ); QSet monthViewIcons() const; void setMonthViewIcons( const QSet &icons ); void setFlatListTodo( bool ); bool flatListTodo() const; void setFullViewTodo( bool ); bool fullViewTodo() const; bool enableTodoQuickSearch() const; void setEnableTodoQuickSearch( bool enable ); bool enableQuickTodo() const; void setEnableQuickTodo( bool enable ); bool highlightTodos() const; void setHighlightTodos( bool ); KConfig *config() const; private: class Private; Private *const d; }; typedef boost::shared_ptr PrefsPtr; } #endif // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/korganizer/kohelper.cpp b/korganizer/kohelper.cpp index 2959b42633..c114dfa55e 100644 --- a/korganizer/kohelper.cpp +++ b/korganizer/kohelper.cpp @@ -1,76 +1,95 @@ /* This file is part of KOrganizer. Copyright (C) 2005 Reinhold Kainhofer 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "kohelper.h" #include "koprefs.h" #include #include QColor KOHelper::getTextColor( const QColor &c ) { double luminance = ( c.red() * 0.299 ) + ( c.green() * 0.587 ) + ( c.blue() * 0.114 ); return ( luminance > 128.0 ) ? QColor( 0, 0, 0 ) : QColor( 255, 255, 255 ); } QColor KOHelper::resourceColor( const Akonadi::Collection &coll ) { if ( !coll.isValid() ) { return QColor(); } const QString id = QString::number( coll.id() ); return KOPrefs::instance()->resourceColor( id ); } +QColor KOHelper::resourceColorKnown( const Akonadi::Collection &coll ) +{ + if ( !coll.isValid() ) { + return QColor(); + } + + const QString id = QString::number( coll.id() ); + return KOPrefs::instance()->resourceColorKnown( id ); +} + +void KOHelper::setResourceColor(const Akonadi::Collection &collection, const QColor &color) +{ + if ( collection.isValid() ) { + const QString id = QString::number( collection.id() ); + return KOPrefs::instance()->setResourceColor(id, color); + } +} + + QColor KOHelper::resourceColor( const Akonadi::Item &item ) { if ( !item.isValid() ) { return QColor(); } const QString id = QString::number( item.storageCollectionId() ); return KOPrefs::instance()->resourceColor( id ); } int KOHelper::yearDiff( const QDate &start, const QDate &end ) { return end.year() - start.year(); } bool KOHelper::isStandardCalendar( const Akonadi::Entity::Id &id ) { return id == CalendarSupport::KCalPrefs::instance()->defaultCalendarId(); } void KOHelper::showSaveIncidenceErrorMsg( QWidget *parent, const KCalCore::Incidence::Ptr &incidence ) { KMessageBox::sorry( parent, i18n( "Unable to save %1 \"%2\".", i18n( incidence->typeStr() ), incidence->summary() ) ); } diff --git a/korganizer/kohelper.h b/korganizer/kohelper.h index c83e448ee8..4e8c559a41 100644 --- a/korganizer/kohelper.h +++ b/korganizer/kohelper.h @@ -1,77 +1,79 @@ /* This file is part of KOrganizer. Copyright (C) 2005 Reinhold Kainhofer 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KORG_KOHELPER_H #define KORG_KOHELPER_H #include "korganizer_export.h" #include #include namespace Akonadi { class Collection; class Item; } class QColor; class QDate; // Provides static methods that are useful to all views. namespace KOHelper { /** Returns a nice QColor for text, give the input color &c. */ KORGANIZERPRIVATE_EXPORT QColor getTextColor( const QColor &c ); /** This method returns the proper resource / subresource color for the view. @return The resource color for the incidence. If the incidence belongs to a subresource, the color for the subresource is returned (if set). @param calendar the calendar for which the resource color should be obtained @param incidence the incidence for which the color is needed (to determine which subresource needs to be used) */ KORGANIZERPRIVATE_EXPORT QColor resourceColor( const Akonadi::Item &incidence ); KORGANIZERPRIVATE_EXPORT QColor resourceColor( const Akonadi::Collection &collection ); + KORGANIZERPRIVATE_EXPORT QColor resourceColorKnown( const Akonadi::Collection &collection ); + KORGANIZERPRIVATE_EXPORT void setResourceColor( const Akonadi::Collection &collection, const QColor &color ); /** Returns the number of years between the @p start QDate and the @p end QDate (i.e. the difference in the year number of both dates) */ KORGANIZERPRIVATE_EXPORT int yearDiff( const QDate &start, const QDate &end ); /** Return true if it's the standard calendar */ KORGANIZERPRIVATE_EXPORT bool isStandardCalendar( const Akonadi::Entity::Id &id ); KORGANIZERPRIVATE_EXPORT void showSaveIncidenceErrorMsg( QWidget *parent, const KCalCore::Incidence::Ptr &incidence ); } #endif diff --git a/korganizer/koprefs.cpp b/korganizer/koprefs.cpp index 93ac61ce37..60b41a2161 100644 --- a/korganizer/koprefs.cpp +++ b/korganizer/koprefs.cpp @@ -1,138 +1,143 @@ /* This file is part of KOrganizer. Copyright (c) 2001,2003 Cornelius Schumacher Copyright (C) 2003-2004 Reinhold Kainhofer 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "koprefs.h" #include #include class KOPrefsPrivate { public: KOPrefsPrivate() : prefs( new KOPrefs ) {} ~KOPrefsPrivate() { delete prefs; } KOPrefs *prefs; }; K_GLOBAL_STATIC( KOPrefsPrivate, sInstance ) KOPrefs::KOPrefs() : KOPrefsBase() { KGlobal::locale()->insertCatalog( QLatin1String("calendarsupport") ); mEventViewsPrefs = EventViews::PrefsPtr( new EventViews::Prefs( this ) ); mDefaultMonthViewFont = KGlobalSettings::generalFont(); // make it a bit smaller mDefaultMonthViewFont.setPointSize( qMax( mDefaultMonthViewFont.pointSize() - 2, 6 ) ); KConfigSkeleton::setCurrentGroup( QLatin1String("General") ); // writes into mHtmlExportFile addItemPath( QLatin1String("Html Export File"), mHtmlExportFile, QDir::homePath() + QLatin1Char('/') + i18nc( "Default export file", "calendar.html" ) ); monthViewFontItem()->setDefaultValue( mDefaultMonthViewFont ); } KOPrefs::~KOPrefs() { kDebug(); mEventViewsPrefs->writeConfig(); } KOPrefs *KOPrefs::instance() { if ( !sInstance.exists() ) { sInstance->prefs->readConfig(); sInstance->prefs->mEventViewsPrefs->readConfig(); } return sInstance->prefs; } void KOPrefs::usrSetDefaults() { setMonthViewFont( mDefaultMonthViewFont ); KConfigSkeleton::usrSetDefaults(); } void KOPrefs::usrReadConfig() { KConfigGroup generalConfig( config(), "General" ); KConfigGroup timeScaleConfig( config(), "Timescale" ); setTimeScaleTimezones( timeScaleConfig.readEntry( "Timescale Timezones", QStringList() ) ); KConfigSkeleton::usrReadConfig(); } void KOPrefs::usrWriteConfig() { KConfigGroup generalConfig( config(), "General" ); KConfigGroup timeScaleConfig( config(), "Timescale" ); timeScaleConfig.writeEntry( "Timescale Timezones", timeScaleTimezones() ); KConfigSkeleton::usrWriteConfig(); } void KOPrefs::setResourceColor ( const QString &cal, const QColor &color ) { return mEventViewsPrefs->setResourceColor( cal, color ); } QColor KOPrefs::resourceColor( const QString &cal ) { return mEventViewsPrefs->resourceColor( cal ); } +QColor KOPrefs::resourceColorKnown(const QString &cal) +{ + return mEventViewsPrefs->resourceColorKnown( cal ); +} + QStringList KOPrefs::timeScaleTimezones() const { return mTimeScaleTimeZones; } void KOPrefs::setTimeScaleTimezones( const QStringList &list ) { mTimeScaleTimeZones = list; } void KOPrefs::setHtmlExportFile( const QString &fileName ) { mHtmlExportFile = fileName; } QString KOPrefs::htmlExportFile() const { return mHtmlExportFile; } EventViews::PrefsPtr KOPrefs::eventViewsPreferences() const { return mEventViewsPrefs; } diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h index 03dff13985..0a00c7de6f 100644 --- a/korganizer/koprefs.h +++ b/korganizer/koprefs.h @@ -1,89 +1,90 @@ /* This file is part of KOrganizer. Copyright (c) 2000,2001 Cornelius Schumacher 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KORG_KOPREFS_H #define KORG_KOPREFS_H #include "korganizer_export.h" #include "koprefs_base.h" #include class KORGANIZER_CORE_EXPORT KOPrefs : public KOPrefsBase { public: virtual ~KOPrefs(); /** Get instance of KOPrefs. It is made sure that there is only one instance. */ static KOPrefs *instance(); EventViews::PrefsPtr eventViewsPreferences() const; /** Set preferences to default values */ void usrSetDefaults(); /** Read preferences from config file */ void usrReadConfig(); /** Write preferences to config file */ void usrWriteConfig(); private: /** Constructor disabled for public. Use instance() to create a KOPrefs object. */ KOPrefs(); friend class KOPrefsPrivate; public: void setResourceColor ( const QString &, const QColor & ); QColor resourceColor( const QString & ); + QColor resourceColorKnown( const QString & ); void setHtmlExportFile( const QString &fileName ); QString htmlExportFile() const; QStringList timeScaleTimezones() const; void setTimeScaleTimezones( const QStringList &list ); private: QHash mCategoryColors; QColor mDefaultCategoryColor; QHash mResourceColors; QColor mDefaultResourceColor; QFont mDefaultMonthViewFont; QStringList mTimeScaleTimeZones; QString mHtmlExportFile; EventViews::PrefsPtr mEventViewsPrefs; public: // Do not use - except in KOPrefsDialogMain QString mName; QString mEmail; }; #endif diff --git a/korganizer/views/collectionview/calendardelegate.cpp b/korganizer/views/collectionview/calendardelegate.cpp index 6633c93a64..c8b6a4029d 100644 --- a/korganizer/views/collectionview/calendardelegate.cpp +++ b/korganizer/views/collectionview/calendardelegate.cpp @@ -1,241 +1,264 @@ /* Copyright (c) 2014 Christian Mollekopf This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "calendardelegate.h" #include #include #include #include #include #include #include #include "controller.h" StyledCalendarDelegate::StyledCalendarDelegate(QObject * parent) : QStyledItemDelegate(parent) { mPixmap.insert(Enable, KIconLoader().loadIcon(QLatin1String("bookmarks"), KIconLoader::Small)); mPixmap.insert(RemoveFromList, KIconLoader().loadIcon(QLatin1String("list-remove"), KIconLoader::Small)); mPixmap.insert(AddToList, KIconLoader().loadIcon(QLatin1String("list-add"), KIconLoader::Small)); mPixmap.insert(Quickview, KIconLoader().loadIcon(QLatin1String("quickview"), KIconLoader::Small)); } StyledCalendarDelegate::~StyledCalendarDelegate() { } static QRect enableButtonRect(const QRect &rect, int pos = 1) { //2px border on each side of the icon static int border = 2; const int side = rect.height() - (2 * border); const int offset = side * pos + border * (pos + 1); return rect.adjusted(rect.width() - (offset + side), border, -offset, -border); } static QStyle *style(const QStyleOptionViewItem &option) { QWidget const *widget = 0; if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast(&option)) { widget = v3->widget; } QStyle *style = widget ? widget->style() : QApplication::style(); return style; } static QStyleOptionButton buttonOpt(const QStyleOptionViewItemV4 &opt, const QPixmap &pixmap, int pos = 1) { QStyleOptionButton option; option.icon = pixmap; QRect r = opt.rect; const int h = r.height() - 4; option.rect = enableButtonRect(r, pos); option.state = QStyle::State_Active | QStyle::State_Enabled; option.iconSize = QSize(h, h); return option; } static bool isChildOfPersonCollection(const QModelIndex &index) { QModelIndex parent = index.parent(); while (parent.isValid()) { if (parent.data(NodeTypeRole).toInt() == PersonNodeRole) { return true; } parent = parent.parent(); } return false; } +static Akonadi::Collection personCollection(const QModelIndex &index) +{ + QModelIndex parent = index.parent(); + while (parent.isValid()) { + if (parent.data(NodeTypeRole).toInt() == PersonNodeRole) { + return CalendarSupport::collectionFromIndex(parent); + } + parent = parent.parent(); + } + return Akonadi::Collection(); +} + static bool isPersonNode(const QModelIndex &index) { if (index.data(NodeTypeRole).toInt() == PersonNodeRole) { return true; } return false; } QList StyledCalendarDelegate::getActions(const QStyleOptionViewItem &option, const QModelIndex &index) const { const bool isSearchResult = index.data(IsSearchResultRole).toBool(); const bool hover = option.state & QStyle::State_MouseOver; const Akonadi::Collection col = CalendarSupport::collectionFromIndex(index); Qt::CheckState enabled = static_cast(index.data(EnabledRole).toInt()); // kDebug() << index.data().toString() << enabled; const bool isSearchCollection = col.resource().startsWith(QLatin1String("akonadi_search_resource")); const bool isKolabCollection = col.resource().startsWith(QLatin1String("akonadi_kolab_resource")); const bool isTopLevelCollection = (col.parentCollection() == Akonadi::Collection::root()); const bool isToplevelSearchCollection = (isTopLevelCollection && isSearchCollection); const bool isToplevelKolabCollection = (isTopLevelCollection && isKolabCollection); QList buttons; if (!isSearchCollection && !isToplevelKolabCollection) { if (isSearchResult) { buttons << AddToList; } else { if (hover) { if (enabled != Qt::Checked) { buttons << Enable; } //The remove button should not be available for person subfolders if (!isChildOfPersonCollection(index)) { buttons << RemoveFromList; } } else { if (enabled == Qt::Checked) { buttons << Enable; } } } } if (!isToplevelSearchCollection && !isToplevelKolabCollection) { buttons << Quickview; } return buttons; } void StyledCalendarDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { Q_ASSERT(index.isValid()); const Akonadi::Collection col = CalendarSupport::collectionFromIndex(index); //We display the toolbuttons while hovering const bool showButtons = option.state & QStyle::State_MouseOver; // const bool enabled = col.shouldList(Akonadi::Collection::ListDisplay); Qt::CheckState enabled = static_cast(index.data(EnabledRole).toInt()); QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); QStyledItemDelegate::paint(painter, opt, index); QStyle *s = style(option); //Buttons { QList buttons; int i = 1; Q_FOREACH (Action action, getActions(option, index)) { QStyleOptionButton buttonOption = buttonOpt(opt, mPixmap.value(action), i); if (action == Enable && showButtons) { buttonOption.state = QStyle::State_Active; } if (action == Enable && !showButtons && enabled == Qt::PartiallyChecked) { buttonOption.state = QStyle::State_Active; } s->drawControl(QStyle::CE_PushButton, &buttonOption, painter, 0); i++; } } //Color indicator if (opt.checkState){ - QColor color = KOHelper::resourceColor(col); + QColor color = KOHelper::resourceColorKnown(col); + if (!color.isValid() && isChildOfPersonCollection(index)){ + const Akonadi::Collection parentCol = personCollection(index); + if (parentCol.isValid()) { + color = KOHelper::resourceColor(parentCol); + KOHelper::setResourceColor(col, color); + } else { + color = KOHelper::resourceColor(col); + } + } else { + color = KOHelper::resourceColor(col); + } if (color.isValid()){ painter->save(); painter->setRenderHint(QPainter::Antialiasing); QPen pen = painter->pen(); pen.setColor(color); QPainterPath path; path.addRoundedRect(enableButtonRect(opt.rect, 0), 5, 5); color.setAlpha(200); painter->fillPath(path, color); painter->strokePath(path, pen); painter->restore(); } } } bool StyledCalendarDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); Q_ASSERT(model); int button = -1; // make sure that we have the right event type if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonDblClick) || (event->type() == QEvent::MouseButtonPress)) { QMouseEvent *me = static_cast(event); for (int i = 1; i < 4; i++) { if (enableButtonRect(option.rect, i).contains(me->pos())) { button = i; break; } } if (me->button() != Qt::LeftButton || button < 0) { return QStyledItemDelegate::editorEvent(event, model, option, index); } if ((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonDblClick)) { return true; } } else { return QStyledItemDelegate::editorEvent(event, model, option, index); } Q_ASSERT(button > 0); QStyleOptionViewItem opt = option; opt.state |= QStyle::State_MouseOver; QList actions = getActions(opt, index); if (actions.count() >= button) { const Action a = actions.at(button - 1); emit action(index, a); return true; } return QStyledItemDelegate::editorEvent(event, model, option, index); } QSize StyledCalendarDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const { QSize size = QStyledItemDelegate::sizeHint(option, index); //Without this adjustment toplevel resource folders get a slightly greater height, which looks silly and breaks the toolbutton position. size.setHeight(mPixmap.value(AddToList).height() + 4); return size; }