FreeCAD

Форк
0
/
DlgSettingsImageImp.cpp 
279 строк · 8.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QRegularExpression>
26
# include <QRegularExpressionMatch>
27
#endif
28

29
#include "DlgSettingsImageImp.h"
30
#include "ui_DlgSettingsImage.h"
31

32

33
using namespace Gui::Dialog;
34
using namespace std;
35

36
/* TRANSLATOR Gui::Dialog::DlgSettingsImageImp */
37

38
/**
39
 *  Constructs a DlgSettingsImageImp as a child of 'parent', with the
40
 *  name 'name' and widget flags set to 'f'.
41
 */
42
DlgSettingsImageImp::DlgSettingsImageImp( QWidget* parent )
43
  : QWidget( parent )
44
  , ui(new Ui_DlgSettingsImage)
45
{
46
    ui->setupUi(this);
47
    setupConnections();
48

49
    SbVec2s res = SoOffscreenRenderer::getMaximumResolution();
50
    ui->spinWidth->setMaximum((int)res[0]);
51
    ui->spinHeight->setMaximum((int)res[1]);
52

53
    _width = width();
54
    _height = height();
55
    _fRatio = (float)_width/(float)_height;
56

57
    ui->comboMethod->addItem(tr("Offscreen (New)"), QByteArray("QtOffscreenRenderer"));
58
    ui->comboMethod->addItem(tr("Offscreen (Old)"), QByteArray("CoinOffscreenRenderer"));
59
    ui->comboMethod->addItem(tr("Framebuffer (custom)"), QByteArray("FramebufferObject"));
60
    ui->comboMethod->addItem(tr("Framebuffer (as is)"), QByteArray("GrabFramebuffer"));
61
}
62

63
/**
64
 *  Destroys the object and frees any allocated resources
65
 */
66
DlgSettingsImageImp::~DlgSettingsImageImp() = default;
67

68
void DlgSettingsImageImp::setupConnections()
69
{
70
    connect(ui->buttonRatioScreen, &QToolButton::clicked,
71
            this, &DlgSettingsImageImp::onButtonRatioScreenClicked);
72
    connect(ui->buttonRatio4x3, &QToolButton::clicked,
73
            this, &DlgSettingsImageImp::onButtonRatio4x3Clicked);
74
    connect(ui->buttonRatio16x9, &QToolButton::clicked,
75
            this, &DlgSettingsImageImp::onButtonRatio16x9Clicked);
76
    connect(ui->buttonRatio1x1, &QToolButton::clicked,
77
            this, &DlgSettingsImageImp::onButtonRatio1x1Clicked);
78
    connect(ui->standardSizeBox, qOverload<int>(&QComboBox::activated),
79
            this, &DlgSettingsImageImp::onStandardSizeBoxActivated);
80
    connect(ui->comboMethod, qOverload<int>(&QComboBox::activated),
81
            this, &DlgSettingsImageImp::onComboMethodActivated);
82
}
83

84
void DlgSettingsImageImp::changeEvent(QEvent *e)
85
{
86
    if (e->type() == QEvent::LanguageChange) {
87
        ui->retranslateUi(this);
88
    }
89
    QWidget::changeEvent(e);
90
}
91

92
/**
93
 * Sets the image size to (\a w, \a h).
94
 */
95
void DlgSettingsImageImp::setImageSize(int w, int h)
96
{
97
    // set current screen size
98
    ui->standardSizeBox->setItemData(0, QSize(w,h));
99

100
    ui->spinWidth->setValue(w);
101
    ui->spinHeight->setValue(h);
102

103
    // As the image size is in pixel why shouldn't _width and _height be integers?
104
    _width  = w;
105
    _height = h;
106
    _fRatio = (float)_width/(float)_height;
107
}
108

109
/**
110
 * Sets the image size to \a s.
111
 */
112
void DlgSettingsImageImp::setImageSize( const QSize& s )
113
{
114
    // set current screen size
115
    ui->standardSizeBox->setItemData(0, s);
116

117
    ui->spinWidth->setValue( s.width() );
118
    ui->spinHeight->setValue( s.height() );
119

120
    // As the image size is in pixel why shouldn't _width and _height be integers?
121
    _width  = s.width();
122
    _height = s.height();
123
    _fRatio = (float)_width/(float)_height;
124
}
125

126
/**
127
 * Returns the currently set image size.
128
 */
129
QSize DlgSettingsImageImp::imageSize() const
130
{
131
    return { ui->spinWidth->value(), ui->spinHeight->value() };
132
}
133

134
/**
135
 * Returns the currently set image width.
136
 */
137
int DlgSettingsImageImp::imageWidth() const
138
{
139
    return ui->spinWidth->value();
140
}
141

142
/**
143
 * Returns the currently set image height.
144
 */
145
int DlgSettingsImageImp::imageHeight() const
146
{
147
    return ui->spinHeight->value();
148
}
149

150
/**
151
 * Returns the comment of the picture. If for the currently selected image format no comments are supported
152
 * QString() is returned.
153
 */
154
QString DlgSettingsImageImp::comment() const
155
{
156
    if ( !ui->textEditComment->isEnabled() )
157
        return {};
158
    else
159
        return ui->textEditComment->toPlainText();
160
}
161

162
int DlgSettingsImageImp::backgroundType() const
163
{
164
    return ui->comboBackground->currentIndex();
165
}
166

167
/**
168
 * Sets the image size to (\a w, \a h).
169
 */
170
void DlgSettingsImageImp::setBackgroundType(int t)
171
{
172
    if ( t < ui->comboBackground->count() )
173
        ui->comboBackground->setCurrentIndex(t);
174
}
175

176
bool DlgSettingsImageImp::addWatermark() const
177
{
178
    return ui->checkWatermark->isChecked();
179
}
180

181
void DlgSettingsImageImp::onSelectedFilter(const QString& filter)
182
{
183
    bool ok = (filter.startsWith(QLatin1String("JPG")) ||
184
               filter.startsWith(QLatin1String("JPEG")) ||
185
               filter.startsWith(QLatin1String("PNG")));
186
    ui->buttonGroupComment->setEnabled( ok );
187
}
188

189
void DlgSettingsImageImp::adjustImageSize(float fRatio)
190
{
191
    // if width has changed then adjust height and vice versa, if both has changed then adjust width
192
    if (_height != ui->spinHeight->value())
193
    {
194
        _height = ui->spinHeight->value();
195
        _width = (int)((float)_height*fRatio);
196
        ui->spinWidth->setValue( (int)_width );
197
    }
198
    else // if( _width != spinWidth->value() )
199
    {
200
        _width = ui->spinWidth->value();
201
        _height = (int)((float)_width/fRatio);
202
        ui->spinHeight->setValue( (int)_height );
203
    }
204
}
205

206
void DlgSettingsImageImp::onButtonRatioScreenClicked()
207
{
208
    adjustImageSize(_fRatio);
209
}
210

211
void DlgSettingsImageImp::onButtonRatio4x3Clicked()
212
{
213
    adjustImageSize(4.0f/3.0f);
214
}
215

216
void DlgSettingsImageImp::onButtonRatio16x9Clicked()
217
{
218
    adjustImageSize(16.0f/9.0f);
219
}
220

221
void DlgSettingsImageImp::onButtonRatio1x1Clicked()
222
{
223
    adjustImageSize(1.0f);
224
}
225

226
void DlgSettingsImageImp::onStandardSizeBoxActivated(int index)
227
{
228
    if (index == 0) {
229
        // we have set the user data for the 1st item
230
        QSize s = ui->standardSizeBox->itemData(0).toSize();
231
        ui->spinWidth->setValue(s.width());
232
        ui->spinHeight->setValue(s.height());
233
    }
234
    else {
235
        // try to extract from the string
236
        QString text = ui->standardSizeBox->itemText(index);
237
        QRegularExpression rx(QLatin1String(R"(\b\d{2,5}\b)"));
238
        int pos = 0;
239
        auto match = rx.match(text, pos);
240
        if (match.hasMatch()) {
241
            pos = match.capturedStart();
242
            QString width = text.mid(pos, match.capturedLength());
243
            ui->spinWidth->setValue(width.toInt());
244
            pos += match.capturedLength();
245
        }
246

247
        match = rx.match(text, pos);
248
        if (match.hasMatch()) {
249
            pos = match.capturedStart();
250
            QString height = text.mid(pos, match.capturedLength());
251
            ui->spinHeight->setValue(height.toInt());
252
        }
253
    }
254
}
255

256
void DlgSettingsImageImp::setMethod(const QByteArray& m)
257
{
258
    int index = ui->comboMethod->findData(m);
259
    if (index >= 0)
260
        ui->comboMethod->setCurrentIndex(index);
261
}
262

263
QByteArray DlgSettingsImageImp::method() const
264
{
265
    return ui->comboMethod->currentData().toByteArray();
266
}
267

268
void DlgSettingsImageImp::onComboMethodActivated(int index)
269
{
270
    QByteArray data = ui->comboMethod->itemData(index).toByteArray();
271
    if (data == QByteArray("GrabFramebuffer")) {
272
        ui->comboBackground->setEnabled(false);
273
    }
274
    else {
275
        ui->comboBackground->setEnabled(true);
276
    }
277
}
278

279
#include "moc_DlgSettingsImageImp.cpp"
280

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.