File indexing completed on 2024-05-12 04:20:40
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KGANTTDATETIMEGRID_P_H 0010 #define KGANTTDATETIMEGRID_P_H 0011 0012 #include "kganttdatetimegrid.h" 0013 #include "kganttabstractgrid_p.h" 0014 #include "kganttdatetimetimeline.h" 0015 0016 #include <QDateTime> 0017 #include <QBrush> 0018 0019 namespace KGantt { 0020 class Q_DECL_HIDDEN DateTimeScaleFormatter::Private 0021 { 0022 public: 0023 Private( DateTimeScaleFormatter::Range _range, 0024 const QString& _format, 0025 const QString& _templ, 0026 Qt::Alignment _alignment ) 0027 : range( _range ), 0028 format( _format ), 0029 templ( _templ ), 0030 alignment( _alignment ) 0031 { 0032 } 0033 0034 const DateTimeScaleFormatter::Range range; 0035 const QString format; 0036 const QString templ; 0037 const Qt::Alignment alignment; 0038 }; 0039 0040 class Q_DECL_HIDDEN DateTimeGrid::Private : public AbstractGrid::Private { 0041 public: 0042 Private() 0043 : startDateTime( QDateTime::currentDateTime().addDays( -3 ) ), 0044 dayWidth( 100. ), 0045 scale( ScaleAuto ), 0046 weekStart( Qt::Monday ), 0047 freeDays( QSet<Qt::DayOfWeek>() << Qt::Saturday << Qt::Sunday ), 0048 rowSeparators( false ), 0049 noInformationBrush( Qt::red, Qt::DiagCrossPattern ), 0050 freeDaysBrush(QBrush()), 0051 upper( new DateTimeScaleFormatter( DateTimeScaleFormatter::Week, QString::fromLatin1( "w" ) ) ), 0052 lower( new DateTimeScaleFormatter( DateTimeScaleFormatter::Day, QString::fromLatin1( "ddd" ) ) ), 0053 year_upper( DateTimeScaleFormatter::Year, QString::fromLatin1("yyyy" ) ), 0054 year_lower( DateTimeScaleFormatter::Month, QString::fromLatin1("MMM" ) ), 0055 month_upper( DateTimeScaleFormatter::Month, QString::fromLatin1("MMMM" ) ), 0056 month_lower( DateTimeScaleFormatter::Week, QString::fromLatin1("w" ) ), 0057 week_upper( DateTimeScaleFormatter::Week, QString::fromLatin1("w" ) ), 0058 week_lower( DateTimeScaleFormatter::Day, QString::fromLatin1("ddd" ) ), 0059 day_upper( DateTimeScaleFormatter::Day, QString::fromLatin1("dddd" ) ), 0060 day_lower( DateTimeScaleFormatter::Hour, QString::fromLatin1("hh" ) ), 0061 hour_upper( DateTimeScaleFormatter::Hour, QString::fromLatin1("hh" ) ), 0062 hour_lower( DateTimeScaleFormatter::Minute, QString::fromLatin1("m" ) ), 0063 minute_upper( DateTimeScaleFormatter::Minute, QString::fromLatin1("m" ) ), 0064 minute_lower( DateTimeScaleFormatter::Second, QString::fromLatin1("s" ) ), 0065 timeLine(new DateTimeTimeLine) 0066 { 0067 } 0068 ~Private() override 0069 { 0070 delete lower; 0071 delete upper; 0072 delete timeLine; 0073 } 0074 0075 qreal dateTimeToChartX( const QDateTime& dt ) const; 0076 QDateTime chartXtoDateTime( qreal x ) const; 0077 0078 int tabHeight( const QString& txt, QWidget* widget = nullptr ) const; 0079 void getAutomaticFormatters( DateTimeScaleFormatter** lower, DateTimeScaleFormatter** upper); 0080 void getFormatters( DateTimeScaleFormatter** lower, DateTimeScaleFormatter** upper); 0081 0082 class DateTextFormatter { 0083 public: 0084 virtual ~DateTextFormatter() {} 0085 virtual QString format( const QDateTime& dt ) = 0; 0086 virtual QRect textRect( qreal x, qreal offset, qreal dayWidth, const QRectF& headerRect, const QDateTime& dt ) = 0; 0087 }; 0088 0089 /*! 0090 * We need this because we have a header type for a year, but no such scale. 0091 */ 0092 enum HeaderType { 0093 HeaderHour, 0094 HeaderDay, 0095 HeaderWeek, 0096 HeaderMonth, 0097 HeaderYear 0098 }; 0099 0100 HeaderType headerTypeForScale( DateTimeGrid::Scale scale ); 0101 0102 void paintHeader( QPainter* painter, 0103 const QRectF& headerRect, const QRectF& exposedRect, 0104 qreal offset, QWidget* widget, 0105 HeaderType headerType, 0106 DateTextFormatter *formatter ); 0107 void paintVerticalLines( QPainter* painter, 0108 const QRectF& sceneRect, 0109 const QRectF& exposedRect, 0110 QWidget* widget, 0111 HeaderType headerType ); 0112 void paintVerticalUserDefinedLines( QPainter* painter, 0113 const QRectF& sceneRect, 0114 const QRectF& exposedRect, 0115 QWidget* widget ); 0116 0117 Qt::PenStyle gridLinePenStyle( QDateTime dt, HeaderType headerType ) const; 0118 QDateTime adjustDateTimeForHeader( QDateTime dt, HeaderType headerType ) const; 0119 0120 void drawTimeLine(QPainter* painter, const QRectF& rect); 0121 0122 QDateTime startDateTime; 0123 QDateTime endDateTime; 0124 qreal dayWidth; 0125 Scale scale; 0126 Qt::DayOfWeek weekStart; 0127 QSet<Qt::DayOfWeek> freeDays; 0128 bool rowSeparators; 0129 QBrush noInformationBrush; 0130 QBrush freeDaysBrush; 0131 0132 DateTimeScaleFormatter* upper; 0133 DateTimeScaleFormatter* lower; 0134 0135 DateTimeScaleFormatter year_upper; 0136 DateTimeScaleFormatter year_lower; 0137 DateTimeScaleFormatter month_upper; 0138 DateTimeScaleFormatter month_lower; 0139 DateTimeScaleFormatter week_upper; 0140 DateTimeScaleFormatter week_lower; 0141 DateTimeScaleFormatter day_upper; 0142 DateTimeScaleFormatter day_lower; 0143 DateTimeScaleFormatter hour_upper; 0144 DateTimeScaleFormatter hour_lower; 0145 DateTimeScaleFormatter minute_upper; 0146 DateTimeScaleFormatter minute_lower; 0147 DateTimeTimeLine *timeLine; 0148 }; 0149 0150 inline DateTimeGrid::DateTimeGrid( DateTimeGrid::Private* d ) : AbstractGrid( d ) {} 0151 0152 inline DateTimeGrid::Private* DateTimeGrid::d_func() { 0153 return static_cast<Private*>( AbstractGrid::d_func() ); 0154 } 0155 inline const DateTimeGrid::Private* DateTimeGrid::d_func() const { 0156 return static_cast<const Private*>( AbstractGrid::d_func() ); 0157 } 0158 } 0159 0160 #endif /* KGANTTDATETIMEGRID_P_H */ 0161