Esempio n. 1
0
void
kMyMoneyCalendar::selectWeekClicked()
{
  const KCalendarSystem* calendar = KGlobal::locale()->calendar();

  KPopupFrame *popup = new KPopupFrame(this);
  KDatePickerPrivateWeekSelector *picker = new KDatePickerPrivateWeekSelector(calendar, date(), popup);
  picker->resize(picker->sizeHint());
  picker->setWeek(weekOfYear(date()));
  picker->selectAll();
  popup->setMainWidget(picker);
  connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
  picker->setFocus();

  if (popup->exec(d->selectWeek->mapToGlobal(QPoint(0, d->selectWeek->height())))) {
    QDate newDate;
    int week = picker->week();
    // check if new week will lead to a valid date
    calendar->setDate(newDate, calendar->year(date()), 1, 1);
    while (weekOfYear(newDate) > 50)
      newDate = newDate.addDays(1);
    while (weekOfYear(newDate) < week && (week != 53 || (week == 53 &&
                                          (weekOfYear(newDate) != 52 || weekOfYear(newDate.addDays(1)) != 1))))
      newDate = newDate.addDays(1);
    if (week == 53 && weekOfYear(newDate) == 52)
      while (weekOfYear(newDate.addDays(-1)) == 52)
        newDate = newDate.addDays(-1);

    // Set the date, if it's invalid in any way then alert user and don't update
    if (!setDate(newDate)) {
      KNotification::beep();
    }
  }
  delete popup;
}
Esempio n. 2
0
void KXmlCommandSelector::slotHelpCommand()
{
    KPopupFrame *pop = new KPopupFrame(m_helpbtn);
    KActiveLabel *lab = new KActiveLabel(m_help, pop);
    lab->resize(lab->sizeHint());
    pop->setMainWidget(lab);
    pop->exec(m_helpbtn->mapToGlobal(QPoint(m_helpbtn->width(), 0)));
    pop->close(0);
    delete pop;
}
Esempio n. 3
0
void
KDatePicker::selectYearClicked()
{
  const KCalendarSystem * calendar = KGlobal::locale()->calendar();

  if (!d->selectYear->isChecked ())
  {
    return;
  }

  int year;
  KPopupFrame* popup = new KPopupFrame(this);
  KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup);
  // -----
  picker->resize(picker->sizeHint());
  picker->setYear( d->table->date().year() );
  picker->selectAll();
  popup->setMainWidget(picker);
  connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
  picker->setFocus();
  if(popup->exec(d->selectYear->mapToGlobal(QPoint(0, d->selectMonth->height()))))
    {
      QDate date;
      int day;
      // -----
      year=picker->getYear();
      date=d->table->date();
      day=calendar->day(date);
      // ----- construct a valid date in this month:
      //date.setYMD(year, date.month(), 1);
      //date.setYMD(year, date.month(), qMin(day, date.daysInMonth()));
      calendar->setYMD(date, year, calendar->month(date),
                       qMin(day, calendar->daysInMonth(date)));
      // ----- set this month
      setDate(date);
    } else {
      //KNotification::beep();
    }
  d->selectYear->setChecked( false );
  delete popup;
}
Esempio n. 4
0
void
ExtDatePicker::selectYearClicked()
{
//  const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();

  if (selectYear->state() == QButton::Off)
  {
    return;
  }

  int year;
  KPopupFrame* popup = new KPopupFrame(this);
  ExtDateInternalYearSelector* picker = new ExtDateInternalYearSelector(popup);
  // -----
  picker->resize(picker->sizeHint());
  popup->setMainWidget(picker);
  connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
  picker->setFocus();
  if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
    {
      ExtDate date;
      int day;
      // -----
      year=picker->getYear();
      date=table->getDate();
      day=d->calendar->day(date);
      // ----- construct a valid date in this month:
      //date.setYMD(year, date.month(), 1);
      //date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
      d->calendar->setYMD(date, year, d->calendar->month(date),
                       QMIN(day, d->calendar->daysInMonth(date)));
      // ----- set this month
      setDate(date);
    } else {
      KNotifyClient::beep();
    }
  delete popup;
}
Esempio n. 5
0
void
kMyMoneyCalendar::selectYearClicked()
{
  QDate newDate;
  const KCalendarSystem* calendar = KGlobal::locale()->calendar();

  KPopupFrame *popup = new KPopupFrame(this);
  KDatePickerPrivateYearSelector *picker = new KDatePickerPrivateYearSelector(calendar, date(), popup);
  picker->resize(picker->sizeHint());
  picker->setYear(calendar->year(date()));
  picker->selectAll();
  popup->setMainWidget(picker);
  connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
  picker->setFocus();

  if (popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) {
    // We need to create a valid date in the year/month selected so we can find out how many
    // days are in the month.
    newDate = d->validDateInYearMonth(picker->year(), calendar->month(date()));

    // If we have succeeded in creating a date in the new month, then try to create the new
    // date, checking we don't set a day after the last day of the month
    if (calendar->isValid(newDate)) {
      calendar->setDate(newDate,
                        picker->year(), calendar->month(date()),
                        qMin(calendar->day(date()), calendar->daysInMonth(newDate))
                       );
    }

    // Set the date, if it's invalid in any way then alert user and don't update
    if (!setDate(newDate)) {
      KNotification::beep();
    }
  }
  delete popup;
}