| 1 | /* |
| 2 | * This file is part of lomiri-online-accounts-ui |
| 3 | * |
| 4 | * Copyright (C) 2014 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 3, as published |
| 10 | * by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <online-accounts-common/debug.h> |
| 22 | #include "dialog.h" |
| 23 | |
| 24 | #include <QEvent> |
| 25 | |
| 26 | using namespace SignOnUi; |
| 27 | |
| 28 | Dialog::Dialog(QWindow *parent): |
| 29 | QQuickView(parent) |
| 30 | { |
| 31 | setResizeMode(QQuickView::SizeRootObjectToView); |
| 32 | setWindowState(Qt::WindowFullScreen); |
| 33 | } |
| 34 | |
| 35 | Dialog::~Dialog() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void Dialog::show(WId parent, ShowMode mode) |
| 40 | { |
| 41 | if (mode != TopLevel) { |
| 42 | QWindow *parentWindow = QWindow::fromWinId(parent); |
| 43 | if (mode == Transient) { |
| 44 | setTransientParent(parentWindow); |
| 45 | } else if (mode == Embedded) { |
| 46 | setParent(parentWindow); |
| 47 | } |
| 48 | } |
| 49 | QQuickView::show(); |
| 50 | } |
| 51 | |
| 52 | void Dialog::accept() |
| 53 | { |
| 54 | done(Dialog::Accepted); |
| 55 | } |
| 56 | |
| 57 | void Dialog::reject() |
| 58 | { |
| 59 | done(Dialog::Rejected); |
| 60 | } |
| 61 | |
| 62 | void Dialog::done(int result) |
| 63 | { |
| 64 | setVisible(false); |
| 65 | Q_EMIT finished(result); |
| 66 | } |
| 67 | |
| 68 | bool Dialog::event(QEvent *e) |
| 69 | { |
| 70 | if (e->type() == QEvent::Close) { |
| 71 | reject(); |
| 72 | } |
| 73 | return QQuickView::event(e); |
| 74 | } |