3 #include <Wt/WTemplate.h> 6 #include <Wt/WTableView.h> 7 #include <Wt/WAbstractItemModel.h> 8 #include <Wt/WPushButton.h> 9 #include <Wt/WStandardItemModel.h> 13 #include "MonthView.h" 16 #define COUT_(X) std::cout << __FILE__ << "::" << __LINE__ << " " << X << std::endl; 17 #define COUT_LINE COUT_(""); 30 addStyleClass(
"divDayOfMonth" );
33 body()-> addNew<Wt::WTableView>();
35 m_tableView-> setHeaderHeight(0);
36 m_tableView-> setSelectionMode( Wt::SelectionMode::Single );
37 m_tableView-> setHeight(
"100px" );
38 m_tableView-> setOverflow( Wt::Overflow::Hidden, Wt::Orientation::Horizontal );
40 m_tableView-> clicked().connect( [=]( Wt::WModelIndex index, Wt::WMouseEvent event )
42 clicked().emit( event );
45 m_tableView-> doubleClicked().connect( [=]( Wt::WModelIndex index, Wt::WMouseEvent event )
47 doubleClicked().emit( event );
52 Wt::WTableView * tableView();
54 virtual void setDate(
const Wt::WDate & value );
56 Wt::WTableView * m_tableView;
62 Wt::WTableView * DayOfMonth::tableView()
67 void DayOfMonth::setDate(
const Wt::WDate & value )
69 Wtx::Web::Calendar::DayWidget::setDate( value );
72 auto datamodel = m_widget-> getModel( date(), {
"keyField",
"cfyField",
"timeStart",
"timeStop",
"note"} );
74 auto model = std::make_shared<Wt::WStandardItemModel>( datamodel-> rowCount(), 3 );
80 for(
int row=0; row < datamodel-> rowCount(); row++ )
86 auto keyField = Wt::asString( datamodel-> data( row, 2 ) );
87 auto cfyField = Wt::asString( datamodel-> data( row, 3 ) );
88 auto timeStart = Wt::WTime::fromString( Wt::asString( datamodel-> data( row, 4 ) ),
"hh:mm:ss" );
89 auto timeStop = Wt::WTime::fromString( Wt::asString( datamodel-> data( row, 5 ) ),
"hh:mm:ss" );
90 auto note = Wt::asString( datamodel-> data( row, 6 ) );
98 if( timeStart.isValid() )
100 Wt::WString format =
"hA";
101 if( timeStart.minute() != 0 )
104 timepart = timeStart.toString(format) +
" ";
111 model-> setData( row, 0, datamodel-> data( row, 0 ) );
112 model-> setData( row, 1, datamodel-> data( row, 1 ) );
113 model-> setData( row, 2, timepart + keyField );
120 Wt::WString(
"{1}\n{2}\n{3}\n{4}\n{5}")
121 .arg( value.toString() )
122 .arg( timeStart.toString() +
" " + timeStop.toString() )
125 .arg( note.toUTF8().substr(0,150) )
128 model-> setData( row, 2, toolTip, Wt::ItemDataRole::ToolTip );
132 m_tableView-> setModel( model );
134 m_tableView-> setColumnHidden(0,
true);
135 m_tableView-> setColumnHidden(1,
true);
144 addStyleClass(
"divTable" );
145 addStyleClass(
"blueTable" );
148 auto cwHeader = addNew<Wt::WContainerWidget>();
149 cwHeader-> addStyleClass(
"divTableHeading" );
151 auto cwRow = cwHeader-> addNew<Wt::WContainerWidget>();
152 cwRow-> addStyleClass(
"divTableRow" );
154 for(
int weekday = 0; weekday < 7; weekday++ )
156 auto cwDay = cwRow-> addNew<Wt::WContainerWidget>();
157 cwDay-> addStyleClass(
"divTableHead" );
159 cwDay-> addNew<Wt::WText>(
daynames().at(weekday) );
167 for(
int week = 0; week < 6; week++ )
169 auto cwWeek = addNew<Wt::WContainerWidget>();
170 cwWeek-> addStyleClass(
"divTableRow" );
176 for(
int day = 0; day < 7; day++ )
182 auto cwDay = cwWeek-> addNew<DayOfMonth>( (week*7)+day,
this );
184 cwDay-> clicked().connect( [=]()
186 if( cwDay-> tableView()-> selectedIndexes().size() == 1 )
188 m_itemClicked.emit( *cwDay-> tableView()-> selectedIndexes().begin() );
191 m_clicked.emit( cwDay-> date() );
195 cwDay-> doubleClicked().connect( [=]()
197 if( cwDay-> tableView()-> selectedIndexes().size() == 1 )
199 m_itemDoubleClicked.emit( *cwDay-> tableView()-> selectedIndexes().begin() );
202 m_doubleClicked.emit( cwDay-> date() );
210 m_dayWidgets.push_back( cwDay );
231 Wt::Signal<Wt::WDate> & Wtx::Web::Calendar::MonthView::clicked()
236 Wt::Signal<Wt::WDate> & Wtx::Web::Calendar::MonthView::doubleClicked()
238 return m_doubleClicked;
241 Wt::Signal<Wt::WModelIndex> & Wtx::Web::Calendar::MonthView::itemClicked()
243 return m_itemClicked;
246 Wt::Signal<Wt::WModelIndex> & Wtx::Web::Calendar::MonthView::itemDoubleClicked()
248 return m_itemDoubleClicked;
251 void Wtx::Web::Calendar::MonthView::updateView()
253 Wt::WDate first( selectedDate().year(), selectedDate().month(), 1 );
254 Wt::WDate start = first.addDays( first.dayOfWeek() * -1 );
256 int cellDate = first.dayOfWeek() * -1;
258 for(
auto cwDay : dayWidgets() )
260 cwDay-> removeStyleClass(
"divPreviousMonth" );
261 cwDay-> removeStyleClass(
"divNextMonth" );
262 cwDay-> removeStyleClass(
"divToday" );
263 cwDay-> day()-> removeStyleClass(
"divSelectedDate" );
265 cwDay-> setDate( start.addDays( cwDay-> index() ) );
272 if( cwDay-> date().month() < selectedDate().month() )
274 cwDay-> addStyleClass(
"divPreviousMonth",
true );
282 if( cwDay-> date().month() > selectedDate().month() )
284 cwDay-> addStyleClass(
"divNextMonth",
true );
292 if( cwDay-> date() == today() )
294 cwDay-> addStyleClass(
"divToday",
true );
302 if( cwDay-> date() == selectedDate() )
304 cwDay-> day()-> addStyleClass(
"divSelectedDate",
true );
311 void Wtx::Web::Calendar::MonthView::setSelectedDate(
const Wt::WDate & date )
313 Wtx::Web::Calendar::BaseView::setSelectedDate( date );
317 const Wt::WDate Wtx::Web::Calendar::MonthView::today()
const 319 return Wt::WDate::currentDate();
324 for(
auto dw : m_dayWidgets )
326 if( date == dw-> date() )
333 const std::vector< Wtx::Web::Calendar::DayWidget * > & Wtx::Web::Calendar::MonthView::dayWidgets()
const
const std::vector< std::string > & daynames()
Long Day Names.
MonthView(int firstDayOfWeek, Wtx::Web::Calendar::Widget *widget)