File: kdatecomboboxtestapp.cpp

package info (click to toggle)
kwidgetsaddons 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,836 kB
  • sloc: cpp: 32,526; python: 677; sh: 14; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
    SPDX-FileCopyrightText: 2022 g10 Code GmbH
    SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "kdatecombobox.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDate>
#include <QDebug>

int main(int argc, char **argv)
{
    QApplication::setApplicationName(QStringLiteral("test"));
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
    QApplication app{argc, argv};

    QCommandLineParser parser;
    parser.addHelpOption();
    parser.addOption({QStringLiteral("min-date"), QStringLiteral("Minimum date in ISO 8601 format, e.g. 2020-02-02"), QStringLiteral("min-date")});
    parser.addOption({QStringLiteral("max-date"), QStringLiteral("Maximum date in ISO 8601 format, e.g. 2121-12-12"), QStringLiteral("max-date")});
    parser.process(app.arguments());

    const auto minDate = QDate::fromString(parser.value(QStringLiteral("min-date")), Qt::ISODate);
    const auto maxDate = QDate::fromString(parser.value(QStringLiteral("max-date")), Qt::ISODate);

    KDateComboBox dateComboBox;
    dateComboBox.setOptions(KDateComboBox::EditDate | KDateComboBox::SelectDate | KDateComboBox::DatePicker | KDateComboBox::DateKeywords
                            | KDateComboBox::WarnOnInvalid);
    dateComboBox.setMinimumDate(minDate);
    dateComboBox.setMaximumDate(maxDate);
    QObject::connect(&dateComboBox, &KDateComboBox::dateEntered, [](const QDate &d) {
        qDebug() << "dateEntered" << d;
    });
    QObject::connect(&dateComboBox, &KDateComboBox::dateChanged, [](const QDate &d) {
        qDebug() << "dateChanged" << d;
    });
    QObject::connect(&dateComboBox, &KDateComboBox::dateEdited, [](const QDate &d) {
        qDebug() << "dateEdited" << d;
    });
    dateComboBox.resize(200, dateComboBox.sizeHint().height());
    dateComboBox.show();
    // dateComboBox.setEnabled(false);
    return app.exec();
}