kdeapp.cpp
来自「celestia源代码」· C++ 代码 · 共 1,548 行 · 第 1/5 页
CPP
1,548 行
/*************************************************************************** kdeapp.cpp - description ------------------- begin : Tue Jul 16 22:28:19 CEST 2002 copyright : (C) 2002 by Christophe Teyssier email : chris@teyssier.org ***************************************************************************//*************************************************************************** * * * 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 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <fstream>#include <sstream>#include <qpushbutton.h>#include <qslider.h>#include <qlayout.h>#include <qframe.h>#include <qgrid.h>#include <qvbox.h>#include <qcheckbox.h>#include <qvgroupbox.h>#include <qlabel.h>#include <qclipboard.h>#include <qregexp.h>#include <qpalette.h>#include <qfont.h>#include <qlineedit.h>#include <qvalidator.h>#include <qmenubar.h>#include <qpopupmenu.h>#include <qapplication.h>#include <qkeycode.h>#include <qtimer.h>#include <qimage.h>#include <kaction.h>#include <kstdaction.h>#include <kmenubar.h>#include <kedittoolbar.h>#include <kkeydialog.h>#include <klocale.h>#include <kconfig.h>#include <qtextedit.h>#include <klineeditdlg.h>#include <qdatetime.h>#include <kshortcut.h>#include <klocale.h>#include <kfiledialog.h>#include <kmessagebox.h>#include <kurl.h>#include <krun.h>#include <kurldrag.h>#include <kstdaccel.h>#include <kpopupmenu.h>#include <kcelbookmarkmenu.h>#include <kbookmarkbar.h>#include <kcelbookmarkmanager.h>#include <kdeversion.h>#if KDE_VERSION >= 0x030200 #include <ksplashscreen.h>#endif#include "kdeglwidget.h"#include "kdeapp.h"#include "kdepreferencesdialog.h"#include "celengine/cmdparser.h"#include "url.h"#include "celestialbrowser.h"#include "eclipsefinderdlg.h"#include "selectionpopup.h"#include "celsplashscreen.h"#include "celengine/glext.h"#define MENUMAXSIZE 100KdeApp* KdeApp::app=0;KBookmarkManager* KCelBookmarkManager::s_bookmarkManager;static uint32 FilterOtherLocations = ~(Location::City | Location::Observatory | Location::LandingSite | Location::Crater | Location::Mons | Location::Terra | Location::Vallis | Location::Mare);KdeApp::KdeApp(std::string config, std::string dir, std::vector<std::string> extrasDirs, bool fullscreen, bool disableSplash) : KMainWindow(0, 0){#if KDE_VERSION >= 0x030200 CelSplashScreen *splash = NULL; if (!disableSplash) { QStringList splashDirs = KGlobal::dirs()->findDirs("appdata", "splash"); QStringList images; srandom(time(NULL)); for(QStringList::iterator i = splashDirs.begin(); i != splashDirs.end(); ++i) { QDir d(*i); d.setFilter(QDir::Files); QStringList splashImages = d.entryList().grep(QRegExp("\\.(jpg|png)$", FALSE)); for(QStringList::iterator j = splashImages.begin(); j != splashImages.end(); ++j) { images.append(*i + *j); } } if (images.size() > 0) { int index = (int)(random()*1./RAND_MAX*images.size()); splash = new CelSplashScreen(images[index], this); } else { KMessageBox::queuedMessageBox(this, KMessageBox::Information, i18n("Something seems to be wrong with your installation of Celestia. The splash screen directory couldn't be found. \nStart-up will continue, but Celestia will probably be missing some data files and may not work correctly, please check your installation.")); } }#endif appCore=new CelestiaCore(); if (appCore == NULL) { cerr << "Out of memory.\n"; exit(1); } kdewatcher = new KdeWatcher(appCore, this); renderer = appCore->getRenderer(); sim = appCore->getSimulation(); app=this; appCore->setContextMenuCallback(&KdeApp::popupMenu); appCore->setAlerter(new KdeAlerter(this)); setAcceptDrops(true); // Create our OpenGL widget if ( (dir.length() > 1 ? chdir(dir.c_str()):chdir(CONFIG_DATA_DIR)) == -1) { ::std::cout << "Cannot chdir to '" << CONFIG_DATA_DIR << "', probably due to improper installation" << ::std::endl; exit(1); } glWidget = new KdeGlWidget( this, "kdeglwidget", appCore); string* altConfig = config.length() > 0 ? &config : NULL;#if KDE_VERSION >= 0x030200 if (!appCore->initSimulation(altConfig, &extrasDirs, splash))#else if (!appCore->initSimulation(altConfig, &extrasDirs))#endif { exit(1); } setCentralWidget(glWidget); initActions(); glWidget->setFocus(); resize(640,480); setAutoSaveSettings("MainWindow"); KConfig* conf = kapp->config(); applyMainWindowSettings(conf, "MainWindow"); conf->setGroup("MainWindow"); restoreWindowSize(conf); conf->setGroup(0); if (fullscreen) slotFullScreen(); KGlobal::config()->setGroup("Preferences"); if (KGlobal::config()->hasKey("DistanceToScreen")) { appCore->setDistanceToScreen(KGlobal::config()->readNumEntry("DistanceToScreen")); } if (conf->hasGroup("Shortcuts")) actionCollection()->readShortcutSettings("Shortcuts", conf); if (toolBar()->isHidden()) toggleToolbar->setChecked(false); if (menuBar()->isHidden()) toggleMenubar->setChecked(false);#if KDE_VERSION >= 0x030200 if (splash != NULL) { splash->finish(this); delete splash; }#endif // We use a timer with a null timeout value // to add appCore->tick to Qt's event loop QTimer *t = new QTimer( dynamic_cast<QObject *>(this) ); QObject::connect( t, SIGNAL(timeout()), SLOT(celestia_tick()) ); t->start( 0, FALSE );}void KdeApp::setStartURL(KURL url) { if (url.protocol() == "cel") { appCore->setStartURL(url.url().latin1()); } if (url.protocol() == "file") { appCore->setStartURL(url.path().latin1()); }}void KdeApp::goToURL(const KURL& url) { if (url.protocol() == "cel") { appCore->addToHistory(); appCore->goToUrl(url.prettyURL().latin1()); } if (url.protocol() == "file") { appCore->addToHistory(); slotOpenFileURL(url); }}void KdeApp::openBookmarkURL(const QString& _url) { KURL url(_url); appCore->addToHistory(); appCore->goToUrl(url.prettyURL().latin1());}Url KdeApp::currentUrl(Url::UrlType type) const { return Url(appCore, type);}QString KdeApp::currentIcon() const { QDateTime now = QDateTime::currentDateTime(); QString iconName = QString::fromLatin1("favicons/celestia_") + now.toString("yyyyMMddhhmmsszzz"); QString iconFilename = locateLocal("cache", iconName) + ".png"; QImage grabedImage = glWidget->grabFrameBuffer(); int width=grabedImage.width(), height=grabedImage.height(); if (width > height) { grabedImage.copy((width - height)/2, 0, height, height).smoothScale(64,64).save(iconFilename, "PNG"); } else { grabedImage.copy(0, (height - width)/2, width, width).smoothScale(64,64).save(iconFilename, "PNG"); } return iconName;}void KdeWatcher::notifyChange(CelestiaCore * core, int property){ if ((property & (CelestiaCore::RenderFlagsChanged| CelestiaCore::LabelFlagsChanged| CelestiaCore::TimeZoneChanged))) kdeapp->resyncMenus(); if (property & CelestiaCore::AmbientLightChanged) kdeapp->resyncAmbient(); if (property & CelestiaCore::FaintestChanged) kdeapp->resyncFaintest(); if (property & CelestiaCore::VerbosityLevelChanged) kdeapp->resyncVerbosity(); if (property & CelestiaCore::HistoryChanged) kdeapp->resyncHistory(); if (property == CelestiaCore::TextEnterModeChanged) { static std::vector<KAction*> actions; if (kdeapp->appCore->getTextEnterMode() != CelestiaCore::KbNormal) { for (unsigned int n=0; n < kdeapp->getActionCollection()->count(); n++) { if (kdeapp->getActionCollection()->action(n)->shortcut().count() > 0 && (kdeapp->getActionCollection()->action(n)->shortcut().seq(0).key(0).modFlags() & (KKey::CTRL | KKey::ALT | KKey::WIN )) == 0 ) { actions.push_back(kdeapp->getActionCollection()->action(n)); kdeapp->getActionCollection()->action(n)->setEnabled(false); } } } else { for (std::vector<KAction*>::iterator n=actions.begin(); n<actions.end(); n++) { (*n)->setEnabled(true); } actions.clear(); } }}void KdeApp::resyncHistory() { std::vector<Url> history=appCore->getHistory(); std::vector<Url>::size_type i=appCore->getHistoryCurrent(); if (i >= history.size()-1) { action("go_forward")->setEnabled(false); } else { action("go_forward")->setEnabled(true); } if (i == 0) { action("go_back")->setEnabled(false); } else { action("go_back")->setEnabled(true); } }void KdeApp::resyncMenus() { int rFlags = renderer->getRenderFlags(); int orbitMask = renderer->getOrbitMask(); ((KToggleAction*)action("showStars"))->setChecked(rFlags & Renderer::ShowStars); ((KToggleAction*)action("showPlanets"))->setChecked(rFlags & Renderer::ShowPlanets); ((KToggleAction*)action("showGalaxies"))->setChecked(rFlags & Renderer::ShowGalaxies); ((KToggleAction*)action("showPartialTrajectories"))->setChecked(rFlags & Renderer::ShowPartialTrajectories); ((KToggleAction*)action("showNebulae"))->setChecked(rFlags & Renderer::ShowNebulae); ((KToggleAction*)action("showOpenClusters"))->setChecked(rFlags & Renderer::ShowOpenClusters); ((KToggleAction*)action("showDiagrams"))->setChecked(rFlags & Renderer::ShowDiagrams); ((KToggleAction*)action("showCloudMaps"))->setChecked(rFlags & Renderer::ShowCloudMaps);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?