use qshortcuts instead of the event filter for tab management key events

This commit is contained in:
Jean-Francois Dockes 2015-08-10 11:28:08 +02:00
parent a319f09411
commit 455543a71e
2 changed files with 48 additions and 32 deletions

View file

@ -21,9 +21,6 @@
#include <list> #include <list>
#include <utility> #include <utility>
#ifndef NO_NAMESPACES
using std::pair;
#endif /* NO_NAMESPACES */
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qthread.h> #include <qthread.h>
@ -48,6 +45,7 @@ using std::pair;
#include <qclipboard.h> #include <qclipboard.h>
#include <qimage.h> #include <qimage.h>
#include <qurl.h> #include <qurl.h>
#include <QShortcut>
#include "debuglog.h" #include "debuglog.h"
#include "pathut.h" #include "pathut.h"
@ -62,6 +60,12 @@ using std::pair;
#include "docseqhist.h" #include "docseqhist.h"
#include "rclhelp.h" #include "rclhelp.h"
static const QKeySequence closeKS(Qt::Key_Escape);
static const QKeySequence nextDocInTabKS(Qt::ShiftModifier+Qt::Key_Down);
static const QKeySequence prevDocInTabKS(Qt::ShiftModifier+Qt::Key_Up);
static const QKeySequence closeTabKS(Qt::ControlModifier+Qt::Key_W);
static const QKeySequence printTabKS(Qt::ControlModifier+Qt::Key_P);
// Subclass plainToRich to add <termtag>s and anchors to the preview text // Subclass plainToRich to add <termtag>s and anchors to the preview text
class PlainToRichQtPreview : public PlainToRich { class PlainToRichQtPreview : public PlainToRich {
public: public:
@ -281,6 +285,17 @@ void Preview::init()
this, SLOT(currentChanged(int))); this, SLOT(currentChanged(int)));
connect(bt, SIGNAL(clicked()), this, SLOT(closeCurrentTab())); connect(bt, SIGNAL(clicked()), this, SLOT(closeCurrentTab()));
connect(new QShortcut(closeKS, this), SIGNAL (activated()),
this, SLOT (close()));
connect(new QShortcut(nextDocInTabKS, this), SIGNAL (activated()),
this, SLOT (emitShowNext()));
connect(new QShortcut(prevDocInTabKS, this), SIGNAL (activated()),
this, SLOT (emitShowPrev()));
connect(new QShortcut(closeTabKS, this), SIGNAL (activated()),
this, SLOT (closeCurrentTab()));
connect(new QShortcut(printTabKS, this), SIGNAL (activated()),
this, SIGNAL (printCurrentPreviewRequest()));
m_dynSearchActive = false; m_dynSearchActive = false;
m_canBeep = true; m_canBeep = true;
if (prefs.pvwidth > 100) { if (prefs.pvwidth > 100) {
@ -291,6 +306,26 @@ void Preview::init()
m_justCreated = true; m_justCreated = true;
} }
void Preview::emitShowNext()
{
if (m_loading)
return;
PreviewTextEdit *edit = currentEditor();
if (edit) {
emit(showNext(this, m_searchId, edit->m_docnum));
}
}
void Preview::emitShowPrev()
{
if (m_loading)
return;
PreviewTextEdit *edit = currentEditor();
if (edit) {
emit(showPrev(this, m_searchId, edit->m_docnum));
}
}
void Preview::closeEvent(QCloseEvent *e) void Preview::closeEvent(QCloseEvent *e)
{ {
LOGDEB(("Preview::closeEvent. m_loading %d\n", m_loading)); LOGDEB(("Preview::closeEvent. m_loading %d\n", m_loading));
@ -334,39 +369,14 @@ bool Preview::eventFilter(QObject *target, QEvent *event)
return false; return false;
} }
LOGDEB2(("Preview::eventFilter: keyEvent\n"));
PreviewTextEdit *edit = currentEditor(); PreviewTextEdit *edit = currentEditor();
QKeyEvent *keyEvent = (QKeyEvent *)event; QKeyEvent *keyEvent = (QKeyEvent *)event;
if (keyEvent->key() == Qt::Key_Escape) {
close(); if (m_dynSearchActive) {
return true;
} else if (keyEvent->key() == Qt::Key_Down &&
(keyEvent->modifiers() & Qt::ShiftModifier)) {
LOGDEB2(("Preview::eventFilter: got Shift-Up\n"));
if (edit)
emit(showNext(this, m_searchId, edit->m_docnum));
return true;
} else if (keyEvent->key() == Qt::Key_Up &&
(keyEvent->modifiers() & Qt::ShiftModifier)) {
LOGDEB2(("Preview::eventFilter: got Shift-Down\n"));
if (edit)
emit(showPrev(this, m_searchId, edit->m_docnum));
return true;
} else if (keyEvent->key() == Qt::Key_W &&
(keyEvent->modifiers() & Qt::ControlModifier)) {
LOGDEB2(("Preview::eventFilter: got ^W\n"));
closeCurrentTab();
return true;
} else if (keyEvent->key() == Qt::Key_P &&
(keyEvent->modifiers() & Qt::ControlModifier)) {
LOGDEB2(("Preview::eventFilter: got ^P\n"));
emit(printCurrentPreviewRequest());
return true;
} else if (m_dynSearchActive) {
if (keyEvent->key() == Qt::Key_F3) { if (keyEvent->key() == Qt::Key_F3) {
LOGDEB2(("Preview::eventFilter: got F3\n")); LOGDEB2(("Preview::eventFilter: got F3\n"));
doSearch(searchTextCMB->currentText(), true, false); doSearch(searchTextCMB->currentText(), true,
(keyEvent->modifiers() & Qt::ShiftModifier) != 0);
return true; return true;
} }
if (target != searchTextCMB) if (target != searchTextCMB)

View file

@ -132,14 +132,20 @@ class Preview : public QWidget {
friend class PreviewTextEdit; friend class PreviewTextEdit;
public slots: public slots:
// Search stuff
virtual void searchTextChanged(const QString& text); virtual void searchTextChanged(const QString& text);
virtual void searchTextFromIndex(int); virtual void searchTextFromIndex(int);
virtual void doSearch(const QString& str, bool next, bool reverse, virtual void doSearch(const QString& str, bool next, bool reverse,
bool wo = false); bool wo = false);
virtual void nextPressed(); virtual void nextPressed();
virtual void prevPressed(); virtual void prevPressed();
// Tabs management
virtual void currentChanged(int); virtual void currentChanged(int);
virtual void closeCurrentTab(); virtual void closeCurrentTab();
virtual void emitShowNext();
virtual void emitShowPrev();
virtual void emitSaveDocToFile(); virtual void emitSaveDocToFile();
virtual void togglePlainPre(); virtual void togglePlainPre();