-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix pre-release issues with attachment viewer #12244
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4b76a57
453b87b
f35fd1c
8ff701f
f9a6c5e
25ac34c
1e6766d
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 |
---|---|---|
|
@@ -19,19 +19,16 @@ | |
#include "TextAttachmentsEditWidget.h" | ||
#include "TextAttachmentsPreviewWidget.h" | ||
|
||
#include "ui_TextAttachmentsWidget.h" | ||
|
||
#include <QSplitter> | ||
#include <QTextEdit> | ||
#include <QTimer> | ||
#include <QVBoxLayout> | ||
|
||
TextAttachmentsWidget::TextAttachmentsWidget(QWidget* parent) | ||
: QWidget(parent) | ||
, m_ui(new Ui::TextAttachmentsWidget()) | ||
, m_previewUpdateTimer(new QTimer(this)) | ||
, m_mode(attachments::OpenMode::ReadOnly) | ||
{ | ||
m_ui->setupUi(this); | ||
initWidget(); | ||
} | ||
|
||
|
@@ -65,7 +62,15 @@ void TextAttachmentsWidget::updateWidget() | |
} | ||
|
||
m_editWidget->openAttachment(m_attachment, m_mode); | ||
m_previewWidget->openAttachment(m_attachment, attachments::OpenMode::ReadOnly); | ||
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. Removing this line causes a delay (almost 1 second) when a preview is rendered, even with really small plain text files. Is this necessary? Could we use something like this here, or does it break the scrollbars you mentioned in the issue thread?
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. But just implementing the above will do the 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. This line was removed because it caused the preview widget to be loaded 3 times when the edit window is first shown and the preview isn't even visible. How can removing it cause more delay? Not sure on your report here. 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. Maybe the videos will help. This PR: As you can see, this PR has a delay every time Preview dialog is opened. 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. Ahhhhhh, just preview, not edit. The delay is from the 500ms timer for when the attachment text is changed. |
||
} | ||
|
||
void TextAttachmentsWidget::updatePreviewWidget() | ||
{ | ||
m_previewVisible = m_previewWidget->width() > 0; | ||
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. This 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. It's kind of crazy qt doesn't offer an |
||
if (m_previewVisible) { | ||
m_attachment = m_editWidget->getAttachment(); | ||
m_previewWidget->openAttachment(m_attachment, attachments::OpenMode::ReadOnly); | ||
} | ||
} | ||
|
||
void TextAttachmentsWidget::initWidget() | ||
|
@@ -78,28 +83,44 @@ void TextAttachmentsWidget::initWidget() | |
m_previewUpdateTimer->setInterval(500); | ||
|
||
// Only update the preview after a set timeout and if it is visible | ||
connect(m_previewUpdateTimer, &QTimer::timeout, this, [this] { | ||
if (m_previewWidget->width() > 0) { | ||
m_attachment = m_editWidget->getAttachment(); | ||
m_previewWidget->openAttachment(m_attachment, attachments::OpenMode::ReadOnly); | ||
} | ||
}); | ||
connect(m_previewUpdateTimer, &QTimer::timeout, this, &TextAttachmentsWidget::updatePreviewWidget); | ||
connect(m_editWidget, | ||
&TextAttachmentsEditWidget::scrollChanged, | ||
m_previewWidget, | ||
&TextAttachmentsPreviewWidget::matchScroll); | ||
|
||
connect( | ||
m_editWidget, &TextAttachmentsEditWidget::textChanged, m_previewUpdateTimer, QOverload<>::of(&QTimer::start)); | ||
|
||
connect(m_editWidget, &TextAttachmentsEditWidget::previewButtonClicked, [this] { | ||
const auto sizes = m_splitter->sizes(); | ||
const auto previewSize = sizes.value(1, 0) > 0 ? 0 : 1; | ||
m_splitter->setSizes({1, previewSize}); | ||
// Split the display in half if showing the preview widget | ||
const auto previewSize = m_previewWidget->width() > 0 ? 0 : m_splitter->width() / 2; | ||
const auto editSize = m_splitter->width() - previewSize; | ||
m_splitter->setSizes({editSize, previewSize}); | ||
updatePreviewWidget(); | ||
}); | ||
|
||
// Check if the preview panel is manually collapsed or shown | ||
connect(m_splitter, &QSplitter::splitterMoved, this, [this](int, int) { | ||
// Trigger a preview update if it has become visible | ||
auto visible = m_previewWidget->width() > 0; | ||
if (visible && !m_previewVisible) { | ||
updatePreviewWidget(); | ||
} | ||
m_previewVisible = visible; | ||
}); | ||
|
||
m_splitter->addWidget(m_editWidget); | ||
m_splitter->addWidget(m_previewWidget); | ||
// Prevent collapsing of the edit widget | ||
m_splitter->setCollapsible(0, false); | ||
|
||
m_ui->verticalLayout->addWidget(m_splitter); | ||
// Setup this widget with the splitter | ||
auto layout = new QVBoxLayout(this); | ||
layout->setContentsMargins(0, 0, 0, 0); | ||
layout->addWidget(m_splitter); | ||
setLayout(layout); | ||
setObjectName("TextAttachmentsWidget"); | ||
|
||
updateWidget(); | ||
} |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.