kdeapp.cpp

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

CPP
1,548
字号
}void KdeApp::slotSingleView() {    appCore->charEntered('\004');}void KdeApp::slotDeleteView() {    appCore->charEntered(127);}void KdeApp::slotAmbientLightLevel(float l) {    appCore->getRenderer()->setAmbientLightLevel(l);}void KdeApp::slotFaintestVisible(float m) {    appCore->getSimulation()->setFaintestVisible(m);}void KdeApp::slotHudDetail(int l) {    appCore->setHudDetail(l);}void KdeApp::slotDisplayLocalTime() {    if (appCore->getTimeZoneBias()) {        appCore->setTimeZoneBias(0);        appCore->setTimeZoneName(i18n("UTC").latin1());    } else {        appCore->setTimeZoneBias(-timezone+3600*daylight);        appCore->setTimeZoneName(tzname[daylight?0:1]);    }}void KdeApp::slotWireframeMode() {	static bool mode = false;	mode = !mode;	renderer->setRenderMode(mode ? GL_LINE : GL_FILL);}void KdeApp::slotCenterCO() {	appCore->charEntered('C');}void KdeApp::slotSetRenderPathBasic() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_Basic)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_Basic);}void KdeApp::slotSetRenderPathMultitexture() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_Multitexture)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_Multitexture);}void KdeApp::slotSetRenderPathNvCombiner() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_NvCombiner)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_NvCombiner);}void KdeApp::slotSetRenderPathDOT3ARBVP() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_DOT3_ARBVP)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_DOT3_ARBVP);}void KdeApp::slotSetRenderPathNvCombinerNvVP() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_NvCombiner_NvVP)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_NvCombiner_NvVP);}void KdeApp::slotSetRenderPathNvCombinerARBVP() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_NvCombiner_ARBVP)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_NvCombiner_ARBVP);}void KdeApp::slotSetRenderPathARBFPARBVP() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_ARBFP_ARBVP)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_ARBFP_ARBVP);}void KdeApp::slotSetRenderPathNV30() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_NV30)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_NV30);}void KdeApp::slotSetRenderPathGLSL() {    if (appCore->getRenderer()->getGLContext()->getRenderPath() != GLContext::GLPath_GLSL)        appCore->getRenderer()->getGLContext()->setRenderPath(GLContext::GLPath_GLSL);}void KdeApp::slotCycleRenderPath() {    appCore->charEntered('\026');}void KdeApp::slotGrabImage() {    QString saveAsName = KFileDialog::getSaveFileName(0, "*.png");    if (saveAsName != "") {        QImage grabedImage = glWidget->grabFrameBuffer();        grabedImage.save(saveAsName, "PNG");    }}void KdeApp::slotShowBookmarkBar() {    KToolBar * bar = static_cast<KToolBar *>( child( "bookmarkBar", "KToolBar" ) );    if (bar->isVisible()) bar->hide();    else bar->show();}void KdeApp::slotBack() {    appCore->back();}void KdeApp::slotForward() {    appCore->forward();}void KdeApp::slotCopyUrl() {    Url url(appCore);    static QClipboard *cb = QApplication::clipboard();    cb->setText(url.getAsString().c_str());}void KdeApp::slotGoTo() {    KLineEditDlg dlg(i18n("Enter URL"), "", this);    if (dlg.exec()) {        appCore->addToHistory();        appCore->goToUrl(dlg.text().latin1());    }}void KdeApp::slotGoToLongLat() {    LongLatDialog dlg(this, appCore);    dlg.exec();}void KdeApp::dragEnterEvent(QDragEnterEvent* event) {    KURL::List urls;    event->accept(KURLDrag::canDecode(event) && KURLDrag::decode(event, urls) && urls.first().protocol() == "cel");}void KdeApp::dropEvent(QDropEvent* event) {    KURL::List urls;    if (KURLDrag::decode(event, urls) && urls.first().protocol() == "cel") {        appCore->addToHistory();        appCore->goToUrl(urls.first().url().latin1());    }}void KdeApp::slotBackAboutToShow() {    int i;     KPopupMenu* menu = backAction->popupMenu();    std::vector<Url>::size_type current = appCore->getHistoryCurrent();    int pos;    std::vector<Url> history = appCore->getHistory();     menu->clear();     for (i=0, pos = current - 1 ; pos >= 0 && i < 15 ; pos--, i++) {        menu->insertItem(QString(history[pos].getName().c_str()), pos);    }}void KdeApp::slotBackActivated(int i) {    appCore->setHistoryCurrent(i);}void KdeApp::slotForwardAboutToShow() {    int i;    KPopupMenu* menu = forwardAction->popupMenu();    std::vector<Url>::size_type current = appCore->getHistoryCurrent();    std::vector<Url>::size_type pos;    std::vector<Url> history = appCore->getHistory();    menu->clear();    for (i=0, pos = current + 1 ; pos < history.size() && i < 15 ; pos++, i++) {        menu->insertItem(QString(history[pos].getName().c_str()), pos);    }}void KdeApp::slotForwardActivated(int i) {    appCore->setHistoryCurrent(i);}void KdeApp::slotCelestialBrowser() {    static CelestialBrowser *cb = new CelestialBrowser(this, appCore);    cb->show();    cb->showNormal();    cb->setActiveWindow();    cb->raise();}void KdeApp::slotEclipseFinder() {    static EclipseFinderDlg *ef = new EclipseFinderDlg(this, appCore);    ef->show();    ef->showNormal();    ef->setActiveWindow();    ef->raise();}void KdeApp::popupMenu(float x, float y, Selection sel) {    SelectionPopup popup(app, app->appCore, sel);    popup.init();    int id = popup.exec(app->glWidget->mapToGlobal(QPoint(int(x),int(y))));    popup.process(id);}LongLatDialog::LongLatDialog(QWidget* parent, CelestiaCore* appCore) :   KDialogBase(parent, "long_lat", true, "Go to Long/Lat"), appCore(appCore){    QGrid* grid = makeGridMainWidget(3, Qt::Horizontal);    QLabel* objLab = new QLabel(i18n("Object: "), grid);    objLab->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    objEdit = new QLineEdit(grid);    new QLabel("", grid);    QLabel* longLab = new QLabel(i18n("Longitude: "), grid);    longLab->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    longEdit = new QLineEdit(grid);    longEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    longEdit->setValidator(new QDoubleValidator(0, 180, 3, longEdit));    longSign = new QComboBox( grid );    longSign->insertItem(i18n("East", "E"));    longSign->insertItem(i18n("West", "W"));    QLabel* latLab = new QLabel(i18n("Latitude: "), grid);    latLab->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    latEdit = new QLineEdit(grid);    latEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    latEdit->setValidator(new QDoubleValidator(0, 90, 3, latEdit));    latSign = new QComboBox( grid );    latSign->insertItem(i18n("North", "N"));    latSign->insertItem(i18n("South", "S"));        QLabel* altLab = new QLabel(i18n("Altitude: "), grid);    altLab->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    altEdit = new QLineEdit(grid);    altEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);    altEdit->setValidator(new QDoubleValidator(altEdit));    new QLabel(i18n("km"), grid);        double distance, longitude, latitude;    appCore->getSimulation()->getSelectionLongLat(distance, longitude, latitude);        if (longitude < 0) {        longitude = -longitude;        longSign->setCurrentItem(1);    }    if (latitude < 0) {        latitude = -latitude;        latSign->setCurrentItem(1);    }        Selection selection = appCore->getSimulation()->getSelection();    QString objName(selection.getName().c_str());    objEdit->setText(objName.mid(objName.findRev('/') + 1));        latEdit->setText(QString("%1").arg(latitude, 0, 'f', 3));    longEdit->setText(QString("%1").arg(longitude, 0, 'f', 3));    altEdit->setText(QString("%1").arg(distance - selection.radius(), 0, 'f', 0));}void LongLatDialog::slotCancel() {    reject();}void LongLatDialog::slotOk() {    slotApply();    accept();}KdeAlerter alerter;void LongLatDialog::slotApply() {    Simulation* appSim = appCore->getSimulation();    Selection sel = appSim->findObjectFromPath(objEdit->text().latin1());    if (!sel.empty())    {        appSim->setSelection(sel);        appSim->follow();        double altitude = altEdit->text().toDouble();        if (altitude < 0.020) altitude = .020;        double distance = altitude + sel.radius();        distance = astro::kilometersToLightYears(distance);        double longitude = longEdit->text().toDouble();        if (longSign->currentItem() == 1) {            longitude = -longitude;        }        double latitude = latEdit->text().toDouble();        if (latSign->currentItem() == 1) {            latitude = -latitude;        }        appSim->gotoSelectionLongLat(5.0,                                distance,                                degToRad(longitude),                                degToRad(latitude),                                Vec3f(0, 1, 0));    }}KdeAlerter::KdeAlerter(QWidget* _parent) : parent(_parent){}void KdeAlerter::fatalError(const std::string& err){    KMessageBox::detailedError(parent, i18n("Celestia encountered an error while processing your script"), QString(err.c_str()));}

⌨️ 快捷键说明

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