Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void MainWindow::insertCalendar (  )  [slot]

[5]

[1]

[1] //! [2]

[2] //! [3]

[3]

Definition at line 92 of file mainwindow.cpp.

References QDate::currentDate(), QWidget::cursor, QDate::daysInMonth(), QDate::month(), QTextCharFormat::setFontWeight(), QDate::shortDayName(), QTextEdit::textCursor(), and QDate::year().

Referenced by setFontSize(), setMonth(), and setYear().

{
    QTextCursor cursor(editor->textCursor());
    cursor.movePosition(QTextCursor::Start); 

    QTextCharFormat format(cursor.charFormat());
    format.setFontFamily("Courier");
    
    QTextCharFormat boldFormat = format;
    boldFormat.setFontWeight(QFont::Bold);

    cursor.insertBlock();
    cursor.insertText(" ", boldFormat);

    QDate date = QDate::currentDate();
    int year = date.year(), month = date.month();

    for (int weekDay = 1; weekDay <= 7; ++weekDay) {
        cursor.insertText(QString("%1 ").arg(QDate::shortDayName(weekDay), 3),
            boldFormat);
    }

    cursor.insertBlock();
    cursor.insertText(" ", format);

    for (int column = 1; column < QDate(year, month, 1).dayOfWeek(); ++column) {
        cursor.insertText("    ", format);
    }

    for (int day = 1; day <= date.daysInMonth(); ++day) {
        int weekDay = QDate(year, month, day).dayOfWeek();

        if (QDate(year, month, day) == date)
            cursor.insertText(QString("%1 ").arg(day, 3), boldFormat);
        else
            cursor.insertText(QString("%1 ").arg(day, 3), format);

        if (weekDay == 7) {
            cursor.insertBlock();
            cursor.insertText(" ", format);
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index