10#include "messagingwidgetlister.h"
11#include "messagingwidget.h"
13#include <KContacts/Addressee>
16MessagingWidgetLister::MessagingWidgetLister(
QWidget *parent)
17 : KWidgetLister(1, 8, parent)
19 setNumberOfShownWidgetsTo(widgetsMinimum());
20 updateAddRemoveButton();
23MessagingWidgetLister::~MessagingWidgetLister() =
default;
27 const auto imaddresses = contact.imppList();
28 if (imaddresses.isEmpty()) {
29 setNumberOfShownWidgetsTo(1);
31 setNumberOfShownWidgetsTo(imaddresses.count());
32 const QList<QWidget *> widgetList = widgets();
35 for (
int i = 0; wIt != wEnd; ++wIt, ++i) {
36 auto w = qobject_cast<MessagingWidget *>(*wIt);
37 w->setIMAddress(imaddresses.at(i));
42void MessagingWidgetLister::storeContact(KContacts::Addressee &contact)
const
44 KContacts::Impp::List imaddresses;
45 const QList<QWidget *> widgetList = widgets();
46 for (QWidget *widget : widgetList) {
47 auto w = qobject_cast<MessagingWidget *>(widget);
48 imaddresses << w->imAddress();
50 contact.setImppList(imaddresses);
53void MessagingWidgetLister::setReadOnly(
bool readOnly)
55 const QList<QWidget *> widgetList = widgets();
56 for (QWidget *widget : widgetList) {
57 auto w = qobject_cast<MessagingWidget *>(widget);
58 w->setReadOnly(readOnly);
62QWidget *MessagingWidgetLister::createWidget(QWidget *parent)
64 auto w =
new MessagingWidget(parent);
69void MessagingWidgetLister::reconnectWidget(MessagingWidget *w)
76void MessagingWidgetLister::slotPreferredChanged(MessagingWidget *w)
78 const QList<QWidget *> widgetList = widgets();
79 for (QWidget *widget : widgetList) {
81 (
static_cast<MessagingWidget *
>(widget))->setPreferred(
false);
86void MessagingWidgetLister::slotAddWidget(MessagingWidget *w)
88 addWidgetAfterThisWidget(w);
89 updateAddRemoveButton();
92void MessagingWidgetLister::slotRemoveWidget(MessagingWidget *w)
94 if (widgets().count() == 1) {
98 updateAddRemoveButton();
102void MessagingWidgetLister::updateAddRemoveButton()
104 QList<QWidget *> widgetList = widgets();
105 const int numberOfWidget(widgetList.
count());
106 bool addButtonEnabled =
false;
107 if (numberOfWidget <= widgetsMinimum()) {
108 addButtonEnabled =
true;
109 }
else if (numberOfWidget >= widgetsMaximum()) {
110 addButtonEnabled =
false;
112 addButtonEnabled =
true;
116 for (; wIt != wEnd; ++wIt) {
117 auto w = qobject_cast<MessagingWidget *>(*wIt);
118 w->updateAddRemoveButton(addButtonEnabled);
122#include "moc_messagingwidgetlister.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)