/*! Works out whether the entry should be deleted, saved, or whether no action should be taken. \return enum Action */ CalenEditorPrivate::Action CalenEditorDataHandler::shouldSaveOrDeleteOrDoNothing(bool launchCalendar) const { OstTraceFunctionEntry0( CALENEDITORDATAHANDLER_SHOULDSAVEORDELETEORDONOTHING_ENTRY ); // Need to save the entry if third party calls editor to launch the // calendar after that. So, that entry will be new entry adn we assume // that client launches editor with some prefilled text items if (!isEdited() && !launchCalendar) { // Not edited at all OR // Only added space characters to text fields but not // edited the non-text items // no need to save the entry OstTraceFunctionExit0( CALENEDITORDATAHANDLER_SHOULDSAVEORDELETEORDONOTHING_EXIT ); return CalenEditorPrivate::ActionNothing; } // new entry is edited if (mCalenEditor->isNewEntry()) { // Subject && Location && Description are text items. // If text items as a whole is not empty, we can save the note // If text items as a whole is empty, we can still save the note // since we edited "non-text" fields if (!nonTextItemsEdited() && areTextItemsEmpty()) { OstTraceFunctionExit0( DUP1_CALENEDITORDATAHANDLER_SHOULDSAVEORDELETEORDONOTHING_EXIT ); return CalenEditorPrivate::ActionNothing; } else { OstTraceFunctionExit0( DUP2_CALENEDITORDATAHANDLER_SHOULDSAVEORDELETEORDONOTHING_EXIT ); return CalenEditorPrivate::ActionSave; } } // Save the note, since the text fields contain something OstTraceFunctionExit0( DUP4_CALENEDITORDATAHANDLER_SHOULDSAVEORDELETEORDONOTHING_EXIT ); return CalenEditorPrivate::ActionSave; }
void MenuBar::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("application/x-qobject") && isEdited()) event->acceptProposedAction(); m_dragPos = QPoint(-1,-1); }
void MenuBar::dropEvent(QDropEvent *event) { const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData()); QAction *aAction = qobject_cast<QAction *>(mimeData->object()); if (aAction && isEdited()) { if (activeAction()) if (activeAction()->menu()) activeAction()->menu()->close(); if (aAction->menu()) if (aAction->objectName() == "actionNewMenu") { Menu *menu = new Menu(aAction->text()); menu->setEdited(true); aAction = menu->menuAction(); } QAction *eAction = this->actionAt(event->pos()); QRect rect = actionGeometry(eAction); eAction = this->actionAt(QPoint(event->pos().x()+rect.width()/2, event->pos().y())); if (eAction) { if (aAction->isSeparator()) insertSeparator(eAction); else insertAction(eAction,aAction); } else { if (aAction->isSeparator()) addSeparator(); else addAction(aAction); } event->acceptProposedAction(); } }
void MenuBar::dragMoveEvent(QDragMoveEvent *event) { const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData()); QAction *eAction = this->actionAt(event->pos()); if (mimeData->hasFormat("application/x-qobject") && isEdited()) if (mimeData->object() != eAction && eAction) if (eAction->menu() && activeAction()!= eAction) setActiveAction(eAction); event->accept(); }
bool ToolBar::eventFilter(QObject *object, QEvent *event) { Q_UNUSED(object) QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); if (event->type() == QEvent::MouseMove) this->mouseMoveEvent(mouseEvent); if (event->type() == QEvent::MouseButtonPress && isEdited()) { if (mouseEvent->button() == Qt::LeftButton) m_dragPos = mapFromGlobal(mouseEvent->globalPos()); } return false; }
void ToolBar::contextMenuEvent(QContextMenuEvent *event) { if (this->actionAt(event->pos())!=NULL && isEdited()) { // Создание контекстного меню QMenu *contextMenu = new QMenu(); QAction *action = new QAction(tr("Удалить"),this); connect(action, &QAction::triggered, this, &ToolBar::removeContextAction); contextMenu->addAction(action); contextMenu->addSeparator(); action = new QAction(tr("Свойства..."),this); connect(action, &QAction::triggered, this, &ToolBar::showActionProp); contextMenu->addAction(action); m_contextAction = this->actionAt(event->pos()); contextMenu->exec(event->globalPos()); delete contextMenu; } else QToolBar::contextMenuEvent(event); }
void ToolBar::dragMoveEvent(QDragMoveEvent *event) { const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData()); QAction *eAction = this->actionAt(event->pos()); if (mimeData->hasFormat("application/x-qobject") && isEdited()) if (mimeData->object() != eAction && eAction) if (eAction->menu() && !eAction->menu()->isVisible()) { if (m_activeAction) m_activeAction->menu()->close(); QToolButton *toolButton = qobject_cast<QToolButton *>(widgetForAction(eAction)); QPoint point = QPoint(toolButton->x(), toolButton->y()+toolButton->height()); eAction->menu()->popup(mapToGlobal(point)); m_activeAction = eAction; } event->accept(); }
void ToolBar::mouseMoveEvent(QMouseEvent *event) { QToolBar::mouseMoveEvent(event); QAction *action = this->actionAt(m_dragPos); if (event->buttons() & Qt::LeftButton && action && isEdited()) { qint32 distance = (event->pos() - m_dragPos).manhattanLength(); if (distance > QApplication::startDragDistance() ) { QDrag *drag = new QDrag(this); MimeDataObject *mimeData = new MimeDataObject(); mimeData->setObject(action); drag->setMimeData(mimeData); if (drag->exec(Qt::MoveAction) == Qt::MoveAction) if (drag->target() != this || action->isSeparator()) this->removeAction(action); return; } } }