Example #1
0
void MonthView::resetFormats() const
{
    if (dirtyModel) {
        dirtyModel = false;
        const_cast<MonthView*>(this)->setDateTextFormat(QDate(),QTextFormat().toCharFormat()); // clear formats
        for (int i = 0; i < model->rowCount(); ++i) {
            // get just the data needed for drawing.
            QDateTime f = model->data(model->index(i, QAppointmentModel::Start), Qt::EditRole).toDateTime();
            QDateTime t = model->data(model->index(i, QAppointmentModel::End), Qt::EditRole).toDateTime();
            bool isAllDay = model->data(model->index(i, QAppointmentModel::AllDay), Qt::EditRole).toBool();

            if (!foundNColor) {
                normalBgColor = palette().button().color();
                foundNColor = true;
            }

            for (QDate i = f.date(); i <= t.date(); i = i.addDays(1)) {
                // get item.
                QTextCharFormat fmt = dateTextFormat(i);
                bool set=false;

                if (isAllDay) {
                    fmt.setBackground(normalBgColor);
                    set = true;
                } else {
                    // Weed out things that end at midnight (e.g should be previous day)
                    if (t != QDateTime(t.date()) || i != t.date()) {
                        fmt.setFontWeight(QFont::Bold);
                        set = true;
                    }
                }

                if ( set )
                    const_cast<MonthView*>(this)->setDateTextFormat(i,fmt);
            }
        }
    }
}
Example #2
0
void CCalendarWidget::paintCell (QPainter *painter, const QRect &rect, const QDate &date) const
{
  QSize fsize = fontMetrics().size (Qt::TextSingleLine, "A");

  if (moon_mode)
     {
      int moon_day = moon_phase_by_algo (moon_phase_algo, date.year(), date.month(), date.day());

      bool has_image = true;

      if (moon_day == 0 || moon_day == 30 || moon_day == 1)
         has_image = false;

      //вычисляем ряд и колонку

      //правильно
      //int row = moon_day / 8;

      int cursorOffset = moon_day;

      int off = 0;
      int row = 0;

      while (cursorOffset >= (off + 8))
            {
             off += 7;
             row++;
            }

      int col = cursorOffset - off;

 //    qDebug() << "moon day: " << moon_day << "| date:" << date.toString("dd") << " | row = " << row << " col = " << col;

    //вычисляем, откуда копировать

      int pad = 3;

      int x = (col - 1) * 73 + (pad * col) - pad;
      int y = row * 73 + (pad * row);

      QRect r (x, y, 66, 73);

      QImage tile = moon_tiles.copy (r);

      QColor bg_color (Qt::black);

      painter->fillRect (rect, bg_color);


      if (has_image)
         {
          if (northern_hemisphere)
             painter->drawImage (rect.x(), rect.y(), tile);
          else
              painter->drawImage (rect.x(), rect.y(), tile.mirrored (true, false));
         }

      painter->setPen (QPen (Qt::yellow));

      QTextCharFormat tcf = dateTextFormat (date);
      if (tcf.fontStrikeOut())
          painter->setPen (QPen (Qt::magenta));
      else
      if (tcf.fontUnderline())
          painter->setPen (QPen (Qt::red));

      painter->drawText (QPoint (rect.x() + 5, rect.y() + fsize.height()), date.toString("dd") + " / " + QString::number (moon_day));

      if (selectedDate() == date)
         {
          QPen dpen (Qt::yellow);
          dpen.setWidth (5);
          painter->setPen (dpen);
          painter->drawRect (rect);
         }
    }
 else
     QCalendarWidget::paintCell (painter, rect, date);
}