[Qt] style adjustments 5

rename even more members and clean headers
adjust some more connects
move some function bodies to cpp
This commit is contained in:
Megamouse 2017-09-06 20:13:01 +02:00 committed by Ani
parent 95231c4dee
commit 43bae9f9d7
8 changed files with 189 additions and 197 deletions

View file

@ -102,42 +102,31 @@ static gui_listener s_gui_listener;
log_frame::log_frame(std::shared_ptr<gui_settings> guiSettings, QWidget *parent) : QDockWidget(tr("Log"), parent), xgui_settings(guiSettings)
{
tabWidget = new QTabWidget;
QTabWidget* tabWidget = new QTabWidget;
log = new QTextEdit(tabWidget);
QPalette logPalette = log->palette();
m_log = new QTextEdit(tabWidget);
QPalette logPalette = m_log->palette();
logPalette.setColor(QPalette::Base, Qt::black);
log->setPalette(logPalette);
log->setReadOnly(true);
m_log->setPalette(logPalette);
m_log->setReadOnly(true);
m_log->setContextMenuPolicy(Qt::CustomContextMenu);
tty = new QTextEdit(tabWidget);
QPalette ttyPalette = log->palette();
m_tty = new QTextEdit(tabWidget);
QPalette ttyPalette = m_log->palette();
ttyPalette.setColor(QPalette::Base, Qt::black);
ttyPalette.setColor(QPalette::Text, Qt::white);
tty->setPalette(ttyPalette);
tty->setReadOnly(true);
m_tty->setPalette(ttyPalette);
m_tty->setReadOnly(true);
tabWidget->addTab(log, tr("Log"));
tabWidget->addTab(tty, tr("TTY"));
tabWidget->addTab(m_log, tr("Log"));
tabWidget->addTab(m_tty, tr("TTY"));
setWidget(tabWidget);
// Open or create TTY.log
tty_file.open(fs::get_config_dir() + "TTY.log", fs::read + fs::create);
m_tty_file.open(fs::get_config_dir() + "TTY.log", fs::read + fs::create);
CreateAndConnectActions();
log->setContextMenuPolicy(Qt::CustomContextMenu);
connect(log, &QWidget::customContextMenuRequested, [=](const QPoint& pos){
QMenu* menu = log->createStandardContextMenu();
menu->addAction(clearAct);
menu->addSeparator();
menu->addActions({ nothingAct, fatalAct, errorAct, todoAct, successAct, warningAct, noticeAct, traceAct });
menu->addSeparator();
menu->addAction(stackAct);
menu->addSeparator();
menu->addAction(TTYAct);
menu->exec(mapToGlobal(pos));
});
// Check for updates every ~10 ms
QTimer *timer = new QTimer(this);
@ -152,47 +141,47 @@ void log_frame::SetLogLevel(logs::level lev)
case logs::level::always:
case logs::level::fatal:
{
fatalAct->trigger();
m_fatalAct->trigger();
break;
}
case logs::level::error:
{
errorAct->trigger();
m_errorAct->trigger();
break;
}
case logs::level::todo:
{
todoAct->trigger();
m_todoAct->trigger();
break;
}
case logs::level::success:
{
successAct->trigger();
m_successAct->trigger();
break;
}
case logs::level::warning:
{
warningAct->trigger();
m_warningAct->trigger();
break;
}
case logs::level::notice:
{
noticeAct->trigger();
m_noticeAct->trigger();
break;
}
case logs::level::trace:
{
traceAct->trigger();
m_traceAct->trigger();
break;
}
default:
warningAct->trigger();
m_warningAct->trigger();
}
}
void log_frame::SetTTYLogging(bool val)
{
TTYAct->setChecked(val);
m_TTYAct->setChecked(val);
}
void log_frame::CreateAndConnectActions()
@ -212,42 +201,57 @@ void log_frame::CreateAndConnectActions()
});
};
clearAct = new QAction(tr("Clear"), this);
connect(clearAct, &QAction::triggered, log, &QTextEdit::clear);
m_clearAct = new QAction(tr("Clear"), this);
connect(m_clearAct, &QAction::triggered, m_log, &QTextEdit::clear);
// Action groups make these actions mutually exclusive.
logLevels = new QActionGroup(this);
nothingAct = new QAction(tr("Nothing"), logLevels);
nothingAct->setVisible(false);
fatalAct = new QAction(tr("Fatal"), logLevels);
errorAct = new QAction(tr("Error"), logLevels);
todoAct = new QAction(tr("Todo"), logLevels);
successAct = new QAction(tr("Success"), logLevels);
warningAct = new QAction(tr("Warning"), logLevels);
noticeAct = new QAction(tr("Notice"), logLevels);
traceAct = new QAction(tr("Trace"), logLevels);
m_logLevels = new QActionGroup(this);
m_nothingAct = new QAction(tr("Nothing"), m_logLevels);
m_nothingAct->setVisible(false);
m_fatalAct = new QAction(tr("Fatal"), m_logLevels);
m_errorAct = new QAction(tr("Error"), m_logLevels);
m_todoAct = new QAction(tr("Todo"), m_logLevels);
m_successAct = new QAction(tr("Success"), m_logLevels);
m_warningAct = new QAction(tr("Warning"), m_logLevels);
m_noticeAct = new QAction(tr("Notice"), m_logLevels);
m_traceAct = new QAction(tr("Trace"), m_logLevels);
stackAct = new QAction(tr("Stack Mode"), this);
stackAct->setCheckable(true);
connect(stackAct, &QAction::toggled, xgui_settings.get(), [=](bool checked) {
m_stackAct = new QAction(tr("Stack Mode"), this);
m_stackAct->setCheckable(true);
connect(m_stackAct, &QAction::toggled, xgui_settings.get(), [=](bool checked)
{
xgui_settings->SetValue(GUI::l_stack, checked);
m_stack_log = checked;
});
TTYAct = new QAction(tr("TTY"), this);
TTYAct->setCheckable(true);
connect(TTYAct, &QAction::triggered, xgui_settings.get(), [=](bool checked){
m_TTYAct = new QAction(tr("TTY"), this);
m_TTYAct->setCheckable(true);
connect(m_TTYAct, &QAction::triggered, xgui_settings.get(), [=](bool checked)
{
xgui_settings->SetValue(GUI::l_tty, checked);
});
l_initAct(nothingAct, logs::level::fatal);
l_initAct(fatalAct, logs::level::fatal);
l_initAct(errorAct, logs::level::error);
l_initAct(todoAct, logs::level::todo);
l_initAct(successAct, logs::level::success);
l_initAct(warningAct, logs::level::warning);
l_initAct(noticeAct, logs::level::notice);
l_initAct(traceAct, logs::level::trace);
l_initAct(m_nothingAct, logs::level::fatal);
l_initAct(m_fatalAct, logs::level::fatal);
l_initAct(m_errorAct, logs::level::error);
l_initAct(m_todoAct, logs::level::todo);
l_initAct(m_successAct, logs::level::success);
l_initAct(m_warningAct, logs::level::warning);
l_initAct(m_noticeAct, logs::level::notice);
l_initAct(m_traceAct, logs::level::trace);
connect(m_log, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
{
QMenu* menu = m_log->createStandardContextMenu();
menu->addAction(m_clearAct);
menu->addSeparator();
menu->addActions({ m_nothingAct, m_fatalAct, m_errorAct, m_todoAct, m_successAct, m_warningAct, m_noticeAct, m_traceAct });
menu->addSeparator();
menu->addAction(m_stackAct);
menu->addSeparator();
menu->addAction(m_TTYAct);
menu->exec(mapToGlobal(pos));
});
LoadSettings();
}
@ -257,7 +261,7 @@ void log_frame::LoadSettings()
SetLogLevel(xgui_settings->GetLogLevel());
SetTTYLogging(xgui_settings->GetValue(GUI::l_tty).toBool());
m_stack_log = xgui_settings->GetValue(GUI::l_stack).toBool();
stackAct->setChecked(m_stack_log);
m_stackAct->setChecked(m_stack_log);
}
void log_frame::UpdateUI()
@ -291,15 +295,15 @@ void log_frame::UpdateUI()
// Check TTY logs
while (const u64 size = std::min<u64>(buf.size(), tty_file.size() - tty_file.pos()))
while (const u64 size = std::min<u64>(buf.size(), m_tty_file.size() - m_tty_file.pos()))
{
QString text = get_utf8(tty_file, size);
QString text = get_utf8(m_tty_file, size);
// Hackily used the state of the check.. be better if I actually stored this value.
if (TTYAct->isChecked())
if (m_TTYAct->isChecked())
{
text.chop(1); // remove newline since Qt automatically adds a newline.
tty->append(text);
m_tty->append(text);
}
// Limit processing time
if (steady_clock::now() >= start + 4ms || text.isEmpty()) break;
@ -331,17 +335,17 @@ void log_frame::UpdateUI()
text += qstr(packet->msg);
// save old log state
QScrollBar *sb = log->verticalScrollBar();
QScrollBar *sb = m_log->verticalScrollBar();
bool isMax = sb->value() == sb->maximum();
int sb_pos = sb->value();
int sel_pos = log->textCursor().position();
int sel_start = log->textCursor().selectionStart();
int sel_end = log->textCursor().selectionEnd();
int sel_pos = m_log->textCursor().position();
int sel_start = m_log->textCursor().selectionStart();
int sel_end = m_log->textCursor().selectionEnd();
// clear selection or else it will get colorized as well
QTextCursor c = log->textCursor();
QTextCursor c = m_log->textCursor();
c.clearSelection();
log->setTextCursor(c);
m_log->setTextCursor(c);
// remove the new line because Qt's append adds a new line already.
text.chop(1);
@ -356,11 +360,11 @@ void log_frame::UpdateUI()
{
m_log_counter++;
suffix = QString(" x%1").arg(m_log_counter);
log->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
log->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
log->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
log->textCursor().removeSelectedText();
log->textCursor().deletePreviousChar();
m_log->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
m_log->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
m_log->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
m_log->textCursor().removeSelectedText();
m_log->textCursor().deletePreviousChar();
}
else
{
@ -370,14 +374,14 @@ void log_frame::UpdateUI()
}
// add actual log message
log->setTextColor(color);
log->append(text);
m_log->setTextColor(color);
m_log->append(text);
// add counter suffix if needed
if (m_stack_log && isSame)
{
log->setTextColor(Qt::white);
log->insertPlainText(suffix);
m_log->setTextColor(Qt::white);
m_log->insertPlainText(suffix);
}
// if we mark text from right to left we need to swap sides (start is always smaller than end)
@ -389,7 +393,7 @@ void log_frame::UpdateUI()
// reset old text cursor and selection
c.setPosition(sel_start);
c.setPosition(sel_end, QTextCursor::KeepAnchor);
log->setTextCursor(c);
m_log->setTextCursor(c);
// set scrollbar to max means auto-scroll
sb->setValue(isMax ? sb->maximum() : sb_pos);