-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
86 lines (79 loc) · 2.37 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QClipboard>
#include <QDate>
#include <QSettings>
#include <QDesktopWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ReadSettings();
ui->editLine->setFocus();
}
void MainWindow::ReadSettings()
{
QSettings settings("marvo","RM-o-Mat");
settings.beginGroup("MainWindow");
QSize windowSize = settings.value("size", QSize(350,65)).toSize();
resize(windowSize);
QPoint windowPosition = settings.value("position", QPoint(20,20)).toPoint();
if (windowPosition.x() + windowSize.width()
> QApplication::desktop()->screenGeometry().width())
{
windowPosition.setX(QApplication::desktop()->screenGeometry().width()
- (windowSize.width() + 20));
}
if (windowPosition.x() <= 0)
{
windowPosition.setX(5);
}
if (windowPosition.y() + windowSize.height()
> QApplication::desktop()->screenGeometry().height())
{
windowPosition.setY(QApplication::desktop()->screenGeometry().height()
- (windowSize.height() + 20));
}
if (windowPosition.y() <= 0)
{
windowPosition.setY(5);
}
move(windowPosition);
settings.endGroup();
settings.beginGroup("Content");
ui->editName->setText(settings.value("Name","").toString());
settings.endGroup();
}
void MainWindow::WriteSettings()
{
QSettings settings("marvo", "RM-o-Mat");
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("position", pos());
settings.endGroup();
settings.beginGroup("Content");
settings.setValue("Name", ui->editName->text());
settings.endGroup();
}
MainWindow::~MainWindow()
{
WriteSettings();
delete ui;
}
void MainWindow::on_btnRM_clicked()
{
QClipboard *myClip = QApplication::clipboard();
QString myRM;
QDate myDate = QDate::currentDate();
myRM = myDate.toString("dd.MM.yy") + " RM "+ ui->editName->text() +
" \"" + ui->editLine->text() + '"';
myClip->setText(myRM);
ui->statusBar->showMessage(myRM);
ui->editLine->setFocus();
ui->editLine->selectAll();
}
void MainWindow::on_editName_returnPressed()
{
ui->editLine->setFocus();
}