void KDateTable::paintCell(QPainter *painter, int row, int col) { QRect rect; QString text; QPen pen; int w=cellWidth(); int h=cellHeight(); int pos; QBrush brushBlue(blue); QBrush brushLightblue(lightGray); QFont font=KGlobalSettings::generalFont(); // ----- font.setPointSize(fontsize); if(row==0) { // we are drawing the headline font.setBold(true); painter->setFont(font); bool normalday = true; QString daystr; if (KGlobal::locale()->weekStartsMonday()) { daystr = KGlobal::locale()->weekDayName(col+1, true); if (col == 5 || col == 6) normalday = false; } else { daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); if (col == 0 || col == 6) normalday = false; } if (!normalday) { painter->setPen(lightGray); painter->setBrush(brushLightblue); painter->drawRect(0, 0, w, h); painter->setPen(blue); } else { painter->setPen(blue); painter->setBrush(brushBlue); painter->drawRect(0, 0, w, h); painter->setPen(white); } painter->drawText(0, 0, w, h-1, AlignCenter, daystr, -1, &rect); painter->setPen(black); painter->moveTo(0, h-1); painter->lineTo(w-1, h-1); // ----- draw the weekday: } else { painter->setFont(font); pos=7*(row-1)+col; if (KGlobal::locale()->weekStartsMonday()) pos++; if(pos<firstday || (firstday+numdays<=pos)) { // we are either // ° painting a day of the previous month or // ° painting a day of the following month if(pos<firstday) { // previous month text.setNum(numDaysPrevMonth+pos-firstday+1); } else { // following month text.setNum(pos-firstday-numdays+1); } painter->setPen(gray); } else { // paint a day of the current month text.setNum(pos-firstday+1); painter->setPen(black); } pen=painter->pen(); if(firstday+date.day()-1==pos) { if(hasFocus()) { // draw the currently selected date painter->setPen(red); painter->setBrush(darkRed); pen=white; } else { painter->setPen(darkGray); painter->setBrush(darkGray); pen=white; } } else { painter->setBrush(lightGray); painter->setPen(lightGray); } painter->drawRect(0, 0, w, h); painter->setPen(pen); painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); } if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); }
void kMyMoneyDateTbl::paintCell(QPainter *painter, int row, int col) { QRect rect; QString text; QPen pen; int w=cellWidth(); int h=cellHeight(); QBrush brushBlue(KGlobalSettings::activeTitleColor()); QBrush brushLightblue(KGlobalSettings::baseColor()); QFont font=KGlobalSettings::generalFont(); // ----- font.setPointSize(fontsize); #if KDE_VERSION < 310 int firstWeekDay = KGlobal::locale()->weekStartsMonday() ? 1 : 0; #else int firstWeekDay = KGlobal::locale()->weekStartDay(); #endif if (row==0) { // we are drawing the headline if (m_type == MONTHLY) { font.setBold(true); painter->setFont(font); bool normalday = true; QString daystr; if ( col+firstWeekDay < 8 ) daystr = WEEK_DAY_NAME(col+firstWeekDay, true); else daystr = WEEK_DAY_NAME(col+firstWeekDay-7, true); if ( daystr==i18n("Sunday", "Sun") || daystr==i18n("Saturday", "Sat") ) normalday=false; if (!normalday) { painter->setPen(KGlobalSettings::baseColor()); painter->setBrush(brushLightblue); painter->drawRect(0, 0, w, h); painter->setPen(KGlobalSettings::activeTitleColor()); } else { painter->setPen(KGlobalSettings::activeTitleColor()); painter->setBrush(brushBlue); painter->drawRect(0, 0, w, h); painter->setPen(KGlobalSettings::activeTextColor()); } painter->drawText(0, 0, w, h-1, AlignCenter, daystr, -1, &rect); painter->setPen(KGlobalSettings::textColor()); painter->moveTo(0, h-1); painter->lineTo(w-1, h-1); if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); } else if (m_type == WEEKLY) { painter->setPen(KGlobalSettings::activeTitleColor()); painter->setBrush(brushBlue); painter->drawRect(0, 0, w, h); painter->setPen(KGlobalSettings::activeTextColor()); int year=date.year(); QString headerText; #if QT_VERSION > 0x030005 // FIXME: Shouldn't that be i18n()'ed as well QString weekStr = QString::number(date.weekNumber(&year)); QString yearStr = QString::number(year); headerText = i18n("Week %1 for year %2.") .arg(weekStr) .arg(yearStr); #else // FIXME: include code to display the same as for KDE >= 3.0.5 QString weekStr = QString::number(weekNumber(date, &year)); QString yearStr = QString::number(year); headerText = i18n("Week %1 for year %2.") .arg(weekStr) .arg(yearStr); #endif painter->drawText(0, 0, w, h-1, AlignCenter, headerText, -1, &rect); maxCell.setWidth(width()); if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); } else if (m_type == QUARTERLY) { int athird = width()/3; painter->setPen(KGlobalSettings::activeTitleColor()); painter->setBrush(brushBlue); painter->setPen(/*KGlobalSettings::activeTextColor()*/black); if (col == 0) { painter->drawRect(0, 0, athird, h); painter->drawText(0, 0, athird, h-1, AlignCenter, "Month 1", -1, &rect); painter->drawRect(athird, 0, athird, h); painter->drawText(athird, 0, athird, h-1, AlignCenter, "Month 2", -1, &rect); painter->drawRect(athird*2, 0, athird, h); painter->drawText(athird*2, 0, athird, h-1, AlignCenter, "Month 3", -1, &rect); } } } else { int pos; QDate drawDate(date); if (m_type == MONTHLY) { pos=7*(row-1)+col; if ( firstWeekDay < 4 ) pos += firstWeekDay; else pos += firstWeekDay - 7; if (pos<firstday || (firstday+numdays<=pos)) { // we are either // painting a day of the previous month or // painting a day of the following month if (pos<firstday) { // previous month drawDate = drawDate.addMonths(-1); text.setNum(numDaysPrevMonth+pos-firstday+1); drawDate.setYMD(drawDate.year(), drawDate.month(), text.toInt()); } else { // following month drawDate = drawDate.addMonths(1); text.setNum(pos-firstday-numdays+1); drawDate.setYMD(drawDate.year(), drawDate.month(), text.toInt()); } } else { // paint a day of the current month text.setNum(pos-firstday+1); drawDate.setYMD(drawDate.year(), drawDate.month(), text.toInt()); } } else if (m_type == WEEKLY) { // TODO: Handle other start weekdays than Monday text = QDate::shortDayName(row); text += " "; int dayOfWeek = date.dayOfWeek(); int diff; if (row < dayOfWeek) { diff = -(dayOfWeek - row); } else { diff = row - dayOfWeek; } drawDate = date.addDays(diff); } else if (m_type == QUARTERLY) { } drawCellContents(painter, row, col, drawDate); } }