-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappw.cpp
232 lines (198 loc) · 7.18 KB
/
appw.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <QtGui>
#include <QtWidgets>
#include <QTextStream>
#include <QApplication>
#include "plot.h"
#include "appw.h"
#include "move.h"
#include "scale.h"
#include "close.h"
#include "curve.h"
#include "fileformat.h"
AppWindow::AppWindow()
{
plot = new Plot;
setCentralWidget(plot);
addActions();
addMenus();
// readSettings();
setDataFile("","");
// connect(textEdit->document(), SIGNAL(contentsChanged()), this,
// SLOT(needsSave()));
// set window size to 67% of desktop if enough to display all widgets
// done this to avoid tiny window on high res laptop screen
QSize swin = this->size(); // current size (fits widgets)
QSize sdesk = qApp->primaryScreen()->availableSize()*2/3;
if (swin.width() < sdesk.width()) swin.setWidth(sdesk.width());
if (swin.height() < sdesk.height()) swin.setHeight(sdesk.height());
this->resize(swin);
}
// to be called by changed signal of contents
/* void AppWindow::needsSave()
{
// call QWidget.setWindowModified to update window change indicator
setWindowModified(textEdit->document()->isModified());
} */
void AppWindow::quitEvent(QCloseEvent *event)
{
if (checkSave())
{
// saveSettings();
event->accept();
} else
{
event->ignore();
}
}
void AppWindow::open()
{
QString *filter = new QString(); // selected filter
FileFormat* format = new FileFormat();
QStringList fns = QFileDialog::getOpenFileNames(this,
tr("Open file"),QString(),
format->filterString(),filter);
delete format;
foreach(const QString & fn, fns)
{
if (!fn.isEmpty())
{
setDataFile(fn,*filter);
}
}
delete filter;
}
void AppWindow::move()
{
QList<Curve*> curves = plot->curveList();
MoveDialog *dia = new MoveDialog(curves, this);
dia->exec();
}
void AppWindow::scale()
{
QList<Curve*> curves = plot->curveList();
ScaleDialog *dia = new ScaleDialog(curves, this);
dia->exec();
}
void AppWindow::fclose()
{
CloseDialog *dia = new CloseDialog(plot, this);
dia->exec();
}
void AppWindow::about()
{
QMessageBox dia;
dia.setText(tr("PXV - Powder X-ray Viewer"));
dia.setInformativeText(tr("<html>Author: Laszlo Fabian, 2010-2022<br>"
"<br>This program is free software: you can "
"redistribute it and/or modify it under the "
"terms of the <a href="
"https://www.gnu.org/licenses>"
"GNU General Public License</a> as "
"published by the Free Software Foundation, "
"either version 3 of the License, or (at your "
"option) any later version.<br><br>"
"This program relies on the <a "
"href=https://qwt.sourceforge.io>Qwt</a> "
"library."
"</html>"
));
dia.exec();
}
void AppWindow::addActions()
{
openAction = new QAction(tr("&Open..."),this);
openAction->setShortcuts(QKeySequence::Open);
openAction->setStatusTip(tr("Open an XY data file"));
openAction->setIcon(QIcon::fromTheme("document-open"));
connect(openAction,SIGNAL(triggered()),this,SLOT(open()));
exportAction = new QAction(tr("&Export..."),this);
// exportAction->setShortcuts(QKeySequence::Print);
exportAction->setStatusTip(tr("Save the graph to an image file"));
exportAction->setIcon(QIcon::fromTheme("document-export"));
connect(exportAction,SIGNAL(triggered()),plot,SLOT(fexport()));
printAction = new QAction(tr("&Print..."),this);
printAction->setShortcuts(QKeySequence::Print);
printAction->setStatusTip(tr("Print the graph"));
printAction->setIcon(QIcon::fromTheme("document-print"));
connect(printAction,SIGNAL(triggered()),plot,SLOT(print()));
closeAction = new QAction(tr("&Close..."),this);
closeAction->setShortcuts(QKeySequence::Close);
closeAction->setStatusTip(tr("Close a data set"));
closeAction->setIcon(QIcon::fromTheme("window-close"));
connect(closeAction,SIGNAL(triggered()),this,SLOT(fclose()));
quitAction = new QAction(tr("&Quit"),this);
quitAction->setShortcuts(QKeySequence::Quit);
quitAction->setStatusTip(tr("Quit the application"));
quitAction->setIcon(QIcon::fromTheme("application-exit"));
connect(quitAction,SIGNAL(triggered()),this,SLOT(close()));
moveAction = new QAction(tr("&Move pattern..."),this);
// quitAction->setShortcuts(QKeySequence::Quit);
moveAction->setStatusTip(tr("Shift a pattern in any direction"));
moveAction->setIcon(QIcon::fromTheme("transform-move")) ;
connect(moveAction,SIGNAL(triggered()),this,SLOT(move()));
scaleAction = new QAction(tr("&Scale pattern..."),this);
// quitAction->setShortcuts(QKeySequence::Quit);
scaleAction->setStatusTip(tr("Change the intensity scale"));
scaleAction->setIcon(QIcon::fromTheme("transform-scale")) ;
connect(scaleAction,SIGNAL(triggered()),this,SLOT(scale()));
zoomFitAction = new QAction(tr("Zoom to &Fit"),this);
zoomFitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Asterisk));
zoomFitAction->setStatusTip(tr("Zoom to show all data"));
zoomFitAction->setIcon(QIcon::fromTheme("zoom-fit-best"));
connect(zoomFitAction,SIGNAL(triggered()),plot,SLOT(zoomToFit()));
aboutAction = new QAction(tr("About &pxv..."),this);
aboutAction->setStatusTip(tr("Information about the program"));
aboutAction->setIcon(QIcon::fromTheme("help-about"));
connect(aboutAction,SIGNAL(triggered()),this,SLOT(about()));
aboutQtAction = new QAction(tr("About &Qt..."),this);
aboutQtAction->setStatusTip(tr("Information about the Qt framework"));
aboutQtAction->setIcon(QIcon::fromTheme("help-about"));
connect(aboutQtAction,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
}
void AppWindow::addMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(openAction);
fileMenu->addAction(exportAction);
fileMenu->addAction(printAction);
fileMenu->addSeparator();
fileMenu->addAction(closeAction);
fileMenu->addAction(quitAction);
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(moveAction);
editMenu->addAction(scaleAction);
viewMenu = menuBar()->addMenu(tr("&View"));
viewMenu->addAction(zoomFitAction);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAction);
helpMenu->addAction(aboutQtAction);
}
bool AppWindow::checkSave()
{
if (true) // should check if a save is needed once implemented
{
QMessageBox::StandardButton re;
re = QMessageBox::warning(this, tr("File modified"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (re == QMessageBox::Save)
return true;
else if (re == QMessageBox::Cancel)
return false;
}
return true;
}
void AppWindow::setDataFile(const QString &fn, const QString & format)
{
dataFile = fn;
// textEdit->document()->setModified(false);
if (!dataFile.isEmpty())
{
// setWindowFilePath(dataFile);
plot->addDataFile(dataFile, format);
} else
{
// setWindowFilePath("untitled");
}
}