~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/gui/ViewDialog.cpp

  • Committer: Package Import Robot
  • Author(s): Tomasz Buchert
  • Date: 2012-05-18 13:26:18 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20120518132618-3uso09fo68c218cx
Tags: 0.11.2-1
* Imported Upstream version 0.11.1 and then 0.11.2 (Closes: #658431)
* Change maintainer (Closes: #668916)
* Machine-readable copyright file
* Bump Standards-Version to 3.9.3
* Update debhelper compat to 9
* Fix lintian duplicate-font-file warning
* Fix copyright-refers-to-symlink-license lintian tag
* Add lintian override for embedded-library error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Stellarium
3
3
 * Copyright (C) 2008 Fabien Chereau
 
4
 * Copyright (C) 2012 Timothy Reaves
4
5
 *
5
6
 * This program is free software; you can redistribute it and/or
6
7
 * modify it under the terms of the GNU General Public License
14
15
 *
15
16
 * You should have received a copy of the GNU General Public License
16
17
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
18
19
*/
19
20
 
20
21
 
45
46
#include <QDebug>
46
47
#include <QFrame>
47
48
#include <QFile>
 
49
#include <QFileInfo>
48
50
#include <QSettings>
49
51
#include <QTimer>
50
52
#include <QDialog>
66
68
        atmosphereDialog = NULL;
67
69
}
68
70
 
69
 
void ViewDialog::languageChanged()
 
71
void ViewDialog::retranslate()
70
72
{
71
73
        if (dialog)
72
74
        {
73
75
                ui->retranslateUi(dialog);
74
 
                shootingStarsZHRChanged();
 
76
                setZhrFromControls();
75
77
                populateLists();
 
78
 
 
79
                //Hack to shrink the tabs to optimal size after language change
 
80
                //by causing the list items to be laid out again.
 
81
                ui->stackListWidget->setWrapping(false);
76
82
        }
77
83
}
78
84
 
87
93
void ViewDialog::createDialogContent()
88
94
{
89
95
        ui->setupUi(dialog);
90
 
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(languageChanged()));
 
96
        connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
91
97
 
92
98
        // Set the Sky tab activated by default
93
99
        ui->stackedWidget->setCurrentIndex(0);
142
148
        // Shooting stars section
143
149
        MeteorMgr* mmgr = GETSTELMODULE(MeteorMgr);
144
150
        Q_ASSERT(mmgr);
145
 
        switch(mmgr->getZHR())
146
 
        {
147
 
                case 0: ui->zhrNone->setChecked(true); break;
148
 
                case 80: ui->zhr80->setChecked(true); break;
149
 
                case 10000: ui->zhr10000->setChecked(true); break;
150
 
                case 144000: ui->zhr144000->setChecked(true); break;
151
 
                default: ui->zhr10->setChecked(true); break;
152
 
        }
153
 
        shootingStarsZHRChanged();
154
 
        connect(ui->zhrNone, SIGNAL(clicked()), this, SLOT(shootingStarsZHRChanged()));
155
 
        connect(ui->zhr10, SIGNAL(clicked()), this, SLOT(shootingStarsZHRChanged()));
156
 
        connect(ui->zhr80, SIGNAL(clicked()), this, SLOT(shootingStarsZHRChanged()));
157
 
        connect(ui->zhr10000, SIGNAL(clicked()), this, SLOT(shootingStarsZHRChanged()));
158
 
        connect(ui->zhr144000, SIGNAL(clicked()), this, SLOT(shootingStarsZHRChanged()));
 
151
        updateZhrControls(mmgr->getZHR());
 
152
        connect(mmgr, SIGNAL(zhrChanged(int)),
 
153
                this, SLOT(updateZhrControls(int)));
 
154
        connect(ui->zhrNone, SIGNAL(clicked()), this, SLOT(setZhrFromControls()));
 
155
        connect(ui->zhr10, SIGNAL(clicked()), this, SLOT(setZhrFromControls()));
 
156
        connect(ui->zhr80, SIGNAL(clicked()), this, SLOT(setZhrFromControls()));
 
157
        connect(ui->zhr10000, SIGNAL(clicked()), this, SLOT(setZhrFromControls()));
 
158
        connect(ui->zhr144000, SIGNAL(clicked()), this, SLOT(setZhrFromControls()));
159
159
 
160
160
        // Labels section
161
161
        StarMgr* smgr = GETSTELMODULE(StarMgr);
247
247
        connect(a, SIGNAL(toggled(bool)), ui->showEquatorialGridCheckBox, SLOT(setChecked(bool)));
248
248
        connect(ui->showEquatorialGridCheckBox, SIGNAL(toggled(bool)), a, SLOT(setChecked(bool)));
249
249
 
 
250
        ui->showGalacticGridCheckBox->setChecked(glmgr->getFlagGalacticGrid());
 
251
        a = gui->getGuiActions("actionShow_Galactic_Grid");
 
252
        connect(a, SIGNAL(toggled(bool)), ui->showGalacticGridCheckBox, SLOT(setChecked(bool)));
 
253
        connect(ui->showGalacticGridCheckBox, SIGNAL(toggled(bool)), a, SLOT(setChecked(bool)));
 
254
 
 
255
        ui->showGalacticPlaneLineCheckBox->setChecked(glmgr->getFlagGalacticPlaneLine());
 
256
        a = gui->getGuiActions("actionShow_Galactic_Plane_Line");
 
257
        connect(a, SIGNAL(toggled(bool)), ui->showGalacticPlaneLineCheckBox, SLOT(setChecked(bool)));
 
258
        connect(ui->showGalacticPlaneLineCheckBox, SIGNAL(toggled(bool)), a, SLOT(setChecked(bool)));
 
259
 
250
260
        ui->showAzimuthalGridCheckBox->setChecked(glmgr->getFlagAzimuthalGrid());
251
261
        a = gui->getGuiActions("actionShow_Azimuthal_Grid");
252
262
        connect(a, SIGNAL(toggled(bool)), ui->showAzimuthalGridCheckBox, SLOT(setChecked(bool)));
338
348
        l->blockSignals(true);
339
349
        l->clear();
340
350
        LandscapeMgr* lmgr = GETSTELMODULE(LandscapeMgr);
341
 
        l->addItems(lmgr->getAllLandscapeNames());
342
 
        l->setCurrentItem(l->findItems(lmgr->getCurrentLandscapeName(), Qt::MatchExactly).at(0));
 
351
        QStringList landscapeList = lmgr->getAllLandscapeNames();
 
352
        foreach (const QString landscapeId, landscapeList)
 
353
        {
 
354
                QString label = q_(landscapeId);
 
355
                QListWidgetItem* item = new QListWidgetItem(label);
 
356
                item->setData(Qt::UserRole, landscapeId);
 
357
                l->addItem(item);
 
358
        }
 
359
        QString selectedLandscapeId = lmgr->getCurrentLandscapeName();
 
360
        for (int i = 0; i < l->count(); i++)
 
361
        {
 
362
                if (l->item(i)->data(Qt::UserRole).toString() == selectedLandscapeId)
 
363
                {
 
364
                        l->setCurrentRow(i);
 
365
                        break;
 
366
                }
 
367
        }
343
368
        l->blockSignals(false);
344
369
        ui->landscapeTextBrowser->setHtml(lmgr->getCurrentLandscapeHtmlDescription());
345
370
        ui->useAsDefaultLandscapeCheckBox->setChecked(lmgr->getDefaultLandscapeID()==lmgr->getCurrentLandscapeID());
388
413
 
389
414
void ViewDialog::updateSkyCultureText()
390
415
{
 
416
        StelApp& app = StelApp::getInstance();
 
417
        QString skyCultureId = app.getSkyCultureMgr().getCurrentSkyCultureID();
391
418
        QString descPath;
392
419
        try
393
420
        {
394
 
                descPath = StelFileMgr::findFile("skycultures/" + StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureID() + "/description."+StelApp::getInstance().getLocaleMgr().getAppLanguage()+".utf8");
 
421
                QString lang = app.getLocaleMgr().getAppLanguage();
 
422
                if (!QString("pt_BR zh_CN zh_HK zh_TW").contains(lang)) 
 
423
                {
 
424
                        lang = lang.split("_").at(0);
 
425
                }
 
426
                descPath = StelFileMgr::findFile("skycultures/" + skyCultureId + "/description."+lang+".utf8");
395
427
        }
396
428
        catch (std::runtime_error& e)
397
429
        {
398
430
                try
399
431
                {
400
 
                        descPath = StelFileMgr::findFile("skycultures/" + StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureID() + "/description.en.utf8");
 
432
                        descPath = StelFileMgr::findFile("skycultures/" + skyCultureId + "/description.en.utf8");
401
433
                }
402
434
                catch (std::runtime_error& e)
403
435
                {
404
 
                        qWarning() << "WARNING: can't find description for skyculture" << StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureID();
 
436
                        qWarning() << "WARNING: can't find description for skyculture" << skyCultureId;
405
437
                }
406
438
        }
407
439
 
408
440
        QStringList searchPaths;
409
441
        try
410
442
        {
411
 
                searchPaths << StelFileMgr::findFile("skycultures/" + StelApp::getInstance().getSkyCultureMgr().getCurrentSkyCultureID());
 
443
                searchPaths << StelFileMgr::findFile("skycultures/" + skyCultureId);
412
444
        }
413
445
        catch (std::runtime_error& e) {}
414
446
 
415
447
        ui->skyCultureTextBrowser->setSearchPaths(searchPaths);
416
 
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
 
448
        StelGui* gui = dynamic_cast<StelGui*>(app.getGui());
417
449
        Q_ASSERT(gui);
418
450
        ui->skyCultureTextBrowser->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
419
451
 
425
457
        {
426
458
                QFile f(descPath);
427
459
                f.open(QIODevice::ReadOnly);
428
 
                ui->skyCultureTextBrowser->setHtml(QString::fromUtf8(f.readAll()));
 
460
                QString htmlFile = QString::fromUtf8(f.readAll());
 
461
#if QT_VERSION == 0x040800
 
462
                // Workaround for https://bugreports.qt-project.org/browse/QTBUG-24077
 
463
                QString path = QFileInfo(f).path();
 
464
                QString newtag = "<img src=\"" + path + "/\\1";
 
465
                htmlFile.replace(QRegExp("<img src=\"(\\w)"), newtag);
 
466
#endif
 
467
                ui->skyCultureTextBrowser->setHtml(htmlFile);
429
468
        }
430
469
}
431
470
 
442
481
void ViewDialog::landscapeChanged(QListWidgetItem* item)
443
482
{
444
483
        LandscapeMgr* lmgr = GETSTELMODULE(LandscapeMgr);
445
 
        lmgr->setCurrentLandscapeName(item->text());
 
484
        lmgr->setCurrentLandscapeName(item->data(Qt::UserRole).toString());
446
485
        StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
447
486
        Q_ASSERT(gui);
448
487
        ui->landscapeTextBrowser->document()->setDefaultStyleSheet(QString(gui->getStelStyle().htmlStyleSheet));
475
514
}
476
515
 
477
516
 
478
 
void ViewDialog::shootingStarsZHRChanged()
 
517
void ViewDialog::setZhrFromControls()
479
518
{
480
519
        MeteorMgr* mmgr = GETSTELMODULE(MeteorMgr);
481
520
        int zhr=-1;
500
539
        {
501
540
                mmgr->setZHR(zhr);
502
541
        }
 
542
        
 
543
        updateZhrDescription(zhr);
 
544
}
 
545
 
 
546
void ViewDialog::updateZhrControls(int zhr)
 
547
{
 
548
        // As the radio buttons are tied to the clicked() signal,
 
549
        // it won't be triggered by setting the value programmatically.
 
550
        switch(zhr)
 
551
        {
 
552
                case 0: ui->zhrNone->setChecked(true); break;
 
553
                case 80: ui->zhr80->setChecked(true); break;
 
554
                case 10000: ui->zhr10000->setChecked(true); break;
 
555
                case 144000: ui->zhr144000->setChecked(true); break;
 
556
                default: ui->zhr10->setChecked(true); break;
 
557
        }
 
558
        
 
559
        updateZhrDescription(zhr);
 
560
}
 
561
 
 
562
void ViewDialog::updateZhrDescription(int zhr)
 
563
{
503
564
        switch (zhr)
504
565
        {
505
566
                case 0:
520
581
                default:
521
582
                        ui->zhrLabel->setText(QString("<small><i>")+"Error"+"</i></small>");
522
583
        }
523
 
 
524
584
}
525
585
 
526
586
void ViewDialog::starsLabelsValueChanged(int v)