Qt: add copy context menu entry to log viewer

This commit is contained in:
Megamouse 2023-02-06 20:01:58 +01:00
parent 8652b7d358
commit 1662bcfae4

View File

@ -7,6 +7,7 @@
#include <QActionGroup> #include <QActionGroup>
#include <QApplication> #include <QApplication>
#include <QClipboard>
#include <QMenu> #include <QMenu>
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
@ -61,6 +62,7 @@ void log_viewer::show_context_menu(const QPoint& pos)
{ {
QMenu menu; QMenu menu;
QAction* clear = new QAction(tr("&Clear")); QAction* clear = new QAction(tr("&Clear"));
QAction* copy = new QAction(tr("&Copy"));
QAction* open = new QAction(tr("&Open log file")); QAction* open = new QAction(tr("&Open log file"));
QAction* save = new QAction(tr("&Save filtered log")); QAction* save = new QAction(tr("&Save filtered log"));
QAction* filter = new QAction(tr("&Filter log")); QAction* filter = new QAction(tr("&Filter log"));
@ -110,6 +112,8 @@ void log_viewer::show_context_menu(const QPoint& pos)
init_action(notice_act, logs::level::notice); init_action(notice_act, logs::level::notice);
init_action(trace_act, logs::level::trace); init_action(trace_act, logs::level::trace);
menu.addAction(copy);
menu.addSeparator();
menu.addAction(open); menu.addAction(open);
menu.addSeparator(); menu.addSeparator();
menu.addAction(save); menu.addAction(save);
@ -128,6 +132,11 @@ void log_viewer::show_context_menu(const QPoint& pos)
menu.addSeparator(); menu.addSeparator();
menu.addAction(clear); menu.addAction(clear);
connect(copy, &QAction::triggered, this, [this]()
{
m_log_text->copy();
});
connect(clear, &QAction::triggered, this, [this]() connect(clear, &QAction::triggered, this, [this]()
{ {
m_log_text->clear(); m_log_text->clear();