|
@@ -0,0 +1,346 @@
|
|
1
|
+/*603:*/
|
|
2
|
+#line 66 "./daterangeselector.w"
|
|
3
|
+
|
|
4
|
+#include <QCalendarWidget>
|
|
5
|
+#include <QPushButton>
|
|
6
|
+#include <QBoxLayout>
|
|
7
|
+#include <QLabel>
|
|
8
|
+#include <QToolButton>
|
|
9
|
+#include <QApplication>
|
|
10
|
+#include <QDesktopWidget>
|
|
11
|
+
|
|
12
|
+#include "daterangeselector.h"
|
|
13
|
+
|
|
14
|
+/*604:*/
|
|
15
|
+#line 86 "./daterangeselector.w"
|
|
16
|
+
|
|
17
|
+class CustomDateRangePopup:public QWidget
|
|
18
|
+{
|
|
19
|
+Q_OBJECT
|
|
20
|
+public:
|
|
21
|
+CustomDateRangePopup(QWidget*parent= NULL);
|
|
22
|
+public slots:
|
|
23
|
+void applyRange();
|
|
24
|
+signals:
|
|
25
|
+void hidingPopup();
|
|
26
|
+protected:
|
|
27
|
+virtual void hideEvent(QHideEvent*event);
|
|
28
|
+private slots:
|
|
29
|
+void validateRange();
|
|
30
|
+private:
|
|
31
|
+QCalendarWidget*startDateSelector;
|
|
32
|
+QCalendarWidget*endDateSelector;
|
|
33
|
+QPushButton*applyButton;
|
|
34
|
+};
|
|
35
|
+
|
|
36
|
+/*:604*/
|
|
37
|
+#line 77 "./daterangeselector.w"
|
|
38
|
+
|
|
39
|
+/*605:*/
|
|
40
|
+#line 110 "./daterangeselector.w"
|
|
41
|
+
|
|
42
|
+CustomDateRangePopup::CustomDateRangePopup(QWidget*parent):
|
|
43
|
+QWidget(parent,Qt::Popup),startDateSelector(new QCalendarWidget),
|
|
44
|
+endDateSelector(new QCalendarWidget),applyButton(new QPushButton(tr("Apply")))
|
|
45
|
+{
|
|
46
|
+setAttribute(Qt::WA_WindowPropagation);
|
|
47
|
+
|
|
48
|
+QVBoxLayout*outerLayout= new QVBoxLayout;
|
|
49
|
+QHBoxLayout*calendarsLayout= new QHBoxLayout;
|
|
50
|
+QVBoxLayout*startDateLayout= new QVBoxLayout;
|
|
51
|
+QVBoxLayout*endDateLayout= new QVBoxLayout;
|
|
52
|
+QHBoxLayout*buttonLayout= new QHBoxLayout;
|
|
53
|
+QLabel*startDateLabel= new QLabel(tr("From"));
|
|
54
|
+QLabel*endDateLabel= new QLabel(tr("To"));
|
|
55
|
+startDateSelector->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
|
|
56
|
+endDateSelector->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
|
|
57
|
+DateRangeSelector*selector= qobject_cast<DateRangeSelector*> (parent);
|
|
58
|
+if(parent){
|
|
59
|
+QStringList range= selector->currentRange().toStringList();
|
|
60
|
+startDateSelector->setSelectedDate(QDate::fromString(range.first(),Qt::ISODate));
|
|
61
|
+endDateSelector->setSelectedDate(QDate::fromString(range.last(),Qt::ISODate));
|
|
62
|
+}
|
|
63
|
+connect(startDateSelector,SIGNAL(selectionChanged()),this,SLOT(validateRange()));
|
|
64
|
+connect(endDateSelector,SIGNAL(selectionChanged()),this,SLOT(validateRange()));
|
|
65
|
+
|
|
66
|
+startDateLayout->addWidget(startDateLabel);
|
|
67
|
+startDateLayout->addWidget(startDateSelector);
|
|
68
|
+endDateLayout->addWidget(endDateLabel);
|
|
69
|
+endDateLayout->addWidget(endDateSelector);
|
|
70
|
+
|
|
71
|
+connect(applyButton,SIGNAL(clicked()),this,SLOT(applyRange()));
|
|
72
|
+
|
|
73
|
+buttonLayout->addStretch();
|
|
74
|
+buttonLayout->addWidget(applyButton);
|
|
75
|
+
|
|
76
|
+calendarsLayout->addLayout(startDateLayout);
|
|
77
|
+calendarsLayout->addLayout(endDateLayout);
|
|
78
|
+outerLayout->addLayout(calendarsLayout);
|
|
79
|
+outerLayout->addLayout(buttonLayout);
|
|
80
|
+setLayout(outerLayout);
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+/*:605*//*606:*/
|
|
84
|
+#line 158 "./daterangeselector.w"
|
|
85
|
+
|
|
86
|
+void CustomDateRangePopup::hideEvent(QHideEvent*)
|
|
87
|
+{
|
|
88
|
+emit hidingPopup();
|
|
89
|
+}
|
|
90
|
+
|
|
91
|
+/*:606*//*607:*/
|
|
92
|
+#line 167 "./daterangeselector.w"
|
|
93
|
+
|
|
94
|
+void CustomDateRangePopup::applyRange()
|
|
95
|
+{
|
|
96
|
+DateRangeSelector*selector= qobject_cast<DateRangeSelector*> (parentWidget());
|
|
97
|
+if(selector)
|
|
98
|
+{
|
|
99
|
+selector->setCustomRange(QVariant(QStringList()<<
|
|
100
|
+startDateSelector->selectedDate().toString(Qt::ISODate)<<
|
|
101
|
+endDateSelector->selectedDate().toString(Qt::ISODate)));
|
|
102
|
+}
|
|
103
|
+hide();
|
|
104
|
+}
|
|
105
|
+
|
|
106
|
+/*:607*//*608:*/
|
|
107
|
+#line 184 "./daterangeselector.w"
|
|
108
|
+
|
|
109
|
+void CustomDateRangePopup::validateRange()
|
|
110
|
+{
|
|
111
|
+if(startDateSelector->selectedDate()> endDateSelector->selectedDate())
|
|
112
|
+{
|
|
113
|
+applyButton->setEnabled(false);
|
|
114
|
+}
|
|
115
|
+else
|
|
116
|
+{
|
|
117
|
+applyButton->setEnabled(true);
|
|
118
|
+}
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+/*:608*/
|
|
122
|
+#line 78 "./daterangeselector.w"
|
|
123
|
+
|
|
124
|
+/*609:*/
|
|
125
|
+#line 202 "./daterangeselector.w"
|
|
126
|
+
|
|
127
|
+DateRangeSelector::DateRangeSelector(QWidget*parent):
|
|
128
|
+QWidget(parent),quickSelector(new QComboBox(this)),
|
|
129
|
+customRangeSelector(NULL),lastIndex(0)
|
|
130
|
+{
|
|
131
|
+connect(quickSelector,SIGNAL(currentIndexChanged(int)),this,SLOT(updateRange(int)));
|
|
132
|
+
|
|
133
|
+QDate currentDate= QDate::currentDate();
|
|
134
|
+
|
|
135
|
+QHBoxLayout*layout= new QHBoxLayout;
|
|
136
|
+/*610:*/
|
|
137
|
+#line 231 "./daterangeselector.w"
|
|
138
|
+
|
|
139
|
+quickSelector->addItem("Yesterday",QVariant(QStringList()<<
|
|
140
|
+currentDate.addDays(-1).toString(Qt::ISODate)));
|
|
141
|
+quickSelector->addItem("Today",QVariant(QStringList()<<
|
|
142
|
+currentDate.toString(Qt::ISODate)));
|
|
143
|
+quickSelector->insertSeparator(quickSelector->count());
|
|
144
|
+quickSelector->addItem("This Week",QVariant(QStringList()<<
|
|
145
|
+(currentDate.dayOfWeek()%7?
|
|
146
|
+currentDate.addDays(-currentDate.dayOfWeek()).toString(Qt::ISODate):
|
|
147
|
+currentDate.toString(Qt::ISODate))<<
|
|
148
|
+currentDate.addDays(6-(currentDate.dayOfWeek()%7)).toString(Qt::ISODate)));
|
|
149
|
+quickSelector->addItem("This Week to Date",currentDate.dayOfWeek()%7?
|
|
150
|
+QVariant(QStringList()<<
|
|
151
|
+currentDate.addDays(-currentDate.dayOfWeek()).toString(Qt::ISODate)<<
|
|
152
|
+currentDate.toString(Qt::ISODate)):
|
|
153
|
+QVariant(QStringList()<<currentDate.toString(Qt::ISODate)));
|
|
154
|
+quickSelector->addItem("Last Week",QVariant(QStringList()<<
|
|
155
|
+currentDate.addDays(-(currentDate.dayOfWeek()%7)-7).toString(Qt::ISODate)<<
|
|
156
|
+currentDate.addDays(-(currentDate.dayOfWeek()%7)-1).toString(Qt::ISODate)));
|
|
157
|
+quickSelector->addItem("Last 7 Days",QVariant(QStringList()<<
|
|
158
|
+currentDate.addDays(-6).toString(Qt::ISODate)<<
|
|
159
|
+currentDate.toString(Qt::ISODate)));
|
|
160
|
+quickSelector->insertSeparator(quickSelector->count());
|
|
161
|
+quickSelector->addItem("This Month",QVariant(QStringList()<<
|
|
162
|
+QDate(currentDate.year(),currentDate.month(),1).toString(Qt::ISODate)<<
|
|
163
|
+QDate(currentDate.year(),currentDate.month(),
|
|
164
|
+currentDate.daysInMonth()).toString(Qt::ISODate)));
|
|
165
|
+quickSelector->addItem("This Month to Date",(currentDate.day()==1?
|
|
166
|
+(QVariant(QStringList()<<currentDate.toString(Qt::ISODate))):
|
|
167
|
+(QVariant(QStringList()<<
|
|
168
|
+QDate(currentDate.year(),currentDate.month(),1).toString(Qt::ISODate)<<
|
|
169
|
+currentDate.toString(Qt::ISODate)))));
|
|
170
|
+quickSelector->addItem("Last Four Weeks",QVariant(QStringList()<<
|
|
171
|
+currentDate.addDays(-27).toString(Qt::ISODate)<<
|
|
172
|
+currentDate.toString(Qt::ISODate)));
|
|
173
|
+quickSelector->addItem("Last 30 Days",QVariant(QStringList()<<
|
|
174
|
+currentDate.addDays(-29).toString(Qt::ISODate)<<
|
|
175
|
+currentDate.toString(Qt::ISODate)));
|
|
176
|
+quickSelector->insertSeparator(quickSelector->count());
|
|
177
|
+quickSelector->addItem("This Quarter",QVariant(QStringList()<<
|
|
178
|
+QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).toString(Qt::ISODate)<<
|
|
179
|
+(currentDate.month()> 9?
|
|
180
|
+QDate(currentDate.year(),12,31).toString(Qt::ISODate):
|
|
181
|
+QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3)+3,1).addDays(-1).toString(Qt::ISODate))));
|
|
182
|
+quickSelector->addItem("This Quarter to Date",
|
|
183
|
+(currentDate.day()==1&&(currentDate.month()-1)%3==0)?
|
|
184
|
+QVariant(QStringList()<<currentDate.toString(Qt::ISODate)):
|
|
185
|
+QVariant(QStringList()<<
|
|
186
|
+QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).toString(Qt::ISODate)<<
|
|
187
|
+currentDate.toString(Qt::ISODate)));
|
|
188
|
+quickSelector->addItem("Last Quarter",currentDate.month()<4?
|
|
189
|
+QVariant(QStringList()<<
|
|
190
|
+QDate(currentDate.year()-1,10,1).toString(Qt::ISODate)<<
|
|
191
|
+QDate(currentDate.year()-1,12,31).toString(Qt::ISODate)):
|
|
192
|
+QVariant(QStringList()<<
|
|
193
|
+QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3)-3,1).toString(Qt::ISODate)<<
|
|
194
|
+QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).addDays(-1).toString(Qt::ISODate)));
|
|
195
|
+quickSelector->addItem("Last 90 Days",QVariant(QStringList()<<
|
|
196
|
+currentDate.addDays(-89).toString(Qt::ISODate)<<
|
|
197
|
+currentDate.toString(Qt::ISODate)));
|
|
198
|
+quickSelector->insertSeparator(quickSelector->count());
|
|
199
|
+quickSelector->addItem("This Year",QVariant(QStringList()<<
|
|
200
|
+QDate(currentDate.year(),1,1).toString(Qt::ISODate)<<
|
|
201
|
+QDate(currentDate.year(),12,31).toString(Qt::ISODate)));
|
|
202
|
+quickSelector->addItem("This Year to Date",(currentDate.dayOfYear()==1)?
|
|
203
|
+QVariant(QStringList()<<currentDate.toString(Qt::ISODate)):
|
|
204
|
+QVariant(QStringList()<<QDate(currentDate.year(),1,1).toString(Qt::ISODate)<<
|
|
205
|
+currentDate.toString(Qt::ISODate)));
|
|
206
|
+quickSelector->addItem("Last Year",QVariant(QStringList()<<
|
|
207
|
+QDate(currentDate.year()-1,1,1).toString(Qt::ISODate)<<
|
|
208
|
+QDate(currentDate.year()-1,12,31).toString(Qt::ISODate)));
|
|
209
|
+quickSelector->addItem("Last 365 Days",QVariant(QStringList()<<
|
|
210
|
+currentDate.addDays(-364).toString(Qt::ISODate)<<
|
|
211
|
+currentDate.toString(Qt::ISODate)));
|
|
212
|
+quickSelector->insertSeparator(quickSelector->count());
|
|
213
|
+quickSelector->addItem("Lifetime");
|
|
214
|
+quickSelector->addItem("Custom");
|
|
215
|
+
|
|
216
|
+/*:610*/
|
|
217
|
+#line 212 "./daterangeselector.w"
|
|
218
|
+
|
|
219
|
+QToolButton*customButton= new QToolButton;
|
|
220
|
+customButton->setIcon(QIcon::fromTheme("office-calendar",
|
|
221
|
+QIcon(":/resources/icons/tango/scalable/apps/office-calendar.svg")));
|
|
222
|
+layout->addWidget(quickSelector);
|
|
223
|
+layout->addWidget(customButton);
|
|
224
|
+setLayout(layout);
|
|
225
|
+
|
|
226
|
+connect(customButton,SIGNAL(clicked()),this,SLOT(toggleCustom()));
|
|
227
|
+}
|
|
228
|
+
|
|
229
|
+/*:609*//*611:*/
|
|
230
|
+#line 314 "./daterangeselector.w"
|
|
231
|
+
|
|
232
|
+void DateRangeSelector::updateRange(int index)
|
|
233
|
+{
|
|
234
|
+if(index!=lastIndex&&index==quickSelector->count()-1)
|
|
235
|
+{
|
|
236
|
+toggleCustom();
|
|
237
|
+}
|
|
238
|
+else
|
|
239
|
+{
|
|
240
|
+lastIndex= index;
|
|
241
|
+emit rangeUpdated(quickSelector->itemData(quickSelector->currentIndex()));
|
|
242
|
+}
|
|
243
|
+}
|
|
244
|
+
|
|
245
|
+/*:611*//*612:*/
|
|
246
|
+#line 331 "./daterangeselector.w"
|
|
247
|
+
|
|
248
|
+void DateRangeSelector::popupHidden()
|
|
249
|
+{
|
|
250
|
+customRangeSelector->deleteLater();
|
|
251
|
+customRangeSelector= NULL;
|
|
252
|
+quickSelector->setCurrentIndex(lastIndex);
|
|
253
|
+}
|
|
254
|
+
|
|
255
|
+/*:612*//*613:*/
|
|
256
|
+#line 342 "./daterangeselector.w"
|
|
257
|
+
|
|
258
|
+void DateRangeSelector::setCustomRange(QVariant range)
|
|
259
|
+{
|
|
260
|
+quickSelector->setItemData(quickSelector->count()-1,range);
|
|
261
|
+emit rangeUpdated(range);
|
|
262
|
+lastIndex= quickSelector->count()-1;
|
|
263
|
+quickSelector->setCurrentIndex(lastIndex);
|
|
264
|
+}
|
|
265
|
+
|
|
266
|
+/*:613*//*614:*/
|
|
267
|
+#line 357 "./daterangeselector.w"
|
|
268
|
+
|
|
269
|
+void DateRangeSelector::toggleCustom()
|
|
270
|
+{
|
|
271
|
+if(!customRangeSelector){
|
|
272
|
+customRangeSelector= new CustomDateRangePopup(this);
|
|
273
|
+QPoint pos= rect().bottomLeft();
|
|
274
|
+QPoint pos2= rect().topLeft();
|
|
275
|
+pos= mapToGlobal(pos);
|
|
276
|
+pos2= mapToGlobal(pos2);
|
|
277
|
+QSize size= customRangeSelector->sizeHint();
|
|
278
|
+QRect screen= QApplication::desktop()->availableGeometry(pos);
|
|
279
|
+if(pos.x()+size.width()> screen.right()){
|
|
280
|
+pos.setX(screen.right()-size.width());
|
|
281
|
+}
|
|
282
|
+pos.setX(qMax(pos.x(),screen.left()));
|
|
283
|
+if(pos.y()+size.height()> screen.bottom()){
|
|
284
|
+pos.setY(pos2.y()-size.height());
|
|
285
|
+}else if(pos.y()<screen.top()){
|
|
286
|
+pos.setY(screen.top());
|
|
287
|
+}
|
|
288
|
+if(pos.y()<screen.top()){
|
|
289
|
+pos.setY(screen.top());
|
|
290
|
+}
|
|
291
|
+if(pos.y()+size.height()> screen.bottom()){
|
|
292
|
+pos.setY(screen.bottom()-size.height());
|
|
293
|
+}
|
|
294
|
+customRangeSelector->move(pos);
|
|
295
|
+customRangeSelector->show();
|
|
296
|
+connect(customRangeSelector,SIGNAL(hidingPopup()),
|
|
297
|
+this,SLOT(popupHidden()));
|
|
298
|
+}
|
|
299
|
+else
|
|
300
|
+{
|
|
301
|
+customRangeSelector->close();
|
|
302
|
+customRangeSelector->deleteLater();
|
|
303
|
+customRangeSelector= NULL;
|
|
304
|
+}
|
|
305
|
+}
|
|
306
|
+
|
|
307
|
+/*:614*//*615:*/
|
|
308
|
+#line 399 "./daterangeselector.w"
|
|
309
|
+
|
|
310
|
+QVariant DateRangeSelector::currentRange()
|
|
311
|
+{
|
|
312
|
+return quickSelector->itemData(lastIndex);
|
|
313
|
+}
|
|
314
|
+
|
|
315
|
+/*:615*//*616:*/
|
|
316
|
+#line 407 "./daterangeselector.w"
|
|
317
|
+
|
|
318
|
+void DateRangeSelector::setCurrentIndex(int index)
|
|
319
|
+{
|
|
320
|
+quickSelector->setCurrentIndex(index);
|
|
321
|
+}
|
|
322
|
+
|
|
323
|
+/*:616*//*617:*/
|
|
324
|
+#line 422 "./daterangeselector.w"
|
|
325
|
+
|
|
326
|
+void DateRangeSelector::setLifetimeRange(QString startDate,QString endDate)
|
|
327
|
+{
|
|
328
|
+quickSelector->setItemData(quickSelector->count()-2,
|
|
329
|
+QVariant(QStringList()<<startDate<<endDate));
|
|
330
|
+}
|
|
331
|
+
|
|
332
|
+/*:617*//*618:*/
|
|
333
|
+#line 432 "./daterangeselector.w"
|
|
334
|
+
|
|
335
|
+void DateRangeSelector::removeIndex(int index)
|
|
336
|
+{
|
|
337
|
+quickSelector->removeItem(index);
|
|
338
|
+}
|
|
339
|
+
|
|
340
|
+/*:618*/
|
|
341
|
+#line 79 "./daterangeselector.w"
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+#include "moc_daterangeselector.cpp"
|
|
345
|
+
|
|
346
|
+/*:603*/
|