10#include "mailwidgetlister.h"
11#include "mailwidget.h"
13#include <KContacts/Addressee>
16MailWidgetLister::MailWidgetLister(
QWidget *parent)
17 : KWidgetLister(1, 8, parent)
19 setNumberOfShownWidgetsTo(widgetsMinimum());
20 updateAddRemoveButton();
23MailWidgetLister::~MailWidgetLister() =
default;
27 KContacts::Email::List mailList = contact.emailList();
28 if (mailList.isEmpty()) {
29 setNumberOfShownWidgetsTo(1);
31 setNumberOfShownWidgetsTo(mailList.count());
35 for (
int i = 0; wIt != wEnd; ++wIt, ++i) {
36 auto w = qobject_cast<MailWidget *>(*wIt);
37 w->setMail(mailList.at(i));
45 KContacts::Email::List emailList;
46 emailList.reserve(widgetList.
count());
47 for (
QWidget *widget : widgetList) {
48 auto w = qobject_cast<MailWidget *>(widget);
50 if (newEmail.isValid()) {
51 emailList << newEmail;
54 contact.setEmailList(emailList);
57void MailWidgetLister::setReadOnly(
bool readOnly)
60 for (
QWidget *widget : widgetList) {
61 auto w = qobject_cast<MailWidget *>(widget);
62 w->setReadOnly(readOnly);
68 auto w =
new MailWidget(parent);
73void MailWidgetLister::reconnectWidget(MailWidget *w)
80void MailWidgetLister::slotAddWidget(MailWidget *w)
82 addWidgetAfterThisWidget(w);
83 updateAddRemoveButton();
86void MailWidgetLister::slotRemoveWidget(MailWidget *w)
88 if (widgets().count() == 1) {
92 updateAddRemoveButton();
96void MailWidgetLister::slotPreferredChanged(MailWidget *w)
99 for (
QWidget *widget : widgetList) {
101 (
static_cast<MailWidget *
>(widget))->setPreferred(
false);
106void MailWidgetLister::updateAddRemoveButton()
109 const int numberOfWidget(widgetList.
count());
110 bool addButtonEnabled =
false;
111 if (numberOfWidget <= widgetsMinimum()) {
112 addButtonEnabled =
true;
113 }
else if (numberOfWidget >= widgetsMaximum()) {
114 addButtonEnabled =
false;
116 addButtonEnabled =
true;
119 for (
QWidget *widget : widgetList) {
120 auto w = qobject_cast<MailWidget *>(widget);
121 w->updateAddRemoveButton(addButtonEnabled);
125#include "moc_mailwidgetlister.cpp"
A widget for editing the display name of a contact.
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype count() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)