forked from dparker2/StudyGroup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroupwidget.cpp
More file actions
executable file
·201 lines (171 loc) · 5.08 KB
/
groupwidget.cpp
File metadata and controls
executable file
·201 lines (171 loc) · 5.08 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "groupwidget.h"
#include "ui_groupwidget.h"
#include <QTime>
#include <QDebug>
#include <QLine>
#include <QVBoxLayout>
GroupWidget::GroupWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::GroupWidget)
{
ui->setupUi(this);
// Begin set whiteboard
whiteboard = new Whiteboard(nullptr, ui->save_whiteboard_button);
qDebug() << connect(whiteboard, SIGNAL(line_drawn(QPoint,QPoint,QColor,int)), this, SLOT(send_line_drawn(QPoint,QPoint,QColor,int)));
qDebug() << connect(this, SIGNAL(whiteboard_draw_line(QPoint,QPoint,QColor,int)), whiteboard, SLOT(draw_line(QPoint,QPoint,QColor,int)));
ui->study_mode->addWidget(whiteboard);
ui->study_mode->setCurrentWidget(whiteboard);
ui->study_menu->setCurrentIndex(0);
whiteboard->set_pen_color(QColor("#000"));
QString pen_string = ui->comboBox_pen_size->currentText();
pen_string.chop(2);
whiteboard->set_pen_size(pen_string.toInt());
//ui->study_mode->setStyleSheet("background-color: #ffffff;");
// End set whiteboard
// Flaschard
flashcard = new CardWidget();
ui->study_mode->insertWidget(1, flashcard);
setFlashcardUI();
connect(flashcard, SIGNAL(set_card(QString,int&,int)), this, SLOT(set_card(QString,int&,int)));
}
/********
*
* PUBLIC
*
*/
QString GroupWidget::get_groupID()
{
return group_id;
}
Whiteboard* GroupWidget::whiteboard_ptr()
{
return whiteboard;
}
/********
*
* SLOTS
*
*/
void GroupWidget::new_chat(QString username, QString time, QString message)
{
qDebug() << message;
QDate new_date = QDate::fromString(time.section(' ', 0, 0), "yyyy-MM-dd");
qDebug() << time.section(' ', 0, 0);
time.remove(0, 11);
qDebug() << new_date.toString("dddd MMM dd yyyy");
qDebug() << last_date_printed.toString("dddd MMM dd yyyy");
if(new_date != last_date_printed)
{
ui->chat_box->append(new_date.toString("dddd MMM dd yyyy"));
last_date_printed = new_date;
}
ui->chat_box->append(time+" - "+username+": "+message);
}
void GroupWidget::users_changed()
{
QLayoutItem* item;
while ( ( item = ui->username_layout->takeAt( 0 ) ) != NULL )
{
delete item->widget();
delete item;
}
}
void GroupWidget::user_joined(QString username)
{
QLabel* username_label = new QLabel(username);
username_label->setStyleSheet("color: white");
username_label->setFont(QFont("Trebuchet MS", 20));
ui->username_layout->addWidget(username_label);
}
void GroupWidget::set_groupID(QString &groupID)
{
group_id = groupID;
ui->groupid_label->setText("GroupID: "+groupID);
}
void GroupWidget::send_line_drawn(const QPoint& first_mouse_pos, const QPoint& second_mouse_pos, const QColor& pen_color, const int& pen_size)
{
ui->save_whiteboard_button->setEnabled(true);
emit line_drawn(group_id, first_mouse_pos, second_mouse_pos, pen_color, pen_size);
}
/********
*
* UI SLOTS
*
*/
void GroupWidget::on_submit_chat_released()
{
QString chat_message = ui->chat_input->text();
if(chat_message != "") {
ui->chat_input->setText("");
QString groupID = group_id;
emit send_chat(groupID, chat_message); // Send the chat signal
}
}
void GroupWidget::on_save_whiteboard_button_released()
{
qDebug() << "saving_whiteboard";
emit save_whiteboard(group_id, whiteboard->whiteboard_ba());
ui->save_whiteboard_button->setEnabled(false);
}
void GroupWidget::on_comboBox_pen_color_currentTextChanged(const QString &pen_color)
{
if(pen_color == "Black")
{
whiteboard->set_pen_color(QColor("#000"));
}
else if(pen_color == "Red")
{
whiteboard->set_pen_color(QColor("#f00"));
}
else if(pen_color == "Green")
{
whiteboard->set_pen_color(QColor("#0f0"));
}
else if(pen_color == "Blue")
{
whiteboard->set_pen_color(QColor("#00f"));
}
}
void GroupWidget::on_comboBox_pen_size_currentTextChanged(const QString &pen_size)
{
QString p_size = pen_size;
p_size.chop(2);
whiteboard->set_pen_size(p_size.toInt());
}
void GroupWidget::setFlashcardUI(){
//flashcard->card_label->hide();
}
void GroupWidget::on_comboBox_study_mode_currentIndexChanged(int index)
{
if(index){
ui->study_mode->setCurrentWidget(flashcard);
ui->study_menu->setCurrentIndex(1);
}
else{
ui->study_mode->setCurrentWidget(whiteboard);
ui->study_menu->setCurrentIndex(0);
}
}
void GroupWidget::on_add_card_button_clicked()
{
flashcard->on_addCardBtn_clicked();
}
void GroupWidget::set_card(QString front, int& card_num, int side){
QString groupID = get_groupID();
qDebug() << "SET FRONT" << endl;
emit send_card(groupID, front, card_num, side);
}
void GroupWidget::incoming_card(int card_index, QString text, bool front)
{
flashcard->setCard(card_index, text, front); // Will edit or create new card
}
void GroupWidget::on_pushButton_clicked()
{
ui->study_menu->setCurrentIndex(0);
ui->study_mode->setCurrentWidget(whiteboard);
ui->comboBox_study_mode->setCurrentIndex(0);
}
void GroupWidget::on_quiz_button_toggled(bool checked)
{
flashcard->setQuiz(checked);
}