Skip to content

Commit ce4708c

Browse files
gui: fix top of text preview being unclickable (closes #231)
1 parent ead7759 commit ce4708c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/gui/previews/TextPreview.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QScrollBar>
55
#include <QStyleOption>
66
#include <QTextBlock>
7+
#include <QTimer>
78
#include <QToolBar>
89
#include <QVBoxLayout>
910

@@ -221,6 +222,7 @@ TextPreview::TextPreview(FileViewer* fileViewer_, Window* window_, QWidget* pare
221222

222223
void TextPreview::setText(const QString& text, const QString& extension) {
223224
this->editor->setText(text, extension);
225+
this->recomputeToolbarVisibility();
224226
}
225227

226228
void TextPreview::setEditing(bool editing) const {
@@ -230,19 +232,33 @@ void TextPreview::setEditing(bool editing) const {
230232
this->cancelAction->setVisible(editing);
231233
this->fileViewer->getNavBar()->setDisabled(editing);
232234
this->window->freezeActions(editing, true, false);
235+
this->recomputeToolbarVisibility();
233236
}
234237

235238
void TextPreview::setReadOnly(bool readOnly) const {
236239
this->editAction->setVisible(!readOnly);
237240
this->saveAction->setVisible(false);
238241
this->cancelAction->setVisible(false);
242+
this->recomputeToolbarVisibility();
239243
}
240244

241245
void TextPreview::resizeEvent(QResizeEvent* event) {
242246
QWidget::resizeEvent(event);
243247
auto width = this->width();
244-
if (auto* scrollbar = this->editor->verticalScrollBar()) {
248+
if (const auto* scrollbar = this->editor->verticalScrollBar()) {
245249
width -= scrollbar->sizeHint().width();
246250
}
247251
this->toolbar->setFixedSize(width, 64);
252+
this->recomputeToolbarVisibility();
253+
}
254+
255+
void TextPreview::recomputeToolbarVisibility() const {
256+
// must be delayed a single frame
257+
QTimer::singleShot(0, this, [this] {
258+
QRegion reg;
259+
reg += this->toolbar->actionGeometry(this->editAction);
260+
reg += this->toolbar->actionGeometry(this->saveAction);
261+
reg += this->toolbar->actionGeometry(this->cancelAction);
262+
this->toolbar->setMask(reg);
263+
});
248264
}

src/gui/previews/TextPreview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class TextPreview : public QWidget {
108108
protected:
109109
void resizeEvent(QResizeEvent* event) override;
110110

111+
void recomputeToolbarVisibility() const;
112+
111113
private:
112114
FileViewer* fileViewer;
113115
Window* window;

0 commit comments

Comments
 (0)