File indexing completed on 2024-04-28 03:59:18

0001 /*
0002     SPDX-FileCopyrightText: 2022 g10 Code GmbH
0003     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "kdatecombobox.h"
0009 #include <QApplication>
0010 #include <QCommandLineParser>
0011 #include <QDate>
0012 #include <QDebug>
0013 
0014 int main(int argc, char **argv)
0015 {
0016     QApplication::setApplicationName(QStringLiteral("test"));
0017     QApplication app{argc, argv};
0018 
0019     QCommandLineParser parser;
0020     parser.addHelpOption();
0021     parser.addOption({QStringLiteral("min-date"), QStringLiteral("Minimum date in ISO 8601 format, e.g. 2020-02-02"), QStringLiteral("min-date")});
0022     parser.addOption({QStringLiteral("max-date"), QStringLiteral("Maximum date in ISO 8601 format, e.g. 2121-12-12"), QStringLiteral("max-date")});
0023     parser.process(app.arguments());
0024 
0025     const auto minDate = QDate::fromString(parser.value(QStringLiteral("min-date")), Qt::ISODate);
0026     const auto maxDate = QDate::fromString(parser.value(QStringLiteral("max-date")), Qt::ISODate);
0027 
0028     KDateComboBox dateComboBox;
0029     dateComboBox.setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords
0030                             | KDateComboBox::WarnOnInvalid);
0031     dateComboBox.setMinimumDate(minDate);
0032     dateComboBox.setMaximumDate(maxDate);
0033     QObject::connect(&dateComboBox, &KDateComboBox::dateEntered, [](const QDate &d) {
0034         qDebug() << "dateEntered" << d;
0035     });
0036     QObject::connect(&dateComboBox, &KDateComboBox::dateChanged, [](const QDate &d) {
0037         qDebug() << "dateChanged" << d;
0038     });
0039     QObject::connect(&dateComboBox, &KDateComboBox::dateEdited, [](const QDate &d) {
0040         qDebug() << "dateEdited" << d;
0041     });
0042     dateComboBox.resize(200, dateComboBox.sizeHint().height());
0043     dateComboBox.show();
0044     // dateComboBox.setEnabled(false);
0045     return app.exec();
0046 }