Element info widget : set focus to the first line edit

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3807 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-03-05 10:26:09 +00:00
parent af54df2983
commit 8a4efc7fc1
4 changed files with 48 additions and 1 deletions

View File

@@ -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();
}

View File

@@ -38,6 +38,7 @@ class ElementInfoPartWidget : public QWidget {
bool mustShow () const;
void setShow (const bool &);
void setHideShow (const bool &);
void setFocusTolineEdit();
//ATTRIBUTES
private:

View File

@@ -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();
}

View File

@@ -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 <ElementInfoPartWidget *> eipw_list;
bool m_first_activation;
};
#endif // ELEMENTINFOWIDGET_H