MCPcopy Create free account
hub / github.com/KDE/labplot / keyPressEvent

Method keyPressEvent

src/backend/worksheet/plots/cartesian/CartesianPlot.cpp:4377–4431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4375}
4376
4377void CartesianPlotPrivate::keyPressEvent(QKeyEvent* event) {
4378 const auto key = event->key();
4379 // const bool ctrl = event->modifiers() & Qt::KeyboardModifier::ControlModifier;
4380 // const bool shift = event->modifiers() & Qt::KeyboardModifier::ShiftModifier;
4381 // const bool alt = event->modifiers() & Qt::KeyboardModifier::AltModifier;
4382 Action a = evaluateKeys(key, event->modifiers());
4383
4384 if (a == Action::Abort) {
4385 m_selectionBandIsShown = false;
4386 } else if (a & Action::Move) {
4387 const auto* worksheet = static_cast<const Worksheet*>(q->parentAspect());
4388 if (worksheet->layout() == Worksheet::Layout::NoLayout) {
4389 // no layout is active -> use arrow keys to move the plot on the worksheet
4390 const int delta = 5;
4391 QRectF rect = q->rect();
4392
4393 if (a == Action::MoveLeft) {
4394 rect.setX(rect.x() - delta);
4395 rect.setWidth(rect.width() - delta);
4396 } else if (a == Action::MoveRight) {
4397 rect.setX(rect.x() + delta);
4398 rect.setWidth(rect.width() + delta);
4399 } else if (a == Action::MoveUp) {
4400 rect.setY(rect.y() - delta);
4401 rect.setHeight(rect.height() - delta);
4402 } else if (a == Action::MoveDown) {
4403 rect.setY(rect.y() + delta);
4404 rect.setHeight(rect.height() + delta);
4405 }
4406
4407 q->setRect(rect);
4408 }
4409 } else if (a == Action::NavigateNextCurve) // (key == Qt::Key_Tab)
4410 navigateNextPrevCurve();
4411 else if (a == Action::NavigatePrevCurve) // (key == Qt::SHIFT + Qt::Key_Tab)
4412 navigateNextPrevCurve(false /*next*/);
4413 else if (a & Action::New) {
4414 const auto* cSystem{defaultCoordinateSystem()};
4415 if (cSystem->isValid()) {
4416 logicalPos = cSystem->mapSceneToLogical(scenePos, AbstractCoordinateSystem::MappingFlag::Limit);
4417 calledFromContextMenu = true;
4418 }
4419 if (a == Action::NewTextLabel)
4420 q->addTextLabel();
4421 else if (a == Action::NewReferenceLine)
4422 q->addReferenceLine();
4423 else if (a == Action::NewReferenceRange)
4424 q->addReferenceRange();
4425 else if (a == Action::NewCustomPoint)
4426 q->addCustomPoint();
4427 else if (a == Action::NewImage)
4428 q->addImage();
4429 }
4430 QGraphicsItem::keyPressEvent(event);
4431}
4432
4433void CartesianPlotPrivate::navigateNextPrevCurve(bool next) const {
4434 const auto& curves = q->children<XYCurve>();

Callers

nothing calls this directly

Calls 15

evaluateKeysFunction · 0.85
parentAspectMethod · 0.80
rectMethod · 0.80
setXMethod · 0.80
xMethod · 0.80
setYMethod · 0.80
setHeightMethod · 0.80
heightMethod · 0.80
addTextLabelMethod · 0.80
addReferenceLineMethod · 0.80
addReferenceRangeMethod · 0.80
addCustomPointMethod · 0.80

Tested by

no test coverage detected