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
|
||||
placeholderText: i18nd("kdeconnect-sms", "Filter...")
|
||||
width: parent.width
|
||||
height: addButton.height
|
||||
width: parent.width - newButton.width
|
||||
z: 10
|
||||
onTextChanged: {
|
||||
if (filter.text != "") {
|
||||
if (conversationListModel.isPhoneNumberValid(filter.text)) {
|
||||
addButton.visible = true
|
||||
view.model.setConversationsFilterRole(ConversationListModel.SenderRole)
|
||||
} else {
|
||||
addButton.visible = false
|
||||
filter.width = view.width
|
||||
view.model.setConversationsFilterRole(Qt.DisplayRole)
|
||||
}
|
||||
} else {
|
||||
view.model.setConversationsFilterRole(ConversationListModel.ConversationIdRole)
|
||||
filter.width = view.width
|
||||
}
|
||||
view.model.setFilterFixedString(filter.text)
|
||||
|
||||
|
@ -196,32 +191,30 @@ Kirigami.ScrollablePage
|
|||
Keys.forwardTo: [headerItem]
|
||||
|
||||
Button {
|
||||
id: addButton
|
||||
text: i18nd("kdeconnect-sms", "Add")
|
||||
id: newButton
|
||||
text: i18nd("kdeconnect-sms", "New")
|
||||
anchors.right: parent.right
|
||||
height: view.headerItem.height
|
||||
visible: false
|
||||
visible: true
|
||||
|
||||
onClicked: {
|
||||
// We have to disable the filter temporarily in order to avoid getting key inputs accidently while processing the request
|
||||
view.headerItem.enabled = false
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
view.headerItem.enabled = true
|
||||
addButton.visible = false
|
||||
view.headerItem.width = view.width
|
||||
}
|
||||
Keys.onReturnPressed: {
|
||||
event.clicked = true
|
||||
addButton.onClicked()
|
||||
newButton.onClicked()
|
||||
}
|
||||
Shortcut {
|
||||
sequence: "Ctrl+A"
|
||||
onActivated: addButton.forceActiveFocus()
|
||||
sequence: "Ctrl+N"
|
||||
onActivated: newButton.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,11 +129,11 @@ QString SmsHelper::canonicalizePhoneNumber(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
|
||||
QRegularExpression validNumberPattern(QStringLiteral("^(\\d{3,15})$"));
|
||||
return validNumberPattern.match(canonicalizedPhoneNumber).hasMatch();
|
||||
return validNumberPattern.match(canonicalizedNumber).hasMatch();
|
||||
}
|
||||
|
||||
class PersonsCache : public QObject {
|
||||
|
|
Loading…
Reference in a new issue