File indexing completed on 2022-09-27 12:24:11

0001 /*
0002     SPDX-FileCopyrightText: 2010 Etienne Rebetez <etienne.rebetez@oberwallis.ch>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KALZIUMELEMENTPROPERTY_H
0008 #define KALZIUMELEMENTPROPERTY_H
0009 
0010 #include <QBrush>
0011 
0012 #include "kalziumgradienttype.h"
0013 #include "kalziumschemetype.h"
0014 
0015 /**
0016  * The logic of the scheme and the gradients is merged in this class. It provides
0017  * an API to set the gradient and scheme without worrying about the real id's.
0018  * Elements can then get their properties with the element functions.
0019  * Here is also the place where the gradientslider is evaluated. (see gradientwidget)
0020  * @short This class holds the logic of the appearance from the periodic table
0021  * @author Etienne Rebetez
0022  */
0023 
0024 class KalziumElementProperty : public QObject
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     /**
0030      * Get the instance of this factory.
0031      */
0032     static KalziumElementProperty *instance();
0033 
0034     enum ELEMENTTEXTINFORMATIONMODE {
0035         NORMAL = 0, // Only Symbol Number
0036         ELNUMBER,
0037         GRADIENTVALUE
0038     };
0039 
0040     enum SPECIALGRADIENTYPDEF { NOGRADIENT = 0, SOMGradientType = 1, DISCOVERYDATE = 9 };
0041 
0042     /**
0043      * all available schemes. Can be used to populate menus.
0044      */
0045     QStringList schemeList() const;
0046     /**
0047      * all available gradients. Can be used to populate menus.
0048      */
0049     QStringList gradientList() const;
0050 
0051     /**
0052      * Returns the current scheme id as int. Equivalent to the scheme list.
0053      */
0054     int schemeId() const;
0055     /**
0056      * Returns the current gradient id as int. Equivalent to the gradient list.
0057      */
0058     int gradientId() const;
0059 
0060     /**
0061      * Returns the current real KalziumSchemeType class
0062      */
0063     KalziumSchemeType *scheme() const;
0064     /**
0065      * Returns the current real KalziumGradientType class
0066      */
0067     KalziumGradientType *gradient() const;
0068 
0069     /**
0070      * This is an element function.
0071      * It returns the Brush (Background) for the given element.
0072      * It uses the color form getElementColor.
0073      * @param el Number of the element.
0074      */
0075     QBrush getElementBrush(int el);
0076     /**
0077      * This is an element function.
0078      * It returns the Color (Background) for the given element.
0079      * @param el Number of the element.
0080      */
0081     QColor getElementColor(int el);
0082     /**
0083      * This is an element function.
0084      * It returns the Text color for the given element.
0085      * @param el Number of the element.
0086      */
0087     QColor getTextColor(int el) const;
0088     /**
0089      * This is an element function.
0090      * It returns the border color of the for the given element.
0091      * @param el Number of the element.
0092      */
0093     QColor getBorderColor(int el) const;
0094 
0095     /**
0096      * This is an element function.
0097      * It returns the value from the current gradient type for the given element.
0098      * @param el Number of the element.
0099      */
0100     double getValue(int el) const;
0101 
0102     /**
0103      * This is an element function.
0104      * The mode returns the enum ELEMENTTEXTINFORMATIONMODE.
0105      * The mode is used to differ different layouts in the elementitem.
0106      */
0107     int getMode() const;
0108 
0109 Q_SIGNALS:
0110     /**
0111      * Is emitted every time a property (scheme, gradient, ...) is changed.
0112      * all elements will be redrawn.
0113      */
0114     void propertyChanged();
0115 
0116 public Q_SLOTS:
0117     /**
0118      * gets the value from the gradientwidget. The value which is used to
0119      * determine if an element is active or not.
0120      * @param slide value of the current gradient
0121      */
0122     void setSliderValue(double slide);
0123     /**
0124      * sets the new scheme
0125      */
0126     void setScheme(int newScheme);
0127     /**
0128      * sets the new gradient
0129      */
0130     void setGradient(int newGradient);
0131 
0132 private:
0133     KalziumElementProperty();
0134     ~KalziumElementProperty() override;
0135 
0136     bool isGradient();
0137 
0138     QColor gradientBrushLogic(int el) const;
0139 
0140     int m_currentScheme;
0141     int m_currentGradient;
0142 
0143     double m_slider;
0144     int m_mode;
0145 };
0146 
0147 #endif // KALZIUMELEMENTPROPERTY_H