diff --git a/sources/ui/elementinfopartwidget.cpp b/sources/ui/elementinfopartwidget.cpp index a21d661b5..d0bacaaff 100644 --- a/sources/ui/elementinfopartwidget.cpp +++ b/sources/ui/elementinfopartwidget.cpp @@ -87,3 +87,11 @@ void ElementInfoPartWidget::setShow(const bool &s) { void ElementInfoPartWidget::setHideShow(const bool &hide) { ui -> checkBox -> setHidden(hide); } + +/** + * @brief ElementInfoPartWidget::setFocusTolineEdit + * Set the focus to the line edit + */ +void ElementInfoPartWidget::setFocusTolineEdit() { + ui->line_edit->setFocus(); +} diff --git a/sources/ui/elementinfopartwidget.h b/sources/ui/elementinfopartwidget.h index f40445077..6f9f5fa3e 100644 --- a/sources/ui/elementinfopartwidget.h +++ b/sources/ui/elementinfopartwidget.h @@ -38,6 +38,7 @@ class ElementInfoPartWidget : public QWidget { bool mustShow () const; void setShow (const bool &); void setHideShow (const bool &); + void setFocusTolineEdit(); //ATTRIBUTES private: diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 406d34bff..42c44ab81 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -33,7 +33,8 @@ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : QWidget(parent), ui(new Ui::ElementInfoWidget), element_(elmt), - elmt_info(elmt->elementInformations()) + elmt_info(elmt->elementInformations()), + m_first_activation (true) { ui->setupUi(this); buildInterface(); @@ -89,6 +90,27 @@ QUndoCommand* ElementInfoWidget::associatedUndo() const { return nullptr; } +/** + * @brief ElementInfoWidget::event + * Reimplemented from QWidget::event + * Only give focus to the first line edit at first activation. + * After send the event to QWidget. + * @param event + * @return + */ +bool ElementInfoWidget::event(QEvent *event) +{ + if (m_first_activation) + { + if (event -> type() == QEvent::WindowActivate || event -> type() == QEvent::Show) + { + QTimer::singleShot(250, this, SLOT(firstActivated())); + m_first_activation = false; + } + } + return(QWidget::event(event)); +} + /** * @brief ElementInfoWidget::buildInterface * Build the widget @@ -122,3 +144,12 @@ void ElementInfoWidget::fillInfo() { eipw->setHideShow(true); } } + +/** + * @brief ElementInfoWidget::firstActivated + * Slot activated when this widget is show. + * Set the focus to the first line edit provided by this widget + */ +void ElementInfoWidget::firstActivated() { + eipw_list.first() -> setFocusTolineEdit(); +} diff --git a/sources/ui/elementinfowidget.h b/sources/ui/elementinfowidget.h index 769a262a4..8ffa81aa3 100644 --- a/sources/ui/elementinfowidget.h +++ b/sources/ui/elementinfowidget.h @@ -45,16 +45,23 @@ class ElementInfoWidget : public QWidget { bool apply(); QUndoCommand* associatedUndo () const; + protected: + virtual bool event(QEvent *event); + private: void buildInterface(); void fillInfo(); + private slots: + void firstActivated(); + //ATTRIBUTES private: Ui::ElementInfoWidget *ui; Element *element_; DiagramContext elmt_info; QList eipw_list; + bool m_first_activation; }; #endif // ELEMENTINFOWIDGET_H