File indexing completed on 2022-12-06 18:52:21

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Pino Toscano <toscano.pino@tiscali.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KALZIUMSCHEMETYPE_H
0008 #define KALZIUMSCHEMETYPE_H
0009 
0010 class KalziumSchemeType;
0011 
0012 #include "kalziumgradienttype.h"
0013 
0014 #include <config-kalzium.h>
0015 
0016 #include <QBrush>
0017 #include <QByteArray>
0018 #include <QColor>
0019 #include <QPair>
0020 #include <QRect>
0021 
0022 using legendPair = QPair<QString, QColor>;
0023 
0024 /**
0025  * Factory for KalziumSchemeType classes.
0026  *
0027  * @author Pino Toscano
0028  */
0029 class KalziumSchemeTypeFactory
0030 {
0031 public:
0032     /**
0033      * Get the instance of this factory.
0034      */
0035     static KalziumSchemeTypeFactory *instance();
0036 
0037     /**
0038      * Returns the KalziumSchemeType with the @p id specified.
0039      * It will gives 0 if none found.
0040      */
0041     KalziumSchemeType *build(int id) const;
0042     /**
0043      * Returns the KalziumSchemeType whose name is the @p id
0044      * specified.
0045      * It will gives 0 if none found.
0046      */
0047     KalziumSchemeType *build(const QByteArray &id) const;
0048 
0049     /**
0050      * Returns a list with the names of the schemes we support.
0051      */
0052     QStringList schemes() const;
0053 
0054 private:
0055     KalziumSchemeTypeFactory();
0056     QList<KalziumSchemeType *> m_schemes;
0057 };
0058 
0059 /**
0060  * This is the base class representing a colour scheme.
0061  *
0062  * @author Pino Toscano
0063  */
0064 class KalziumSchemeType
0065 {
0066 public:
0067     /**
0068      * Get its instance.
0069      */
0070     static KalziumSchemeType *instance();
0071 
0072     virtual ~KalziumSchemeType();
0073 
0074     /**
0075      * Returns the ID of this scheme.
0076      * Mainly used when saving/loading.
0077      */
0078     virtual QByteArray name() const = 0;
0079     /**
0080      * Returns the description of this scheme.
0081      * Used in all the visible places.
0082      */
0083     virtual QString description() const = 0;
0084 
0085     /**
0086      * Returns the brush with which the element with number
0087      * @p el should be painted.
0088      *
0089      * @param el Element number
0090      * @param elrect is the rect designed for the element
0091      *
0092      * @return A brush for painting in @p elrect
0093      */
0094     virtual QBrush elementBrush(int el) const = 0;
0095     /**
0096      * Returns the color which will be used to draw the texts for
0097      * the element with atomic number @p el.
0098      */
0099     virtual QColor textColor(int el) const = 0;
0100 
0101     /**
0102      * Returns a list with the legend of the current scheme.
0103      */
0104     virtual QList<legendPair> legendItems() const = 0;
0105 
0106 protected:
0107     KalziumSchemeType();
0108 };
0109 
0110 /**
0111  * Class representing the all-one-colour scheme.
0112  *
0113  * @author Pino Toscano
0114  */
0115 class KalziumMonoColorSchemeType : public KalziumSchemeType
0116 {
0117 public:
0118     static KalziumMonoColorSchemeType *instance();
0119 
0120     QByteArray name() const override;
0121     QString description() const override;
0122 
0123     QBrush elementBrush(int el) const override;
0124     QColor textColor(int el) const override;
0125 
0126     QList<legendPair> legendItems() const override;
0127 
0128 private:
0129     KalziumMonoColorSchemeType();
0130 };
0131 
0132 /**
0133  * The scheme by element block.
0134  *
0135  * @author Pino Toscano
0136  */
0137 class KalziumBlocksSchemeType : public KalziumSchemeType
0138 {
0139 public:
0140     static KalziumBlocksSchemeType *instance();
0141 
0142     QByteArray name() const override;
0143     QString description() const override;
0144 
0145     QBrush elementBrush(int el) const override;
0146     QColor textColor(int el) const override;
0147 
0148     QList<legendPair> legendItems() const override;
0149 
0150 private:
0151     KalziumBlocksSchemeType();
0152 };
0153 
0154 /**
0155  * The scheme for iconic representation.
0156  *
0157  * @author Carsten Niehaus
0158  */
0159 class KalziumIconicSchemeType : public KalziumSchemeType
0160 {
0161 public:
0162     static KalziumIconicSchemeType *instance();
0163 
0164     QByteArray name() const override;
0165     QString description() const override;
0166 
0167     QBrush elementBrush(int el) const override;
0168     QColor textColor(int el) const override;
0169 
0170     QList<legendPair> legendItems() const override;
0171 
0172 private:
0173     KalziumIconicSchemeType();
0174 };
0175 
0176 /**
0177  * The scheme for family representation.
0178  *
0179  * @author Carsten Niehaus
0180  */
0181 class KalziumFamilySchemeType : public KalziumSchemeType
0182 {
0183 public:
0184     static KalziumFamilySchemeType *instance();
0185 
0186     QByteArray name() const override;
0187     QString description() const override;
0188 
0189     QBrush elementBrush(int el) const override;
0190     QColor textColor(int el) const override;
0191 
0192     QList<legendPair> legendItems() const override;
0193 
0194 private:
0195     KalziumFamilySchemeType();
0196 };
0197 
0198 /**
0199  * The scheme for groups representation.
0200  *
0201  * @author Carsten Niehaus
0202  */
0203 class KalziumGroupsSchemeType : public KalziumSchemeType
0204 {
0205 public:
0206     static KalziumGroupsSchemeType *instance();
0207 
0208     QByteArray name() const override;
0209     QString description() const override;
0210 
0211     QBrush elementBrush(int el) const override;
0212     QColor textColor(int el) const override;
0213 
0214     QList<legendPair> legendItems() const override;
0215 
0216 private:
0217     KalziumGroupsSchemeType();
0218 };
0219 
0220 #ifdef HAVE_OPENBABEL
0221 /**
0222  * The scheme for color
0223  *
0224  * @author Etienne Rebetez
0225  */
0226 class KalziumColorSchemeType : public KalziumSchemeType
0227 {
0228 public:
0229     static KalziumColorSchemeType *instance();
0230 
0231     QByteArray name() const override;
0232     QString description() const override;
0233 
0234     QBrush elementBrush(int el) const override;
0235     QColor textColor(int el) const override;
0236 
0237     QList<legendPair> legendItems() const override;
0238 
0239 private:
0240     KalziumColorSchemeType();
0241 };
0242 #endif
0243 
0244 // X /**
0245 // X  * The scheme for the crystal structures.
0246 // X  *
0247 // X  * @author Carsten Niehaus
0248 // X  */
0249 // X class KalziumCrystalSchemeType : public KalziumSchemeType
0250 // X {
0251 // X     public:
0252 // X         static KalziumCrystalSchemeType* instance();
0253 // X
0254 // X         QByteArray name() const;
0255 // X         QString description() const;
0256 // X
0257 // X         QBrush elementBrush(int el, const QRect& elrect) const;
0258 // X         QColor textColor(int el) const;
0259 // X
0260 // X         QList<legendPair> legendItems() const;
0261 // X
0262 // X     private:
0263 // X         KalziumCrystalSchemeType();
0264 // X };
0265 
0266 // X /**
0267 // X  * @author Carsten Niehaus
0268 // X  */
0269 // X class KalziumDiscoverymapSchemeType : public KalziumSchemeType
0270 // X {
0271 // X     public:
0272 // X         static KalziumDiscoverymapSchemeType* instance();
0273 // X
0274 // X         QByteArray name() const;
0275 // X         QString description() const;
0276 // X
0277 // X         QBrush elementBrush(int el, const QRect& elrect) const;
0278 // X         QColor textColor(int el) const;
0279 // X
0280 // X         QList<legendPair> legendItems() const;
0281 // X
0282 // X     private:
0283 // X         KalziumDiscoverymapSchemeType();
0284 // X };
0285 
0286 #endif // KALZIUMSCHEMETYPE_H