Skip to content

Commit

Permalink
Show override cursor for more long-running things
Browse files Browse the repository at this point in the history
Like pasting or clearing the canvas, which block the main thread for a
bit and can appear to be stuck if not for such a cursor switch.
  • Loading branch information
askmeaboutlo0m committed Oct 31, 2024
1 parent 9509f03 commit 09f46aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/desktop/filewrangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "libclient/canvas/paintengine.h"
#include "libclient/document.h"
#include "libclient/import/canvasloaderrunnable.h"
#include "libclient/utils/scopedoverridecursor.h"
#include "libshared/util/paths.h"
#include <QCoreApplication>
#include <QDir>
Expand Down Expand Up @@ -260,6 +261,7 @@ QString FileWrangler::saveSelectionAs(Document *doc) const
&selectedFilter);

if(!filename.isEmpty()) {
utils::ScopedOverrideCursor waitCursor;
doc->saveSelection(filename);
return filename;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,7 @@ void MainWindow::copyText()

void MainWindow::paste()
{
utils::ScopedOverrideCursor waitCursor;
const QMimeData *mimeData = Document::getClipboardData();
if(mimeData && mimeData->hasImage()) {
QPoint pastepos;
Expand Down Expand Up @@ -3612,6 +3613,7 @@ void MainWindow::paste()
// clang-format on
void MainWindow::pasteCentered()
{
utils::ScopedOverrideCursor waitCursor;
const QMimeData *mimeData = Document::getClipboardData();
if(mimeData && mimeData->hasImage()) {
pasteImage(mimeData->imageData().value<QImage>(), nullptr, true);
Expand All @@ -3625,6 +3627,7 @@ void MainWindow::pasteFile()
if(img.isNull()) {
showErrorMessage(tr("The image could not be loaded"));
} else {
utils::ScopedOverrideCursor waitCursor;
pasteImage(img);
}
};
Expand All @@ -3634,11 +3637,14 @@ void MainWindow::pasteFile()

void MainWindow::pasteFilePath(const QString &path)
{
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
QImage img(path);
if(img.isNull()) {
QGuiApplication::restoreOverrideCursor();
showErrorMessage(tr("The image could not be loaded"));
} else {
pasteImage(img);
QGuiApplication::restoreOverrideCursor();
}
}

Expand All @@ -3662,6 +3668,7 @@ void MainWindow::pasteImage(

void MainWindow::dropImage(const QImage &image)
{
utils::ScopedOverrideCursor waitCursor;
pasteImage(image);
}

Expand Down Expand Up @@ -3700,6 +3707,7 @@ void MainWindow::clearOrDelete()
}

// No annotation selected: clear seleted area as usual
utils::ScopedOverrideCursor waitCursor;
m_doc->clearArea();
}

Expand Down

0 comments on commit 09f46aa

Please sign in to comment.