Mercurial > minori
comparison src/ui_utils.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children | b1f73678ef61 |
comparison
equal
deleted
inserted
replaced
6:1d82f6e04d7d | 7:07a9095eaeed |
---|---|
1 #include <QPixmap> | |
2 #include <QLabel> | |
3 #include <QFrame> | |
4 #include <QVBoxLayout> | |
5 #include <QTextBlock> | |
1 #include "window.h" | 6 #include "window.h" |
2 #include "ui_utils.h" | 7 #include "ui_utils.h" |
8 #include "session.h" | |
3 #ifdef MACOSX | 9 #ifdef MACOSX |
4 #include "sys/osx/dark_theme.h" | 10 #include "sys/osx/dark_theme.h" |
5 #else | 11 #else |
6 #include "sys/win32/dark_theme.h" | 12 #include "sys/win32/dark_theme.h" |
7 #endif | 13 #endif |
35 } | 41 } |
36 #endif | 42 #endif |
37 return (session.config.theme == DARK); | 43 return (session.config.theme == DARK); |
38 } | 44 } |
39 | 45 |
40 void UiUtils::CreateTextHeader(QWidget* parent, QString title, QPoint point, QSize size) { | 46 void UiUtils::CreateTextHeader(QWidget* parent, QString title) { |
41 QLabel* static_text_title = new QLabel(title, parent); | 47 QLabel* static_text_title = new QLabel(title, parent); |
42 static_text_title->setTextFormat(Qt::PlainText); | 48 static_text_title->setTextFormat(Qt::PlainText); |
43 static_text_title->setStyleSheet("font-weight: bold"); | 49 |
44 static_text_title->move(point.x(), point.y()); | 50 QFont font = static_text_title->font(); |
45 static_text_title->resize(size.width(), 16); | 51 font.setWeight(QFont::Bold); |
52 static_text_title->setFont(font); | |
53 | |
54 static_text_title->setFixedHeight(16); | |
55 parent->layout()->addWidget(static_text_title); | |
46 | 56 |
47 QFrame* static_text_line = new QFrame(parent); | 57 QFrame* static_text_line = new QFrame(parent); |
48 static_text_line->setFrameShape(QFrame::HLine); | 58 static_text_line->setFrameShape(QFrame::HLine); |
49 static_text_line->setFrameShadow(QFrame::Sunken); | 59 static_text_line->setFrameShadow(QFrame::Sunken); |
50 static_text_line->resize(size.width(), 2); | 60 static_text_line->setFixedHeight(2); |
51 static_text_line->move(point.x(), point.y()+18); | 61 parent->layout()->addWidget(static_text_line); |
52 } | 62 } |
53 | 63 |
54 QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data, QPoint point, QSize size) { | 64 QPlainTextEdit* UiUtils::CreateTextParagraph(QWidget* parent, QString title, QString data) { |
55 CreateTextHeader(parent, title, point, size); | 65 QWidget* paragraph_master = new QWidget(parent); |
66 paragraph_master->setLayout(new QVBoxLayout); | |
56 | 67 |
57 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent); | 68 CreateTextHeader(paragraph_master, title); |
69 | |
70 Paragraph* paragraph = new Paragraph(data, paragraph_master); | |
58 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | 71 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); |
59 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 72 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
60 paragraph->setWordWrapMode(QTextOption::NoWrap); | 73 paragraph->setWordWrapMode(QTextOption::NoWrap); |
61 paragraph->setFrameShape(QFrame::NoFrame); | 74 paragraph->setContentsMargins(12, 0, 0, 0); |
62 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 75 |
63 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 76 paragraph_master->layout()->addWidget(paragraph); |
64 paragraph->setStyleSheet("background: transparent;"); | 77 paragraph_master->layout()->setSpacing(0); |
65 paragraph->move(point.x()+12, point.y()+32); | 78 paragraph_master->layout()->setMargin(0); |
66 paragraph->resize(size.width()-12, size.height()-32); | 79 paragraph_master->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
80 | |
67 return paragraph; | 81 return paragraph; |
68 } | 82 } |
69 | 83 |
70 QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data, QPoint point, QSize size) { | 84 QPlainTextEdit* UiUtils::CreateTextParagraphWithLabels(QWidget* parent, QString title, QString label, QString data) { |
71 CreateTextHeader(parent, title, point, size); | 85 QWidget* paragraph_master = new QWidget(parent); |
86 paragraph_master->setLayout(new QVBoxLayout); | |
72 | 87 |
73 QPlainTextEdit* label_t = new QPlainTextEdit(label, parent); | 88 CreateTextHeader(paragraph_master, title); |
89 | |
90 QWidget* paragraph_and_label = new QWidget(paragraph_master); | |
91 paragraph_and_label->setLayout(new QHBoxLayout); | |
92 paragraph_and_label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
93 | |
94 Paragraph* label_t = new Paragraph(label, paragraph_and_label); | |
74 label_t->setTextInteractionFlags(Qt::NoTextInteraction); | 95 label_t->setTextInteractionFlags(Qt::NoTextInteraction); |
75 label_t->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 96 label_t->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
76 label_t->setWordWrapMode(QTextOption::NoWrap); | 97 label_t->setWordWrapMode(QTextOption::NoWrap); |
77 label_t->setFrameShape(QFrame::NoFrame); | 98 label_t->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
78 label_t->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 99 label_t->setFixedWidth(123); |
79 label_t->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
80 label_t->setStyleSheet("background: transparent;"); | |
81 label_t->move(point.x()+12, point.y()+32); | |
82 label_t->resize(90, size.height()-32); | |
83 | 100 |
84 QPlainTextEdit* paragraph = new QPlainTextEdit(data, parent); | 101 Paragraph* paragraph = new Paragraph(data, paragraph_and_label); |
85 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | 102 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); |
86 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 103 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
87 paragraph->setWordWrapMode(QTextOption::NoWrap); | 104 paragraph->setWordWrapMode(QTextOption::NoWrap); |
88 paragraph->setFrameShape(QFrame::NoFrame); | 105 |
89 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 106 ((QBoxLayout*)paragraph_and_label->layout())->addWidget(label_t, 0, Qt::AlignTop); |
90 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 107 ((QBoxLayout*)paragraph_and_label->layout())->addWidget(paragraph, 0, Qt::AlignTop); |
91 paragraph->setStyleSheet("background: transparent;"); | 108 |
92 paragraph->move(point.x()+102, point.y()+32); | 109 paragraph_and_label->setContentsMargins(12, 0, 0, 0); |
93 paragraph->resize(size.width()-102, size.height()-32); | 110 |
111 paragraph_master->layout()->addWidget(paragraph_and_label); | |
112 paragraph_master->layout()->setSpacing(0); | |
113 paragraph_master->layout()->setMargin(0); | |
114 paragraph_master->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
115 | |
94 return paragraph; | 116 return paragraph; |
95 } | 117 } |
96 | 118 |
97 /* As far as I can tell, this is identical to the way Taiga implements it. | 119 /* 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 */ | 120 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) { | 121 QPlainTextEdit* UiUtils::CreateSelectableTextParagraph(QWidget* parent, QString title, QString data) { |
100 CreateTextHeader(parent, title, point, size); | 122 QWidget* paragraph_master = new QWidget(parent); |
123 paragraph_master->setLayout(new QVBoxLayout); | |
101 | 124 |
102 QPlainTextEdit* text_edit = new QPlainTextEdit(data, parent); | 125 CreateTextHeader(paragraph_master, title); |
103 text_edit->setReadOnly(true); | 126 |
104 text_edit->setFrameShape(QFrame::NoFrame); | 127 QWidget* paragraph_widget = new QWidget(paragraph_master); |
105 text_edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 128 paragraph_widget->setLayout(new QHBoxLayout); |
106 text_edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 129 paragraph_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
107 text_edit->setStyleSheet("background: transparent;"); | 130 |
108 text_edit->move(point.x()+12, point.y()+32); | 131 Paragraph* text_edit = new Paragraph(data, paragraph_widget); |
109 text_edit->resize(size.width()-12, size.height()-32); | 132 |
133 paragraph_widget->layout()->addWidget(text_edit); | |
134 | |
135 paragraph_widget->setContentsMargins(12, 0, 0, 0); | |
136 | |
137 paragraph_master->layout()->addWidget(paragraph_widget); | |
138 paragraph_master->layout()->setSpacing(0); | |
139 paragraph_master->layout()->setMargin(0); | |
140 | |
141 paragraph_master->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
142 | |
110 return text_edit; | 143 return text_edit; |
111 } | 144 } |
145 | |
146 void UiUtils::SetPlainTextEditData(QPlainTextEdit* text_edit, QString data) { | |
147 QTextDocument* document = new QTextDocument(text_edit); | |
148 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
149 document->setPlainText(data); | |
150 text_edit->setDocument(document); | |
151 } | |
152 | |
153 Paragraph::Paragraph(QString text, QWidget* parent) | |
154 : QPlainTextEdit(text, parent) { | |
155 setReadOnly(true); | |
156 setTextInteractionFlags(Qt::TextBrowserInteraction); | |
157 setFrameShape(QFrame::NoFrame); | |
158 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
159 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
160 setStyleSheet("background: transparent;"); | |
161 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
162 } | |
163 | |
164 QSize Paragraph::minimumSizeHint() const { | |
165 QTextDocument* doc = document(); | |
166 long h = (long)(blockBoundingGeometry(doc->findBlockByNumber(doc->blockCount() - 1)).bottom() + (2 * doc->documentMargin())); | |
167 return QSize(QPlainTextEdit::sizeHint().width(), (long)h); | |
168 } | |
169 | |
170 QSize Paragraph::sizeHint() const { | |
171 return minimumSizeHint(); | |
172 } |