BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
StyleUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Tool/StyleUtils.cpp
6 //! @brief Defines GUI::StyleUtils namespace
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
18 #include <QApplication>
19 #include <QBoxLayout>
20 #include <QDialog>
21 #include <QTreeView>
22 
23 namespace {
24 
25 //! Calculates size of letter `M` for current system font settings.
26 
27 QSize FindSizeOfLetterM(const QWidget* widget)
28 {
29  QFontMetrics fontMetric(widget->font());
30 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
31  auto em = fontMetric.horizontalAdvance('M');
32 #else
33  auto em = fontMetric.width('M');
34 #endif
35  auto fontAscent = fontMetric.ascent();
36 
37  return QSize(em, fontAscent);
38 }
39 
40 QSize DefaultSizeOfLetterM()
41 {
42  QWidget widget;
43  return FindSizeOfLetterM(&widget);
44 }
45 
46 } // namespace
47 
48 
50 {
51  ASSERT(tree);
52  tree->setStyleSheet(GUI::Util::Style::propertyTreeStyle());
53  tree->setAlternatingRowColors(true);
54 }
55 
57 {
58  QString result;
59 
60  // lines arount cell content
61  result += "QTreeView::item {"
62  " border-bottom: 1px solid #c7c8c9; "
63  " border-right: 1px solid #c7c8c9;}"
64  "QTreeView::branch {border-bottom: 1px solid #c7c8c9;}";
65 
66  // styling of branch to restore open/closed signs eliminated by previous styling
67  result += "QTreeView::branch:has-children:!has-siblings:closed,"
68  "QTreeView::branch:closed:has-children:has-siblings {"
69  "padding:2px 2px 2px 2px;border-image: none;"
70  "image: url(:/images/caret-right.svg);}"
71  "QTreeView::branch:open:has-children:!has-siblings,"
72  "QTreeView::branch:open:has-children:has-siblings {"
73  "padding:2px 2px 2px 2px;border-image: none; image: url(:/images/caret-down.svg);"
74  "}";
75 
76  // background of selected rows restored
77  result += "QTreeView::item:selected{background:#3daee9;}";
78 
79  return result;
80 }
81 
83 {
84  QFont result;
85  result.setPointSize(DesignerHelper::getSectionFontSize());
86  result.setBold(bold);
87 
88  return result;
89 }
90 
92 {
93  QFont result;
94  result.setPointSize(DesignerHelper::getLabelFontSize());
95  result.setBold(bold);
96 
97  return result;
98 }
99 
101 #ifdef Q_OS_MAC
102  dialog
103 #endif
104 )
105 {
106 #ifdef Q_OS_MAC
107  dialog->setWindowFlags(Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint
108  | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint
109  | Qt::Window);
110 #endif
111 }
112 
113 QSize GUI::Util::Style::SizeOfLetterM(const QWidget* widget)
114 {
115  static QSize default_size = DefaultSizeOfLetterM();
116  return widget ? FindSizeOfLetterM(widget) : default_size;
117 }
118 
120 {
121  return QApplication::font().pointSize();
122 }
123 
125 {
126  return SizeOfLetterM().width() * 16;
127 }
Defines class DesignerHelper.
Defines GUI::StyleUtils namespace.
static int getLabelFontSize()
static int getSectionFontSize()
Returns system dependent font size.
int SystemPointSize()
Returns size in points of default system font.
Definition: StyleUtils.cpp:119
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:113
QFont sectionFont(bool bold=false)
Returns font for sections.
Definition: StyleUtils.cpp:82
QFont labelFont(bool bold=false)
Returns font for labels.
Definition: StyleUtils.cpp:91
void setPropertyStyle(QTreeView *tree)
Sets style for the tree to use in property editors.
Definition: StyleUtils.cpp:49
int PropertyPanelWidth()
Returns typical width of the vertical property panel.
Definition: StyleUtils.cpp:124
QString propertyTreeStyle()
Returns string representing the style of QTreeView intended for property editor.
Definition: StyleUtils.cpp:56
void setResizable(QDialog *dialog)
Make modal dialog resizable.
Definition: StyleUtils.cpp:100