-
Notifications
You must be signed in to change notification settings - Fork 3
/
MonthChooser.cpp
90 lines (70 loc) · 2.22 KB
/
MonthChooser.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
#include <QBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QDialogButtonBox>
#include <QStatusBar>
#include <QCalendarWidget>
#include "util.h"
#include "MonthChooser.h"
MonthChooser::
MonthChooser(QWidget *parent)
/******************************************************************************************
* Constructor
*/
: QDialog(parent)
{
setWindowTitle("Month Chooser");
QVBoxLayout *vbl = new QVBoxLayout(this);
{ /************************** 1st row ************************/
QHBoxLayout *hbl = new QHBoxLayout;
vbl->addLayout(hbl);
QPushButton *btn= new QPushButton("Today", this);
hbl->addWidget(btn);
QLabel *lbl= new QLabel("<b>Selected month:</b>", this);
hbl->addWidget(lbl);
_selection_lbl= new QLabel(this);
hbl->addWidget(_selection_lbl);
hbl->addStretch(10);
}
{ /************************** 2nd row ************************/
QHBoxLayout *hbl = new QHBoxLayout;
vbl->addLayout(hbl);
_cw= new QCalendarWidget(this);
hbl->addWidget(_cw);
connect(_cw, SIGNAL(activated(const QDate&)), SLOT(dateChosen(const QDate&)));
connect(_cw, SIGNAL(clicked(const QDate&)), SLOT(dateChosen(const QDate&)));
hbl->addStretch();
}
{ /* Accept & Cancel buttons */
QHBoxLayout *hbl = new QHBoxLayout;
vbl->addLayout(hbl);
QDialogButtonBox *dbb =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
hbl->addWidget(dbb);
connect(dbb, SIGNAL(rejected()), SLOT(reject()));
connect(dbb, SIGNAL(accepted()), SLOT(accept()));
}
QStatusBar *sb= new QStatusBar(this);
vbl->addWidget(sb);
dateChosen(QDate::currentDate());
}
MonthChooser::
~MonthChooser()
/******************************************************************************************
* Destructor
*/
{
}
void
MonthChooser::
dateChosen(const QDate &when)
/******************************************************************************************
* A data was chosen
*/
{
QDateTime end_dt;
_selection_lbl->setText(when.toString("MMMM yyyy"));
_begin_dt.setDate(when.addDays(-when.day()+1));
end_dt.setDate(_begin_dt.date().addMonths(1));
_end_dt= end_dt.addMSecs(-1);
}