Test change - can I push OK?
[kdeedu-porting.git] / kalzium / src / kalziumtabletype.h
blob8eadf760303aa5e038c44d17563bf9ade7ec8012
1 /***************************************************************************
2 * Copyright (C) 2005, 2006 by Pino Toscano, toscano.pino@tiscali.it *
3 * Copyright (C) 2007 by Carste Niehaus, cniehaus@kde.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef KALZIUMTABLETYPE_H
22 #define KALZIUMTABLETYPE_H
24 class KalziumNumerationType;
25 class KalziumTableType;
27 #include <QByteArray>
28 #include <QPoint>
29 #include <QRect>
30 #include <QSize>
31 #include <QStringList>
33 /**
34 * Factory for KalziumTableType classes.
36 * @author Pino Toscano
38 class KalziumTableTypeFactory
40 public:
41 /**
42 * Get the instance of this factory.
44 static KalziumTableTypeFactory* instance();
46 /**
47 * Returns the KalziumTableType with the @p id specified.
48 * It will gives 0 if none found.
50 KalziumTableType* build( int id ) const;
52 /**
53 * Returns the KalziumTableType whose name is the @p id
54 * specified.
55 * It will gives 0 if none found.
57 KalziumTableType* build( const QByteArray& id ) const;
59 /**
60 * Returns a list with the names of the table types we support.
62 QStringList tables() const;
63 private:
64 KalziumTableTypeFactory();
66 QList<KalziumTableType*> m_tables;
69 /**
70 * This is one of the most important classes. It represents a table type, with
71 * all its attributes and metrics.
73 * @author Pino Toscano
75 class KalziumTableType
77 public:
78 /**
79 * Get its instance.
81 static KalziumTableType* instance();
83 virtual ~KalziumTableType();
85 /**
86 * Returns the ID of this table type.
87 * Mainly used when saving/loading.
89 virtual QByteArray name() const = 0;
90 /**
91 * Returns the description of this table type.
92 * Used in all the visible places.
94 virtual QString description() const = 0;
96 /**
97 * Returns the size of this table type.
99 virtual QSize size() const = 0;
102 * @return the number of the element at the coordinates @p coords.
103 * If there is no element it will return 0.
104 * For example, for Carbon "6" will be returned
106 virtual int elementAtCoords( const QPoint& coords ) const = 0;
108 * Returns the rect for the element with atomic number @p numelem.
110 virtual QRect elementRect( const int numelem ) const = 0;
113 * Returns the rect for the @p numelement 'th item of the
114 * numeration @p nt.
116 virtual QRect numerationRect( const int numelem, KalziumNumerationType *nt ) const;
119 * Returns the element that comes right before the specified @p element.
120 * -1 means that @p element is the first in this table type.
122 * The default implementation returns <tt>element - 1</tt> if @p element
123 * is not 1, else -1.
125 virtual int previousOf( int element ) const;
128 * Returns the element that comes right after the specified @p element.
129 * -1 means that @p element is the last in this table type.
131 * The default implementation returns <tt>element + 1</tt> if @p element
132 * is not the latest element, else -1.
134 virtual int nextOf( int element ) const;
137 * Returns the first element of the table.
139 * The default implementation returns 1.
141 virtual int firstElement() const;
144 * @return the list of elements the specific KalziumTableType displays
146 virtual QList<int> elementList() const;
148 protected:
149 KalziumTableType();
152 * This QList stores the numbers of the elements the table will display
154 QList<int> m_elementList;
157 * @return the coordinates of the element under the point
158 * @p coords.
159 * For example, H will be 1/1 and Li will be 1/2
161 QPoint elementUnderMouse( const QPoint& coords ) const;
165 * The class representing the "classic" periodic table, and its metrics.
167 * @author Pino Toscano
169 class KalziumClassicTableType : public KalziumTableType
171 public:
172 static KalziumClassicTableType* instance();
174 QByteArray name() const;
175 QString description() const;
177 QSize size() const;
179 int elementAtCoords( const QPoint& coords ) const;
180 QRect elementRect( const int numelem ) const;
182 private:
183 KalziumClassicTableType();
187 * The class representing the "short" periodic table, and its metrics.
189 * @author Carsten Niehaus
191 class KalziumShortTableType : public KalziumTableType
193 public:
194 static KalziumShortTableType* instance();
196 QByteArray name() const;
197 QString description() const;
199 QSize size() const;
201 int elementAtCoords( const QPoint& coords ) const;
202 QRect elementRect( const int numelem ) const;
204 int previousOf( int element ) const;
205 int nextOf( int element ) const;
207 private:
208 KalziumShortTableType();
211 * @return The number of the element in this scheme. As we skip
212 * the d- and f-block, for example element 31 is infact the 21st
213 element in this scheme (because elements 21 to 30 are skipped)
215 static int translateToShort(int num);
219 * The class representing the d-Block of the periodic table, and its metrics.
221 * @author Carsten Niehaus
223 class KalziumDTableType : public KalziumTableType
225 public:
226 static KalziumDTableType* instance();
228 QByteArray name() const;
229 QString description() const;
231 QSize size() const;
233 int elementAtCoords( const QPoint& coords ) const;
234 QRect elementRect( const int numelem ) const;
236 int previousOf( int element ) const;
237 int nextOf( int element ) const;
239 int firstElement() const;
241 private:
242 KalziumDTableType();
245 * @return The number of the element in this scheme. As we skip
246 * the s-, p and f-block, for example element 1st is infact the 21st
247 element in this scheme
249 static int translateToD(int num);
253 * This class represents the table the DZ (Deutscher Zentralausschuss, "German Central Comitee")
254 * suggests.
256 * @author Carsten Niehaus
258 class KalziumDZTableType : public KalziumTableType
260 public:
261 static KalziumDZTableType* instance();
263 QByteArray name() const;
264 QString description() const;
266 QSize size() const;
268 int elementAtCoords( const QPoint& coords ) const;
269 QRect elementRect( const int numelem ) const;
271 private:
272 KalziumDZTableType();
275 #endif // KALZIUMTABLETYPE_H