From f54f32b7758bdac60f6a8c92d81a9e6817d0a2a3 Mon Sep 17 00:00:00 2001 From: Petr Semiletov Date: Tue, 8 Nov 2022 19:03:28 +0300 Subject: [PATCH] --- document.cpp | 30 +++++++++++++++++++++++++++++- document.h | 12 ++++++++---- tea.cpp | 1 - 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/document.cpp b/document.cpp index d5b09db..1fe0113 100644 --- a/document.cpp +++ b/document.cpp @@ -1210,6 +1210,34 @@ void CDocument::wheelEvent (QWheelEvent *e) } +void CDocument::contextMenuEvent (QContextMenuEvent *event) +{ + QMenu *menu = new QMenu (this); + + QAction *a = menu->addAction (tr("Copy")); + connect (a, SIGNAL(triggered()), this, SLOT(ed_copy())); + + a = menu->addAction (tr("Cut")); + connect (a, SIGNAL(triggered()), this, SLOT(ed_cut())); + + a = menu->addAction (tr("Paste")); + connect (a, SIGNAL(triggered()), this, SLOT(ed_paste())); + + menu->addSeparator(); + + a = menu->addAction (tr("Undo")); + connect (a, SIGNAL(triggered()), this, SLOT(undo())); + + a = menu->addAction (tr("Redo")); + connect (a, SIGNAL(triggered()), this, SLOT(redo())); + +// menu->show(); + + menu->exec(event->globalPos()); + delete menu; +} + + CDocument::CDocument (CDox *hldr, QWidget *parent): QPlainTextEdit (parent) { holder = hldr; @@ -1274,7 +1302,7 @@ CDocument::CDocument (CDox *hldr, QWidget *parent): QPlainTextEdit (parent) //actCopy = new QAction (tr("Copy"), this); //connect (actCopy, SIGNAL(triggered()), this, SLOT(ed_copy())); - setContextMenuPolicy (Qt::PreventContextMenu); +// setContextMenuPolicy (Qt::PreventContextMenu); /* set dots color, put to hl init diff --git a/document.h b/document.h index e65f6db..eac619b 100644 --- a/document.h +++ b/document.h @@ -161,6 +161,9 @@ class CDocument: public QPlainTextEdit void keyPressEvent (QKeyEvent *event); void resizeEvent (QResizeEvent *event); void wheelEvent (QWheelEvent *e); + void contextMenuEvent (QContextMenuEvent *event); + + //QMenu* createStandardContextMenu(); public: @@ -211,10 +214,6 @@ class CDocument: public QPlainTextEdit QString get() const; //return selected text void put (const QString &value); //replace selection or insert text at cursor - bool ed_copy(); - bool ed_cut(); - void ed_paste(); - bool has_selection(); @@ -277,6 +276,11 @@ public slots: void cb_cursorPositionChanged(); void updateLineNumberArea (const QRect &, int); void slot_selectionChanged(); + + bool ed_copy(); + bool ed_cut(); + void ed_paste(); + }; diff --git a/tea.cpp b/tea.cpp index 1691b58..2abfc68 100644 --- a/tea.cpp +++ b/tea.cpp @@ -473,7 +473,6 @@ void CTEA::dropEvent (QDropEvent *event) event->accept(); } - /* =========================== Main window slots