File indexing completed on 2024-11-17 04:40:40
0001 /* 0002 SPDX-FileCopyrightText: 2010 KDAB 0003 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "emailaddressselectionwidgettest.h" 0009 0010 #include <KComboBox> 0011 #include <QApplication> 0012 #include <QTextBrowser> 0013 0014 #include <QGridLayout> 0015 #include <QPushButton> 0016 #include <QTreeView> 0017 0018 MainWidget::MainWidget() 0019 : QWidget(nullptr) 0020 { 0021 auto layout = new QGridLayout(this); 0022 0023 mAddressesWidget = new Akonadi::EmailAddressSelectionWidget; 0024 layout->addWidget(mAddressesWidget, 0, 0); 0025 0026 mInfo = new QTextBrowser; 0027 layout->addWidget(mInfo, 0, 1); 0028 0029 auto box = new KComboBox; 0030 box->addItem(QStringLiteral("Single Selection")); 0031 box->addItem(QStringLiteral("Multi Selection")); 0032 connect(box, &KComboBox::activated, this, &MainWidget::selectionModeChanged); 0033 layout->addWidget(box, 1, 0); 0034 0035 auto button = new QPushButton(QStringLiteral("Show Selection")); 0036 connect(button, &QPushButton::clicked, this, &MainWidget::showSelection); 0037 layout->addWidget(button, 1, 1); 0038 } 0039 0040 void MainWidget::selectionModeChanged(int index) 0041 { 0042 mAddressesWidget->view()->setSelectionMode(index == 0 ? QTreeView::SingleSelection : QTreeView::MultiSelection); 0043 } 0044 0045 void MainWidget::showSelection() 0046 { 0047 mInfo->append(QStringLiteral("===========================\n")); 0048 mInfo->append(QStringLiteral("Current selection:\n")); 0049 0050 const auto selectedAddress = mAddressesWidget->selectedAddresses(); 0051 for (const Akonadi::EmailAddressSelection &selection : selectedAddress) { 0052 mInfo->append(QStringLiteral("%1: %2\n").arg(selection.name(), selection.email())); 0053 } 0054 } 0055 0056 int main(int argc, char **argv) 0057 { 0058 QApplication app(argc, argv); 0059 0060 MainWidget wdg; 0061 wdg.show(); 0062 0063 return app.exec(); 0064 } 0065 0066 #include "moc_emailaddressselectionwidgettest.cpp"