-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rtf popup QMainWindow #3
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,18 @@ | |
|
||
#include "../interop/QtDotNetConverters.h" | ||
|
||
RtfPopup::RtfPopup(System::String^ rtfText, QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) | ||
RtfPopup::RtfPopup(System::String^ rtfText, QWidget* parent, Qt::WindowFlags f) : QMainWindow(nullptr, f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we still take the parent argument if we're always using nullptr? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept the parameter and use it but now I pass |
||
{ | ||
QString text = rtfText->StartsWith("{\\rtf") ? toQString(RtfPipe::Rtf::ToHtml(rtfText)) : Qt::convertFromPlainText(toQString(rtfText), Qt::WhiteSpaceNormal); | ||
QRegularExpression urlFinder(R"REGEX((?<!(?:href="))((?:(?:https?|ftp|file)://|www\.|ftp\.)(?:\([-A-Z0-9+@#/%=~_|$?!:,.]|(?:&)*\)|[-A-Z0-9+@#/%=~_|$?!:,.]|(?:&))*(?:\([-A-Z0-9+@#/%=~+|$?!:,.]|(?:&)*\)|[A-Z0-9+@#/%=~_|$]|(?:&))))REGEX", QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption); | ||
text.replace(urlFinder, R"(<a href="\1">\1</a>)"); | ||
|
||
QLayout* layout = new QGridLayout(this); | ||
setLayout(layout); | ||
setAttribute(Qt::WA_DeleteOnClose); | ||
|
||
QScrollArea* scrollArea = new QScrollArea(this); | ||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | ||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
layout->addWidget(scrollArea); | ||
setCentralWidget(scrollArea); | ||
|
||
QLabel* label = new QLabel(text, scrollArea); | ||
label->setWordWrap(true); | ||
|
@@ -28,6 +28,10 @@ RtfPopup::RtfPopup(System::String^ rtfText, QWidget* parent, Qt::WindowFlags f) | |
label->setTextInteractionFlags(Qt::TextBrowserInteraction); | ||
scrollArea->setWidget(label); | ||
scrollArea->setWidgetResizable(true); | ||
} | ||
|
||
setSizeGripEnabled(true); | ||
void RtfPopup::closeEvent(QCloseEvent* event) | ||
{ | ||
emit closed(); | ||
event->accept(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
using namespace cli; | ||
|
||
#include <QDialog> | ||
#include <QMainWindow> | ||
#include <QCloseEvent> | ||
|
||
class RtfPopup : public QDialog | ||
class RtfPopup : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
RtfPopup(System::String^ rtfText, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); | ||
|
||
signals: | ||
void closed(); | ||
|
||
protected: | ||
void closeEvent(QCloseEvent* event); | ||
Holt59 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New question. The popup's constructor sets
WA_DeleteOnClose
, but it's stack-allocated here. Is there anything guaranteeing we don't end up with a double-free?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never encountered issues with this when testing but I did not manage to find a clear answer for this in Qt documentation so it's probably better to move the
setAttribute
outside of the constructor.