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 \brief Initializes a QLabel to explain difficult things of dialogs.
54
55 The label should be used to explain difficult things of the GUI, e.g. in the
56 options dialog pages.
57
58 \param[in] label The label to initialize
59 \param[in] heading The heading for the label.
60 \param[in] text The text for the label.
61*/
62void initExplanationLabel(QLabel * label,
63 const QString & heading,
64 const QString & text);
65
66/**
67 \returns whether the character at position "pos" of text is inside an HTML tag.
68*/
69bool inHTMLTag(int pos, const QString & text);
70
71/**
72 \brief Calculates a maximum rendered text width for a widget and a string with
73 the a given length.
74
75 This function can be used for setting the size for a widget. It may be better
76 to roughly calculate the size based on some text width rather than use a hard-
77 coded value.
78
79 \param[in] widget the widget whose font metrics to use.
80 \param[in] mCount the length of the string of 'M' characters to use for
81 calculating the width.
82
83 \returns the width in pixels.
84*/
85int mWidth(QWidget const & widget, int const mCount);
86
87/**
88 \param[in] input The potentially invalid BCP 47 string from Sword to fix.
89 \returns a string (hopefully) more conformant to BCP 47
90 */
91QString fixSwordBcp47(QString input);
92
93} /* namespace tool { */
94} /* namespace util { */
QString fixSwordBcp47(QString input)
Definition tool.cpp:120
void initExplanationLabel(QLabel *const label, const QString &heading, const QString &text)
Initializes a QLabel to explain difficult things of dialogs.
Definition tool.cpp:78
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:117
bool savePlainFile(const QString &filename, void(&writer)(QTextStream &, void *), void *userPtr)
Definition tool.cpp:33
bool inHTMLTag(const int pos, const QString &text)
Definition tool.cpp:99