diff --git a/3rdparty/kdgantt/CMakeLists.txt b/3rdparty/kdgantt/CMakeLists.txt index 21081583d3..f6afcbac5e 100644 --- a/3rdparty/kdgantt/CMakeLists.txt +++ b/3rdparty/kdgantt/CMakeLists.txt @@ -1,41 +1,42 @@ include_directories( ${QT_INCLUDES} + ${KDE4_INCLUDES} ${KDGANTT_INCLUDES} ) add_definitions(-DKDAB_NO_UNIT_TESTS -DKDGANTT_SHAREDLIB -DKDGANTT_BUILD_KDGANTT_LIB) set( kdgantt_LIB_SRCS kdganttglobal.cpp kdganttview.cpp kdganttstyleoptionganttitem.cpp kdganttgraphicsview.cpp kdganttabstractrowcontroller.cpp kdgantttreeviewrowcontroller.cpp kdganttlistviewrowcontroller.cpp kdganttgraphicsscene.cpp kdganttgraphicsitem.cpp kdganttconstraint.cpp kdganttconstraintproxy.cpp kdganttconstraintgraphicsitem.cpp kdganttitemdelegate.cpp kdganttforwardingproxymodel.cpp kdganttsummaryhandlingproxymodel.cpp kdganttproxymodel.cpp kdganttconstraintmodel.cpp kdganttabstractgrid.cpp kdganttdatetimegrid.cpp kdganttlegend.cpp kdgantttimescalezoomdialog.cpp ) kde4_add_library(calligrakdgantt SHARED ${kdgantt_LIB_SRCS}) -target_link_libraries(calligrakdgantt ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) -target_link_libraries(calligrakdgantt LINK_INTERFACE_LIBRARIES ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) +target_link_libraries(calligrakdgantt ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) +target_link_libraries(calligrakdgantt LINK_INTERFACE_LIBRARIES ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) set_target_properties(calligrakdgantt PROPERTIES VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION} ) install(TARGETS calligrakdgantt ${INSTALL_TARGETS_DEFAULT_ARGS} ) diff --git a/3rdparty/kdgantt/kdganttdatetimegrid.cpp b/3rdparty/kdgantt/kdganttdatetimegrid.cpp index 79c405c9c1..9ee56aaedd 100644 --- a/3rdparty/kdgantt/kdganttdatetimegrid.cpp +++ b/3rdparty/kdgantt/kdganttdatetimegrid.cpp @@ -1,1002 +1,1017 @@ /**************************************************************************** ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved. ** ** This file is part of the KD Gantt library. ** ** This file may be used under the terms of the GNU General Public ** License versions 2.0 or 3.0 as published by the Free Software ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Alternatively you may (at ** your option) use any later version of the GNU General Public ** License if such license has been publicly approved by ** Klarälvdalens Datakonsult AB (or its successors, if any). ** ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights ** not expressly granted herein. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "kdganttdatetimegrid.h" #include "kdganttdatetimegrid_p.h" #include "kdganttabstractrowcontroller.h" +#include +#include + #include #include #include #include #include #include #include #include using namespace KDGantt; /*!\class KDGantt::DateTimeGrid * \ingroup KDGantt * * This implementation of AbstractGrid works with QDateTime * and shows days and week numbers in the header * * \todo Extend to work with hours, minutes,... as units too. */ // TODO: I think maybe this class should be responsible // for unit-transformation of the scene... qreal DateTimeGrid::Private::dateTimeToChartX( const QDateTime& dt ) const { assert( startDateTime.isValid() ); qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.; result += startDateTime.time().msecsTo(dt.time())/1000.; result *= dayWidth/( 24.*60.*60. ); return result; } QDateTime DateTimeGrid::Private::chartXtoDateTime( qreal x ) const { assert( startDateTime.isValid() ); int days = static_cast( x/dayWidth ); qreal secs = x*( 24.*60.*60. )/dayWidth; QDateTime dt = startDateTime; QDateTime result = dt.addDays( days ) .addSecs( static_cast(secs-(days*24.*60.*60.) ) ) .addMSecs( qRound( ( secs-static_cast( secs ) )*1000. ) ); return result; } #define d d_func() DateTimeGrid::DateTimeGrid() : AbstractGrid( new Private ) { } DateTimeGrid::~DateTimeGrid() { } /*! \returns The QDateTime used as start date for the grid. * * The default is three days before the current date. */ QDateTime DateTimeGrid::startDateTime() const { return d->startDateTime; } /*! \param dt The start date of the grid. It is used as the beginning of the * horizontal scrollbar in the view. * * Emits gridChanged() after the start date has changed. */ void DateTimeGrid::setStartDateTime( const QDateTime& dt ) { d->startDateTime = dt; emit gridChanged(); } /*! \returns The width in pixels for each day in the grid. * * The default is 100 pixels. */ qreal DateTimeGrid::dayWidth() const { return d->dayWidth; } /*! \param w The width in pixels for each day in the grid. * Day width is limited to minimum 1.0. * * The signal gridChanged() is emitted after the day width is changed. */ void DateTimeGrid::setDayWidth( qreal w ) { qDebug()<<"DateTimeGrid::setDayWidth"<dayWidth = qMax( w, qreal(0.1) ); emit gridChanged(); } /*! \param s The scale to be used to paint the grid. * * The signal gridChanged() is emitted after the scale has changed. * \sa Scale */ void DateTimeGrid::setScale( Scale s ) { d->scale = s; emit gridChanged(); } /*! \returns The scale used to paint the grid. * * The default is ScaleAuto, which means the day scale will be used * as long as the day width is less or equal to 500. * \sa Scale */ DateTimeGrid::Scale DateTimeGrid::scale() const { return d->scale; } /*! \returns The format used to paint the hours. * * The default is "hh". */ QString DateTimeGrid::hourFormat() const { return d->hourFormat; } /*! Set the format used to paint the hours. * * If @p format is empty, it is not set. */ void DateTimeGrid::setHourFormat( const QString &format ) { if ( ! format.isEmpty() ) { d->hourFormat = format; } } /*! \param factor The zoom factor * */ void DateTimeGrid::zoomIn( qreal factor ) { setDayWidth( d->dayWidth * factor ); } /*! \param factor The zoom factor * */ void DateTimeGrid::zoomOut( qreal factor ) { setDayWidth( d->dayWidth * factor ); } /*! \param ws The start day of the week. * * A solid line is drawn on the grid to mark the beginning of a new week. * Emits gridChanged() after the start day has changed. */ void DateTimeGrid::setWeekStart( Qt::DayOfWeek ws ) { d->weekStart = ws; emit gridChanged(); } /*! \returns The start day of the week */ Qt::DayOfWeek DateTimeGrid::weekStart() const { return d->weekStart; } /*! \param fd A set of days to mark as free in the grid. * * Free days are filled with the alternate base brush of the * palette used by the view. * The signal gridChanged() is emitted after the free days are changed. */ void DateTimeGrid::setFreeDays( const QSet& fd ) { d->freeDays = fd; emit gridChanged(); } /*! \returns true if row separators are used. */ bool DateTimeGrid::rowSeparators() const { return d->rowSeparators; } /*! \param enable Whether to use row separators or not. */ void DateTimeGrid::setRowSeparators( bool enable ) { d->rowSeparators = enable; } /*! \returns The days marked as free in the grid. */ QSet DateTimeGrid::freeDays() const { return d->freeDays; } /*! * \param value The datetime to get the x value for. * \returns The x value corresponding to \a value or -1.0 if \a value is not a datetime variant. */ qreal DateTimeGrid::mapToChart( const QVariant& value ) const { if ( ! qVariantCanConvert( value ) || ( value.type() == QVariant::String && qVariantValue(value).isEmpty() ) ) { return -1.0; } return d->dateTimeToChartX( value.toDateTime() ); } /*! * \param x The x value get the datetime for. * \returns The datetime corresponding to \a x or an invalid datetime if x cannot be mapped. */ QVariant DateTimeGrid::mapFromChart( qreal x ) const { return d->chartXtoDateTime( x ); } /*! \param idx The index to get the Span for. * \returns The start and end pixels, in a Span, of the specified index. */ Span DateTimeGrid::mapToChart( const QModelIndex& idx ) const { assert( model() ); if ( !idx.isValid() ) return Span(); assert( idx.model()==model() ); const QVariant sv = model()->data( idx, StartTimeRole ); const QVariant ev = model()->data( idx, EndTimeRole ); if( qVariantCanConvert(sv) && qVariantCanConvert(ev) && !(sv.type() == QVariant::String && qVariantValue(sv).isEmpty()) && !(ev.type() == QVariant::String && qVariantValue(ev).isEmpty()) ) { QDateTime st = sv.toDateTime(); QDateTime et = ev.toDateTime(); if ( et.isValid() && st.isValid() ) { qreal sx = d->dateTimeToChartX( st ); qreal ex = d->dateTimeToChartX( et )-sx; //qDebug() << "DateTimeGrid::mapToChart("< "<< Span( sx, ex ); return Span( sx, ex); } } // Special case for Events with only a start date if( qVariantCanConvert(sv) && !(sv.type() == QVariant::String && qVariantValue(sv).isEmpty()) ) { QDateTime st = sv.toDateTime(); if ( st.isValid() ) { qreal sx = d->dateTimeToChartX( st ); return Span( sx, 0 ); } } return Span(); } #if 0 static void debug_print_idx( const QModelIndex& idx ) { if ( !idx.isValid() ) { qDebug() << "[Invalid]"; return; } QDateTime st = idx.data( StartTimeRole ).toDateTime(); QDateTime et = idx.data( StartTimeRole ).toDateTime(); qDebug() << idx << "["<& constraints ) const { assert( model() ); if ( !idx.isValid() ) return false; assert( idx.model()==model() ); QDateTime st = d->chartXtoDateTime(span.start()); QDateTime et = d->chartXtoDateTime(span.start()+span.length()); //qDebug() << "DateTimeGrid::mapFromChart("< "<< st << et; Q_FOREACH( const Constraint& c, constraints ) { if ( c.type() != Constraint::TypeHard || !isSatisfiedConstraint( c )) continue; if ( c.startIndex() == idx ) { QDateTime tmpst = model()->data( c.endIndex(), StartTimeRole ).toDateTime(); //qDebug() << tmpst << "<" << et <<"?"; if ( tmpstdata( c.startIndex(), EndTimeRole ).toDateTime(); //qDebug() << tmpet << ">" << st <<"?"; if ( tmpet>st ) return false; } } return model()->setData( idx, qVariantFromValue(st), StartTimeRole ) && model()->setData( idx, qVariantFromValue(et), EndTimeRole ); } DateTimeGrid::Scale DateTimeGrid::autoScale() const { Scale scale = ScaleDay; if ( dayWidth() > 450) { scale = ScaleHour; } else if (dayWidth() * 30 < 20) { scale = ScaleYear; } else if (dayWidth() * 7 < 20) { scale = ScaleMonth; } else if (dayWidth() < 12) { scale = ScaleWeek; } return scale; } void DateTimeGrid::paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect, AbstractRowController* rowController, QWidget* widget ) { //qDebug()<<"paintGrid()"<chartXtoDateTime( exposedRect.left() ); dt.setTime( QTime( dt.time().hour(), 0, 0, 0 ) ); for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addSecs( 60*60 ),x=d->dateTimeToChartX( dt ) ) { QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); if ( dt.time() == QTime( 23, 0, 0 ) ) { pen.setStyle( Qt::SolidLine ); } else { pen.setStyle( Qt::DashLine ); } painter->setPen( pen ); x += ( dayWidth() / 24.0 ) - 1; painter->drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) ); } } void DateTimeGrid::paintDayGrid( QPainter* painter, const QRectF& /*sceneRect*/, const QRectF& exposedRect, AbstractRowController* /*rowController*/, QWidget* widget ) { //qDebug()<<"paintDayGrid()"<chartXtoDateTime( exposedRect.left() ); dt.setTime( QTime( 0, 0, 0, 0 ) ); for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) { QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); if ( dt.date().addDays( 1 ).dayOfWeek() == d->weekStart ) { pen.setStyle( Qt::SolidLine ); } else { pen.setStyle( Qt::DashLine ); } painter->setPen( pen ); paintFreeDay( painter, x, exposedRect, dt.date(), widget ); x += dayWidth() - 1; painter->drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) ); } } void DateTimeGrid::paintWeekGrid( QPainter* painter, const QRectF& /*sceneRect*/, const QRectF& exposedRect, AbstractRowController* /*rowController*/, QWidget* widget ) { //qDebug()<<"paintWeekGrid()"<chartXtoDateTime( exposedRect.left() ); dt.setTime( QTime( 0, 0, 0, 0 ) ); while ( dt.date().dayOfWeek() != d->weekStart ) dt = dt.addDays( -1 ); for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) { QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); if ( dt.date().addDays( 1 ).day() == 1 ) { pen.setStyle( Qt::SolidLine ); } else if ( dt.date().addDays( 1 ).dayOfWeek() == d->weekStart ) { pen.setStyle( Qt::DashLine ); } else { pen.setStyle( Qt::NoPen ); } painter->setPen( pen ); paintFreeDay( painter, x, exposedRect, dt.date(), widget ); if ( pen.style() != Qt::NoPen ) { //qDebug()<<"paintWeekGrid()"<drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) ); } } } void DateTimeGrid::paintMonthGrid( QPainter* painter, const QRectF& /*sceneRect*/, const QRectF& exposedRect, AbstractRowController* /*rowController*/, QWidget* widget ) { //qDebug()<<"paintMonthGrid()"<chartXtoDateTime( exposedRect.left() ); dt.setTime( QTime( 0, 0, 0, 0 ) ); dt = dt.addDays( 1 - dt.date().day() ); for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) { QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); if ( dt.date().addMonths( 1 ).month() == 1 && dt.date().addDays( 1 ).day() == 1 ) { pen.setStyle( Qt::SolidLine ); } else if ( dt.date().addDays( 1 ).day() == 1 ) { pen.setStyle( Qt::DashLine ); } else { pen.setStyle( Qt::NoPen ); } painter->setPen( pen ); paintFreeDay( painter, x, exposedRect, dt.date(), widget ); if ( pen.style() != Qt::NoPen ) { //qDebug()<<"paintMonthGrid()"<drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) ); } } } void DateTimeGrid::paintYearGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect, AbstractRowController* rowController, QWidget* widget ) { //qDebug()<<"paintYearGrid()"<chartXtoDateTime( exposedRect.left() ); dt.setTime( QTime( 0, 0, 0, 0 ) ); dt = dt.addDays( 1 - dt.date().day() ); for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right(); dt = dt.addDays( 1 ),x=d->dateTimeToChartX( dt ) ) { QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); if ( dt.date().addMonths( 1 ).month() == 1 && dt.date().addDays( 1 ).day() == 1 ) { // Solid line at day 1 of each year. pen.setStyle( Qt::SolidLine ); } else if ( dt.date().addMonths( 1 ).month() % 3 == 1 && dt.date().addDays( 1 ).day() == 1 ) { // Dashed line between the quarters pen.setStyle( Qt::DashLine ); } else { pen.setStyle( Qt::NoPen ); } painter->setPen( pen ); paintFreeDay( painter, x, exposedRect, dt.date(), widget ); if ( pen.style() != Qt::NoPen ) { //qDebug()<<"paintYearGrid()"<drawLine( QPointF( x, exposedRect.top() ), QPointF( x, exposedRect.bottom() ) ); } } } void DateTimeGrid::paintFreeDay( QPainter* painter, qreal x, const QRectF& exposedRect, const QDate &dt, QWidget* widget ) { if ( d->freeDays.contains( static_cast( dt.dayOfWeek() ) ) ) { //FIXME We now use same color for alternating rows and free days painter->setBrush( widget ? widget->palette().alternateBase() : QApplication::palette().alternateBase() ); painter->fillRect( QRectF( x, exposedRect.top(), dayWidth(), exposedRect.height() ), painter->brush() ); } } void DateTimeGrid::paintRowGrid( QPainter* painter, const QRectF& /*sceneRect*/, const QRectF& exposedRect, AbstractRowController* rowController, QWidget* /*widget*/ ) { if ( rowController && rowSeparators() ) { // First draw the rows QPen pen = painter->pen(); pen.setBrush( QApplication::palette().dark() ); pen.setStyle( Qt::DashLine ); painter->setPen( pen ); QModelIndex idx = rowController->indexAt( qRound( exposedRect.top() ) ); qreal y = 0; while ( y < exposedRect.bottom() && idx.isValid() ) { const Span s = rowController->rowGeometry( idx ); y = s.start()+s.length(); //painter->drawLine( QPointF( sceneRect.left(), y ), QPointF( sceneRect.right(), y ) ); // Is alternating background better? if ( idx.row()%2 ) painter->fillRect( QRectF( exposedRect.x(), s.start(), exposedRect.width(), s.length() ), QApplication::palette().alternateBase() ); idx = rowController->indexBelow( idx ); } } } void DateTimeGrid::render( QPainter* painter, const QRectF &target, const QRectF& headerRect, const QRectF& exposedRect, QWidget *widget, Qt::AspectRatioMode aspectRatioMode ) { painter->save(); qreal xratio = target.width() / exposedRect.width(); qreal yratio = target.height() / exposedRect.height(); //qDebug()<<"QGraphicsScene::render()"<drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } dt = d->chartXtoDateTime( offset+exposedRect.left() ); dt.setTime( QTime( 0, 0, 0, 0 ) ); // Go backwards until start of week while ( dt.date().dayOfWeek() != d->weekStart ) dt = dt.addDays( -1 ); // Paint a section for each week for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; dt = dt.addDays( 7 ),x2=d->dateTimeToChartX( dt ) ) { QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*7., headerRect.height()/2. ).toRect(); - opt.text = QString::number( dt.date().weekNumber() ); +#if KDE_IS_VERSION(4,7,0) + opt.text = QString::number( calendar->week(dt.date()) ); +#else + opt.text = QString::number( calendar->weekNumber(dt.date()) ); +#endif opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } } /*! Paints the week scale header. * \sa paintHeader() */ void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget ) { + const KCalendarSystem * calendar = KGlobal::locale()->calendar(); + QStyle* style = widget?widget->style():QApplication::style(); // Paint a section for each week QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() ); sdt.setTime( QTime( 0, 0, 0, 0 ) ); // Go backwards until start of week while ( sdt.date().dayOfWeek() != d->weekStart ) sdt = sdt.addDays( -1 ); QDateTime dt = sdt; for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset; dt = dt.addDays( 7 ),x=d->dateTimeToChartX( dt ) ) { QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect(); - opt.text = QString::number( dt.date().weekNumber() ); +#if KDE_IS_VERSION(4,7,0) + opt.text = QString::number( calendar->week(dt.date()) ); +#else + opt.text = QString::number( calendar->weekNumber(dt.date()) ); +#endif opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } // Paint a section for each month dt = sdt; for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) { //qDebug()<<"paintWeekScaleHeader()"<drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } dt.setDate( next ); } } /*! Paints the month scale header. * \sa paintHeader() */ void DateTimeGrid::paintMonthScaleHeader( QPainter* painter, Scale scale, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget ) { QStyle* style = widget?widget->style():QApplication::style(); // Paint a section for each month QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() ); sdt.setTime( QTime( 0, 0, 0, 0 ) ); sdt = sdt.addDays( 1 - sdt.date().day() ); QDateTime dt = sdt; for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset; dt = dt.addMonths( 1 ),x=d->dateTimeToChartX( dt ) ) { QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*dt.date().daysInMonth(), headerRect.height()/2. ).toRect(); QString monthName = QDate::shortMonthName( dt.date().month() ); if (scale == ScaleYear) opt.text = monthName.left(1); else opt.text = monthName; opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } // Paint a section for each year dt = sdt; for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) { //qDebug()<<"paintMonthScaleHeader()"<drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } dt.setDate( next ); } } #if 0 /*! Paints the year scale header. * \sa paintHeader() */ void DateTimeGrid::paintYearScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget ) { #if 1 // FIXME: Improve this with e.g. single letter months paintMonthScaleHeader( painter, headerRect, exposedRect, offset, widget ); #else QStyle* style = widget?widget->style():QApplication::style(); // Paint a section for each month QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() ); sdt.setTime( QTime( 0, 0, 0, 0 ) ); sdt = sdt.addDays( 1 - sdt.date().day() ); QDateTime dt = sdt; for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset; dt = dt.addMonths( 1 ),x=d->dateTimeToChartX( dt ) ) { QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*dt.date().daysInMonth(), headerRect.height()/2. ).toRect(); opt.text = QDate::shortMonthName( dt.date().month() ); opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } // Paint a section for each year dt = sdt; for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) { //qDebug()<<"paintMonthScaleHeader()"<drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } dt.setDate( next ); } #endif } #endif #undef d #ifndef KDAB_NO_UNIT_TESTS #include #include "unittest/test.h" namespace { std::ostream& operator<<( std::ostream& os, const QDateTime& dt ) { os << dt.toString().toStdString(); return os; } } KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, DateTimeGrid, "test" ) { QStandardItemModel model( 3, 2 ); DateTimeGrid grid; QDateTime dt = QDateTime::currentDateTime(); grid.setModel( &model ); grid.setStartDateTime( dt.addDays( -10 ) ); model.setData( model.index( 0, 0 ), dt, StartTimeRole ); model.setData( model.index( 0, 0 ), dt.addDays( 17 ), EndTimeRole ); model.setData( model.index( 2, 0 ), dt.addDays( 18 ), StartTimeRole ); model.setData( model.index( 2, 0 ), dt.addDays( 19 ), EndTimeRole ); Span s = grid.mapToChart( model.index( 0, 0 ) ); //qDebug() << "span="<0 ); assertTrue( s.length()>0 ); grid.mapFromChart( s, model.index( 1, 0 ) ); QDateTime s1 = model.data( model.index( 0, 0 ), StartTimeRole ).toDateTime(); QDateTime e1 = model.data( model.index( 0, 0 ), EndTimeRole ).toDateTime(); QDateTime s2 = model.data( model.index( 1, 0 ), StartTimeRole ).toDateTime(); QDateTime e2 = model.data( model.index( 1, 0 ), EndTimeRole ).toDateTime(); assertTrue( s1.isValid() ); assertTrue( e1.isValid() ); assertTrue( s2.isValid() ); assertTrue( e2.isValid() ); assertEqual( s1, s2 ); assertEqual( e1, e2 ); assertTrue( grid.isSatisfiedConstraint( Constraint( model.index( 0, 0 ), model.index( 2, 0 ) ) ) ); assertFalse( grid.isSatisfiedConstraint( Constraint( model.index( 2, 0 ), model.index( 0, 0 ) ) ) ); s = grid.mapToChart( model.index( 0, 0 ) ); s.setEnd( s.end()+100000. ); bool rc = grid.mapFromChart( s, model.index( 0, 0 ) ); assertTrue( rc ); assertEqual( s1, model.data( model.index( 0, 0 ), StartTimeRole ).toDateTime() ); Span newspan = grid.mapToChart( model.index( 0, 0 ) ); assertEqual( newspan.start(), s.start() ); assertEqual( newspan.length(), s.length() ); { QDateTime startDateTime = QDateTime::currentDateTime(); qreal dayWidth = 100; QDate currentDate = QDate::currentDate(); QDateTime dt( QDate(currentDate.year(), 1, 1), QTime( 0, 0, 0, 0 ) ); assert( dt.isValid() ); qreal result = startDateTime.date().daysTo(dt.date())*24.*60.*60.; result += startDateTime.time().msecsTo(dt.time())/1000.; result *= dayWidth/( 24.*60.*60. ); int days = static_cast( result/dayWidth ); qreal secs = result*( 24.*60.*60. )/dayWidth; QDateTime dt2 = startDateTime; QDateTime result2 = dt2.addDays( days ).addSecs( static_cast(secs-(days*24.*60.*60.) ) ).addMSecs( qRound( ( secs-static_cast( secs ) )*1000. ) ); assertEqual( dt, result2 ); } } #endif /* KDAB_NO_UNIT_TESTS */ #include "moc_kdganttdatetimegrid.cpp" diff --git a/3rdparty/kdganttpatches/iso_week_numbering.diff b/3rdparty/kdganttpatches/iso_week_numbering.diff new file mode 100644 index 0000000000..bbcf1768c3 --- /dev/null +++ b/3rdparty/kdganttpatches/iso_week_numbering.diff @@ -0,0 +1,95 @@ +From 8b493063ad15668551214596e4e2ee7f5548989b Mon Sep 17 00:00:00 2001 +From: Alvaro Soliverez +Date: Sun, 24 Nov 2013 13:55:11 -0300 +Subject: [PATCH] If using ISO for week numbering, first day of week must be + Monday Use KLocale for week numbers instead of QDate's week methods + +Specific patch for 3rd party libkdgantt +--- + 3rdparty/kdgantt/CMakeLists.txt | 5 +++-- + 3rdparty/kdgantt/kdganttdatetimegrid.cpp | 19 +++++++++++++++++-- + 2 files changed, 20 insertions(+), 4 deletions(-) + +diff --git a/3rdparty/kdgantt/CMakeLists.txt b/3rdparty/kdgantt/CMakeLists.txt +index 2108158..f6afcba 100644 +--- a/3rdparty/kdgantt/CMakeLists.txt ++++ b/3rdparty/kdgantt/CMakeLists.txt +@@ -1,5 +1,6 @@ + include_directories( + ${QT_INCLUDES} ++ ${KDE4_INCLUDES} + ${KDGANTT_INCLUDES} + ) + +@@ -31,8 +32,8 @@ set( kdgantt_LIB_SRCS + + kde4_add_library(calligrakdgantt SHARED ${kdgantt_LIB_SRCS}) + +-target_link_libraries(calligrakdgantt ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) +-target_link_libraries(calligrakdgantt LINK_INTERFACE_LIBRARIES ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) ++target_link_libraries(calligrakdgantt ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) ++target_link_libraries(calligrakdgantt LINK_INTERFACE_LIBRARIES ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) + + set_target_properties(calligrakdgantt PROPERTIES + VERSION ${GENERIC_CALLIGRA_LIB_VERSION} +diff --git a/3rdparty/kdgantt/kdganttdatetimegrid.cpp b/3rdparty/kdgantt/kdganttdatetimegrid.cpp +index 79c405c..9ee56aa 100644 +--- a/3rdparty/kdgantt/kdganttdatetimegrid.cpp ++++ b/3rdparty/kdgantt/kdganttdatetimegrid.cpp +@@ -25,6 +25,9 @@ + + #include "kdganttabstractrowcontroller.h" + ++#include ++#include ++ + #include + #include + #include +@@ -700,6 +703,8 @@ void DateTimeGrid::paintHourScaleHeader( QPainter* painter, const QRectF& heade + void DateTimeGrid::paintDayScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, + qreal offset, QWidget* widget ) + { ++ const KCalendarSystem * calendar = KGlobal::locale()->calendar(); ++ + // For starters, support only the regular tab-per-day look + QStyle* style = widget?widget->style():QApplication::style(); + +@@ -732,7 +737,11 @@ void DateTimeGrid::paintDayScaleHeader( QPainter* painter, const QRectF& header + QStyleOptionHeader opt; + opt.init( widget ); + opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*7., headerRect.height()/2. ).toRect(); +- opt.text = QString::number( dt.date().weekNumber() ); ++#if KDE_IS_VERSION(4,7,0) ++ opt.text = QString::number( calendar->week(dt.date()) ); ++#else ++ opt.text = QString::number( calendar->weekNumber(dt.date()) ); ++#endif + opt.textAlignment = Qt::AlignCenter; + // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here + style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing +@@ -750,6 +759,8 @@ void DateTimeGrid::paintDayScaleHeader( QPainter* painter, const QRectF& header + void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, + qreal offset, QWidget* widget ) + { ++ const KCalendarSystem * calendar = KGlobal::locale()->calendar(); ++ + QStyle* style = widget?widget->style():QApplication::style(); + + // Paint a section for each week +@@ -763,7 +774,11 @@ void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& heade + QStyleOptionHeader opt; + opt.init( widget ); + opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect(); +- opt.text = QString::number( dt.date().weekNumber() ); ++#if KDE_IS_VERSION(4,7,0) ++ opt.text = QString::number( calendar->week(dt.date()) ); ++#else ++ opt.text = QString::number( calendar->weekNumber(dt.date()) ); ++#endif + opt.textAlignment = Qt::AlignCenter; + // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here + style->drawControl( QStyle::CE_HeaderSection, &opt, painter, 0 ); //NOTE: using widget will loose background when printing +-- +1.8.4 +