10#include "phonewidgetlister.h"
11#include "phonewidget.h"
13#include <KContacts/Addressee>
16PhoneWidgetLister::PhoneWidgetLister(
QWidget *parent)
17 : KWidgetLister(1, 8, parent)
19 setNumberOfShownWidgetsTo(widgetsMinimum());
20 updateAddRemoveButton();
23PhoneWidgetLister::~PhoneWidgetLister() =
default;
29 setNumberOfShownWidgetsTo(1);
31 setNumberOfShownWidgetsTo(phoneNumbers.
count());
32 const QList<QWidget *> widgetList = widgets();
35 for (
int i = 0; wIt != wEnd; ++wIt, ++i) {
36 auto w = qobject_cast<PhoneWidget *>(*wIt);
37 w->loadPhone(phoneNumbers.
at(i));
42void PhoneWidgetLister::storeContact(KContacts::Addressee &contact)
const
45 const QList<QWidget *> widgetList = widgets();
46 for (QWidget *widget : widgetList) {
47 auto w = qobject_cast<PhoneWidget *>(widget);
48 KContacts::PhoneNumber
number = w->storePhone();
53 contact.setPhoneNumbers(phoneNumbers);
56void PhoneWidgetLister::setReadOnly(
bool readOnly)
58 const QList<QWidget *> widgetList = widgets();
59 for (QWidget *widget : widgetList) {
60 auto w = qobject_cast<PhoneWidget *>(widget);
61 w->setReadOnly(readOnly);
65QWidget *PhoneWidgetLister::createWidget(QWidget *parent)
67 auto w =
new PhoneWidget(parent);
72void PhoneWidgetLister::reconnectWidget(PhoneWidget *w)
79void PhoneWidgetLister::slotAddWidget(PhoneWidget *w)
81 addWidgetAfterThisWidget(w);
82 updateAddRemoveButton();
85void PhoneWidgetLister::slotRemoveWidget(PhoneWidget *w)
87 if (widgets().count() == 1) {
91 updateAddRemoveButton();
95void PhoneWidgetLister::slotPreferredChanged(PhoneWidget *w)
97 const QList<QWidget *> widgetList = widgets();
98 for (QWidget *widget : widgetList) {
100 (
static_cast<PhoneWidget *
>(widget))->setPreferred(
false);
105void PhoneWidgetLister::updateAddRemoveButton()
107 const QList<QWidget *> widgetList = widgets();
108 const int numberOfWidget(widgetList.
count());
109 bool addButtonEnabled =
false;
110 if (numberOfWidget <= widgetsMinimum()) {
111 addButtonEnabled =
true;
112 }
else if (numberOfWidget >= widgetsMaximum()) {
113 addButtonEnabled =
false;
115 addButtonEnabled =
true;
118 for (QWidget *widget : widgetList) {
119 auto w = qobject_cast<PhoneWidget *>(widget);
120 w->updateAddRemoveButton(addButtonEnabled);
124#include "moc_phonewidgetlister.cpp"
A widget for editing the display name of a contact.
KIOCORE_EXPORT QString number(KIO::filesize_t size)
const_reference at(qsizetype i) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype count() const const
bool isEmpty() const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)