Mercurial > minori
annotate src/gui/ui_utils.cpp @ 30:4dc59e1a81a3
ci/win32: fix echo-ing to binfmt
ok, so apparently bash AUTOMATICALLY writes a newline to the end of
a file. why does it do this? nobody knows, but we can avoid it by
simply adding the `-n` flag
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 20 Sep 2023 00:53:11 -0400 |
| parents | cde8f67a7c7d |
| children | 2743011a6042 |
| rev | line source |
|---|---|
| 9 | 1 /** |
| 2 * FIXME: most of these can actually be rerouted to *separate* files. | |
| 3 * Please do this! It makes everything cleaner :) | |
| 4 **/ | |
| 5 #include "gui/ui_utils.h" | |
| 6 #include "core/session.h" | |
| 7 #include <QFrame> | |
| 7 | 8 #include <QLabel> |
| 9 | 9 #include <QPixmap> |
| 10 #include <QTextBlock> | |
| 7 | 11 #include <QVBoxLayout> |
| 2 | 12 #ifdef MACOSX |
| 15 | 13 # include "sys/osx/dark_theme.h" |
| 2 | 14 #else |
| 15 | 15 # include "sys/win32/dark_theme.h" |
| 2 | 16 #endif |
| 17 | |
| 8 | 18 namespace UiUtils { |
| 19 | |
| 20 bool IsInDarkMode() { | |
| 9 | 21 if (session.config.theme != Themes::OS) |
| 22 return (session.config.theme == Themes::DARK); | |
| 2 | 23 #ifdef MACOSX |
| 24 if (osx::DarkThemeAvailable()) { | |
| 25 if (osx::IsInDarkTheme()) { | |
| 26 return true; | |
| 27 } else { | |
| 28 return false; | |
| 29 } | |
| 30 } | |
| 31 #elif defined(WIN32) | |
| 32 if (win32::DarkThemeAvailable()) { | |
| 33 if (win32::IsInDarkTheme()) { | |
| 34 return true; | |
| 35 } else { | |
| 36 return false; | |
| 37 } | |
| 38 } | |
| 39 #endif | |
| 9 | 40 return (session.config.theme == Themes::DARK); |
| 2 | 41 } |
| 42 | |
| 9 | 43 Header::Header(QString title, QWidget* parent) : QWidget(parent) { |
| 8 | 44 setLayout(new QVBoxLayout); |
| 45 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | |
| 46 | |
| 9 | 47 static_text_title = new QLabel(title, this); |
| 2 | 48 static_text_title->setTextFormat(Qt::PlainText); |
| 7 | 49 QFont font = static_text_title->font(); |
| 50 font.setWeight(QFont::Bold); | |
| 51 static_text_title->setFont(font); | |
| 8 | 52 static_text_title->setFixedHeight(16); |
| 7 | 53 |
| 8 | 54 static_text_line = new QFrame(this); |
| 2 | 55 static_text_line->setFrameShape(QFrame::HLine); |
| 56 static_text_line->setFrameShadow(QFrame::Sunken); | |
| 7 | 57 static_text_line->setFixedHeight(2); |
| 8 | 58 |
| 59 layout()->addWidget(static_text_title); | |
| 60 layout()->addWidget(static_text_line); | |
| 61 layout()->setSpacing(0); | |
| 62 layout()->setMargin(0); | |
| 63 } | |
| 64 | |
| 65 void Header::SetTitle(QString title) { | |
| 66 static_text_title->setText(title); | |
| 2 | 67 } |
| 68 | |
| 9 | 69 TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { |
| 8 | 70 setLayout(new QVBoxLayout); |
| 7 | 71 |
| 8 | 72 header = new Header(title, this); |
| 2 | 73 |
| 8 | 74 QWidget* content = new QWidget(this); |
| 75 content->setLayout(new QHBoxLayout); | |
| 7 | 76 |
| 8 | 77 paragraph = new Paragraph(data, this); |
| 2 | 78 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
79 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
| 2 | 80 paragraph->setWordWrapMode(QTextOption::NoWrap); |
| 7 | 81 |
| 8 | 82 content->layout()->addWidget(paragraph); |
| 83 content->layout()->setSpacing(0); | |
| 84 content->layout()->setMargin(0); | |
| 85 content->setContentsMargins(12, 0, 0, 0); | |
| 7 | 86 |
| 8 | 87 layout()->addWidget(header); |
| 88 layout()->addWidget(paragraph); | |
| 89 layout()->setSpacing(0); | |
| 90 layout()->setMargin(0); | |
| 91 } | |
| 7 | 92 |
| 8 | 93 Header* TextParagraph::GetHeader() { |
| 94 return header; | |
| 95 } | |
| 96 | |
| 97 Paragraph* TextParagraph::GetParagraph() { | |
| 2 | 98 return paragraph; |
| 99 } | |
| 100 | |
| 15 | 101 LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, |
| 102 QWidget* parent) | |
| 103 : QWidget(parent) { | |
| 8 | 104 setLayout(new QVBoxLayout); |
| 105 | |
| 106 header = new Header(title, this); | |
| 7 | 107 |
| 8 | 108 // this is not accessible from the object because there's really |
| 109 // no reason to make it accessible... | |
| 110 QWidget* content = new QWidget(this); | |
| 15 | 111 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 7 | 112 |
| 8 | 113 labels = new Paragraph(label, this); |
| 114 labels->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 115 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 116 labels->setWordWrapMode(QTextOption::NoWrap); | |
| 15 | 117 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 8 | 118 labels->setFixedWidth(123); |
| 2 | 119 |
| 8 | 120 paragraph = new Paragraph(data, this); |
| 121 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | |
| 122 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | |
| 123 paragraph->setWordWrapMode(QTextOption::NoWrap); | |
| 7 | 124 |
| 8 | 125 QHBoxLayout* content_layout = new QHBoxLayout; |
| 126 content_layout->addWidget(labels, 0, Qt::AlignTop); | |
| 127 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | |
| 128 content_layout->setSpacing(0); | |
| 129 content_layout->setMargin(0); | |
| 130 content->setLayout(content_layout); | |
| 7 | 131 |
| 8 | 132 content->setContentsMargins(12, 0, 0, 0); |
| 7 | 133 |
| 8 | 134 layout()->addWidget(header); |
| 135 layout()->addWidget(content); | |
| 136 layout()->setSpacing(0); | |
| 137 layout()->setMargin(0); | |
| 2 | 138 } |
| 7 | 139 |
| 8 | 140 Header* LabelledTextParagraph::GetHeader() { |
| 141 return header; | |
| 142 } | |
| 143 | |
| 144 Paragraph* LabelledTextParagraph::GetLabels() { | |
| 145 return labels; | |
| 146 } | |
| 147 | |
| 148 Paragraph* LabelledTextParagraph::GetParagraph() { | |
| 149 return paragraph; | |
| 150 } | |
| 151 | |
| 15 | 152 SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) |
| 153 : QWidget(parent) { | |
| 8 | 154 setLayout(new QVBoxLayout); |
| 155 | |
| 156 header = new Header(title, this); | |
| 157 | |
| 158 QWidget* content = new QWidget(this); | |
| 159 content->setLayout(new QHBoxLayout); | |
| 160 | |
| 161 paragraph = new Paragraph(data, content); | |
| 162 | |
| 163 content->layout()->addWidget(paragraph); | |
| 164 content->layout()->setSpacing(0); | |
| 165 content->layout()->setMargin(0); | |
| 166 content->setContentsMargins(12, 0, 0, 0); | |
| 167 | |
| 168 layout()->addWidget(header); | |
| 169 layout()->addWidget(content); | |
| 170 layout()->setSpacing(0); | |
| 171 layout()->setMargin(0); | |
| 172 } | |
| 173 | |
| 174 Header* SelectableTextParagraph::GetHeader() { | |
| 175 return header; | |
| 176 } | |
| 177 | |
| 178 Paragraph* SelectableTextParagraph::GetParagraph() { | |
| 179 return paragraph; | |
| 180 } | |
| 181 | |
| 182 void SetPlainTextEditData(QPlainTextEdit* text_edit, QString data) { | |
| 7 | 183 QTextDocument* document = new QTextDocument(text_edit); |
| 184 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | |
| 185 document->setPlainText(data); | |
| 186 text_edit->setDocument(document); | |
| 187 } | |
| 188 | |
| 8 | 189 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
| 9 | 190 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { |
| 7 | 191 setReadOnly(true); |
| 192 setTextInteractionFlags(Qt::TextBrowserInteraction); | |
| 193 setFrameShape(QFrame::NoFrame); | |
| 194 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
| 195 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
| 196 setStyleSheet("background: transparent;"); | |
| 197 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | |
| 198 } | |
| 199 | |
| 8 | 200 /* highly based upon... some stackoverflow answer for PyQt */ |
| 7 | 201 QSize Paragraph::minimumSizeHint() const { |
| 202 QTextDocument* doc = document(); | |
| 9 | 203 long h = (long)(blockBoundingGeometry(doc->findBlockByNumber(doc->blockCount() - 1)).bottom() + |
| 15 | 204 (2 * doc->documentMargin())); |
| 205 return QSize(QPlainTextEdit::sizeHint().width(), h); | |
| 7 | 206 } |
| 207 | |
| 208 QSize Paragraph::sizeHint() const { | |
| 209 return minimumSizeHint(); | |
| 210 } | |
| 8 | 211 |
| 212 } // namespace UiUtils | |
| 9 | 213 |
| 214 #include "gui/moc_ui_utils.cpp" |
