qml_dialogue_helper.h 3.18 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
#pragma once
25 26 27

#include <QObject>
#include <QString>
28
#include <QWindow>
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

/*!
 * @brief Class defining enumeration types.
 *
 * @note The enumeration types cannot be defined in a class with a private
 * constructor because of qmlRegisterType(). Also, because the types are
 * registered before main window is loaded the constructor is called and that
 * causes trouble on Android and iOS devices.
 */
class QmlDlgHelper : public QObject {
	Q_OBJECT

public:
	/*!
	 * @brief Emits accepted signal.
	 *
	 * @param[in] input Value to emit together with the signal.
	 */
	Q_INVOKABLE
	void emitAccepted(const QString &input);

	/*!
	 * @brief Emits rejected signal.
	 */
	Q_INVOKABLE
	void emitRejected(void);

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	/*!
	 * @brief Emits closed signal.
	 *
	 * @param[in] button Pressed button code.
	 * @param[in] customButton Custom button value.
	 */
	Q_INVOKABLE
	void emitClosed(int button, int customButton);

	/*!
	 * @brief Return pointer to top level window.
	 *
	 * @return non-null pointer to window if top level window could be
	 *     acquired.
	 */
	static
	QWindow *topLevelWindow(void);

	/*
	 * Cannot be a static object. Android code complains:
	 * Illegal attempt to connect to object that is in a different thread
	 * than the QML engine.
	 */
	static
	QmlDlgHelper *dlgEmitter; /*!< Object used to invoke QML dialogues. */

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
signals:
	/*!
	 * @brief This signal should be emitted when QML text input dialogue
	 *     should be displayed.
	 */
	void dlgGetText(const QString &title, const QString &message,
	    int echoMode, const QString &text, const QString &placeholderText,
	    int inputMethodHints, bool explicitPasteMenu);

	/*!
	 * @brief This signal should be emitted when QML text input dialogue
	 *     was accepted.
	 */
	void accepted(const QString &input);

	/*!
	 * @brief This signal should be emitted when QML text input dialogue
	 *     was rejected.
	 */
	void rejected(void);
102 103 104 105 106

	/*!
	 * @brief This signal should be emitted when QML message dialogue
	 *     should be displayed.
	 */
107
	void dlgMessage(int icon, const QString &title, const QString &message,
108
	    const QString &infoMessage, int buttons);
109 110 111 112 113 114

	/*!
	 * @brief This signal should be emitted when QML message dialogue
	 *    was closed.
	 */
	void closed(int button, int customButton);
115
};