#include "stdafx.h"
#include "Calendar.h"
#include <QIcon>
#include <QCheckBox>
#include <QComboBox>
#include <QDate>
#include <QDateEdit>
#include <QGroupBox>
#include <QGridLayout>
#include <QLabel>
#include <QCalendarWidget>
#include <QList>
#include <QTextCharFormat>
#include <Clock.h>
#include <QPushButton>
#include <QToolButton>
#include "SettingButton.h"
#include <QMessageBox>
#include <QAction>
//.._Calendar类实现
/* 构造函数实现 */
_Calendar::_Calendar(QWidget * parent)
{
_CreatePreviewGroupBox();
_CreateGeneralOptionGroupBox();
_CreateDatesGroupBox();
_CreateTextFormatGroupBox();
QGridLayout* _MainLayout = new QGridLayout;
_MainLayout->addWidget(m_PreviewGroupBox, 0, 0);
_MainLayout->addWidget(m_GeneralOptionsGroupBox, 0, 1);
_MainLayout->addWidget(m_DatesGroupBox, 1, 0);
_MainLayout->addWidget(m_TextFormatsGroupBox, 1, 1);
_MainLayout->setSizeConstraint(QLayout::SetFixedSize);
m_PreviewLayout->setRowMinimumHeight(
0, m_Calendar->sizeHint().height());
m_PreviewLayout->setColumnMinimumWidth(
0, m_Calendar->sizeHint().width());
m_Today = QDate(m_Calendar->selectedDate());
setLayout(_MainLayout);
setWindowTitle(tr("Domino Calendar"));
setWindowIcon(QIcon(":/Images/Icon.ico"));
_ReadSettings();
}
/////////////////////////////////////////////////////////////////
//..protected部分
/* _CreatePreviewGroupBox()函数实现 */
void _Calendar::_CreatePreviewGroupBox()
{
m_PreviewGroupBox = new QGroupBox(tr("日历"));
m_Calendar = new QCalendarWidget;
m_Calendar->setMinimumDate(QDate(1900, 1, 1));
m_Calendar->setMaximumDate(QDate(3000, 1, 1));
m_Calendar->setGridVisible(true);
connect(m_Calendar, SIGNAL(currentPageChanged(int, int)),
this, SLOT(_ReformatCalendarPage()));
m_ReturnToday = new _DIYButton;
m_ReturnToday->setIcon(QIcon(":/Images/ShowToday.ico"));
m_ReturnToday->setToolTip(tr("m_ReturnToday"));
connect(m_ReturnToday, SIGNAL(clicked()),
this, SLOT(_ReturnToday()));
m_ShowClock = new _DIYButton;
m_ShowClock->setIcon(QIcon(":/Images/Clock.ico"));
m_ShowClock->setToolTip(tr("m_ShowClock"));
connect(m_ShowClock, SIGNAL(clicked()),
this, SLOT(_ShowClockButtonClicked()));
m_ConfigureButton = new _DIYButton;
m_ConfigureButton->setText(tr("configure"));
m_ConfigureButton->setIcon(QIcon(":/Images/Configure.ico"));
m_ConfigureButton->setToolTip(tr("m_ConfigureButton"));
connect(m_ConfigureButton, SIGNAL(clicked()),
this, SLOT(_ConfigureButtonClicked()));
m_AboutButton = new _DIYButton;
m_AboutButton->setIcon(QIcon(":/Images/Help.ico"));
m_AboutButton->setToolTip(tr("m_AboutButton"));
m_TimeZoneLabel = new QLabel(tr("m_TimeZoneLabel"));
m_TimeZoneButton = new _DIYButton;
m_TimeZoneButton->setIcon(QIcon(":/Images/flag-cn.ico"));
connect(m_AboutButton, SIGNAL(clicked()),
this, SLOT(_AboutButtonClicked()));
#if 0
// TODO: Context Menu
m_ReturnTodayAction = new QAction(tr("回到今天"), this);
m_ReturnTodayAction->setIcon(QIcon(":/Images/ShowToday.ico"));
m_ReturnTodayAction->setShortcut(tr("F9"));
m_ShowClockAction = new QAction(tr("显示时钟"), this);
m_ShowClockAction->setIcon(QIcon(":/Images/Clock.ico"));
m_ShowClockAction->setShortcut(tr("F10"));
m_ConfigureButtonAction = new QAction(tr("设置"), this);
m_ConfigureButtonAction->setIcon(QIcon(":/Images/Configure.ico"));
m_ConfigureButtonAction->setShortcut(tr("Ctrl+G"));
connect(m_ReturnTodayAction, SIGNAL(triggered()),
this, SLOT(_ReturnToday()));
connect(m_ShowClockAction, SIGNAL(triggered()),
SLOT(_ShowClockButtonClicked()));
connect(m_ConfigureButtonAction, SIGNAL(clicked()),
this, SLOT(_ConfigureButtonClicked()));
#endif
/////////////////////////////////////////////////////////////
m_PreviewLayout = new QGridLayout;
m_PreviewLayout->addWidget(m_Calendar, 0, 0, Qt::AlignCenter);
QHBoxLayout* _ShowLayout = new QHBoxLayout;
_ShowLayout->addWidget(m_TimeZoneLabel);
_ShowLayout->addWidget(m_TimeZoneButton);
_ShowLayout->addStretch();
_ShowLayout->addWidget(m_ReturnToday);
_ShowLayout->addWidget(m_ShowClock);
_ShowLayout->addWidget(m_ConfigureButton);
_ShowLayout->addWidget(m_AboutButton);
QVBoxLayout* _MainLayout = new QVBoxLayout;
_MainLayout->addLayout(m_PreviewLayout);
_MainLayout->addLayout(_ShowLayout);
m_PreviewGroupBox->setLayout(_MainLayout);
}
/* _CreateGeneralOptionsGroupBox()函数实现 */
void _Calendar::_CreateGeneralOptionGroupBox()
{
m_GeneralOptionsGroupBox = new QGroupBox(tr("常规选项"));
//..创建并设置m_LocaleComboBox和m_LocaleLabel
m_LocaleComboBox = 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;
m_LocaleComboBox->addItem(_Label, _Locale);
++_Index;
}
}
if (_CurLocaleIndex != -1)
m_LocaleComboBox->setCurrentIndex(_CurLocaleIndex);
m_LocaleLabel = new QLabel(tr("m_LocaleLabel"));
m_LocaleLabel->setBuddy(m_LocaleComboBox);
connect(m_LocaleComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(_LocaleChanged(int)));
/////////////////////////////////////////////////////////////
//..创建并设置m_SelectionModeLabel和m_SelectionModeLabel
m_SelectionModeComboBox = new QComboBox;
m_SelectionModeComboBox->addItem(tr("m_SelectionModeComboBox"),
QCalendarWidget::SingleSelection);
m_SelectionModeComboBox->addItem(tr("m_SelectionModeComboBox"),
QCalendarWidget::NoSelection);
m_SelectionModeLabel = new QLabel(tr("m_SelectionModeLabel"));
m_SelectionModeLabel->setBuddy(m_SelectionModeComboBox);
connect(m_SelectionModeComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(_SelectionModeChanged(int)));
/////////////////////////////////////////////////////////////
//..创建并设置m_GridCheckBox和m_NavigationBarCheckBar
m_GridCheckBox = new QCheckBox(tr("m_GridCheckBox"));
m_GridCheckBox->setChecked(true);
connect(m_GridCheckBox, SIGNAL(toggled(bool)),
m_Calendar, SLOT(setGridVisible(bool)));
m_NavigationBarCheckBox = new QCheckBox(tr("m_NavigationBarCheckBox"));
m_NavigationBarCheckBox->setChecked(true);
connect(m_NavigationBarCheckBox, SIGNAL(toggled(bool)),
m_Calendar, SLOT(setNavigationBarVisible(bool)));
/////////////////////////////////////////////////////////////
//..创建并设置m_HorizontalHeaderComboBox和m_HorizontalHeaderLabel
m_HorizontalHeaderComboBox = new QComboBox;
m_HorizontalHeaderComboBox->addItem(QStringLiteral("jianxie"),
QCalendarWidget::SingleLetterDayNames);
m_HorizontalHeaderComboBox->addItem(QStringLiteral("wanzheng"),
QCalendarWidget::ShortDayNames);
m_HorizontalHeaderComboBox->addItem(QStringLiteral("yincang"),
QCalendarWidget::NoHorizontalHeader);
m_HorizontalHeaderComboBox->setCurrentIndex(1);
m_HorizontalHeaderLabel = new QLabel(QStringLiteral("h tou"));
m_HorizontalHeaderLabel->setBuddy(m_HorizontalHeaderComboBox);
connect(m_HorizontalHeaderComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(_HorizontalHeaderChanged(int)));
/////////////////////////////////////////////////////////////
//..创建并设置m_VerticalHeaderComboBox和m_VerticalHeaderLabel
m_VerticalHeaderComboBox = new QComboBox;
m_VerticalHeaderComboBox->addItem(QStringLiteral("show"),
QCalendarWidget::ISOWeekNumbers);
m_VerticalHeaderComboBox->addItem(QStri