void tst_QMenu::tearOff() { QWidget widget; QMenu *menu = new QMenu(&widget); QVERIFY(!menu->isTearOffEnabled()); //default value menu->setTearOffEnabled(true); menu->addAction("aaa"); menu->addAction("bbb"); QVERIFY(menu->isTearOffEnabled()); widget.show(); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); menu->popup(QPoint(0,0)); QVERIFY(QTest::qWaitForWindowActive(menu)); QVERIFY(!menu->isTearOffMenuVisible()); QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10); QTRY_VERIFY(menu->isTearOffMenuVisible()); QPointer<QMenu> torn = 0; foreach (QWidget *w, QApplication::allWidgets()) { if (w->inherits("QTornOffMenu")) { torn = static_cast<QMenu *>(w); break; } } QVERIFY(torn); QVERIFY(torn->isVisible()); menu->hideTearOffMenu(); QVERIFY(!menu->isTearOffMenuVisible()); QVERIFY(!torn->isVisible()); }
TazDlg::TazDlg(QWidget* pParent) : QMainWindow(pParent), m_settings("tobis_stuff", "takin"), m_pSettingsDlg(new SettingsDlg(this, &m_settings)), m_pStatusMsg(new QLabel(this)), m_pCoordQStatusMsg(new QLabel(this)), m_pCoordCursorStatusMsg(new QLabel(this)), m_sceneRecip(this), m_dlgRecipParam(this, &m_settings), m_dlgRealParam(this, &m_settings), m_pGotoDlg(new GotoDlg(this, &m_settings)) { //log_debug("In ", __func__, "."); const bool bSmallqVisible = 0; const bool bBZVisible = 1; const bool bWSVisible = 1; this->setupUi(this); this->setWindowTitle(s_strTitle.c_str()); this->setFont(g_fontGen); this->setWindowIcon(load_icon("res/icons/takin.svg")); btnAtoms->setEnabled(g_bHasScatlens); if(m_settings.contains("main/geo")) { QByteArray geo = m_settings.value("main/geo").toByteArray(); restoreGeometry(geo); } /*if(m_settings.contains("main/width") && m_settings.contains("main/height")) { int iW = m_settings.value("main/width").toInt(); int iH = m_settings.value("main/height").toInt(); resize(iW, iH); }*/ m_pStatusMsg->setFrameStyle(QFrame::Panel | QFrame::Sunken); m_pCoordQStatusMsg->setFrameStyle(QFrame::Panel | QFrame::Sunken); m_pCoordCursorStatusMsg->setFrameStyle(QFrame::Panel | QFrame::Sunken); for(QLabel* pLabel : {m_pStatusMsg/*, m_pCoordQStatusMsg, m_pCoordCursorStatusMsg*/}) pLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); QStatusBar *pStatusBar = new QStatusBar(this); pStatusBar->addWidget(m_pStatusMsg, 1); pStatusBar->addPermanentWidget(m_pCoordQStatusMsg, 0); pStatusBar->addPermanentWidget(m_pCoordCursorStatusMsg, 0); m_pCoordQStatusMsg->setMinimumWidth(350); m_pCoordQStatusMsg->setAlignment(Qt::AlignCenter); m_pCoordCursorStatusMsg->setMinimumWidth(325); m_pCoordCursorStatusMsg->setAlignment(Qt::AlignCenter); this->setStatusBar(pStatusBar); // -------------------------------------------------------------------------------- m_vecEdits_real = { editA, editB, editC, editAlpha, editBeta, editGamma }; m_vecEdits_recip = { editARecip, editBRecip, editCRecip, editAlphaRecip, editBetaRecip, editGammaRecip }; m_vecEdits_plane = { editScatX0, editScatX1, editScatX2, editScatY0, editScatY1, editScatY2, editRealX0, editRealX1, editRealX2, editRealY0, editRealY1, editRealY2, }; m_vecEdits_monoana = { editMonoD, editAnaD }; //m_vecSpinBoxesSample = { spinRotPhi, spinRotTheta, spinRotPsi }; m_vecCheckBoxesSenses = { checkSenseM, checkSenseS, checkSenseA }; m_vecEditNames_real = { "sample/a", "sample/b", "sample/c", "sample/alpha", "sample/beta", "sample/gamma" }; m_vecEditNames_recip = { "sample/a_recip", "sample/b_recip", "sample/c_recip", "sample/alpha_recip", "sample/beta_recip", "sample/gamma_recip" }; m_vecEditNames_plane = { "plane/x0", "plane/x1", "plane/x2", "plane/y0", "plane/y1", "plane/y2", "plane/real_x0", "plane/real_x1", "plane/real_x2", "plane/real_y0", "plane/real_y1", "plane/real_y2", }; m_vecEditNames_monoana = { "tas/mono_d", "tas/ana_d" }; m_vecSpinBoxNamesSample = {"sample/phi", "sample/theta", "sample/psi"}; m_vecCheckBoxNamesSenses = {"tas/sense_m", "tas/sense_s", "tas/sense_a"}; // recip m_pviewRecip = new ScatteringTriangleView(groupRecip); groupRecip->addTab(m_pviewRecip, "Reciprocal Lattice"); m_pviewProjRecip = new ProjLatticeView(groupRecip); groupRecip->addTab(m_pviewProjRecip, "Projection"); m_pviewRecip->setScene(&m_sceneRecip); m_pviewProjRecip->setScene(&m_sceneProjRecip); if(m_settings.contains("main/recip_tab")) groupRecip->setCurrentIndex(m_settings.value("main/recip_tab").value<int>()); // real m_pviewRealLattice = new LatticeView(groupReal); groupReal->addTab(m_pviewRealLattice, "Real Lattice"); m_pviewReal = new TasLayoutView(groupReal); groupReal->addTab(m_pviewReal, "TAS Instrument"); m_pviewTof = new TofLayoutView(groupReal); groupReal->addTab(m_pviewTof, "TOF Instrument"); m_pviewRealLattice->setScene(&m_sceneRealLattice); m_pviewReal->setScene(&m_sceneReal); m_pviewTof->setScene(&m_sceneTof); if(m_settings.contains("main/real_tab")) groupReal->setCurrentIndex(m_settings.value("main/real_tab").value<int>()); QObject::connect(m_pSettingsDlg, SIGNAL(SettingsChanged()), this, SLOT(SettingsChanged())); QObject::connect(&m_sceneReal, SIGNAL(nodeEvent(bool)), this, SLOT(RealNodeEvent(bool))); QObject::connect(&m_sceneRecip, SIGNAL(nodeEvent(bool)), this, SLOT(RecipNodeEvent(bool))); QObject::connect(&m_sceneTof, SIGNAL(nodeEvent(bool)), this, SLOT(TofNodeEvent(bool))); // TAS QObject::connect(&m_sceneRecip, SIGNAL(triangleChanged(const TriangleOptions&)), &m_sceneReal, SLOT(triangleChanged(const TriangleOptions&))); QObject::connect(&m_sceneReal, SIGNAL(tasChanged(const TriangleOptions&)), &m_sceneRecip, SLOT(tasChanged(const TriangleOptions&))); QObject::connect(&m_sceneRecip, SIGNAL(paramsChanged(const RecipParams&)), &m_sceneReal, SLOT(recipParamsChanged(const RecipParams&))); // TOF QObject::connect(&m_sceneRecip, SIGNAL(triangleChanged(const TriangleOptions&)), &m_sceneTof, SLOT(triangleChanged(const TriangleOptions&))); QObject::connect(&m_sceneTof, SIGNAL(tasChanged(const TriangleOptions&)), &m_sceneRecip, SLOT(tasChanged(const TriangleOptions&))); QObject::connect(&m_sceneRecip, SIGNAL(paramsChanged(const RecipParams&)), &m_sceneTof, SLOT(recipParamsChanged(const RecipParams&))); // connections between instruments QObject::connect(&m_sceneTof, SIGNAL(tasChanged(const TriangleOptions&)), &m_sceneReal, SLOT(triangleChanged(const TriangleOptions&))); QObject::connect(&m_sceneReal, SIGNAL(tasChanged(const TriangleOptions&)), &m_sceneTof, SLOT(triangleChanged(const TriangleOptions&))); // scale factor if(m_pviewRecip) QObject::connect(m_pviewRecip, SIGNAL(scaleChanged(t_real_glob)), &m_sceneRecip, SLOT(scaleChanged(t_real_glob))); if(m_pviewProjRecip) QObject::connect(m_pviewProjRecip, SIGNAL(scaleChanged(t_real_glob)), &m_sceneProjRecip, SLOT(scaleChanged(t_real_glob))); if(m_pviewRealLattice) QObject::connect(m_pviewRealLattice, SIGNAL(scaleChanged(t_real_glob)), &m_sceneRealLattice, SLOT(scaleChanged(t_real_glob))); if(m_pviewReal) QObject::connect(m_pviewReal, SIGNAL(scaleChanged(t_real_glob)), &m_sceneReal, SLOT(scaleChanged(t_real_glob))); if(m_pviewTof) QObject::connect(m_pviewTof, SIGNAL(scaleChanged(t_real_glob)), &m_sceneTof, SLOT(scaleChanged(t_real_glob))); // parameter dialogs QObject::connect(&m_sceneRecip, SIGNAL(paramsChanged(const RecipParams&)), &m_dlgRecipParam, SLOT(paramsChanged(const RecipParams&))); QObject::connect(&m_sceneReal, SIGNAL(paramsChanged(const RealParams&)), &m_dlgRealParam, SLOT(paramsChanged(const RealParams&))); // cursor position QObject::connect(&m_sceneRecip, SIGNAL(coordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob)), this, SLOT(RecipCoordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob))); QObject::connect(&m_sceneProjRecip, SIGNAL(coordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob)), this, SLOT(RecipCoordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob))); QObject::connect(&m_sceneRealLattice, SIGNAL(coordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob)), this, SLOT(RealCoordsChanged(t_real_glob, t_real_glob, t_real_glob, bool, t_real_glob, t_real_glob, t_real_glob))); QObject::connect(&m_sceneRecip, SIGNAL(spurionInfo(const tl::ElasticSpurion&, const std::vector<tl::InelasticSpurion<t_real_glob>>&, const std::vector<tl::InelasticSpurion<t_real_glob>>&)), this, SLOT(spurionInfo(const tl::ElasticSpurion&, const std::vector<tl::InelasticSpurion<t_real_glob>>&, const std::vector<tl::InelasticSpurion<t_real_glob>>&))); QObject::connect(m_pGotoDlg, SIGNAL(vars_changed(const CrystalOptions&, const TriangleOptions&)), this, SLOT(VarsChanged(const CrystalOptions&, const TriangleOptions&))); QObject::connect(&m_sceneRecip, SIGNAL(paramsChanged(const RecipParams&)), m_pGotoDlg, SLOT(RecipParamsChanged(const RecipParams&))); QObject::connect(&m_sceneRecip, SIGNAL(paramsChanged(const RecipParams&)), this, SLOT(recipParamsChanged(const RecipParams&))); for(QLineEdit* pEdit : m_vecEdits_monoana) QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(UpdateDs())); for(QLineEdit* pEdit : m_vecEdits_real) { QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(CheckCrystalType())); QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(CalcPeaks())); } for(QLineEdit* pEdit : m_vecEdits_plane) { QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(CalcPeaks())); } //for(QDoubleSpinBox* pSpin : m_vecSpinBoxesSample) // QObject::connect(pSpin, SIGNAL(valueChanged(t_real)), this, SLOT(CalcPeaks())); for(QLineEdit* pEdit : m_vecEdits_recip) { QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(CheckCrystalType())); QObject::connect(pEdit, SIGNAL(textEdited(const QString&)), this, SLOT(CalcPeaksRecip())); } QObject::connect(checkSenseM, SIGNAL(stateChanged(int)), this, SLOT(UpdateMonoSense())); QObject::connect(checkSenseS, SIGNAL(stateChanged(int)), this, SLOT(UpdateSampleSense())); QObject::connect(checkSenseA, SIGNAL(stateChanged(int)), this, SLOT(UpdateAnaSense())); QObject::connect(editSpaceGroupsFilter, SIGNAL(textEdited(const QString&)), this, SLOT(RepopulateSpaceGroups())); QObject::connect(comboSpaceGroups, SIGNAL(currentIndexChanged(int)), this, SLOT(SetCrystalType())); QObject::connect(comboSpaceGroups, SIGNAL(currentIndexChanged(int)), this, SLOT(CalcPeaks())); QObject::connect(checkPowder, SIGNAL(stateChanged(int)), this, SLOT(CalcPeaks())); QObject::connect(btnAtoms, SIGNAL(clicked(bool)), this, SLOT(ShowAtomsDlg())); // -------------------------------------------------------------------------------- // file menu QMenu *pMenuFile = new QMenu("File", this); QAction *pNew = new QAction("New", this); pNew->setIcon(load_icon("res/icons/document-new.svg")); pMenuFile->addAction(pNew); pMenuFile->addSeparator(); QAction *pLoad = new QAction("Load...", this); pLoad->setIcon(load_icon("res/icons/document-open.svg")); pMenuFile->addAction(pLoad); m_pMenuRecent = new QMenu("Recently Loaded", this); tl::RecentFiles recent(&m_settings, "main/recent"); m_pMapperRecent = new QSignalMapper(m_pMenuRecent); QObject::connect(m_pMapperRecent, SIGNAL(mapped(const QString&)), this, SLOT(LoadFile(const QString&))); recent.FillMenu(m_pMenuRecent, m_pMapperRecent); pMenuFile->addMenu(m_pMenuRecent); QAction *pSave = new QAction("Save", this); pSave->setIcon(load_icon("res/icons/document-save.svg")); pMenuFile->addAction(pSave); QAction *pSaveAs = new QAction("Save as...", this); pSaveAs->setIcon(load_icon("res/icons/document-save-as.svg")); pMenuFile->addAction(pSaveAs); pMenuFile->addSeparator(); QAction *pImport = new QAction("Import...", this); pImport->setIcon(load_icon("res/icons/drive-harddisk.svg")); pMenuFile->addAction(pImport); m_pMenuRecentImport = new QMenu("Recently Imported", this); tl::RecentFiles recentimport(&m_settings, "main/recent_import"); m_pMapperRecentImport = new QSignalMapper(m_pMenuRecentImport); QObject::connect(m_pMapperRecentImport, SIGNAL(mapped(const QString&)), this, SLOT(ImportFile(const QString&))); recentimport.FillMenu(m_pMenuRecentImport, m_pMapperRecentImport); pMenuFile->addMenu(m_pMenuRecentImport); pMenuFile->addSeparator(); QAction *pSettings = new QAction("Settings...", this); pSettings->setIcon(load_icon("res/icons/preferences-system.svg")); pMenuFile->addAction(pSettings); pMenuFile->addSeparator(); QAction *pExit = new QAction("Exit", this); pExit->setIcon(load_icon("res/icons/system-log-out.svg")); pMenuFile->addAction(pExit); // -------------------------------------------------------------------------------- // recip menu m_pMenuViewRecip = new QMenu("Reciprocal Space", this); m_pGoto = new QAction("Go to Position...", this); m_pGoto->setIcon(load_icon("res/icons/goto.svg")); m_pMenuViewRecip->addAction(m_pGoto); QAction *pRecipParams = new QAction("Information...", this); m_pMenuViewRecip->addAction(pRecipParams); m_pMenuViewRecip->addSeparator(); m_pSmallq = new QAction("Show Reduced Scattering Vector q", this); m_pSmallq->setIcon(load_icon("res/icons/q.svg")); m_pSmallq->setCheckable(1); m_pSmallq->setChecked(bSmallqVisible); m_pMenuViewRecip->addAction(m_pSmallq); m_pSnapSmallq = new QAction("Snap G to Bragg Peak", this); m_pSnapSmallq->setCheckable(1); m_pSnapSmallq->setChecked(m_sceneRecip.getSnapq()); m_pMenuViewRecip->addAction(m_pSnapSmallq); QAction *pKeepAbsKiKf = new QAction("Keep |ki| and |kf| Fixed", this); pKeepAbsKiKf->setCheckable(1); pKeepAbsKiKf->setChecked(m_sceneRecip.getKeepAbsKiKf()); m_pMenuViewRecip->addAction(pKeepAbsKiKf); m_pBZ = new QAction("Show First Brillouin Zone", this); m_pBZ->setIcon(load_icon("res/icons/brillouin.svg")); m_pBZ->setCheckable(1); m_pBZ->setChecked(bBZVisible); m_pMenuViewRecip->addAction(m_pBZ); QMenu *pMenuEwald = new QMenu("Ewald Sphere", this); QActionGroup *pGroupEwald = new QActionGroup(this); m_pEwaldSphereNone = new QAction("Disabled", this); m_pEwaldSphereKi = new QAction("Around ki", this); m_pEwaldSphereKf = new QAction("Around kf", this); for(QAction* pAct : {m_pEwaldSphereNone, m_pEwaldSphereKi, m_pEwaldSphereKf}) { pAct->setCheckable(1); pGroupEwald->addAction(pAct); } m_pEwaldSphereKf->setChecked(1); pMenuEwald->addActions(pGroupEwald->actions()); m_pMenuViewRecip->addMenu(pMenuEwald); m_pMenuViewRecip->addSeparator(); QMenu *pMenuProj = new QMenu("Projection", this); pMenuProj->setTearOffEnabled(1); QActionGroup *pGroupProj = new QActionGroup(this); m_pProjGnom = new QAction("Gnomonic", this); m_pProjStereo = new QAction("Stereographic", this); m_pProjPara = new QAction("Parallel", this); m_pProjPersp = new QAction("Perspectivic", this); for(QAction *pAct : {m_pProjGnom, m_pProjStereo, m_pProjPara, m_pProjPersp}) { pAct->setCheckable(1); pGroupProj->addAction(pAct); } m_pProjStereo->setChecked(1); pMenuProj->addActions(pGroupProj->actions()); m_pMenuViewRecip->addMenu(pMenuProj); #if !defined NO_3D QAction *pView3D = new QAction("3D View...", this); //pView3D->setIcon(QIcon::fromTheme("applications-graphics")); m_pMenuViewRecip->addAction(pView3D); #endif m_pMenuViewRecip->addSeparator(); QAction *pRecipExport = new QAction("Export Lattice Graphics...", this); pRecipExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewRecip->addAction(pRecipExport); QAction *pProjExport = new QAction("Export Projection Graphics...", this); pProjExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewRecip->addAction(pProjExport); #ifdef USE_GIL QAction *pBZExport = new QAction("Export Brillouin Zone Image...", this); pBZExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewRecip->addAction(pBZExport); #endif // -------------------------------------------------------------------------------- // real menu m_pMenuViewReal = new QMenu("Real Space", this); m_pMenuViewReal->addAction(m_pGoto); QAction *pRealParams = new QAction("Information...", this); m_pMenuViewReal->addAction(pRealParams); m_pMenuViewReal->addSeparator(); m_pShowRealQDir = new QAction("Show Q Direction", this); m_pShowRealQDir->setCheckable(1); m_pShowRealQDir->setChecked(m_sceneReal.GetTasLayout()->GetRealQVisible()); m_pMenuViewReal->addAction(m_pShowRealQDir); m_pWS = new QAction("Show Wigner-Seitz Cell", this); m_pWS->setIcon(load_icon("res/icons/brillouin.svg")); m_pWS->setCheckable(1); m_pWS->setChecked(bWSVisible); m_pMenuViewReal->addAction(m_pWS); m_pMenuViewReal->addSeparator(); #if !defined NO_3D QAction *pView3DReal = new QAction("3D View...", this); //pView3DReal->setIcon(QIcon::fromTheme("applications-graphics")); m_pMenuViewReal->addAction(pView3DReal); m_pMenuViewReal->addSeparator(); #endif QAction *pRealLatticeExport = new QAction("Export Lattice Graphics...", this); pRealLatticeExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewReal->addAction(pRealLatticeExport); QAction *pRealExport = new QAction("Export TAS Layout...", this); pRealExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewReal->addAction(pRealExport); QAction *pTofExport = new QAction("Export TOF Layout...", this); pTofExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewReal->addAction(pTofExport); #ifdef USE_GIL QAction *pWSExport = new QAction("Export Wigner-Seitz Cell Image...", this); pWSExport->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewReal->addAction(pWSExport); #endif QAction *pExportUC = new QAction("Export Unit Cell Model...", this); pExportUC->setIcon(load_icon("res/icons/image-x-generic.svg")); m_pMenuViewReal->addAction(pExportUC); // -------------------------------------------------------------------------------- // resolution menu QMenu *pMenuReso = new QMenu("Resolution", this); QAction *pResoParams = new QAction("Parameters...", this); pResoParams->setIcon(load_icon("res/icons/accessories-calculator.svg")); pMenuReso->addAction(pResoParams); pMenuReso->addSeparator(); QAction *pResoEllipses = new QAction("Ellipses...", this); pResoEllipses->setIcon(load_icon("res/icons/ellipses.svg")); pMenuReso->addAction(pResoEllipses); #if !defined NO_3D QAction *pResoEllipses3D = new QAction("3D Ellipsoids...", this); pMenuReso->addAction(pResoEllipses3D); #endif pMenuReso->addSeparator(); QAction *pResoConv = new QAction("Convolution...", this); pMenuReso->addAction(pResoConv); // -------------------------------------------------------------------------------- // calc menu QMenu *pMenuCalc = new QMenu("Calculation", this); QAction *pNeutronProps = new QAction("Neutron Properties...", this); pNeutronProps->setIcon(load_icon("res/icons/x-office-spreadsheet-template.svg")); pMenuCalc->addAction(pNeutronProps); pMenuCalc->addSeparator(); QAction *pPowder = new QAction("Powder Lines...", this); pPowder->setIcon(load_icon("res/icons/weather-snow.svg")); pMenuCalc->addAction(pPowder); QAction *pDW = new QAction("Scattering Factors...", this); pMenuCalc->addAction(pDW); QAction *pFormfactor = nullptr; if(g_bHasFormfacts && g_bHasScatlens) { pFormfactor = new QAction("Form Factors...", this); pMenuCalc->addAction(pFormfactor); } QAction *pSgList = new QAction("Space Group Types...", this); pMenuCalc->addAction(pSgList); QAction *pDisp = new QAction("Dispersions...", this); //pDisp->setIcon(load_icon("disp.svg")); pMenuCalc->addAction(pDisp); pMenuCalc->addSeparator(); QAction *pDynPlane = new QAction("Kinematic Plane...", this); pMenuCalc->addAction(pDynPlane); QAction *pSpuri = new QAction("Spurious Scattering...", this); pMenuCalc->addAction(pSpuri); #if !defined NO_NET // -------------------------------------------------------------------------------- // network menu QMenu *pMenuNet = new QMenu("Network", this); QAction *pConn = new QAction("Connect to Instrument...", this); pConn->setIcon(load_icon("res/icons/network-transmit-receive.svg")); pMenuNet->addAction(pConn); QAction *pDisconn = new QAction("Disconnect", this); pDisconn->setIcon(load_icon("res/icons/network-offline.svg")); pMenuNet->addAction(pDisconn); pMenuNet->addSeparator(); QAction *pNetScanMon = new QAction("Scan Monitor...", this); pMenuNet->addAction(pNetScanMon); QAction *pNetCache = new QAction("Network Cache...", this); pMenuNet->addAction(pNetCache); QAction *pNetRefresh = new QAction("Refresh", this); pNetRefresh->setIcon(load_icon("res/icons/view-refresh.svg")); pMenuNet->addSeparator(); pMenuNet->addAction(pNetRefresh); #endif // -------------------------------------------------------------------------------- // tools menu QMenu *pMenuTools = new QMenu("Tools", this); QAction *pScanViewer = new QAction("Scan Viewer...", this); pMenuTools->addAction(pScanViewer); // -------------------------------------------------------------------------------- // help menu QMenu *pMenuHelp = new QMenu("Help", this); QAction *pHelp = new QAction("Show Help...", this); pHelp->setIcon(load_icon("res/icons/help-browser.svg")); pMenuHelp->addAction(pHelp); QAction *pDevelDoc = new QAction("Show Developer Help...", this); if(find_resource("doc/devel/html/index.html", 0) == "") pDevelDoc->setEnabled(0); pDevelDoc->setIcon(load_icon("res/icons/help-browser.svg")); pMenuHelp->addAction(pDevelDoc); pMenuHelp->addSeparator(); QAction *pAboutQt = new QAction("About Qt...", this); //pAboutQt->setIcon(QIcon::fromTheme("help-about")); pMenuHelp->addAction(pAboutQt); //pMenuHelp->addSeparator(); QAction *pAbout = new QAction("About Takin...", this); pAbout->setIcon(load_icon("res/icons/dialog-information.svg")); pMenuHelp->addAction(pAbout); // -------------------------------------------------------------------------------- QMenuBar *pMenuBar = new QMenuBar(this); pMenuBar->addMenu(pMenuFile); pMenuBar->addMenu(m_pMenuViewRecip); pMenuBar->addMenu(m_pMenuViewReal); pMenuBar->addMenu(pMenuReso); pMenuBar->addMenu(pMenuCalc); pMenuBar->addMenu(pMenuTools); #if !defined NO_NET pMenuBar->addMenu(pMenuNet); #endif pMenuBar->addMenu(pMenuHelp); QObject::connect(pNew, SIGNAL(triggered()), this, SLOT(New())); QObject::connect(pLoad, SIGNAL(triggered()), this, SLOT(Load())); QObject::connect(pSave, SIGNAL(triggered()), this, SLOT(Save())); QObject::connect(pSaveAs, SIGNAL(triggered()), this, SLOT(SaveAs())); QObject::connect(pImport, SIGNAL(triggered()), this, SLOT(Import())); QObject::connect(pScanViewer, SIGNAL(triggered()), this, SLOT(ShowScanViewer())); QObject::connect(pSettings, SIGNAL(triggered()), this, SLOT(ShowSettingsDlg())); QObject::connect(pExit, SIGNAL(triggered()), this, SLOT(close())); QObject::connect(m_pSmallq, SIGNAL(toggled(bool)), this, SLOT(EnableSmallq(bool))); QObject::connect(m_pBZ, SIGNAL(toggled(bool)), this, SLOT(EnableBZ(bool))); QObject::connect(m_pWS, SIGNAL(toggled(bool)), this, SLOT(EnableWS(bool))); for(QAction* pAct : {m_pEwaldSphereNone, m_pEwaldSphereKi, m_pEwaldSphereKf}) QObject::connect(pAct, SIGNAL(triggered()), this, SLOT(ShowEwaldSphere())); QObject::connect(m_pShowRealQDir, SIGNAL(toggled(bool)), this, SLOT(EnableRealQDir(bool))); QObject::connect(m_pSnapSmallq, SIGNAL(toggled(bool)), &m_sceneRecip, SLOT(setSnapq(bool))); QObject::connect(pKeepAbsKiKf, SIGNAL(toggled(bool)), &m_sceneRecip, SLOT(setKeepAbsKiKf(bool))); QObject::connect(pRecipParams, SIGNAL(triggered()), this, SLOT(ShowRecipParams())); QObject::connect(pRealParams, SIGNAL(triggered()), this, SLOT(ShowRealParams())); for(QAction *pProj : {m_pProjGnom, m_pProjStereo, m_pProjPara, m_pProjPersp}) QObject::connect(pProj, SIGNAL(triggered()), this, SLOT(RecipProjChanged())); #if !defined NO_3D QObject::connect(pView3D, SIGNAL(triggered()), this, SLOT(Show3D())); QObject::connect(pView3DReal, SIGNAL(triggered()), this, SLOT(Show3DReal())); QObject::connect(pResoEllipses3D, SIGNAL(triggered()), this, SLOT(ShowResoEllipses3D())); #endif QObject::connect(pRecipExport, SIGNAL(triggered()), this, SLOT(ExportRecip())); QObject::connect(pProjExport, SIGNAL(triggered()), this, SLOT(ExportProj())); QObject::connect(pRealExport, SIGNAL(triggered()), this, SLOT(ExportReal())); QObject::connect(pTofExport, SIGNAL(triggered()), this, SLOT(ExportTof())); QObject::connect(pRealLatticeExport, SIGNAL(triggered()), this, SLOT(ExportRealLattice())); QObject::connect(pExportUC, SIGNAL(triggered()), this, SLOT(ExportUCModel())); #ifdef USE_GIL QObject::connect(pBZExport, SIGNAL(triggered()), this, SLOT(ExportBZImage())); QObject::connect(pWSExport, SIGNAL(triggered()), this, SLOT(ExportWSImage())); #endif QObject::connect(pResoParams, SIGNAL(triggered()), this, SLOT(ShowResoParams())); QObject::connect(pResoEllipses, SIGNAL(triggered()), this, SLOT(ShowResoEllipses())); QObject::connect(pResoConv, SIGNAL(triggered()), this, SLOT(ShowResoConv())); QObject::connect(pNeutronProps, SIGNAL(triggered()), this, SLOT(ShowNeutronDlg())); QObject::connect(m_pGoto, SIGNAL(triggered()), this, SLOT(ShowGotoDlg())); QObject::connect(pPowder, SIGNAL(triggered()), this, SLOT(ShowPowderDlg())); QObject::connect(pDisp, SIGNAL(triggered()), this, SLOT(ShowDispDlg())); QObject::connect(pSpuri, SIGNAL(triggered()), this, SLOT(ShowSpurions())); QObject::connect(pDW, SIGNAL(triggered()), this, SLOT(ShowDWDlg())); QObject::connect(pDynPlane, SIGNAL(triggered()), this, SLOT(ShowDynPlaneDlg())); #if !defined NO_NET QObject::connect(pConn, SIGNAL(triggered()), this, SLOT(ShowConnectDlg())); QObject::connect(pDisconn, SIGNAL(triggered()), this, SLOT(Disconnect())); QObject::connect(pNetRefresh, SIGNAL(triggered()), this, SLOT(NetRefresh())); QObject::connect(pNetCache, SIGNAL(triggered()), this, SLOT(ShowNetCache())); QObject::connect(pNetScanMon, SIGNAL(triggered()), this, SLOT(ShowNetScanMonitor())); #endif QObject::connect(pSgList, SIGNAL(triggered()), this, SLOT(ShowSgListDlg())); if(pFormfactor) QObject::connect(pFormfactor, SIGNAL(triggered()), this, SLOT(ShowFormfactorDlg())); QObject::connect(pHelp, SIGNAL(triggered()), this, SLOT(ShowHelp())); QObject::connect(pDevelDoc, SIGNAL(triggered()), this, SLOT(ShowDevelDoc())); QObject::connect(pAbout, SIGNAL(triggered()), this, SLOT(ShowAbout())); QObject::connect(pAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); setMenuBar(pMenuBar); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // context menus if(m_pviewRecip) m_pviewRecip->setContextMenuPolicy(Qt::CustomContextMenu); if(m_pviewProjRecip) m_pviewProjRecip->setContextMenuPolicy(Qt::CustomContextMenu); if(m_pviewRealLattice) m_pviewRealLattice->setContextMenuPolicy(Qt::CustomContextMenu); if(m_pviewReal) m_pviewReal->setContextMenuPolicy(Qt::CustomContextMenu); if(m_pviewTof) m_pviewTof->setContextMenuPolicy(Qt::CustomContextMenu); if(m_pviewRecip) QObject::connect(m_pviewRecip, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(RecipContextMenu(const QPoint&))); if(m_pviewProjRecip) QObject::connect(m_pviewProjRecip, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(RecipContextMenu(const QPoint&))); if(m_pviewRealLattice) QObject::connect(m_pviewRealLattice, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(RealContextMenu(const QPoint&))); if(m_pviewReal) QObject::connect(m_pviewReal, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(RealContextMenu(const QPoint&))); if(m_pviewTof) QObject::connect(m_pviewTof, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(RealContextMenu(const QPoint&))); // -------------------------------------------------------------------------------- // tool bars QToolBar *pFileTools = new QToolBar(this); pFileTools->setWindowTitle("File"); pFileTools->addAction(pNew); pFileTools->addAction(pLoad); pFileTools->addAction(pImport); pFileTools->addAction(pSave); pFileTools->addAction(pSaveAs); addToolBar(pFileTools); QToolBar *pRecipTools = new QToolBar(this); pRecipTools->setWindowTitle("Reciprocal Space"); pRecipTools->addAction(m_pGoto); pRecipTools->addAction(m_pSmallq); pRecipTools->addAction(m_pBZ); //pRecipTools->addAction(m_pEwaldSphere); addToolBar(pRecipTools); QToolBar *pResoTools = new QToolBar(this); pResoTools->setWindowTitle("Resolution"); pResoTools->addAction(pResoParams); pResoTools->addAction(pResoEllipses); addToolBar(pResoTools); QToolBar *pCalcTools = new QToolBar(this); pCalcTools->setWindowTitle("Calculation"); pCalcTools->addAction(pNeutronProps); pCalcTools->addAction(pPowder); addToolBar(pCalcTools); #if !defined NO_NET QToolBar *pNetTools = new QToolBar(this); pNetTools->setWindowTitle("Network"); pNetTools->addAction(pConn); pNetTools->addAction(pDisconn); pNetTools->addAction(pNetRefresh); addToolBar(pNetTools); #endif // -------------------------------------------------------------------------------- RepopulateSpaceGroups(); unsigned int iMaxPeaks = m_settings.value("main/max_peaks", 10).toUInt(); m_sceneRecip.GetTriangle()->SetMaxPeaks(iMaxPeaks); m_sceneRecip.GetTriangle()->SetPlaneDistTolerance(s_dPlaneDistTolerance); m_sceneProjRecip.GetLattice()->SetMaxPeaks(iMaxPeaks/2); m_sceneRealLattice.GetLattice()->SetMaxPeaks(iMaxPeaks); m_sceneRealLattice.GetLattice()->SetPlaneDistTolerance(s_dPlaneDistTolerance); #if !defined NO_3D if(m_pRecip3d) { m_pRecip3d->SetMaxPeaks((t_real)iMaxPeaks); m_pRecip3d->SetPlaneDistTolerance(s_dPlaneDistTolerance); } #endif m_bReady = 1; UpdateDs(); CalcPeaks(); m_sceneRecip.GetTriangle()->SetqVisible(bSmallqVisible); m_sceneRecip.GetTriangle()->SetBZVisible(bBZVisible); m_sceneRecip.GetTriangle()->SetEwaldSphereVisible(EWALD_KF); m_sceneRealLattice.GetLattice()->SetWSVisible(bWSVisible); m_sceneRecip.emitUpdate(); //m_sceneRecip.emitAllParams(); setAcceptDrops(1); }
void QMenuProto::setTearOffEnabled(bool enabled) { QMenu *item = qscriptvalue_cast<QMenu*>(thisObject()); if (item) item->setTearOffEnabled(enabled); }
// Neue Widget-Klasse vom eigentlichen Widget ableiten MyWindow::MyWindow( QMainWindow *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) { editor = new QTextEdit; editor->setWhatsThis( "Dieser Text kann mit (Shift)+(F1) angezeigt werden." "Auch eine <b>HTML-Formatierung</b> ist möglich. "); // Das komplette Menü zum Hauptprogramm QMenu *fileMenu = new QMenu(tr("&Datei"), this); menuBar()->addMenu(fileMenu); act1 = fileMenu->addAction( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/page_white.png")), tr("&Neu"), this, SLOT(newFile()), QKeySequence(tr("Ctrl+N", "Datei|Neu")) ); act1->setStatusTip( tr("Löscht den aktuellen Inhalt der Datei")); act2 = fileMenu->addAction( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/folder_page_white.png")), tr("&Öffnen..."), this, SLOT(openFile() ), QKeySequence(tr("Ctrl+O", "Datei|Öffnen"))); act2->setStatusTip( tr("Öffnet eine Datei in den Texteditor")); fileMenu->addSeparator(); act3 = fileMenu->addAction( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/cancel.png")) , tr("Be&enden"), qApp, SLOT(quit()), QKeySequence(tr("Ctrl+E", "Datei|Beenden")) ); act3->setStatusTip(tr("Programm beenden")); QMenu *workMenu = new QMenu( tr("&Bearbeiten"), this); menuBar()->addMenu(workMenu); act4 = workMenu->addAction( tr("&Suchen"), this, SLOT(search()), QKeySequence(tr("Ctrl+S", "Bearbeiten|Suchen"))); act4->setStatusTip( tr("Nach einer Stringfolge suchen") ); // Menü mit Linie von der Leiste Abnehmbar fileMenu->setSeparatorsCollapsible(true); // Mehrere Aktionen erzeugen QAction* underLineAct = new QAction( tr("&Unterstreichen"), this ); underLineAct->setCheckable(true); underLineAct->setShortcut(tr("Ctrl+U")); underLineAct->setStatusTip( tr("Text unterstreichen") ); underLineAct->setIcon( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_underline.png"))); connect( underLineAct, SIGNAL(triggered(bool)), editor, SLOT(setFontUnderline(bool)) ); QAction *leftAlignAct = new QAction( tr("&Links ausgerichtet"), this); leftAlignAct->setCheckable(true); leftAlignAct->setShortcut(tr("Ctrl+L")); leftAlignAct->setStatusTip( tr("Text links ausrichten")); leftAlignAct->setIcon( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_left.png"))); connect( leftAlignAct, SIGNAL(triggered()), this, SLOT(leftAlignment() ) ); QAction *rightAlignAct = new QAction( tr("&Rechts ausgerichtet"), this); rightAlignAct->setCheckable(true); rightAlignAct->setShortcut(tr("Ctrl+R")); rightAlignAct->setStatusTip( tr("Text rechts ausrichten") ); rightAlignAct->setIcon( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_right.png"))); connect( rightAlignAct, SIGNAL(triggered()), this, SLOT(rightAlignment() ) ); QAction *justifyAct = new QAction( tr("&Bündig ausrichten"), this); justifyAct->setCheckable(true); justifyAct->setShortcut(tr("Ctrl+J")); justifyAct->setStatusTip( tr("Text bündig ausrichten")); justifyAct->setIcon( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_justify.png"))); connect( justifyAct, SIGNAL(triggered()), this, SLOT(justifyAlignment() ) ); QAction *centerAct = new QAction( tr("&Zentriert ausrichten"), this); centerAct->setCheckable(true); centerAct->setShortcut(tr("Ctrl+E")); centerAct->setStatusTip( tr("Text zentriert ausrichten") ); centerAct->setIcon( QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_center.png"))); connect( centerAct, SIGNAL(triggered()), this, SLOT(centerAlignment() ) ); // Einige Aktionen zu einer Gruppe zusammenfassen QActionGroup* alignmentGroup = new QActionGroup( this ); alignmentGroup->addAction(leftAlignAct); alignmentGroup->addAction(rightAlignAct); alignmentGroup->addAction(justifyAct); alignmentGroup->addAction(centerAct); leftAlignAct->setChecked(true); // Nochmals zwei weitere Aktionen QAction *InZoom = new QAction( tr("&Zoom in ..."), this ); InZoom->setStatusTip(tr("Zoom in the text")); connect( InZoom, SIGNAL(triggered()), editor, SLOT(zoomIn() ) ); QAction *OutZoom = new QAction( tr("&Zoom out ..."), this ); OutZoom->setStatusTip(tr("Zoom out the text")); connect( OutZoom, SIGNAL(triggered() ), editor, SLOT(zoomOut() ) ); // Ein Sub-Menü "Format" bei "Bearbeiten" einfügen QMenu *formatMenu = workMenu->addMenu( tr("&Format") ); formatMenu->addAction(underLineAct); formatMenu->addSeparator(); formatMenu->addAction(leftAlignAct); formatMenu->addAction(rightAlignAct); formatMenu->addAction(justifyAct); formatMenu->addAction(centerAct); formatMenu->addSeparator(); formatMenu->addAction(InZoom); formatMenu->addAction(OutZoom); workMenu->setTearOffEnabled(true); workMenu->setWindowTitle("Bearbeiten"); // Zur Demonstration eine Aktion mit QVariant Start = new QAction(tr("&Programmstart ..."), this); Start->setStatusTip(tr("Zeit des Programmstarts")); Start->setData(QVariant(QTime::currentTime())); QFont font; font.setBold(true); Start->setFont(font); Start->setShortcut(tr("Ctrl+T")); Start->setShortcutContext(Qt::ApplicationShortcut); connect( Start, SIGNAL( triggered() ), this, SLOT( printStart() ) ); workMenu->addAction(Start); // Eine neue Statusleiste erzeugen und zum // Hauptfenster hinzufügen (void*) statusBar (); // Permanente Meldung in der Statusleiste // Zeichen, Wörter, Zeilen sLabel = new QLabel; sLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); sLabel->setLineWidth(2); statusBar()->addPermanentWidget(sLabel); connect( editor, SIGNAL( textChanged() ), this, SLOT( updateStatusBar() ) ); updateStatusBar(); // Laufend aktuelle Uhrzeit in der Statusleiste time = new QLCDNumber; time->setFrameStyle(QFrame::Panel | QFrame::Sunken); time->setLineWidth(2); time->setSegmentStyle(QLCDNumber::Flat); statusBar()->addPermanentWidget(time); QTimer *timer = new QTimer(this); connect( timer, SIGNAL(timeout()), this, SLOT(updateTime()) ); // Jede Sekunde updateTime() aufrufen timer->start(1000); updateTime(); // Werkzeugleiste erzeugen toolFile = addToolBar(tr("Datei")); // Icons mit Text darunter anzeigen toolFile->setToolButtonStyle ( Qt::ToolButtonTextUnderIcon ); // Werkzeugleiste nur nach links // oder oben Verschiebbar toolFile->setAllowedAreas( Qt::LeftToolBarArea | Qt::TopToolBarArea ); // Aktionen zur Werkzeugleiste hinzufügen toolFile->addAction(act1); toolFile->addAction(act2); toolFile->addAction(act3); // Noch eine Werkzeugleiste toolWork = addToolBar(tr("Bearbeiten")); // Werkzeugleiste unten anzeigen addToolBar(Qt::TopToolBarArea, toolWork ); // Position nicht mehr veränderbar toolWork->setMovable(false); // Aktionen zur Werkzeugleiste hinzufügen toolWork->addAction(underLineAct); toolWork->addSeparator (); toolWork->addAction(leftAlignAct); toolWork->addAction(rightAlignAct); toolWork->addAction(justifyAct); toolWork->addAction(centerAct); toolWork->addSeparator (); // Eine Schrift-Combobox zur Werkzeugleiste QFontComboBox *cFont = new QFontComboBox; toolWork->addWidget(cFont); connect( cFont, SIGNAL( currentFontChanged(const QFont& )), editor, SLOT(setCurrentFont ( const QFont&) ) ); // Ein neues Dock-Widget-erzeugen QDockWidget *dock = new QDockWidget( tr("WYSIWYG-Editor"), this ); // nur in den rechten und linken Bereich erlauben dock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); // Widget für das Dock-Widget erzeugen dock_editor = new QTextEdit; // Editor als Widget im Dock-Fenster verwenden dock->setWidget(dock_editor); // auf der rechten Seite zum Hauptfenster hinzufügen addDockWidget(Qt::RightDockWidgetArea, dock); connect( editor, SIGNAL(textChanged() ), this, SLOT( showHTML() ) ); // Einstellungen des Programms speichern // Im Beispiel wird nur (ggf.) die zuletzt // geöffnete Datei und die Größe des Fensters settings = new QSettings( tr("J.Wolf"), tr("JWTexteditor") ); settings->beginGroup("HauptFenster"); QString fileName = settings->value("lastFile").toString(); QSize size = settings->value("size", sizeHint()).toSize(); if (!fileName.isEmpty()) { QFile file(fileName); if (file.open(QFile::ReadOnly | QFile::Text)) { editor->setPlainText(file.readAll()); statusBar()->showMessage( tr("Zuletzt geöffnete Datei " "erfolgreich geladen")); // Wieder setzen settings->setValue("lastFile", fileName ); } else // falls die Datei nicht mehr existiert settings->setValue("lastFile", ""); } else // Keine Datei gesetzt settings->setValue("lastFile", ""); settings->endGroup(); if( size.isNull() ) resize(640, 480); else resize(size); setCentralWidget(editor); setWindowTitle("QMainWindow - Demo"); }