summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/_Win/UI/StudioProjectSettingsPage.cpp
blob: c2a7e26c43047928ba847462be33a03cdb80ec45 (plain)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/****************************************************************************
**
** Copyright (C) 2002 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//==============================================================================
//	Prefix
//==============================================================================

#include "stdafx.h"
#include "Strings.h"
#include "StringLoader.h"

#include "ui_StudioProjectSettingsPage.h"

//==============================================================================
//	Includes
//==============================================================================
#include "StudioProjectSettingsPage.h"
#include "StudioProjectSettings.h"
#include "StudioApp.h"
#include "Doc.h"
#include "Views.h"
#include "MainFrm.h"
#include "CommonConstants.h"

#include "StudioPreferences.h"
#include "Core.h"

/////////////////////////////////////////////////////////////////////////////
// CStudioProjectSettingsPage property page

//==============================================================================
/**
 *	Constructor: Initializes the object.
 */
//==============================================================================
CStudioProjectSettingsPage::CStudioProjectSettingsPage(QWidget *parent)
    : CStudioPreferencesPropPage(parent)
    , m_AspectRatio(0.0f)
    , m_ui(new Ui::StudioProjectSettingsPage)
{
    m_Font = QFont(CStudioPreferences::GetFontFaceName());
    m_Font.setPixelSize(CStudioPreferences::fontSize());

    // Create a bold font for the group box text
    m_BoldFont = m_Font;
    m_BoldFont.setBold(true);

    OnInitDialog();
}

//==============================================================================
/**
 *	Destructor: Releases the object.
 */
//==============================================================================
CStudioProjectSettingsPage::~CStudioProjectSettingsPage()
{
}

//==============================================================================
//	Message Map is defined by subclasses, since there is any specific handlers must be
//	defined within the BEGIN_MESSAGE_MAP macros.
//==============================================================================

/////////////////////////////////////////////////////////////////////////////
// CStudioProjectSettingsPage message handlers

//==============================================================================
/**
 *	OnInitDialog: Handle the WM_INITDIALOG message.
 *
 *	Initialize the dialog by setting the various control values.
 *
 *	@param	None
 *
 *	@return Returns TRUE always.
 */
//==============================================================================
void CStudioProjectSettingsPage::OnInitDialog()
{
    m_ui->setupUi(this);

    m_ui->m_ClientSizeWidth->setToolTip(::LoadResourceString(IDS_PREFS_PRESENTATIONWIDTH).toQString());
    m_ui->m_ClientSizeHeight->setToolTip(::LoadResourceString(IDS_PREFS_PRESENTATIONHEIGHT).toQString());
    m_ui->m_checkConstrainProportions->setToolTip(::LoadResourceString(IDS_PREFS_PRESENTATIONASPECTRATIO).toQString());
    m_ui->m_Author->setToolTip(::LoadResourceString(IDS_PREFS_AUTHORNAME).toQString());
    m_ui->m_Company->setToolTip(::LoadResourceString(IDS_PREFS_COMPANYNAME).toQString());

    // Set fonts for child windows.
    for (auto w : findChildren<QWidget *>())
        w->setFont(m_Font);

    // Make the group text bold
    for (auto w : findChildren<QGroupBox *>())
        w->setFont(m_BoldFont);

    // Set the ranges of the client width and height
    m_ui->m_ClientSizeWidth->setRange(1, 16384);
    m_ui->m_ClientSizeHeight->setRange(1, 16384);

    // Load the settings for the controls
    this->LoadSettings();

    auto valueChanged = static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged);
    connect(m_ui->m_ClientSizeWidth, valueChanged, this, &CStudioProjectSettingsPage::OnChangeEditPresWidth);
    connect(m_ui->m_ClientSizeHeight, valueChanged, this, &CStudioProjectSettingsPage::OnChangeEditPresHeight);
    connect(m_ui->m_checkConstrainProportions, &QCheckBox::clicked, this, &CStudioProjectSettingsPage::OnCheckMaintainRatio);
    connect(m_ui->m_Author, &QLineEdit::textEdited, this, &CStudioProjectSettingsPage::OnChangeAuthor);
    connect(m_ui->m_Company, &QLineEdit::textEdited, this, &CStudioProjectSettingsPage::OnChangeCompany);
}

//==============================================================================
/**
 *	LoadSettings: Load the settings from the project settings and set the control values.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::LoadSettings()
{
    // Get the Client size
    CStudioProjectSettings *theProjectSettings = g_StudioApp.GetCore()->GetStudioProjectSettings();
    CPt theClientSize = theProjectSettings->GetPresentationSize();

    // Set client width & height
    m_ui->m_ClientSizeWidth->setValue(theClientSize.x);
    m_ui->m_ClientSizeHeight->setValue(theClientSize.y);

    // Save the aspect ratio
    m_AspectRatio = (double)theClientSize.x / (double)theClientSize.y;

    // Maintain Aspect Ratio checkbox
    m_ui->m_checkConstrainProportions->setChecked(theProjectSettings->GetMaintainAspect());

    m_ui->m_checkPortraitFormat->setChecked(theProjectSettings->GetRotatePresentation());

    // Author
    m_ui->m_Author->setText(theProjectSettings->GetAuthor());

    // Company
    m_ui->m_Company->setText(theProjectSettings->GetCompany());
}

//==============================================================================
/**
 *	SaveSettings: Save the settings from the controls to the project settings.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::SaveSettings()
{
    CPt theClientSize;
    CStudioProjectSettings *theProjectSettings = g_StudioApp.GetCore()->GetStudioProjectSettings();

    // Presentation width & height
    theClientSize.x = m_ui->m_ClientSizeWidth->value();
    theClientSize.y = m_ui->m_ClientSizeHeight->value();
    theProjectSettings->SetPresentationSize(theClientSize);

    // Author
    QString theAuthor = m_ui->m_Author->text();
    theProjectSettings->SetAuthor(theAuthor);

    // Company
    QString theCompany = m_ui->m_Company->text();
    theProjectSettings->SetCompany(theCompany);

    g_StudioApp.GetViews()->RecheckMainframeSizingMode();

    // Maintain Aspect Ratio checkbox
    theProjectSettings->SetMaintainAspect(m_ui->m_checkConstrainProportions->isChecked());

    theProjectSettings->SetRotatePresentation(m_ui->m_checkPortraitFormat->isChecked());
}

//==============================================================================
/**
 *	Generic function when settings are modified.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnSettingsModified()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnApply: Handler for the Apply button
 *
 *	@param	None
 */
//==============================================================================
bool CStudioProjectSettingsPage::OnApply()
{
    // Apply was clicked - save settings and disabled the Apply button
    this->SaveSettings();

    this->SetModified(FALSE);

    return CStudioPreferencesPropPage::OnApply();
}

//==============================================================================
/**
 *	OnOK: Handler for the OK button
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnOK()
{
    CStudioPreferencesPropPage::OnOK();
}

//==============================================================================
/**
 *	OnChangeEditPresWidth: EN_CHANGE handler for the IDC_EDIT_PRESWIDTH field
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeEditPresWidth()
{
    this->SetModified(TRUE);

    // Should the aspect ratio be maintained?
    if (m_ui->m_checkConstrainProportions->isChecked()) {
        long thePresWidth, thePresHeight;

        thePresWidth = m_ui->m_ClientSizeWidth->value();

        // Change the height
        thePresHeight = ((double)thePresWidth / m_AspectRatio);

        QSignalBlocker sb(m_ui->m_ClientSizeHeight);
        m_ui->m_ClientSizeHeight->setValue(thePresHeight);
    }
}

//==============================================================================
/**
 *	OnChangeEditPresHeight: EN_CHANGE handler for the IDC_EDIT_PRESHEIGHT field
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeEditPresHeight()
{
    this->SetModified(TRUE);

    // Should the aspect ratio be maintained?
    if (m_ui->m_checkConstrainProportions->isChecked()) {
        long thePresWidth, thePresHeight;

        thePresHeight = m_ui->m_ClientSizeHeight->value();

        // Change the width
        thePresWidth = ((double)thePresHeight * m_AspectRatio);

        QSignalBlocker sb(m_ui->m_ClientSizeWidth);
        m_ui->m_ClientSizeWidth->setValue(thePresWidth);
    }
}

//==============================================================================
/**
 *	OnCheckMaintainRatio: The aspect ratio checkbox has changed.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnCheckMaintainRatio()
{
    this->SetModified(TRUE);

    long thePresWidth, thePresHeight;

    // Get the width and height
    thePresWidth = m_ui->m_ClientSizeWidth->value();
    thePresHeight = m_ui->m_ClientSizeHeight->value();

    // Save the Aspect Ratio
    m_AspectRatio = (double)thePresWidth / (double)thePresHeight;
}

//==============================================================================
/**
 *	OnChangeAuthor: EN_CHANGE handler for the IDC_AUTHOR field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeAuthor()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnChangeCompany: EN_CHANGE handler for the IDC_COMPANY field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeCompany()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnChangeSet1: EN_CHANGE handler for the IDC_SET1 field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeSet1()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnChangeSet2: EN_CHANGE handler for the IDC_SET2 field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeSet2()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnChangeSet3: EN_CHANGE handler for the IDC_SET3 field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeSet3()
{
    this->SetModified(TRUE);
}

//==============================================================================
/**
 *	OnChangeSet5: EN_CHANGE handler for the IDC_SET5 field.
 *
 *	@param	None
 */
//==============================================================================
void CStudioProjectSettingsPage::OnChangeSet5()
{
    this->SetModified(TRUE);
}