commit 0d54d3b762e4aae2450d218971fc667448a0e164
Author: Richard Kimberly Heck <[email protected]>
Date:   Mon May 27 23:20:45 2019 -0400

    Allow click on the 'spinner' to cancel export.
---
 src/frontends/qt4/GuiClickableLabel.cpp |   31 +++++++++++++++++++++++++++
 src/frontends/qt4/GuiClickableLabel.h   |   35 +++++++++++++++++++++++++++++++
 src/frontends/qt4/GuiView.cpp           |   16 +++++++++++++-
 src/frontends/qt4/GuiView.h             |    2 +
 src/frontends/qt4/Makefile.am           |    2 +
 5 files changed, 85 insertions(+), 1 deletions(-)

diff --git a/src/frontends/qt4/GuiClickableLabel.cpp 
b/src/frontends/qt4/GuiClickableLabel.cpp
new file mode 100644
index 0000000..31a5be5
--- /dev/null
+++ b/src/frontends/qt4/GuiClickableLabel.cpp
@@ -0,0 +1,31 @@
+// -*- C++ -*-
+/**
+ * \file GuiClickableLabel.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include "config.h"
+
+#include "GuiClickableLabel.h"
+
+namespace lyx {
+namespace frontend {
+
+GuiClickableLabel::GuiClickableLabel(QWidget * parent)
+       : QLabel(parent)
+{}
+
+GuiClickableLabel::~GuiClickableLabel()
+{}
+
+void GuiClickableLabel::mouseReleaseEvent(QMouseEvent *) {
+               Q_EMIT clicked();
+       }
+
+}
+}
+
+#include "moc_GuiClickableLabel.cpp"
diff --git a/src/frontends/qt4/GuiClickableLabel.h 
b/src/frontends/qt4/GuiClickableLabel.h
new file mode 100644
index 0000000..4ae4905
--- /dev/null
+++ b/src/frontends/qt4/GuiClickableLabel.h
@@ -0,0 +1,35 @@
+// -*- C++ -*-
+/**
+ * \file GuiClickableLabel.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUICLICKABLELABEL_H
+#define GUICLICKABLELABEL_H
+
+#include <QLabel>
+
+namespace lyx {
+namespace frontend {
+
+// see https://wiki.qt.io/Clickable_QLabel
+class GuiClickableLabel : public QLabel {
+       Q_OBJECT
+public:
+       explicit GuiClickableLabel(QWidget * parent);
+
+       ~GuiClickableLabel();
+
+Q_SIGNALS:
+       void clicked();
+
+protected:
+       void mouseReleaseEvent(QMouseEvent *);
+};
+
+}
+}
+#endif
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 98dba1d..8ef8ca5 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -19,6 +19,7 @@
 #include "FileDialog.h"
 #include "FontLoader.h"
 #include "GuiApplication.h"
+#include "GuiClickableLabel.h"
 #include "GuiCommandBuffer.h"
 #include "GuiCompleter.h"
 #include "GuiKeySymbol.h"
@@ -610,7 +611,7 @@ GuiView::GuiView(int id)
        setAcceptDrops(true);
 
        // add busy indicator to statusbar
-       QLabel * busylabel = new QLabel(statusBar());
+       GuiClickableLabel * busylabel = new GuiClickableLabel(statusBar());
        statusBar()->addPermanentWidget(busylabel);
        search_mode mode = theGuiApp()->imageSearchMode();
        QString fn = toqstr(lyx::libFileSearch("images", "busy", "gif", 
mode).absFileName());
@@ -623,6 +624,7 @@ GuiView::GuiView(int id)
                busylabel, SLOT(show()));
        connect(&d.processing_thread_watcher_, SIGNAL(finished()),
                busylabel, SLOT(hide()));
+       connect(busylabel, SIGNAL(clicked()), this, 
SLOT(checkCancelBackground()));
 
        QFontMetrics const fm(statusBar()->fontMetrics());
        int const iconheight = max(int(d.normalIconSize), fm.height());
@@ -713,6 +715,18 @@ void GuiView::disableShellEscape()
 }
 
 
+void GuiView::checkCancelBackground()
+{
+       docstring const ttl = _("Cancel Export?");
+       docstring const msg = _("Do you want to cancel the background export 
process?");
+       int const ret =
+               Alert::prompt(ttl, msg, 1, 1,
+                       _("&Cancel export"), _("Co&ntinue"));
+       if (ret == 0)
+               Systemcall::killscript();
+}
+
+
 QVector<GuiWorkArea*> GuiView::GuiViewPrivate::guiWorkAreas()
 {
        QVector<GuiWorkArea*> areas;
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index fa36f7f..007e4f9 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -237,6 +237,8 @@ private Q_SLOTS:
        void resetWindowTitle();
 
        ///
+       void checkCancelBackground();
+       ///
        void on_currentWorkAreaChanged(GuiWorkArea *);
        ///
        void onBufferViewChanged();
diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am
index e2e3e1c..b09e2b9 100644
--- a/src/frontends/qt4/Makefile.am
+++ b/src/frontends/qt4/Makefile.am
@@ -80,6 +80,7 @@ SOURCEFILES = \
        GuiChanges.cpp \
        GuiCharacter.cpp \
        GuiCitation.cpp \
+       GuiClickableLabel.cpp \
        GuiClipboard.cpp \
        GuiCommandBuffer.cpp \
        GuiCommandEdit.cpp \
@@ -197,6 +198,7 @@ MOCHEADER = \
        GuiChanges.h \
        GuiCharacter.h \
        GuiCitation.h \
+       GuiClickableLabel.h \
        GuiClipboard.h \
        GuiCommandBuffer.h \
        GuiCommandEdit.h \

Reply via email to