M module-apps/application-calendar/models/MonthModel.cpp => module-apps/application-calendar/models/MonthModel.cpp +61 -4
@@ 3,10 3,11 @@
MonthModel::MonthModel(year_month_day ymd)
{
this->m = ymd.month();
- this->offset = weekday{ymd}.c_encoding();
this->y = ymd.year();
year_month_day_last ymdl = this->y / this->m / last;
- this->lastDay = ymdl.day();
+ this->lastDay = unsigned{ymdl.day()};
+ year_month_day ymdf = this->y / this->m / 1;
+ this->offset = weekday{ymdf}.c_encoding();
}
month MonthModel::getMonth()
@@ 14,12 15,68 @@ month MonthModel::getMonth()
return this->m;
}
-day MonthModel::getLastDay()
+uint32_t MonthModel::getLastDay()
{
return this->lastDay;
}
uint32_t MonthModel::getFirstWeekOffset()
{
- return this->offset;
+ if (this->offset == 0) {
+ return 7;
+ }
+ else {
+ return this->offset;
+ }
+}
+
+std::string MonthModel::getMonthYearText()
+{
+ int yearUInt = static_cast<decltype(yearUInt)>(y);
+ std::string yearStr = std::to_string(yearUInt);
+ std::string monthStr;
+ unsigned int monthUInt = unsigned{m};
+
+ switch (monthUInt) {
+ case 1:
+ monthStr = "January";
+ break;
+ case 2:
+ monthStr = "February";
+ break;
+ case 3:
+ monthStr = "March";
+ break;
+ case 4:
+ monthStr = "April";
+ break;
+ case 5:
+ monthStr = "May";
+ break;
+ case 6:
+ monthStr = "June";
+ break;
+ case 7:
+ monthStr = "July";
+ break;
+ case 8:
+ monthStr = "August";
+ break;
+ case 9:
+ monthStr = "September";
+ break;
+ case 10:
+ monthStr = "October";
+ break;
+ case 11:
+ monthStr = "November";
+ break;
+ case 12:
+ monthStr = "December";
+ break;
+ default:
+ monthStr = "";
+ }
+
+ return monthStr + " " + yearStr;
}
M module-apps/application-calendar/models/MonthModel.hpp => module-apps/application-calendar/models/MonthModel.hpp +3 -2
@@ 17,7 17,7 @@ class MonthModel
{
public:
month m;
- day lastDay;
+ unsigned int lastDay;
// first week offset
uint32_t offset;
year y;
@@ 29,6 29,7 @@ class MonthModel
year getYear();
month getMonth();
- day getLastDay();
+ uint32_t getLastDay();
uint32_t getFirstWeekOffset();
+ std::string getMonthYearText();
};
M module-apps/application-calendar/windows/CalendarMainWindow.cpp => module-apps/application-calendar/windows/CalendarMainWindow.cpp +9 -17
@@ 34,12 34,12 @@ namespace gui
this->activeItem = false;
}
else if (i >= style::window::calendar::week_days_number &&
- i <= style::window::calendar::week_days_number + firstWeekOffset) {
+ i < style::window::calendar::week_days_number + firstWeekOffset - 1) {
this->setPenWidth(style::window::default_border_no_focus_w);
this->activeItem = false;
}
else {
- std::string number = std::to_string(i - firstWeekOffset - style::window::calendar::week_days_number);
+ std::string number = std::to_string(i - firstWeekOffset - style::window::calendar::week_days_number + 2);
this->setText(number);
this->activeItem = true;
this->setFont(style::window::font::medium);
@@ 74,19 74,12 @@ namespace gui
grid.y = dayHeight;
uint32_t firstDayOffset = model->getFirstWeekOffset();
- day lastDay = model->getLastDay();
- uint32_t notActiveElements = style::window::calendar::week_days_number + firstDayOffset;
+ uint32_t lastDay = model->getLastDay();
+ uint32_t iterations = style::window::calendar::week_days_number + firstDayOffset + lastDay - 1;
+ LOG_DEBUG("OFFSET DAY: %u", firstDayOffset);
+ LOG_DEBUG("LAST DAY: %u", lastDay);
uint32_t i;
- for (i = 0; i < notActiveElements; ++i) {
- auto day = new DayLabel(app,
- this,
- i,
- firstDayOffset,
- style::window::calendar::day_cell_width,
- style::window::calendar::day_cell_height);
- addWidget(day);
- }
- for (day d = day(1); d <= lastDay; ++d, ++i) {
+ for (i = 0; i < iterations; ++i) {
auto day = new DayLabel(app,
this,
i,
@@ 111,8 104,7 @@ namespace gui
month->erase();
monthModel = std::make_unique<MonthModel>(actualDate);
- /// TODO: convert actual date to string
- std::string dateText = "March 2020";
+ std::string dateText = monthModel->getMonthYearText();
this->buildMonth(monthModel);
this->buildDateLabel(dateText);
}
@@ 232,7 224,7 @@ namespace gui
monthModel = std::make_unique<MonthModel>(actualDate);
this->buildMonth(monthModel);
- this->buildDateLabel(style::window::calendar::test::date_text_2);
+ this->buildDateLabel(monthModel->getMonthYearText());
bottomBar->setActive(gui::BottomBar::Side::CENTER, true);
bottomBar->setActive(gui::BottomBar::Side::RIGHT, true);