-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyScrollView.h
107 lines (83 loc) · 3.2 KB
/
MyScrollView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by Niccolò Caselli on 14/06/23.
//
#ifndef ACTIVITYJOURNAL_MYSCROLLVIEW_H
#define ACTIVITYJOURNAL_MYSCROLLVIEW_H
#include <wx/scrolwin.h>
#include <wx/wx.h>
#include "Utils.h"
#include "ActivityManager.h"
#include "Observer.h"
class MyScrollView : public wxScrolledWindow, public Observer {
public:
MyScrollView(wxWindow* parent,wxPoint pos,wxSize size, ActivityManager* activityManager, Form* subject):
subject(subject), wxScrolledWindow(parent, wxID_ANY, pos),
activityManager(activityManager), size(size), pos(pos){
// Registra l'observer
subject->registerObserver(this);
// GARFICA
drawActivities();
}
/**
* Disegna le attività del giorno selezionato
*/
void drawActivities() {
if (sizer != nullptr){
sizer->Clear(true);
std::cout << "Cleared sizer" << std::endl;
}
sizer = new wxBoxSizer(wxVERTICAL);
for (auto activity : shownActivities){
auto textPanel = new wxPanel(this, wxID_ANY);
textPanel->SetBackgroundColour("#02758c");
std::string timeString;
if(Utils::formatTime(activity->getStartTime()) == Utils::formatTime(activity->getEndTime()))
timeString = Utils::formatTime(activity->getStartTime());
else timeString = Utils::formatTime(activity->getStartTime()) + " - " + Utils::formatTime(activity->getEndTime());
auto timeText= new wxStaticText(textPanel, wxID_ANY, wxString(timeString), wxPoint(0,0));
auto timeFont = timeText->GetFont();
timeFont.SetPointSize(10);
timeText->SetFont(timeFont);
wxStaticText* text = new wxStaticText(textPanel, wxID_ANY, wxString(activity->getDescription()),wxPoint(0,30));
auto textFont = text->GetFont();
textFont.SetPointSize(15);
text->SetFont(textFont);
sizer->Add(textPanel, 0, wxALL, wxBorder(6));
}
SetSizer(sizer);
SetSize(size);
SetVirtualSize(size.GetWidth() ,10000);
SetScrollRate(10, 10);
EnableScrolling(true, true);
}
~MyScrollView() {
subject->removeObserver( this );
}
void update() override {
std::cout << "Observer updated" << std::endl;
// Recupera la data del giorno di cui mostrare le attività
auto date = subject->getSearchDate();
// Recupera le attività da mostrare
fetchActivitiesToShow(date);
// Disegna le attività
drawActivities();
}
private:
ActivityManager* activityManager;
Form* subject;
std::list<Activity*> shownActivities;
wxBoxSizer* sizer;
wxSize size;
wxPoint pos;
/**
* Metodo che recupera le attività da mostrare del giorno sceleto
*/
void fetchActivitiesToShow(std::time_t date) {
std::cout << "Showing activities in: " << std::asctime(std::localtime(&date)) << std::endl;
shownActivities = activityManager->getActivitiesByDate(*std::localtime(&date));
for (auto activity : shownActivities){
std::cout << "description: "<< activity->getDescription() << std::endl;
}
}
};
#endif //ACTIVITYJOURNAL_MYSCROLLVIEW_H