1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, http://www.bibletime.info/.
6 *
7 * Copyright 1999-2016 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License version 2.0.
9 *
10 **********/
11 
12 #ifndef TOOL_H
13 #define TOOL_H
14 
15 #include <QIcon>
16 #include <QString>
17 #include <QTextCodec>
18 
19 
20 class CSwordModuleInfo;
21 class QLabel;
22 class QWidget;
23 
24 namespace util {
25 namespace tool {
26 
27 /**
28   Creates the file filename and save the given text into the file.
29 
30   \param[in] filename the filename to save to.
31   \param[in] text the string data to save.
32   \param[in] forceOverwrite whether to force the overwrite.
33   \param[in] fileCodec the codec to use to save the given string data.
34   \note if the file exists, and forceOverwrite is false, a confirmation dialog
35         is shown to ask the user whether to overwrite the existing file.
36   \returns whether the file was properly saved.
37 */
38 bool savePlainFile(const QString & filename,
39                    const QString & text,
40                    bool forceOverwrite = false,
41                    QTextCodec * fileCodec = QTextCodec::codecForLocale());
42 
43 /**
44   \param[in] module the module whose icon to return.
45   \returns the icon used for the a module.
46 */
47 QIcon const & getIconForModule(const CSwordModuleInfo * module);
48 
49 /**
50   Creates a new explanation label.
51 
52   \param[in] parent the parent widget.
53   \param[in] heading the heading of the label.
54   \param[in] text the text of the label.
55   \returns a new QLabel initialized by initExplanationLabel().
56 */
57 QLabel * explanationLabel(QWidget * parent,
58                           const QString & heading,
59                           const QString & text);
60 
61 /**
62   \brief Initializes a QLabel to explain difficult things of dialogs.
63 
64   The label should be used to explain difficult things of the GUI, e.g. in the
65   options dialog pages.
66 
67   \param[in] label The label to initialize
68   \param[in] heading The heading for the label.
69   \param[in] text The text for the label.
70 */
71 void initExplanationLabel(QLabel * label,
72                           const QString & heading,
73                           const QString & text);
74 
75 /**
76   \returns whether the character at position "pos" of text is inside an HTML tag.
77 */
78 bool inHTMLTag(int pos, const QString & text);
79 
80 /**
81   \param[in] module The module required for the tooltip
82   \returns the remote module's tooltip text.
83 */
84 QString remoteModuleToolTip(const CSwordModuleInfo & module,
85                             const QString & localVer);
86 
87 /**
88   \brief Calculates a maximum rendered text width for a widget and a string with
89          the a given length.
90 
91   This function can be used for setting the size for a widget. It may be better
92   to roughly calculate the size based on some text width rather than use a hard-
93   coded value.
94 
95   \param[in] widget the widget whose font metrics to use. If 0, then the font
96                     metrics of the application are used.
97   \param[in] mCount the length of the string of 'M' characters to use for
98                     calculating the width.
99 
100   \returns the width in pixels.
101 */
102 int mWidth(const QWidget * widget, int mCount);
103 
104 } /* namespace tool { */
105 } /* namespace util { */
106 
107 #endif
108