2
Copyright (c) 2012 Montel Laurent <montel@kde.org>
4
This program is free software; you can redistribute it and/or modify it
5
under the terms of the GNU General Public License, version 2, as
6
published by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program; if not, write to the Free Software Foundation, Inc.,
15
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "autoresizeimagewidget.h"
19
#include "ui_autoresizeimagewidget.h"
20
#include "messagecomposersettings.h"
25
using namespace MessageComposer;
27
AutoResizeImageWidget::AutoResizeImageWidget(QWidget *parent)
29
ui(new Ui::AutoResizeImageWidget),
33
initComboBox(ui->CBMaximumWidth);
34
initComboBox(ui->CBMaximumHeight);
35
initComboBox(ui->CBMinimumWidth);
36
initComboBox(ui->CBMinimumHeight);
38
connect(ui->enabledAutoResize,SIGNAL(clicked()),SIGNAL(changed()));
39
connect(ui->KeepImageRatio,SIGNAL(clicked()),SIGNAL(changed()));
40
connect(ui->AskBeforeResizing,SIGNAL(clicked()),SIGNAL(changed()));
41
connect(ui->EnlargeImageToMinimum,SIGNAL(clicked()),SIGNAL(changed()));
42
connect(ui->ReduceImageToMaximum,SIGNAL(clicked()),SIGNAL(changed()));
43
connect(ui->customMaximumWidth,SIGNAL(valueChanged(int)),SIGNAL(changed()));
44
connect(ui->customMaximumHeight,SIGNAL(valueChanged(int)),SIGNAL(changed()));
45
connect(ui->customMinimumWidth,SIGNAL(valueChanged(int)),SIGNAL(changed()));
46
connect(ui->customMinimumHeight,SIGNAL(valueChanged(int)),SIGNAL(changed()));
48
connect(ui->CBMaximumWidth,SIGNAL(activated(QString)),SLOT(slotComboboxChanged(QString)));
49
connect(ui->CBMaximumHeight,SIGNAL(activated(QString)),SLOT(slotComboboxChanged(QString)));
50
connect(ui->CBMinimumWidth,SIGNAL(activated(QString)),SLOT(slotComboboxChanged(QString)));
51
connect(ui->CBMinimumHeight,SIGNAL(activated(QString)),SLOT(slotComboboxChanged(QString)));
54
AutoResizeImageWidget::~AutoResizeImageWidget()
59
void AutoResizeImageWidget::slotComboboxChanged(const QString& text)
61
const bool isCustom = (text == i18n("Custom"));
62
KComboBox* combo = qobject_cast< KComboBox* >( sender() );
64
if(combo == ui->CBMaximumWidth) {
65
ui->customMaximumWidth->setEnabled(isCustom);
66
} else if(combo == ui->CBMaximumHeight) {
67
ui->customMaximumHeight->setEnabled(isCustom);
68
} else if(combo == ui->CBMinimumWidth) {
69
ui->customMinimumWidth->setEnabled(isCustom);
70
} else if(combo == ui->CBMinimumHeight) {
71
ui->customMinimumHeight->setEnabled(isCustom);
77
void AutoResizeImageWidget::initComboBox(KComboBox *combo)
88
Q_FOREACH(int val, size)
90
combo->addItem(QString::number(val));
92
combo->addItem(i18n("Custom"));
95
void AutoResizeImageWidget::loadConfig()
97
ui->enabledAutoResize->setChecked(MessageComposer::MessageComposerSettings::self()->autoResizeImageEnabled());
98
ui->KeepImageRatio->setChecked(MessageComposer::MessageComposerSettings::self()->keepImageRatio());
99
ui->AskBeforeResizing->setChecked(MessageComposer::MessageComposerSettings::self()->askBeforeResizing());
100
ui->EnlargeImageToMinimum->setChecked(MessageComposer::MessageComposerSettings::self()->enlargeImageToMinimum());
101
ui->ReduceImageToMaximum->setChecked(MessageComposer::MessageComposerSettings::self()->reduceImageToMaximum());
103
ui->customMaximumWidth->setValue(MessageComposer::MessageComposerSettings::self()->customMaximumWidth());
104
ui->customMaximumHeight->setValue(MessageComposer::MessageComposerSettings::self()->customMaximumHeight());
105
ui->customMinimumWidth->setValue(MessageComposer::MessageComposerSettings::self()->customMinimumWidth());
106
ui->customMinimumHeight->setValue(MessageComposer::MessageComposerSettings::self()->customMinimumHeight());
109
ui->CBMaximumWidth->setCurrentIndex(MessageComposer::MessageComposerSettings::self()->maximumWidth());
110
ui->CBMaximumHeight->setCurrentIndex(MessageComposer::MessageComposerSettings::self()->maximumHeight());
111
ui->CBMinimumWidth->setCurrentIndex(MessageComposer::MessageComposerSettings::self()->minimumWidth());
112
ui->CBMinimumHeight->setCurrentIndex(MessageComposer::MessageComposerSettings::self()->minimumHeight());
117
void AutoResizeImageWidget::writeConfig()
119
MessageComposer::MessageComposerSettings::self()->setAutoResizeImageEnabled(ui->enabledAutoResize->isChecked());
120
MessageComposer::MessageComposerSettings::self()->setKeepImageRatio(ui->KeepImageRatio->isChecked());
121
MessageComposer::MessageComposerSettings::self()->setAskBeforeResizing(ui->AskBeforeResizing->isChecked());
122
MessageComposer::MessageComposerSettings::self()->setEnlargeImageToMinimum(ui->EnlargeImageToMinimum->isChecked());
123
MessageComposer::MessageComposerSettings::self()->setReduceImageToMaximum(ui->ReduceImageToMaximum->isChecked());
125
MessageComposer::MessageComposerSettings::self()->setCustomMaximumWidth(ui->customMaximumWidth->value());
126
MessageComposer::MessageComposerSettings::self()->setCustomMaximumHeight(ui->customMaximumHeight->value());
127
MessageComposer::MessageComposerSettings::self()->setCustomMinimumWidth(ui->customMinimumWidth->value());
128
MessageComposer::MessageComposerSettings::self()->setCustomMinimumHeight(ui->customMinimumHeight->value());
130
MessageComposer::MessageComposerSettings::self()->setMaximumWidth(ui->CBMaximumWidth->currentIndex());
131
MessageComposer::MessageComposerSettings::self()->setMaximumHeight(ui->CBMaximumHeight->currentIndex());
132
MessageComposer::MessageComposerSettings::self()->setMinimumWidth(ui->CBMinimumWidth->currentIndex());
133
MessageComposer::MessageComposerSettings::self()->setMinimumHeight(ui->CBMinimumHeight->currentIndex());
139
void AutoResizeImageWidget::resetToDefault()
144
#include "autoresizeimagewidget.moc"