Added focus handling to the Date Picker.

Added focus handling for the date picker, this way the user
can use the keyboard to change the date. ( still not implemented )

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-19 15:52:30 -03:00 committed by Dirk Hohndel
parent 70c8bbcc91
commit a7240cd83f
3 changed files with 31 additions and 10 deletions

View file

@ -19,9 +19,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="1"> <item row="2" column="1">
<widget class="KMessageWidget" name="diveNotesMessage" native="true"> <widget class="KMessageWidget" name="diveNotesMessage" native="true"/>
<zorder>scrollArea</zorder>
</widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
@ -248,7 +246,11 @@
</widget> </widget>
</item> </item>
<item row="1" column="0" rowspan="2"> <item row="1" column="0" rowspan="2">
<widget class="DateWidget" name="dateEdit" native="true"/> <widget class="DateWidget" name="dateEdit" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -280,8 +282,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>662</width> <width>100</width>
<height>642</height> <height>30</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
@ -360,8 +362,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>662</width> <width>548</width>
<height>642</height> <height>395</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
@ -670,8 +672,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>662</width> <width>468</width>
<height>642</height> <height>229</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
@ -923,6 +925,7 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>scrollArea</tabstop> <tabstop>scrollArea</tabstop>
<tabstop>dateEdit</tabstop>
<tabstop>airtemp</tabstop> <tabstop>airtemp</tabstop>
<tabstop>watertemp</tabstop> <tabstop>watertemp</tabstop>
<tabstop>location</tabstop> <tabstop>location</tabstop>
@ -937,6 +940,7 @@
<tabstop>scrollArea_2</tabstop> <tabstop>scrollArea_2</tabstop>
<tabstop>scrollArea_3</tabstop> <tabstop>scrollArea_3</tabstop>
<tabstop>scrollArea_4</tabstop> <tabstop>scrollArea_4</tabstop>
<tabstop>photosView</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View file

@ -305,6 +305,7 @@ DateWidget::DateWidget(QWidget *parent) : QWidget(parent),
{ {
setDate(QDate::currentDate()); setDate(QDate::currentDate());
setMinimumSize(QSize(64,64)); setMinimumSize(QSize(64,64));
setFocusPolicy(Qt::StrongFocus);
calendarWidget->setWindowFlags(Qt::FramelessWindowHint); calendarWidget->setWindowFlags(Qt::FramelessWindowHint);
connect(calendarWidget, SIGNAL(activated(QDate)), calendarWidget, SLOT(hide())); connect(calendarWidget, SIGNAL(activated(QDate)), calendarWidget, SLOT(hide()));
@ -352,6 +353,9 @@ void DateWidget::paintEvent(QPaintEvent *event)
painter.setBrush(Qt::black); painter.setBrush(Qt::black);
painter.setFont(font); painter.setFont(font);
painter.drawText(QPoint(32 - metrics.width(day)/2, 45), day); painter.drawText(QPoint(32 - metrics.width(day)/2, 45), day);
if(hasFocus())
painter.drawLine(0, 63, 63, 63);
} }
void DateWidget::mousePressEvent(QMouseEvent *event) void DateWidget::mousePressEvent(QMouseEvent *event)
@ -360,3 +364,14 @@ void DateWidget::mousePressEvent(QMouseEvent *event)
calendarWidget->show(); calendarWidget->show();
} }
void DateWidget::focusInEvent(QFocusEvent *event)
{
setFocus();
QWidget::focusInEvent(event);
}
void DateWidget::focusOutEvent(QFocusEvent *event)
{
QWidget::focusOutEvent(event);
}

View file

@ -100,6 +100,8 @@ public slots:
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void focusInEvent(QFocusEvent *);
void focusOutEvent(QFocusEvent *);
signals: signals:
void dateChanged(const QDate& date); void dateChanged(const QDate& date);
private: private: