From 2afd2bfeb3ddfca2b22124be9f9d90c615fd0ed5 Mon Sep 17 00:00:00 2001 From: Edric Milaret <edric.ladent-milaret@savoirfairelinux.com> Date: Tue, 21 Jul 2015 17:12:25 -0400 Subject: [PATCH] contact: add choose dialog for contact with multiple contact method - Add a little popup that let you choose the contactmethod you want to use when you doubleclick on a Contact who have more than one. Refs #77968 Change-Id: Iec645756afda419c97496d58a9816b748b480bc0 --- RingWinClient.pro | 9 ++++--- callwidget.cpp | 24 ++++++++++------- callwidget.ui | 9 ------- contactdelegate.cpp | 5 +++- contactmethodpicker.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ contactmethodpicker.h | 51 ++++++++++++++++++++++++++++++++++++ contactmethodpicker.ui | 39 ++++++++++++++++++++++++++++ 7 files changed, 172 insertions(+), 22 deletions(-) create mode 100644 contactmethodpicker.cpp create mode 100644 contactmethodpicker.h create mode 100644 contactmethodpicker.ui diff --git a/RingWinClient.pro b/RingWinClient.pro index 42ef5bc..9e9feb1 100644 --- a/RingWinClient.pro +++ b/RingWinClient.pro @@ -49,7 +49,8 @@ SOURCES += main.cpp\ videooverlay.cpp \ imdelegate.cpp \ contactdialog.cpp \ - contactpicker.cpp + contactpicker.cpp \ + contactmethodpicker.cpp HEADERS += mainwindow.h \ callwidget.h \ @@ -74,7 +75,8 @@ HEADERS += mainwindow.h \ videooverlay.h \ imdelegate.h \ contactdialog.h \ - contactpicker.h + contactpicker.h \ + contactmethodpicker.h FORMS += mainwindow.ui \ callwidget.ui \ @@ -89,7 +91,8 @@ FORMS += mainwindow.ui \ videoview.ui \ videooverlay.ui \ contactdialog.ui \ - contactpicker.ui + contactpicker.ui \ + contactmethodpicker.ui win32: LIBS += -lole32 -luuid -lshlwapi diff --git a/callwidget.cpp b/callwidget.cpp index 670e632..0fad742 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -41,6 +41,7 @@ #include "windowscontactbackend.h" #include "contactdialog.h" #include "contactpicker.h" +#include "contactmethodpicker.h" CallWidget::CallWidget(QWidget *parent) : NavWidget(Main ,parent), @@ -125,7 +126,6 @@ CallWidget::CallWidget(QWidget *parent) : connect(copyAction, &QAction::triggered, [=]() { QApplication::clipboard()->setText(contactMethod->uri()); }); - if (not contactMethod->contact()) { auto addNew = new QAction("Add to new contact", this); menu.addAction(addNew); @@ -373,19 +373,25 @@ CallWidget::on_contactView_doubleClicked(const QModelIndex &index) if (not index.isValid()) return; - ContactMethod* uri; + ContactMethod* uri = nullptr; auto var = index.child(0,0).data( static_cast<int>(Person::Role::Object)); if (var.isValid()) { Person* person = var.value<Person*>(); - if (person->phoneNumbers().size() > 0) { - uri = person->phoneNumbers().at(0); // FIXME: A person can have multiple contact method - if (uri) { - auto outCall = CallModel::instance()->dialingCall(person->formattedName()); - outCall->setDialNumber(uri); - outCall->performAction(Call::Action::ACCEPT); - } + if (person->phoneNumbers().size() == 1) { + uri = person->phoneNumbers().at(0); + } else if (person->phoneNumbers().size() > 1) { + ContactMethodPicker dlg(person->phoneNumbers()); + auto pos = QCursor::pos(); + dlg.move(pos.x(), pos.y()); + if (dlg.exec()) + uri = dlg.getSelected(); + } + if (uri) { + auto outCall = CallModel::instance()->dialingCall(person->formattedName()); + outCall->setDialNumber(uri); + outCall->performAction(Call::Action::ACCEPT); } } } diff --git a/callwidget.ui b/callwidget.ui index f1a0d8f..6a522eb 100644 --- a/callwidget.ui +++ b/callwidget.ui @@ -315,15 +315,6 @@ <property name="sizeAdjustPolicy"> <enum>QAbstractScrollArea::AdjustIgnored</enum> </property> - <property name="resizeMode"> - <enum>QListView::Fixed</enum> - </property> - <property name="layoutMode"> - <enum>QListView::SinglePass</enum> - </property> - <property name="wordWrap"> - <bool>false</bool> - </property> </widget> </item> </layout> diff --git a/contactdelegate.cpp b/contactdelegate.cpp index 79c806f..c8f0565 100644 --- a/contactdelegate.cpp +++ b/contactdelegate.cpp @@ -83,7 +83,10 @@ ContactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, break; } default: - /* more than one, for now don't show any of the contact methods */ + painter->drawText(QRect(rect.left()+sizeImage_+5, + rect.top() + rect.height()/2, + rect.width(), rect.height()/2), + opt.displayAlignment, "<Multiple contact methods>"); break; } } diff --git a/contactmethodpicker.cpp b/contactmethodpicker.cpp new file mode 100644 index 0000000..6a87e8f --- /dev/null +++ b/contactmethodpicker.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2015 by Savoir-Faire Linux * + * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* + * * + * 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 3 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, see <http://www.gnu.org/licenses/>. * + **************************************************************************/ + +#include "contactmethodpicker.h" +#include "ui_contactmethodpicker.h" + +#include "contactmethod.h" + +ContactMethodPicker::ContactMethodPicker(const Person::ContactMethods& cM, QWidget *parent) : + QDialog(parent), + ui(new Ui::ContactMethodPicker), + contactMethods_(cM) +{ + ui->setupUi(this); + + this->setWindowFlags(Qt::CustomizeWindowHint); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup); + + for (auto contactMethod : cM) { + auto item = new QListWidgetItem(); + item->setText(contactMethod->uri()); + ui->contactMethodListWidget->addItem(item); + } +} + +ContactMethodPicker::~ContactMethodPicker() +{ + delete ui; +} + +void +ContactMethodPicker::on_contactMethodListWidget_clicked(const QModelIndex &index) +{ + index_ = index.row(); + accept(); +} + +ContactMethod* +ContactMethodPicker::getSelected() const +{ + return contactMethods_.at(index_); +} diff --git a/contactmethodpicker.h b/contactmethodpicker.h new file mode 100644 index 0000000..9f8fef7 --- /dev/null +++ b/contactmethodpicker.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2015 by Savoir-Faire Linux * + * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* + * * + * 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 3 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, see <http://www.gnu.org/licenses/>. * + **************************************************************************/ + +#ifndef CONTACTMETHODPICKER_H +#define CONTACTMETHODPICKER_H + +#include <QDialog> + +#include "person.h" +#include "personmodel.h" + +namespace Ui { +class ContactMethodPicker; +} + +class ContactMethodPicker final : public QDialog +{ + Q_OBJECT + +public: + explicit ContactMethodPicker(const Person::ContactMethods &cM, QWidget *parent = 0); + ~ContactMethodPicker(); + + ContactMethod* getSelected() const; + +//UI SLOTS +private slots: + void on_contactMethodListWidget_clicked(const QModelIndex &index); + +private: + Ui::ContactMethodPicker *ui; + const Person::ContactMethods& contactMethods_; + int index_; +}; + +#endif // CONTACTMETHODPICKER_H diff --git a/contactmethodpicker.ui b/contactmethodpicker.ui new file mode 100644 index 0000000..2e5ec14 --- /dev/null +++ b/contactmethodpicker.ui @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ContactMethodPicker</class> + <widget class="QDialog" name="ContactMethodPicker"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>93</width> + <height>93</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>0</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QListWidget" name="contactMethodListWidget"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> -- GitLab