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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
1 #include "window.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #include "ui_utils.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #ifdef MACOSX
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 #include "sys/osx/dark_theme.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 #else
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
6 #include "sys/win32/dark_theme.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 bool UiUtils::IsInDarkMode() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 if (session.config.theme != OS)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 return (session.config.theme == DARK);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 #ifdef MACOSX
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 if (osx::DarkThemeAvailable()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 if (osx::IsInDarkTheme()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 return true;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 } else {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 return false;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 #elif defined(WIN32)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 if (win32::DarkThemeAvailable()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 if (win32::IsInDarkTheme()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 return true;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 } else {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 return false;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 return (session.config.theme == DARK);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 void UiUtils::CreateTextHeader(QWidget* parent, QString title, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 QLabel* static_text_title = new QLabel(title, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 static_text_title->setTextFormat(Qt::PlainText);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43 static_text_title->setStyleSheet("font-weight: bold");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 static_text_title->move(point.x(), point.y());
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45 static_text_title->resize(size.width(), 16);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 QFrame* static_text_line = new QFrame(parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48 static_text_line->setFrameShape(QFrame::HLine);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 static_text_line->setFrameShadow(QFrame::Sunken);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 static_text_line->resize(size.width(), 2);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51 static_text_line->move(point.x(), point.y()+18);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54 QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
57 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
60 paragraph->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
65 paragraph->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
66 paragraph->resize(size.width()-12, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
67 return paragraph;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
70 QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
71 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
72
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
73 QPlainTextEdit* label_t = new QPlainTextEdit(label, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
76 label_t->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
81 label_t->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82 label_t->resize(90, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
83
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 paragraph->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 paragraph->move(point.x()+102, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
93 paragraph->resize(size.width()-102, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
94 return paragraph;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
96
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
97 /* As far as I can tell, this is identical to the way Taiga implements it.
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
98 Kind of cool, I didn't even look into the source code for it :p */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
99 QPlainTextEdit* UiUtils::CreateSelectableTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
100 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
101
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
102 QPlainTextEdit* text_edit = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
103 text_edit->setReadOnly(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
108 text_edit->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
109 text_edit->resize(size.width()-12, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
110 return text_edit;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
111 }