Improved unit property edit handling while it has focus
Dieser Commit ist enthalten in:
Ursprung
4359c7a5ad
Commit
fb204a8217
49
client/src/widget/lineeditwithfocusoutsignal.hpp
Normale Datei
49
client/src/widget/lineeditwithfocusoutsignal.hpp
Normale Datei
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* client/src/widget/lineeditwithfocusoutsignal.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2021 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_CLIENT_WIDGET_LINEEDITWITHFOCUSOUTSIGNAL_HPP
|
||||
#define TRAINTASTIC_CLIENT_WIDGET_LINEEDITWITHFOCUSOUTSIGNAL_HPP
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
class LineEditWithFocusOutSignal : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
void focusOutEvent(QFocusEvent* event) final
|
||||
{
|
||||
QLineEdit::focusOutEvent(event);
|
||||
emit focusOut();
|
||||
}
|
||||
|
||||
public:
|
||||
explicit LineEditWithFocusOutSignal(const QString& text, QWidget* parent = nullptr) :
|
||||
QLineEdit(text, parent)
|
||||
{
|
||||
}
|
||||
|
||||
signals:
|
||||
void focusOut();
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -24,13 +24,14 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include "lineeditwithfocusoutsignal.hpp"
|
||||
#include "../network/unitproperty.hpp"
|
||||
#include "../utils/enum.hpp"
|
||||
|
||||
UnitPropertyEdit::UnitPropertyEdit(UnitProperty& property, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_property{property},
|
||||
m_valueLineEdit{new QLineEdit(m_property.toString(), this)},
|
||||
m_valueLineEdit{new LineEditWithFocusOutSignal(m_property.toString(), this)},
|
||||
m_unitComboBox{new QComboBox(this)}
|
||||
{
|
||||
setEnabled(m_property.getAttributeBool(AttributeName::Enabled, true));
|
||||
@ -55,7 +56,8 @@ UnitPropertyEdit::UnitPropertyEdit(UnitProperty& property, QWidget *parent) :
|
||||
connect(&m_property, &UnitProperty::valueChanged, this,
|
||||
[this]()
|
||||
{
|
||||
m_valueLineEdit->setText(m_property.toString());
|
||||
if(!m_valueLineEdit->hasFocus())
|
||||
m_valueLineEdit->setText(m_property.toString());
|
||||
|
||||
const qint64 unit = m_property.unitValue();
|
||||
for(int i = 0; i < m_unitComboBox->count(); i++)
|
||||
@ -72,6 +74,11 @@ UnitPropertyEdit::UnitPropertyEdit(UnitProperty& property, QWidget *parent) :
|
||||
m_valueLineEdit->setReadOnly(!m_property.isWritable());
|
||||
l->addWidget(m_valueLineEdit, 1);
|
||||
connect(m_valueLineEdit, &QLineEdit::textEdited, &m_property, QOverload<const QString&>::of(&AbstractProperty::setValueString));
|
||||
connect(m_valueLineEdit, &LineEditWithFocusOutSignal::focusOut, this,
|
||||
[this]()
|
||||
{
|
||||
m_valueLineEdit->setText(m_property.toString());
|
||||
});
|
||||
|
||||
for(qint64 value : enumValues(m_property.unitName()))
|
||||
{
|
||||
|
||||
@ -26,8 +26,8 @@
|
||||
#include <QWidget>
|
||||
|
||||
class UnitProperty;
|
||||
class QLineEdit;
|
||||
class QComboBox;
|
||||
class LineEditWithFocusOutSignal;
|
||||
|
||||
class UnitPropertyEdit : public QWidget
|
||||
{
|
||||
@ -35,7 +35,7 @@ class UnitPropertyEdit : public QWidget
|
||||
|
||||
protected:
|
||||
UnitProperty& m_property;
|
||||
QLineEdit* m_valueLineEdit;
|
||||
LineEditWithFocusOutSignal* m_valueLineEdit;
|
||||
QComboBox* m_unitComboBox;
|
||||
|
||||
public:
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren