Commit f556fde8 authored by Ronan's avatar Ronan
Browse files

feat(views/App/MainWindow/ContactEdit): username can be edited

parent add3cffb
......@@ -137,6 +137,7 @@
<file>ui/modules/Common/Form/CheckBoxText.qml</file>
<file>ui/modules/Common/Form/ExclusiveButtons.qml</file>
<file>ui/modules/Common/Form/ListForm.qml</file>
<file>ui/modules/Common/Form/ScrollableTextEdit.qml</file>
<file>ui/modules/Common/Form/SmallButton.qml</file>
<file>ui/modules/Common/Form/TextButtonA.qml</file>
<file>ui/modules/Common/Form/TextButtonB.qml</file>
......
......@@ -30,13 +30,12 @@ QString ContactModel::getUsername () const {
);
}
bool ContactModel::setUsername (const QString &username) {
if (username.length() == 0)
return false;
void ContactModel::setUsername (const QString &username) {
if (username.length() == 0 || username == getUsername())
return;
return !m_linphone_friend->setName(
Utils::qStringToLinphoneString(username)
);
if (!m_linphone_friend->setName(Utils::qStringToLinphoneString(username)))
emit contactUpdated();
}
// -------------------------------------------------------------------
......@@ -62,12 +61,12 @@ QString ContactModel::getAvatar () const {
));
}
bool ContactModel::setAvatar (const QString &path) {
void ContactModel::setAvatar (const QString &path) {
// 1. Try to copy photo in avatars folder.
QFile file(path);
if (!file.exists() || QImageReader::imageFormat(path).size() == 0)
return false;
return;
QFileInfo info(file);
QString uuid = QUuid::createUuid().toString();
......@@ -79,7 +78,7 @@ bool ContactModel::setAvatar (const QString &path) {
file_id;
if (!file.copy(dest))
return false;
return;
qInfo() << QStringLiteral("Update avatar of `%1`. (path=%2)")
.arg(getUsername()).arg(dest);
......@@ -116,7 +115,7 @@ bool ContactModel::setAvatar (const QString &path) {
emit contactUpdated();
return true;
return;
}
// -------------------------------------------------------------------
......
......@@ -89,10 +89,10 @@ signals:
private:
QString getUsername () const;
bool setUsername (const QString &username);
void setUsername (const QString &username);
QString getAvatar () const;
bool setAvatar (const QString &path);
void setAvatar (const QString &path);
QVariantList getSipAddresses () const;
void setSipAddresses (const QVariantList &sip_addresses);
......
import QtQuick 2.7
import QtQuick 2.7 as Quick
import Common 1.0
import Common.Styles 1.0
// ===================================================================
Item {
property alias text: textEdit.text
property alias font: textEdit.font
property alias color: textEdit.color
signal editionFinished
// -----------------------------------------------------------------
function _handleEditionFinished () {
textEdit.cursorPosition = 0
editionFinished()
}
// -----------------------------------------------------------------
Rectangle {
anchors.fill: flick
color: textEdit.activeFocus && !textEdit.readOnly
? TextEditStyle.backgroundColor.focused
: TextEditStyle.backgroundColor.normal
InvertedMouseArea {
anchors.fill: parent
enabled: textEdit.activeFocus
onPressed: textEdit.focus = false
}
}
Flickable {
id: flick
// See: http://doc.qt.io/qt-5/qml-qtquick-texttextEdit.html
function _ensureVisible (r) {
if (contentX >= r.x) {
contentX = r.x
} else if (contentX + width <= r.x + r.width) {
contentX = r.x + r.width - width
}
if (contentY >= r.y) {
contentY = r.y
} else if (contentY + height <= r.y + r.height) {
contentY = r.y + r.height - height
}
}
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
clip: true
contentHeight: textEdit.paintedHeight
contentWidth: textEdit.paintedWidth
interactive: textEdit.activeFocus
Quick.TextEdit {
id: textEdit
color: activeFocus && !readOnly
? TextEditStyle.textColor.focused
: TextEditStyle.textColor.normal
padding: ListFormStyle.value.text.padding
selectByMouse: true
wrapMode: Text.Wrap
Keys.onEscapePressed: focus = false
Keys.onReturnPressed: focus = false
height: flick.height
width: flick.width
onCursorRectangleChanged: flick._ensureVisible(cursorRectangle)
onEditingFinished: _handleEditionFinished()
}
}
}
......@@ -8,16 +8,13 @@ import Common.Styles 1.0
TextEdit {
id: textEdit
color: activeFocus
color: activeFocus && !readOnly
? TextEditStyle.textColor.focused
: TextEditStyle.textColor.normal
padding: ListFormStyle.value.text.padding
selectByMouse: true
verticalAlignment: TextEdit.AlignVCenter
width: !activeFocus
? parent.width
: contentWidth + padding * 2
wrapMode: Text.Wrap
Keys.onEscapePressed: focus = false
Keys.onReturnPressed: focus = false
......@@ -29,9 +26,10 @@ TextEdit {
}
Rectangle {
color: parent.activeFocus
anchors.fill: textEdit
color: textEdit.activeFocus && !readOnly
? TextEditStyle.backgroundColor.focused
: TextEditStyle.backgroundColor.normal
anchors.fill: parent
z: -1
}
}
......@@ -38,6 +38,7 @@ CheckBoxText 1.0 Form/CheckBoxText.qml
ExclusiveButtons 1.0 Form/ExclusiveButtons.qml
LightButton 1.0 Form/LightButton.qml
ListForm 1.0 Form/ListForm.qml
ScrollableTextEdit 1.0 Form/ScrollableTextEdit.qml
TextButtonA 1.0 Form/TextButtonA.qml
TextButtonB 1.0 Form/TextButtonB.qml
TextEdit 1.0 Form/TextEdit.qml
......
......@@ -70,8 +70,6 @@ Item {
// and http://doc.qt.io/qt-5/richtext-html-subset.html
textFormat: Text.RichText // To supports links and imgs.
wrapMode: Text.Wrap
onHoveredLinkChanged: _handleHoveredLink(hoveredLink)
onLinkActivated: Qt.openUrlExternally(link)
......
......@@ -96,8 +96,12 @@ ColumnLayout {
}
}
TextEdit {
ScrollableTextEdit {
id: editUsername
Layout.fillWidth: true
Layout.preferredHeight: ContactEditStyle.infoBar.buttons.size
color: ContactEditStyle.infoBar.username.color
font {
......@@ -106,6 +110,11 @@ ColumnLayout {
}
text: avatar.username
onEditionFinished: {
_contact.username = text
text = _contact.username
}
}
ActionBar {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment