-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogdialog.cpp
More file actions
92 lines (78 loc) · 2.48 KB
/
Copy pathlogdialog.cpp
File metadata and controls
92 lines (78 loc) · 2.48 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "logdialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTextBrowser>
#include <QPushButton>
#include <QFileDialog>
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
void LogDialog::create(QWidget *parent)
{
if (logDialog) {
logDialog->show();
logDialog->activateWindow();
logDialog->raise();
return;
}
logDialog = new LogDialog(parent);
logDialog->show();
qInstallMessageHandler(msgHandler);
}
LogDialog::LogDialog(QWidget *parent) : QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
browser = new QTextBrowser(this);
layout->addWidget(browser);
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->setContentsMargins(0, 0, 0, 0);
layout->addLayout(buttonLayout);
buttonLayout->addStretch(10);
clearButton = new QPushButton(this);
clearButton->setText("Clear");
buttonLayout->addWidget(clearButton);
connect(clearButton, SIGNAL (clicked()), browser, SLOT (clear()));
saveButton = new QPushButton(this);
saveButton->setText("Save");
buttonLayout->addWidget(saveButton);
connect(saveButton, SIGNAL (clicked()), this, SLOT (save()));
resize(600, 400);
setWindowTitle("Patchdirector Log");
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
LogDialog::~LogDialog()
{
logDialog = Q_NULLPTR;
qInstallMessageHandler(0);
}
void LogDialog::save()
{
QString saveFileName = QFileDialog::getSaveFileName(
this, "Save Log", QDir::home().absoluteFilePath("log.txt"),
"Text Files (*.txt);;All Files (*.*)"
);
if(saveFileName.isEmpty()) return;
QFile file(saveFileName);
if(!file.open(QIODevice::WriteOnly)) {
QMessageBox::warning(this, "Error", "The log could not be saved!");
return;
}
QTextStream stream(&file);
stream << browser->toPlainText();
file.close();
}
void LogDialog::msgHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
if (!logDialog) return;
QString s = msg;
switch (type) {
case QtWarningMsg: s.prepend("Warning: "); break;
case QtCriticalMsg: s.prepend("Critical: "); break;
case QtFatalMsg: s.prepend("Fatal: "); break;
}
logDialog->browser->append(s);
}
LogDialog* LogDialog::logDialog = Q_NULLPTR;