CalendarWidget::CalendarWidget(QWidget *parent) : QWidget(parent) { QDate currentDate = QDate::currentDate(); Ct::Date::PersianDate::GregorianToJalali(currentDate, realCurrent_j_y, realCurrent_j_m, realCurrent_j_d); active_j_y = realCurrent_j_y; active_j_m = realCurrent_j_m; int hUnit = this->width() / 7; int vUnit = this->height() / 7; btnPrevMonth = new QPushButton(this); btnPrevMonth->setIcon(QIcon(":/res/1rightarrow.png")); btnPrevMonth->setToolTip(u("ماه قبل")); btnPrevMonth->setGeometry(this->width() - hUnit / 2, 0, hUnit / 2, vUnit); int iconDimension = qMin(btnPrevMonth->width(), btnPrevMonth->height()) - 4; btnPrevMonth->setIconSize(QSize(iconDimension, iconDimension)); connect(btnPrevMonth, SIGNAL(clicked()), this, SLOT(prevMonth())); btnNextMonth = new QPushButton(this); btnNextMonth->setIcon(QIcon(":/res/1leftarrow.png")); btnNextMonth->setToolTip(u("ماه بعد")); btnNextMonth->setGeometry(0, 0, hUnit / 2, vUnit); btnNextMonth->setIconSize(QSize(iconDimension, iconDimension)); connect(btnNextMonth, SIGNAL(clicked()), this, SLOT(nextMonth())); //a `resizeEvent` is automatically generated which draws the month. }
void WCalendar::create() { selectionMode_ = SelectionMode::Single; singleClickSelect_ = false; horizontalHeaderFormat_ = CalendarHeaderFormat::ShortDayNames; firstDayOfWeek_ = 1; WDate currentDay = WDate::currentDate(); currentYear_ = currentDay.year(); currentMonth_ = currentDay.month(); WStringStream text; text << "<table class=\"days ${table-class}\" cellspacing=\"0\" cellpadding=\"0\">" """<tr>" "" "<th class=\"caption\">${nav-prev}</th>" "" "<th class=\"caption\"colspan=\"5\">${month} ${year}</th>" "" "<th class=\"caption\">${nav-next}</th>" """</tr>" """<tr>"; for (int j = 0; j < 7; ++j) text << "<th title=\"${t" << j << "}\" scope=\"col\">${d" << j << "}</th>"; text << "</tr>"; for (int i = 0; i < 6; ++i) { text << "<tr>"; for (int j = 0; j < 7; ++j) text << "<td>${c" << (i * 7 + j) << "}</td>"; text << "</tr>"; } text << "</table>"; std::unique_ptr<WTemplate> t(new WTemplate()); impl_ = t.get(); setImplementation(std::move(t)); impl_->setTemplateText(WString::fromUTF8(text.str()), TextFormat::UnsafeXHTML); impl_->setStyleClass("Wt-cal"); setSelectable(false); std::unique_ptr<WText> prevMonth(new WText(tr("Wt.WCalendar.PrevMonth"))); prevMonth->setStyleClass("Wt-cal-navbutton"); prevMonth->clicked().connect(this, &WCalendar::browseToPreviousMonth); std::unique_ptr<WText> nextMonth(new WText(tr("Wt.WCalendar.NextMonth"))); nextMonth->setStyleClass("Wt-cal-navbutton"); nextMonth->clicked().connect(this, &WCalendar::browseToNextMonth); std::unique_ptr<WComboBox> monthEdit(new WComboBox()); monthEdit_ = monthEdit.get(); monthEdit->setInline(true); for (unsigned i = 0; i < 12; ++i) monthEdit->addItem(WDate::longMonthName(i+1)); monthEdit->activated().connect(this, &WCalendar::monthChanged); monthEdit->setDisabled(!WApplication::instance()->environment().ajax()); std::unique_ptr<WInPlaceEdit> yearEdit(new WInPlaceEdit("")); yearEdit_ = yearEdit.get(); yearEdit->setButtonsEnabled(false); yearEdit->lineEdit()->setTextSize(4); yearEdit->setStyleClass("Wt-cal-year"); yearEdit->valueChanged().connect(this, &WCalendar::yearChanged); impl_->bindWidget("nav-prev", std::move(prevMonth)); impl_->bindWidget("nav-next", std::move(nextMonth)); impl_->bindWidget("month", std::move(monthEdit)); impl_->bindWidget("year", std::move(yearEdit)); setHorizontalHeaderFormat(horizontalHeaderFormat_); setFirstDayOfWeek(firstDayOfWeek_); }