bool CanvasPicker::eventFilter(QObject *object, QEvent *e) { QVector<int> images = plot()->imageMarkerKeys(); QVector<int> lines = plot()->lineMarkerKeys(); if (object != (QObject *)plot()->plotWidget()->canvas()) return false; switch(e->type()) { case QEvent::MouseButtonPress: { plot()->deselect(); emit selectPlot(); const QMouseEvent *me = (const QMouseEvent *)e; bool allAxisDisabled = true; for (int i=0; i < QwtPlot::axisCnt; i++){ if (plotWidget->axisEnabled(i)){ allAxisDisabled = false; break; } } int dist, point; plotWidget->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (me->button() == Qt::LeftButton && (plot()->drawLineActive())){ startLinePoint = me->pos(); return true; } if (me->button() == Qt::LeftButton && plot()->drawTextActive()){ drawTextMarker(me->pos()); return true; } if (!plot()->zoomOn() && selectMarker(me)){ if (me->button() == Qt::RightButton) emit showMarkerPopupMenu(); return true; } return !(me->modifiers() & Qt::ShiftModifier); } break; case QEvent::MouseButtonDblClick: { if (d_editing_marker) { return d_editing_marker->eventFilter(plotWidget->canvas(), e); } else if (plot()->selectedMarkerKey() >= 0) { if (lines.contains(plot()->selectedMarkerKey())){ emit viewLineDialog(); return true; } else if (images.contains(plot()->selectedMarkerKey())){ emit viewImageDialog(); return true; } } else if (plot()->isPiePlot()){ emit showPlotDialog(plot()->curveKey(0)); return true; } else { const QMouseEvent *me = (const QMouseEvent *)e; int dist, point; int curveKey = plotWidget->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (dist < 10) emit showPlotDialog(curveKey); else emit showPlotDialog(-1); return true; } } break; case QEvent::MouseMove: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->state() != Qt::LeftButton) return true; QPoint pos = me->pos(); DataCurve *c = plot()->selectedCurveLabels(); if (c){ c->moveLabels(pos); return true; } if (plot()->drawLineActive()) { drawLineMarker(pos, plot()->drawArrow()); return true; } return false; } break; case QEvent::MouseButtonRelease: { const QMouseEvent *me = (const QMouseEvent *)e; Graph *g = plot(); if (g->drawLineActive()) { ApplicationWindow *app = g->multiLayer()->applicationWindow(); if (!app) return true; ArrowMarker mrk; mrk.attach(g->plotWidget()); mrk.setStartPoint(startLinePoint); mrk.setEndPoint(QPoint(me->x(), me->y())); mrk.setColor(app->defaultArrowColor); mrk.setWidth(app->defaultArrowLineWidth); mrk.setStyle(app->defaultArrowLineStyle); mrk.setHeadLength(app->defaultArrowHeadLength); mrk.setHeadAngle(app->defaultArrowHeadAngle); mrk.fillArrowHead(app->defaultArrowHeadFill); mrk.drawEndArrow(g->drawArrow()); mrk.drawStartArrow(false); g->addArrow(&mrk); g->drawLine(false); mrk.detach(); plotWidget->replot(); return true; } /*if(plot()->zoomOn()) { //fix for colormap changing on releasing the mouse button after zooming Graph * gr=plot(); if(!gr) return NULL; Spectrogram * spectrogram=gr->getSpectrogram(); if(spectrogram) spectrogram->setupColorBarScaling(); }*/ return false; } break; case QEvent::KeyPress: { int key=((const QKeyEvent *)e)->key(); int selectedMarker = plot()->selectedMarkerKey(); if (lines.contains(selectedMarker) && (key==Qt::Key_Enter || key==Qt::Key_Return)) { emit viewLineDialog(); return true; } if (images.contains(selectedMarker) && (key==Qt::Key_Enter || key==Qt::Key_Return)) { emit viewImageDialog(); return true; } } break; default: break; } return QObject::eventFilter(object, e); }
KstApp::KstApp(QWidget *parent, const char* name) : KMainWindow(parent, name) { clearWFlags(WDestructiveClose); stopping = false; config = kapp->config(); initStatusBar(); initDocument(); initView(); /* create dialogs */ debugDialog = new KstDebugDialogI(this); plotDialog = new KstPlotDialogI(doc, this); dataManager = new KstDataManagerI(doc, this); filterListEditor = new FilterListEditor(this); viewScalarsDialog = new KstViewScalarsDialogI(this); viewVectorsDialog = new KstViewVectorsDialogI(this); changeFileDialog = new KstChangeFileDialogI(this); changeNptsDialog = new KstChangeNptsDialogI(this); quickCurvesDialog = new KstQuickCurvesDialogI(this); quickPSDDialog = new KstQuickPSDDialogI(this); graphFileDialog = new KstGraphFileDialogI(this); vectorSaveDialog = new VectorSaveDialog(this); connect(KstVectorDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstCurveDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstEqDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstHsDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstPsdDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstPluginDialogI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); connect(KstEventMonitorI::globalInstance(), SIGNAL(modified()), doc, SLOT(wasModified())); initActions(); readOptions(); _updateThread = new UpdateThread(doc); _updateThread->setUpdateTime(KstSettings::globalSettings()->plotUpdateTimer); _updateThread->start(); connect(doc, SIGNAL(newFrameMsg(int)), this, SLOT(slotUpdateFrameMsg(int))); connect(view, SIGNAL(newStatusMsg(const QString &)), this, SLOT(slotUpdateStatusMsg(const QString &))); connect(view, SIGNAL(newDataMsg(const QString &)), this, SLOT(slotUpdateDataMsg(const QString &))); /*** Plot Dialog signals */ connect(changeFileDialog, SIGNAL(docChanged()), this, SLOT(registerDocChange())); connect(changeNptsDialog, SIGNAL(docChanged()), this, SLOT(registerDocChange())); connect(quickCurvesDialog,SIGNAL(docChanged()), this, SLOT(registerDocChange())); connect(quickPSDDialog, SIGNAL(docChanged()), this, SLOT(registerDocChange())); connect(filterListEditor, SIGNAL(docChanged()), this, SLOT(registerDocChange())); connect(graphFileDialog, SIGNAL(graphFileReq(const QString &,int,int)), view, SLOT(printToGraphicsFile(const QString &,int,int))); /*** label dialog ***/ connect(view->labelDialog, SIGNAL(applied()), this, SLOT(registerDocChange())); /*** plot dialog ***/ connect(plotDialog, SIGNAL(docChanged()), this, SLOT(registerDocChange())); /*** ***/ connect(doc, SIGNAL(dataChanged()), this, SLOT(updateDialogs())); connect(dataManager, SIGNAL(editDataVector(const QString &)), KstVectorDialogI::globalInstance(), SLOT(show_I(const QString &))); connect(dataManager->OpenPlotDialog, SIGNAL(clicked()), this, SLOT(showPlotDialog())); setAutoSaveSettings("KST-KMainWindow", true); _dcopIface = new KstIfaceImpl(doc, this); view->forceUpdate(); connect(this, SIGNAL(settingsChanged()), this, SLOT(slotSettingsChanged())); QTimer::singleShot(0, this, SLOT(updateActions())); // Load any extensions ExtensionMgr *mgr = ExtensionMgr::self(); mgr->setWindow(this); KService::List sl = KServiceType::offers("Kst Extension"); for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) { KService::Ptr service = *it; QString name = service->property("Name").toString(); if (!mgr->enabled(name) && !service->property("X-Kst-Enabled").toBool()) { continue; } mgr->loadExtension(service); } }
bool CanvasPicker::eventFilter(QObject *object, QEvent *e) { if (object != (QObject *)plot()->canvas()) return false; Graph *g = plot(); QList<QwtPlotMarker *> lines = g->linesList(); switch(e->type()) { case QEvent::MouseButtonPress: { const QMouseEvent *me = (const QMouseEvent *)e; if (!(me->modifiers() & Qt::ShiftModifier)) g->deselect(); emit selectPlot(); bool allAxisDisabled = true; for (int i=0; i < QwtPlot::axisCnt; i++){ if (g->axisEnabled(i)){ allAxisDisabled = false; break; } } int dist, point; g->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (me->button() == Qt::LeftButton && (g->drawLineActive())){ startLinePoint = me->pos(); return true; } if (!g->zoomOn() && selectMarker(me)){ if (me->button() == Qt::RightButton) emit showMarkerPopupMenu(); return true; } return !(me->modifiers() & Qt::ShiftModifier); } break; case QEvent::MouseButtonDblClick: { if (d_editing_marker) { return d_editing_marker->eventFilter(g->canvas(), e); } else if (g->selectedMarker()) { if (lines.contains(g->selectedMarker())){ emit viewLineDialog(); return true; } } else if (g->isPiePlot()){ emit showPlotDialog(0); return true; } else { const QMouseEvent *me = (const QMouseEvent *)e; int dist, point; QwtPlotCurve *c = g->closestCurve(me->pos().x(), me->pos().y(), dist, point); if (c && dist < 10) emit showPlotDialog(g->curveIndex(c)); else emit showPlotDialog(-1); return true; } } break; case QEvent::MouseMove: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->state() != Qt::LeftButton) return true; QPoint pos = me->pos(); DataCurve *c = g->selectedCurveLabels(); if (c){ c->moveLabels(pos); return true; } if (plot()->drawLineActive()) { drawLineMarker(pos, g->drawArrow()); return true; } return false; } break; case QEvent::MouseButtonRelease: { const QMouseEvent *me = (const QMouseEvent *)e; if (g->drawLineActive()) { ApplicationWindow *app = g->multiLayer()->applicationWindow(); if (!app) return true; ArrowMarker mrk; mrk.attach(g); mrk.setStartPoint(startLinePoint); mrk.setEndPoint(QPoint(me->x(), me->y())); mrk.setColor(app->defaultArrowColor); mrk.setWidth(app->defaultArrowLineWidth); mrk.setStyle(app->defaultArrowLineStyle); mrk.setHeadLength(app->defaultArrowHeadLength); mrk.setHeadAngle(app->defaultArrowHeadAngle); mrk.fillArrowHead(app->defaultArrowHeadFill); mrk.drawEndArrow(g->drawArrow()); mrk.drawStartArrow(false); g->addArrow(&mrk); g->drawLine(false); mrk.detach(); g->replot(); return true; } return false; } break; case QEvent::KeyPress: { int key = ((const QKeyEvent *)e)->key(); QwtPlotMarker *selectedMarker = g->selectedMarker(); if (lines.contains(selectedMarker) && (key == Qt::Key_Enter || key == Qt::Key_Return)){ emit viewLineDialog(); return true; } } break; default: break; } return QObject::eventFilter(object, e); }
void KstApp::initActions() { fileNewWindow = new KAction(i18n("New &Window"), 0, 0, this, SLOT(slotFileNewWindow()), actionCollection(),"file_new_window"); fileOpenNew = KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection()); fileOpenNew->setWhatsThis(i18n("Open Kst plot file.")); fileSave = KStdAction::save( this, SLOT(slotFileSave()), actionCollection()); fileSave->setWhatsThis(i18n("Save to current Kst plot file.")); fileSaveAs = KStdAction::saveAs( this, SLOT(slotFileSaveAs()), actionCollection()); fileSaveAs->setWhatsThis(i18n("Save to new Kst plot file.")); fileClose = KStdAction::close( this, SLOT(slotFileClose()), actionCollection()); fileClose->setWhatsThis(i18n("Close Kst.")); fileQuit = KStdAction::quit( this, SLOT(slotFileClose()), actionCollection()); fileQuit->setWhatsThis(i18n("Quit Kst.")); fileKeyBindings = KStdAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection()); fileKeyBindings->setWhatsThis(i18n("Bring up a dialog box\n" "to configure shortcuts.")); filePreferences = KStdAction::preferences(this, SLOT(slotPreferences()), actionCollection()); filePreferences->setWhatsThis(i18n("Bring up a dialog box\n" "to configure Kst settings.")); fileCopy = KStdAction::copy(this, SLOT(slotCopy()), actionCollection()); fileCopy->setWhatsThis(i18n("Copy cursor position to the clipboard.")); /************/ filePrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection()); filePrint->setToolTip(i18n("Print")); filePrint->setWhatsThis(i18n("Print current display")); /************/ ToolBarAction = KStdAction::showToolbar(this, SLOT(slotViewToolBar()), actionCollection()); ToolBarAction->setWhatsThis(i18n("Toggle Toolbar")); connect(ToolBarAction, SIGNAL(activated()), this, SLOT(setSettingsDirty())); /************/ StatusBarAction = KStdAction::showStatusbar(this, SLOT(slotViewStatusBar()), actionCollection()); StatusBarAction->setWhatsThis(i18n("Toggle Statusbar")); connect(StatusBarAction, SIGNAL(activated()), this, SLOT(setSettingsDirty())); /************/ KStdAction::open(this, SLOT(slotFileOpen()), actionCollection()); /************/ recent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL &)), actionCollection()); recent->setWhatsThis(i18n("Open a recently used Kst plot.")); /************/ PauseAction = new KToggleAction(i18n("P&ause"),"player_pause",0, actionCollection(), "pause_action"); PauseAction->setToolTip(i18n("Pause")); PauseAction->setWhatsThis(i18n("When paused, new data will not be read.")); /************/ TiedZoomAction = new KAction(i18n("&Tied Zoom"),"kst_zoomtie",0, view, SLOT(toggleTiedZoom()), actionCollection(), "zoomtie_action"); TiedZoomAction->setToolTip(i18n("Toggle tied zoom")); TiedZoomAction->setWhatsThis(i18n("Apply zoom actions to all plots\n" "(not just the active one).")); /************/ XYZoomAction = new KRadioAction(i18n("XY Mouse &Zoom"), "kst_zoomxy",0, actionCollection(), "zoomxy_action"); XYZoomAction->setExclusiveGroup("zoom"); XYZoomAction->setToolTip(i18n("XY mouse zoom")); XYZoomAction->setWhatsThis(i18n("XY zoom: mouse zooming effects\n" "both X and Y axis")); XYZoomAction->setChecked(true); /************/ XZoomAction = new KRadioAction(i18n("&X Mouse Zoom"), "kst_zoomx",0, actionCollection(), "zoomx_action"); XZoomAction->setExclusiveGroup("zoom"); XZoomAction->setToolTip(i18n("X mouse zoom")); XZoomAction->setWhatsThis(i18n("X zoom: Mouse zooming effects only the\n" "X axis (CTRL-mouse also does this)")); /************/ YZoomAction = new KRadioAction(i18n("&Y Mouse Zoom"), "kst_zoomy",0, actionCollection(), "zoomy_action"); YZoomAction->setExclusiveGroup("zoom"); YZoomAction->setToolTip(i18n("Y mouse zoom")); YZoomAction->setWhatsThis(i18n("Y zoom: Mouse zooming effects only the\n" "Y axis (SHIFT-mouse also does this)")); /************/ TextAction = new KRadioAction(i18n("&Label Editor"), "text",0, actionCollection(), "label_action"); TextAction->setExclusiveGroup("zoom"); TextAction->setToolTip(i18n("Label Editor")); TextAction->setWhatsThis(i18n("Use the mouse to create and edit labels.")); /************/ FilterDialogAction = new KAction(i18n("Edit &Filters"), 0, 0, this, SLOT(showFilterListEditor()), actionCollection(), "filterdialog_action"); FilterDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit filters.")); /************/ PlotDialogAction = new KAction(i18n("Edit &Plots"), "kst_editplots", 0, this, SLOT(showPlotDialog()), actionCollection(), "plotdialog_action"); PlotDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit plot settings.")); /************/ DataManagerAction = new KAction(i18n("&Data Manager"), "kst_datamanager", 0, dataManager, SLOT(show_I()), actionCollection(), "datamanager_action"); DataManagerAction->setWhatsThis(i18n("Bring up a dialog box\n" "to manage data.")); /************/ VectorDialogAction = new KAction(i18n("Edit &Vectors"), 0, 0, KstVectorDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "vectordialog_action"); VectorDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit or create vectors.")); /************/ CurveDialogAction = new KAction(i18n("Edit &Curves"), 0, 0, KstCurveDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "curvedialog_action"); CurveDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit or create curves.")); /************/ EqDialogAction = new KAction(i18n("Edit &Equations"), 0, 0, KstEqDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "eqdialog_action"); EqDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit or create equations.")); /************/ HsDialogAction = new KAction(i18n("Edit &Histograms"), 0, 0, KstHsDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "hsdialog_action"); HsDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit or create histograms.")); /************/ PsdDialogAction = new KAction(i18n("Edit Power &Spectra"), 0, 0, KstPsdDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "psddialog_action"); PsdDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit or create power spectra.")); /************/ PluginDialogAction = new KAction(i18n("Edit &Plugins"), 0, 0, KstPluginDialogI::globalInstance(), SLOT(show_I()), actionCollection(), "plugindialog_action"); PluginDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to use plugins.")); /************/ ChangeFileDialogAction = new KAction(i18n("Change Data &File"), "kst_changefile", 0, this, SLOT(showChangeFileDialog()), actionCollection(), "changefiledialog_action"); ChangeFileDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to change input files.")); /************/ ViewScalarsDialogAction = new KAction(i18n("View &Scalars"), 0, 0, this, SLOT(showViewScalarsDialog()), actionCollection(), "viewscalarsdialog_action"); ViewScalarsDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to view scalar values.")); /************/ ViewVectorsDialogAction = new KAction(i18n("View Vec&tors"), 0, 0, this, SLOT(showViewVectorsDialog()), actionCollection(), "viewvectorsdialog_action"); ViewVectorsDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to view vector values.")); /************/ ChangeNptsDialogAction = new KAction(i18n("Change Data Sample &Ranges"), "kst_changenpts", 0, this, SLOT(showChangeNptsDialog()), actionCollection(), "changenptsdialog_action"); ChangeNptsDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to change data sample ranges.")); /************/ QuickCurvesDialogAction = new KAction(i18n("Quickly Create New Curve"), "kst_quickcurves", 0, this, SLOT(showQuickCurvesDialog()), actionCollection(), "quickcurvesdialog_action"); QuickCurvesDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to create a data curve\n" "and put it in a plot.")); /************/ QuickPSDDialogAction = new KAction(i18n("Quickly Create New PSD"), "kst_quickpsd", 0, this, SLOT(showQuickPSDDialog()), actionCollection(), "quickpsddialog_action"); QuickPSDDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to create a PSD\n" "and put it in a plot.")); /************/ EventMonitorAction = new KAction(i18n("Edit Event &Monitoring"), 0, 0, KstEventMonitorI::globalInstance(), SLOT(show_I()), actionCollection(), "eventmonitor_action"); EventMonitorAction->setWhatsThis(i18n("Bring up a dialog box\n" "to edit event monitoring.")); /************/ GraphFileDialogAction = new KAction(i18n("Export to Graphics File..."), "kst_graphfile", 0, this, SLOT(showGraphFileDialog()), actionCollection(), "graphfiledialog_action"); GraphFileDialogAction->setWhatsThis(i18n("Bring up a dialog box\n" "to export the plot as a\n" "graphics file.")); /************/ _vectorSaveAction = new KAction(i18n("Save Vectors to Disk..."), 0, 0, vectorSaveDialog, SLOT(show()), actionCollection(), "vectorsavedialog_action"); _vectorSaveAction->setWhatsThis(i18n("Bring up a dialog box\n" "to save vectors to text files.")); /************/ SamplesDownAction = new KAction(i18n("&Back 1 Screen"), "kst_back", KAccel::stringToKey("Ctrl+Left"), this, SLOT(samplesDown()), actionCollection(), "samplesdown_action"); //SamplesDownAction->setToolTip(i18n("Back")); SamplesDownAction->setWhatsThis(i18n("Reduce the starting frame by\n" "the current number of frames.")); /************/ SamplesUpAction = new KAction(i18n("&Advance 1 Screen"), "kst_advance", KAccel::stringToKey("Ctrl+Right"), this, SLOT(samplesUp()), actionCollection(), "samplesup_action"); //SamplesUpAction->setToolTip(i18n("Advance")); SamplesUpAction->setWhatsThis(i18n("Increase the starting frame by\n" "the current number of frames.")); /************/ SamplesFromEndAction = new KAction(i18n("Read From &End"), "1rightarrow", KAccel::stringToKey("Shift+Ctrl+Right"), this, SLOT(samplesEnd()), actionCollection(), "samplesend_action"); SamplesFromEndAction->setToolTip(i18n("Read from end")); SamplesFromEndAction->setWhatsThis(i18n("Read current data from end of file.")); /************/ PluginManagerAction = new KAction(i18n("&Plugins..."), 0, 0, this, SLOT(showPluginManager()), actionCollection(), "pluginmanager_action"); PluginManagerAction->setWhatsThis(i18n("Bring up a dialog box\n" "to manage plugins.")); /************/ ExtensionManagerAction = new KAction(i18n("&Extensions..."), 0, 0, this, SLOT(showExtensionManager()), actionCollection(), "extensionmanager_action"); ExtensionManagerAction->setWhatsThis(i18n("Bring up a dialog box\n" "to manage extensions.")); /************/ DataWizardAction = new KAction(i18n("Data &Wizard..."), "kst_datawizard", 0, this, SLOT(showDataWizard()), actionCollection(), "datawizard_action"); DataWizardAction->setWhatsThis(i18n("Bring up a wizard\n" "to easily load data.")); /************/ DebugDialogAction = new KAction(i18n("Debug Kst..."), 0, 0, this, SLOT(showDebugDialog()), actionCollection(), "debug_action"); DebugDialogAction->setWhatsThis(i18n("Bring up a dialog\n" "to display debugging information.")); /************/ DataMode = new KToggleAction(i18n("Data Mode"), "kst_datamode", 0, this, SLOT(toggleDataMode()), actionCollection(), "datamode_action"); DataMode->setWhatsThis(i18n("Toggle between cursor mode and data mode.")); /************/ _reloadAction = new KAction(i18n("Reload"), "reload", Key_F5, this, SLOT(reload()), actionCollection(), "reload"); _reloadAction->setWhatsThis(i18n("Reload the data from file.")); createGUI(); }