BibleTime
tool.h
Go to the documentation of this file.
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, https://bibletime.info/
6*
7* Copyright 1999-2025 by the BibleTime developers.
8* The BibleTime source code is licensed under the GNU General Public License
9* version 2.0.
10*
11**********/
12
13#pragma once
14
15#include <QString>
16
17
19class QIcon;
20class QLabel;
21class QTextStream;
22class QWidget;
23
24namespace util {
25namespace tool {
26
27/**
28 Creates the file filename and writes to it using a callback..
29
30 \param[in] filename the filename to save to.
31 \param[in] writer the writer callback.
32 \param[in] userPtr arbitrary data passed on to the callback.
33 \param[in] fileCodec the codec to use to save the given string data.
34 \warning if a file with the given name already exists, it is first removed.
35 \returns whether the file was properly saved.
36*/
37bool savePlainFile(QString const & filename,
38 void (&writer)(QTextStream &, void *),
39 void * userPtr);
40
41/**
42 Creates the file filename and save the given text into the file.
43
44 \param[in] filename the filename to save to.
45 \param[in] text the string data to save.
46 \param[in] fileCodec the codec to use to save the given string data.
47 \warning if a file with the given name already exists, it is first removed.
48 \returns whether the file was properly saved.
49*/
50bool savePlainFile(QString const & filename, QString const & text);
51
52/**
53 \param[in] module the module whose icon to return.
54 \returns the icon used for the a module.
55*/
56QIcon const & getIconForModule(const CSwordModuleInfo * module);
57
58/**
59 \brief Initializes a QLabel to explain difficult things of dialogs.
60
61 The label should be used to explain difficult things of the GUI, e.g. in the
62 options dialog pages.
63
64 \param[in] label The label to initialize
65 \param[in] heading The heading for the label.
66 \param[in] text The text for the label.
67*/
68void initExplanationLabel(QLabel * label,
69 const QString & heading,
70 const QString & text);
71
72/**
73 \returns whether the character at position "pos" of text is inside an HTML tag.
74*/
75bool inHTMLTag(int pos, const QString & text);
76
77/**
78 \brief Calculates a maximum rendered text width for a widget and a string with
79 the a given length.
80
81 This function can be used for setting the size for a widget. It may be better
82 to roughly calculate the size based on some text width rather than use a hard-
83 coded value.
84
85 \param[in] widget the widget whose font metrics to use.
86 \param[in] mCount the length of the string of 'M' characters to use for
87 calculating the width.
88
89 \returns the width in pixels.
90*/
91int mWidth(QWidget const & widget, int const mCount);
92
93/**
94 \param[in] input The potentially invalid BCP 47 string from Sword to fix.
95 \returns a string (hopefully) more conformant to BCP 47
96 */
97QString fixSwordBcp47(QString input);
98
99} /* namespace tool { */
100} /* namespace util { */
QString fixSwordBcp47(QString input)
Definition tool.cpp:158
void initExplanationLabel(QLabel *const label, const QString &heading, const QString &text)
Initializes a QLabel to explain difficult things of dialogs.
Definition tool.cpp:116
int mWidth(QWidget const &widget, int const mCount)
Calculates a maximum rendered text width for a widget and a string with the a given length.
Definition tool.cpp:155
bool savePlainFile(const QString &filename, void(&writer)(QTextStream &, void *), void *userPtr)
Definition tool.cpp:35
bool inHTMLTag(const int pos, const QString &text)
Definition tool.cpp:137
QIcon const & getIconForModule(const CSwordModuleInfo *const module)
Definition tool.cpp:80