<commit_before>/****************************************************************************
**
** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Script Generator project on Qt Labs.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

function tr(s) { return s; }

function CalendarWidget(parent) { 
    QWidget.call(this, parent);

    this.createPreviewGroupBox();
    this.createGeneralOptionsGroupBox();
    this.createDatesGroupBox();
    this.createTextFormatsGroupBox();
    
    var layout = new QGridLayout();
    layout.addWidget(this.previewGroupBox, 0, 0);
    layout.addWidget(this.generalOptionsGroupBox, 0, 1);
    layout.addWidget(this.datesGroupBox, 1, 0);
    layout.addWidget(this.textFormatsGroupBox, 1, 1);
    layout.sizeConstraint = QLayout.SetFixedSize;
    this.setLayout(layout);
    
    this.previewLayout.setRowMinimumHeight(0, this.calendar.sizeHint.height());
    this.previewLayout.setColumnMinimumWidth(0, this.calendar.sizeHint.width());
    
    this.setWindowTitle(tr("Calendar Widget"));
}

CalendarWidget.prototype = new QWidget();

CalendarWidget.prototype.localeChanged = function(index) {
    this.calendar.setLocale(this.localeCombo.itemData(index));
}

CalendarWidget.prototype.firstDayChanged = function(index) {
    this.calendar.firstDayOfWeek = this.firstDayCombo.itemData(index);
}

CalendarWidget.prototype.selectionModeChanged = function(index) {
    this.calendar.selectionMode = this.selectionModeCombo.itemData(index);
}

CalendarWidget.prototype.horizontalHeaderChanged = function(index) {
    this.calendar.horizontalHeaderFormat = this.horizontalHeaderCombo.itemData(index);
}

CalendarWidget.prototype.verticalHeaderChanged = function(index) {
    this.calendar.verticalHeaderFormat = this.verticalHeaderCombo.itemData(index);
}

CalendarWidget.prototype.selectedDateChanged = function() {
    this.currentDateEdit.setDate(this.calendar.selectedDate);
}

CalendarWidget.prototype.minimumDateChanged = function(date) {
    this.calendar.minimumDate = date;
    this.maximumDateEdit.setDate(this.calendar.maximumDate);
}

CalendarWidget.prototype.maximumDateChanged = function(date) {
    this.calendar.setMaximumDate(date);
    this.minimumDateEdit.setDate(this.calendar.minimumDate);
}

CalendarWidget.prototype.weekdayFormatChanged = function() {
    var format = new QTextCharFormat();
    format.setForeground(new QBrush(this.weekdayColorCombo.itemData(this.weekdayColorCombo.currentIndex)));

    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Monday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Tuesday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Wednesday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Thursday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Friday, format);
}

CalendarWidget.prototype.weekendFormatChanged = function() {
    var format = new QTextCharFormat();
    format.setForeground(new QBrush(this.weekendColorCombo.itemData(this.weekendColorCombo.currentIndex)));
    
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Saturday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Sunday, format);
}

CalendarWidget.prototype.reformatHeaders = function() {
    var text = this.headerTextFormatCombo.currentText;
    var format = new QTextCharFormat();

    if (text == tr("Bold")) {
        format.setFontWeight(QFont.Bold);
    } else if (text == tr("Italic")) {
        format.setFontItalic(true);
    } else if (text == tr("Green")) {
        format.setForeground(new QBrush(new QColor(Qt.green)));
    }
    
    this.calendar.setHeaderTextFormat(format);
}

CalendarWidget.prototype.reformatCalendarPage = function() {
    var mayFirstFormat = new QTextCharFormat();
    if (this.mayFirstCheckBox.isChecked)
        mayFirstFormat.setForeground(new QBrush(new QColor(Qt.red)));

    var firstFridayFormat = new QTextCharFormat();
    if (this.firstFridayCheckBox.isChecked)
        firstFridayFormat.setForeground(new QBrush(new QColor(Qt.blue)));
    
    var date = new Date(this.calendar.yearShown(), this.calendar.monthShown(), 1); //fixme

    this.calendar.setDateTextFormat(new Date(date.year, 5, 1), mayFirstFormat);

    date.setDate(date.year, date.month, 1);
 //fixme
 //   while (date.dayOfWeek != Qt.Friday)
 //       date = date.addDays(1);
    this.calendar.setDateTextFormat(date, firstFridayFormat);
}

CalendarWidget.prototype.createPreviewGroupBox = function() {
    this.previewGroupBox = new QGroupBox(tr("Preview"));

    this.calendar = new QCalendarWidget();
    this.calendar.minimumDate = new Date(1900, 1, 1);
    this.calendar.maximumDate = new Date(3000, 1, 1);
    this.calendar.setGridVisible(true);

    this.calendar.currentPageChanged.connect(this, this.reformatCalendarPage);

    this.previewLayout = new QGridLayout();
    this.previewLayout.addWidget(this.calendar, 0, 0, Qt.AlignmentFlag.AlignCenter);
    this.previewGroupBox.setLayout(this.previewLayout);
}

CalendarWidget.prototype.createGeneralOptionsGroupBox = function() {
    this.generalOptionsGroupBox = new QGroupBox(tr("General Options"));
    
    this.localeCombo = new QComboBox();
    var curLocaleIndex = -1;
    var index = 0;

    

    for (var lang in QLocale.Language) {
        var countries = QLocale.countriesForLanguage(lang);
            
        for (var country in countries) {
            var label = QLocale.languageToString(lang);
            label += "/";
            label += QLocale.countryToString(country);
            var locale = new QLocale(lang, country);
            if (this.locale().language() == lang && this.locale().country() == country)
                curLocaleIndex = index;

            localeCombo.addItem(label, locale);
            ++index;
        }
    }

    if (curLocaleIndex != -1)
        localeCombo.setCurrentIndex(curLocaleIndex);
    this.localeLabel = new QLabel(tr("&Locale"));
    this.localeLabel.setBuddy(this.localeCombo);
    
    this.firstDayCombo = new QComboBox();
    this.firstDayCombo.addItem(null, tr("Sunday"), Qt.DayOfWeek.Sunday);
    this.firstDayCombo.addItem(null, tr("Monday"), Qt.DayOfWeek.Monday);
    this.firstDayCombo.addItem(null, tr("Tuesday"), Qt.DayOfWeek.Tuesday);
    this.firstDayCombo.addItem(null, tr("Wednesday"), Qt.DayOfWeek.Wednesday);
    this.firstDayCombo.addItem(null, tr("Thursday"), Qt.DayOfWeek.Thursday);<commit_msg>Fixed CalendarWidget example<commit_after>/****************************************************************************
**
** Copyright (C) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of the Qt Script Generator project on Qt Labs.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

function tr(s) { return s; }

function CalendarWidget(parent) { 
    QWidget.call(this, parent);

    this.createPreviewGroupBox();
    this.createGeneralOptionsGroupBox();
    this.createDatesGroupBox();
    this.createTextFormatsGroupBox();
    
    var layout = new QGridLayout();
    layout.addWidget(this.previewGroupBox, 0, 0);
    layout.addWidget(this.generalOptionsGroupBox, 0, 1);
    layout.addWidget(this.datesGroupBox, 1, 0);
    layout.addWidget(this.textFormatsGroupBox, 1, 1);
    layout.sizeConstraint = QLayout.SetFixedSize;
    this.setLayout(layout);
    
    this.previewLayout.setRowMinimumHeight(0, this.calendar.sizeHint.height());
    this.previewLayout.setColumnMinimumWidth(0, this.calendar.sizeHint.width());
    
    this.setWindowTitle(tr("Calendar Widget"));
}

CalendarWidget.prototype = new QWidget();

CalendarWidget.prototype.localeChanged = function(index) {
    this.calendar.locale = this.localeCombo.itemData(index);
}

CalendarWidget.prototype.firstDayChanged = function(index) {
    this.calendar.firstDayOfWeek = this.firstDayCombo.itemData(index);
}

CalendarWidget.prototype.selectionModeChanged = function(index) {
    this.calendar.selectionMode = this.selectionModeCombo.itemData(index);
}

CalendarWidget.prototype.horizontalHeaderChanged = function(index) {
    this.calendar.horizontalHeaderFormat = this.horizontalHeaderCombo.itemData(index);
}

CalendarWidget.prototype.verticalHeaderChanged = function(index) {
    this.calendar.verticalHeaderFormat = this.verticalHeaderCombo.itemData(index);
}

CalendarWidget.prototype.selectedDateChanged = function() {
    this.currentDateEdit.setDate(this.calendar.selectedDate);
}

CalendarWidget.prototype.minimumDateChanged = function(date) {
    this.calendar.minimumDate = date;
    this.maximumDateEdit.setDate(this.calendar.maximumDate);
}

CalendarWidget.prototype.maximumDateChanged = function(date) {
    this.calendar.maximumDate = date;
    this.minimumDateEdit.setDate(this.calendar.minimumDate);
}

CalendarWidget.prototype.weekdayFormatChanged = function() {
    var format = new QTextCharFormat();
    format.setForeground(new QBrush(this.weekdayColorCombo.itemData(this.weekdayColorCombo.currentIndex)));

    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Monday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Tuesday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Wednesday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Thursday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Friday, format);
}

CalendarWidget.prototype.weekendFormatChanged = function() {
    var format = new QTextCharFormat();
    format.setForeground(new QBrush(this.weekendColorCombo.itemData(this.weekendColorCombo.currentIndex)));
    
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Saturday, format);
    this.calendar.setWeekdayTextFormat(Qt.DayOfWeek.Sunday, format);
}

CalendarWidget.prototype.reformatHeaders = function() {
    var text = this.headerTextFormatCombo.currentText;
    var format = new QTextCharFormat();

    if (text == tr("Bold")) {
        format.setFontWeight(QFont.Bold);
    } else if (text == tr("Italic")) {
        format.setFontItalic(true);
    } else if (text == tr("Green")) {
        format.setForeground(new QBrush(new QColor(Qt.green)));
    }
    
    this.calendar.setHeaderTextFormat(format);
}

CalendarWidget.prototype.reformatCalendarPage = function() {
    var mayFirstFormat = new QTextCharFormat();
    if (this.mayFirstCheckBox.isChecked)
        mayFirstFormat.setForeground(new QBrush(new QColor(Qt.red)));

    var firstFridayFormat = new QTextCharFormat();
    if (this.firstFridayCheckBox.isChecked)
        firstFridayFormat.setForeground(new QBrush(new QColor(Qt.blue)));
    
    var date = new Date(this.calendar.yearShown(), this.calendar.monthShown(), 1); //fixme

    this.calendar.setDateTextFormat(new Date(date.year, 5, 1), mayFirstFormat);

    date.setDate(date.year, date.month, 1);
 //fixme
 //   while (date.dayOfWeek != Qt.Friday)
 //       date = date.addDays(1);
    this.calendar.setDateTextFormat(date, firstFridayFormat);
}

CalendarWidget.prototype.createPreviewGroupBox = function() {
    this.previewGroupBox = new QGroupBox(tr("Preview"));

    this.calendar = new QCalendarWidget();
    this.calendar.minimumDate = new Date(1900, 1, 1);
    this.calendar.maximumDate = new Date(3000, 1, 1);
    this.calendar.setGridVisible(true);

    this.calendar.currentPageChanged.connect(this, this.reformatCalendarPage);

    this.previewLayout = new QGridLayout();
    this.previewLayout.addWidget(this.calendar, 0, 0, Qt.AlignmentFlag.AlignCenter);
    this.previewGroupBox.setLayout(this.previewLayout);
}

CalendarWidget.prototype.createGeneralOptionsGroupBox = function() {
    this.generalOptionsGroupBox = new QGroupBox(tr("General Options"));
    
    this.localeCombo = new QComboBox();
    var curLocaleIndex = -1;
    var index = 0;

    for (var i = 0; i <= QLocale.Ugaritic; ++i) {
        var lang = QLocale.Language(i);
        var countries = QLocale.countriesForLanguage(lang);
        for (var country in countries) {
            var label = QLocale.languageToString(lang);
            label += "/";
            label += QLocale.countryToString(QLocale.Country(country));
            var locale = new QLocale(lang, country);
            if (this.locale.language() == lang && this.locale.country() == country)
                curLocaleIndex = index;
            this.localeCombo.addItem(label, locale);
            ++index;
        }
    }

    if (curLocaleIndex != -1)
        this.localeCombo.setCurrentIndex(curLocaleIndex);
    this.localeLabel = new QLabel(tr("&Locale"));
    this.localeLabel.setBuddy(this.localeCombo);
    
    this.firstDayCombo = new QComboBox();
    this.firstDayCombo.addItem(null, tr("Sunday"), Qt.DayOfWeek.Sunday);
    this.firstDayCombo.addItem(null, tr("Monday"), Qt.DayOfWeek.Monday);
    this.firstDayCombo.addItem(null, tr("Tuesday"), Qt.DayOfWeek.Tuesday);
    this.firstDayCombo.addItem(null, tr("Wednesday"), Qt.DayOfWeek.Wednesday);
    this.firstDayCombo.addItem(null, tr("Thursday"), Qt.DayOfWeek.Thursday);
{'fraction_non_alphanumeric': 0.1367037543106253, 'fraction_numerical': 0.006311406077168326, 'mean_word_length': 4.379768988449422, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4792568', 'n_tokens_mistral': 4599, 'n_tokens_neox': 4380, 'n_words': 910}