comparison src/gui/widgets/text.cc @ 295:b82841e76e79

*: better support on Windows things now look much better in dark mode
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 20:24:09 -0400
parents 9a88e1725fd2
children 6b0768158dcd
comparison
equal deleted inserted replaced
294:99cbc51433e4 295:b82841e76e79
60 60
61 text_edit.setTextInteractionFlags(Qt::TextBrowserInteraction); 61 text_edit.setTextInteractionFlags(Qt::TextBrowserInteraction);
62 text_edit.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 62 text_edit.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
63 text_edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 63 text_edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
64 text_edit.setStyleSheet("background: transparent;"); 64 text_edit.setStyleSheet("background: transparent;");
65 text_edit.setFrameStyle(QFrame::NoFrame);
65 66
66 text_edit.document()->setDocumentMargin(0); 67 text_edit.document()->setDocumentMargin(0);
67 68
68 SetText(text); 69 SetText(text);
69 70
77 QTextCursor cursor = text_edit.textCursor(); 78 QTextCursor cursor = text_edit.textCursor();
78 cursor.setPosition(0); 79 cursor.setPosition(0);
79 text_edit.setTextCursor(cursor); 80 text_edit.setTextCursor(cursor);
80 } 81 }
81 82
82 QSize Paragraph::minimumSizeHint() const { 83 bool Paragraph::hasHeightForWidth() const {
83 return QSize(0, 0); 84 return true;
84 } 85 }
85 86
86 /* highly based upon... some stackoverflow answer for PyQt */ 87 int Paragraph::heightForWidth(int w) const {
87 QSize Paragraph::sizeHint() const {
88 QTextDocument* doc = text_edit.document(); 88 QTextDocument* doc = text_edit.document();
89 doc->adjustSize(); 89 doc->setTextWidth(w);
90 90
91 long h = 0; 91 return doc->size().toSize().height();
92 for (QTextBlock line = doc->begin(); line != doc->end(); line = line.next())
93 h += doc->documentLayout()->blockBoundingRect(line).height();
94
95 return QSize(doc->size().width(), h);
96 } 92 }
97 93
98 QPlainTextEdit* Paragraph::GetLabel() { 94 QPlainTextEdit* Paragraph::GetLabel() {
99 return &text_edit; 95 return &text_edit;
100 } 96 }