-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (52 loc) · 2.06 KB
/
main.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
#include <QAction>
#include <QApplication>
#include <QHBoxLayout>
#include <QSettings>
#include "ovalViewer.h"
/** ----------------------------------------------------------------------------
\fn save_window_position Saves the position of a window
---------------------------------------------------------------------------- */
static void save_window_position( QWidget *window, const QString& what )
{
QSettings prefs( QString( "Company" ), QString( "curve_fitting" ) );
// there are two parts to the window, the size and position
prefs.setValue( QString( "%1Position" ).arg( what ), QVariant( window->pos() ) );
prefs.setValue( QString( "%1Size" ).arg( what ), QVariant( window->size() ) );
}
/** ----------------------------------------------------------------------------
\fn restore_window_position Saves the position of a window
---------------------------------------------------------------------------- */
static void restore_window_position( QWidget *window, const QString& what )
{
QSettings prefs( QString( "Company" ), QString( "curve_fitting" ) );
QPoint pos = prefs.value( QString( "%1Position" ).arg( what ), QPoint( 10, 50 ) ).toPoint();
QSize size = prefs.value( QString( "%1Size" ).arg( what ), QSize( 600, 300 ) ).toSize();
window->setGeometry( QRect( pos, size ) );
}
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QWidget *window = new QWidget();
window->setWindowTitle( QString( "Window" ) );
QAction *quitX = new QAction( "Quit", & app );
quitX->setShortcut( QString( "Ctrl+Q" ) );
QObject::connect( quitX, SIGNAL( triggered() ), & app, SLOT( quit() ) );
QHBoxLayout *wl = new QHBoxLayout( window );
ovalViewer *oview = new ovalViewer( window );
wl->addWidget( oview );
restore_window_position( window, QString( "window" ) );
window->show();
int status = 0;
bool done = false;
do
{
status = app.exec();
if( status == 0 )
done = window->close();
else
break;
} while( not done );
save_window_position( window, "window" );
delete window;
return status;
}