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

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Carsten Niehaus <cniehaus@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef KALZIUMUTILS_H
0007 #define KALZIUMUTILS_H
0008 
0009 class QString;
0010 class QRect;
0011 class QFont;
0012 class QPainter;
0013 class Element;
0014 
0015 #include <QComboBox>
0016 #include <chemicaldataobject.h>
0017 
0018 class KalziumUtils
0019 {
0020 public:
0021     /**
0022      * @param string the string which is measured
0023      * @param rect the rect needed for measurement
0024      * @param font the used font
0025      * @param painter the used painter
0026      * @param maxFontSize the maximum fontsize
0027      * @param minFontSize the maximum fontsize
0028      */
0029     static int maxSize(const QString &string, const QRect &rect, QFont font, QPainter *painter, int minFontSize = 4, int maxFontSize = 20);
0030 
0031     /**
0032      * calculate the 4-digit value of the value @p w. For
0033      * example, 12.3456 will be returned as 12.35
0034      * @param value the value which will be stripped
0035      * @return the 4-digit value
0036      */
0037     static double strippedValue(double value);
0038 
0039     /**
0040      * @param string the string which is measured
0041      * @param font the used font
0042      * @param painter the used painter
0043      * @return the width of the string @p string
0044      */
0045     static int StringWidth(const QString &string, const QFont &font, QPainter *painter);
0046     /**
0047      * @param string the string which is measured
0048      * @param font the used font
0049      * @param painter the used painter
0050      * @return the height of the string @p string
0051      */
0052     static int StringHeight(const QString &string, const QFont &font, QPainter *painter);
0053 
0054     /**
0055      * An almost standard way to get an unit well converted for
0056      * displaying including (eventual) unit.
0057      * @param el the element
0058      * @param kind the unit we want to print of the element @p el
0059      * @return the formatted string
0060      */
0061     static QString prettyUnit(const Element *el, ChemicalDataObject::BlueObelisk kind);
0062 
0063     /**
0064      * Populates a combobox with the names of the units. @see KUnitConversion.
0065      * @param combobox the pointer to the combobox
0066      * @param unitList Unit list with enums of KUnitConversion
0067      */
0068     static void populateUnitCombobox(QComboBox *comboBox, const QList<int> &unitList);
0069 };
0070 
0071 #endif // KALZIUMUTILS_H