From b13763e25da39f59032a9b0b5cf3a11a7e9cae1c Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 15 Dec 2016 15:56:42 +0100 Subject: [PATCH] fix(ui/views/App/MainWindow/ContactEdit): little ui fixes --- .../src/components/contacts/ContactsListModel.cpp | 6 ++++-- .../src/components/contacts/ContactsListModel.hpp | 2 +- .../modules/Common/Form/TransparentTextInput.qml | 10 ++++++---- tests/ui/views/App/MainWindow/ContactEdit.qml | 14 ++++++++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/src/components/contacts/ContactsListModel.cpp b/tests/src/components/contacts/ContactsListModel.cpp index fd6b38a48..0fb852936 100644 --- a/tests/src/components/contacts/ContactsListModel.cpp +++ b/tests/src/components/contacts/ContactsListModel.cpp @@ -86,7 +86,7 @@ ContactModel *ContactsListModel::mapSipAddressToContact (const QString &sipAddre return &friend_->getData(ContactModel::NAME); } -void ContactsListModel::addContact (VcardModel *vcard) { +ContactModel *ContactsListModel::addContact (VcardModel *vcard) { ContactModel *contact = new ContactModel(vcard); App::getInstance()->getEngine()->setObjectOwnership(contact, QQmlEngine::CppOwnership); @@ -98,7 +98,7 @@ void ContactsListModel::addContact (VcardModel *vcard) { ) { qWarning() << "Unable to add friend from vcard:" << vcard; delete contact; - return; + return nullptr; } int row = rowCount(); @@ -106,6 +106,8 @@ void ContactsListModel::addContact (VcardModel *vcard) { beginInsertRows(QModelIndex(), row, row); m_list << contact; endInsertRows(); + + return contact; } void ContactsListModel::removeContact (ContactModel *contact) { diff --git a/tests/src/components/contacts/ContactsListModel.hpp b/tests/src/components/contacts/ContactsListModel.hpp index de3055780..a241b696c 100644 --- a/tests/src/components/contacts/ContactsListModel.hpp +++ b/tests/src/components/contacts/ContactsListModel.hpp @@ -28,7 +28,7 @@ public: public slots: ContactModel *mapSipAddressToContact (const QString &sipAddress) const; - void addContact (VcardModel *vcard); + ContactModel *addContact (VcardModel *vcard); void removeContact (ContactModel *contact); private: diff --git a/tests/ui/modules/Common/Form/TransparentTextInput.qml b/tests/ui/modules/Common/Form/TransparentTextInput.qml index 7921b7fbf..62eefee48 100644 --- a/tests/ui/modules/Common/Form/TransparentTextInput.qml +++ b/tests/ui/modules/Common/Form/TransparentTextInput.qml @@ -3,9 +3,9 @@ import QtQuick 2.7 import Common 1.0 import Common.Styles 1.0 -// =================================================================== +// ============================================================================= // A editable text that has a background color on focus. -// =================================================================== +// ============================================================================= Item { property alias color: textInput.color @@ -13,11 +13,13 @@ Item { property alias inputMethodHints: textInput.inputMethodHints property alias readOnly: textInput.readOnly property alias text: textInput.text + property bool forceFocus: false property bool isInvalid: false property int padding: TransparentTextInputStyle.padding + signal editingFinished - // ----------------------------------------------------------------- + // --------------------------------------------------------------------------- onActiveFocusChanged: { if (activeFocus) { @@ -28,7 +30,7 @@ Item { Rectangle { id: background - color: textInput.activeFocus && !textInput.readOnly + color: (textInput.activeFocus || parent.forceFocus) && !textInput.readOnly ? TransparentTextInputStyle.backgroundColor : // No Style constant, see component name. // It's a `transparent` TextInput. diff --git a/tests/ui/views/App/MainWindow/ContactEdit.qml b/tests/ui/views/App/MainWindow/ContactEdit.qml index 2f7e25a23..87c8e1c8c 100644 --- a/tests/ui/views/App/MainWindow/ContactEdit.qml +++ b/tests/ui/views/App/MainWindow/ContactEdit.qml @@ -30,10 +30,11 @@ ColumnLayout { function _save () { if (_contact) { _contact.endEdit() - _edition = false } else { _contact = ContactsListModel.addContact(_vcard) } + + _edition = false } function _cancel () { @@ -50,8 +51,8 @@ ColumnLayout { descriptionText: qsTr('removeContactDescription'), exitHandler: function (status) { if (status) { + window.setView('Contacts') ContactsListModel.removeContact(_contact) - window.setView('Home') } }, title: qsTr('removeContactTitle') @@ -65,7 +66,7 @@ ColumnLayout { function _setUsername (username) { _vcard.username = username - // Update current text with new username. + // Update current text with new/old username. usernameInput.text = _vcard.username } @@ -114,6 +115,10 @@ ColumnLayout { } Component.onDestruction: { + if (_edition && _contact) { + _contact.abortEdit() + } + // TODO: Remove photo if contact not created. } @@ -174,7 +179,8 @@ ColumnLayout { bold: true pointSize: ContactEditStyle.infoBar.username.fontSize } - + forceFocus: true + readOnly: !_edition text: avatar.username onEditingFinished: _setUsername(text)