Made New button static in UI
This commit is contained in:
parent
75c87e6fdf
commit
9db5634a6c
2 changed files with 10 additions and 17 deletions
|
@ -153,22 +153,17 @@ Kirigami.ScrollablePage
|
||||||
*/
|
*/
|
||||||
id: filter
|
id: filter
|
||||||
placeholderText: i18nd("kdeconnect-sms", "Filter...")
|
placeholderText: i18nd("kdeconnect-sms", "Filter...")
|
||||||
width: parent.width
|
width: parent.width - newButton.width
|
||||||
height: addButton.height
|
|
||||||
z: 10
|
z: 10
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
if (filter.text != "") {
|
if (filter.text != "") {
|
||||||
if (conversationListModel.isPhoneNumberValid(filter.text)) {
|
if (conversationListModel.isPhoneNumberValid(filter.text)) {
|
||||||
addButton.visible = true
|
|
||||||
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
|
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
|
||||||
} else {
|
} else {
|
||||||
addButton.visible = false
|
|
||||||
filter.width = view.width
|
|
||||||
view.model.setConversationsFilterRole(Qt.DisplayRole)
|
view.model.setConversationsFilterRole(Qt.DisplayRole)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
|
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
|
||||||
filter.width = view.width
|
|
||||||
}
|
}
|
||||||
view.model.setFilterFixedString(filter.text)
|
view.model.setFilterFixedString(filter.text)
|
||||||
|
|
||||||
|
@ -196,32 +191,30 @@ Kirigami.ScrollablePage
|
||||||
Keys.forwardTo: [headerItem]
|
Keys.forwardTo: [headerItem]
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
id: addButton
|
id: newButton
|
||||||
text: i18nd("kdeconnect-sms", "Add")
|
text: i18nd("kdeconnect-sms", "New")
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: view.headerItem.height
|
height: view.headerItem.height
|
||||||
visible: false
|
visible: true
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
|
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
|
||||||
view.headerItem.enabled = false
|
view.headerItem.enabled = false
|
||||||
|
|
||||||
// If the address entered by the user already exists then ignore adding new contact
|
// If the address entered by the user already exists then ignore adding new contact
|
||||||
if (!view.model.isPhoneNumberExists(view.headerItem.text)) {
|
if (!view.model.isPhoneNumberExists(view.headerItem.text) && conversationListModel.isPhoneNumberValid(view.headerItem.text)) {
|
||||||
conversationListModel.createConversationForAddress(view.headerItem.text)
|
conversationListModel.createConversationForAddress(view.headerItem.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
view.headerItem.enabled = true
|
view.headerItem.enabled = true
|
||||||
addButton.visible = false
|
|
||||||
view.headerItem.width = view.width
|
|
||||||
}
|
}
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
event.clicked = true
|
event.clicked = true
|
||||||
addButton.onClicked()
|
newButton.onClicked()
|
||||||
}
|
}
|
||||||
Shortcut {
|
Shortcut {
|
||||||
sequence: "Ctrl+A"
|
sequence: "Ctrl+N"
|
||||||
onActivated: addButton.forceActiveFocus()
|
onActivated: newButton.forceActiveFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,11 +129,11 @@ QString SmsHelper::canonicalizePhoneNumber(const QString& phoneNumber)
|
||||||
|
|
||||||
bool SmsHelper::isPhoneNumberValid(const QString& phoneNumber)
|
bool SmsHelper::isPhoneNumberValid(const QString& phoneNumber)
|
||||||
{
|
{
|
||||||
QString canonicalizedPhoneNumber(phoneNumber);
|
QString canonicalizedNumber = canonicalizePhoneNumber(phoneNumber);
|
||||||
|
|
||||||
// This regular expression matches a wide range of international Phone numbers, minimum of 3 digits and maximum upto 15 digits
|
// This regular expression matches a wide range of international Phone numbers, minimum of 3 digits and maximum upto 15 digits
|
||||||
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
|
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
|
||||||
return validNumberPattern.match(canonicalizedPhoneNumber).hasMatch();
|
return validNumberPattern.match(canonicalizedNumber).hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
class PersonsCache : public QObject {
|
class PersonsCache : public QObject {
|
||||||
|
|
Loading…
Reference in a new issue