annotate src/ui_utils.cpp @ 3:190ded9438c0

Fix many warnings
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 11:57:25 -0400
parents 23d0d9319a00
children 1d82f6e04d7d
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 bool UiUtils::IsInDarkMode() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 if (session.config.theme != OS)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 return (session.config.theme == DARK);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 #ifdef MACOSX
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 if (osx::DarkThemeAvailable()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 if (osx::IsInDarkTheme()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 return true;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 } else {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 return false;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 #elif defined(WIN32)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 if (win32::DarkThemeAvailable()) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 if (win32::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 #endif
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 return (session.config.theme == DARK);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 void UiUtils::CreateTextHeader(QWidget* parent, QString title, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 QLabel* static_text_title = new QLabel(title, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 static_text_title->setTextFormat(Qt::PlainText);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 static_text_title->setStyleSheet("font-weight: bold");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 static_text_title->move(point.x(), point.y());
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 static_text_title->resize(size.width(), 16);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39 QFrame* static_text_line = new QFrame(parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 static_text_line->setFrameShape(QFrame::HLine);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 static_text_line->setFrameShadow(QFrame::Sunken);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 static_text_line->resize(size.width(), 2);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43 static_text_line->move(point.x(), point.y()+18);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51 paragraph->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 paragraph->setFrameShape(QFrame::NoFrame);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53 paragraph->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54 paragraph->resize(size.width()-12, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 return paragraph;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
57
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
58 QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
59 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
60
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
61 QPlainTextEdit* label_t = new QPlainTextEdit(label, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
62 label_t->setTextInteractionFlags(Qt::NoTextInteraction);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
63 label_t->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
64 label_t->setFrameShape(QFrame::NoFrame);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
65 label_t->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
66 label_t->resize(90, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
67
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69 paragraph->setTextInteractionFlags(Qt::NoTextInteraction);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
70 paragraph->setWordWrapMode(QTextOption::NoWrap);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
71 paragraph->setFrameShape(QFrame::NoFrame);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
72 paragraph->move(point.x()+102, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
73 paragraph->resize(size.width()-102, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
74 return paragraph;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
75 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
76
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
77 /* As far as I can tell, this is identical to the way Taiga implements it.
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
78 Kind of cool, I didn't even look into the source code for it :p */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
79 QPlainTextEdit* UiUtils::CreateSelectableTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
80 CreateTextHeader(parent, title, point, size);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
81
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82 QPlainTextEdit* text_edit = new QPlainTextEdit(data, parent);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
83 text_edit->setReadOnly(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 text_edit->setFrameShape(QFrame::NoFrame);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
85 text_edit->move(point.x()+12, point.y()+32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
86 text_edit->resize(size.width()-12, size.height()-32);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 return text_edit;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
88 }