Qt: add "clear" option to tty log contextmenu

This commit is contained in:
Unknown 2017-10-19 14:06:17 +02:00 committed by Ani
parent b3efa75206
commit 34a6085cc0
2 changed files with 12 additions and 0 deletions

View File

@ -112,6 +112,7 @@ log_frame::log_frame(std::shared_ptr<gui_settings> guiSettings, QWidget *parent)
m_tty = new QTextEdit(tabWidget); m_tty = new QTextEdit(tabWidget);
m_tty->setObjectName("tty_frame"); m_tty->setObjectName("tty_frame");
m_tty->setReadOnly(true); m_tty->setReadOnly(true);
m_tty->setContextMenuPolicy(Qt::CustomContextMenu);
tabWidget->addTab(m_log, tr("Log")); tabWidget->addTab(m_log, tr("Log"));
tabWidget->addTab(m_tty, tr("TTY")); tabWidget->addTab(m_tty, tr("TTY"));
@ -199,6 +200,9 @@ void log_frame::CreateAndConnectActions()
m_clearAct = new QAction(tr("Clear"), this); m_clearAct = new QAction(tr("Clear"), this);
connect(m_clearAct, &QAction::triggered, m_log, &QTextEdit::clear); connect(m_clearAct, &QAction::triggered, m_log, &QTextEdit::clear);
m_clearTTYAct = new QAction(tr("Clear"), this);
connect(m_clearTTYAct, &QAction::triggered, m_tty, &QTextEdit::clear);
// Action groups make these actions mutually exclusive. // Action groups make these actions mutually exclusive.
m_logLevels = new QActionGroup(this); m_logLevels = new QActionGroup(this);
m_nothingAct = new QAction(tr("Nothing"), m_logLevels); m_nothingAct = new QAction(tr("Nothing"), m_logLevels);
@ -248,6 +252,13 @@ void log_frame::CreateAndConnectActions()
menu->exec(mapToGlobal(pos)); menu->exec(mapToGlobal(pos));
}); });
connect(m_tty, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
{
QMenu* menu = m_tty->createStandardContextMenu();
menu->addAction(m_clearTTYAct);
menu->exec(mapToGlobal(pos));
});
LoadSettings(); LoadSettings();
} }

View File

@ -50,6 +50,7 @@ private:
fs::file m_tty_file; fs::file m_tty_file;
QAction* m_clearAct; QAction* m_clearAct;
QAction* m_clearTTYAct;
QActionGroup* m_logLevels; QActionGroup* m_logLevels;
QAction* m_nothingAct; QAction* m_nothingAct;