⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 2007-2007 Trolltech ASA. All rights reserved.**** This file is part of the example classes of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <QtGui>#include "window.h"Window::Window(){    createPreviewGroupBox();    createGeneralOptionsGroupBox();    createDatesGroupBox();    createTextFormatsGroupBox();    QGridLayout *layout = new QGridLayout;    layout->addWidget(previewGroupBox, 0, 0);    layout->addWidget(generalOptionsGroupBox, 0, 1);    layout->addWidget(datesGroupBox, 1, 0);    layout->addWidget(textFormatsGroupBox, 1, 1);    layout->setSizeConstraint(QLayout::SetFixedSize);    setLayout(layout);    previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height());    previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width());    setWindowTitle(tr("Calendar Widget"));}void Window::localeChanged(int index){    calendar->setLocale(localeCombo->itemData(index).toLocale());}void Window::firstDayChanged(int index){    calendar->setFirstDayOfWeek(Qt::DayOfWeek(                                firstDayCombo->itemData(index).toInt()));}void Window::selectionModeChanged(int index){    calendar->setSelectionMode(QCalendarWidget::SelectionMode(                               selectionModeCombo->itemData(index).toInt()));}void Window::horizontalHeaderChanged(int index){    calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat(        horizontalHeaderCombo->itemData(index).toInt()));}void Window::verticalHeaderChanged(int index){    calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat(        verticalHeaderCombo->itemData(index).toInt()));}void Window::selectedDateChanged(){    currentDateEdit->setDate(calendar->selectedDate());}void Window::minimumDateChanged(const QDate &date){    calendar->setMinimumDate(date);    maximumDateEdit->setDate(calendar->maximumDate());}void Window::maximumDateChanged(const QDate &date){    calendar->setMaximumDate(date);    minimumDateEdit->setDate(calendar->minimumDate());}void Window::weekdayFormatChanged(){    QTextCharFormat format;    format.setForeground(qvariant_cast<QColor>(        weekdayColorCombo->itemData(weekdayColorCombo->currentIndex())));    calendar->setWeekdayTextFormat(Qt::Monday, format);    calendar->setWeekdayTextFormat(Qt::Tuesday, format);    calendar->setWeekdayTextFormat(Qt::Wednesday, format);    calendar->setWeekdayTextFormat(Qt::Thursday, format);    calendar->setWeekdayTextFormat(Qt::Friday, format);}void Window::weekendFormatChanged(){    QTextCharFormat format;    format.setForeground(qvariant_cast<QColor>(        weekendColorCombo->itemData(weekendColorCombo->currentIndex())));    calendar->setWeekdayTextFormat(Qt::Saturday, format);    calendar->setWeekdayTextFormat(Qt::Sunday, format);}void Window::reformatHeaders(){    QString text = headerTextFormatCombo->currentText();    QTextCharFormat format;    if (text == tr("Bold")) {        format.setFontWeight(QFont::Bold);    } else if (text == tr("Italic")) {        format.setFontItalic(true);    } else if (text == tr("Green")) {        format.setForeground(Qt::green);    }    calendar->setHeaderTextFormat(format);}void Window::reformatCalendarPage(){    QTextCharFormat mayFirstFormat;    if (mayFirstCheckBox->isChecked())        mayFirstFormat.setForeground(Qt::red);    QTextCharFormat firstFridayFormat;    if (firstFridayCheckBox->isChecked())        firstFridayFormat.setForeground(Qt::blue);    QDate date(calendar->yearShown(), calendar->monthShown(), 1);     calendar->setDateTextFormat(QDate(date.year(), 5, 1), mayFirstFormat);    date.setDate(date.year(), date.month(), 1);    while (date.dayOfWeek() != Qt::Friday)        date = date.addDays(1);    calendar->setDateTextFormat(date, firstFridayFormat);}void Window::createPreviewGroupBox(){    previewGroupBox = new QGroupBox(tr("Preview"));    calendar = new QCalendarWidget;    calendar->setMinimumDate(QDate(1900, 1, 1));    calendar->setMaximumDate(QDate(3000, 1, 1));    calendar->setGridVisible(true);    connect(calendar, SIGNAL(currentPageChanged(int, int)),            this, SLOT(reformatCalendarPage()));    previewLayout = new QGridLayout;    previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter);    previewGroupBox->setLayout(previewLayout);}void Window::createGeneralOptionsGroupBox(){    generalOptionsGroupBox = new QGroupBox(tr("General Options"));    localeCombo = new QComboBox;    int curLocaleIndex = -1;    int index = 0;    for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {        QLocale::Language lang = static_cast<QLocale::Language>(_lang);        QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);        for (int i = 0; i < countries.count(); ++i) {            QLocale::Country country = countries.at(i);            QString label = QLocale::languageToString(lang);            label += QLatin1Char('/');            label += QLocale::countryToString(country);            QLocale locale(lang, country);            if (this->locale().language() == lang && this->locale().country() == country)                curLocaleIndex = index;            localeCombo->addItem(label, locale);            ++index;        }    }    if (curLocaleIndex != -1)        localeCombo->setCurrentIndex(curLocaleIndex);    localeLabel = new QLabel(tr("&Locale"));    localeLabel->setBuddy(localeCombo);    firstDayCombo = new QComboBox;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -