File indexing completed on 2024-05-12 15:27:57
0001 /*************************************************************************** 0002 File : CartesianPlotLegendDock.cpp 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2013-2020 by Alexander Semke (alexander.semke@web.de) 0006 Description : widget for cartesian plot legend properties 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #include "CartesianPlotLegendDock.h" 0030 #include "backend/worksheet/plots/PlotArea.h" 0031 #include "backend/worksheet/Worksheet.h" 0032 #include "kdefrontend/widgets/LabelWidget.h" 0033 #include "kdefrontend/GuiTools.h" 0034 #include "kdefrontend/TemplateHandler.h" 0035 0036 #include <QCompleter> 0037 #include <QDir> 0038 #include <QDirModel> 0039 #include <QFileDialog> 0040 #include <QImageReader> 0041 0042 #include <KLocalizedString> 0043 0044 /*! 0045 \class CartesianPlotLegendDock 0046 \brief Provides a widget for editing the properties of the cartesian plot legend currently selected in the project explorer. 0047 0048 \ingroup kdefrontend 0049 */ 0050 CartesianPlotLegendDock::CartesianPlotLegendDock(QWidget* parent) : BaseDock(parent) { 0051 ui.setupUi(this); 0052 m_leName = ui.leName; 0053 m_leComment = ui.leComment; 0054 0055 //"Title"-tab 0056 auto hboxLayout = new QHBoxLayout(ui.tabTitle); 0057 labelWidget = new LabelWidget(ui.tabTitle); 0058 labelWidget->setGeometryAvailable(false); 0059 labelWidget->setBorderAvailable(false); 0060 hboxLayout->addWidget(labelWidget); 0061 hboxLayout->setContentsMargins(2, 2, 2, 2); 0062 hboxLayout->setSpacing(2); 0063 0064 //"Background"-tab 0065 ui.bOpen->setIcon( QIcon::fromTheme("document-open") ); 0066 ui.leBackgroundFileName->setCompleter(new QCompleter(new QDirModel, this)); 0067 0068 //adjust layouts in the tabs 0069 for (int i = 0; i < ui.tabWidget->count(); ++i) { 0070 auto layout = dynamic_cast<QGridLayout*>(ui.tabWidget->widget(i)->layout()); 0071 if (!layout) 0072 continue; 0073 0074 layout->setContentsMargins(2, 2, 2, 2); 0075 layout->setHorizontalSpacing(2); 0076 layout->setVerticalSpacing(2); 0077 } 0078 0079 CartesianPlotLegendDock::updateLocale(); 0080 0081 //SIGNAL/SLOT 0082 0083 //General 0084 connect(ui.leName, &QLineEdit::textChanged, this, &CartesianPlotLegendDock::nameChanged); 0085 connect(ui.leComment, &QLineEdit::textChanged, this, &CartesianPlotLegendDock::commentChanged); 0086 connect(ui.chkVisible, &QCheckBox::clicked, this, &CartesianPlotLegendDock::visibilityChanged); 0087 connect(ui.kfrLabelFont, &KFontRequester::fontSelected, this, &CartesianPlotLegendDock::labelFontChanged); 0088 connect(ui.kcbLabelColor, &KColorButton::changed, this, &CartesianPlotLegendDock::labelColorChanged); 0089 connect(ui.cbOrder, QOverload<int>::of(&QComboBox::currentIndexChanged), 0090 this, &CartesianPlotLegendDock::labelOrderChanged); 0091 connect(ui.sbLineSymbolWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0092 this, &CartesianPlotLegendDock::lineSymbolWidthChanged); 0093 0094 connect(ui.cbPositionX, QOverload<int>::of(&QComboBox::currentIndexChanged), 0095 this, &CartesianPlotLegendDock::positionXChanged); 0096 connect(ui.cbPositionY, QOverload<int>::of(&QComboBox::currentIndexChanged), 0097 this, &CartesianPlotLegendDock::positionYChanged); 0098 connect(ui.sbPositionX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0099 this, &CartesianPlotLegendDock::customPositionXChanged); 0100 connect(ui.sbPositionY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0101 this, &CartesianPlotLegendDock::customPositionYChanged); 0102 0103 connect(ui.sbRotation, QOverload<int>::of(&QSpinBox::valueChanged), 0104 this, &CartesianPlotLegendDock::rotationChanged); 0105 0106 //Background 0107 connect(ui.cbBackgroundType, QOverload<int>::of(&QComboBox::currentIndexChanged), 0108 this, &CartesianPlotLegendDock::backgroundTypeChanged); 0109 connect(ui.cbBackgroundColorStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0110 this, &CartesianPlotLegendDock::backgroundColorStyleChanged); 0111 connect(ui.cbBackgroundImageStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0112 this, &CartesianPlotLegendDock::backgroundImageStyleChanged); 0113 connect(ui.cbBackgroundBrushStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0114 this, &CartesianPlotLegendDock::backgroundBrushStyleChanged); 0115 connect(ui.bOpen, &QPushButton::clicked, this, &CartesianPlotLegendDock::selectFile); 0116 connect(ui.leBackgroundFileName, &QLineEdit::returnPressed, this, &CartesianPlotLegendDock::fileNameChanged); 0117 connect(ui.leBackgroundFileName, &QLineEdit::textChanged, this, &CartesianPlotLegendDock::fileNameChanged); 0118 connect(ui.kcbBackgroundFirstColor, &KColorButton::changed, this, &CartesianPlotLegendDock::backgroundFirstColorChanged); 0119 connect(ui.kcbBackgroundSecondColor, &KColorButton::changed, this, &CartesianPlotLegendDock::backgroundSecondColorChanged); 0120 connect(ui.sbBackgroundOpacity, QOverload<int>::of(&QSpinBox::valueChanged), 0121 this, &CartesianPlotLegendDock::backgroundOpacityChanged); 0122 0123 //Border 0124 connect(ui.cbBorderStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0125 this, &CartesianPlotLegendDock::borderStyleChanged); 0126 connect(ui.kcbBorderColor, &KColorButton::changed, this, &CartesianPlotLegendDock::borderColorChanged); 0127 connect(ui.sbBorderWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0128 this, &CartesianPlotLegendDock::borderWidthChanged); 0129 connect(ui.sbBorderCornerRadius, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0130 this, &CartesianPlotLegendDock::borderCornerRadiusChanged); 0131 connect(ui.sbBorderOpacity, QOverload<int>::of(&QSpinBox::valueChanged), 0132 this, &CartesianPlotLegendDock::borderOpacityChanged); 0133 0134 //Layout 0135 connect(ui.sbLayoutTopMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0136 this, &CartesianPlotLegendDock::layoutTopMarginChanged); 0137 connect(ui.sbLayoutBottomMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0138 this, &CartesianPlotLegendDock::layoutBottomMarginChanged); 0139 connect(ui.sbLayoutLeftMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0140 this, &CartesianPlotLegendDock::layoutLeftMarginChanged); 0141 connect(ui.sbLayoutRightMargin, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0142 this, &CartesianPlotLegendDock::layoutRightMarginChanged); 0143 connect(ui.sbLayoutHorizontalSpacing, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0144 this, &CartesianPlotLegendDock::layoutHorizontalSpacingChanged); 0145 connect(ui.sbLayoutVerticalSpacing, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 0146 this, &CartesianPlotLegendDock::layoutVerticalSpacingChanged); 0147 connect(ui.sbLayoutColumnCount, QOverload<int>::of(&QSpinBox::valueChanged), 0148 this, &CartesianPlotLegendDock::layoutColumnCountChanged); 0149 0150 //template handler 0151 auto* frame = new QFrame(this); 0152 auto* layout = new QHBoxLayout(frame); 0153 layout->setContentsMargins(0, 11, 0, 11); 0154 0155 auto* templateHandler = new TemplateHandler(this, TemplateHandler::ClassName::CartesianPlotLegend); 0156 layout->addWidget(templateHandler); 0157 connect(templateHandler, &TemplateHandler::loadConfigRequested, this, &CartesianPlotLegendDock::loadConfigFromTemplate); 0158 connect(templateHandler, &TemplateHandler::saveConfigRequested, this, &CartesianPlotLegendDock::saveConfigAsTemplate); 0159 connect(templateHandler, &TemplateHandler::info, this, &CartesianPlotLegendDock::info); 0160 0161 ui.verticalLayout->addWidget(frame); 0162 0163 init(); 0164 } 0165 0166 void CartesianPlotLegendDock::init() { 0167 this->retranslateUi(); 0168 } 0169 0170 void CartesianPlotLegendDock::setLegends(QList<CartesianPlotLegend*> list) { 0171 Lock lock(m_initializing); 0172 m_legendList = list; 0173 m_legend = list.first(); 0174 m_aspect = list.first(); 0175 0176 //if there is more then one legend in the list, disable the tab "general" 0177 if (list.size() == 1) { 0178 ui.lName->setEnabled(true); 0179 ui.leName->setEnabled(true); 0180 ui.lComment->setEnabled(true); 0181 ui.leComment->setEnabled(true); 0182 0183 ui.leName->setText(m_legend->name()); 0184 ui.leComment->setText(m_legend->comment()); 0185 } else { 0186 ui.lName->setEnabled(false); 0187 ui.leName->setEnabled(false); 0188 ui.lComment->setEnabled(false); 0189 ui.leComment->setEnabled(false); 0190 0191 ui.leName->setText(QString()); 0192 ui.leComment->setText(QString()); 0193 } 0194 ui.leName->setStyleSheet(""); 0195 ui.leName->setToolTip(""); 0196 0197 //show the properties of the first curve 0198 this->load(); 0199 0200 //on the very first start the column count shown in UI is 1. 0201 //if the this count for m_legend is also 1 then the slot layoutColumnCountChanged is not called 0202 //and we need to disable the "order" widgets here. 0203 ui.lOrder->setVisible(m_legend->layoutColumnCount()!=1); 0204 ui.cbOrder->setVisible(m_legend->layoutColumnCount()!=1); 0205 0206 //legend title 0207 QList<TextLabel*> labels; 0208 for (auto* legend : list) 0209 labels.append(legend->title()); 0210 0211 labelWidget->setLabels(labels); 0212 0213 //update active widgets 0214 backgroundTypeChanged(ui.cbBackgroundType->currentIndex()); 0215 0216 //SIGNALs/SLOTs 0217 //General 0218 connect(m_legend, &AbstractAspect::aspectDescriptionChanged, this, &CartesianPlotLegendDock::legendDescriptionChanged); 0219 connect(m_legend, &CartesianPlotLegend::labelFontChanged, this, &CartesianPlotLegendDock::legendLabelFontChanged); 0220 connect(m_legend, &CartesianPlotLegend::labelColorChanged, this, &CartesianPlotLegendDock::legendLabelColorChanged); 0221 connect(m_legend, &CartesianPlotLegend::labelColumnMajorChanged, this, &CartesianPlotLegendDock::legendLabelOrderChanged); 0222 connect(m_legend, QOverload<const CartesianPlotLegend::PositionWrapper&>::of(&CartesianPlotLegend::positionChanged), 0223 this, &CartesianPlotLegendDock::legendPositionChanged); 0224 connect(m_legend, &CartesianPlotLegend::rotationAngleChanged, this, &CartesianPlotLegendDock::legendRotationAngleChanged); 0225 connect(m_legend, &CartesianPlotLegend::lineSymbolWidthChanged, this, &CartesianPlotLegendDock::legendLineSymbolWidthChanged); 0226 connect(m_legend, &CartesianPlotLegend::visibilityChanged, this, &CartesianPlotLegendDock::legendVisibilityChanged); 0227 0228 //background 0229 connect(m_legend, &CartesianPlotLegend::backgroundTypeChanged, this, &CartesianPlotLegendDock::legendBackgroundTypeChanged); 0230 connect(m_legend, &CartesianPlotLegend::backgroundColorStyleChanged, this, &CartesianPlotLegendDock::legendBackgroundColorStyleChanged); 0231 connect(m_legend, &CartesianPlotLegend::backgroundImageStyleChanged, this, &CartesianPlotLegendDock::legendBackgroundImageStyleChanged); 0232 connect(m_legend, &CartesianPlotLegend::backgroundBrushStyleChanged, this, &CartesianPlotLegendDock::legendBackgroundBrushStyleChanged); 0233 connect(m_legend, &CartesianPlotLegend::backgroundFirstColorChanged, this, &CartesianPlotLegendDock::legendBackgroundFirstColorChanged); 0234 connect(m_legend, &CartesianPlotLegend::backgroundSecondColorChanged, this, &CartesianPlotLegendDock::legendBackgroundSecondColorChanged); 0235 connect(m_legend, &CartesianPlotLegend::backgroundFileNameChanged, this, &CartesianPlotLegendDock::legendBackgroundFileNameChanged); 0236 connect(m_legend, &CartesianPlotLegend::backgroundOpacityChanged, this, &CartesianPlotLegendDock::legendBackgroundOpacityChanged); 0237 connect(m_legend, &CartesianPlotLegend::borderPenChanged, this, &CartesianPlotLegendDock::legendBorderPenChanged); 0238 connect(m_legend, &CartesianPlotLegend::borderCornerRadiusChanged, this, &CartesianPlotLegendDock::legendBorderCornerRadiusChanged); 0239 connect(m_legend, &CartesianPlotLegend::borderOpacityChanged, this, &CartesianPlotLegendDock::legendBorderOpacityChanged); 0240 0241 //layout 0242 connect(m_legend, &CartesianPlotLegend::layoutTopMarginChanged, this, &CartesianPlotLegendDock::legendLayoutTopMarginChanged); 0243 connect(m_legend, &CartesianPlotLegend::layoutBottomMarginChanged, this, &CartesianPlotLegendDock::legendLayoutBottomMarginChanged); 0244 connect(m_legend, &CartesianPlotLegend::layoutLeftMarginChanged, this, &CartesianPlotLegendDock::legendLayoutLeftMarginChanged); 0245 connect(m_legend, &CartesianPlotLegend::layoutRightMarginChanged, this, &CartesianPlotLegendDock::legendLayoutRightMarginChanged); 0246 connect(m_legend, &CartesianPlotLegend::layoutVerticalSpacingChanged, this, &CartesianPlotLegendDock::legendLayoutVerticalSpacingChanged); 0247 connect(m_legend, &CartesianPlotLegend::layoutHorizontalSpacingChanged, this, &CartesianPlotLegendDock::legendLayoutHorizontalSpacingChanged); 0248 connect(m_legend, &CartesianPlotLegend::layoutColumnCountChanged, this, &CartesianPlotLegendDock::legendLayoutColumnCountChanged); 0249 } 0250 0251 void CartesianPlotLegendDock::activateTitleTab() const{ 0252 ui.tabWidget->setCurrentWidget(ui.tabTitle); 0253 } 0254 0255 /* 0256 * updates the locale in the widgets. called when the application settins are changed. 0257 */ 0258 void CartesianPlotLegendDock::updateLocale() { 0259 SET_NUMBER_LOCALE 0260 ui.sbLineSymbolWidth->setLocale(numberLocale); 0261 ui.sbPositionX->setLocale(numberLocale); 0262 ui.sbPositionY->setLocale(numberLocale); 0263 ui.sbBorderWidth->setLocale(numberLocale); 0264 ui.sbBorderCornerRadius->setLocale(numberLocale); 0265 ui.sbLayoutTopMargin->setLocale(numberLocale); 0266 ui.sbLayoutBottomMargin->setLocale(numberLocale); 0267 ui.sbLayoutLeftMargin->setLocale(numberLocale); 0268 ui.sbLayoutRightMargin->setLocale(numberLocale); 0269 } 0270 0271 void CartesianPlotLegendDock::updateUnits() { 0272 const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General")); 0273 BaseDock::Units units = (BaseDock::Units)group.readEntry("Units", static_cast<int>(Units::Metric)); 0274 if (units == m_units) 0275 return; 0276 0277 m_units = units; 0278 Lock lock(m_initializing); 0279 QString suffix; 0280 if (m_units == Units::Metric) { 0281 //convert from imperial to metric 0282 m_worksheetUnit = Worksheet::Unit::Centimeter; 0283 suffix = QLatin1String(" cm"); 0284 ui.sbLineSymbolWidth->setValue(ui.sbLineSymbolWidth->value()*2.54); 0285 ui.sbPositionX->setValue(ui.sbPositionX->value()*2.54); 0286 ui.sbPositionY->setValue(ui.sbPositionY->value()*2.54); 0287 ui.sbBorderCornerRadius->setValue(ui.sbBorderCornerRadius->value()*2.54); 0288 ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()*2.54); 0289 ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()*2.54); 0290 ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()*2.54); 0291 ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()*2.54); 0292 ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()*2.54); 0293 ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()*2.54); 0294 } else { 0295 //convert from metric to imperial 0296 m_worksheetUnit = Worksheet::Unit::Inch; 0297 suffix = QLatin1String(" in"); 0298 ui.sbLineSymbolWidth->setValue(ui.sbLineSymbolWidth->value()/2.54); 0299 ui.sbPositionX->setValue(ui.sbPositionX->value()/2.54); 0300 ui.sbPositionY->setValue(ui.sbPositionY->value()/2.54); 0301 ui.sbBorderCornerRadius->setValue(ui.sbBorderCornerRadius->value()/2.54); 0302 ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()/2.54); 0303 ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()/2.54); 0304 ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()/2.54); 0305 ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()/2.54); 0306 ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()/2.54); 0307 ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()/2.54); 0308 } 0309 0310 ui.sbLineSymbolWidth->setSuffix(suffix); 0311 ui.sbPositionX->setSuffix(suffix); 0312 ui.sbPositionY->setSuffix(suffix); 0313 ui.sbBorderCornerRadius->setSuffix(suffix); 0314 ui.sbLayoutTopMargin->setSuffix(suffix); 0315 ui.sbLayoutBottomMargin->setSuffix(suffix); 0316 ui.sbLayoutLeftMargin->setSuffix(suffix); 0317 ui.sbLayoutRightMargin->setSuffix(suffix); 0318 ui.sbLayoutHorizontalSpacing->setSuffix(suffix); 0319 ui.sbLayoutVerticalSpacing->setSuffix(suffix); 0320 0321 labelWidget->updateUnits(); 0322 } 0323 0324 //************************************************************ 0325 //** SLOTs for changes triggered in CartesianPlotLegendDock ** 0326 //************************************************************ 0327 void CartesianPlotLegendDock::retranslateUi() { 0328 Lock lock(m_initializing); 0329 0330 ui.cbBackgroundType->addItem(i18n("Color")); 0331 ui.cbBackgroundType->addItem(i18n("Image")); 0332 ui.cbBackgroundType->addItem(i18n("Pattern")); 0333 0334 ui.cbBackgroundColorStyle->addItem(i18n("Single Color")); 0335 ui.cbBackgroundColorStyle->addItem(i18n("Horizontal Gradient")); 0336 ui.cbBackgroundColorStyle->addItem(i18n("Vertical Gradient")); 0337 ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Top Left)")); 0338 ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Bottom Left)")); 0339 ui.cbBackgroundColorStyle->addItem(i18n("Radial Gradient")); 0340 0341 ui.cbBackgroundImageStyle->addItem(i18n("Scaled and Cropped")); 0342 ui.cbBackgroundImageStyle->addItem(i18n("Scaled")); 0343 ui.cbBackgroundImageStyle->addItem(i18n("Scaled, Keep Proportions")); 0344 ui.cbBackgroundImageStyle->addItem(i18n("Centered")); 0345 ui.cbBackgroundImageStyle->addItem(i18n("Tiled")); 0346 ui.cbBackgroundImageStyle->addItem(i18n("Center Tiled")); 0347 0348 ui.cbOrder->addItem(i18n("Column Major")); 0349 ui.cbOrder->addItem(i18n("Row Major")); 0350 0351 ui.cbPositionX->addItem(i18n("Left")); 0352 ui.cbPositionX->addItem(i18n("Center")); 0353 ui.cbPositionX->addItem(i18n("Right")); 0354 ui.cbPositionX->addItem(i18n("Custom")); 0355 ui.cbPositionY->addItem(i18n("Top")); 0356 ui.cbPositionY->addItem(i18n("Center")); 0357 ui.cbPositionY->addItem(i18n("Bottom")); 0358 ui.cbPositionY->addItem(i18n("Custom")); 0359 0360 GuiTools::updatePenStyles(ui.cbBorderStyle, Qt::black); 0361 GuiTools::updateBrushStyles(ui.cbBackgroundBrushStyle, Qt::SolidPattern); 0362 0363 QString suffix; 0364 if (m_units == Units::Metric) 0365 suffix = QLatin1String(" cm"); 0366 else 0367 suffix = QLatin1String(" in"); 0368 0369 ui.sbLineSymbolWidth->setSuffix(suffix); 0370 ui.sbPositionX->setSuffix(suffix); 0371 ui.sbPositionY->setSuffix(suffix); 0372 ui.sbBorderCornerRadius->setSuffix(suffix); 0373 ui.sbLayoutTopMargin->setSuffix(suffix); 0374 ui.sbLayoutBottomMargin->setSuffix(suffix); 0375 ui.sbLayoutLeftMargin->setSuffix(suffix); 0376 ui.sbLayoutRightMargin->setSuffix(suffix); 0377 ui.sbLayoutHorizontalSpacing->setSuffix(suffix); 0378 ui.sbLayoutVerticalSpacing->setSuffix(suffix); 0379 } 0380 0381 // "General"-tab 0382 void CartesianPlotLegendDock::visibilityChanged(bool state) { 0383 if (m_initializing) 0384 return; 0385 0386 for (auto* legend : m_legendList) 0387 legend->setVisible(state); 0388 } 0389 0390 //General 0391 void CartesianPlotLegendDock::labelFontChanged(const QFont& font) { 0392 if (m_initializing) 0393 return; 0394 0395 QFont labelsFont = font; 0396 labelsFont.setPixelSize( Worksheet::convertToSceneUnits(font.pointSizeF(), Worksheet::Unit::Point) ); 0397 for (auto* legend : m_legendList) 0398 legend->setLabelFont(labelsFont); 0399 } 0400 0401 void CartesianPlotLegendDock::labelColorChanged(const QColor& color) { 0402 if (m_initializing) 0403 return; 0404 0405 for (auto* legend : m_legendList) 0406 legend->setLabelColor(color); 0407 } 0408 0409 void CartesianPlotLegendDock::labelOrderChanged(const int index) { 0410 if (m_initializing) 0411 return; 0412 0413 bool columnMajor = (index == 0); 0414 for (auto* legend : m_legendList) 0415 legend->setLabelColumnMajor(columnMajor); 0416 } 0417 0418 void CartesianPlotLegendDock::lineSymbolWidthChanged(double value) { 0419 if (m_initializing) 0420 return; 0421 0422 for (auto* legend : m_legendList) 0423 legend->setLineSymbolWidth(Worksheet::convertToSceneUnits(value, m_worksheetUnit)); 0424 } 0425 0426 /*! 0427 called when legend's current horizontal position relative to its parent (left, center, right, custom ) is changed. 0428 */ 0429 void CartesianPlotLegendDock::positionXChanged(int index) { 0430 //Enable/disable the spinbox for the x- oordinates if the "custom position"-item is selected/deselected 0431 if (index == ui.cbPositionX->count()-1 ) { 0432 ui.sbPositionX->setEnabled(true); 0433 } else { 0434 ui.sbPositionX->setEnabled(false); 0435 } 0436 0437 if (m_initializing) 0438 return; 0439 0440 CartesianPlotLegend::PositionWrapper position = m_legend->position(); 0441 position.horizontalPosition = CartesianPlotLegend::HorizontalPosition(index); 0442 for (auto* legend : m_legendList) 0443 legend->setPosition(position); 0444 } 0445 0446 /*! 0447 called when legend's current horizontal position relative to its parent (top, center, bottom, custom ) is changed. 0448 */ 0449 void CartesianPlotLegendDock::positionYChanged(int index) { 0450 //Enable/disable the spinbox for the y- oordinates if the "custom position"-item is selected/deselected 0451 if (index == ui.cbPositionY->count()-1 ) { 0452 ui.sbPositionY->setEnabled(true); 0453 } else { 0454 ui.sbPositionY->setEnabled(false); 0455 } 0456 0457 if (m_initializing) 0458 return; 0459 0460 CartesianPlotLegend::PositionWrapper position = m_legend->position(); 0461 position.verticalPosition = CartesianPlotLegend::VerticalPosition(index); 0462 for (auto* legend : m_legendList) 0463 legend->setPosition(position); 0464 } 0465 0466 void CartesianPlotLegendDock::customPositionXChanged(double value) { 0467 if (m_initializing) 0468 return; 0469 0470 CartesianPlotLegend::PositionWrapper position = m_legend->position(); 0471 position.point.setX(Worksheet::convertToSceneUnits(value, m_worksheetUnit)); 0472 for (auto* legend : m_legendList) 0473 legend->setPosition(position); 0474 } 0475 0476 void CartesianPlotLegendDock::customPositionYChanged(double value) { 0477 if (m_initializing) 0478 return; 0479 0480 CartesianPlotLegend::PositionWrapper position = m_legend->position(); 0481 position.point.setY(Worksheet::convertToSceneUnits(value, m_worksheetUnit)); 0482 for (auto* legend : m_legendList) 0483 legend->setPosition(position); 0484 } 0485 0486 void CartesianPlotLegendDock::rotationChanged(int value) { 0487 if (m_initializing) 0488 return; 0489 0490 for (auto* curve : m_legendList) 0491 curve->setRotationAngle(value); 0492 } 0493 0494 // "Background"-tab 0495 void CartesianPlotLegendDock::backgroundTypeChanged(int index) { 0496 const auto type = (PlotArea::BackgroundType)index; 0497 0498 if (type == PlotArea::BackgroundType::Color) { 0499 ui.lBackgroundColorStyle->show(); 0500 ui.cbBackgroundColorStyle->show(); 0501 ui.lBackgroundImageStyle->hide(); 0502 ui.cbBackgroundImageStyle->hide(); 0503 ui.lBackgroundBrushStyle->hide(); 0504 ui.cbBackgroundBrushStyle->hide(); 0505 0506 ui.lBackgroundFileName->hide(); 0507 ui.leBackgroundFileName->hide(); 0508 ui.bOpen->hide(); 0509 0510 ui.lBackgroundFirstColor->show(); 0511 ui.kcbBackgroundFirstColor->show(); 0512 0513 auto style = (PlotArea::BackgroundColorStyle) ui.cbBackgroundColorStyle->currentIndex(); 0514 if (style == PlotArea::BackgroundColorStyle::SingleColor) { 0515 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0516 ui.lBackgroundSecondColor->hide(); 0517 ui.kcbBackgroundSecondColor->hide(); 0518 } else { 0519 ui.lBackgroundFirstColor->setText(i18n("First color:")); 0520 ui.lBackgroundSecondColor->show(); 0521 ui.kcbBackgroundSecondColor->show(); 0522 } 0523 } else if (type == PlotArea::BackgroundType::Image) { 0524 ui.lBackgroundColorStyle->hide(); 0525 ui.cbBackgroundColorStyle->hide(); 0526 ui.lBackgroundImageStyle->show(); 0527 ui.cbBackgroundImageStyle->show(); 0528 ui.lBackgroundBrushStyle->hide(); 0529 ui.cbBackgroundBrushStyle->hide(); 0530 ui.lBackgroundFileName->show(); 0531 ui.leBackgroundFileName->show(); 0532 ui.bOpen->show(); 0533 0534 ui.lBackgroundFirstColor->hide(); 0535 ui.kcbBackgroundFirstColor->hide(); 0536 ui.lBackgroundSecondColor->hide(); 0537 ui.kcbBackgroundSecondColor->hide(); 0538 } else if (type == PlotArea::BackgroundType::Pattern) { 0539 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0540 ui.lBackgroundColorStyle->hide(); 0541 ui.cbBackgroundColorStyle->hide(); 0542 ui.lBackgroundImageStyle->hide(); 0543 ui.cbBackgroundImageStyle->hide(); 0544 ui.lBackgroundBrushStyle->show(); 0545 ui.cbBackgroundBrushStyle->show(); 0546 ui.lBackgroundFileName->hide(); 0547 ui.leBackgroundFileName->hide(); 0548 ui.bOpen->hide(); 0549 0550 ui.lBackgroundFirstColor->show(); 0551 ui.kcbBackgroundFirstColor->show(); 0552 ui.lBackgroundSecondColor->hide(); 0553 ui.kcbBackgroundSecondColor->hide(); 0554 } 0555 0556 if (m_initializing) 0557 return; 0558 0559 for (auto* legend : m_legendList) 0560 legend->setBackgroundType(type); 0561 } 0562 0563 void CartesianPlotLegendDock::backgroundColorStyleChanged(int index) { 0564 auto style = (PlotArea::BackgroundColorStyle)index; 0565 0566 if (style == PlotArea::BackgroundColorStyle::SingleColor) { 0567 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0568 ui.lBackgroundSecondColor->hide(); 0569 ui.kcbBackgroundSecondColor->hide(); 0570 } else { 0571 ui.lBackgroundFirstColor->setText(i18n("First color:")); 0572 ui.lBackgroundSecondColor->show(); 0573 ui.kcbBackgroundSecondColor->show(); 0574 ui.lBackgroundBrushStyle->hide(); 0575 ui.cbBackgroundBrushStyle->hide(); 0576 } 0577 0578 if (m_initializing) 0579 return; 0580 0581 for (auto* legend : m_legendList) 0582 legend->setBackgroundColorStyle(style); 0583 } 0584 0585 void CartesianPlotLegendDock::backgroundImageStyleChanged(int index) { 0586 if (m_initializing) 0587 return; 0588 0589 auto style = (PlotArea::BackgroundImageStyle)index; 0590 for (auto* legend : m_legendList) 0591 legend->setBackgroundImageStyle(style); 0592 } 0593 0594 void CartesianPlotLegendDock::backgroundBrushStyleChanged(int index) { 0595 if (m_initializing) 0596 return; 0597 0598 auto style = (Qt::BrushStyle)index; 0599 for (auto* legend : m_legendList) 0600 legend->setBackgroundBrushStyle(style); 0601 } 0602 0603 void CartesianPlotLegendDock::backgroundFirstColorChanged(const QColor& c) { 0604 if (m_initializing) 0605 return; 0606 0607 for (auto* legend : m_legendList) 0608 legend->setBackgroundFirstColor(c); 0609 } 0610 0611 void CartesianPlotLegendDock::backgroundSecondColorChanged(const QColor& c) { 0612 if (m_initializing) 0613 return; 0614 0615 for (auto* legend : m_legendList) 0616 legend->setBackgroundSecondColor(c); 0617 } 0618 0619 /*! 0620 opens a file dialog and lets the user select the image file. 0621 */ 0622 void CartesianPlotLegendDock::selectFile() { 0623 KConfigGroup conf(KSharedConfig::openConfig(), "CartesianPlotLegendDock"); 0624 QString dir = conf.readEntry("LastImageDir", ""); 0625 0626 QString formats; 0627 for (const QByteArray& format : QImageReader::supportedImageFormats()) { 0628 QString f = "*." + QString(format.constData()); 0629 if (f == QLatin1String("*.svg")) 0630 continue; 0631 formats.isEmpty() ? formats += f : formats += ' ' + f; 0632 } 0633 0634 QString path = QFileDialog::getOpenFileName(this, i18n("Select the image file"), dir, i18n("Images (%1)", formats)); 0635 if (path.isEmpty()) 0636 return; //cancel was clicked in the file-dialog 0637 0638 int pos = path.lastIndexOf(QLatin1String("/")); 0639 if (pos != -1) { 0640 QString newDir = path.left(pos); 0641 if (newDir != dir) 0642 conf.writeEntry("LastImageDir", newDir); 0643 } 0644 0645 ui.leBackgroundFileName->setText( path ); 0646 0647 for (auto* legend : m_legendList) 0648 legend->setBackgroundFileName(path); 0649 } 0650 0651 void CartesianPlotLegendDock::fileNameChanged() { 0652 if (m_initializing) 0653 return; 0654 0655 const QString& fileName = ui.leBackgroundFileName->text(); 0656 bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName)); 0657 GuiTools::highlight(ui.leBackgroundFileName, invalid); 0658 0659 for (auto* legend : m_legendList) 0660 legend->setBackgroundFileName(fileName); 0661 } 0662 0663 void CartesianPlotLegendDock::backgroundOpacityChanged(int value) { 0664 if (m_initializing) 0665 return; 0666 0667 float opacity = (float)value/100.; 0668 for (auto* legend : m_legendList) 0669 legend->setBackgroundOpacity(opacity); 0670 } 0671 0672 // "Border"-tab 0673 void CartesianPlotLegendDock::borderStyleChanged(int index) { 0674 if (m_initializing) 0675 return; 0676 0677 auto penStyle = Qt::PenStyle(index); 0678 QPen pen; 0679 for (auto* legend : m_legendList) { 0680 pen = legend->borderPen(); 0681 pen.setStyle(penStyle); 0682 legend->setBorderPen(pen); 0683 } 0684 } 0685 0686 void CartesianPlotLegendDock::borderColorChanged(const QColor& color) { 0687 if (m_initializing) 0688 return; 0689 0690 QPen pen; 0691 for (auto* legend : m_legendList) { 0692 pen = legend->borderPen(); 0693 pen.setColor(color); 0694 legend->setBorderPen(pen); 0695 } 0696 0697 m_initializing = true; 0698 GuiTools::updatePenStyles(ui.cbBorderStyle, color); 0699 m_initializing = false; 0700 } 0701 0702 void CartesianPlotLegendDock::borderWidthChanged(double value) { 0703 if (m_initializing) 0704 return; 0705 0706 QPen pen; 0707 for (auto* legend : m_legendList) { 0708 pen = legend->borderPen(); 0709 pen.setWidthF( Worksheet::convertToSceneUnits(value, Worksheet::Unit::Point) ); 0710 legend->setBorderPen(pen); 0711 } 0712 } 0713 0714 void CartesianPlotLegendDock::borderCornerRadiusChanged(double value) { 0715 if (m_initializing) 0716 return; 0717 0718 for (auto* legend : m_legendList) 0719 legend->setBorderCornerRadius(Worksheet::convertToSceneUnits(value, m_worksheetUnit)); 0720 } 0721 0722 void CartesianPlotLegendDock::borderOpacityChanged(int value) { 0723 if (m_initializing) 0724 return; 0725 0726 double opacity = (double)value/100.; 0727 for (auto* legend : m_legendList) 0728 legend->setBorderOpacity(opacity); 0729 } 0730 0731 //Layout 0732 void CartesianPlotLegendDock::layoutTopMarginChanged(double margin) { 0733 if (m_initializing) 0734 return; 0735 0736 for (auto* legend : m_legendList) 0737 legend->setLayoutTopMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0738 } 0739 0740 void CartesianPlotLegendDock::layoutBottomMarginChanged(double margin) { 0741 if (m_initializing) 0742 return; 0743 0744 for (auto* legend : m_legendList) 0745 legend->setLayoutBottomMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0746 } 0747 0748 void CartesianPlotLegendDock::layoutLeftMarginChanged(double margin) { 0749 if (m_initializing) 0750 return; 0751 0752 for (auto* legend : m_legendList) 0753 legend->setLayoutLeftMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0754 } 0755 0756 void CartesianPlotLegendDock::layoutRightMarginChanged(double margin) { 0757 if (m_initializing) 0758 return; 0759 0760 for (auto* legend : m_legendList) 0761 legend->setLayoutRightMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0762 } 0763 0764 void CartesianPlotLegendDock::layoutHorizontalSpacingChanged(double spacing) { 0765 if (m_initializing) 0766 return; 0767 0768 for (auto* legend : m_legendList) 0769 legend->setLayoutHorizontalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit)); 0770 } 0771 0772 void CartesianPlotLegendDock::layoutVerticalSpacingChanged(double spacing) { 0773 if (m_initializing) 0774 return; 0775 0776 for (auto* legend : m_legendList) 0777 legend->setLayoutVerticalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit)); 0778 } 0779 0780 void CartesianPlotLegendDock::layoutColumnCountChanged(int count) { 0781 ui.lOrder->setVisible(count!=1); 0782 ui.cbOrder->setVisible(count!=1); 0783 0784 if (m_initializing) 0785 return; 0786 0787 for (auto* legend : m_legendList) 0788 legend->setLayoutColumnCount(count); 0789 } 0790 0791 //************************************************************* 0792 //**** SLOTs for changes triggered in CartesianPlotLegend ***** 0793 //************************************************************* 0794 //General 0795 void CartesianPlotLegendDock::legendDescriptionChanged(const AbstractAspect* aspect) { 0796 if (m_legend != aspect) 0797 return; 0798 0799 m_initializing = true; 0800 if (aspect->name() != ui.leName->text()) { 0801 ui.leName->setText(aspect->name()); 0802 } else if (aspect->comment() != ui.leComment->text()) { 0803 ui.leComment->setText(aspect->comment()); 0804 } 0805 m_initializing = false; 0806 } 0807 0808 void CartesianPlotLegendDock::legendLabelFontChanged(QFont& font) { 0809 m_initializing = true; 0810 //we need to set the font size in points for KFontRequester 0811 QFont f(font); 0812 f.setPointSizeF( Worksheet::convertFromSceneUnits(f.pixelSize(), Worksheet::Unit::Point) ); 0813 ui.kfrLabelFont->setFont(f); 0814 m_initializing = false; 0815 } 0816 0817 void CartesianPlotLegendDock::legendLabelColorChanged(QColor& color) { 0818 m_initializing = true; 0819 ui.kcbLabelColor->setColor(color); 0820 m_initializing = false; 0821 } 0822 0823 void CartesianPlotLegendDock::legendLabelOrderChanged(bool b) { 0824 m_initializing = true; 0825 if (b) 0826 ui.cbOrder->setCurrentIndex(0); //column major 0827 else 0828 ui.cbOrder->setCurrentIndex(1); //row major 0829 m_initializing = false; 0830 } 0831 0832 void CartesianPlotLegendDock::legendLineSymbolWidthChanged(float value) { 0833 m_initializing = true; 0834 ui.sbLineSymbolWidth->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0835 m_initializing = false; 0836 } 0837 0838 0839 void CartesianPlotLegendDock::legendPositionChanged(const CartesianPlotLegend::PositionWrapper& position) { 0840 m_initializing = true; 0841 ui.sbPositionX->setValue( Worksheet::convertFromSceneUnits(position.point.x(), m_worksheetUnit) ); 0842 ui.sbPositionY->setValue( Worksheet::convertFromSceneUnits(position.point.y(), m_worksheetUnit) ); 0843 ui.cbPositionX->setCurrentIndex( static_cast<int>(position.horizontalPosition) ); 0844 ui.cbPositionY->setCurrentIndex( static_cast<int>(position.verticalPosition) ); 0845 m_initializing = false; 0846 } 0847 0848 void CartesianPlotLegendDock::legendRotationAngleChanged(qreal angle) { 0849 m_initializing = true; 0850 ui.sbRotation->setValue(angle); 0851 m_initializing = false; 0852 } 0853 0854 void CartesianPlotLegendDock::legendVisibilityChanged(bool on) { 0855 m_initializing = true; 0856 ui.chkVisible->setChecked(on); 0857 m_initializing = false; 0858 } 0859 0860 //Background 0861 void CartesianPlotLegendDock::legendBackgroundTypeChanged(PlotArea::BackgroundType type) { 0862 m_initializing = true; 0863 ui.cbBackgroundType->setCurrentIndex(static_cast<int>(type)); 0864 m_initializing = false; 0865 } 0866 0867 void CartesianPlotLegendDock::legendBackgroundColorStyleChanged(PlotArea::BackgroundColorStyle style) { 0868 m_initializing = true; 0869 ui.cbBackgroundColorStyle->setCurrentIndex(static_cast<int>(style)); 0870 m_initializing = false; 0871 } 0872 0873 void CartesianPlotLegendDock::legendBackgroundImageStyleChanged(PlotArea::BackgroundImageStyle style) { 0874 m_initializing = true; 0875 ui.cbBackgroundImageStyle->setCurrentIndex(static_cast<int>(style)); 0876 m_initializing = false; 0877 } 0878 0879 void CartesianPlotLegendDock::legendBackgroundBrushStyleChanged(Qt::BrushStyle style) { 0880 m_initializing = true; 0881 ui.cbBackgroundBrushStyle->setCurrentIndex(style); 0882 m_initializing = false; 0883 } 0884 0885 void CartesianPlotLegendDock::legendBackgroundFirstColorChanged(QColor& color) { 0886 m_initializing = true; 0887 ui.kcbBackgroundFirstColor->setColor(color); 0888 m_initializing = false; 0889 } 0890 0891 void CartesianPlotLegendDock::legendBackgroundSecondColorChanged(QColor& color) { 0892 m_initializing = true; 0893 ui.kcbBackgroundSecondColor->setColor(color); 0894 m_initializing = false; 0895 } 0896 0897 void CartesianPlotLegendDock::legendBackgroundFileNameChanged(QString& filename) { 0898 m_initializing = true; 0899 ui.leBackgroundFileName->setText(filename); 0900 m_initializing = false; 0901 } 0902 0903 void CartesianPlotLegendDock::legendBackgroundOpacityChanged(float opacity) { 0904 m_initializing = true; 0905 ui.sbBackgroundOpacity->setValue( qRound(opacity*100.0) ); 0906 m_initializing = false; 0907 } 0908 0909 //Border 0910 void CartesianPlotLegendDock::legendBorderPenChanged(QPen& pen) { 0911 if (m_initializing) 0912 return; 0913 0914 m_initializing = true; 0915 if (ui.cbBorderStyle->currentIndex() != pen.style()) 0916 ui.cbBorderStyle->setCurrentIndex(pen.style()); 0917 if (ui.kcbBorderColor->color() != pen.color()) 0918 ui.kcbBorderColor->setColor(pen.color()); 0919 if (ui.sbBorderWidth->value() != pen.widthF()) 0920 ui.sbBorderWidth->setValue(Worksheet::convertFromSceneUnits(pen.widthF(), Worksheet::Unit::Point)); 0921 m_initializing = false; 0922 } 0923 0924 void CartesianPlotLegendDock::legendBorderCornerRadiusChanged(float value) { 0925 m_initializing = true; 0926 ui.sbBorderCornerRadius->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0927 m_initializing = false; 0928 } 0929 0930 void CartesianPlotLegendDock::legendBorderOpacityChanged(float opacity) { 0931 m_initializing = true; 0932 ui.sbBorderOpacity->setValue( qRound(opacity*100.0) ); 0933 m_initializing = false; 0934 } 0935 0936 //Layout 0937 void CartesianPlotLegendDock::legendLayoutTopMarginChanged(float value) { 0938 m_initializing = true; 0939 ui.sbLayoutTopMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0940 m_initializing = false; 0941 } 0942 0943 void CartesianPlotLegendDock::legendLayoutBottomMarginChanged(float value) { 0944 m_initializing = true; 0945 ui.sbLayoutBottomMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0946 m_initializing = false; 0947 } 0948 0949 void CartesianPlotLegendDock::legendLayoutLeftMarginChanged(float value) { 0950 m_initializing = true; 0951 ui.sbLayoutLeftMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0952 m_initializing = false; 0953 } 0954 0955 void CartesianPlotLegendDock::legendLayoutRightMarginChanged(float value) { 0956 m_initializing = true; 0957 ui.sbLayoutRightMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0958 m_initializing = false; 0959 } 0960 0961 void CartesianPlotLegendDock::legendLayoutVerticalSpacingChanged(float value) { 0962 m_initializing = true; 0963 ui.sbLayoutVerticalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0964 m_initializing = false; 0965 } 0966 0967 void CartesianPlotLegendDock::legendLayoutHorizontalSpacingChanged(float value) { 0968 m_initializing = true; 0969 ui.sbLayoutHorizontalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0970 m_initializing = false; 0971 } 0972 0973 void CartesianPlotLegendDock::legendLayoutColumnCountChanged(int value) { 0974 m_initializing = true; 0975 ui.sbLayoutColumnCount->setValue(value); 0976 m_initializing = false; 0977 } 0978 0979 //************************************************************* 0980 //******************** SETTINGS ******************************* 0981 //************************************************************* 0982 void CartesianPlotLegendDock::load() { 0983 //General-tab 0984 0985 //Format 0986 //we need to set the font size in points for KFontRequester 0987 QFont font = m_legend->labelFont(); 0988 font.setPointSizeF( qRound(Worksheet::convertFromSceneUnits(font.pixelSize(), Worksheet::Unit::Point)) ); 0989 ui.kfrLabelFont->setFont(font); 0990 0991 ui.kcbLabelColor->setColor( m_legend->labelColor() ); 0992 bool columnMajor = m_legend->labelColumnMajor(); 0993 if (columnMajor) 0994 ui.cbOrder->setCurrentIndex(0); //column major 0995 else 0996 ui.cbOrder->setCurrentIndex(1); //row major 0997 0998 ui.sbLineSymbolWidth->setValue( Worksheet::convertFromSceneUnits(m_legend->lineSymbolWidth(), m_worksheetUnit) ); 0999 1000 //Geometry 1001 ui.cbPositionX->setCurrentIndex(static_cast<int>(m_legend->position().horizontalPosition)); 1002 ui.sbPositionX->setValue( Worksheet::convertFromSceneUnits(m_legend->position().point.x(), m_worksheetUnit) ); 1003 ui.cbPositionY->setCurrentIndex(static_cast<int>(m_legend->position().verticalPosition)); 1004 ui.sbPositionY->setValue( Worksheet::convertFromSceneUnits(m_legend->position().point.y(), m_worksheetUnit) ); 1005 ui.sbRotation->setValue(m_legend->rotationAngle()); 1006 1007 ui.chkVisible->setChecked( m_legend->isVisible() ); 1008 1009 //Background-tab 1010 ui.cbBackgroundType->setCurrentIndex( (int) m_legend->backgroundType() ); 1011 ui.cbBackgroundColorStyle->setCurrentIndex( (int) m_legend->backgroundColorStyle() ); 1012 ui.cbBackgroundImageStyle->setCurrentIndex( (int) m_legend->backgroundImageStyle() ); 1013 ui.cbBackgroundBrushStyle->setCurrentIndex( (int) m_legend->backgroundBrushStyle() ); 1014 ui.leBackgroundFileName->setText( m_legend->backgroundFileName() ); 1015 ui.kcbBackgroundFirstColor->setColor( m_legend->backgroundFirstColor() ); 1016 ui.kcbBackgroundSecondColor->setColor( m_legend->backgroundSecondColor() ); 1017 ui.sbBackgroundOpacity->setValue( qRound(m_legend->backgroundOpacity()*100.0) ); 1018 1019 //highlight the text field for the background image red if an image is used and cannot be found 1020 const QString& fileName = m_legend->backgroundFileName(); 1021 bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName)); 1022 GuiTools::highlight(ui.leBackgroundFileName, invalid); 1023 1024 //Border 1025 ui.kcbBorderColor->setColor( m_legend->borderPen().color() ); 1026 ui.cbBorderStyle->setCurrentIndex( (int) m_legend->borderPen().style() ); 1027 ui.sbBorderWidth->setValue( Worksheet::convertFromSceneUnits(m_legend->borderPen().widthF(), Worksheet::Unit::Point) ); 1028 ui.sbBorderCornerRadius->setValue( Worksheet::convertFromSceneUnits(m_legend->borderCornerRadius(), m_worksheetUnit) ); 1029 ui.sbBorderOpacity->setValue( qRound(m_legend->borderOpacity()*100.0) ); 1030 1031 // Layout 1032 ui.sbLayoutTopMargin->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutTopMargin(), m_worksheetUnit) ); 1033 ui.sbLayoutBottomMargin->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutBottomMargin(), m_worksheetUnit) ); 1034 ui.sbLayoutLeftMargin->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutLeftMargin(), m_worksheetUnit) ); 1035 ui.sbLayoutRightMargin->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutRightMargin(), m_worksheetUnit) ); 1036 ui.sbLayoutHorizontalSpacing->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutHorizontalSpacing(), m_worksheetUnit) ); 1037 ui.sbLayoutVerticalSpacing->setValue( Worksheet::convertFromSceneUnits(m_legend->layoutVerticalSpacing(), m_worksheetUnit) ); 1038 1039 ui.sbLayoutColumnCount->setValue( m_legend->layoutColumnCount() ); 1040 1041 m_initializing = true; 1042 GuiTools::updatePenStyles(ui.cbBorderStyle, ui.kcbBorderColor->color()); 1043 m_initializing = false; 1044 } 1045 1046 void CartesianPlotLegendDock::loadConfigFromTemplate(KConfig& config) { 1047 //extract the name of the template from the file name 1048 QString name; 1049 int index = config.name().lastIndexOf(QLatin1String("/")); 1050 if (index != -1) 1051 name = config.name().right(config.name().size() - index - 1); 1052 else 1053 name = config.name(); 1054 1055 int size = m_legendList.size(); 1056 if (size > 1) 1057 m_legend->beginMacro(i18n("%1 cartesian plot legends: template \"%2\" loaded", size, name)); 1058 else 1059 m_legend->beginMacro(i18n("%1: template \"%2\" loaded", m_legend->name(), name)); 1060 1061 this->loadConfig(config); 1062 1063 m_legend->endMacro(); 1064 } 1065 1066 void CartesianPlotLegendDock::loadConfig(KConfig& config) { 1067 KConfigGroup group = config.group( "CartesianPlotLegend" ); 1068 1069 //General-tab 1070 1071 //Format 1072 //we need to set the font size in points for KFontRequester 1073 QFont font = m_legend->labelFont(); 1074 font.setPointSizeF( qRound(Worksheet::convertFromSceneUnits(font.pixelSize(), Worksheet::Unit::Point)) ); 1075 ui.kfrLabelFont->setFont( group.readEntry("LabelFont", font) ); 1076 1077 ui.kcbLabelColor->setColor( group.readEntry("LabelColor", m_legend->labelColor()) ); 1078 1079 bool columnMajor = group.readEntry("LabelColumMajor", m_legend->labelColumnMajor()); 1080 if (columnMajor) 1081 ui.cbOrder->setCurrentIndex(0); //column major 1082 else 1083 ui.cbOrder->setCurrentIndex(1); //row major 1084 1085 ui.sbLineSymbolWidth->setValue(group.readEntry("LineSymbolWidth", Worksheet::convertFromSceneUnits(m_legend->lineSymbolWidth(), m_worksheetUnit)) ); 1086 1087 // Geometry 1088 ui.cbPositionX->setCurrentIndex( group.readEntry("PositionX", (int) m_legend->position().horizontalPosition ) ); 1089 ui.sbPositionX->setValue( Worksheet::convertFromSceneUnits(group.readEntry("PositionXValue", m_legend->position().point.x()),m_worksheetUnit) ); 1090 ui.cbPositionY->setCurrentIndex( group.readEntry("PositionY", (int) m_legend->position().verticalPosition ) ); 1091 ui.sbPositionY->setValue( Worksheet::convertFromSceneUnits(group.readEntry("PositionYValue", m_legend->position().point.y()),m_worksheetUnit) ); 1092 ui.sbRotation->setValue( group.readEntry("Rotation", (int) m_legend->rotationAngle() ) ); 1093 1094 ui.chkVisible->setChecked( group.readEntry("Visible", m_legend->isVisible()) ); 1095 1096 //Background-tab 1097 ui.cbBackgroundType->setCurrentIndex( group.readEntry("BackgroundType", (int) m_legend->backgroundType()) ); 1098 ui.cbBackgroundColorStyle->setCurrentIndex( group.readEntry("BackgroundColorStyle", (int) m_legend->backgroundColorStyle()) ); 1099 ui.cbBackgroundImageStyle->setCurrentIndex( group.readEntry("BackgroundImageStyle", (int) m_legend->backgroundImageStyle()) ); 1100 ui.cbBackgroundBrushStyle->setCurrentIndex( group.readEntry("BackgroundBrushStyle", (int) m_legend->backgroundBrushStyle()) ); 1101 ui.leBackgroundFileName->setText( group.readEntry("BackgroundFileName", m_legend->backgroundFileName()) ); 1102 ui.kcbBackgroundFirstColor->setColor( group.readEntry("BackgroundFirstColor", m_legend->backgroundFirstColor()) ); 1103 ui.kcbBackgroundSecondColor->setColor( group.readEntry("BackgroundSecondColor", m_legend->backgroundSecondColor()) ); 1104 ui.sbBackgroundOpacity->setValue( qRound(group.readEntry("BackgroundOpacity", m_legend->backgroundOpacity())*100.0) ); 1105 1106 //Border 1107 ui.kcbBorderColor->setColor( group.readEntry("BorderColor", m_legend->borderPen().color()) ); 1108 ui.cbBorderStyle->setCurrentIndex( group.readEntry("BorderStyle", (int) m_legend->borderPen().style()) ); 1109 ui.sbBorderWidth->setValue( Worksheet::convertFromSceneUnits(group.readEntry("BorderWidth", m_legend->borderPen().widthF()), Worksheet::Unit::Point) ); 1110 ui.sbBorderCornerRadius->setValue( Worksheet::convertFromSceneUnits(group.readEntry("BorderCornerRadius", m_legend->borderCornerRadius()), m_worksheetUnit) ); 1111 ui.sbBorderOpacity->setValue( qRound(group.readEntry("BorderOpacity", m_legend->borderOpacity())*100.0) ); 1112 1113 // Layout 1114 ui.sbLayoutTopMargin->setValue(group.readEntry("LayoutTopMargin", Worksheet::convertFromSceneUnits(m_legend->layoutTopMargin(), m_worksheetUnit)) ); 1115 ui.sbLayoutBottomMargin->setValue(group.readEntry("LayoutBottomMargin", Worksheet::convertFromSceneUnits(m_legend->layoutBottomMargin(), m_worksheetUnit)) ); 1116 ui.sbLayoutLeftMargin->setValue(group.readEntry("LayoutLeftMargin", Worksheet::convertFromSceneUnits(m_legend->layoutLeftMargin(), m_worksheetUnit)) ); 1117 ui.sbLayoutRightMargin->setValue(group.readEntry("LayoutRightMargin", Worksheet::convertFromSceneUnits(m_legend->layoutRightMargin(), m_worksheetUnit)) ); 1118 ui.sbLayoutHorizontalSpacing->setValue(group.readEntry("LayoutHorizontalSpacing", Worksheet::convertFromSceneUnits(m_legend->layoutHorizontalSpacing(), m_worksheetUnit)) ); 1119 ui.sbLayoutVerticalSpacing->setValue(group.readEntry("LayoutVerticalSpacing", Worksheet::convertFromSceneUnits(m_legend->layoutVerticalSpacing(), m_worksheetUnit)) ); 1120 ui.sbLayoutColumnCount->setValue(group.readEntry("LayoutColumnCount", m_legend->layoutColumnCount())); 1121 1122 //Title 1123 group = config.group("PlotLegend"); 1124 labelWidget->loadConfig(group); 1125 1126 m_initializing = true; 1127 GuiTools::updatePenStyles(ui.cbBorderStyle, ui.kcbBorderColor->color()); 1128 m_initializing = false; 1129 } 1130 1131 void CartesianPlotLegendDock::saveConfigAsTemplate(KConfig& config) { 1132 KConfigGroup group = config.group( "CartesianPlotLegend" ); 1133 1134 //General-tab 1135 //Format 1136 QFont font = m_legend->labelFont(); 1137 font.setPointSizeF( Worksheet::convertFromSceneUnits(font.pointSizeF(), Worksheet::Unit::Point) ); 1138 group.writeEntry("LabelFont", font); 1139 group.writeEntry("LabelColor", ui.kcbLabelColor->color()); 1140 group.writeEntry("LabelColumMajorOrder", ui.cbOrder->currentIndex() == 0);// true for "column major", false for "row major" 1141 group.writeEntry("LineSymbolWidth", Worksheet::convertToSceneUnits(ui.sbLineSymbolWidth->value(), m_worksheetUnit)); 1142 1143 //Geometry 1144 group.writeEntry("PositionX", ui.cbPositionX->currentIndex()); 1145 group.writeEntry("PositionXValue", Worksheet::convertToSceneUnits(ui.sbPositionX->value(),m_worksheetUnit) ); 1146 group.writeEntry("PositionY", ui.cbPositionY->currentIndex()); 1147 group.writeEntry("PositionYValue", Worksheet::convertToSceneUnits(ui.sbPositionY->value(),m_worksheetUnit) ); 1148 group.writeEntry("Rotation", ui.sbRotation->value()); 1149 1150 group.writeEntry("Visible", ui.chkVisible->isChecked()); 1151 1152 //Background 1153 group.writeEntry("BackgroundType", ui.cbBackgroundType->currentIndex()); 1154 group.writeEntry("BackgroundColorStyle", ui.cbBackgroundColorStyle->currentIndex()); 1155 group.writeEntry("BackgroundImageStyle", ui.cbBackgroundImageStyle->currentIndex()); 1156 group.writeEntry("BackgroundBrushStyle", ui.cbBackgroundBrushStyle->currentIndex()); 1157 group.writeEntry("BackgroundFileName", ui.leBackgroundFileName->text()); 1158 group.writeEntry("BackgroundFirstColor", ui.kcbBackgroundFirstColor->color()); 1159 group.writeEntry("BackgroundSecondColor", ui.kcbBackgroundSecondColor->color()); 1160 group.writeEntry("BackgroundOpacity", ui.sbBackgroundOpacity->value()/100.0); 1161 1162 //Border 1163 group.writeEntry("BorderStyle", ui.cbBorderStyle->currentIndex()); 1164 group.writeEntry("BorderColor", ui.kcbBorderColor->color()); 1165 group.writeEntry("BorderWidth", Worksheet::convertToSceneUnits(ui.sbBorderWidth->value(), Worksheet::Unit::Point)); 1166 group.writeEntry("BorderCornerRadius", Worksheet::convertToSceneUnits(ui.sbBorderCornerRadius->value(), m_worksheetUnit)); 1167 group.writeEntry("BorderOpacity", ui.sbBorderOpacity->value()/100.0); 1168 1169 //Layout 1170 group.writeEntry("LayoutTopMargin",Worksheet::convertToSceneUnits(ui.sbLayoutTopMargin->value(), m_worksheetUnit)); 1171 group.writeEntry("LayoutBottomMargin",Worksheet::convertToSceneUnits(ui.sbLayoutBottomMargin->value(), m_worksheetUnit)); 1172 group.writeEntry("LayoutLeftMargin",Worksheet::convertToSceneUnits(ui.sbLayoutLeftMargin->value(), m_worksheetUnit)); 1173 group.writeEntry("LayoutRightMargin",Worksheet::convertToSceneUnits(ui.sbLayoutRightMargin->value(), m_worksheetUnit)); 1174 group.writeEntry("LayoutVerticalSpacing",Worksheet::convertToSceneUnits(ui.sbLayoutVerticalSpacing->value(), m_worksheetUnit)); 1175 group.writeEntry("LayoutHorizontalSpacing",Worksheet::convertToSceneUnits(ui.sbLayoutHorizontalSpacing->value(), m_worksheetUnit)); 1176 group.writeEntry("LayoutColumnCount", ui.sbLayoutColumnCount->value()); 1177 1178 //Title 1179 group = config.group("PlotLegend"); 1180 labelWidget->saveConfig(group); 1181 1182 config.sync(); 1183 }