44#include " ../davis_one/davis.h"
55
66#include < QApplication>
7- #include " QDragEnterEvent"
8- #include " QMimeData"
9- #include " QDebug"
10- #include " QFileInfo"
11- #include " QPainter"
12- #include " QMenuBar"
13- #include " QHBoxLayout"
14- #include " QPushButton"
15- #include " QPainterPath"
16- #include " QFileDialog"
17- #include " QTextStream"
7+ #include < QDragEnterEvent>
8+ #include < QMimeData>
9+ #include < QDebug>
10+ #include < QFileInfo>
11+ #include < QPainter>
12+ #include < QMenuBar>
13+ #include < QHBoxLayout>
14+ #include < QPushButton>
15+ #include < QPainterPath>
16+ #include < QFileDialog>
17+ #include < QTextStream>
1818#include < QClipboard>
1919#include < QPropertyAnimation>
2020#include < QParallelAnimationGroup>
2121#include < QStateMachine>
2222#include < QSignalTransition>
23- #include < QGraphicsColorizeEffect>
24- #include < QJsonArray>
25- #include " QDateTime"
23+ #include < QDateTime>
2624#include < QProcess>
27- #include < QJsonObject>
2825#include < QProgressBar>
2926#include < QTimer>
3027#include < QtConcurrent/QtConcurrent>
28+ #include < QScreen>
3129#include " json_utils.h"
3230
3331
34-
3532const int ANIMATION_DURATION = 300 ;
3633
37-
3834DavisGUI::DavisGUI (QWidget* parent)
3935 : QMainWindow(parent)
4036 , ui(new Ui::DavisGUI) {
@@ -154,27 +150,31 @@ DavisGUI::DavisGUI(QWidget* parent)
154150 connect (this , &DavisGUI::hideProgressBar, barCool, &coolProgressBar::stopAnimation);
155151
156152 qpbOpen = new AnimatedButton (" Open" , QColor (120 , 120 , 120 ), QColor (42 , 130 , 218 ), this );
157- qpbOpen->setGeometry (70 , 180 , 90 , 30 );
153+ qpbOpen->setGeometry (65 , 180 , 90 , 30 );
158154 qpbOpen->setOriginalGeometry (qpbOpen->geometry ());
159155
160156 qpbBuffer = new AnimatedButton (" Copy from buffer or Ctrl+V" ,
161157 QColor (120 , 120 , 120 ),
162158 QColor (42 , 130 , 218 ),
163159 this );
164- qpbBuffer->setGeometry (170 , 180 , 170 , 30 );
160+ qpbBuffer->setGeometry (165 , 180 , 170 , 30 );
165161 qpbBuffer->setOriginalGeometry (qpbBuffer->geometry ());
166162
167163 connect (qpbOpen, &QPushButton::released, this , &DavisGUI::selectAndShowFiles);
168164 connect (qpbBuffer, &QPushButton::released, this , &DavisGUI::pasteFromClipboard);
165+
166+ settingsFilePath = " settings.json" ;
167+ QJsonObject settings = loadSettings (settingsFilePath);
168+ applySettings (settings);
169169}
170170
171171DavisGUI::~DavisGUI () {
172+ saveSettings (settingsFilePath);
172173 delete ui;
173174}
174175
175176void DavisGUI::show () {
176177 QMainWindow::show ();
177- setMaxStyleWindow (0 );
178178}
179179
180180void DavisGUI::hideElementsDuringResize () {
@@ -188,6 +188,46 @@ void DavisGUI::hideElementsDuringResize() {
188188 update ();
189189}
190190
191+ void DavisGUI::saveSettings (const QString& fileName) {
192+ QJsonObject settings;
193+ settings[" windowPosX" ] = pos ().x ();
194+ settings[" windowPosY" ] = pos ().y ();
195+ settings[" isMinStyleWindow" ] = m_isMinStyleWindow;
196+
197+ bool isSaved = jsn::saveJsonObjectToFile (fileName, settings);
198+ if (!isSaved) {
199+ qWarning (" Couldn't save settings file." );
200+ }
201+ return ;
202+ }
203+
204+ QJsonObject DavisGUI::loadSettings (const QString& fileName) {
205+ QJsonObject settings;
206+ bool isOpen = jsn::getJsonObjectFromFile (fileName, settings);
207+ if (!isOpen) {
208+ QScreen* screen = QGuiApplication::primaryScreen ();
209+ QRect screenGeometry = screen->geometry ();
210+ int x = (screenGeometry.width () - width ()) / 2 ;
211+ int y = (screenGeometry.height () - height ()) / 2 ;
212+ settings[" windowPosX" ] = x;
213+ settings[" windowPosY" ] = y;
214+ settings[" isMinStyleWindow" ] = false ;;
215+ }
216+ return settings;
217+ }
218+
219+ void DavisGUI::applySettings (const QJsonObject& settings) {
220+ m_isMinStyleWindow = settings[" isMinStyleWindow" ].toBool ();
221+ if (m_isMinStyleWindow) {
222+ setMinStyleWindow (0 );
223+ } else {
224+ setMaxStyleWindow (0 );
225+ }
226+ int x = settings[" windowPosX" ].toInt ();
227+ int y = settings[" windowPosY" ].toInt ();
228+ move (x, y);
229+ }
230+
191231void DavisGUI::readJsonToPlot (const QString& pathToFile) {
192232 QJsonObject user_stamp_keys;
193233 if (jsn::getJsonObjectFromFile (" user_keys_list.json" , user_stamp_keys) == false ) {
0 commit comments