diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 65bee8c9f..c33250557 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -200,6 +200,8 @@ SET(MULTIMC_SOURCES # GUI - widgets widgets/Common.cpp widgets/Common.h + widgets/FocusLineEdit.cpp + widgets/FocusLineEdit.h widgets/IconLabel.cpp widgets/IconLabel.h widgets/LabeledToolButton.cpp diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui index f9d59a56b..6b875ff46 100644 --- a/application/dialogs/NewInstanceDialog.ui +++ b/application/dialogs/NewInstanceDialog.ui @@ -9,7 +9,7 @@ 0 0 - 277 + 281 404 @@ -118,7 +118,7 @@ - + false @@ -192,6 +192,13 @@ + + + FocusLineEdit + QLineEdit +
widgets/FocusLineEdit.h
+
+
instNameTextBox groupBox diff --git a/application/widgets/FocusLineEdit.cpp b/application/widgets/FocusLineEdit.cpp new file mode 100644 index 000000000..139126c80 --- /dev/null +++ b/application/widgets/FocusLineEdit.cpp @@ -0,0 +1,25 @@ +#include "FocusLineEdit.h" +#include + +FocusLineEdit::FocusLineEdit(QWidget *parent) : QLineEdit(parent) +{ + _selectOnMousePress = false; +} + +void FocusLineEdit::focusInEvent(QFocusEvent *e) +{ + QLineEdit::focusInEvent(e); + selectAll(); + _selectOnMousePress = true; +} + +void FocusLineEdit::mousePressEvent(QMouseEvent *me) +{ + QLineEdit::mousePressEvent(me); + if (_selectOnMousePress) + { + selectAll(); + _selectOnMousePress = false; + } + qDebug() << selectedText(); +} diff --git a/application/widgets/FocusLineEdit.h b/application/widgets/FocusLineEdit.h new file mode 100644 index 000000000..6d1c78a87 --- /dev/null +++ b/application/widgets/FocusLineEdit.h @@ -0,0 +1,17 @@ +#include + +class FocusLineEdit : public QLineEdit +{ + Q_OBJECT +public: + FocusLineEdit(QWidget *parent); + virtual ~FocusLineEdit() + { + } + +protected: + void focusInEvent(QFocusEvent *e); + void mousePressEvent(QMouseEvent *me); + + bool _selectOnMousePress; +};