From 75e3d12f2eb32d94f12cd1a127aa9b202c6f5ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 10 Dec 2013 23:37:29 +0100 Subject: [PATCH] fixed key events in goToFlow TODO: add eventFilter to goToFlow edit... --- YACReader/goto_flow.cpp | 33 ++++++++++++--------------- YACReader/goto_flow.h | 3 ++- YACReader/goto_flow_gl.cpp | 39 ++++++++++++-------------------- YACReader/goto_flow_gl.h | 7 +++--- YACReader/goto_flow_widget.cpp | 21 +++++++++++++---- YACReader/goto_flow_widget.h | 1 + YACReader/main_window_viewer.cpp | 2 ++ YACReader/viewer.cpp | 6 ++++- common/pictureflow.cpp | 6 +++++ common/yacreader_flow_gl.cpp | 6 +++++ 10 files changed, 70 insertions(+), 54 deletions(-) diff --git a/YACReader/goto_flow.cpp b/YACReader/goto_flow.cpp index 512f943f..f6325b0f 100644 --- a/YACReader/goto_flow.cpp +++ b/YACReader/goto_flow.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -71,6 +71,20 @@ GoToFlow::~GoToFlow() worker->deleteLater(); } +void GoToFlow::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: + QApplication::sendEvent(flow,event); + return; + default: + break; + } + + GoToFlowWidget::keyPressEvent(event); +} + void GoToFlow::centerSlide(int slide) { if(flow->centerIndex()!=slide) @@ -188,23 +202,6 @@ void GoToFlow::updateImageData() updateTimer->stop(); } -bool GoToFlow::eventFilter(QObject *target, QEvent *event) -{ - if (event->type() == QEvent::KeyPress) - { - QKeyEvent *keyEvent = static_cast(event); - int key = keyEvent->key(); - if((key==Qt::Key_Return)|| - (key==Qt::Key_Enter)|| - (key==Qt::Key_Space)|| - (key==Qt::Key_Left)|| - (key==Qt::Key_Right)|| - (key==Qt::Key_S)) - this->keyPressEvent(keyEvent); - } - return QWidget::eventFilter(target, event); -} - void GoToFlow::wheelEvent(QWheelEvent * event) { if(event->delta()<0) diff --git a/YACReader/goto_flow.h b/YACReader/goto_flow.h index 26e07565..eb2c2112 100644 --- a/YACReader/goto_flow.h +++ b/YACReader/goto_flow.h @@ -23,6 +23,7 @@ class SlideInitializer; class PageLoader; class YACReaderFlow; class PictureFlow; +class QKeyEvent; class GoToFlow : public GoToFlowWidget { @@ -31,9 +32,9 @@ public: GoToFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); ~GoToFlow(); bool ready; //comic is ready for read. - bool eventFilter(QObject *target, QEvent *event); private: YACReaderFlow * flow; + void keyPressEvent(QKeyEvent* event); //Comic * comic; QSize imageSize; diff --git a/YACReader/goto_flow_gl.cpp b/YACReader/goto_flow_gl.cpp index 210e1600..8f315c7d 100644 --- a/YACReader/goto_flow_gl.cpp +++ b/YACReader/goto_flow_gl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "configuration.h" @@ -32,12 +33,6 @@ GoToFlowGL::GoToFlowGL(QWidget* parent, FlowType flowType) resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); - //install eventFilter - //flow->installEventFilter(this); - //edit->installEventFilter(this); - //centerButton->installEventFilter(this); - //goToButton->installEventFilter(this); - this->setCursor(QCursor(Qt::ArrowCursor)); } @@ -46,25 +41,6 @@ GoToFlowGL::~GoToFlowGL() delete flow; } -bool GoToFlowGL::eventFilter(QObject *target, QEvent *event) -{ - if (event->type() == QEvent::KeyPress) - { - QKeyEvent *keyEvent = static_cast(event); - int key = keyEvent->key(); - if((key==Qt::Key_Return)|| - (key==Qt::Key_Enter)|| - (key==Qt::Key_Space)|| - (key==Qt::Key_Left)|| - (key==Qt::Key_Right)|| - (key==Qt::Key_S)) - this->keyPressEvent(keyEvent); - } - return QWidget::eventFilter(target, event); -} - - - void GoToFlowGL::reset() { flow->reset(); @@ -167,3 +143,16 @@ void GoToFlowGL::updateConfig(QSettings * settings) } +void GoToFlowGL::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Left: case Qt::Key_Right: case Qt::Key_Up: + QApplication::sendEvent(flow,event); + return; + default: + break; + } + + GoToFlowWidget::keyPressEvent(event); +} diff --git a/YACReader/goto_flow_gl.h b/YACReader/goto_flow_gl.h index 1e51cf1c..5b6ed1b5 100644 --- a/YACReader/goto_flow_gl.h +++ b/YACReader/goto_flow_gl.h @@ -10,6 +10,7 @@ class QIntValidator; class QPushButton; class QPushButton; class QSize; +class QKeyEvent; class GoToFlowGL : public GoToFlowWidget { @@ -23,7 +24,6 @@ public: void setNumSlides(unsigned int slides); void setImageReady(int index,const QByteArray & image); void updateSize(); - bool eventFilter(QObject *target, QEvent *event); void updateConfig(QSettings * settings); @@ -31,10 +31,9 @@ signals: void goToPage(unsigned int page); private: YACReaderPageFlowGL * flow; - - + void keyPressEvent(QKeyEvent* event); //Comic * comic; QSize imageSize; }; -#endif \ No newline at end of file +#endif diff --git a/YACReader/goto_flow_widget.cpp b/YACReader/goto_flow_widget.cpp index 69909e5d..1f0c98c8 100644 --- a/YACReader/goto_flow_widget.cpp +++ b/YACReader/goto_flow_widget.cpp @@ -26,6 +26,8 @@ GoToFlowWidget::GoToFlowWidget(QWidget * parent) mainLayout->setSpacing(0); setLayout(mainLayout); + + //toolBar->installEventFilter(this); } GoToFlowWidget::~GoToFlowWidget() { @@ -53,12 +55,21 @@ void GoToFlowWidget::keyPressEvent(QKeyEvent* event) case Qt::Key_S: QCoreApplication::sendEvent(this->parent(),event); break; - case Qt::Key_Left: case Qt::Key_Right: - //if(event->modifiers() == Qt::ControlModifier) - //flow->keyPressEvent(event); - //QCoreApplication::sendEvent(flow,event); - break; } event->accept(); } + +/*bool GoToFlowWidget::eventFilter(QObject * target, QEvent * event) +{ + if(event->type() == QEvent::KeyPress) + { + QKeyEvent * e = static_cast(event); + if(e->key()==Qt::Key_S || e->key() == Qt::Key_Space) + { + this->keyPressEvent(e); + return true; + } + } + return QWidget::eventFilter(target,event); +}*/ diff --git a/YACReader/goto_flow_widget.h b/YACReader/goto_flow_widget.h index 78debdd5..e4f42b2c 100644 --- a/YACReader/goto_flow_widget.h +++ b/YACReader/goto_flow_widget.h @@ -34,6 +34,7 @@ public slots: protected: void keyPressEvent(QKeyEvent* event); + //bool eventFilter(QObject *, QEvent *); }; diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index e8591692..67d79cec 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -273,6 +273,7 @@ void MainWindowViewer::createActions() prevAction = new QAction(tr("&Previous"),this); prevAction->setIcon(QIcon(":/images/viewer_toolbar/previous.png")); prevAction->setShortcut(Qt::Key_Left); + prevAction->setShortcutContext(Qt::WidgetShortcut); prevAction->setToolTip(tr("Go to previous page")); prevAction->setDisabled(true); connect(prevAction, SIGNAL(triggered()),viewer,SLOT(prev())); @@ -280,6 +281,7 @@ void MainWindowViewer::createActions() nextAction = new QAction(tr("&Next"),this); nextAction->setIcon(QIcon(":/images/viewer_toolbar/next.png")); nextAction->setShortcut(Qt::Key_Right); + nextAction->setShortcutContext(Qt::WidgetShortcut); nextAction->setToolTip(tr("Go to next page")); nextAction->setDisabled(true); connect(nextAction, SIGNAL(triggered()),viewer,SLOT(next())); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 63ce813b..7be5af6c 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -82,6 +82,7 @@ shouldOpenPrevious(false) else goToFlow = new GoToFlow(this,Configuration::getConfiguration().getFlowType()); + goToFlow->setFocusPolicy(Qt::StrongFocus); goToFlow->hide(); showGoToFlowAnimation = new QPropertyAnimation(goToFlow,"pos"); showGoToFlowAnimation->setDuration(150); @@ -255,7 +256,10 @@ void Viewer::updatePage() emit backgroundChanges(); emit(pageAvailable(true)); - setFocus(Qt::ShortcutFocusReason); + if(goToFlow->isHidden()) + setFocus(Qt::ShortcutFocusReason); + else + goToFlow->setFocus(Qt::OtherFocusReason); delete previousPage; if(currentPage->isNull()) diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index e0f4f032..5aa4ba3f 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -1244,6 +1244,12 @@ void PictureFlow::keyPressEvent(QKeyEvent* event) return; } + if(event->key() == Qt::Key_Up) + { + //TODO emit selected signal + return; + } + event->ignore(); } diff --git a/common/yacreader_flow_gl.cpp b/common/yacreader_flow_gl.cpp index a8d89e34..a7aba4c4 100644 --- a/common/yacreader_flow_gl.cpp +++ b/common/yacreader_flow_gl.cpp @@ -952,6 +952,12 @@ void YACReaderFlowGL::keyPressEvent(QKeyEvent *event) return; } + if(event->key() == Qt::Key_Up) + { + emit selected(centerIndex()); + return; + } + event->ignore(); }