-
Notifications
You must be signed in to change notification settings - Fork 29
/
editannouncementdialog.cpp
157 lines (141 loc) · 4.67 KB
/
editannouncementdialog.cpp
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
/***************************************************************************
//
// softProjector - an open source media projection software
// Copyright (C) 2017 Vladislav Kobzar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
***************************************************************************/
#include "editannouncementdialog.hpp"
#include "ui_editannouncementdialog.h"
EditAnnouncementDialog::EditAnnouncementDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditAnnouncementDialog)
{
ui->setupUi(this);
highlight = new HighlightAnnounce(ui->textEditAnnouncement->document());
ui->groupBoxPrivateSettings->setVisible(false);
ui->checkBoxUsePrivateSettings->setVisible(false);
}
EditAnnouncementDialog::~EditAnnouncementDialog()
{
delete highlight;
delete ui;
}
void EditAnnouncementDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch ( e->type() ) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void EditAnnouncementDialog::on_checkBoxUsePrivateSettings_stateChanged(int arg1)
{
ui->groupBoxPrivateSettings->setVisible(arg1 == 2);
}
void EditAnnouncementDialog::on_checkBoxTimedSlides_stateChanged(int arg1)
{
ui->spinBoxTimeOut->setEnabled(arg1 == 2);
ui->checkBoxLoop->setEnabled(arg1 == 2);
}
void EditAnnouncementDialog::setNewAnnouce()
{
resetUiItems();
isNew = true;
}
void EditAnnouncementDialog::setEditAnnouce(Announcement &editAnnoucement)
{
editAnnounce = editAnnoucement;
setUiItems();
isNew = false;
}
void EditAnnouncementDialog::setCopyAnnouce(Announcement ©Annoucement)
{
editAnnounce = copyAnnoucement;
editAnnounce.idNum = 0;
setUiItems();
isNew = true;
}
void EditAnnouncementDialog::setUiItems()
{
ui->lineEditTitle->setText(editAnnounce.title);
ui->labelIdNum->setText(QString::number(editAnnounce.idNum));
ui->textEditAnnouncement->setPlainText(editAnnounce.text);
ui->checkBoxUsePrivateSettings->setChecked(editAnnounce.usePrivateSettings);
ui->checkBoxTimedSlides->setChecked(editAnnounce.useAutoNext);
ui->spinBoxTimeOut->setValue(editAnnounce.slideTimer);
ui->checkBoxLoop->setChecked(editAnnounce.loop);
}
void EditAnnouncementDialog::resetUiItems()
{
Announcement a;
a.text = tr("Announce\n - Text of the announcement goes here\n\n"
"Slide\n - Text of the announcement goes here\n"
"You can have both Annouce or Slide as announcement block titles.");
ui->lineEditTitle->setText(a.title);
ui->labelIdNum->setText(QString::number(a.idNum));
ui->textEditAnnouncement->setPlainText(a.text);
ui->checkBoxUsePrivateSettings->setChecked(a.usePrivateSettings);
ui->checkBoxTimedSlides->setChecked(a.useAutoNext);
ui->spinBoxTimeOut->setValue(a.slideTimer);
ui->checkBoxLoop->setChecked(a.loop);
}
bool EditAnnouncementDialog::setSave()
{
QString t = ui->lineEditTitle->text();
t = t.simplified();
if(!t.isEmpty())
{
editAnnounce.title = t;
editAnnounce.text = ui->textEditAnnouncement->toPlainText();
editAnnounce.usePrivateSettings = ui->checkBoxUsePrivateSettings->isChecked();
editAnnounce.useAutoNext = ui->checkBoxTimedSlides->isChecked();
editAnnounce.slideTimer = ui->spinBoxTimeOut->value();
editAnnounce.loop = ui->checkBoxLoop->isChecked();
return true;
}
else
{
QMessageBox mb(this);
mb.setText(tr("Announcement title cannot be left empty.\nPlease enter announcement title."));
mb.setWindowTitle(tr("Announcement title is missing"));
mb.setIcon(QMessageBox::Warning);
mb.exec();
ui->lineEditTitle->setFocus();
return false;
}
}
void EditAnnouncementDialog::on_pushButtonSave_clicked()
{
if(!setSave())
return;
if(isNew)
{
editAnnounce.saveNew();
emit announceToAdd(editAnnounce);
}
else
{
editAnnounce.saveUpdate();
emit announceToUpdate();
}
close();
}
void EditAnnouncementDialog::on_pushButtonCancel_clicked()
{
close();
}