GUI fixes + log stacking (#2897)

* Add Stacking option to log contextmenu

Squashed commit:

[69f296af] cleanup

[4f4bf41f] use contextmenu instead

[e67036bc] use gui settings instead (+1 squashed commits)

Squashed commits:

[b3913dbe] fix backwards selection (+1 squashed commits)

Squashed commits:

[1e150f04] add stacking option (+3 squashed commit)

Squashed commit:

[be78da4f] fix scroll

[d3450c21] fix clearSelection

[e962ec9c] fix log color issue

* fix recent games related app crash

* gamelist improvements

Squashed commit:

[aa1f79c2] fix title names & con background

[d8381984] fix gamelist search

* finally fix show menu bug

* add rows to gamelist: resolutions, sound formats and parental level

* fix gamelist loadsettings
This commit is contained in:
Megamouse 2017-06-30 14:41:40 +02:00 committed by Ivan
parent 645f0e63ab
commit fd4a153eef
9 changed files with 257 additions and 59 deletions

View file

@ -5,6 +5,7 @@
#include <QMenu>
#include <QActionGroup>
#include <QScrollBar>
inline QString qstr(const std::string& _in) { return QString::fromUtf8(_in.data(), _in.size()); }
@ -135,6 +136,8 @@ log_frame::log_frame(std::shared_ptr<gui_settings> guiSettings, QWidget *parent)
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));
});
@ -231,6 +234,13 @@ void log_frame::CreateAndConnectActions()
noticeAct = new QAction(tr("Notice"), logLevels);
traceAct = new QAction(tr("Trace"), logLevels);
stackAct = new QAction(tr("Stack Mode"), this);
stackAct->setCheckable(true);
connect(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){
@ -253,6 +263,7 @@ void log_frame::LoadSettings()
{
SetLogLevel(xgui_settings->GetLogLevel());
SetTTYLogging(xgui_settings->GetValue(GUI::l_tty).toBool());
stackAct->setChecked(xgui_settings->GetValue(GUI::l_stack).toBool());
}
void log_frame::UpdateUI()
@ -324,10 +335,70 @@ void log_frame::UpdateUI()
// Print UTF-8 text.
text += qstr(packet->msg);
log->setTextColor(color);
// save old log state
QScrollBar *sb = 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();
// clear selection or else it will get colorized as well
QTextCursor c = log->textCursor();
c.clearSelection();
log->setTextCursor(c);
// remove the new line because Qt's append adds a new line already.
text.chop(1);
QString suffix;
bool isSame = text == m_old_text;
// create counter suffix and remove recurring line if needed
if (m_stack_log)
{
if (isSame)
{
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();
}
else
{
m_log_counter = 1;
m_old_text = text;
}
}
// add actual log message
log->setTextColor(color);
log->append(text);
// add counter suffix if needed
if (m_stack_log && isSame)
{
log->setTextColor(Qt::white);
log->insertPlainText(suffix);
}
// if we mark text from right to left we need to swap sides (start is always smaller than end)
if (sel_pos < sel_end)
{
std::swap(sel_start, sel_end);
}
// reset old text cursor and selection
c.setPosition(sel_start);
c.setPosition(sel_end, QTextCursor::KeepAnchor);
log->setTextCursor(c);
// set scrollbar to max means auto-scroll
sb->setValue(isMax ? sb->maximum() : sb_pos);
}
// Drop packet