kdeapp.cpp

来自「celestia源代码」· C++ 代码 · 共 1,548 行 · 第 1/5 页

CPP
1,548
字号
    /////////////////////////////////////////    // Location Filters    KToggleAction* showCityLocations = new KToggleAction(i18n("Show City Locations"), 0, this, SLOT(slotShowCityLocations()), actionCollection(), "showCityLocations");    showCityLocations->setChecked(lFilter & Location::City);    KToggleAction* showObservatoryLocations = new KToggleAction(i18n("Show Observatory Locations"), 0, this, SLOT(slotShowObservatoryLocations()), actionCollection(), "showObservatoryLocations");    showObservatoryLocations->setChecked(lFilter & Location::Observatory);    KToggleAction* showLandingSiteLocations = new KToggleAction(i18n("Show Landing Sites Locations"), 0, this, SLOT(slotShowLandingSiteLocations()), actionCollection(), "showLandingSiteLocations");    showLandingSiteLocations->setChecked(lFilter & Location::LandingSite);    KToggleAction* showCraterLocations = new KToggleAction(i18n("Show Crater Locations"), 0, this, SLOT(slotShowCraterLocations()), actionCollection(), "showCraterLocations");    showCraterLocations->setChecked(lFilter & Location::Crater);    KToggleAction* showMonsLocations = new KToggleAction(i18n("Show Mons Locations"), 0, this, SLOT(slotShowMonsLocations()), actionCollection(), "showMonsLocations");    showMonsLocations->setChecked(lFilter & Location::Mons);    KToggleAction* showTerraLocations = new KToggleAction(i18n("Show Terra Locations"), 0, this, SLOT(slotShowTerraLocations()), actionCollection(), "showTerraLocations");    showTerraLocations->setChecked(lFilter & Location::Terra);    KToggleAction* showVallisLocations = new KToggleAction(i18n("Show Vallis Locations"), 0, this, SLOT(slotShowVallisLocations()), actionCollection(), "showVallisLocations");    showVallisLocations->setChecked(lFilter & Location::Vallis);    KToggleAction* showMareLocations = new KToggleAction(i18n("Show Mare Locations"), 0, this, SLOT(slotShowMareLocations()), actionCollection(), "showMareLocations");    showMareLocations->setChecked(lFilter & Location::Mare);    KToggleAction* showOtherLocations = new KToggleAction(i18n("Show Other Locations"), 0, this, SLOT(slotShowOtherLocations()), actionCollection(), "showOtherLocations");    showOtherLocations->setChecked(lFilter & FilterOtherLocations);    /////////////////////////////////////////    new KToggleAction(i18n("Wireframe Mode"), CTRL + Key_W, this, SLOT(slotWireframeMode()), actionCollection(), "wireframeMode");    new KAction(i18n("Center on Orbit"), SHIFT + Key_C, this, SLOT(slotCenterCO()), actionCollection(), "centerCO");    KToggleAction *renderPath = 0;    renderPath = new KToggleAction(i18n("Basic"), 0, this, SLOT(slotSetRenderPathBasic()), actionCollection(), "renderPathBasic");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("Multitexture"), 0, this, SLOT(slotSetRenderPathMultitexture()), actionCollection(), "renderPathMultitexture");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("NvCombiners"), 0, this, SLOT(slotSetRenderPathNvCombiner()), actionCollection(), "renderPathNvCombiner");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("DOT3 ARBVP"), 0, this, SLOT(slotSetRenderPathDOT3ARBVP()), actionCollection(), "renderPathDOT3ARBVP");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("NvCombiner NvVP"), 0, this, SLOT(slotSetRenderPathNvCombinerNvVP()), actionCollection(), "renderPathNvCombinerNvVP");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("NvCombiner ARBVP"), 0, this, SLOT(slotSetRenderPathNvCombinerARBVP()), actionCollection(), "renderPathNvCombinerARBVP");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("ARBFP ARBVP"), 0, this, SLOT(slotSetRenderPathARBFPARBVP()), actionCollection(), "renderPathARBFPARBVP");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("NV30"), 0, this, SLOT(slotSetRenderPathNV30()), actionCollection(), "renderPathNV30");    renderPath->setExclusiveGroup("renderPath");    renderPath = new KToggleAction(i18n("OpenGL 2.0"), 0, this, SLOT(slotSetRenderPathGLSL()), actionCollection(), "renderPathGLSL");    renderPath->setExclusiveGroup("renderPath");    new KAction(i18n("Cycle OpenGL Render Path"), "reload", CTRL + Key_V, this, SLOT(slotCycleRenderPath()), actionCollection(), "cycleRenderPath");    new KAction(i18n("Grab Image"), "filesave", Key_F10, this, SLOT(slotGrabImage()), actionCollection(), "grabImage");    new KAction(i18n("OpenGL info"), 0, this, SLOT(slotOpenGLInfo()),                      actionCollection(), "opengl_info");    toggleMenubar=KStdAction::showMenubar(this, SLOT(slotToggleMenubar()), actionCollection());    toggleToolbar=KStdAction::showToolbar(this, SLOT(slotToggleToolbar()), actionCollection());    new KToggleAction(i18n("Show Bookmark Toolbar"), 0, this,        SLOT(slotShowBookmarkBar()), actionCollection(), "showBookmarkBar");    createGUI();        bookmarkBarActionCollection = new KActionCollection( this );    bookmarkBarActionCollection->setHighlightingEnabled( true );    bookmarkBar = 0;    initBookmarkBar();    }void KdeApp::initBookmarkBar() {    KToolBar *bar = new KToolBar(this, QMainWindow::Top, true, "bookmarkBar");        if (bookmarkBar) delete bookmarkBar;    bookmarkBar = new KBookmarkBar( KCelBookmarkManager::self(), this, bar, bookmarkBarActionCollection, 0, "bookmarkBar");    if (bar->count() == 0) bar->hide();    applyMainWindowSettings( KGlobal::config(), "MainWindow" );    if (bar->isHidden()) ((KToggleAction*)actionCollection()->action("showBookmarkBar"))->setChecked(false);    else ((KToggleAction*)actionCollection()->action("showBookmarkBar"))->setChecked(true);}bool KdeApp::queryExit() {     KConfig* conf = kapp->config();    saveMainWindowSettings(conf, "MainWindow");    conf->setGroup("MainWindow");    saveWindowSize(conf);    conf->setGroup("Preferences");    conf->writeEntry("RendererFlags", appCore->getRenderer()->getRenderFlags());    conf->writeEntry("OrbitMask", appCore->getRenderer()->getOrbitMask());    conf->writeEntry("LabelMode", appCore->getRenderer()->getLabelMode());    conf->writeEntry("AmbientLightLevel", appCore->getRenderer()->getAmbientLightLevel());    conf->writeEntry("FaintestVisible", appCore->getSimulation()->getFaintestVisible());    conf->writeEntry("HudDetail", appCore->getHudDetail());    conf->writeEntry("TimeZoneBias", appCore->getTimeZoneBias());    conf->writeEntry("RenderPath", appCore->getRenderer()->getGLContext()->getRenderPath());    conf->writeEntry("FramesVisible", appCore->getFramesVisible());    conf->writeEntry("ActiveFrameVisible", appCore->getActiveFrameVisible());    conf->writeEntry("SyncTime", appCore->getSimulation()->getSyncTime());    conf->writeEntry("DistanceToScreen", appCore->getDistanceToScreen());    conf->writeEntry("LocationFilter", appCore->getSimulation()->getActiveObserver()->getLocationFilter());    conf->writeEntry("MinFeatureSize", appCore->getRenderer()->getMinimumFeatureSize());    conf->setGroup(0);    actionCollection()->writeShortcutSettings("Shortcuts", conf);    openRecent->saveEntries(KGlobal::config());    return true;}bool KdeApp::queryClose() {    KConfig* conf = kapp->config();    saveMainWindowSettings(conf, "MainWindow");    conf->setGroup("MainWindow");    saveWindowSize(conf);    conf->setGroup("Preferences");    conf->writeEntry("RendererFlags", appCore->getRenderer()->getRenderFlags());    conf->setGroup(0);    return true;}void KdeApp::slotNull() {    // dev only}void KdeApp::slotFullScreen() {    static bool isFullScreen=false;    if (isFullScreen) {        showNormal();        action("fullScreen")->setIcon("window_fullscreen");    } else {        showFullScreen();        action("fullScreen")->setIcon("window_nofullscreen");    }                 isFullScreen = !isFullScreen;}void KdeApp::slotHome() {    appCore->charEntered('h');    appCore->charEntered('g');}void KdeApp::slotClose() {    close();}void KdeApp::slotZoomIn() {    appCore->charEntered(',');}void KdeApp::slotZoomOut() {    appCore->charEntered('.');}void KdeApp::slotToggleToolbar() {    if (toolBar()->isVisible()) toolBar()->hide();    else toolBar()->show();}void KdeApp::slotToggleMenubar() {    if (menuBar()->isVisible()) menuBar()->hide();    else menuBar()->show();}void KdeApp::slotToggleFramesVisible() {    appCore->setFramesVisible(!appCore->getFramesVisible());}void KdeApp::slotToggleActiveFrameVisible() {    appCore->setActiveFrameVisible(!appCore->getActiveFrameVisible());}void KdeApp::slotToggleSyncTime() {    appCore->getSimulation()->setSyncTime(!appCore->getSimulation()->getSyncTime());}void KdeApp::slotConfigureToolbars(){    saveMainWindowSettings( KGlobal::config(), "MainWindow" );    KEditToolbar dlg(actionCollection());    connect( &dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()));    if (dlg.exec())    {        createGUI();        initBookmarkBar();    }}void KdeApp::slotNewToolbarConfig() // This is called when OK or Apply is clicked{//    ...if you use any action list, use plugActionList on each here...    applyMainWindowSettings( KGlobal::config(), "MainWindow" );}void KdeApp::slotKeyBindings(){    KKeyDialog dlg(false, this);    dlg.insert(actionCollection());    if (dlg.exec()) {        dlg.commitChanges();    }}void KdeApp::slotFileOpen(){#ifdef CELX    QString fileOpen = KFileDialog::getOpenFileName(0, "*.cel *.celx");#else    QString fileOpen = KFileDialog::getOpenFileName(0, "*.cel");#endif    if (fileOpen == "") return;    slotOpenFileURL(KURL(fileOpen));}void KdeApp::slotOpenFileURL(const KURL& url) {    QString file = url.directory(false) + url.fileName();#ifdef CELX    if (file.right(5).compare(QString(".celx")) == 0) {        openRecent->addURL(url);        appCore->cancelScript();        appCore->runScript(file.latin1());        return;    }#endif    ifstream scriptfile(file.latin1());    if (!scriptfile.good()) {        KMessageBox::error(this, "Error opening script file " + file);        return;    } else {        CommandParser parser(scriptfile);        CommandSequence* script = parser.parse();        if (script == NULL) {            const vector<string>* errors = parser.getErrors();            const char* errorMsg = "";            if (errors->size() > 0)                errorMsg = (*errors)[0].c_str();            KMessageBox::error(this, "Errors in script file " + file + "\n" + errorMsg);            return;        } else {            openRecent->addURL(url);            appCore->cancelScript();            appCore->runScript(script);        }    }}QString KdeApp::getOpenGLInfo() {    // Code grabbed from gtkmain.cpp    char* vendor = (char*) glGetString(GL_VENDOR);    char* render = (char*) glGetString(GL_RENDERER);    char* version = (char*) glGetString(GL_VERSION);    char* ext = (char*) glGetString(GL_EXTENSIONS);    QString s;    s = "Vendor : ";    if (vendor != NULL)        s += vendor;    s += "\n";    s += "Renderer : ";    if (render != NULL)        s += render;    s += "\n";    s += "Version : ";    if (version != NULL)        s += version;    s += "\n";    char buf[100];    GLint simTextures = 1;    if (ExtensionSupported("GL_ARB_multitexture"))        glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &simTextures);    sprintf(buf, "Max simultaneous textures: %d\n", simTextures);    s += buf;    GLint maxTextureSize = 0;    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);    sprintf(buf, "Max texture size: %d\n\n", maxTextureSize);    s += buf;    s += "Supported Extensions:\n    ";    if (ext != NULL)    {        QString extString(ext);        unsigned int pos = extString.find(' ', 0);        while (pos != (unsigned int)string::npos)        {            extString.replace(pos, 1, "\n    ");            pos = extString.find(' ', pos+5);        }        s += extString;    }    return s;}void KdeApp::slotOpenGLInfo() {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?