]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/delegate.h
Bump copyright years.
[toast/confclerk.git] / src / mvc / delegate.h
index 269e35eb58ef2e84f6fc4d1124d8367abac0b25e..83c591d85eda570b660441791e1d4bd14f8d43c1 100644 (file)
@@ -1,9 +1,31 @@
+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl
+ *
+ * This file is part of ConfClerk.
+ *
+ * ConfClerk 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.
+ *
+ * ConfClerk 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
+ * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
+ */
 #ifndef DELEGATE_H
 #define DELEGATE_H
 
-#include <QItemDelegate>
-#include <QTreeView>
-#include <QPointer>
+#include "qglobal.h"
+#if QT_VERSION >= 0x050000
+#include <QtWidgets>
+#else
+#include <QtGui>
+#endif
 
 class Delegate : public QItemDelegate
 {
@@ -14,25 +36,30 @@ class Delegate : public QItemDelegate
         enum ControlId
         {
             ControlNone = 0,
-            FavouriteControlOn,
-            FavouriteControlOff,
+            FavouriteControlStrong,
+            FavouriteControlWeak,
+            FavouriteControlNo,
             AlarmControlOn,
             AlarmControlOff,
-            MapControl,
-            WarningControlOn,
-            WarningControlOff
+            WarningControl
         };
 
         class Control
         {
             public:
-                Control(ControlId aControlId, const QString &aImageName)
-                    : mId(aControlId)
-                    , mImage(new QImage(aImageName))
-                    , mDrawPoint(QPoint(0,0))
-                { }
+                Control(ControlId aControlId, const QString &aImageName, const Control* prev_control);
+
                 inline QImage *image() const { return mImage; }
                 inline void setDrawPoint(const QPoint &aPoint) { mDrawPoint = aPoint; }
+                inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
+                {
+                    return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
+                }
+                void paint(QPainter* painter, const QRect rect);
+
+                bool enabled() const { return mEnabled; }
+                void setEnabled(bool v) { mEnabled = v; }
+            private:
                 inline QPoint drawPoint(const QRect &aRect = QRect()) const // for painter to draw Control
                 {
                     if(aRect == QRect()) // null rectangle
@@ -40,14 +67,11 @@ class Delegate : public QItemDelegate
                     else
                         return QPoint(aRect.x()+aRect.width(),aRect.y()) + mDrawPoint; // returns absolute drawing point
                 }
-                inline QRect drawRect(const QRect &aRect) const // helper for determining if Control was clicked
-                {
-                    return QRect(drawPoint(aRect), drawPoint(aRect)+QPoint(mImage->size().width(),mImage->size().height()));
-                }
-            private:
+
                 ControlId mId;
                 QImage *mImage;
                 QPoint mDrawPoint; // relative 'start-drawing' position (may hold negative values)
+                bool mEnabled;
         };
 
         Delegate(QTreeView *aParent); // the delegate 'owner' has to be specified in the constructor - it's used to obtain visualRect of selected item/index
@@ -66,10 +90,10 @@ class Delegate : public QItemDelegate
         void defineControls();
         // TODO: the better place for these methods would be 'eventmodel'
         // they are used in 'paint' method and so it's better to obtain number of
-        // favourities/alarms once when the data has changed and not to call
+        // favourites/alarms once when the data has changed and not to call
         // these methods which iterate over all Events in corresponding group
         // every time it requires them
-        int numberOfFavourities(const QModelIndex &index) const;
+        int numberOfFavourites(const QModelIndex &index) const;
         int numberOfAlarms(const QModelIndex &index) const;
 
     private: