-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoursecontroller.cpp
More file actions
119 lines (104 loc) · 3.54 KB
/
coursecontroller.cpp
File metadata and controls
119 lines (104 loc) · 3.54 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
#include <qlabel.h>
#include <qpushbutton.h>
#include "coursecontroller.h"
#include "course.h"
// The constructor is the only way to set the private variables.
// Here we also connect the controller to 3 signals that the course emits.
// The signalling is one-way: the controller emits nothing. It calls
// methods directly on the course.
CourseController::CourseController(Course *Icourse, int Isemester,
QWidget* parent, Qt::WindowFlags fl) :
QWidget(parent, fl) {
setupUi(this);
setAutoFillBackground(true);
backgr = palette().color(QPalette::Window);
course = Icourse;
semester = Isemester;
preffered = false;
selected = false;
sync();
connect( course, SIGNAL(pref_changed(int)), SLOT(prefChangeRequested(int)) );
connect( course, SIGNAL(selected(int)), SLOT(courseSelected(int)) );
connect( course, SIGNAL(deselected()), SLOT(courseDeselected()) );
}
// <sync> does the initialization of internal widgets.
void CourseController::sync() {
courseNumber->setText( course->getNumber() );
courseTitle->setText( course->getTitle() );
}
void CourseController::selectSelf() {
selected = true;
auto pal = palette();
pal.setColor(QPalette::Background, Qt::green);
setPalette(pal);
emit used( course->getNumber(), course->getHours() );
}
void CourseController::deselectSelf() {
selected = false;
auto pal = palette();
pal.setColor(QPalette::Background, backgr);
setPalette(pal);;
emit unused( course->getNumber(), course->getHours() );
}
// This one is connected with the button that selects
// the course without selecting its dependencies.
void CourseController::selectionForced() {
course->select(semester);
}
// Connected with the button that selects the course and its dependencies
void CourseController::selectionRequested() {
//We need to recurse over dependencies now.
course->select(semester, course);
}
// Connected with the button that deselects the course even if it supplies a
// dependency.
void CourseController::deselectionForced() {
course->deselect();
}
// Connected with the button that requests to remove the course only if it
// does not supply a dependency.
void CourseController::deselectionRequested() {
course->deselect(course);
}
// Traps the signal from the course and decides if its relevant
// to the controller. If it is, lights the controller.
void CourseController::courseSelected(int sem) {
// sem = 0 means 'use default'.
if ((sem == semester) || (!sem && preffered)) {
if ( ! selected ) {
selectSelf();
}
} else {
if ( selected ) {
deselectSelf();
}
}
}
// Traps the signal from the course, and dimms the controller.
void CourseController::courseDeselected() {
if ( selected ) {
deselectSelf();
}
}
// Used by the dependency selection button and others. It is used to
// declare the controller as the preferred one for dependency use of
// the course.
void CourseController::requestPrefChange() {
course->changePrefSem(semester);
}
// When a preference is changes, the course is used as a hub and it
// informs all the controllers by a signal. This method checks to see
// If this controller is the new preferred one, and indicates it if so.
void CourseController::prefChangeRequested(int sem) {
if (sem == semester) {
preffered = true;
auto pal = btnUseMe->palette();
pal.setColor(QPalette::Background, Qt::yellow);
btnUseMe->setPalette(pal);
} else {
preffered = false;
auto pal = btnUseMe->palette();
pal.setColor(QPalette::Background, backgr);
btnUseMe->setPalette(pal);
}
}