~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/ScriptingLangDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
        File                 : ScriptingLangDialog.cpp
 
3
        Project              : SciDAVis
 
4
--------------------------------------------------------------------
 
5
        Copyright            : (C) 2006 by Knut Franke, Ion Vasilief
 
6
        Email (use @ for *)  : knut.franke*gmx.de, ion_vasilief*yahoo.fr
 
7
        Description          : Dialog for changing the current scripting
 
8
                               language
 
9
 
 
10
 ***************************************************************************/
 
11
 
 
12
/***************************************************************************
 
13
 *                                                                         *
 
14
 *  This program is free software; you can redistribute it and/or modify   *
 
15
 *  it under the terms of the GNU General Public License as published by   *
 
16
 *  the Free Software Foundation; either version 2 of the License, or      *
 
17
 *  (at your option) any later version.                                    *
 
18
 *                                                                         *
 
19
 *  This program is distributed in the hope that it will be useful,        *
 
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
22
 *  GNU General Public License for more details.                           *
 
23
 *                                                                         *
 
24
 *   You should have received a copy of the GNU General Public License     *
 
25
 *   along with this program; if not, write to the Free Software           *
 
26
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
27
 *   Boston, MA  02110-1301  USA                                           *
 
28
 *                                                                         *
 
29
 ***************************************************************************/
 
30
#include "ScriptingLangDialog.h"
 
31
#include "ApplicationWindow.h"
 
32
 
 
33
#include <QListWidget>
 
34
#include <QPushButton>
 
35
#include <QLayout>
 
36
#include <QMessageBox>
 
37
 
 
38
ScriptingLangDialog::ScriptingLangDialog(ScriptingEnv *env, ApplicationWindow *parent, Qt::WFlags fl )
 
39
: QDialog(parent, fl), scripted(env)
 
40
{
 
41
        setCaption(tr("Select scripting language"));
 
42
 
 
43
        langList = new QListWidget(this);
 
44
 
 
45
        btnOK = new QPushButton(tr("OK"));
 
46
        btnCancel = new QPushButton(tr("Cancel"));
 
47
 
 
48
        QHBoxLayout *hbox1 = new QHBoxLayout(); 
 
49
    hbox1->addStretch();
 
50
        hbox1->addWidget(btnOK);
 
51
        hbox1->addWidget(btnCancel);
 
52
 
 
53
        QVBoxLayout *vl = new QVBoxLayout(this);
 
54
        vl->addWidget(langList);
 
55
        vl->addLayout(hbox1);   
 
56
 
 
57
        connect(btnOK, SIGNAL(clicked()), this, SLOT(accept()));
 
58
        connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
 
59
        connect(langList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(accept()));
 
60
 
 
61
        updateLangList();
 
62
}
 
63
 
 
64
void ScriptingLangDialog::updateLangList()
 
65
{
 
66
        langList->clear();
 
67
        langList->insertItems(0, ScriptingLangManager::languages());
 
68
        QListWidgetItem *current = langList->findItems(scriptEnv->name(), Qt::MatchExactly).first();
 
69
        if (current)
 
70
                langList->setCurrentItem(current);
 
71
}
 
72
 
 
73
void ScriptingLangDialog::accept()
 
74
{
 
75
        ApplicationWindow *app = (ApplicationWindow*) parent();
 
76
        if (app->setScriptingLang(langList->currentItem()->text()))
 
77
                close();
 
78
        else
 
79
                QMessageBox::critical(this, tr("Scripting Error"),
 
80
                                tr("Scripting language \"%1\" failed to initialize.").arg(langList->currentItem()->text()));
 
81
}
 
82