summaryrefslogtreecommitdiffstats
path: root/qt-ui/starwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/starwidget.cpp')
-rw-r--r--qt-ui/starwidget.cpp35
1 files changed, 35 insertions, 0 deletions
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 <QDebug>
#include <QMouseEvent>
#include <unistd.h>
+#include <QStyle>
+#include <QStyleOption>
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);
+ }
+ }
+}