Mercurial > minori
diff src/gui/widgets/text.cpp @ 75:d3e9310598b1
*: refactor some stuff
text: "TextParagraph"s are now called sections, because that's the
actual word for it :P
text: new classes: Line and OneLineSection, solves many problems with
paragraphs that are only one line long (ex. going out of bounds)
http: reworked http stuff to allow threaded get requests, also moved it
to its own file to (hopefully) remove clutter
eventually I'll make a threaded post request method and use that in
the "basic" function
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 04 Oct 2023 01:42:30 -0400 |
parents | 5ccb99bfa605 |
children | 3364fadc8a36 |
line wrap: on
line diff
--- a/src/gui/widgets/text.cpp Tue Oct 03 06:12:43 2023 -0400 +++ b/src/gui/widgets/text.cpp Wed Oct 04 01:42:30 2023 -0400 @@ -1,9 +1,7 @@ #include "gui/widgets/text.h" #include "core/session.h" -#include <QDebug> #include <QFrame> #include <QLabel> -#include <QPixmap> #include <QTextBlock> #include <QVBoxLayout> @@ -36,7 +34,68 @@ static_text_title->setText(text); } -TextParagraph::TextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { +/* inherits QPlainTextEdit and gives a much more reasonable minimum size */ +Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { + setTextInteractionFlags(Qt::TextBrowserInteraction); + setFrameShape(QFrame::NoFrame); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + QPalette pal; + pal.setColor(QPalette::Window, Qt::transparent); + setPalette(pal); + + 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; + for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next()) { + h += doc->documentLayout()->blockBoundingRect(line).height(); + } + return QSize(doc->size().width(), h); +} + +/* 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) { + setFrame(false); + setReadOnly(true); + + QPalette pal; + pal.setColor(QPalette::Window, Qt::transparent); + setPalette(pal); + + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); +} + +Title::Title(QString title, QWidget* parent) : Line(title, parent) { + QFont fnt(font()); + fnt.setPixelSize(16); + setFont(fnt); + + QPalette pal(palette()); + pal.setColor(QPalette::Window, Qt::transparent); + pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); + setPalette(pal); +} + +Section::Section(QString title, QString data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -60,15 +119,15 @@ layout->setContentsMargins(0, 0, 0, 0); } -Header* TextParagraph::GetHeader() { +Header* Section::GetHeader() { return header; } -Paragraph* TextParagraph::GetParagraph() { +Paragraph* Section::GetParagraph() { return paragraph; } -LabelledTextParagraph::LabelledTextParagraph(QString title, QString label, QString data, QWidget* parent) +LabelledSection::LabelledSection(QString title, QString label, QString data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); @@ -104,19 +163,19 @@ layout->setContentsMargins(0, 0, 0, 0); } -Header* LabelledTextParagraph::GetHeader() { +Header* LabelledSection::GetHeader() { return header; } -Paragraph* LabelledTextParagraph::GetLabels() { +Paragraph* LabelledSection::GetLabels() { return labels; } -Paragraph* LabelledTextParagraph::GetParagraph() { +Paragraph* LabelledSection::GetParagraph() { return paragraph; } -SelectableTextParagraph::SelectableTextParagraph(QString title, QString data, QWidget* parent) : QWidget(parent) { +SelectableSection::SelectableSection(QString title, QString data, QWidget* parent) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(this); header = new Header(title, this); @@ -137,67 +196,41 @@ layout->setContentsMargins(0, 0, 0, 0); } -Header* SelectableTextParagraph::GetHeader() { +Header* SelectableSection::GetHeader() { return header; } -Paragraph* SelectableTextParagraph::GetParagraph() { +Paragraph* SelectableSection::GetParagraph() { return paragraph; } -/* inherits QPlainTextEdit and gives a much more reasonable minimum size */ -Paragraph::Paragraph(QString text, QWidget* parent) : QPlainTextEdit(text, parent) { - setTextInteractionFlags(Qt::TextBrowserInteraction); - setFrameShape(QFrame::NoFrame); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +OneLineSection::OneLineSection(QString title, QString text, QWidget* parent) : QWidget(parent) { + QVBoxLayout* layout = new QVBoxLayout(this); + + header = new Header(title, this); - QPalette pal; - pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); - setPalette(pal); + QWidget* content = new QWidget(this); + QHBoxLayout* content_layout = new QHBoxLayout(content); + + line = new Line(text, content); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); -} + content_layout->addWidget(line); + content_layout->setSpacing(0); + content_layout->setContentsMargins(0, 0, 0, 0); + content->setContentsMargins(12, 0, 0, 0); -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); + layout->addWidget(header); + layout->addWidget(content); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); } -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); +Header* OneLineSection::GetHeader() { + return header; } -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); - - QFont fnt(font()); - fnt.setPixelSize(16); - setFont(fnt); - - QPalette pal(palette()); - pal.setColor(QPalette::Window, Qt::transparent); - pal.setColor(QPalette::Text, QColor(0x00, 0x33, 0x99)); - setPalette(pal); +Line* OneLineSection::GetLine() { + return line; } } // namespace TextWidgets