| 234 | } |
| 235 | |
| 236 | QMenu* WorksheetElement::createContextMenu() { |
| 237 | if (!m_drawingOrderMenu) { |
| 238 | m_drawingOrderMenu = new QMenu(i18n("Drawing &order")); |
| 239 | m_drawingOrderMenu->setIcon(QIcon::fromTheme(QStringLiteral("layer-bottom"))); |
| 240 | |
| 241 | m_moveBehindMenu = new QMenu(i18n("Move &behind")); |
| 242 | m_moveBehindMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-down"))); |
| 243 | m_drawingOrderMenu->addMenu(m_moveBehindMenu); |
| 244 | |
| 245 | m_moveInFrontOfMenu = new QMenu(i18n("Move in &front of")); |
| 246 | m_moveInFrontOfMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-up"))); |
| 247 | m_drawingOrderMenu->addMenu(m_moveInFrontOfMenu); |
| 248 | |
| 249 | connect(m_drawingOrderMenu, &QMenu::aboutToShow, this, &WorksheetElement::prepareDrawingOrderMenu); |
| 250 | connect(m_moveBehindMenu, &QMenu::triggered, this, &WorksheetElement::execMoveBehind); |
| 251 | connect(m_moveInFrontOfMenu, &QMenu::triggered, this, &WorksheetElement::execMoveInFrontOf); |
| 252 | } |
| 253 | |
| 254 | QMenu* menu = AbstractAspect::createContextMenu(); |
| 255 | QAction* firstAction = menu->actions().at(1); // skip the first action because of the "title-action" |
| 256 | |
| 257 | auto* visibilityAction = this->visibilityAction(); |
| 258 | visibilityAction->setChecked(isVisible()); |
| 259 | menu->insertAction(firstAction, visibilityAction); |
| 260 | menu->insertSeparator(firstAction); |
| 261 | |
| 262 | // don't add the lock action for elements which cannot be freely moved on the worksheet (like axis and curves/plots) |
| 263 | if (!dynamic_cast<Axis*>(this) && !dynamic_cast<Plot*>(this)) { |
| 264 | auto* lockingAction = this->lockingAction(); |
| 265 | lockingAction->setChecked(isLocked()); |
| 266 | menu->insertAction(firstAction, lockingAction); |
| 267 | menu->insertSeparator(firstAction); |
| 268 | } |
| 269 | |
| 270 | // add the sub-menu for the drawing order |
| 271 | // don't add the drawing order menu for axes and legends, they're always drawn on top of each other elements |
| 272 | if (type() == AspectType::Axis || type() == AspectType::CartesianPlotLegend) |
| 273 | return menu; |
| 274 | |
| 275 | // for plots in a worksheet with an active layout the Z-factor is not relevant but we still |
| 276 | // want to use the "Drawing order" menu to be able to change the position/order of the plot in the layout. |
| 277 | // Since the order of the child in the list of children is opposite to the Z-factor, we change |
| 278 | // the names of the menus to adapt to the reversed logic. |
| 279 | if (dynamic_cast<AbstractPlot*>(this)) { |
| 280 | const auto* w = dynamic_cast<const Worksheet*>(this->parentAspect()); |
| 281 | if (!w) |
| 282 | return menu; |
| 283 | |
| 284 | if (w->layout() != Worksheet::Layout::NoLayout) { |
| 285 | m_moveBehindMenu->setTitle(i18n("Move in &front of")); |
| 286 | m_moveBehindMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-up"))); |
| 287 | m_moveInFrontOfMenu->setTitle(i18n("Move &behind")); |
| 288 | m_moveInFrontOfMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-down"))); |
| 289 | } else { |
| 290 | m_moveBehindMenu->setTitle(i18n("Move &behind")); |
| 291 | m_moveBehindMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-down"))); |
| 292 | m_moveInFrontOfMenu->setTitle(i18n("Move in &front of")); |
| 293 | m_moveInFrontOfMenu->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow-up"))); |
no test coverage detected