-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpintool.cpp
More file actions
50 lines (40 loc) · 1.17 KB
/
pintool.cpp
File metadata and controls
50 lines (40 loc) · 1.17 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
#include "pintool.h"
#include <QCloseEvent>
#include <QFile>
#include <QScrollBar>
#include <QStandardPaths>
#include <QString>
#include <QTextStream>
#include <QDebug>
namespace {
const QString DESKTOP_PATH = QString("%1/pinLog.txt").arg(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
const int SCROLLBAR_HIDE_TIME = 500;
};
PinTool::PinTool(QWidget *parent) : QWidget(parent), m_file(new QFile(DESKTOP_PATH, this)) {
ui.setupUi(this);
init();
}
PinTool::~PinTool() {
}
void PinTool::init() {
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
initEditContent();
}
// 读文件内容
void PinTool::initEditContent() {
if (m_file->open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream textStream(m_file);
ui.textEdit->setText(textStream.readAll());
m_file->close();
}
}
void PinTool::closeEvent(QCloseEvent* event) {
// 保存至本地
QString toSaveText = ui.textEdit->toPlainText();
if (m_file->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
QTextStream textStream(m_file);
textStream << toSaveText;
m_file->close();
}
event->accept();
}