Mercurial > minori
diff src/gui/widgets/text.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 5ccb99bfa605 |
line wrap: on
line diff
--- a/src/gui/widgets/text.cpp Sun Oct 01 06:39:47 2023 -0400 +++ b/src/gui/widgets/text.cpp Sun Oct 01 23:15:43 2023 -0400 @@ -10,7 +10,7 @@ namespace TextWidgets { Header::Header(QString title, QWidget* parent) : QWidget(parent) { - setLayout(new QVBoxLayout); + QVBoxLayout* layout = new QVBoxLayout(this); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); static_text_title = new QLabel(title, this); @@ -18,6 +18,7 @@ QFont font = static_text_title->font(); font.setWeight(QFont::Bold); static_text_title->setFont(font); + /* FIXME: is this needed? */ static_text_title->setFixedHeight(16); static_text_line = new QFrame(this); @@ -25,38 +26,38 @@ static_text_line->setFrameShadow(QFrame::Sunken); static_text_line->setFixedHeight(2); - layout()->addWidget(static_text_title); - layout()->addWidget(static_text_line); - layout()->setSpacing(0); - layout()->setContentsMargins(0, 0, 0, 0); + layout->addWidget(static_text_title); + layout->addWidget(static_text_line); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); } -void Header::SetTitle(QString title) { - static_text_title->setText(title); +void Header::SetText(QString text) { + static_text_title->setText(text); } TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { - setLayout(new QVBoxLayout); + QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); QWidget* content = new QWidget(this); - content->setLayout(new QHBoxLayout); + QHBoxLayout* content_layout = new QHBoxLayout(content); paragraph = new Paragraph(data, this); paragraph->setTextInteractionFlags(Qt::NoTextInteraction); paragraph->setAttribute(Qt::WidgetAttribute::WA_TransparentForMouseEvents); paragraph->setWordWrapMode(QTextOption::NoWrap); - content->layout()->addWidget(paragraph); - content->layout()->setSpacing(0); - content->layout()->setContentsMargins(0, 0, 0, 0); + content_layout->addWidget(paragraph); + content_layout->setSpacing(0); + content_layout->setContentsMargins(0, 0, 0, 0); content->setContentsMargins(12, 0, 0, 0); - layout()->addWidget(header); - layout()->addWidget(paragraph); - layout()->setSpacing(0); - layout()->setContentsMargins(0, 0, 0, 0); + layout->addWidget(header); + layout->addWidget(paragraph); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); } Header* TextParagraph::GetHeader() { @@ -69,7 +70,7 @@ LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) : QWidget(parent) { - setLayout(new QVBoxLayout); + QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -97,10 +98,10 @@ content->setContentsMargins(12, 0, 0, 0); - layout()->addWidget(header); - layout()->addWidget(content); - layout()->setSpacing(0); - layout()->setContentsMargins(0, 0, 0, 0); + layout->addWidget(header); + layout->addWidget(content); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); } Header* LabelledTextParagraph::GetHeader() { @@ -116,24 +117,24 @@ } SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { - setLayout(new QVBoxLayout); + QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); QWidget* content = new QWidget(this); - content->setLayout(new QHBoxLayout); + QHBoxLayout* content_layout = new QHBoxLayout(content); paragraph = new Paragraph(data, content); - content->layout()->addWidget(paragraph); - content->layout()->setSpacing(0); - content->layout()->setContentsMargins(0, 0, 0, 0); + content_layout->addWidget(paragraph); + content_layout->setSpacing(0); + content_layout->setContentsMargins(0, 0, 0, 0); content->setContentsMargins(12, 0, 0, 0); - layout()->addWidget(header); - layout()->addWidget(content); - layout()->setSpacing(0); - layout()->setContentsMargins(0, 0, 0, 0); + layout->addWidget(header); + layout->addWidget(content); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); } Header* SelectableTextParagraph::GetHeader() { @@ -158,8 +159,19 @@ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } +void Paragraph::SetText(QString text) { + QTextDocument* document = new QTextDocument(this); + document->setDocumentLayout(new QPlainTextDocumentLayout(document)); + document->setPlainText(text); + setDocument(document); +} + /* highly based upon... some stackoverflow answer for PyQt */ QSize Paragraph::minimumSizeHint() const { + return QSize(0, 0); +} + +QSize Paragraph::sizeHint() const { QTextDocument* doc = document(); doc->adjustSize(); long h = 0; @@ -169,16 +181,23 @@ return QSize(doc->size().width(), h); } -QSize Paragraph::sizeHint() const { - return minimumSizeHint(); -} +Title::Title(QString title, QWidget* parent) : Paragraph(title, parent) { + setReadOnly(true); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setWordWrapMode(QTextOption::NoWrap); + setFrameShape(QFrame::NoFrame); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); -/* this is still actually useful, so we'll keep it */ -void SetPlainTextEditData(QPlainTextEdit* text_edit, QString data) { - QTextDocument* document = new QTextDocument(text_edit); - document->setDocumentLayout(new QPlainTextDocumentLayout(document)); - document->setPlainText(data); - text_edit->setDocument(document); + QFont fnt(font()); + fnt.setPointSize(12); + setFont(fnt); + + QPalette pal(palette()); + pal.setColor(QPalette::Window, Qt::transparent); + pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); + setPalette(pal); } } // namespace TextWidgets