void ItemEditorWidget::initMenuItems() { Q_ASSERT(m_editor); foreach (QAction *action, m_toolBar->actions()) delete action; QAction *act; act = new QAction( iconSave(), tr("Save"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Save Item (<strong>F2</strong>)") ); act->setShortcut( QKeySequence(tr("F2", "Shortcut to save item editor changes")) ); connect( act, SIGNAL(triggered()), this, SLOT(saveAndExit()) ); act = new QAction( iconCancel(), tr("Cancel"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Cancel Editing and Revert Changes") ); act->setShortcut( QKeySequence(tr("Escape", "Shortcut to revert item editor changes")) ); connect( act, SIGNAL(triggered()), this, SIGNAL(cancel()) ); QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit*>(m_editor); if (plainTextEdit != NULL) { plainTextEdit->setFrameShape(QFrame::NoFrame); act = new QAction( iconUndo(), tr("Undo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Undo); act->setEnabled(false); connect( act, SIGNAL(triggered()), plainTextEdit, SLOT(undo()) ); connect( plainTextEdit, SIGNAL(undoAvailable(bool)), act, SLOT(setEnabled(bool)) ); act = new QAction( iconRedo(), tr("Redo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Redo); act->setEnabled(false); connect( act, SIGNAL(triggered()), plainTextEdit, SLOT(redo()) ); connect( plainTextEdit, SIGNAL(redoAvailable(bool)), act, SLOT(setEnabled(bool)) ); } }
void ItemEditorWidget::initMenuItems() { Q_ASSERT(m_editor); auto frame = qobject_cast<QFrame*>(m_editor); if (frame) frame->setFrameShape(QFrame::NoFrame); for (auto action : m_toolBar->actions()) delete action; QAction *act; act = new QAction( iconSave(), tr("Save"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Save Item (<strong>F2</strong>)") ); act->setShortcut( QKeySequence(tr("F2", "Shortcut to save item editor changes")) ); connect( act, &QAction::triggered, this, &ItemEditorWidget::saveAndExit ); act = new QAction( iconCancel(), tr("Cancel"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Cancel Editing and Revert Changes") ); act->setShortcut( QKeySequence(tr("Escape", "Shortcut to revert item editor changes")) ); connect( act, &QAction::triggered, this, &ItemEditorWidget::cancel ); auto doc = document(); if (document()) { m_toolBar->addSeparator(); act = new QAction( iconUndo(), tr("Undo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Undo); act->setEnabled(false); connect( act, &QAction::triggered, doc, static_cast<void (QTextDocument::*)()>(&QTextDocument::undo) ); connect( doc, &QTextDocument::undoAvailable, act, &QAction::setEnabled ); act = new QAction( iconRedo(), tr("Redo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Redo); act->setEnabled(false); connect( act, &QAction::triggered, doc, static_cast<void (QTextDocument::*)()>(&QTextDocument::redo) ); connect( doc, &QTextDocument::redoAvailable, act, &QAction::setEnabled ); m_toolBar->addSeparator(); act = new QAction( iconFont(), tr("Font"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setFont ); act = new QAction( iconBold(), tr("Bold"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Bold ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleBoldText ); act = new QAction( iconItalic(), tr("Italic"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Italic ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleItalicText ); act = new QAction( iconUnderline(), tr("Underline"), m_editor ); m_toolBar->addAction(act); act->setShortcut( QKeySequence::Underline ); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleUnderlineText ); act = new QAction( iconStrikethrough(), tr("Strikethrough"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::toggleStrikethroughText ); m_toolBar->addSeparator(); act = new QAction( iconForeground(), tr("Foreground"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setForeground ); act = new QAction( iconBackground(), tr("Background"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::setBackground ); m_toolBar->addSeparator(); act = new QAction( iconEraseStyle(), tr("Erase Style"), m_editor ); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::eraseStyle ); m_toolBar->addSeparator(); act = new QAction( iconSearch(), tr("Search"), m_editor ); act->setShortcuts(QKeySequence::Find); m_toolBar->addAction(act); connect( act, &QAction::triggered, this, &ItemEditorWidget::searchRequest ); } }