123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- /*694:*/
- #line 70 "./daterangeselector.w"
-
- #include <QCalendarWidget>
- #include <QPushButton>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QToolButton>
- #include <QApplication>
- #include <QDesktopWidget>
-
- #include "daterangeselector.h"
-
- /*696:*/
- #line 117 "./daterangeselector.w"
-
- CustomDateRangePopup::CustomDateRangePopup(QWidget*parent):
- QWidget(parent,Qt::Popup),startDateSelector(new QCalendarWidget),
- endDateSelector(new QCalendarWidget),applyButton(new QPushButton(tr("Apply")))
- {
- setAttribute(Qt::WA_WindowPropagation);
-
- QVBoxLayout*outerLayout= new QVBoxLayout;
- QHBoxLayout*calendarsLayout= new QHBoxLayout;
- QVBoxLayout*startDateLayout= new QVBoxLayout;
- QVBoxLayout*endDateLayout= new QVBoxLayout;
- QHBoxLayout*buttonLayout= new QHBoxLayout;
- QLabel*startDateLabel= new QLabel(tr("From"));
- QLabel*endDateLabel= new QLabel(tr("To"));
- startDateSelector->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
- endDateSelector->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
- DateRangeSelector*selector= qobject_cast<DateRangeSelector*> (parent);
- if(parent){
- QStringList range= selector->currentRange().toStringList();
- startDateSelector->setSelectedDate(QDate::fromString(range.first(),Qt::ISODate));
- endDateSelector->setSelectedDate(QDate::fromString(range.last(),Qt::ISODate));
- }
- connect(startDateSelector,SIGNAL(selectionChanged()),this,SLOT(validateRange()));
- connect(endDateSelector,SIGNAL(selectionChanged()),this,SLOT(validateRange()));
-
- startDateLayout->addWidget(startDateLabel);
- startDateLayout->addWidget(startDateSelector);
- endDateLayout->addWidget(endDateLabel);
- endDateLayout->addWidget(endDateSelector);
-
- connect(applyButton,SIGNAL(clicked()),this,SLOT(applyRange()));
-
- buttonLayout->addStretch();
- buttonLayout->addWidget(applyButton);
-
- calendarsLayout->addLayout(startDateLayout);
- calendarsLayout->addLayout(endDateLayout);
- outerLayout->addLayout(calendarsLayout);
- outerLayout->addLayout(buttonLayout);
- setLayout(outerLayout);
- }
-
- /*:696*//*697:*/
- #line 165 "./daterangeselector.w"
-
- void CustomDateRangePopup::hideEvent(QHideEvent*)
- {
- emit hidingPopup();
- }
-
- /*:697*//*698:*/
- #line 174 "./daterangeselector.w"
-
- void CustomDateRangePopup::applyRange()
- {
- DateRangeSelector*selector= qobject_cast<DateRangeSelector*> (parentWidget());
- if(selector)
- {
- selector->setCustomRange(QVariant(QStringList()<<
- startDateSelector->selectedDate().toString(Qt::ISODate)<<
- endDateSelector->selectedDate().toString(Qt::ISODate)));
- }
- hide();
- }
-
- /*:698*//*699:*/
- #line 191 "./daterangeselector.w"
-
- void CustomDateRangePopup::validateRange()
- {
- if(startDateSelector->selectedDate()> endDateSelector->selectedDate())
- {
- applyButton->setEnabled(false);
- }
- else
- {
- applyButton->setEnabled(true);
- }
- }
-
- /*:699*/
- #line 81 "./daterangeselector.w"
-
- /*700:*/
- #line 209 "./daterangeselector.w"
-
- DateRangeSelector::DateRangeSelector(QWidget*parent):
- QWidget(parent),quickSelector(new QComboBox(this)),
- customRangeSelector(NULL),lastIndex(0)
- {
- connect(quickSelector,SIGNAL(currentIndexChanged(int)),this,SLOT(updateRange(int)));
-
- QDate currentDate= QDate::currentDate();
-
- QHBoxLayout*layout= new QHBoxLayout;
- /*701:*/
- #line 238 "./daterangeselector.w"
-
- quickSelector->addItem("Yesterday",QVariant(QStringList()<<
- currentDate.addDays(-1).toString(Qt::ISODate)));
- quickSelector->addItem("Today",QVariant(QStringList()<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->insertSeparator(quickSelector->count());
- quickSelector->addItem("This Week",QVariant(QStringList()<<
- (currentDate.dayOfWeek()%7?
- currentDate.addDays(-currentDate.dayOfWeek()).toString(Qt::ISODate):
- currentDate.toString(Qt::ISODate))<<
- currentDate.addDays(6-(currentDate.dayOfWeek()%7)).toString(Qt::ISODate)));
- quickSelector->addItem("This Week to Date",currentDate.dayOfWeek()%7?
- QVariant(QStringList()<<
- currentDate.addDays(-currentDate.dayOfWeek()).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)):
- QVariant(QStringList()<<currentDate.toString(Qt::ISODate)));
- quickSelector->addItem("Last Week",QVariant(QStringList()<<
- currentDate.addDays(-(currentDate.dayOfWeek()%7)-7).toString(Qt::ISODate)<<
- currentDate.addDays(-(currentDate.dayOfWeek()%7)-1).toString(Qt::ISODate)));
- quickSelector->addItem("Last 7 Days",QVariant(QStringList()<<
- currentDate.addDays(-6).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->insertSeparator(quickSelector->count());
- quickSelector->addItem("This Month",QVariant(QStringList()<<
- QDate(currentDate.year(),currentDate.month(),1).toString(Qt::ISODate)<<
- QDate(currentDate.year(),currentDate.month(),
- currentDate.daysInMonth()).toString(Qt::ISODate)));
- quickSelector->addItem("This Month to Date",(currentDate.day()==1?
- (QVariant(QStringList()<<currentDate.toString(Qt::ISODate))):
- (QVariant(QStringList()<<
- QDate(currentDate.year(),currentDate.month(),1).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)))));
- quickSelector->addItem("Last Four Weeks",QVariant(QStringList()<<
- currentDate.addDays(-27).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->addItem("Last 30 Days",QVariant(QStringList()<<
- currentDate.addDays(-29).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->insertSeparator(quickSelector->count());
- quickSelector->addItem("This Quarter",QVariant(QStringList()<<
- QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).toString(Qt::ISODate)<<
- (currentDate.month()> 9?
- QDate(currentDate.year(),12,31).toString(Qt::ISODate):
- QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3)+3,1).addDays(-1).toString(Qt::ISODate))));
- quickSelector->addItem("This Quarter to Date",
- (currentDate.day()==1&&(currentDate.month()-1)%3==0)?
- QVariant(QStringList()<<currentDate.toString(Qt::ISODate)):
- QVariant(QStringList()<<
- QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->addItem("Last Quarter",currentDate.month()<4?
- QVariant(QStringList()<<
- QDate(currentDate.year()-1,10,1).toString(Qt::ISODate)<<
- QDate(currentDate.year()-1,12,31).toString(Qt::ISODate)):
- QVariant(QStringList()<<
- QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3)-3,1).toString(Qt::ISODate)<<
- QDate(currentDate.year(),currentDate.month()-((currentDate.month()-1)%3),1).addDays(-1).toString(Qt::ISODate)));
- quickSelector->addItem("Last 90 Days",QVariant(QStringList()<<
- currentDate.addDays(-89).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->insertSeparator(quickSelector->count());
- quickSelector->addItem("This Year",QVariant(QStringList()<<
- QDate(currentDate.year(),1,1).toString(Qt::ISODate)<<
- QDate(currentDate.year(),12,31).toString(Qt::ISODate)));
- quickSelector->addItem("This Year to Date",(currentDate.dayOfYear()==1)?
- QVariant(QStringList()<<currentDate.toString(Qt::ISODate)):
- QVariant(QStringList()<<QDate(currentDate.year(),1,1).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->addItem("Last Year",QVariant(QStringList()<<
- QDate(currentDate.year()-1,1,1).toString(Qt::ISODate)<<
- QDate(currentDate.year()-1,12,31).toString(Qt::ISODate)));
- quickSelector->addItem("Last 365 Days",QVariant(QStringList()<<
- currentDate.addDays(-364).toString(Qt::ISODate)<<
- currentDate.toString(Qt::ISODate)));
- quickSelector->insertSeparator(quickSelector->count());
- quickSelector->addItem("Lifetime");
- quickSelector->addItem("Custom");
-
- /*:701*/
- #line 219 "./daterangeselector.w"
-
- QToolButton*customButton= new QToolButton;
- customButton->setIcon(QIcon::fromTheme("office-calendar",
- QIcon(":/resources/icons/tango/scalable/apps/office-calendar.svg")));
- layout->addWidget(quickSelector);
- layout->addWidget(customButton);
- setLayout(layout);
-
- connect(customButton,SIGNAL(clicked()),this,SLOT(toggleCustom()));
- }
-
- /*:700*//*702:*/
- #line 321 "./daterangeselector.w"
-
- void DateRangeSelector::updateRange(int index)
- {
- if(index!=lastIndex&&index==quickSelector->count()-1)
- {
- toggleCustom();
- }
- else
- {
- lastIndex= index;
- emit rangeUpdated(quickSelector->itemData(quickSelector->currentIndex()));
- }
- }
-
- /*:702*//*703:*/
- #line 338 "./daterangeselector.w"
-
- void DateRangeSelector::popupHidden()
- {
- customRangeSelector->deleteLater();
- customRangeSelector= NULL;
- quickSelector->setCurrentIndex(lastIndex);
- }
-
- /*:703*//*704:*/
- #line 349 "./daterangeselector.w"
-
- void DateRangeSelector::setCustomRange(QVariant range)
- {
- quickSelector->setItemData(quickSelector->count()-1,range);
- emit rangeUpdated(range);
- lastIndex= quickSelector->count()-1;
- quickSelector->setCurrentIndex(lastIndex);
- }
-
- /*:704*//*705:*/
- #line 364 "./daterangeselector.w"
-
- void DateRangeSelector::toggleCustom()
- {
- if(!customRangeSelector){
- customRangeSelector= new CustomDateRangePopup(this);
- QPoint pos= rect().bottomLeft();
- QPoint pos2= rect().topLeft();
- pos= mapToGlobal(pos);
- pos2= mapToGlobal(pos2);
- QSize size= customRangeSelector->sizeHint();
- QRect screen= QApplication::desktop()->availableGeometry(pos);
- if(pos.x()+size.width()> screen.right()){
- pos.setX(screen.right()-size.width());
- }
- pos.setX(qMax(pos.x(),screen.left()));
- if(pos.y()+size.height()> screen.bottom()){
- pos.setY(pos2.y()-size.height());
- }else if(pos.y()<screen.top()){
- pos.setY(screen.top());
- }
- if(pos.y()<screen.top()){
- pos.setY(screen.top());
- }
- if(pos.y()+size.height()> screen.bottom()){
- pos.setY(screen.bottom()-size.height());
- }
- customRangeSelector->move(pos);
- customRangeSelector->show();
- connect(customRangeSelector,SIGNAL(hidingPopup()),
- this,SLOT(popupHidden()));
- }
- else
- {
- customRangeSelector->close();
- customRangeSelector->deleteLater();
- customRangeSelector= NULL;
- }
- }
-
- /*:705*//*706:*/
- #line 406 "./daterangeselector.w"
-
- QVariant DateRangeSelector::currentRange()
- {
- return quickSelector->itemData(lastIndex);
- }
-
- /*:706*//*707:*/
- #line 414 "./daterangeselector.w"
-
- void DateRangeSelector::setCurrentIndex(int index)
- {
- quickSelector->setCurrentIndex(index);
- }
-
- int DateRangeSelector::currentIndex()
- {
- return quickSelector->currentIndex();
- }
-
- /*:707*//*708:*/
- #line 434 "./daterangeselector.w"
-
- void DateRangeSelector::setLifetimeRange(QString startDate,QString endDate)
- {
- quickSelector->setItemData(quickSelector->count()-2,
- QVariant(QStringList()<<startDate<<endDate));
- }
-
- /*:708*//*709:*/
- #line 444 "./daterangeselector.w"
-
- void DateRangeSelector::removeIndex(int index)
- {
- quickSelector->removeItem(index);
- }
-
- /*:709*/
- #line 82 "./daterangeselector.w"
-
-
- #ifdef __unix__
- #ifndef __linux__
- #include "moc_daterangeselector.cpp"
- #endif
- #endif
-
- /*:694*/
|