File indexing completed on 2024-05-12 15:28:02
0001 /*************************************************************************** 0002 File : WorksheetDock.cpp 0003 Project : LabPlot 0004 Description : widget for worksheet properties 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2010-2016 by Alexander Semke (alexander.semke@web.de) 0007 Copyright : (C) 2012-2013 by Stefan Gerlach (stefan.gerlach@uni-konstanz.de) 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 0030 #include "WorksheetDock.h" 0031 #include "kdefrontend/GuiTools.h" 0032 #include "kdefrontend/ThemeHandler.h" 0033 #include "kdefrontend/TemplateHandler.h" 0034 0035 #include <QCompleter> 0036 #include <QDirModel> 0037 #include <QFileDialog> 0038 #include <QImageReader> 0039 #include <QPageSize> 0040 0041 #include <KConfig> 0042 #include <KLocalizedString> 0043 0044 /*! 0045 \class WorksheetDock 0046 \brief Provides a widget for editing the properties of the worksheets currently selected in the project explorer. 0047 0048 \ingroup kdefrontend 0049 */ 0050 0051 WorksheetDock::WorksheetDock(QWidget *parent): BaseDock(parent) { 0052 ui.setupUi(this); 0053 m_leName = ui.leName; 0054 m_leComment = ui.leComment; 0055 0056 //Background-tab 0057 ui.cbBackgroundColorStyle->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon); 0058 ui.bOpen->setIcon( QIcon::fromTheme("document-open") ); 0059 0060 ui.leBackgroundFileName->setCompleter(new QCompleter(new QDirModel, this)); 0061 0062 //Layout-tab 0063 ui.chScaleContent->setToolTip(i18n("If checked, rescale the content of the worksheet on size changes. Otherwise resize the canvas only.")); 0064 0065 ui.cbLayout->addItem(QIcon::fromTheme("labplot-editbreaklayout"), i18n("No Layout")); 0066 ui.cbLayout->addItem(QIcon::fromTheme("labplot-editvlayout"), i18n("Vertical Layout")); 0067 ui.cbLayout->addItem(QIcon::fromTheme("labplot-edithlayout"), i18n("Horizontal Layout")); 0068 ui.cbLayout->addItem(QIcon::fromTheme("labplot-editgrid"), i18n("Grid Layout")); 0069 0070 //adjust layouts in the tabs 0071 for (int i = 0; i < ui.tabWidget->count(); ++i) { 0072 auto* layout = dynamic_cast<QGridLayout*>(ui.tabWidget->widget(i)->layout()); 0073 if (!layout) 0074 continue; 0075 0076 layout->setContentsMargins(2, 2, 2, 2); 0077 layout->setHorizontalSpacing(2); 0078 layout->setVerticalSpacing(2); 0079 } 0080 0081 WorksheetDock::updateLocale(); 0082 0083 //SLOTs 0084 //General 0085 connect(ui.leName, &QLineEdit::textChanged, this, &WorksheetDock::nameChanged); 0086 connect(ui.leComment, &QLineEdit::textChanged, this, &WorksheetDock::commentChanged); 0087 connect(ui.cbSize, QOverload<int>::of(&QComboBox::currentIndexChanged), 0088 this, static_cast<void (WorksheetDock::*)(int)>(&WorksheetDock::sizeChanged)); 0089 connect(ui.sbWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0090 this, static_cast<void (WorksheetDock::*)()>(&WorksheetDock::sizeChanged)); 0091 connect(ui.sbHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0092 this, static_cast<void (WorksheetDock::*)()>(&WorksheetDock::sizeChanged)); 0093 connect(ui.cbOrientation, QOverload<int>::of(&QComboBox::currentIndexChanged), 0094 this, &WorksheetDock::orientationChanged); 0095 0096 //Background 0097 connect(ui.cbBackgroundType, QOverload<int>::of(&QComboBox::currentIndexChanged), 0098 this, &WorksheetDock::backgroundTypeChanged); 0099 connect(ui.cbBackgroundColorStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0100 this, &WorksheetDock::backgroundColorStyleChanged); 0101 connect(ui.cbBackgroundImageStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0102 this, &WorksheetDock::backgroundImageStyleChanged); 0103 connect(ui.cbBackgroundBrushStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), 0104 this, &WorksheetDock::backgroundBrushStyleChanged); 0105 connect(ui.bOpen, &QPushButton::clicked, this, &WorksheetDock::selectFile); 0106 connect(ui.leBackgroundFileName, &QLineEdit::returnPressed, this, &WorksheetDock::fileNameChanged); 0107 connect(ui.leBackgroundFileName, &QLineEdit::textChanged, this, &WorksheetDock::fileNameChanged); 0108 connect(ui.kcbBackgroundFirstColor, &KColorButton::changed, this, &WorksheetDock::backgroundFirstColorChanged); 0109 connect(ui.kcbBackgroundSecondColor, &KColorButton::changed, this, &WorksheetDock::backgroundSecondColorChanged); 0110 connect(ui.sbBackgroundOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), 0111 this, &WorksheetDock::backgroundOpacityChanged); 0112 0113 //Layout 0114 connect(ui.cbLayout, QOverload<int>::of(&QComboBox::currentIndexChanged), 0115 this, &WorksheetDock::layoutChanged); 0116 connect( ui.chScaleContent, &QCheckBox::clicked, this, &WorksheetDock::scaleContentChanged); 0117 connect( ui.sbLayoutTopMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0118 this, &WorksheetDock::layoutTopMarginChanged); 0119 connect( ui.sbLayoutBottomMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0120 this, &WorksheetDock::layoutBottomMarginChanged); 0121 connect( ui.sbLayoutLeftMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0122 this, &WorksheetDock::layoutLeftMarginChanged); 0123 connect( ui.sbLayoutRightMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0124 this, &WorksheetDock::layoutRightMarginChanged); 0125 connect( ui.sbLayoutHorizontalSpacing, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0126 this, &WorksheetDock::layoutHorizontalSpacingChanged); 0127 connect( ui.sbLayoutVerticalSpacing, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), 0128 this, &WorksheetDock::layoutVerticalSpacingChanged); 0129 connect( ui.sbLayoutRowCount, static_cast<void (QSpinBox::*) (int)>(&QSpinBox::valueChanged), 0130 this, &WorksheetDock::layoutRowCountChanged); 0131 connect( ui.sbLayoutColumnCount, static_cast<void (QSpinBox::*) (int)>(&QSpinBox::valueChanged), 0132 this, &WorksheetDock::layoutColumnCountChanged); 0133 0134 //theme and template handlers 0135 auto* frame = new QFrame(this); 0136 auto* layout = new QHBoxLayout(frame); 0137 layout->setContentsMargins(0, 11, 0, 11); 0138 0139 m_themeHandler = new ThemeHandler(this); 0140 layout->addWidget(m_themeHandler); 0141 connect(m_themeHandler, &ThemeHandler::loadThemeRequested, this, &WorksheetDock::loadTheme); 0142 connect(m_themeHandler, &ThemeHandler::info, this, &WorksheetDock::info); 0143 0144 auto* templateHandler = new TemplateHandler(this, TemplateHandler::ClassName::Worksheet); 0145 layout->addWidget(templateHandler); 0146 connect(templateHandler, &TemplateHandler::loadConfigRequested, this, &WorksheetDock::loadConfigFromTemplate); 0147 connect(templateHandler, &TemplateHandler::saveConfigRequested, this, &WorksheetDock::saveConfigAsTemplate); 0148 connect(templateHandler, &TemplateHandler::info, this, &WorksheetDock::info); 0149 0150 ui.verticalLayout->addWidget(frame); 0151 0152 this->retranslateUi(); 0153 } 0154 0155 void WorksheetDock::setWorksheets(QList<Worksheet*> list) { 0156 m_initializing = true; 0157 m_worksheetList = list; 0158 m_worksheet = list.first(); 0159 m_aspect = list.first(); 0160 0161 //if there are more then one worksheet in the list, disable the name and comment field in the tab "general" 0162 if (list.size() == 1) { 0163 ui.lName->setEnabled(true); 0164 ui.leName->setEnabled(true); 0165 ui.lComment->setEnabled(true); 0166 ui.leComment->setEnabled(true); 0167 0168 ui.leName->setText(m_worksheet->name()); 0169 ui.leComment->setText(m_worksheet->comment()); 0170 } else { 0171 ui.lName->setEnabled(false); 0172 ui.leName->setEnabled(false); 0173 ui.lComment->setEnabled(false); 0174 ui.leComment->setEnabled(false); 0175 0176 ui.leName->setText(QString()); 0177 ui.leComment->setText(QString()); 0178 } 0179 ui.leName->setStyleSheet(""); 0180 ui.leName->setToolTip(""); 0181 0182 //show the properties of the first worksheet 0183 this->load(); 0184 this->worksheetLayoutChanged(m_worksheet->layout()); 0185 0186 m_themeHandler->setCurrentTheme(m_worksheet->theme()); 0187 0188 connect(m_worksheet, &Worksheet::aspectDescriptionChanged, this, &WorksheetDock::worksheetDescriptionChanged); 0189 connect(m_worksheet, &Worksheet::pageRectChanged, this, &WorksheetDock::worksheetPageRectChanged); 0190 connect(m_worksheet, &Worksheet::scaleContentChanged, this, &WorksheetDock::worksheetScaleContentChanged); 0191 0192 connect(m_worksheet, &Worksheet::backgroundTypeChanged, this, &WorksheetDock::worksheetBackgroundTypeChanged); 0193 connect(m_worksheet, &Worksheet::backgroundColorStyleChanged, this, &WorksheetDock::worksheetBackgroundColorStyleChanged); 0194 connect(m_worksheet, &Worksheet::backgroundImageStyleChanged, this, &WorksheetDock::worksheetBackgroundImageStyleChanged); 0195 connect(m_worksheet, &Worksheet::backgroundBrushStyleChanged, this, &WorksheetDock::worksheetBackgroundBrushStyleChanged); 0196 connect(m_worksheet, &Worksheet::backgroundFirstColorChanged, this, &WorksheetDock::worksheetBackgroundFirstColorChanged); 0197 connect(m_worksheet, &Worksheet::backgroundSecondColorChanged, this, &WorksheetDock::worksheetBackgroundSecondColorChanged); 0198 connect(m_worksheet, &Worksheet::backgroundFileNameChanged, this, &WorksheetDock::worksheetBackgroundFileNameChanged); 0199 connect(m_worksheet, &Worksheet::backgroundOpacityChanged, this, &WorksheetDock::worksheetBackgroundOpacityChanged); 0200 0201 connect(m_worksheet, &Worksheet::layoutChanged, this, &WorksheetDock::worksheetLayoutChanged); 0202 connect(m_worksheet, &Worksheet::layoutTopMarginChanged, this, &WorksheetDock::worksheetLayoutTopMarginChanged); 0203 connect(m_worksheet, &Worksheet::layoutBottomMarginChanged, this, &WorksheetDock::worksheetLayoutBottomMarginChanged); 0204 connect(m_worksheet, &Worksheet::layoutLeftMarginChanged, this, &WorksheetDock::worksheetLayoutLeftMarginChanged); 0205 connect(m_worksheet, &Worksheet::layoutRightMarginChanged, this, &WorksheetDock::worksheetLayoutRightMarginChanged); 0206 connect(m_worksheet, &Worksheet::layoutVerticalSpacingChanged, this, &WorksheetDock::worksheetLayoutVerticalSpacingChanged); 0207 connect(m_worksheet, &Worksheet::layoutHorizontalSpacingChanged, this, &WorksheetDock::worksheetLayoutHorizontalSpacingChanged); 0208 connect(m_worksheet, &Worksheet::layoutRowCountChanged, this, &WorksheetDock::worksheetLayoutRowCountChanged); 0209 connect(m_worksheet, &Worksheet::layoutColumnCountChanged, this, &WorksheetDock::worksheetLayoutColumnCountChanged); 0210 0211 connect(m_worksheet, &Worksheet::themeChanged, m_themeHandler, &ThemeHandler::setCurrentTheme); 0212 0213 m_initializing = false; 0214 } 0215 0216 void WorksheetDock::updateLocale() { 0217 SET_NUMBER_LOCALE 0218 ui.sbWidth->setLocale(numberLocale); 0219 ui.sbHeight->setLocale(numberLocale); 0220 ui.sbLayoutTopMargin->setLocale(numberLocale); 0221 ui.sbLayoutBottomMargin->setLocale(numberLocale); 0222 ui.sbLayoutLeftMargin->setLocale(numberLocale); 0223 ui.sbLayoutRightMargin->setLocale(numberLocale); 0224 ui.sbLayoutHorizontalSpacing->setLocale(numberLocale); 0225 ui.sbLayoutVerticalSpacing->setLocale(numberLocale); 0226 } 0227 0228 void WorksheetDock::updateUnits() { 0229 const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General")); 0230 BaseDock::Units units = (BaseDock::Units)group.readEntry("Units", static_cast<int>(Units::Metric)); 0231 if (units == m_units) 0232 return; 0233 0234 m_units = units; 0235 Lock lock(m_initializing); 0236 QString suffix; 0237 if (m_units == Units::Metric) { 0238 //convert from imperial to metric 0239 m_worksheetUnit = Worksheet::Unit::Centimeter; 0240 suffix = QLatin1String(" cm"); 0241 ui.sbWidth->setValue(ui.sbWidth->value()*2.54); 0242 ui.sbHeight->setValue(ui.sbHeight->value()*2.54); 0243 ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()*2.54); 0244 ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()*2.54); 0245 ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()*2.54); 0246 ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()*2.54); 0247 ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()*2.54); 0248 ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()*2.54); 0249 } else { 0250 //convert from metric to imperial 0251 m_worksheetUnit = Worksheet::Unit::Inch; 0252 suffix = QLatin1String(" in"); 0253 ui.sbWidth->setValue(ui.sbWidth->value()/2.54); 0254 ui.sbHeight->setValue(ui.sbHeight->value()/2.54); 0255 ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()/2.54); 0256 ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()/2.54); 0257 ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()/2.54); 0258 ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()/2.54); 0259 ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()/2.54); 0260 ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()/2.54); 0261 } 0262 0263 ui.sbWidth->setSuffix(suffix); 0264 ui.sbHeight->setSuffix(suffix); 0265 ui.sbLayoutTopMargin->setSuffix(suffix); 0266 ui.sbLayoutBottomMargin->setSuffix(suffix); 0267 ui.sbLayoutLeftMargin->setSuffix(suffix); 0268 ui.sbLayoutRightMargin->setSuffix(suffix); 0269 ui.sbLayoutHorizontalSpacing->setSuffix(suffix); 0270 ui.sbLayoutVerticalSpacing->setSuffix(suffix); 0271 } 0272 0273 /*! 0274 Checks whether the size is one of the QPageSize::PageSizeId and 0275 updates Size and Orientation checkbox when width/height changes. 0276 */ 0277 void WorksheetDock::updatePaperSize() { 0278 if (m_worksheet->useViewSize()) { 0279 ui.cbSize->setCurrentIndex(0); 0280 return; 0281 } 0282 0283 double w = ui.sbWidth->value(); 0284 double h = ui.sbHeight->value(); 0285 if (m_units == Units::Metric) { 0286 //In UI we use cm, so we need to convert to mm first before we check with QPageSize 0287 w *= 10; 0288 h *= 10; 0289 } 0290 0291 const QSizeF s = QSizeF(w, h); 0292 const QSizeF st = s.transposed(); 0293 0294 //determine the position of the QPageSize::PageSizeId in the combobox 0295 bool found = false; 0296 for (int i = 0; i < ui.cbSize->count(); ++i) { 0297 const QVariant v = ui.cbSize->itemData(i); 0298 if (!v.isValid()) 0299 continue; 0300 0301 const auto id = v.value<QPageSize::PageSizeId>(); 0302 QPageSize::Unit pageUnit = (m_units == Units::Metric) ? QPageSize::Millimeter : QPageSize::Inch; 0303 const QSizeF ps = QPageSize::size(id, pageUnit); 0304 if (s == ps) { //check the portrait-orientation first 0305 ui.cbSize->setCurrentIndex(i); 0306 ui.cbOrientation->setCurrentIndex(0); //a QPageSize::PaperSize in portrait-orientation was found 0307 found = true; 0308 break; 0309 } else if (st == ps) { //check for the landscape-orientation 0310 ui.cbSize->setCurrentIndex(i); 0311 ui.cbOrientation->setCurrentIndex(1); //a QPageSize::PaperSize in landscape-orientation was found 0312 found = true; 0313 break; 0314 } 0315 } 0316 0317 if (!found) 0318 ui.cbSize->setCurrentIndex(ui.cbSize->count() - 1); //select "Custom" size 0319 } 0320 0321 //************************************************************* 0322 //****** SLOTs for changes triggered in WorksheetDock ********* 0323 //************************************************************* 0324 void WorksheetDock::retranslateUi() { 0325 Lock lock(m_initializing); 0326 0327 //Geometry 0328 ui.cbOrientation->clear(); 0329 ui.cbOrientation->addItem(i18n("Portrait")); 0330 ui.cbOrientation->addItem(i18n("Landscape")); 0331 0332 QString suffix; 0333 if (m_units == Units::Metric) 0334 suffix = QLatin1String(" cm"); 0335 else 0336 suffix = QLatin1String(" in"); 0337 0338 ui.sbWidth->setSuffix(suffix); 0339 ui.sbHeight->setSuffix(suffix); 0340 ui.sbLayoutTopMargin->setSuffix(suffix); 0341 ui.sbLayoutBottomMargin->setSuffix(suffix); 0342 ui.sbLayoutLeftMargin->setSuffix(suffix); 0343 ui.sbLayoutRightMargin->setSuffix(suffix); 0344 ui.sbLayoutHorizontalSpacing->setSuffix(suffix); 0345 ui.sbLayoutVerticalSpacing->setSuffix(suffix); 0346 0347 const QVector<QPageSize::PageSizeId> pageSizeIds = { 0348 QPageSize::A0, 0349 QPageSize::A1, 0350 QPageSize::A2, 0351 QPageSize::A3, 0352 QPageSize::A4, 0353 QPageSize::A5, 0354 QPageSize::A6, 0355 QPageSize::A7, 0356 QPageSize::A8, 0357 QPageSize::A9, 0358 QPageSize::B0, 0359 QPageSize::B1, 0360 QPageSize::B2, 0361 QPageSize::B3, 0362 QPageSize::B4, 0363 QPageSize::B5, 0364 QPageSize::B6, 0365 QPageSize::B7, 0366 QPageSize::B8, 0367 QPageSize::B9, 0368 QPageSize::B10, 0369 QPageSize::C5E, 0370 QPageSize::DLE, 0371 QPageSize::Executive, 0372 QPageSize::Folio, 0373 QPageSize::Ledger, 0374 QPageSize::Legal, 0375 QPageSize::Letter, 0376 QPageSize::Tabloid, 0377 QPageSize::Comm10E, 0378 QPageSize::Custom, 0379 }; 0380 ui.cbSize->clear(); 0381 ui.cbSize->addItem(i18n("View Size")); 0382 for (auto id : pageSizeIds) 0383 ui.cbSize->addItem(QPageSize::name(id), id); 0384 ui.cbSize->insertSeparator(1); 0385 0386 //Background 0387 ui.cbBackgroundType->clear(); 0388 ui.cbBackgroundType->addItem(i18n("Color")); 0389 ui.cbBackgroundType->addItem(i18n("Image")); 0390 ui.cbBackgroundType->addItem(i18n("Pattern")); 0391 0392 ui.cbBackgroundColorStyle->clear(); 0393 ui.cbBackgroundColorStyle->addItem(i18n("Single Color")); 0394 ui.cbBackgroundColorStyle->addItem(i18n("Horizontal Gradient")); 0395 ui.cbBackgroundColorStyle->addItem(i18n("Vertical Gradient")); 0396 ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Top Left)")); 0397 ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Bottom Left)")); 0398 ui.cbBackgroundColorStyle->addItem(i18n("Radial Gradient")); 0399 0400 ui.cbBackgroundImageStyle->clear(); 0401 ui.cbBackgroundImageStyle->addItem(i18n("Scaled and Cropped")); 0402 ui.cbBackgroundImageStyle->addItem(i18n("Scaled")); 0403 ui.cbBackgroundImageStyle->addItem(i18n("Scaled, Keep Proportions")); 0404 ui.cbBackgroundImageStyle->addItem(i18n("Centered")); 0405 ui.cbBackgroundImageStyle->addItem(i18n("Tiled")); 0406 ui.cbBackgroundImageStyle->addItem(i18n("Center Tiled")); 0407 GuiTools::updateBrushStyles(ui.cbBackgroundBrushStyle, Qt::SolidPattern); 0408 } 0409 0410 // "General"-tab 0411 void WorksheetDock::scaleContentChanged(bool scaled) { 0412 if (m_initializing) 0413 return; 0414 0415 for (auto* worksheet : m_worksheetList) 0416 worksheet->setScaleContent(scaled); 0417 } 0418 0419 void WorksheetDock::sizeChanged(int i) { 0420 const auto index = ui.cbSize->itemData(i).value<QPageSize::PageSizeId>(); 0421 0422 if (index == QPageSize::Custom) { 0423 ui.sbWidth->setEnabled(true); 0424 ui.sbHeight->setEnabled(true); 0425 ui.lOrientation->hide(); 0426 ui.cbOrientation->hide(); 0427 } else { 0428 ui.sbWidth->setEnabled(false); 0429 ui.sbHeight->setEnabled(false); 0430 if (i == 0) { //no orientation available when using the complete view size (first item in the combox is selected) 0431 ui.lOrientation->hide(); 0432 ui.cbOrientation->hide(); 0433 } else { 0434 ui.lOrientation->show(); 0435 ui.cbOrientation->show(); 0436 } 0437 } 0438 0439 if (m_initializing) 0440 return; 0441 0442 Lock lock(m_initializing); 0443 if (i == 0) { 0444 //use the complete view size (first item in the combox is selected) 0445 for (auto* worksheet : m_worksheetList) 0446 worksheet->setUseViewSize(true); 0447 } else if (index == QPageSize::Custom) { 0448 if (m_worksheet->useViewSize()) { 0449 for (auto* worksheet : m_worksheetList) 0450 worksheet->setUseViewSize(false); 0451 } 0452 } else { 0453 //determine the width and the height of the to be used predefined layout 0454 QSizeF s = QPageSize::size(index, QPageSize::Millimeter); 0455 if (ui.cbOrientation->currentIndex() == 1) 0456 s.transpose(); 0457 0458 //s is in mm, in UI we show everything in cm/in 0459 if (m_units == Units::Metric) { 0460 ui.sbWidth->setValue(s.width()/10); 0461 ui.sbHeight->setValue(s.height()/10); 0462 } else { 0463 ui.sbWidth->setValue(s.width()/25.4); 0464 ui.sbHeight->setValue(s.height()/25.4); 0465 } 0466 0467 float w = Worksheet::convertToSceneUnits(s.width(), Worksheet::Unit::Millimeter); 0468 float h = Worksheet::convertToSceneUnits(s.height(), Worksheet::Unit::Millimeter); 0469 for (auto* worksheet : m_worksheetList) { 0470 worksheet->setUseViewSize(false); 0471 worksheet->setPageRect(QRect(0,0,w,h)); 0472 } 0473 } 0474 } 0475 0476 void WorksheetDock::sizeChanged() { 0477 if (m_initializing) 0478 return; 0479 0480 int w = Worksheet::convertToSceneUnits(ui.sbWidth->value(), m_worksheetUnit); 0481 int h = Worksheet::convertToSceneUnits(ui.sbHeight->value(), m_worksheetUnit); 0482 for (auto* worksheet : m_worksheetList) 0483 worksheet->setPageRect(QRect(0,0,w,h)); 0484 } 0485 0486 void WorksheetDock::orientationChanged(int index) { 0487 Q_UNUSED(index); 0488 if (m_initializing) 0489 return; 0490 0491 this->sizeChanged(ui.cbSize->currentIndex()); 0492 } 0493 0494 // "Background"-tab 0495 void WorksheetDock::backgroundTypeChanged(int index) { 0496 if (index == -1) 0497 return; 0498 0499 auto type = (PlotArea::BackgroundType)index; 0500 0501 if (type == PlotArea::BackgroundType::Color) { 0502 ui.lBackgroundColorStyle->show(); 0503 ui.cbBackgroundColorStyle->show(); 0504 ui.lBackgroundImageStyle->hide(); 0505 ui.cbBackgroundImageStyle->hide(); 0506 ui.lBackgroundBrushStyle->hide(); 0507 ui.cbBackgroundBrushStyle->hide(); 0508 0509 ui.lBackgroundFileName->hide(); 0510 ui.leBackgroundFileName->hide(); 0511 ui.bOpen->hide(); 0512 0513 ui.lBackgroundFirstColor->show(); 0514 ui.kcbBackgroundFirstColor->show(); 0515 0516 auto style = (PlotArea::BackgroundColorStyle)ui.cbBackgroundColorStyle->currentIndex(); 0517 if (style == PlotArea::BackgroundColorStyle::SingleColor) { 0518 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0519 ui.lBackgroundSecondColor->hide(); 0520 ui.kcbBackgroundSecondColor->hide(); 0521 } else { 0522 ui.lBackgroundFirstColor->setText(i18n("First color:")); 0523 ui.lBackgroundSecondColor->show(); 0524 ui.kcbBackgroundSecondColor->show(); 0525 } 0526 } else if (type == PlotArea::BackgroundType::Image) { 0527 ui.lBackgroundFirstColor->hide(); 0528 ui.kcbBackgroundFirstColor->hide(); 0529 ui.lBackgroundSecondColor->hide(); 0530 ui.kcbBackgroundSecondColor->hide(); 0531 0532 ui.lBackgroundColorStyle->hide(); 0533 ui.cbBackgroundColorStyle->hide(); 0534 ui.lBackgroundImageStyle->show(); 0535 ui.cbBackgroundImageStyle->show(); 0536 ui.lBackgroundBrushStyle->hide(); 0537 ui.cbBackgroundBrushStyle->hide(); 0538 ui.lBackgroundFileName->show(); 0539 ui.leBackgroundFileName->show(); 0540 ui.bOpen->show(); 0541 } else if (type == PlotArea::BackgroundType::Pattern) { 0542 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0543 ui.lBackgroundFirstColor->show(); 0544 ui.kcbBackgroundFirstColor->show(); 0545 ui.lBackgroundSecondColor->hide(); 0546 ui.kcbBackgroundSecondColor->hide(); 0547 0548 ui.lBackgroundColorStyle->hide(); 0549 ui.cbBackgroundColorStyle->hide(); 0550 ui.lBackgroundImageStyle->hide(); 0551 ui.cbBackgroundImageStyle->hide(); 0552 ui.lBackgroundBrushStyle->show(); 0553 ui.cbBackgroundBrushStyle->show(); 0554 ui.lBackgroundFileName->hide(); 0555 ui.leBackgroundFileName->hide(); 0556 ui.bOpen->hide(); 0557 } 0558 0559 if (m_initializing) 0560 return; 0561 0562 for (auto* worksheet : m_worksheetList) 0563 worksheet->setBackgroundType(type); 0564 } 0565 0566 void WorksheetDock::backgroundColorStyleChanged(int index) { 0567 if (index == -1) 0568 return; 0569 0570 auto style = (PlotArea::BackgroundColorStyle)index; 0571 0572 if (style == PlotArea::BackgroundColorStyle::SingleColor) { 0573 ui.lBackgroundFirstColor->setText(i18n("Color:")); 0574 ui.lBackgroundSecondColor->hide(); 0575 ui.kcbBackgroundSecondColor->hide(); 0576 } else { 0577 ui.lBackgroundFirstColor->setText(i18n("First color:")); 0578 ui.lBackgroundSecondColor->show(); 0579 ui.kcbBackgroundSecondColor->show(); 0580 } 0581 0582 if (m_initializing) 0583 return; 0584 0585 int size = m_worksheetList.size(); 0586 if (size>1) { 0587 m_worksheet->beginMacro(i18n("%1 worksheets: background color style changed", size)); 0588 for (auto* w : m_worksheetList) 0589 w->setBackgroundColorStyle(style); 0590 m_worksheet->endMacro(); 0591 } else 0592 m_worksheet->setBackgroundColorStyle(style); 0593 } 0594 0595 void WorksheetDock::backgroundImageStyleChanged(int index) { 0596 if (m_initializing) 0597 return; 0598 0599 auto style = (PlotArea::BackgroundImageStyle)index; 0600 for (auto* worksheet : m_worksheetList) 0601 worksheet->setBackgroundImageStyle(style); 0602 } 0603 0604 void WorksheetDock::backgroundBrushStyleChanged(int index) { 0605 if (m_initializing) 0606 return; 0607 0608 auto style = (Qt::BrushStyle)index; 0609 for (auto* worksheet : m_worksheetList) 0610 worksheet->setBackgroundBrushStyle(style); 0611 } 0612 0613 void WorksheetDock::backgroundFirstColorChanged(const QColor& c) { 0614 if (m_initializing) 0615 return; 0616 0617 for (auto* worksheet : m_worksheetList) 0618 worksheet->setBackgroundFirstColor(c); 0619 } 0620 0621 void WorksheetDock::backgroundSecondColorChanged(const QColor& c) { 0622 if (m_initializing) 0623 return; 0624 0625 for (auto* worksheet : m_worksheetList) 0626 worksheet->setBackgroundSecondColor(c); 0627 } 0628 0629 void WorksheetDock::backgroundOpacityChanged(int value) { 0630 if (m_initializing) 0631 return; 0632 0633 float opacity = (float)value/100; 0634 for (auto* worksheet : m_worksheetList) 0635 worksheet->setBackgroundOpacity(opacity); 0636 } 0637 0638 //"Layout"-tab 0639 void WorksheetDock::layoutChanged(int index) { 0640 auto layout = (Worksheet::Layout)index; 0641 0642 bool b = (layout != Worksheet::Layout::NoLayout); 0643 ui.sbLayoutTopMargin->setEnabled(b); 0644 ui.sbLayoutBottomMargin->setEnabled(b); 0645 ui.sbLayoutLeftMargin->setEnabled(b); 0646 ui.sbLayoutRightMargin->setEnabled(b); 0647 ui.sbLayoutHorizontalSpacing->setEnabled(b); 0648 ui.sbLayoutVerticalSpacing->setEnabled(b); 0649 ui.sbLayoutRowCount->setEnabled(b); 0650 ui.sbLayoutColumnCount->setEnabled(b); 0651 0652 //show the "scale content" option if no layout active 0653 ui.lScaleContent->setVisible(!b); 0654 ui.chScaleContent->setVisible(!b); 0655 0656 if (b) { 0657 //show grid specific settings if grid layout selected 0658 bool grid = (layout == Worksheet::Layout::GridLayout); 0659 ui.lGrid->setVisible(grid); 0660 ui.lRowCount->setVisible(grid); 0661 ui.sbLayoutRowCount->setVisible(grid); 0662 ui.lColumnCount->setVisible(grid); 0663 ui.sbLayoutColumnCount->setVisible(grid); 0664 } else { 0665 //no layout selected, hide grid specific settings that were potentially shown before 0666 ui.lGrid->setVisible(false); 0667 ui.lRowCount->setVisible(false); 0668 ui.sbLayoutRowCount->setVisible(false); 0669 ui.lColumnCount->setVisible(false); 0670 ui.sbLayoutColumnCount->setVisible(false); 0671 } 0672 0673 if (m_initializing) 0674 return; 0675 0676 for (auto* worksheet : m_worksheetList) 0677 worksheet->setLayout(layout); 0678 } 0679 0680 void WorksheetDock::layoutTopMarginChanged(double margin) { 0681 if (m_initializing) 0682 return; 0683 0684 for (auto* worksheet : m_worksheetList) 0685 worksheet->setLayoutTopMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0686 } 0687 0688 void WorksheetDock::layoutBottomMarginChanged(double margin) { 0689 if (m_initializing) 0690 return; 0691 0692 for (auto* worksheet : m_worksheetList) 0693 worksheet->setLayoutBottomMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0694 } 0695 0696 void WorksheetDock::layoutLeftMarginChanged(double margin) { 0697 if (m_initializing) 0698 return; 0699 0700 for (auto* worksheet : m_worksheetList) 0701 worksheet->setLayoutLeftMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0702 } 0703 0704 void WorksheetDock::layoutRightMarginChanged(double margin) { 0705 if (m_initializing) 0706 return; 0707 0708 for (auto* worksheet : m_worksheetList) 0709 worksheet->setLayoutRightMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit)); 0710 } 0711 0712 void WorksheetDock::layoutHorizontalSpacingChanged(double spacing) { 0713 if (m_initializing) 0714 return; 0715 0716 for (auto* worksheet : m_worksheetList) 0717 worksheet->setLayoutHorizontalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit)); 0718 } 0719 0720 void WorksheetDock::layoutVerticalSpacingChanged(double spacing) { 0721 if (m_initializing) 0722 return; 0723 0724 for (auto* worksheet : m_worksheetList) 0725 worksheet->setLayoutVerticalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit)); 0726 } 0727 0728 void WorksheetDock::layoutRowCountChanged(int count) { 0729 if (m_initializing) 0730 return; 0731 0732 for (auto* worksheet : m_worksheetList) 0733 worksheet->setLayoutRowCount(count); 0734 } 0735 0736 void WorksheetDock::layoutColumnCountChanged(int count) { 0737 if (m_initializing) 0738 return; 0739 0740 for (auto* worksheet : m_worksheetList) 0741 worksheet->setLayoutColumnCount(count); 0742 } 0743 0744 /*! 0745 opens a file dialog and lets the user select the image file. 0746 */ 0747 void WorksheetDock::selectFile() { 0748 KConfigGroup conf(KSharedConfig::openConfig(), "WorksheetDock"); 0749 QString dir = conf.readEntry("LastImageDir", ""); 0750 0751 QString formats; 0752 for (const QByteArray& format : QImageReader::supportedImageFormats()) { 0753 QString f = "*." + QString(format.constData()); 0754 if (f == QLatin1String("*.svg")) 0755 continue; 0756 formats.isEmpty() ? formats += f : formats += ' ' + f; 0757 } 0758 0759 QString path = QFileDialog::getOpenFileName(this, i18n("Select the image file"), dir, i18n("Images (%1)", formats)); 0760 if (path.isEmpty()) 0761 return; //cancel was clicked in the file-dialog 0762 0763 int pos = path.lastIndexOf(QLatin1String("/")); 0764 if (pos != -1) { 0765 QString newDir = path.left(pos); 0766 if (newDir != dir) 0767 conf.writeEntry("LastImageDir", newDir); 0768 } 0769 0770 ui.leBackgroundFileName->setText( path ); 0771 0772 for (auto* worksheet : m_worksheetList) 0773 worksheet->setBackgroundFileName(path); 0774 } 0775 0776 void WorksheetDock::fileNameChanged() { 0777 if (m_initializing) 0778 return; 0779 0780 const QString& fileName = ui.leBackgroundFileName->text(); 0781 bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName)); 0782 GuiTools::highlight(ui.leBackgroundFileName, invalid); 0783 0784 for (auto* worksheet : m_worksheetList) 0785 worksheet->setBackgroundFileName(fileName); 0786 } 0787 0788 //************************************************************* 0789 //******** SLOTs for changes triggered in Worksheet *********** 0790 //************************************************************* 0791 void WorksheetDock::worksheetDescriptionChanged(const AbstractAspect* aspect) { 0792 if (m_worksheet != aspect) 0793 return; 0794 0795 m_initializing = true; 0796 if (aspect->name() != ui.leName->text()) 0797 ui.leName->setText(aspect->name()); 0798 else if (aspect->comment() != ui.leComment->text()) 0799 ui.leComment->setText(aspect->comment()); 0800 m_initializing = false; 0801 } 0802 0803 void WorksheetDock::worksheetScaleContentChanged(bool scaled) { 0804 m_initializing = true; 0805 ui.chScaleContent->setChecked(scaled); 0806 m_initializing = false; 0807 } 0808 0809 void WorksheetDock::worksheetPageRectChanged(const QRectF& rect) { 0810 m_initializing = true; 0811 ui.sbWidth->setValue(Worksheet::convertFromSceneUnits(rect.width(), m_worksheetUnit)); 0812 ui.sbHeight->setValue(Worksheet::convertFromSceneUnits(rect.height(), m_worksheetUnit)); 0813 updatePaperSize(); 0814 m_initializing = false; 0815 } 0816 0817 void WorksheetDock::worksheetBackgroundTypeChanged(PlotArea::BackgroundType type) { 0818 m_initializing = true; 0819 ui.cbBackgroundType->setCurrentIndex(static_cast<int>(type)); 0820 m_initializing = false; 0821 } 0822 0823 void WorksheetDock::worksheetBackgroundColorStyleChanged(PlotArea::BackgroundColorStyle style) { 0824 m_initializing = true; 0825 ui.cbBackgroundColorStyle->setCurrentIndex(static_cast<int>(style)); 0826 m_initializing = false; 0827 } 0828 0829 void WorksheetDock::worksheetBackgroundImageStyleChanged(PlotArea::BackgroundImageStyle style) { 0830 m_initializing = true; 0831 ui.cbBackgroundImageStyle->setCurrentIndex(static_cast<int>(style)); 0832 m_initializing = false; 0833 } 0834 0835 void WorksheetDock::worksheetBackgroundBrushStyleChanged(Qt::BrushStyle style) { 0836 m_initializing = true; 0837 ui.cbBackgroundBrushStyle->setCurrentIndex(style); 0838 m_initializing = false; 0839 } 0840 0841 void WorksheetDock::worksheetBackgroundFirstColorChanged(const QColor& color) { 0842 m_initializing = true; 0843 ui.kcbBackgroundFirstColor->setColor(color); 0844 m_initializing = false; 0845 } 0846 0847 void WorksheetDock::worksheetBackgroundSecondColorChanged(const QColor& color) { 0848 m_initializing = true; 0849 ui.kcbBackgroundSecondColor->setColor(color); 0850 m_initializing = false; 0851 } 0852 0853 void WorksheetDock::worksheetBackgroundFileNameChanged(const QString& name) { 0854 m_initializing = true; 0855 ui.leBackgroundFileName->setText(name); 0856 m_initializing = false; 0857 } 0858 0859 void WorksheetDock::worksheetBackgroundOpacityChanged(float opacity) { 0860 m_initializing = true; 0861 ui.sbBackgroundOpacity->setValue( qRound(opacity*100.0) ); 0862 m_initializing = false; 0863 } 0864 0865 void WorksheetDock::worksheetLayoutChanged(Worksheet::Layout layout) { 0866 m_initializing = true; 0867 ui.cbLayout->setCurrentIndex(static_cast<int>(layout)); 0868 m_initializing = false; 0869 } 0870 0871 void WorksheetDock::worksheetLayoutTopMarginChanged(float value) { 0872 m_initializing = true; 0873 ui.sbLayoutTopMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0874 m_initializing = false; 0875 } 0876 0877 void WorksheetDock::worksheetLayoutBottomMarginChanged(float value) { 0878 m_initializing = true; 0879 ui.sbLayoutBottomMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0880 m_initializing = false; 0881 } 0882 0883 void WorksheetDock::worksheetLayoutLeftMarginChanged(float value) { 0884 m_initializing = true; 0885 ui.sbLayoutLeftMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0886 m_initializing = false; 0887 } 0888 0889 void WorksheetDock::worksheetLayoutRightMarginChanged(float value) { 0890 m_initializing = true; 0891 ui.sbLayoutRightMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0892 m_initializing = false; 0893 } 0894 0895 void WorksheetDock::worksheetLayoutVerticalSpacingChanged(float value) { 0896 m_initializing = true; 0897 ui.sbLayoutVerticalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0898 m_initializing = false; 0899 } 0900 0901 void WorksheetDock::worksheetLayoutHorizontalSpacingChanged(float value) { 0902 m_initializing = true; 0903 ui.sbLayoutHorizontalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit)); 0904 m_initializing = false; 0905 } 0906 0907 void WorksheetDock::worksheetLayoutRowCountChanged(int value) { 0908 m_initializing = true; 0909 ui.sbLayoutRowCount->setValue(value); 0910 m_initializing = false; 0911 } 0912 0913 void WorksheetDock::worksheetLayoutColumnCountChanged(int value) { 0914 m_initializing = true; 0915 ui.sbLayoutColumnCount->setValue(value); 0916 m_initializing = false; 0917 } 0918 0919 //************************************************************* 0920 //******************** SETTINGS ******************************* 0921 //************************************************************* 0922 void WorksheetDock::load() { 0923 // Geometry 0924 ui.chScaleContent->setChecked(m_worksheet->scaleContent()); 0925 ui.sbWidth->setValue(Worksheet::convertFromSceneUnits( m_worksheet->pageRect().width(), m_worksheetUnit) ); 0926 ui.sbHeight->setValue(Worksheet::convertFromSceneUnits( m_worksheet->pageRect().height(), m_worksheetUnit) ); 0927 updatePaperSize(); 0928 0929 // Background-tab 0930 ui.cbBackgroundType->setCurrentIndex( (int) m_worksheet->backgroundType() ); 0931 ui.cbBackgroundColorStyle->setCurrentIndex( (int) m_worksheet->backgroundColorStyle() ); 0932 ui.cbBackgroundImageStyle->setCurrentIndex( (int) m_worksheet->backgroundImageStyle() ); 0933 ui.cbBackgroundBrushStyle->setCurrentIndex( (int) m_worksheet->backgroundBrushStyle() ); 0934 ui.leBackgroundFileName->setText( m_worksheet->backgroundFileName() ); 0935 ui.kcbBackgroundFirstColor->setColor( m_worksheet->backgroundFirstColor() ); 0936 ui.kcbBackgroundSecondColor->setColor( m_worksheet->backgroundSecondColor() ); 0937 ui.sbBackgroundOpacity->setValue( qRound(m_worksheet->backgroundOpacity()*100) ); 0938 0939 //highlight the text field for the background image red if an image is used and cannot be found 0940 const QString& fileName = m_worksheet->backgroundFileName(); 0941 bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName)); 0942 GuiTools::highlight(ui.leBackgroundFileName, invalid); 0943 0944 // Layout 0945 ui.cbLayout->setCurrentIndex( (int) m_worksheet->layout() ); 0946 ui.sbLayoutTopMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutTopMargin(), m_worksheetUnit) ); 0947 ui.sbLayoutBottomMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutBottomMargin(), m_worksheetUnit) ); 0948 ui.sbLayoutLeftMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutLeftMargin(), m_worksheetUnit) ); 0949 ui.sbLayoutRightMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutRightMargin(), m_worksheetUnit) ); 0950 ui.sbLayoutHorizontalSpacing->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutHorizontalSpacing(), m_worksheetUnit) ); 0951 ui.sbLayoutVerticalSpacing->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutVerticalSpacing(), m_worksheetUnit) ); 0952 0953 ui.sbLayoutRowCount->setValue( m_worksheet->layoutRowCount() ); 0954 ui.sbLayoutColumnCount->setValue( m_worksheet->layoutColumnCount() ); 0955 } 0956 0957 void WorksheetDock::loadConfigFromTemplate(KConfig& config) { 0958 //extract the name of the template from the file name 0959 QString name; 0960 int index = config.name().lastIndexOf(QLatin1String("/")); 0961 if (index != -1) 0962 name = config.name().right(config.name().size() - index - 1); 0963 else 0964 name = config.name(); 0965 0966 int size = m_worksheetList.size(); 0967 if (size > 1) 0968 m_worksheet->beginMacro(i18n("%1 worksheets: template \"%2\" loaded", size, name)); 0969 else 0970 m_worksheet->beginMacro(i18n("%1: template \"%2\" loaded", m_worksheet->name(), name)); 0971 0972 this->loadConfig(config); 0973 m_worksheet->endMacro(); 0974 } 0975 0976 void WorksheetDock::loadConfig(KConfig& config) { 0977 KConfigGroup group = config.group( "Worksheet" ); 0978 0979 // Geometry 0980 ui.chScaleContent->setChecked(group.readEntry("ScaleContent", false)); 0981 ui.sbWidth->setValue(Worksheet::convertFromSceneUnits(group.readEntry("Width", m_worksheet->pageRect().width()), m_worksheetUnit)); 0982 ui.sbHeight->setValue(Worksheet::convertFromSceneUnits(group.readEntry("Height", m_worksheet->pageRect().height()), m_worksheetUnit)); 0983 if (group.readEntry("UseViewSize", false)) 0984 ui.cbSize->setCurrentIndex(0); 0985 else 0986 updatePaperSize(); 0987 0988 // Background-tab 0989 ui.cbBackgroundType->setCurrentIndex( group.readEntry("BackgroundType", (int) m_worksheet->backgroundType()) ); 0990 ui.cbBackgroundColorStyle->setCurrentIndex( group.readEntry("BackgroundColorStyle", (int) m_worksheet->backgroundColorStyle()) ); 0991 ui.cbBackgroundImageStyle->setCurrentIndex( group.readEntry("BackgroundImageStyle", (int) m_worksheet->backgroundImageStyle()) ); 0992 ui.cbBackgroundBrushStyle->setCurrentIndex( group.readEntry("BackgroundBrushStyle", (int) m_worksheet->backgroundBrushStyle()) ); 0993 ui.leBackgroundFileName->setText( group.readEntry("BackgroundFileName", m_worksheet->backgroundFileName()) ); 0994 ui.kcbBackgroundFirstColor->setColor( group.readEntry("BackgroundFirstColor", m_worksheet->backgroundFirstColor()) ); 0995 ui.kcbBackgroundSecondColor->setColor( group.readEntry("BackgroundSecondColor", m_worksheet->backgroundSecondColor()) ); 0996 ui.sbBackgroundOpacity->setValue( qRound(group.readEntry("BackgroundOpacity", m_worksheet->backgroundOpacity())*100) ); 0997 0998 // Layout 0999 ui.cbLayout->setCurrentIndex( group.readEntry("Layout", (int)m_worksheet->layout()) ); 1000 ui.sbLayoutTopMargin->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutTopMargin", m_worksheet->layoutTopMargin()), m_worksheetUnit) ); 1001 ui.sbLayoutBottomMargin->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutBottomMargin", m_worksheet->layoutBottomMargin()), m_worksheetUnit) ); 1002 ui.sbLayoutLeftMargin->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutLeftMargin", m_worksheet->layoutLeftMargin()), m_worksheetUnit) ); 1003 ui.sbLayoutRightMargin->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutRightMargin", m_worksheet->layoutRightMargin()), m_worksheetUnit) ); 1004 ui.sbLayoutHorizontalSpacing->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutHorizontalSpacing", m_worksheet->layoutHorizontalSpacing()), m_worksheetUnit) ); 1005 ui.sbLayoutVerticalSpacing->setValue( Worksheet::convertFromSceneUnits(group.readEntry("LayoutVerticalSpacing", m_worksheet->layoutVerticalSpacing()), m_worksheetUnit) ); 1006 1007 ui.sbLayoutRowCount->setValue(group.readEntry("LayoutRowCount", m_worksheet->layoutRowCount())); 1008 ui.sbLayoutColumnCount->setValue(group.readEntry("LayoutColumnCount", m_worksheet->layoutColumnCount())); 1009 } 1010 1011 void WorksheetDock::saveConfigAsTemplate(KConfig& config) { 1012 KConfigGroup group = config.group( "Worksheet" ); 1013 1014 //General 1015 group.writeEntry("ScaleContent",ui.chScaleContent->isChecked()); 1016 group.writeEntry("UseViewSize",ui.cbSize->currentIndex() == 0); 1017 group.writeEntry("Width",Worksheet::convertToSceneUnits(ui.sbWidth->value(), m_worksheetUnit)); 1018 group.writeEntry("Height",Worksheet::convertToSceneUnits(ui.sbHeight->value(), m_worksheetUnit)); 1019 1020 //Background 1021 group.writeEntry("BackgroundType",ui.cbBackgroundType->currentIndex()); 1022 group.writeEntry("BackgroundColorStyle", ui.cbBackgroundColorStyle->currentIndex()); 1023 group.writeEntry("BackgroundImageStyle", ui.cbBackgroundImageStyle->currentIndex()); 1024 group.writeEntry("BackgroundBrushStyle", ui.cbBackgroundBrushStyle->currentIndex()); 1025 group.writeEntry("BackgroundFileName", ui.leBackgroundFileName->text()); 1026 group.writeEntry("BackgroundFirstColor", ui.kcbBackgroundFirstColor->color()); 1027 group.writeEntry("BackgroundSecondColor", ui.kcbBackgroundSecondColor->color()); 1028 group.writeEntry("BackgroundOpacity", ui.sbBackgroundOpacity->value()/100.0); 1029 1030 //Layout 1031 group.writeEntry("Layout", ui.cbLayout->currentIndex()); 1032 group.writeEntry("LayoutTopMargin",Worksheet::convertToSceneUnits(ui.sbLayoutTopMargin->value(), m_worksheetUnit)); 1033 group.writeEntry("LayoutBottomMargin",Worksheet::convertToSceneUnits(ui.sbLayoutBottomMargin->value(), m_worksheetUnit)); 1034 group.writeEntry("LayoutLeftMargin",Worksheet::convertToSceneUnits(ui.sbLayoutLeftMargin->value(), m_worksheetUnit)); 1035 group.writeEntry("LayoutRightMargin",Worksheet::convertToSceneUnits(ui.sbLayoutRightMargin->value(), m_worksheetUnit)); 1036 group.writeEntry("LayoutVerticalSpacing",Worksheet::convertToSceneUnits(ui.sbLayoutVerticalSpacing->value(), m_worksheetUnit)); 1037 group.writeEntry("LayoutHorizontalSpacing",Worksheet::convertToSceneUnits(ui.sbLayoutHorizontalSpacing->value(), m_worksheetUnit)); 1038 group.writeEntry("LayoutRowCount", ui.sbLayoutRowCount->value()); 1039 group.writeEntry("LayoutColumnCount", ui.sbLayoutColumnCount->value()); 1040 1041 config.sync(); 1042 } 1043 1044 void WorksheetDock::loadTheme(const QString& theme) { 1045 for (auto* worksheet : m_worksheetList) 1046 worksheet->setTheme(theme); 1047 }