Mercurial > minori
diff src/gui/widgets/text.cc @ 253:b3549da699a6
*: ooooh! stupid big commit!
oops
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 06 Feb 2024 16:56:32 -0500 |
parents | 4d461ef7d424 |
children | 862d0d8619f6 |
line wrap: on
line diff
--- a/src/gui/widgets/text.cc Tue Feb 06 02:24:49 2024 -0500 +++ b/src/gui/widgets/text.cc Tue Feb 06 16:56:32 2024 -0500 @@ -1,5 +1,6 @@ #include "gui/widgets/text.h" #include "core/session.h" + #include <QDebug> #include <QFrame> #include <QLabel> @@ -37,66 +38,37 @@ updateGeometry(); } -/* inherits QPlainTextEdit and gives a much more reasonable minimum size */ -Paragraph::Paragraph(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { +/* for now, this is a QLabel with a couple of default settings. + * + * eventually I'll have to implement this as a QScrollArea, just in case + * some random text decides to overflow or something. +*/ +Paragraph::Paragraph(const QString& text, QWidget* parent) : QLabel(text, parent) { setTextInteractionFlags(Qt::TextBrowserInteraction); setFrameShape(QFrame::NoFrame); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - - QPalette pal; - pal.setColor(QPalette::Base, Qt::transparent); - setPalette(pal); - - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); -} + setCursor(Qt::IBeamCursor); /* emulate Taiga */ + setWordWrap(true); -void Paragraph::SetText(const QString& text) { - QTextDocument* document = new QTextDocument(this); - document->setDocumentLayout(new QPlainTextDocumentLayout(document)); - document->setPlainText(text); - setDocument(document); - updateGeometry(); -} - -/* highly based upon... some stackoverflow answer for PyQt */ -QSize Paragraph::minimumSizeHint() const { - return QSize(0, 0); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); } -QSize Paragraph::sizeHint() const { - QTextDocument* doc = document(); - doc->adjustSize(); - long h = 0; - for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { - h += doc->documentLayout()->blockBoundingRect(line).height(); - } - return QSize(doc->size().width(), h); +/* kept here for legacy reasons, see explanation above */ +void Paragraph::SetText(const QString& text) { + setText(text); } -/* Equivalent to Paragraph(), but is only capable of showing one line. Only - exists because with SelectableSection it will let you go - out of bounds and that looks really fugly for most things */ -Line::Line(QWidget* parent) : QLineEdit(parent) { - setFrame(false); - setReadOnly(true); - setCursor(Qt::IBeamCursor); - - QPalette pal; - pal.setColor(QPalette::Window, Qt::transparent); - pal.setColor(QPalette::Base, Qt::transparent); - setPalette(pal); - - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); +/* Equivalent to Paragraph(), but disables word wrap. */ +Line::Line(QWidget* parent) : Paragraph("", parent) { + setWordWrap(false); } -Line::Line(const QString& text, QWidget* parent) : Line(parent) { - SetText(text); +Line::Line(const QString& text, QWidget* parent) : Paragraph(text, parent) { + setWordWrap(false); } +/* legacy function, don't use in new code */ void Line::SetText(const QString& text) { setText(text); - setCursorPosition(0); /* displays left text first */ } Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { @@ -120,7 +92,7 @@ paragraph = new Paragraph(data, this); paragraph->setTextInteractionFlags(Qt::NoTextInteraction); paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); - paragraph->setWordWrapMode(QTextOption::NoWrap); + paragraph->setWordWrap(QTextOption::NoWrap); content_layout->addWidget(paragraph); content_layout->setSpacing(0); @@ -141,6 +113,35 @@ return paragraph; } +LabelledParagraph::LabelledParagraph(const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { + QHBoxLayout* ly = new QHBoxLayout(this); + + labels = new Paragraph(label, this); + labels->setTextInteractionFlags(Qt::NoTextInteraction); + labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); + labels->setWordWrap(QTextOption::NoWrap); + labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + + paragraph = new Paragraph(data, this); + paragraph->setTextInteractionFlags(Qt::NoTextInteraction); + paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); + paragraph->setWordWrap(QTextOption::NoWrap); + paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + + ly->addWidget(labels, 0, Qt::AlignTop); + ly->addWidget(paragraph, 0, Qt::AlignTop); + ly->setSpacing(20); + ly->setContentsMargins(0, 0, 0, 0); +} + +Paragraph* LabelledParagraph::GetLabels() { + return labels; +} + +Paragraph* LabelledParagraph::GetParagraph() { + return paragraph; +} + LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); @@ -148,27 +149,8 @@ // this is not accessible from the object because there's really // no reason to make it accessible... - QWidget* content = new QWidget(this); + content = new LabelledParagraph(label, data, this); content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - - labels = new Paragraph(label, this); - labels->setTextInteractionFlags(Qt::NoTextInteraction); - labels->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); - labels->setWordWrapMode(QTextOption::NoWrap); - labels->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); - - paragraph = new Paragraph(data, this); - paragraph->setTextInteractionFlags(Qt::NoTextInteraction); - paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); - paragraph->setWordWrapMode(QTextOption::NoWrap); - paragraph->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - - QHBoxLayout* content_layout = new QHBoxLayout(content); - content_layout->addWidget(labels, 0, Qt::AlignTop); - content_layout->addWidget(paragraph, 0, Qt::AlignTop); - content_layout->setSpacing(20); - content_layout->setContentsMargins(0, 0, 0, 0); - content->setContentsMargins(12, 0, 0, 0); layout->addWidget(header); @@ -182,11 +164,11 @@ } Paragraph* LabelledSection::GetLabels() { - return labels; + return content->GetLabels(); } Paragraph* LabelledSection::GetParagraph() { - return paragraph; + return content->GetParagraph(); } SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) {