Mercurial > minori
comparison src/gui/widgets/text.cc @ 83:d02fdf1d6708
*: huuuge update
1. make the now playing page function correctly
2. de-constructorfy many of our custom widgets,
allowing them to be changed on-the-fly from
the Now Playing page
3. ... :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 24 Oct 2023 22:01:02 -0400 |
| parents | 9b2b41f83a5e |
| children | c912128af0eb |
comparison
equal
deleted
inserted
replaced
| 82:8b65c417c225 | 83:d02fdf1d6708 |
|---|---|
| 6 #include <QTextBlock> | 6 #include <QTextBlock> |
| 7 #include <QVBoxLayout> | 7 #include <QVBoxLayout> |
| 8 | 8 |
| 9 namespace TextWidgets { | 9 namespace TextWidgets { |
| 10 | 10 |
| 11 Header::Header(QString title, QWidget* parent) : QWidget(parent) { | 11 Header::Header(const QString& title, QWidget* parent) : QWidget(parent) { |
| 12 QVBoxLayout* layout = new QVBoxLayout(this); | 12 QVBoxLayout* layout = new QVBoxLayout(this); |
| 13 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); | 13 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); |
| 14 | 14 |
| 15 static_text_title = new QLabel(title, this); | 15 static_text_title = new QLabel(title, this); |
| 16 static_text_title->setTextFormat(Qt::PlainText); | 16 static_text_title->setTextFormat(Qt::PlainText); |
| 27 layout->addWidget(static_text_line); | 27 layout->addWidget(static_text_line); |
| 28 layout->setSpacing(0); | 28 layout->setSpacing(0); |
| 29 layout->setContentsMargins(0, 0, 0, 0); | 29 layout->setContentsMargins(0, 0, 0, 0); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void Header::SetText(QString text) { | 32 void Header::SetText(const QString& text) { |
| 33 static_text_title->setText(text); | 33 static_text_title->setText(text); |
| 34 updateGeometry(); | |
| 34 } | 35 } |
| 35 | 36 |
| 36 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ | 37 /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ |
| 37 Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { | 38 Paragraph::Paragraph(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { |
| 38 setTextInteractionFlags(Qt::TextBrowserInteraction); | 39 setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 39 setFrameShape(QFrame::NoFrame); | 40 setFrameShape(QFrame::NoFrame); |
| 40 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 41 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 41 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 42 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 42 | 43 |
| 45 setPalette(pal); | 46 setPalette(pal); |
| 46 | 47 |
| 47 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | 48 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void Paragraph::SetText(QString text) { | 51 void Paragraph::SetText(const QString& text) { |
| 51 QTextDocument* document = new QTextDocument(this); | 52 QTextDocument* document = new QTextDocument(this); |
| 52 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); | 53 document->setDocumentLayout(new QPlainTextDocumentLayout(document)); |
| 53 document->setPlainText(text); | 54 document->setPlainText(text); |
| 54 setDocument(document); | 55 setDocument(document); |
| 56 updateGeometry(); | |
| 55 } | 57 } |
| 56 | 58 |
| 57 /* highly based upon... some stackoverflow answer for PyQt */ | 59 /* highly based upon... some stackoverflow answer for PyQt */ |
| 58 QSize Paragraph::minimumSizeHint() const { | 60 QSize Paragraph::minimumSizeHint() const { |
| 59 return QSize(0, 0); | 61 return QSize(0, 0); |
| 70 } | 72 } |
| 71 | 73 |
| 72 /* Equivalent to Paragraph(), but is only capable of showing one line. Only | 74 /* Equivalent to Paragraph(), but is only capable of showing one line. Only |
| 73 exists because sometimes with SelectableSection it will let you go | 75 exists because sometimes with SelectableSection it will let you go |
| 74 out of bounds */ | 76 out of bounds */ |
| 75 Line::Line(QString text, QWidget* parent) : QLineEdit(text, parent) { | 77 Line::Line(QWidget* parent) : QLineEdit(parent) { |
| 76 setFrame(false); | 78 setFrame(false); |
| 77 setReadOnly(true); | 79 setReadOnly(true); |
| 78 setCursorPosition(0); /* displays left text first */ | |
| 79 | 80 |
| 80 QPalette pal; | 81 QPalette pal; |
| 81 pal.setColor(QPalette::Window, Qt::transparent); | 82 pal.setColor(QPalette::Window, Qt::transparent); |
| 82 setPalette(pal); | 83 setPalette(pal); |
| 83 | 84 |
| 84 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | 85 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); |
| 85 } | 86 } |
| 86 | 87 |
| 87 Title::Title(QString title, QWidget* parent) : Line(title, parent) { | 88 Line::Line(const QString& text, QWidget* parent) : Line(parent) { |
| 89 SetText(text); | |
| 90 } | |
| 91 | |
| 92 void Line::SetText(const QString& text) { | |
| 93 setText(text); | |
| 94 setCursorPosition(0); /* displays left text first */ | |
| 95 } | |
| 96 | |
| 97 Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { | |
| 88 QFont fnt(font()); | 98 QFont fnt(font()); |
| 89 fnt.setPixelSize(16); | 99 fnt.setPixelSize(16); |
| 90 setFont(fnt); | 100 setFont(fnt); |
| 91 | 101 |
| 92 QPalette pal(palette()); | 102 QPalette pal(palette()); |
| 93 pal.setColor(QPalette::Window, Qt::transparent); | 103 pal.setColor(QPalette::Window, Qt::transparent); |
| 94 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); | 104 pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); |
| 95 setPalette(pal); | 105 setPalette(pal); |
| 96 } | 106 } |
| 97 | 107 |
| 98 Section::Section(QString title, QString data, QWidget* parent) : QWidget(parent) { | 108 Section::Section(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
| 99 QVBoxLayout* layout = new QVBoxLayout(this); | 109 QVBoxLayout* layout = new QVBoxLayout(this); |
| 100 | 110 |
| 101 header = new Header(title, this); | 111 header = new Header(title, this); |
| 102 | 112 |
| 103 QWidget* content = new QWidget(this); | 113 QWidget* content = new QWidget(this); |
| 125 | 135 |
| 126 Paragraph* Section::GetParagraph() { | 136 Paragraph* Section::GetParagraph() { |
| 127 return paragraph; | 137 return paragraph; |
| 128 } | 138 } |
| 129 | 139 |
| 130 LabelledSection::LabelledSection(QString title, QString label, QString data, QWidget* parent) : QWidget(parent) { | 140 LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { |
| 131 QVBoxLayout* layout = new QVBoxLayout(this); | 141 QVBoxLayout* layout = new QVBoxLayout(this); |
| 132 | 142 |
| 133 header = new Header(title, this); | 143 header = new Header(title, this); |
| 134 | 144 |
| 135 // this is not accessible from the object because there's really | 145 // this is not accessible from the object because there's really |
| 136 // no reason to make it accessible... | 146 // no reason to make it accessible... |
| 137 QWidget* content = new QWidget(this); | 147 QWidget* content = new QWidget(this); |
| 138 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | 148 content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
| 139 | 149 |
| 140 labels = new Paragraph(label, this); | 150 labels = new Paragraph(label, this); |
| 141 labels->setTextInteractionFlags(Qt::NoTextInteraction); | 151 labels->setTextInteractionFlags(Qt::NoTextInteraction); |
| 142 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 152 labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
| 143 labels->setWordWrapMode(QTextOption::NoWrap); | 153 labels->setWordWrapMode(QTextOption::NoWrap); |
| 144 labels->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); | 154 labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); |
| 145 | 155 |
| 146 paragraph = new Paragraph(data, this); | 156 paragraph = new Paragraph(data, this); |
| 147 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); | 157 paragraph->setTextInteractionFlags(Qt::NoTextInteraction); |
| 148 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); | 158 paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); |
| 149 paragraph->setWordWrapMode(QTextOption::NoWrap); | 159 paragraph->setWordWrapMode(QTextOption::NoWrap); |
| 160 paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); | |
| 150 | 161 |
| 151 QHBoxLayout* content_layout = new QHBoxLayout(content); | 162 QHBoxLayout* content_layout = new QHBoxLayout(content); |
| 152 content_layout->addWidget(labels, 0, Qt::AlignTop); | 163 content_layout->addWidget(labels, 0, Qt::AlignTop); |
| 153 content_layout->addWidget(paragraph, 0, Qt::AlignTop); | 164 content_layout->addWidget(paragraph, 0, Qt::AlignTop); |
| 154 content_layout->setSpacing(20); | 165 content_layout->setSpacing(20); |
| 172 | 183 |
| 173 Paragraph* LabelledSection::GetParagraph() { | 184 Paragraph* LabelledSection::GetParagraph() { |
| 174 return paragraph; | 185 return paragraph; |
| 175 } | 186 } |
| 176 | 187 |
| 177 SelectableSection::SelectableSection(QString title, QString data, QWidget* parent) : QWidget(parent) { | 188 SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { |
| 178 QVBoxLayout* layout = new QVBoxLayout(this); | 189 QVBoxLayout* layout = new QVBoxLayout(this); |
| 179 | 190 |
| 180 header = new Header(title, this); | 191 header = new Header(title, this); |
| 181 | 192 |
| 182 QWidget* content = new QWidget(this); | 193 QWidget* content = new QWidget(this); |
| 201 | 212 |
| 202 Paragraph* SelectableSection::GetParagraph() { | 213 Paragraph* SelectableSection::GetParagraph() { |
| 203 return paragraph; | 214 return paragraph; |
| 204 } | 215 } |
| 205 | 216 |
| 206 OneLineSection::OneLineSection(QString title, QString text, QWidget* parent) : QWidget(parent) { | 217 OneLineSection::OneLineSection(const QString& title, const QString& text, QWidget* parent) : QWidget(parent) { |
| 207 QVBoxLayout* layout = new QVBoxLayout(this); | 218 QVBoxLayout* layout = new QVBoxLayout(this); |
| 208 | 219 |
| 209 header = new Header(title, this); | 220 header = new Header(title, this); |
| 210 | 221 |
| 211 QWidget* content = new QWidget(this); | 222 QWidget* content = new QWidget(this); |
