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