blob: 36dd9b42fc0e4ed7ea78f44df64b8037adf84af6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include "messageaveraging.h"
#include <QSettings>
#include <QApplication>
#include <QTextCharFormat>
#include "SettingsGroup.hpp"
#include "qt_helpers.hpp"
#include "ui_messageaveraging.h"
MessageAveraging::MessageAveraging(QSettings * settings, QFont const& font, QWidget *parent) :
QWidget(parent),
settings_ {settings},
ui(new Ui::MessageAveraging)
{
ui->setupUi(this);
setWindowTitle (QApplication::applicationName () + " - " + tr ("Message Averaging"));
ui->msgAvgPlainTextEdit->setReadOnly (true);
changeFont (font);
read_settings ();
}
MessageAveraging::~MessageAveraging()
{
if (isVisible ()) write_settings ();
}
void MessageAveraging::changeFont (QFont const& font)
{
ui->header_label->setStyleSheet (font_as_stylesheet (font));
ui->msgAvgPlainTextEdit->setStyleSheet (font_as_stylesheet (font));
setContentFont (font);
updateGeometry ();
}
void MessageAveraging::setContentFont(QFont const& font)
{
ui->msgAvgPlainTextEdit->setFont (font);
QTextCharFormat charFormat;
charFormat.setFont (font);
ui->msgAvgPlainTextEdit->selectAll ();
auto cursor = ui->msgAvgPlainTextEdit->textCursor ();
cursor.mergeCharFormat (charFormat);
cursor.clearSelection ();
cursor.movePosition (QTextCursor::End);
// position so viewport scrolled to left
cursor.movePosition (QTextCursor::Up);
cursor.movePosition (QTextCursor::StartOfLine);
ui->msgAvgPlainTextEdit->setTextCursor (cursor);
ui->msgAvgPlainTextEdit->ensureCursorVisible ();
}
void MessageAveraging::closeEvent (QCloseEvent * e)
{
write_settings ();
QWidget::closeEvent (e);
}
void MessageAveraging::read_settings ()
{
SettingsGroup group {settings_, "MessageAveraging"};
restoreGeometry (settings_->value ("window/geometry").toByteArray ());
}
void MessageAveraging::write_settings ()
{
SettingsGroup group {settings_, "MessageAveraging"};
settings_->setValue ("window/geometry", saveGeometry ());
}
void MessageAveraging::displayAvg(QString const& t)
{
ui->msgAvgPlainTextEdit->setPlainText(t);
}
|