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

Method keyPressEvent

src/frontend/worksheet/WorksheetView.cpp:1027–1098  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1025}
1026
1027void WorksheetView::keyPressEvent(QKeyEvent* event) {
1028 // handle delete
1029 if (event->matches(QKeySequence::Delete)) {
1030 deleteElement();
1031 QGraphicsView::keyPressEvent(event);
1032 return;
1033 }
1034
1035 // handle copy/paste/duplicate
1036
1037 // determine the currently selected aspect
1038 AbstractAspect* aspect = nullptr;
1039 if (m_selectedItems.count() == 1) {
1040 // at the moment we allow to copy/paste/duplicate one single selcted object only
1041 const auto children = m_worksheet->children<WorksheetElement>(AbstractAspect::ChildIndexFlag::Recursive);
1042 const auto* item = m_selectedItems.constFirst();
1043 for (auto* child : children) {
1044 if (child->graphicsItem() == item) {
1045 aspect = child;
1046 break;
1047 }
1048 }
1049 } else
1050 aspect = m_worksheet;
1051
1052 if (!aspect) {
1053 QGraphicsView::keyPressEvent(event);
1054 return;
1055 }
1056
1057 if (event->matches(QKeySequence::Copy)) {
1058 exportToClipboard(); // export the image to the clipboard
1059 if (aspect != m_worksheet)
1060 aspect->copy(); // copy the selected object itself
1061 } else if (event->matches(QKeySequence::Paste)) {
1062 // paste
1063 QString name;
1064 auto t = AbstractAspect::clipboardAspectType(name);
1065 if (t != AspectType::AbstractAspect && aspect->pasteTypes().indexOf(t) != -1)
1066 aspect->paste();
1067 } else if ((event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_D) && aspect != m_worksheet) {
1068 // duplicate
1069 aspect->copy();
1070 aspect->parentAspect()->paste(true);
1071
1072 /* zooming related key events, handle them here so we can also use them in PresenterWidget without registering shortcuts */
1073 } else if ((event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_Plus)) {
1074 changeZoom(zoomInViewAction);
1075 } else if ((event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_Minus)) {
1076 changeZoom(zoomOutViewAction);
1077 } else if ((event->modifiers() & Qt::ControlModifier) && (event->key() == Qt::Key_1)) {
1078 changeZoom(zoomOriginAction);
1079 } else if (event->key() == 32) {
1080 // space key - hide/show the current object
1081 auto* we = dynamic_cast<WorksheetElement*>(aspect);
1082 if (we)
1083 we->setVisible(!we->isVisible());
1084 } else if (aspect->type() == AspectType::CartesianPlot && m_worksheet->layout() != Worksheet::Layout::NoLayout) {

Callers

nothing calls this directly

Calls 10

pasteMethod · 0.80
parentAspectMethod · 0.80
countMethod · 0.45
graphicsItemMethod · 0.45
copyMethod · 0.45
indexOfMethod · 0.45
pasteTypesMethod · 0.45
setVisibleMethod · 0.45
isVisibleMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected