void CalPrintYear::setSettingsWidget()
{
  CalPrintYearConfig *cfg =
      dynamic_cast<CalPrintYearConfig*>( (QWidget *)mConfigWidget );
  if ( cfg ) {
    const KCalendarSystem *calsys = calendarSystem();
    QDate start;
    calsys->setYMD( start, mYear, 1, 1 );
    int months = calsys->monthsInYear( start );
    int pages = 0;
    int prevPages = 0;
    for ( int i=1; i<= months; ++i ) {
      pages = ( months - 1 ) / i + 1;
      if ( pages != prevPages ) {
        prevPages = pages;
        cfg->mPages->addItem( QString::number( pages ), 0 );
      }
    }

    cfg->mYear->setValue( mYear );
    cfg->mPages->setItemText( cfg->mPages->currentIndex(), QString::number( mPages ) );

    cfg->mSubDays->setCurrentIndex( ( mSubDaysEvents == Text ) ? 0 : 1 );
    cfg->mHolidays->setCurrentIndex( ( mHolidaysEvents == Text ) ? 0 : 1 );
  }
}
Beispiel #2
0
KLocale::CalendarSystem KLocale::calendarSystem() const
{
    return d->calendarSystem();
}
void CalPrintYear::print( QPainter &p, int width, int height )
{
  QRect headerBox( 0, 0, width, headerHeight() );
  const KCalendarSystem *calsys = calendarSystem();
  KLocale *locale = KGlobal::locale();
  if ( !calsys || !locale ) {
    return;
  }

  QDate start;
  calsys->setYMD( start, mYear, 1, 1 );

  // Determine the nr of months and the max nr of days per month (dependent on
  // calendar system!!!!)
  QDate temp( start );
  int months = calsys->monthsInYear( start );
  int maxdays = 1;
  for ( int i = 1; i< months; ++i ) {
    maxdays = qMax( maxdays, temp.daysInMonth() );
    temp = calsys->addMonths( temp, 1 );
  }

  // Now determine the months per page so that the printout fits on
  // exactly mPages pages
  int monthsPerPage = ( months - 1 ) / mPages + 1;
  int pages = ( months - 1 ) / monthsPerPage + 1;
  int thismonth = 0;
  temp = start;
  for ( int page = 0; page < pages; ++page ) {
    if ( page > 0 ) {
      mPrinter->newPage();
    }
    QDate end( calsys->addMonths( start, monthsPerPage ) );
    end = calsys->addDays( end, -1 );
    QString stdate = locale->formatDate( start );
    QString endate = locale->formatDate( end );
    QString title;
    if ( orientation() == QPrinter::Landscape ) {
      title = i18nc( "date from - to", "%1 - %2", stdate, endate );
    } else {
      title = i18nc( "date from -\nto", "%1 -\n%2", stdate, endate );
    }
    drawHeader( p, title, calsys->addMonths( start, -1 ),
                calsys->addMonths( start, monthsPerPage ), headerBox );

    QRect monthesBox( headerBox );
    monthesBox.setTop( monthesBox.bottom() + padding() );
    monthesBox.setBottom( height );

    drawBox( p, BOX_BORDER_WIDTH, monthesBox );
    float monthwidth = float( monthesBox.width() ) / float( monthsPerPage );

    for ( int j=0; j<monthsPerPage; ++j ) {
      if ( ++thismonth > months ) {
        break;
      }
      int xstart = int( j * monthwidth + 0.5 );
      int xend = int( ( j + 1 ) * monthwidth + 0.5 );
      QRect monthBox( xstart, monthesBox.top(), xend - xstart, monthesBox.height() );
      drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents );

      temp = calsys->addMonths( temp, 1 );
    }
    start = calsys->addMonths( start, monthsPerPage );
  }
}