forked from SoftProjector/softprojector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generalsettingwidget.cpp
220 lines (189 loc) · 6.77 KB
/
generalsettingwidget.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/***************************************************************************
//
// 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 "generalsettingwidget.hpp"
#include "ui_generalsettingwidget.h"
GeneralSettingWidget::GeneralSettingWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::GeneralSettingWidget)
{
ui->setupUi(this);
}
GeneralSettingWidget::~GeneralSettingWidget()
{
delete ui;
}
void GeneralSettingWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch ( e->type() ) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void GeneralSettingWidget::setSettings(GeneralSettings settings)
{
mySettings = settings;
loadSettings();
}
void GeneralSettingWidget::loadSettings()
{
ui->checkBoxDisplayOnTop->setChecked(mySettings.displayIsOnTop);
ui->checkBoxDisplayOnStartUp->setChecked(mySettings.displayOnStartUp);
// Load Themes
loadThemes();
ui->comboBoxTheme->setCurrentIndex(themeIdList.indexOf(mySettings.currentThemeId));
// Get display screen infomration
monitors.clear();
QDesktopWidget d;
int screen_count = d.screenCount();
ui->comboBoxDisplayScreen->clear();
for(int i(0); i<screen_count;++i)
monitors << QString("%1 - %2x%3").arg(i+1).arg(d.screenGeometry(i).width()).arg(d.screenGeometry(i).height());
if(screen_count>1)
ui->groupBoxDisplayScreen->setEnabled(true);
else
ui->groupBoxDisplayScreen->setEnabled(false);
// Fill display screen comboBoxes
ui->comboBoxDisplayScreen->clear();
ui->comboBoxDisplayScreen->addItems(monitors);
ui->comboBoxDisplayScreen_2->clear();
ui->comboBoxDisplayScreen_2->addItem(tr("none"));
ui->comboBoxDisplayScreen_2->addItems(monitors);
// Set primary display screen
if(mySettings.displayScreen<0 || mySettings.displayScreen>=screen_count)
ui->comboBoxDisplayScreen->setCurrentIndex(0);
else
ui->comboBoxDisplayScreen->setCurrentIndex(mySettings.displayScreen);
// Set secondaty display screen
if(mySettings.displayScreen2<-1 || mySettings.displayScreen2>=screen_count)
ui->comboBoxDisplayScreen_2->setCurrentIndex(0);
else
ui->comboBoxDisplayScreen_2->setCurrentIndex(mySettings.displayScreen2+1);
updateSecondaryDisplayScreen();
// Set Display Controls
if(screen_count>1)
ui->groupBoxDisplayControls->setEnabled(false);
else
ui->groupBoxDisplayControls->setEnabled(true);
ui->comboBoxIconSize->setCurrentIndex(mySettings.displayControls.buttonSize);
ui->comboBoxControlsAlignV->setCurrentIndex(mySettings.displayControls.alignmentV);
ui->comboBoxControlsAlignH->setCurrentIndex(mySettings.displayControls.alignmentH);
ui->horizontalSliderOpacity->setValue(mySettings.displayControls.opacity*100);
}
void GeneralSettingWidget::loadThemes()
{
QSqlQuery sq;
sq.exec("SELECT id, name FROM Themes");
themeIdList.clear();
themes.clear();
while(sq.next())
{
themeIdList<< sq.value(0).toInt();
themes<<sq.value(1).toString();
}
ui->comboBoxTheme->clear();
ui->comboBoxTheme->addItems(themes);
}
GeneralSettings GeneralSettingWidget::getSettings()
{
mySettings.displayIsOnTop = ui->checkBoxDisplayOnTop->isChecked();
mySettings.displayOnStartUp = ui->checkBoxDisplayOnStartUp->isChecked();
int tmx = ui->comboBoxTheme->currentIndex();
if(tmx != -1)
mySettings.currentThemeId = themeIdList.at(tmx);
else
mySettings.currentThemeId = 0;
mySettings.displayScreen = ui->comboBoxDisplayScreen->currentIndex();
mySettings.displayScreen2 = monitors.indexOf(ui->comboBoxDisplayScreen_2->currentText());
mySettings.displayControls.buttonSize = ui->comboBoxIconSize->currentIndex();
mySettings.displayControls.alignmentV = ui->comboBoxControlsAlignV->currentIndex();
mySettings.displayControls.alignmentH = ui->comboBoxControlsAlignH->currentIndex();
qreal r = ui->horizontalSliderOpacity->value();
r = r/100;
mySettings.displayControls.opacity = r;
return mySettings;
}
void GeneralSettingWidget::on_pushButtonDefault_clicked()
{
GeneralSettings g;
mySettings = g;
loadSettings();
}
void GeneralSettingWidget::updateSecondaryDisplayScreen()
{
QString ds1 = ui->comboBoxDisplayScreen->currentText();
QString ds2 = ui->comboBoxDisplayScreen_2->currentText();
QStringList monitors2 = monitors;
monitors2.removeOne(ds1);
ui->comboBoxDisplayScreen_2->clear();
ui->comboBoxDisplayScreen_2->addItem(tr("None"));
ui->comboBoxDisplayScreen_2->addItems(monitors2);
int i = ui->comboBoxDisplayScreen_2->findText(ds2);
if(i != -1)
ui->comboBoxDisplayScreen_2->setCurrentIndex(i);
else
{
ui->comboBoxDisplayScreen_2->setCurrentIndex(0);
emit setDisp2Use(false);
}
}
void GeneralSettingWidget::on_comboBoxDisplayScreen_activated(const QString &arg1)
{
updateSecondaryDisplayScreen();
}
void GeneralSettingWidget::on_comboBoxDisplayScreen_2_activated(int index)
{
if(index<=0)
emit setDisp2Use(false);
else
emit setDisp2Use(true);
}
void GeneralSettingWidget::on_pushButtonAddTheme_clicked()
{
Theme tm;
ThemeInfo tmi;
int nId;
AddSongbookDialog theme_dia;
theme_dia.setWindowTitle(tr("Edit Theme"));
theme_dia.setWindowText(tr("Theme Name:"),tr("Comments:"));
theme_dia.setSongbook(tr("Default"),tr("This theme will contain program default settings."));
int ret = theme_dia.exec();
switch(ret)
{
case AddSongbookDialog::Accepted:
tmi.name = theme_dia.title;
tmi.comments = theme_dia.info;
tm.setThemeInfo(tmi);
tm.saveThemeNew();
nId = tm.getThemeId();
loadThemes();
ui->comboBoxTheme->setCurrentIndex(themeIdList.indexOf(nId));
emit themeChanged(nId);
break;
case AddSongbookDialog::Rejected:
break;
}
}
void GeneralSettingWidget::on_comboBoxTheme_activated(int index)
{
emit themeChanged(themeIdList.at(index));
}