diff --git a/src/KGantt/kganttdatetimetimeline.h b/src/KGantt/kganttdatetimetimeline.h index b454679..2f9e95d 100644 --- a/src/KGantt/kganttdatetimetimeline.h +++ b/src/KGantt/kganttdatetimetimeline.h @@ -1,136 +1,135 @@ /* * Copyright (C) 2019 Dag Andersen * * This file is part of the KGantt library. * * 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, see . */ #ifndef KGANTTDATETIMETIMELINE_H #define KGANTTDATETIMETIMELINE_H #include "kganttglobal.h" #include class QDateTime; namespace KGantt { /*!\class KGantt::DateTimeTimeLine * \ingroup KGantt * * This class implements a timeline. * * The timeline can optionally be shown in the Background or in the Foreground. * Default is Foreground. * * The pen can be set with setPen(), and must be activated by setting the option UseCustomPen. * * The datetime can be set using setDateTime(). * * The timeline can priodically moved to the current datetime * by setting the interval > 0 with setInterval(). * Setting a zero interval turns the periodically update off. * * The timeline is off by default. * * For example: * \code * // Show a red timeline in the foreground * timeLine->setOptions(Foreground | UseCustomPen); * timeLine->setPen(QPen(Qt:red)); * // Update the timeline every 5 seconds * timeLine->setInterval(5000); * \endcode */ class KGANTT_EXPORT DateTimeTimeLine : public QObject { Q_OBJECT KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( DateTimeTimeLine ) public: enum Option { - Foreground = 1, /// Display the timeline in the foreground. - Background = 2, /// Display the timeline in the background. - - - /** - * @return the pen to be used to draw the timeline. - * If option UseCustomPen is not set a default pen is returned. - */ - UseCustomPen = 4, /// Paint the timeline using the pen set with setPen(). + Foreground = 1, ///< Display the timeline in the foreground. + Background = 2, ///< Display the timeline in the background. + UseCustomPen = 4, ///< Paint the timeline using the pen set with setPen(). MaxOptions = 0xFFFF }; Q_DECLARE_FLAGS(Options, Option) /** * Create a timeline object. * * By default, no timeline is displayed. */ DateTimeTimeLine(); /** * @return options */ DateTimeTimeLine::Options options() const; /** * Set options to @p options. * If both Background and Foreground are set, Foreground is used. */ void setOptions(DateTimeTimeLine::Options options); /** * @return the datetime * If the datetime is not valid, the current datetime is returned. */ QDateTime dateTime() const; /** * Set datetime to @p dt. */ void setDateTime(const QDateTime &dt); /** * @return the update interval in milliseconds */ int interval() const; /** * Set timer interval to @p msecs milliseconds. * Setting a zero time disables the timer. */ void setInterval(int msec); + + /** + * @return the pen that will be used for rendering the timeline + * If no pen has been set with setPen(), a default pen is returned. + */ QPen pen() const; /** * Set the custom pen to @p pen. */ void setPen(const QPen &pen); /** * @return the pen that has been set with setPen() */ QPen customPen() const; Q_SIGNALS: void updated(); }; } Q_DECLARE_OPERATORS_FOR_FLAGS(KGantt::DateTimeTimeLine::Options) #endif /* KGANTTDATETIMETIMELINE_H */ diff --git a/src/KGantt/kganttglobal.h b/src/KGantt/kganttglobal.h index 54028d5..d0676ad 100644 --- a/src/KGantt/kganttglobal.h +++ b/src/KGantt/kganttglobal.h @@ -1,324 +1,324 @@ /* * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. * * This file is part of the KGantt library. * * 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, see . */ /** \file kganttglobal.h \brief Contains KGantt macros. Contains KGantt macros. */ #ifndef KGANTTGLOBAL_H #define KGANTTGLOBAL_H #include #include #include #include #include "kgantt_export.h" #if (defined(__MINGW32__) || defined(__MINGW64__)) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 4) && (__GNUC_PATCHLEVEL__ == 0) // workaround a mingw bug, http://sourceforge.net/tracker/index.php?func=detail&aid=2373234&group_id=2435&atid=102435 int swprintf (wchar_t *, size_t, const wchar_t *, ...); int vswprintf(wchar_t *, const wchar_t *, va_list); #endif #ifndef KDAB_SET_OBJECT_NAME template inline T & __kdab__dereference_for_methodcall( T & o ) { return o; } template inline T & __kdab__dereference_for_methodcall( T * o ) { return *o; } #define KDAB_SET_OBJECT_NAME( x ) __kdab__dereference_for_methodcall( x ).setObjectName( QLatin1String( #x ) ) #endif #if defined(_MSC_VER) && _MSC_VER <= 1300 #define KGANTT_DECLARE_PRIVATE_DERIVED( X ) \ public: \ class Private; \ friend class Private; \ protected: \ inline Private * d_func(); \ inline const Private * d_func() const; \ explicit inline X( Private * ); \ private: \ void init(); #else #define KGANTT_DECLARE_PRIVATE_DERIVED( X ) \ protected: \ class Private; \ friend class Private; \ inline Private * d_func(); \ inline const Private * d_func() const; \ explicit inline X( Private * ); \ private: \ void init(); #endif #if defined(_MSC_VER) && _MSC_VER <= 1300 #define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ public: \ class Private; \ friend class Private; \ protected: \ inline Private * d_func(); \ inline const Private * d_func() const; \ explicit inline X( Private *, ParentType ); \ private: \ void init(); #else #define KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, ParentType ) \ protected: \ class Private; \ friend class Private; \ inline Private * d_func(); \ inline const Private * d_func() const; \ explicit inline X( Private *, ParentType ); \ private: \ void init(); #endif #define KGANTT_DECLARE_PRIVATE_DERIVED_QWIDGET( X ) \ KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( X, QWidget* ) #define KGANTT_DECLARE_PRIVATE_BASE_VALUE( X ) \ public: \ inline void swap( X & other ) { qSwap( _d, other._d ); } \ protected: \ class Private; \ friend class Private; \ Private * d_func() { return _d; } \ const Private * d_func() const { return _d; } \ private: \ void init(); \ Private * _d; #if defined(_MSC_VER) && _MSC_VER <= 1300 #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ public: \ class Private; \ friend class Private; \ protected: \ Private * d_func() { return _d; } \ const Private * d_func() const { return _d; } \ explicit inline X( Private * ); \ private: \ void init(); \ Private * _d; #else #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( X ) \ protected: \ class Private; \ friend class Private; \ Private * d_func() { return _d; } \ const Private * d_func() const { return _d; } \ explicit inline X( Private * ); \ private: \ void init(); \ Private * _d; #endif #if defined(_MSC_VER) && _MSC_VER <= 1300 #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ public: \ class Private; \ friend class Private; \ protected: \ Private * d_func() { return _d; } \ const Private * d_func() const { return _d; } \ explicit inline X( Private *, QWidget* ); \ private: \ void init(); \ Private * _d; #else #define KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET( X ) \ protected: \ class Private; \ friend class Private; \ Private * d_func() { return _d; } \ const Private * d_func() const { return _d; } \ explicit inline X( Private *, QWidget* ); \ private: \ void init(); \ Private * _d; #endif // enable this for testing if KD Gantt works without STL support in Qt: // // #define QT_NO_STL #include // qSwap #ifndef QT_NO_STL #include #define KGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ QT_BEGIN_NAMESPACE \ template <> inline void qSwap( X & lhs, X & rhs ) \ { lhs.swap( rhs ); } \ QT_END_NAMESPACE \ namespace std { \ template <> inline void swap( X & lhs, X & rhs ) \ { lhs.swap( rhs ); } \ } #else #define KGANTT_DECLARE_SWAP_SPECIALISATION( X ) \ QT_BEGIN_NAMESPACE \ template <> inline void qSwap( X & lhs, X & rhs ) \ { lhs.swap( rhs ); } \ QT_END_NAMESPACE #endif #define KGANTT_DECLARE_SWAP_SPECIALISATION_DERIVED( X ) \ KGANTT_DECLARE_SWAP_SPECIALISATION( X ) #define KGANTT_DECLARE_SWAP_BASE( X ) \ protected: \ void doSwap( X& other ) \ { qSwap( _d, other._d); } #define KGANTT_DECLARE_SWAP_DERIVED( X ) \ void swap( X& other ) { doSwap( other ); } #if defined(Q_OS_WIN) && defined(QT_DLL) #if defined(_MSC_VER) && _MSC_VER >= 1300 // workaround http://support.microsoft.com/default.aspx?scid=kb;en-us;309801 #include #include template class Q_DECL_IMPORT QVector; #endif #endif /*!\namespace KGantt *\ingroup KGantt *\brief Global namespace */ namespace KGantt { /*!\enum KGantt::ItemDataRole *\ingroup KGantt * The values of this enum are used for the special data roles * for gantt items */ enum ItemDataRole { - KGanttRoleBase = Qt::UserRole + 1174, /// * The base value used for the KGantt role enum values. The actual roles have values base+1, base+2, ... - StartTimeRole = KGanttRoleBase + 1, /// * Start time (or other start value) for a gantt item. - EndTimeRole = KGanttRoleBase + 2, /// * End time (or other end value) for a gantt item. - TaskCompletionRole = KGanttRoleBase + 3, /// * Task completetion percentage used by Task items. Should be an integer og a qreal between 0 and 100. - ItemTypeRole = KGanttRoleBase + 4, /// * The item type. \see KGantt::ItemType. - LegendRole = KGanttRoleBase + 5, - TextPositionRole = KGanttRoleBase + 6 /// * The position of the text label on the item. The type of this value is KGantt::StyleOptionGanttItem::Position and the default values is Right. + KGanttRoleBase = Qt::UserRole + 1174, ///< The base value used for the KGantt role enum values. The actual roles have values base+1, base+2, ... + StartTimeRole = KGanttRoleBase + 1, ///< Start time (or other start value) for a gantt item. + EndTimeRole = KGanttRoleBase + 2, ///< End time (or other end value) for a gantt item. + TaskCompletionRole = KGanttRoleBase + 3, ///< Task completetion percentage used by Task items. Should be an integer og a qreal between 0 and 100. + ItemTypeRole = KGanttRoleBase + 4, ///< The item type. \see KGantt::ItemType. + LegendRole = KGanttRoleBase + 5, ///< The Legend text + TextPositionRole = KGanttRoleBase + 6 ///< The position of the text label on the item. The type of this value is KGantt::StyleOptionGanttItem::Position and the default values is Right. }; /*!\enum KGantt::ItemType *\ingroup KGantt * The values of this enum are used to represent the different * types of gantt items that KGantt understands. The itemtype * is served through the KGantt::ItemTypeRole role */ enum ItemType { TypeNone = 0, TypeEvent = 1, TypeTask = 2, TypeSummary = 3, TypeMulti = 4, TypeUser = 1000 }; /*!\class KGantt::Span kganttglobal.h KGanttGlobal *\ingroup KGantt * \brief A class representing a start point and a length */ class Span { qreal m_start; qreal m_length; public: inline Span() : m_start( -1 ), m_length( 0 ) {} inline Span( qreal start, qreal length ) : m_start( start ), m_length( length ) {} inline Span( const Span& other ) : m_start(other.m_start), m_length(other.m_length) {} inline Span& operator=( const Span& other ) { m_start=other.m_start; m_length=other.m_length; return *this; } inline void setStart( qreal start ) { m_start=start; } inline qreal start() const { return m_start; } inline void setEnd( qreal end ) { m_length = m_start-end; } inline qreal end() const { return m_start+m_length; } inline void setLength( qreal length ) { m_length=length; } inline qreal length() const { return m_length; } inline bool isValid() const { return m_start >= 0.;} inline bool equals( const Span& other ) const { return m_start == other.m_start && m_length == other.m_length; } inline Span expandedTo( const Span& other) const { const qreal new_start = qMin(start(),other.start()); return Span( new_start, (end()