File indexing completed on 2024-05-12 16:35:03

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 #ifndef DATEVARIABLE_H
0021 #define DATEVARIABLE_H
0022 
0023 #include <KoVariable.h>
0024 
0025 #include <QString>
0026 #include <QDateTime>
0027 
0028 /**
0029  * Base class for in-text variables.
0030  * A variable is a field inserted into the text and the content is set to a specific value that
0031  * is used as text.  This class is pretty boring in that it has just a setValue() to alter the
0032  * text shown; we depend on plugin writers to create more exciting ways to update variables.
0033  */
0034 class DateVariable : public KoVariable
0035 {
0036 public:
0037     enum DateType {
0038         Fixed,
0039         AutoUpdate
0040     };
0041 
0042     enum DisplayType {
0043         Date,
0044         Time
0045     };
0046 
0047     enum ValueType {
0048         DateOrTime,
0049         DateTime
0050     };
0051 
0052     /**
0053      * Constructor.
0054      */
0055     explicit DateVariable(DateType type);
0056     ~DateVariable() override;
0057 
0058     ///reimplemented
0059     void saveOdf(KoShapeSavingContext & context) override;
0060 
0061     ///reimplemented
0062     bool loadOdf(const KoXmlElement & element, KoShapeLoadingContext & context) override;
0063 
0064     void readProperties(const KoProperties *props);
0065 
0066     QWidget *createOptionsWidget() override;
0067 
0068     const QString & definition() const {
0069         return m_definition;
0070     }
0071     void setDefinition(const QString &definition);
0072 
0073     int daysOffset() const {
0074         return m_daysOffset;
0075     }
0076     void setDaysOffset(int daysOffset);
0077 
0078     int monthsOffset() const {
0079         return m_monthsOffset;
0080     }
0081     void setMonthsOffset(int monthsOffset);
0082 
0083     int yearsOffset() const {
0084         return m_yearsOffset;
0085     }
0086     void setYearsOffset(int yearsOffset);
0087 
0088     int secsOffset() const {
0089         return m_secsOffset;
0090     }
0091     void setSecsOffset(int secsOffset);
0092 
0093 private:
0094     void update();
0095     void adjustTime(const QString & adjustTime);
0096 
0097     DateType m_type;
0098     DisplayType m_displayType;
0099     ValueType m_valueType;
0100     QString m_definition;
0101     QDateTime m_datetime;
0102     int m_daysOffset;
0103     int m_monthsOffset;
0104     int m_yearsOffset;
0105     int m_secsOffset;
0106 };
0107 
0108 #endif