From f0da41c937b9381e67a57b8103bbf2d4aca7bb39 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 20 Dec 2013 11:33:22 -0200 Subject: Added Keyboard Navigation for the Star Widget Keys up and down to increase / decrease stars and also fixed focus policy for it. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/maintab.ui | 34 ++++++++++++++++++++++------------ qt-ui/starwidget.cpp | 35 +++++++++++++++++++++++++++++++++++ qt-ui/starwidget.h | 4 +++- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 7dec3aa8f..846fb4f12 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -6,8 +6,8 @@ 0 0 - 535 - 517 + 690 + 720 @@ -37,8 +37,8 @@ 0 0 - 493 - 586 + 662 + 644 @@ -219,10 +219,18 @@ - + + + Qt::StrongFocus + + - + + + Qt::StrongFocus + + @@ -281,8 +289,8 @@ 0 0 - 507 - 459 + 662 + 644 @@ -361,8 +369,8 @@ 0 0 - 492 - 375 + 662 + 644 @@ -671,8 +679,8 @@ 0 0 - 323 - 130 + 662 + 644 @@ -846,6 +854,8 @@ coordinates divemaster buddy + rating + visibility suit tagWidget notes diff --git a/qt-ui/starwidget.cpp b/qt-ui/starwidget.cpp index 12b400124..59e625f35 100644 --- a/qt-ui/starwidget.cpp +++ b/qt-ui/starwidget.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include QPixmap* StarWidget::activeStar = 0; QPixmap* StarWidget::inactiveStar = 0; @@ -52,6 +54,13 @@ void StarWidget::paintEvent(QPaintEvent* event) for(int i = current; i < TOTALSTARS; i++) p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive()); + + if(hasFocus()){ + QStyleOptionFocusRect option; + option.initFrom(this); + option.backgroundColor = palette().color(QPalette::Background); + style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &p, this); + } } void StarWidget::setCurrentStars(int value) @@ -81,6 +90,7 @@ StarWidget::StarWidget(QWidget* parent, Qt::WindowFlags f): inactiveStar = new QPixmap(); (*inactiveStar) = grayImage(activeStar); } + setFocusPolicy(Qt::StrongFocus); } QPixmap StarWidget::grayImage(QPixmap* coloredImg) @@ -110,3 +120,28 @@ void StarWidget::setReadOnly(bool r) { readOnly = r; } + +void StarWidget::focusInEvent(QFocusEvent* event) +{ + setFocus(); + QWidget::focusInEvent(event); +} + +void StarWidget::focusOutEvent(QFocusEvent* event) +{ + QWidget::focusOutEvent(event); +} + + +void StarWidget::keyPressEvent(QKeyEvent* event) +{ + if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Right){ + if (currentStars() < TOTALSTARS){ + setCurrentStars( currentStars()+1); + } + }else if(event->key() == Qt::Key_Down || event->key() == Qt::Key_Left){ + if(currentStars() > 0){ + setCurrentStars( currentStars()-1); + } + } +} diff --git a/qt-ui/starwidget.h b/qt-ui/starwidget.h index 9620bc62e..6bbaafc85 100644 --- a/qt-ui/starwidget.h +++ b/qt-ui/starwidget.h @@ -27,7 +27,9 @@ public slots: protected: /*reimp*/ void mouseReleaseEvent(QMouseEvent* ); /*reimp*/ void paintEvent(QPaintEvent* ); - + /*reimp*/ void focusInEvent(QFocusEvent*); + /*reimp*/ void focusOutEvent(QFocusEvent*); + /*reimp*/ void keyPressEvent(QKeyEvent*); private: int current; bool readOnly; -- cgit v1.2.3-70-g09d2