Mercurial > minori
annotate src/ui_utils.cpp @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 16 Aug 2023 00:49:17 -0400 |
parents | 23d0d9319a00 |
children | 07a9095eaeed |
rev | line source |
---|---|
2 | 1 #include "window.h" |
2 #include "ui_utils.h" | |
3 #ifdef MACOSX | |
4 #include "sys/osx/dark_theme.h" | |
5 #else | |
6 #include "sys/win32/dark_theme.h" | |
7 #endif | |
8 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
9 QIcon UiUtils::CreateSideBarIcon(const char* file) { |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
10 QPixmap pixmap(file, "PNG"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
11 QIcon result; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
12 result.addPixmap(pixmap, QIcon::Normal); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
13 result.addPixmap(pixmap, QIcon::Selected); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
14 return result; |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
15 } |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
16 |
2 | 17 bool UiUtils::IsInDarkMode() { |
18 if (session.config.theme != OS) | |
19 return (session.config.theme == DARK); | |
20 #ifdef MACOSX | |
21 if (osx::DarkThemeAvailable()) { | |
22 if (osx::IsInDarkTheme()) { | |
23 return true; | |
24 } else { | |
25 return false; | |
26 } | |
27 } | |
28 #elif defined(WIN32) | |
29 if (win32::DarkThemeAvailable()) { | |
30 if (win32::IsInDarkTheme()) { | |
31 return true; | |
32 } else { | |
33 return false; | |
34 } | |
35 } | |
36 #endif | |
37 return (session.config.theme == DARK); | |
38 } | |
39 | |
40 void UiUtils::CreateTextHeader(QWidget* parent, QString title, QPoint point, QSize size) { | |
41 QLabel* static_text_title = new QLabel(title, parent); | |
42 static_text_title->setTextFormat(Qt::PlainText); | |
43 static_text_title->setStyleSheet("font-weight: bold"); | |
44 static_text_title->move(point.x(), point.y()); | |
45 static_text_title->resize(size.width(), 16); | |
46 | |
47 QFrame* static_text_line = new QFrame(parent); | |
48 static_text_line->setFrameShape(QFrame::HLine); | |
49 static_text_line->setFrameShadow(QFrame::Sunken); | |
50 static_text_line->resize(size.width(), 2); | |
51 static_text_line->move(point.x(), point.y()+18); | |
52 } | |
53 | |
54 QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) { | |
55 CreateTextHeader(parent, title, point, size); | |
56 | |
57 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent); | |
58 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
59 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
2 | 60 paragraph->setWordWrapMode(QTextOption::NoWrap); |
61 paragraph->setFrameShape(QFrame::NoFrame); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
62 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
63 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
64 paragraph->setStyleSheet("background: transparent;"); |
2 | 65 paragraph->move(point.x()+12, point.y()+32); |
66 paragraph->resize(size.width()-12, size.height()-32); | |
67 return paragraph; | |
68 } | |
69 | |
70 QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data, QPoint point, QSize size) { | |
71 CreateTextHeader(parent, title, point, size); | |
72 | |
73 QPlainTextEdit* label_t = new QPlainTextEdit(label, parent); | |
74 label_t->setTextInteractionFlags(Qt::NoTextInteraction); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
75 label_t->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
2 | 76 label_t->setWordWrapMode(QTextOption::NoWrap); |
77 label_t->setFrameShape(QFrame::NoFrame); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
78 label_t->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
79 label_t->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
80 label_t->setStyleSheet("background: transparent;"); |
2 | 81 label_t->move(point.x()+12, point.y()+32); |
82 label_t->resize(90, size.height()-32); | |
83 | |
84 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent); | |
85 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
86 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
2 | 87 paragraph->setWordWrapMode(QTextOption::NoWrap); |
88 paragraph->setFrameShape(QFrame::NoFrame); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
89 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
90 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
91 paragraph->setStyleSheet("background: transparent;"); |
2 | 92 paragraph->move(point.x()+102, point.y()+32); |
93 paragraph->resize(size.width()-102, size.height()-32); | |
94 return paragraph; | |
95 } | |
96 | |
97 /* As far as I can tell, this is identical to the way Taiga implements it. | |
98 Kind of cool, I didn't even look into the source code for it :p */ | |
99 QPlainTextEdit* UiUtils::CreateSelectableTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) { | |
100 CreateTextHeader(parent, title, point, size); | |
101 | |
102 QPlainTextEdit* text_edit = new QPlainTextEdit(data, parent); | |
103 text_edit->setReadOnly(true); | |
104 text_edit->setFrameShape(QFrame::NoFrame); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
105 text_edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
106 text_edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
107 text_edit->setStyleSheet("background: transparent;"); |
2 | 108 text_edit->move(point.x()+12, point.y()+32); |
109 text_edit->resize(size.width()-12, size.height()-32); | |
110 return text_edit; | |
111 } |