mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3e3fff262e
commit
f0da41c937
3 changed files with 60 additions and 13 deletions
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>535</width>
|
<width>690</width>
|
||||||
<height>517</height>
|
<height>720</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
|
@ -37,8 +37,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>493</width>
|
<width>662</width>
|
||||||
<height>586</height>
|
<height>644</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
@ -219,10 +219,18 @@
|
||||||
<item row="10" column="0">
|
<item row="10" column="0">
|
||||||
<layout class="QHBoxLayout" name="ratingVisibilityWidgets">
|
<layout class="QHBoxLayout" name="ratingVisibilityWidgets">
|
||||||
<item>
|
<item>
|
||||||
<widget class="StarWidget" name="rating" native="true"/>
|
<widget class="StarWidget" name="rating" native="true">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="StarWidget" name="visibility" native="true"/>
|
<widget class="StarWidget" name="visibility" native="true">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::StrongFocus</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -281,8 +289,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>507</width>
|
<width>662</width>
|
||||||
<height>459</height>
|
<height>644</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_5">
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
|
@ -361,8 +369,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>492</width>
|
<width>662</width>
|
||||||
<height>375</height>
|
<height>644</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_6">
|
<layout class="QGridLayout" name="gridLayout_6">
|
||||||
|
@ -671,8 +679,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>323</width>
|
<width>662</width>
|
||||||
<height>130</height>
|
<height>644</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_7">
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
|
@ -846,6 +854,8 @@
|
||||||
<tabstop>coordinates</tabstop>
|
<tabstop>coordinates</tabstop>
|
||||||
<tabstop>divemaster</tabstop>
|
<tabstop>divemaster</tabstop>
|
||||||
<tabstop>buddy</tabstop>
|
<tabstop>buddy</tabstop>
|
||||||
|
<tabstop>rating</tabstop>
|
||||||
|
<tabstop>visibility</tabstop>
|
||||||
<tabstop>suit</tabstop>
|
<tabstop>suit</tabstop>
|
||||||
<tabstop>tagWidget</tabstop>
|
<tabstop>tagWidget</tabstop>
|
||||||
<tabstop>notes</tabstop>
|
<tabstop>notes</tabstop>
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
QPixmap* StarWidget::activeStar = 0;
|
QPixmap* StarWidget::activeStar = 0;
|
||||||
QPixmap* StarWidget::inactiveStar = 0;
|
QPixmap* StarWidget::inactiveStar = 0;
|
||||||
|
@ -52,6 +54,13 @@ void StarWidget::paintEvent(QPaintEvent* event)
|
||||||
|
|
||||||
for(int i = current; i < TOTALSTARS; i++)
|
for(int i = current; i < TOTALSTARS; i++)
|
||||||
p.drawPixmap(i * IMG_SIZE + SPACING, 0, starInactive());
|
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)
|
void StarWidget::setCurrentStars(int value)
|
||||||
|
@ -81,6 +90,7 @@ StarWidget::StarWidget(QWidget* parent, Qt::WindowFlags f):
|
||||||
inactiveStar = new QPixmap();
|
inactiveStar = new QPixmap();
|
||||||
(*inactiveStar) = grayImage(activeStar);
|
(*inactiveStar) = grayImage(activeStar);
|
||||||
}
|
}
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap StarWidget::grayImage(QPixmap* coloredImg)
|
QPixmap StarWidget::grayImage(QPixmap* coloredImg)
|
||||||
|
@ -110,3 +120,28 @@ void StarWidget::setReadOnly(bool r)
|
||||||
{
|
{
|
||||||
readOnly = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@ public slots:
|
||||||
protected:
|
protected:
|
||||||
/*reimp*/ void mouseReleaseEvent(QMouseEvent* );
|
/*reimp*/ void mouseReleaseEvent(QMouseEvent* );
|
||||||
/*reimp*/ void paintEvent(QPaintEvent* );
|
/*reimp*/ void paintEvent(QPaintEvent* );
|
||||||
|
/*reimp*/ void focusInEvent(QFocusEvent*);
|
||||||
|
/*reimp*/ void focusOutEvent(QFocusEvent*);
|
||||||
|
/*reimp*/ void keyPressEvent(QKeyEvent*);
|
||||||
private:
|
private:
|
||||||
int current;
|
int current;
|
||||||
bool readOnly;
|
bool readOnly;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue