Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/implementations/ScriptFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ void ScriptFunctionsHelper::DisplayTextSlot(QWidget* parentWidget, const QString
popup.setWindowTitle(title);
// the size readmes are becoming automatically
popup.resize(492, 366);
popup.exec();
popup.setWindowModality(Qt::ApplicationModal);
popup.show();
QEventLoop loop;
connect(&popup, SIGNAL(closed()), &loop, SLOT(quit()), Qt::DirectConnection);
loop.exec();
Copy link
Owner

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?

Copy link
Contributor Author

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.

}

void ScriptFunctionsHelper::DialogSelectSlot(std::optional<QVector<int>>& resultOut, QWidget* parent, const QString& title, const QVector<QString>& items,
Expand Down
14 changes: 9 additions & 5 deletions src/newstuff/rtfPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the parameter and use it but now I pass nullptr explicitly when needed so that we can still pass other parents.

{
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+@#/%=~_|$?!:,.]|(?:&amp;)*\)|[-A-Z0-9+@#/%=~_|$?!:,.]|(?:&amp;))*(?:\([-A-Z0-9+@#/%=~+|$?!:,.]|(?:&amp;)*\)|[A-Z0-9+@#/%=~_|$]|(?:&amp;))))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);
Expand All @@ -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();
}
11 changes: 9 additions & 2 deletions src/newstuff/rtfPopup.h
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
};