QTfrontend/ui/dialog/ask_quit.cpp
author koda
Tue, 23 Oct 2012 07:03:07 +0200
changeset 7795 ba32d3f9e567
parent 7631 01b599d6f72d
child 7902 a82b1bf2eca1
permissions -rw-r--r--
set window modality also for custom dialogs, small text changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     1
/*
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     2
 * Hedgewars, a free turn based strategy game
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     4
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     8
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    12
 * GNU General Public License for more details.
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    13
 *
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    14
 * You should have received a copy of the GNU General Public License
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    15
 * along with this program; if not, write to the Free Software
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    17
 */
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    18
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    19
#include <QVBoxLayout>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    20
#include <QLabel>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    21
#include <QDialogButtonBox>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    22
#include <QPushButton>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    23
#include <QTimer>
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    24
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    25
#include "hwform.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    26
#include "ask_quit.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    27
#include "pagevideos.h"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    28
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    29
HWAskQuitDialog::HWAskQuitDialog(QWidget* parent, HWForm * form) : QDialog(parent)
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    30
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    31
    this->form = form;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    32
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    33
    setWindowTitle(tr("Do yot really want to quit?"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    34
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    35
    QVBoxLayout * layout = new QVBoxLayout(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    36
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    37
    QLabel * lbLabel = new QLabel(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    38
    lbLabel->setText(QLabel::tr("There are videos that are currently being processed.\n"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    39
                                "Exiting now will abort them.\n"
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    40
                                "Do yot really want to quit?"));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    41
    layout->addWidget(lbLabel);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    42
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    43
    lbList = new QLabel(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    44
    layout->addWidget(lbList);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    45
    updateList();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    46
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    47
    QDialogButtonBox* dbbButtons = new QDialogButtonBox(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    48
    QPushButton * pbYes = dbbButtons->addButton(QDialogButtonBox::Yes);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    49
    QPushButton * pbNo  = dbbButtons->addButton(QDialogButtonBox::No);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    50
    QPushButton * pbMore = dbbButtons->addButton(QPushButton::tr("More info"), QDialogButtonBox::HelpRole);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    51
    layout->addWidget(dbbButtons);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    52
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    53
    connect(pbYes,  SIGNAL(clicked()), this, SLOT(accept()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    54
    connect(pbNo,   SIGNAL(clicked()), this, SLOT(reject()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    55
    connect(pbMore, SIGNAL(clicked()), this, SLOT(goToPageVideos()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    56
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    57
    // update list periodically
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    58
    QTimer * timer = new QTimer(this);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    59
    connect(timer, SIGNAL(timeout()), this, SLOT(updateList()));
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    60
    timer->start(200);
7795
ba32d3f9e567 set window modality also for custom dialogs, small text changes
koda
parents: 7631
diff changeset
    61
ba32d3f9e567 set window modality also for custom dialogs, small text changes
koda
parents: 7631
diff changeset
    62
    this->setWindowModality(Qt::WindowModal);
7631
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    63
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    64
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    65
void HWAskQuitDialog::goToPageVideos()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    66
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    67
    reject();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    68
    form->GoToVideos();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    69
}
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    70
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    71
void HWAskQuitDialog::updateList()
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    72
{
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    73
    QString text = form->ui.pageVideos->getVideosInProgress();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    74
    if (text.isEmpty())
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    75
    {
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    76
        // automatically exit when everything is finished
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    77
        accept();
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    78
        return;
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    79
    }
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    80
    lbList->setText(text);
01b599d6f72d dos2unix newline fixes on 7 (video recording-)merged files
sheepluva
parents: 7447
diff changeset
    81
}