BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
widgetutils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/view/mvvm/widgets/widgetutils.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_VIEW_MVVM_WIDGETS_WIDGETUTILS_H
16 #define BORNAGAIN_MVVM_VIEW_MVVM_WIDGETS_WIDGETUTILS_H
17 
18 #include "mvvm/view_export.h"
19 #include <QString>
20 #include <QStringList>
21 #include <string>
22 #include <vector>
23 
24 class QColor;
25 class QSize;
26 class QMainWindow;
27 class QLabel;
28 
29 namespace ModelView {
30 
31 //! Collection of various widget-related utils.
32 
33 namespace Utils {
34 
35 //! Returns random color.
36 MVVM_VIEW_EXPORT QColor RandomColor();
37 
38 //! Returns the name of random color.
39 MVVM_VIEW_EXPORT std::string RandomNamedColor();
40 
41 //! Returns true if it is Windows.
42 MVVM_VIEW_EXPORT bool IsWindowsHost();
43 
44 //! Returns true if it is Mac.
45 MVVM_VIEW_EXPORT bool IsMacHost();
46 
47 //! Returns true if it is Linux.
48 MVVM_VIEW_EXPORT bool IsLinuxHost();
49 
50 //! Returns a string where Linux path to the file is striped using '~/'.
51 MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString& path);
52 
53 //! Returns a title composed from last part of project path, and `is_modified` flag.
54 MVVM_VIEW_EXPORT QString ProjectWindowTitle(const QString& project_dir, bool is_modified);
55 
56 //! Returns width of the letter 'M' deduced from current font metrics.
57 MVVM_VIEW_EXPORT int WidthOfLetterM();
58 
59 //! Returns height of the letter 'M' deduced from current font metrics.
60 MVVM_VIEW_EXPORT int HeightOfLetterM();
61 
62 //! Returns size corresponding to actual size of letter `M` basing on current font metrics.
63 MVVM_VIEW_EXPORT QSize SizeOfLetterM();
64 
65 //! Returns size in points of default system font.
66 MVVM_VIEW_EXPORT int SystemPointSize();
67 
68 //! Finds main window.
69 MVVM_VIEW_EXPORT QMainWindow* FindMainWindow();
70 
71 //! Returns text wrapped into 'href' tag to provide clickable links in QLabel.
72 //! Example: <a href="tag">text</a>, if 'tag' is empty, 'text' will be used instead.
73 MVVM_VIEW_EXPORT QString ClickableText(const QString& text, const QString& tag = {});
74 
75 //! Set label's font size to system font size scaled by given factor.
76 MVVM_VIEW_EXPORT void ScaleLabelFont(QLabel* label, double scale);
77 
78 //! Converts vector of strings to QStringList.
79 MVVM_VIEW_EXPORT QStringList toStringList(const std::vector<std::string>& vec);
80 
81 //! Converts vector of strings to QStringList.
82 MVVM_VIEW_EXPORT std::vector<std::string> fromStringList(const QStringList& string_list);
83 
84 //! Converts vector of strings to byte array.
85 MVVM_VIEW_EXPORT QByteArray serialize(const QStringList& data);
86 
87 //! Converts byte array to vector of strings.
88 MVVM_VIEW_EXPORT QStringList deserialize(const QByteArray& byteArray);
89 
90 } // namespace Utils
91 
92 } // namespace ModelView
93 
94 #endif // BORNAGAIN_MVVM_VIEW_MVVM_WIDGETS_WIDGETUTILS_H
MVVM_VIEW_EXPORT std::string RandomNamedColor()
Returns the name of random color.
Definition: widgetutils.cpp:47
MVVM_VIEW_EXPORT int HeightOfLetterM()
Returns height of the letter 'M' deduced from current font metrics.
MVVM_VIEW_EXPORT QStringList deserialize(const QByteArray &byteArray)
Converts byte array to vector of strings.
MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString &path)
Returns a string where Linux path to the file is striped using '~/'.
Definition: widgetutils.cpp:79
MVVM_VIEW_EXPORT bool IsWindowsHost()
Returns true if it is Windows.
Definition: widgetutils.cpp:52
MVVM_VIEW_EXPORT QSize SizeOfLetterM()
Returns size corresponding to actual size of letter M basing on current font metrics.
MVVM_VIEW_EXPORT bool IsMacHost()
Returns true if it is Mac.
Definition: widgetutils.cpp:61
MVVM_VIEW_EXPORT QByteArray serialize(const QStringList &data)
Converts vector of strings to byte array.
MVVM_VIEW_EXPORT QStringList toStringList(const std::vector< std::string > &vec)
Converts vector of strings to QStringList.
MVVM_VIEW_EXPORT QString ClickableText(const QString &text, const QString &tag={})
Returns text wrapped into 'href' tag to provide clickable links in QLabel.
MVVM_VIEW_EXPORT void ScaleLabelFont(QLabel *label, double scale)
Set label's font size to system font size scaled by given factor.
MVVM_VIEW_EXPORT QMainWindow * FindMainWindow()
Finds main window.
MVVM_VIEW_EXPORT QColor RandomColor()
Returns random color.
Definition: widgetutils.cpp:41
MVVM_VIEW_EXPORT std::vector< std::string > fromStringList(const QStringList &string_list)
Converts vector of strings to QStringList.
MVVM_VIEW_EXPORT int WidthOfLetterM()
Returns width of the letter 'M' deduced from current font metrics.
MVVM_VIEW_EXPORT bool IsLinuxHost()
Returns true if it is Linux.
Definition: widgetutils.cpp:70
MVVM_VIEW_EXPORT int SystemPointSize()
Returns size in points of default system font.
MVVM_VIEW_EXPORT QString ProjectWindowTitle(const QString &project_dir, bool is_modified)
Returns a title composed from last part of project path, and is_modified flag.
Definition: widgetutils.cpp:98
materialitems.h Collection of materials to populate MaterialModel.