File indexing completed on 2024-04-28 05:51:09
0001 /* 0002 * SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 **/ 0006 0007 #include "kmultiformlistbox-multivisible.h" 0008 #include "kmultiformlistbox-windowed.h" 0009 0010 #include <QHBoxLayout> 0011 0012 #include "kmultiformlistboxfactory.h" 0013 0014 KMultiFormListBox::KMultiFormListBox(KMultiFormListBoxFactory *factory, 0015 KMultiFormListBoxType tp, 0016 QWidget *parent, 0017 bool showUpDownButtons, 0018 bool showHelpButton, 0019 const QString &addButtonText) 0020 : QWidget(parent) 0021 { 0022 switch (tp) { 0023 case MultiVisible: 0024 theWidget = new KMultiFormListBoxMultiVisible(factory, this); 0025 break; 0026 0027 case Windowed: 0028 theWidget = new KMultiFormListBoxWindowed(factory, this, showUpDownButtons, showHelpButton, addButtonText); 0029 break; 0030 } 0031 0032 QWidget *widget = theWidget->qWidget(); 0033 0034 QHBoxLayout *layout = new QHBoxLayout(this); 0035 layout->setContentsMargins(0, 0, 0, 0); 0036 _factory = factory; 0037 layout->addWidget(widget); 0038 } 0039 0040 void KMultiFormListBox::append(KMultiFormListBoxEntry *element) 0041 { 0042 theWidget->append(element); 0043 } 0044 0045 void KMultiFormListBox::addElement() 0046 { 0047 theWidget->addElement(); 0048 } 0049 0050 KMultiFormListBoxEntryList KMultiFormListBox::elements() 0051 { 0052 return theWidget->elements(); 0053 } 0054 0055 const KMultiFormListBoxEntryList KMultiFormListBox::elements() const 0056 { 0057 return const_cast<KMultiFormListBox *>(this)->elements(); 0058 } 0059 0060 void KMultiFormListBox::slotChangeFace(KMultiFormListBoxType /*newFace*/) 0061 { 0062 // TODO 0063 // kDebug() << "It's not possible yet to change the face on the fly." 0064 // << "Please let me (blackie@kde.org) know that you need it, and I'll work on it" << endl; 0065 } 0066 0067 void KMultiFormListBox::toStream(QDataStream &stream) const 0068 { 0069 const KMultiFormListBoxEntryList elms = elements(); 0070 stream << elms.count(); 0071 for (KMultiFormListBoxEntry *entry : elms) { 0072 _factory->toStream(entry, stream); 0073 } 0074 } 0075 0076 void KMultiFormListBox::fromStream(QDataStream &stream) 0077 { 0078 unsigned int fromCount, toCount; 0079 stream >> fromCount; 0080 0081 toCount = elements().count(); 0082 0083 // adds/remove elements in the to list, to make it have the correct length. 0084 for (unsigned int j = toCount; j < fromCount; ++j) { 0085 addElement(); 0086 } 0087 for (unsigned int k = fromCount; k < toCount; ++k) { 0088 theWidget->delAnElement(); 0089 } 0090 0091 const KMultiFormListBoxEntryList elms = elements(); 0092 for (KMultiFormListBoxEntry *entry : elms) { 0093 _factory->fromStream(stream, entry); 0094 } 0095 } 0096 0097 #include "moc_kmultiformlistbox.cpp"