Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/widgets/text.cc Mon Oct 23 13:37:42 2023 -0400 +++ b/src/gui/widgets/text.cc Tue Oct 24 22:01:02 2023 -0400 @@ -8,7 +8,7 @@ namespace TextWidgets { -Header::Header(QString title, QWidget* parent) : QWidget(parent) { +Header::Header(const QString& title, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); @@ -29,12 +29,13 @@ layout->setContentsMargins(0, 0, 0, 0); } -void Header::SetText(QString text) { +void Header::SetText(const QString& text) { static_text_title->setText(text); + updateGeometry(); } /* inherits QPlainTextEdit and gives a much more reasonable minimum size */ -Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { +Paragraph::Paragraph(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { setTextInteractionFlags(Qt::TextBrowserInteraction); setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -47,11 +48,12 @@ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } -void Paragraph::SetText(QString text) { +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 */ @@ -72,10 +74,9 @@ /* Equivalent to Paragraph(), but is only capable of showing one line. Only exists because sometimes with SelectableSection it will let you go out of bounds */ -Line::Line(QString text, QWidget* parent) : QLineEdit(text, parent) { +Line::Line(QWidget* parent) : QLineEdit(parent) { setFrame(false); setReadOnly(true); - setCursorPosition(0); /* displays left text first */ QPalette pal; pal.setColor(QPalette::Window, Qt::transparent); @@ -84,7 +85,16 @@ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); } -Title::Title(QString title, QWidget* parent) : Line(title, parent) { +Line::Line(const QString& text, QWidget* parent) : Line(parent) { + SetText(text); +} + +void Line::SetText(const QString& text) { + setText(text); + setCursorPosition(0); /* displays left text first */ +} + +Title::Title(const QString& title, QWidget* parent) : Line(title, parent) { QFont fnt(font()); fnt.setPixelSize(16); setFont(fnt); @@ -95,7 +105,7 @@ setPalette(pal); } -Section::Section(QString title, QString data, QWidget* parent) : QWidget(parent) { +Section::Section(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -127,7 +137,7 @@ return paragraph; } -LabelledSection::LabelledSection(QString title, QString label, QString data, QWidget* parent) : QWidget(parent) { +LabelledSection::LabelledSection(const QString& title, const QString& label, const QString& data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -135,18 +145,19 @@ // this is not accessible from the object because there's really // no reason to make it accessible... QWidget* content = new QWidget(this); - content->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + 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::Preferred, QSizePolicy::Preferred); + 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); @@ -174,7 +185,7 @@ return paragraph; } -SelectableSection::SelectableSection(QString title, QString data, QWidget* parent) : QWidget(parent) { +SelectableSection::SelectableSection(const QString& title, const QString& data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -203,7 +214,7 @@ return paragraph; } -OneLineSection::OneLineSection(QString title, QString text, QWidget* parent) : QWidget(parent) { +OneLineSection::OneLineSection(const QString& title, const QString& text, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this);