"Fossies" - the Fresh Open Source Software Archive

Member "labplot-2.8.2/src/kdefrontend/dockwidgets/WorksheetDock.cpp" (24 Feb 2021, 41646 Bytes) of package /linux/privat/labplot-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "WorksheetDock.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 /***************************************************************************
    2     File                 : WorksheetDock.cpp
    3     Project              : LabPlot
    4     Description          : widget for worksheet properties
    5     --------------------------------------------------------------------
    6     Copyright            : (C) 2010-2016 by Alexander Semke (alexander.semke@web.de)
    7     Copyright            : (C) 2012-2013 by Stefan Gerlach (stefan.gerlach@uni-konstanz.de)
    8 
    9  ***************************************************************************/
   10 
   11 /***************************************************************************
   12  *                                                                         *
   13  *  This program is free software; you can redistribute it and/or modify   *
   14  *  it under the terms of the GNU General Public License as published by   *
   15  *  the Free Software Foundation; either version 2 of the License, or      *
   16  *  (at your option) any later version.                                    *
   17  *                                                                         *
   18  *  This program is distributed in the hope that it will be useful,        *
   19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   21  *  GNU General Public License for more details.                           *
   22  *                                                                         *
   23  *   You should have received a copy of the GNU General Public License     *
   24  *   along with this program; if not, write to the Free Software           *
   25  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   26  *   Boston, MA  02110-1301  USA                                           *
   27  *                                                                         *
   28  ***************************************************************************/
   29 
   30 #include "WorksheetDock.h"
   31 #include "kdefrontend/GuiTools.h"
   32 #include "kdefrontend/ThemeHandler.h"
   33 #include "kdefrontend/TemplateHandler.h"
   34 
   35 #include <QCompleter>
   36 #include <QDirModel>
   37 #include <QFileDialog>
   38 #include <QImageReader>
   39 #include <QPageSize>
   40 
   41 #include <KConfig>
   42 #include <KLocalizedString>
   43 
   44 /*!
   45   \class WorksheetDock
   46   \brief  Provides a widget for editing the properties of the worksheets currently selected in the project explorer.
   47 
   48   \ingroup kdefrontend
   49 */
   50 
   51 WorksheetDock::WorksheetDock(QWidget *parent): BaseDock(parent) {
   52     ui.setupUi(this);
   53     m_leName = ui.leName;
   54     m_leComment = ui.leComment;
   55 
   56     //Background-tab
   57     ui.cbBackgroundColorStyle->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
   58     ui.bOpen->setIcon( QIcon::fromTheme("document-open") );
   59 
   60     ui.leBackgroundFileName->setCompleter(new QCompleter(new QDirModel, this));
   61 
   62     //Layout-tab
   63     ui.chScaleContent->setToolTip(i18n("If checked, rescale the content of the worksheet on size changes. Otherwise resize the canvas only."));
   64 
   65     ui.cbLayout->addItem(QIcon::fromTheme("labplot-editbreaklayout"), i18n("No Layout"));
   66     ui.cbLayout->addItem(QIcon::fromTheme("labplot-editvlayout"), i18n("Vertical Layout"));
   67     ui.cbLayout->addItem(QIcon::fromTheme("labplot-edithlayout"), i18n("Horizontal Layout"));
   68     ui.cbLayout->addItem(QIcon::fromTheme("labplot-editgrid"), i18n("Grid Layout"));
   69 
   70     //adjust layouts in the tabs
   71     for (int i = 0; i < ui.tabWidget->count(); ++i) {
   72         auto* layout = dynamic_cast<QGridLayout*>(ui.tabWidget->widget(i)->layout());
   73         if (!layout)
   74             continue;
   75 
   76         layout->setContentsMargins(2, 2, 2, 2);
   77         layout->setHorizontalSpacing(2);
   78         layout->setVerticalSpacing(2);
   79     }
   80 
   81     WorksheetDock::updateLocale();
   82 
   83     //SLOTs
   84     //General
   85     connect(ui.leName, &QLineEdit::textChanged, this, &WorksheetDock::nameChanged);
   86     connect(ui.leComment, &QLineEdit::textChanged, this, &WorksheetDock::commentChanged);
   87     connect(ui.cbSize, QOverload<int>::of(&QComboBox::currentIndexChanged),
   88              this, static_cast<void (WorksheetDock::*)(int)>(&WorksheetDock::sizeChanged));
   89     connect(ui.sbWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
   90             this, static_cast<void (WorksheetDock::*)()>(&WorksheetDock::sizeChanged));
   91     connect(ui.sbHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
   92              this, static_cast<void (WorksheetDock::*)()>(&WorksheetDock::sizeChanged));
   93     connect(ui.cbOrientation, QOverload<int>::of(&QComboBox::currentIndexChanged),
   94              this, &WorksheetDock::orientationChanged);
   95 
   96     //Background
   97     connect(ui.cbBackgroundType, QOverload<int>::of(&QComboBox::currentIndexChanged),
   98              this, &WorksheetDock::backgroundTypeChanged);
   99     connect(ui.cbBackgroundColorStyle, QOverload<int>::of(&QComboBox::currentIndexChanged),
  100              this, &WorksheetDock::backgroundColorStyleChanged);
  101     connect(ui.cbBackgroundImageStyle, QOverload<int>::of(&QComboBox::currentIndexChanged),
  102              this, &WorksheetDock::backgroundImageStyleChanged);
  103     connect(ui.cbBackgroundBrushStyle, QOverload<int>::of(&QComboBox::currentIndexChanged),
  104              this, &WorksheetDock::backgroundBrushStyleChanged);
  105     connect(ui.bOpen, &QPushButton::clicked, this, &WorksheetDock::selectFile);
  106     connect(ui.leBackgroundFileName, &QLineEdit::returnPressed, this, &WorksheetDock::fileNameChanged);
  107     connect(ui.leBackgroundFileName, &QLineEdit::textChanged, this, &WorksheetDock::fileNameChanged);
  108     connect(ui.kcbBackgroundFirstColor, &KColorButton::changed, this, &WorksheetDock::backgroundFirstColorChanged);
  109     connect(ui.kcbBackgroundSecondColor, &KColorButton::changed, this, &WorksheetDock::backgroundSecondColorChanged);
  110     connect(ui.sbBackgroundOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
  111             this, &WorksheetDock::backgroundOpacityChanged);
  112 
  113     //Layout
  114     connect(ui.cbLayout, QOverload<int>::of(&QComboBox::currentIndexChanged),
  115              this, &WorksheetDock::layoutChanged);
  116     connect( ui.chScaleContent, &QCheckBox::clicked, this, &WorksheetDock::scaleContentChanged);
  117     connect( ui.sbLayoutTopMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  118              this, &WorksheetDock::layoutTopMarginChanged);
  119     connect( ui.sbLayoutBottomMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  120              this, &WorksheetDock::layoutBottomMarginChanged);
  121     connect( ui.sbLayoutLeftMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  122              this, &WorksheetDock::layoutLeftMarginChanged);
  123     connect( ui.sbLayoutRightMargin, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  124              this, &WorksheetDock::layoutRightMarginChanged);
  125     connect( ui.sbLayoutHorizontalSpacing, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  126              this, &WorksheetDock::layoutHorizontalSpacingChanged);
  127     connect( ui.sbLayoutVerticalSpacing, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
  128              this, &WorksheetDock::layoutVerticalSpacingChanged);
  129     connect( ui.sbLayoutRowCount, static_cast<void (QSpinBox::*) (int)>(&QSpinBox::valueChanged),
  130              this, &WorksheetDock::layoutRowCountChanged);
  131     connect( ui.sbLayoutColumnCount, static_cast<void (QSpinBox::*) (int)>(&QSpinBox::valueChanged),
  132              this, &WorksheetDock::layoutColumnCountChanged);
  133 
  134     //theme and template handlers
  135     auto* frame = new QFrame(this);
  136     auto* layout = new QHBoxLayout(frame);
  137     layout->setContentsMargins(0, 11, 0, 11);
  138 
  139     m_themeHandler = new ThemeHandler(this);
  140     layout->addWidget(m_themeHandler);
  141     connect(m_themeHandler, &ThemeHandler::loadThemeRequested, this, &WorksheetDock::loadTheme);
  142     connect(m_themeHandler, &ThemeHandler::info, this, &WorksheetDock::info);
  143 
  144     auto* templateHandler = new TemplateHandler(this, TemplateHandler::ClassName::Worksheet);
  145     layout->addWidget(templateHandler);
  146     connect(templateHandler, &TemplateHandler::loadConfigRequested, this, &WorksheetDock::loadConfigFromTemplate);
  147     connect(templateHandler, &TemplateHandler::saveConfigRequested, this, &WorksheetDock::saveConfigAsTemplate);
  148     connect(templateHandler, &TemplateHandler::info, this, &WorksheetDock::info);
  149 
  150     ui.verticalLayout->addWidget(frame);
  151 
  152     this->retranslateUi();
  153 }
  154 
  155 void WorksheetDock::setWorksheets(QList<Worksheet*> list) {
  156     m_initializing = true;
  157     m_worksheetList = list;
  158     m_worksheet = list.first();
  159     m_aspect = list.first();
  160 
  161     //if there are more then one worksheet in the list, disable the name and comment field in the tab "general"
  162     if (list.size() == 1) {
  163         ui.lName->setEnabled(true);
  164         ui.leName->setEnabled(true);
  165         ui.lComment->setEnabled(true);
  166         ui.leComment->setEnabled(true);
  167 
  168         ui.leName->setText(m_worksheet->name());
  169         ui.leComment->setText(m_worksheet->comment());
  170     } else {
  171         ui.lName->setEnabled(false);
  172         ui.leName->setEnabled(false);
  173         ui.lComment->setEnabled(false);
  174         ui.leComment->setEnabled(false);
  175 
  176         ui.leName->setText(QString());
  177         ui.leComment->setText(QString());
  178     }
  179     ui.leName->setStyleSheet("");
  180     ui.leName->setToolTip("");
  181 
  182     //show the properties of the first worksheet
  183     this->load();
  184     this->worksheetLayoutChanged(m_worksheet->layout());
  185 
  186     m_themeHandler->setCurrentTheme(m_worksheet->theme());
  187 
  188     connect(m_worksheet, &Worksheet::aspectDescriptionChanged, this, &WorksheetDock::worksheetDescriptionChanged);
  189     connect(m_worksheet, &Worksheet::pageRectChanged, this, &WorksheetDock::worksheetPageRectChanged);
  190     connect(m_worksheet, &Worksheet::scaleContentChanged, this, &WorksheetDock::worksheetScaleContentChanged);
  191 
  192     connect(m_worksheet, &Worksheet::backgroundTypeChanged, this, &WorksheetDock::worksheetBackgroundTypeChanged);
  193     connect(m_worksheet, &Worksheet::backgroundColorStyleChanged, this, &WorksheetDock::worksheetBackgroundColorStyleChanged);
  194     connect(m_worksheet, &Worksheet::backgroundImageStyleChanged, this, &WorksheetDock::worksheetBackgroundImageStyleChanged);
  195     connect(m_worksheet, &Worksheet::backgroundBrushStyleChanged, this, &WorksheetDock::worksheetBackgroundBrushStyleChanged);
  196     connect(m_worksheet, &Worksheet::backgroundFirstColorChanged, this, &WorksheetDock::worksheetBackgroundFirstColorChanged);
  197     connect(m_worksheet, &Worksheet::backgroundSecondColorChanged, this, &WorksheetDock::worksheetBackgroundSecondColorChanged);
  198     connect(m_worksheet, &Worksheet::backgroundFileNameChanged, this, &WorksheetDock::worksheetBackgroundFileNameChanged);
  199     connect(m_worksheet, &Worksheet::backgroundOpacityChanged, this, &WorksheetDock::worksheetBackgroundOpacityChanged);
  200 
  201     connect(m_worksheet, &Worksheet::layoutChanged, this, &WorksheetDock::worksheetLayoutChanged);
  202     connect(m_worksheet, &Worksheet::layoutTopMarginChanged, this, &WorksheetDock::worksheetLayoutTopMarginChanged);
  203     connect(m_worksheet, &Worksheet::layoutBottomMarginChanged, this, &WorksheetDock::worksheetLayoutBottomMarginChanged);
  204     connect(m_worksheet, &Worksheet::layoutLeftMarginChanged, this, &WorksheetDock::worksheetLayoutLeftMarginChanged);
  205     connect(m_worksheet, &Worksheet::layoutRightMarginChanged, this, &WorksheetDock::worksheetLayoutRightMarginChanged);
  206     connect(m_worksheet, &Worksheet::layoutVerticalSpacingChanged, this, &WorksheetDock::worksheetLayoutVerticalSpacingChanged);
  207     connect(m_worksheet, &Worksheet::layoutHorizontalSpacingChanged, this, &WorksheetDock::worksheetLayoutHorizontalSpacingChanged);
  208     connect(m_worksheet, &Worksheet::layoutRowCountChanged, this, &WorksheetDock::worksheetLayoutRowCountChanged);
  209     connect(m_worksheet, &Worksheet::layoutColumnCountChanged, this, &WorksheetDock::worksheetLayoutColumnCountChanged);
  210 
  211     connect(m_worksheet, &Worksheet::themeChanged, m_themeHandler, &ThemeHandler::setCurrentTheme);
  212 
  213     m_initializing = false;
  214 }
  215 
  216 void WorksheetDock::updateLocale() {
  217     SET_NUMBER_LOCALE
  218     ui.sbWidth->setLocale(numberLocale);
  219     ui.sbHeight->setLocale(numberLocale);
  220     ui.sbLayoutTopMargin->setLocale(numberLocale);
  221     ui.sbLayoutBottomMargin->setLocale(numberLocale);
  222     ui.sbLayoutLeftMargin->setLocale(numberLocale);
  223     ui.sbLayoutRightMargin->setLocale(numberLocale);
  224     ui.sbLayoutHorizontalSpacing->setLocale(numberLocale);
  225     ui.sbLayoutVerticalSpacing->setLocale(numberLocale);
  226 }
  227 
  228 void WorksheetDock::updateUnits() {
  229     const KConfigGroup group = KSharedConfig::openConfig()->group(QLatin1String("Settings_General"));
  230     BaseDock::Units units = (BaseDock::Units)group.readEntry("Units", static_cast<int>(Units::Metric));
  231     if (units == m_units)
  232         return;
  233 
  234     m_units = units;
  235     Lock lock(m_initializing);
  236     QString suffix;
  237     if (m_units == Units::Metric) {
  238         //convert from imperial to metric
  239         m_worksheetUnit = Worksheet::Unit::Centimeter;
  240         suffix = QLatin1String(" cm");
  241         ui.sbWidth->setValue(ui.sbWidth->value()*2.54);
  242         ui.sbHeight->setValue(ui.sbHeight->value()*2.54);
  243         ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()*2.54);
  244         ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()*2.54);
  245         ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()*2.54);
  246         ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()*2.54);
  247         ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()*2.54);
  248         ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()*2.54);
  249     } else {
  250         //convert from metric to imperial
  251         m_worksheetUnit = Worksheet::Unit::Inch;
  252         suffix = QLatin1String(" in");
  253         ui.sbWidth->setValue(ui.sbWidth->value()/2.54);
  254         ui.sbHeight->setValue(ui.sbHeight->value()/2.54);
  255         ui.sbLayoutTopMargin->setValue(ui.sbLayoutTopMargin->value()/2.54);
  256         ui.sbLayoutBottomMargin->setValue(ui.sbLayoutBottomMargin->value()/2.54);
  257         ui.sbLayoutLeftMargin->setValue(ui.sbLayoutLeftMargin->value()/2.54);
  258         ui.sbLayoutRightMargin->setValue(ui.sbLayoutRightMargin->value()/2.54);
  259         ui.sbLayoutHorizontalSpacing->setValue(ui.sbLayoutHorizontalSpacing->value()/2.54);
  260         ui.sbLayoutVerticalSpacing->setValue(ui.sbLayoutVerticalSpacing->value()/2.54);
  261     }
  262 
  263     ui.sbWidth->setSuffix(suffix);
  264     ui.sbHeight->setSuffix(suffix);
  265     ui.sbLayoutTopMargin->setSuffix(suffix);
  266     ui.sbLayoutBottomMargin->setSuffix(suffix);
  267     ui.sbLayoutLeftMargin->setSuffix(suffix);
  268     ui.sbLayoutRightMargin->setSuffix(suffix);
  269     ui.sbLayoutHorizontalSpacing->setSuffix(suffix);
  270     ui.sbLayoutVerticalSpacing->setSuffix(suffix);
  271 }
  272 
  273 /*!
  274     Checks whether the size is one of the QPageSize::PageSizeId and
  275     updates Size and Orientation checkbox when width/height changes.
  276 */
  277 void WorksheetDock::updatePaperSize() {
  278     if (m_worksheet->useViewSize()) {
  279         ui.cbSize->setCurrentIndex(0);
  280         return;
  281     }
  282 
  283     double w = ui.sbWidth->value();
  284     double h = ui.sbHeight->value();
  285     if (m_units == Units::Metric) {
  286         //In UI we use cm, so we need to convert to mm first before we check with QPageSize
  287         w *= 10;
  288         h *= 10;
  289     }
  290 
  291     const QSizeF s = QSizeF(w, h);
  292     const QSizeF st = s.transposed();
  293 
  294     //determine the position of the QPageSize::PageSizeId in the combobox
  295     bool found = false;
  296     for (int i = 0; i < ui.cbSize->count(); ++i) {
  297         const QVariant v = ui.cbSize->itemData(i);
  298         if (!v.isValid())
  299             continue;
  300 
  301         const auto id = v.value<QPageSize::PageSizeId>();
  302         QPageSize::Unit pageUnit = (m_units == Units::Metric) ? QPageSize::Millimeter : QPageSize::Inch;
  303         const QSizeF ps = QPageSize::size(id, pageUnit);
  304         if (s == ps) { //check the portrait-orientation first
  305             ui.cbSize->setCurrentIndex(i);
  306             ui.cbOrientation->setCurrentIndex(0);  //a QPageSize::PaperSize in portrait-orientation was found
  307             found = true;
  308             break;
  309         } else if (st == ps) { //check for the landscape-orientation
  310             ui.cbSize->setCurrentIndex(i);
  311             ui.cbOrientation->setCurrentIndex(1); //a QPageSize::PaperSize in landscape-orientation was found
  312             found = true;
  313             break;
  314         }
  315     }
  316 
  317     if (!found)
  318         ui.cbSize->setCurrentIndex(ui.cbSize->count() - 1); //select "Custom" size
  319 }
  320 
  321 //*************************************************************
  322 //****** SLOTs for changes triggered in WorksheetDock *********
  323 //*************************************************************
  324 void WorksheetDock::retranslateUi() {
  325     Lock lock(m_initializing);
  326 
  327     //Geometry
  328     ui.cbOrientation->clear();
  329     ui.cbOrientation->addItem(i18n("Portrait"));
  330     ui.cbOrientation->addItem(i18n("Landscape"));
  331 
  332     QString suffix;
  333     if (m_units == Units::Metric)
  334         suffix = QLatin1String(" cm");
  335     else
  336         suffix = QLatin1String(" in");
  337 
  338     ui.sbWidth->setSuffix(suffix);
  339     ui.sbHeight->setSuffix(suffix);
  340     ui.sbLayoutTopMargin->setSuffix(suffix);
  341     ui.sbLayoutBottomMargin->setSuffix(suffix);
  342     ui.sbLayoutLeftMargin->setSuffix(suffix);
  343     ui.sbLayoutRightMargin->setSuffix(suffix);
  344     ui.sbLayoutHorizontalSpacing->setSuffix(suffix);
  345     ui.sbLayoutVerticalSpacing->setSuffix(suffix);
  346 
  347     const QVector<QPageSize::PageSizeId> pageSizeIds = {
  348         QPageSize::A0,
  349         QPageSize::A1,
  350         QPageSize::A2,
  351         QPageSize::A3,
  352         QPageSize::A4,
  353         QPageSize::A5,
  354         QPageSize::A6,
  355         QPageSize::A7,
  356         QPageSize::A8,
  357         QPageSize::A9,
  358         QPageSize::B0,
  359         QPageSize::B1,
  360         QPageSize::B2,
  361         QPageSize::B3,
  362         QPageSize::B4,
  363         QPageSize::B5,
  364         QPageSize::B6,
  365         QPageSize::B7,
  366         QPageSize::B8,
  367         QPageSize::B9,
  368         QPageSize::B10,
  369         QPageSize::C5E,
  370         QPageSize::DLE,
  371         QPageSize::Executive,
  372         QPageSize::Folio,
  373         QPageSize::Ledger,
  374         QPageSize::Legal,
  375         QPageSize::Letter,
  376         QPageSize::Tabloid,
  377         QPageSize::Comm10E,
  378         QPageSize::Custom,
  379     };
  380     ui.cbSize->clear();
  381     ui.cbSize->addItem(i18n("View Size"));
  382     for (auto id : pageSizeIds)
  383         ui.cbSize->addItem(QPageSize::name(id), id);
  384     ui.cbSize->insertSeparator(1);
  385 
  386     //Background
  387     ui.cbBackgroundType->clear();
  388     ui.cbBackgroundType->addItem(i18n("Color"));
  389     ui.cbBackgroundType->addItem(i18n("Image"));
  390     ui.cbBackgroundType->addItem(i18n("Pattern"));
  391 
  392     ui.cbBackgroundColorStyle->clear();
  393     ui.cbBackgroundColorStyle->addItem(i18n("Single Color"));
  394     ui.cbBackgroundColorStyle->addItem(i18n("Horizontal Gradient"));
  395     ui.cbBackgroundColorStyle->addItem(i18n("Vertical Gradient"));
  396     ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Top Left)"));
  397     ui.cbBackgroundColorStyle->addItem(i18n("Diag. Gradient (From Bottom Left)"));
  398     ui.cbBackgroundColorStyle->addItem(i18n("Radial Gradient"));
  399 
  400     ui.cbBackgroundImageStyle->clear();
  401     ui.cbBackgroundImageStyle->addItem(i18n("Scaled and Cropped"));
  402     ui.cbBackgroundImageStyle->addItem(i18n("Scaled"));
  403     ui.cbBackgroundImageStyle->addItem(i18n("Scaled, Keep Proportions"));
  404     ui.cbBackgroundImageStyle->addItem(i18n("Centered"));
  405     ui.cbBackgroundImageStyle->addItem(i18n("Tiled"));
  406     ui.cbBackgroundImageStyle->addItem(i18n("Center Tiled"));
  407     GuiTools::updateBrushStyles(ui.cbBackgroundBrushStyle, Qt::SolidPattern);
  408 }
  409 
  410 // "General"-tab
  411 void WorksheetDock::scaleContentChanged(bool scaled) {
  412     if (m_initializing)
  413         return;
  414 
  415     for (auto* worksheet : m_worksheetList)
  416         worksheet->setScaleContent(scaled);
  417 }
  418 
  419 void WorksheetDock::sizeChanged(int i) {
  420     const auto index = ui.cbSize->itemData(i).value<QPageSize::PageSizeId>();
  421 
  422     if (index == QPageSize::Custom) {
  423         ui.sbWidth->setEnabled(true);
  424         ui.sbHeight->setEnabled(true);
  425         ui.lOrientation->hide();
  426         ui.cbOrientation->hide();
  427     } else {
  428         ui.sbWidth->setEnabled(false);
  429         ui.sbHeight->setEnabled(false);
  430         if (i == 0) { //no orientation available when using the complete view size (first item in the combox is selected)
  431             ui.lOrientation->hide();
  432             ui.cbOrientation->hide();
  433         } else {
  434             ui.lOrientation->show();
  435             ui.cbOrientation->show();
  436         }
  437     }
  438 
  439     if (m_initializing)
  440         return;
  441 
  442     Lock lock(m_initializing);
  443     if (i == 0) {
  444         //use the complete view size (first item in the combox is selected)
  445         for (auto* worksheet : m_worksheetList)
  446             worksheet->setUseViewSize(true);
  447     } else if (index == QPageSize::Custom) {
  448         if (m_worksheet->useViewSize()) {
  449             for (auto* worksheet : m_worksheetList)
  450                 worksheet->setUseViewSize(false);
  451         }
  452     } else {
  453         //determine the width and the height of the to be used predefined layout
  454         QSizeF s = QPageSize::size(index, QPageSize::Millimeter);
  455         if (ui.cbOrientation->currentIndex() == 1)
  456             s.transpose();
  457 
  458         //s is in mm, in UI we show everything in cm/in
  459         if (m_units == Units::Metric) {
  460             ui.sbWidth->setValue(s.width()/10);
  461             ui.sbHeight->setValue(s.height()/10);
  462         } else {
  463             ui.sbWidth->setValue(s.width()/25.4);
  464             ui.sbHeight->setValue(s.height()/25.4);
  465         }
  466 
  467         float w = Worksheet::convertToSceneUnits(s.width(), Worksheet::Unit::Millimeter);
  468         float h = Worksheet::convertToSceneUnits(s.height(), Worksheet::Unit::Millimeter);
  469         for (auto* worksheet : m_worksheetList) {
  470             worksheet->setUseViewSize(false);
  471             worksheet->setPageRect(QRect(0,0,w,h));
  472         }
  473     }
  474 }
  475 
  476 void WorksheetDock::sizeChanged() {
  477     if (m_initializing)
  478         return;
  479 
  480     int w = Worksheet::convertToSceneUnits(ui.sbWidth->value(), m_worksheetUnit);
  481     int h = Worksheet::convertToSceneUnits(ui.sbHeight->value(), m_worksheetUnit);
  482     for (auto* worksheet : m_worksheetList)
  483         worksheet->setPageRect(QRect(0,0,w,h));
  484 }
  485 
  486 void WorksheetDock::orientationChanged(int index) {
  487     Q_UNUSED(index);
  488     if (m_initializing)
  489         return;
  490 
  491     this->sizeChanged(ui.cbSize->currentIndex());
  492 }
  493 
  494 // "Background"-tab
  495 void WorksheetDock::backgroundTypeChanged(int index) {
  496     if (index == -1)
  497         return;
  498 
  499     auto type = (PlotArea::BackgroundType)index;
  500 
  501     if (type == PlotArea::BackgroundType::Color) {
  502         ui.lBackgroundColorStyle->show();
  503         ui.cbBackgroundColorStyle->show();
  504         ui.lBackgroundImageStyle->hide();
  505         ui.cbBackgroundImageStyle->hide();
  506         ui.lBackgroundBrushStyle->hide();
  507         ui.cbBackgroundBrushStyle->hide();
  508 
  509         ui.lBackgroundFileName->hide();
  510         ui.leBackgroundFileName->hide();
  511         ui.bOpen->hide();
  512 
  513         ui.lBackgroundFirstColor->show();
  514         ui.kcbBackgroundFirstColor->show();
  515 
  516         auto style = (PlotArea::BackgroundColorStyle)ui.cbBackgroundColorStyle->currentIndex();
  517         if (style == PlotArea::BackgroundColorStyle::SingleColor) {
  518             ui.lBackgroundFirstColor->setText(i18n("Color:"));
  519             ui.lBackgroundSecondColor->hide();
  520             ui.kcbBackgroundSecondColor->hide();
  521         } else {
  522             ui.lBackgroundFirstColor->setText(i18n("First color:"));
  523             ui.lBackgroundSecondColor->show();
  524             ui.kcbBackgroundSecondColor->show();
  525         }
  526     } else if (type == PlotArea::BackgroundType::Image) {
  527         ui.lBackgroundFirstColor->hide();
  528         ui.kcbBackgroundFirstColor->hide();
  529         ui.lBackgroundSecondColor->hide();
  530         ui.kcbBackgroundSecondColor->hide();
  531 
  532         ui.lBackgroundColorStyle->hide();
  533         ui.cbBackgroundColorStyle->hide();
  534         ui.lBackgroundImageStyle->show();
  535         ui.cbBackgroundImageStyle->show();
  536         ui.lBackgroundBrushStyle->hide();
  537         ui.cbBackgroundBrushStyle->hide();
  538         ui.lBackgroundFileName->show();
  539         ui.leBackgroundFileName->show();
  540         ui.bOpen->show();
  541     } else if (type == PlotArea::BackgroundType::Pattern) {
  542         ui.lBackgroundFirstColor->setText(i18n("Color:"));
  543         ui.lBackgroundFirstColor->show();
  544         ui.kcbBackgroundFirstColor->show();
  545         ui.lBackgroundSecondColor->hide();
  546         ui.kcbBackgroundSecondColor->hide();
  547 
  548         ui.lBackgroundColorStyle->hide();
  549         ui.cbBackgroundColorStyle->hide();
  550         ui.lBackgroundImageStyle->hide();
  551         ui.cbBackgroundImageStyle->hide();
  552         ui.lBackgroundBrushStyle->show();
  553         ui.cbBackgroundBrushStyle->show();
  554         ui.lBackgroundFileName->hide();
  555         ui.leBackgroundFileName->hide();
  556         ui.bOpen->hide();
  557     }
  558 
  559     if (m_initializing)
  560         return;
  561 
  562     for (auto* worksheet : m_worksheetList)
  563         worksheet->setBackgroundType(type);
  564 }
  565 
  566 void WorksheetDock::backgroundColorStyleChanged(int index) {
  567     if (index == -1)
  568         return;
  569 
  570     auto style = (PlotArea::BackgroundColorStyle)index;
  571 
  572     if (style == PlotArea::BackgroundColorStyle::SingleColor) {
  573         ui.lBackgroundFirstColor->setText(i18n("Color:"));
  574         ui.lBackgroundSecondColor->hide();
  575         ui.kcbBackgroundSecondColor->hide();
  576     } else {
  577         ui.lBackgroundFirstColor->setText(i18n("First color:"));
  578         ui.lBackgroundSecondColor->show();
  579         ui.kcbBackgroundSecondColor->show();
  580     }
  581 
  582     if (m_initializing)
  583         return;
  584 
  585     int size = m_worksheetList.size();
  586     if (size>1) {
  587         m_worksheet->beginMacro(i18n("%1 worksheets: background color style changed", size));
  588         for (auto* w : m_worksheetList)
  589             w->setBackgroundColorStyle(style);
  590         m_worksheet->endMacro();
  591     } else
  592         m_worksheet->setBackgroundColorStyle(style);
  593 }
  594 
  595 void WorksheetDock::backgroundImageStyleChanged(int index) {
  596     if (m_initializing)
  597         return;
  598 
  599     auto style = (PlotArea::BackgroundImageStyle)index;
  600     for (auto* worksheet : m_worksheetList)
  601         worksheet->setBackgroundImageStyle(style);
  602 }
  603 
  604 void WorksheetDock::backgroundBrushStyleChanged(int index) {
  605     if (m_initializing)
  606         return;
  607 
  608     auto style = (Qt::BrushStyle)index;
  609     for (auto* worksheet : m_worksheetList)
  610         worksheet->setBackgroundBrushStyle(style);
  611 }
  612 
  613 void WorksheetDock::backgroundFirstColorChanged(const QColor& c) {
  614     if (m_initializing)
  615         return;
  616 
  617     for (auto* worksheet : m_worksheetList)
  618         worksheet->setBackgroundFirstColor(c);
  619 }
  620 
  621 void WorksheetDock::backgroundSecondColorChanged(const QColor& c) {
  622     if (m_initializing)
  623         return;
  624 
  625     for (auto* worksheet : m_worksheetList)
  626         worksheet->setBackgroundSecondColor(c);
  627 }
  628 
  629 void WorksheetDock::backgroundOpacityChanged(int value) {
  630     if (m_initializing)
  631         return;
  632 
  633     float opacity = (float)value/100;
  634     for (auto* worksheet : m_worksheetList)
  635         worksheet->setBackgroundOpacity(opacity);
  636 }
  637 
  638 //"Layout"-tab
  639 void WorksheetDock::layoutChanged(int index) {
  640     auto layout = (Worksheet::Layout)index;
  641 
  642     bool b = (layout != Worksheet::Layout::NoLayout);
  643     ui.sbLayoutTopMargin->setEnabled(b);
  644     ui.sbLayoutBottomMargin->setEnabled(b);
  645     ui.sbLayoutLeftMargin->setEnabled(b);
  646     ui.sbLayoutRightMargin->setEnabled(b);
  647     ui.sbLayoutHorizontalSpacing->setEnabled(b);
  648     ui.sbLayoutVerticalSpacing->setEnabled(b);
  649     ui.sbLayoutRowCount->setEnabled(b);
  650     ui.sbLayoutColumnCount->setEnabled(b);
  651 
  652     //show the "scale content" option if no layout active
  653     ui.lScaleContent->setVisible(!b);
  654     ui.chScaleContent->setVisible(!b);
  655 
  656     if (b) {
  657         //show grid specific settings if grid layout selected
  658         bool grid = (layout == Worksheet::Layout::GridLayout);
  659         ui.lGrid->setVisible(grid);
  660         ui.lRowCount->setVisible(grid);
  661         ui.sbLayoutRowCount->setVisible(grid);
  662         ui.lColumnCount->setVisible(grid);
  663         ui.sbLayoutColumnCount->setVisible(grid);
  664     } else {
  665         //no layout selected, hide grid specific settings that were potentially shown before
  666         ui.lGrid->setVisible(false);
  667         ui.lRowCount->setVisible(false);
  668         ui.sbLayoutRowCount->setVisible(false);
  669         ui.lColumnCount->setVisible(false);
  670         ui.sbLayoutColumnCount->setVisible(false);
  671     }
  672 
  673     if (m_initializing)
  674         return;
  675 
  676     for (auto* worksheet : m_worksheetList)
  677         worksheet->setLayout(layout);
  678 }
  679 
  680 void WorksheetDock::layoutTopMarginChanged(double margin) {
  681     if (m_initializing)
  682         return;
  683 
  684     for (auto* worksheet : m_worksheetList)
  685         worksheet->setLayoutTopMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit));
  686 }
  687 
  688 void WorksheetDock::layoutBottomMarginChanged(double margin) {
  689     if (m_initializing)
  690         return;
  691 
  692     for (auto* worksheet : m_worksheetList)
  693         worksheet->setLayoutBottomMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit));
  694 }
  695 
  696 void WorksheetDock::layoutLeftMarginChanged(double margin) {
  697     if (m_initializing)
  698         return;
  699 
  700     for (auto* worksheet : m_worksheetList)
  701         worksheet->setLayoutLeftMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit));
  702 }
  703 
  704 void WorksheetDock::layoutRightMarginChanged(double margin) {
  705     if (m_initializing)
  706         return;
  707 
  708     for (auto* worksheet : m_worksheetList)
  709         worksheet->setLayoutRightMargin(Worksheet::convertToSceneUnits(margin, m_worksheetUnit));
  710 }
  711 
  712 void WorksheetDock::layoutHorizontalSpacingChanged(double spacing) {
  713     if (m_initializing)
  714         return;
  715 
  716     for (auto* worksheet : m_worksheetList)
  717         worksheet->setLayoutHorizontalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit));
  718 }
  719 
  720 void WorksheetDock::layoutVerticalSpacingChanged(double spacing) {
  721     if (m_initializing)
  722         return;
  723 
  724     for (auto* worksheet : m_worksheetList)
  725         worksheet->setLayoutVerticalSpacing(Worksheet::convertToSceneUnits(spacing, m_worksheetUnit));
  726 }
  727 
  728 void WorksheetDock::layoutRowCountChanged(int count) {
  729     if (m_initializing)
  730         return;
  731 
  732     for (auto* worksheet : m_worksheetList)
  733         worksheet->setLayoutRowCount(count);
  734 }
  735 
  736 void WorksheetDock::layoutColumnCountChanged(int count) {
  737     if (m_initializing)
  738         return;
  739 
  740     for (auto* worksheet : m_worksheetList)
  741         worksheet->setLayoutColumnCount(count);
  742 }
  743 
  744 /*!
  745     opens a file dialog and lets the user select the image file.
  746 */
  747 void WorksheetDock::selectFile() {
  748     KConfigGroup conf(KSharedConfig::openConfig(), "WorksheetDock");
  749     QString dir = conf.readEntry("LastImageDir", "");
  750 
  751     QString formats;
  752     for (const QByteArray& format : QImageReader::supportedImageFormats()) {
  753         QString f = "*." + QString(format.constData());
  754         if (f == QLatin1String("*.svg"))
  755             continue;
  756         formats.isEmpty() ? formats += f : formats += ' ' + f;
  757     }
  758 
  759     QString path = QFileDialog::getOpenFileName(this, i18n("Select the image file"), dir, i18n("Images (%1)", formats));
  760     if (path.isEmpty())
  761         return; //cancel was clicked in the file-dialog
  762 
  763     int pos = path.lastIndexOf(QLatin1String("/"));
  764     if (pos != -1) {
  765         QString newDir = path.left(pos);
  766         if (newDir != dir)
  767             conf.writeEntry("LastImageDir", newDir);
  768     }
  769 
  770     ui.leBackgroundFileName->setText( path );
  771 
  772     for (auto* worksheet : m_worksheetList)
  773         worksheet->setBackgroundFileName(path);
  774 }
  775 
  776 void WorksheetDock::fileNameChanged() {
  777     if (m_initializing)
  778         return;
  779 
  780     const QString& fileName = ui.leBackgroundFileName->text();
  781     bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName));
  782     GuiTools::highlight(ui.leBackgroundFileName, invalid);
  783 
  784     for (auto* worksheet : m_worksheetList)
  785         worksheet->setBackgroundFileName(fileName);
  786 }
  787 
  788 //*************************************************************
  789 //******** SLOTs for changes triggered in Worksheet ***********
  790 //*************************************************************
  791 void WorksheetDock::worksheetDescriptionChanged(const AbstractAspect* aspect) {
  792     if (m_worksheet != aspect)
  793         return;
  794 
  795     m_initializing = true;
  796     if (aspect->name() != ui.leName->text())
  797         ui.leName->setText(aspect->name());
  798     else if (aspect->comment() != ui.leComment->text())
  799         ui.leComment->setText(aspect->comment());
  800     m_initializing = false;
  801 }
  802 
  803 void WorksheetDock::worksheetScaleContentChanged(bool scaled) {
  804     m_initializing = true;
  805     ui.chScaleContent->setChecked(scaled);
  806     m_initializing = false;
  807 }
  808 
  809 void WorksheetDock::worksheetPageRectChanged(const QRectF& rect) {
  810     m_initializing = true;
  811     ui.sbWidth->setValue(Worksheet::convertFromSceneUnits(rect.width(), m_worksheetUnit));
  812     ui.sbHeight->setValue(Worksheet::convertFromSceneUnits(rect.height(), m_worksheetUnit));
  813     updatePaperSize();
  814     m_initializing = false;
  815 }
  816 
  817 void WorksheetDock::worksheetBackgroundTypeChanged(PlotArea::BackgroundType type) {
  818     m_initializing = true;
  819     ui.cbBackgroundType->setCurrentIndex(static_cast<int>(type));
  820     m_initializing = false;
  821 }
  822 
  823 void WorksheetDock::worksheetBackgroundColorStyleChanged(PlotArea::BackgroundColorStyle style) {
  824     m_initializing = true;
  825     ui.cbBackgroundColorStyle->setCurrentIndex(static_cast<int>(style));
  826     m_initializing = false;
  827 }
  828 
  829 void WorksheetDock::worksheetBackgroundImageStyleChanged(PlotArea::BackgroundImageStyle style) {
  830     m_initializing = true;
  831     ui.cbBackgroundImageStyle->setCurrentIndex(static_cast<int>(style));
  832     m_initializing = false;
  833 }
  834 
  835 void WorksheetDock::worksheetBackgroundBrushStyleChanged(Qt::BrushStyle style) {
  836     m_initializing = true;
  837     ui.cbBackgroundBrushStyle->setCurrentIndex(style);
  838     m_initializing = false;
  839 }
  840 
  841 void WorksheetDock::worksheetBackgroundFirstColorChanged(const QColor& color) {
  842     m_initializing = true;
  843     ui.kcbBackgroundFirstColor->setColor(color);
  844     m_initializing = false;
  845 }
  846 
  847 void WorksheetDock::worksheetBackgroundSecondColorChanged(const QColor& color) {
  848     m_initializing = true;
  849     ui.kcbBackgroundSecondColor->setColor(color);
  850     m_initializing = false;
  851 }
  852 
  853 void WorksheetDock::worksheetBackgroundFileNameChanged(const QString& name) {
  854     m_initializing = true;
  855     ui.leBackgroundFileName->setText(name);
  856     m_initializing = false;
  857 }
  858 
  859 void WorksheetDock::worksheetBackgroundOpacityChanged(float opacity) {
  860     m_initializing = true;
  861     ui.sbBackgroundOpacity->setValue( qRound(opacity*100.0) );
  862     m_initializing = false;
  863 }
  864 
  865 void WorksheetDock::worksheetLayoutChanged(Worksheet::Layout layout) {
  866     m_initializing = true;
  867     ui.cbLayout->setCurrentIndex(static_cast<int>(layout));
  868     m_initializing = false;
  869 }
  870 
  871 void WorksheetDock::worksheetLayoutTopMarginChanged(float value) {
  872     m_initializing = true;
  873     ui.sbLayoutTopMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  874     m_initializing = false;
  875 }
  876 
  877 void WorksheetDock::worksheetLayoutBottomMarginChanged(float value) {
  878     m_initializing = true;
  879     ui.sbLayoutBottomMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  880     m_initializing = false;
  881 }
  882 
  883 void WorksheetDock::worksheetLayoutLeftMarginChanged(float value) {
  884     m_initializing = true;
  885     ui.sbLayoutLeftMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  886     m_initializing = false;
  887 }
  888 
  889 void WorksheetDock::worksheetLayoutRightMarginChanged(float value) {
  890     m_initializing = true;
  891     ui.sbLayoutRightMargin->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  892     m_initializing = false;
  893 }
  894 
  895 void WorksheetDock::worksheetLayoutVerticalSpacingChanged(float value) {
  896     m_initializing = true;
  897     ui.sbLayoutVerticalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  898     m_initializing = false;
  899 }
  900 
  901 void WorksheetDock::worksheetLayoutHorizontalSpacingChanged(float value) {
  902     m_initializing = true;
  903     ui.sbLayoutHorizontalSpacing->setValue(Worksheet::convertFromSceneUnits(value, m_worksheetUnit));
  904     m_initializing = false;
  905 }
  906 
  907 void WorksheetDock::worksheetLayoutRowCountChanged(int value) {
  908     m_initializing = true;
  909     ui.sbLayoutRowCount->setValue(value);
  910     m_initializing = false;
  911 }
  912 
  913 void WorksheetDock::worksheetLayoutColumnCountChanged(int value) {
  914     m_initializing = true;
  915     ui.sbLayoutColumnCount->setValue(value);
  916     m_initializing = false;
  917 }
  918 
  919 //*************************************************************
  920 //******************** SETTINGS *******************************
  921 //*************************************************************
  922 void WorksheetDock::load() {
  923     // Geometry
  924     ui.chScaleContent->setChecked(m_worksheet->scaleContent());
  925     ui.sbWidth->setValue(Worksheet::convertFromSceneUnits( m_worksheet->pageRect().width(), m_worksheetUnit) );
  926     ui.sbHeight->setValue(Worksheet::convertFromSceneUnits( m_worksheet->pageRect().height(), m_worksheetUnit) );
  927     updatePaperSize();
  928 
  929     // Background-tab
  930     ui.cbBackgroundType->setCurrentIndex( (int) m_worksheet->backgroundType() );
  931     ui.cbBackgroundColorStyle->setCurrentIndex( (int) m_worksheet->backgroundColorStyle() );
  932     ui.cbBackgroundImageStyle->setCurrentIndex( (int) m_worksheet->backgroundImageStyle() );
  933     ui.cbBackgroundBrushStyle->setCurrentIndex( (int) m_worksheet->backgroundBrushStyle() );
  934     ui.leBackgroundFileName->setText( m_worksheet->backgroundFileName() );
  935     ui.kcbBackgroundFirstColor->setColor( m_worksheet->backgroundFirstColor() );
  936     ui.kcbBackgroundSecondColor->setColor( m_worksheet->backgroundSecondColor() );
  937     ui.sbBackgroundOpacity->setValue( qRound(m_worksheet->backgroundOpacity()*100) );
  938 
  939     //highlight the text field for the background image red if an image is used and cannot be found
  940     const QString& fileName = m_worksheet->backgroundFileName();
  941     bool invalid = (!fileName.isEmpty() && !QFile::exists(fileName));
  942     GuiTools::highlight(ui.leBackgroundFileName, invalid);
  943 
  944     // Layout
  945     ui.cbLayout->setCurrentIndex( (int) m_worksheet->layout() );
  946     ui.sbLayoutTopMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutTopMargin(), m_worksheetUnit) );
  947     ui.sbLayoutBottomMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutBottomMargin(), m_worksheetUnit) );
  948     ui.sbLayoutLeftMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutLeftMargin(), m_worksheetUnit) );
  949     ui.sbLayoutRightMargin->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutRightMargin(), m_worksheetUnit) );
  950     ui.sbLayoutHorizontalSpacing->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutHorizontalSpacing(), m_worksheetUnit) );
  951     ui.sbLayoutVerticalSpacing->setValue( Worksheet::convertFromSceneUnits(m_worksheet->layoutVerticalSpacing(), m_worksheetUnit) );
  952 
  953     ui.sbLayoutRowCount->setValue( m_worksheet->layoutRowCount() );
  954     ui.sbLayoutColumnCount->setValue( m_worksheet->layoutColumnCount() );
  955 }
  956 
  957 void WorksheetDock::loadConfigFromTemplate(KConfig& config) {
  958     //extract the name of the template from the file name
  959     QString name;
  960     int index = config.name().lastIndexOf(QLatin1String("/"));
  961     if (index != -1)
  962         name = config.name().right(config.name().size() - index - 1);
  963     else
  964         name = config.name();
  965 
  966     int size = m_worksheetList.size();
  967     if (size > 1)
  968         m_worksheet->beginMacro(i18n("%1 worksheets: template \"%2\" loaded", size, name));
  969     else
  970         m_worksheet->beginMacro(i18n("%1: template \"%2\" loaded", m_worksheet->name(), name));
  971 
  972     this->loadConfig(config);
  973     m_worksheet->endMacro();
  974 }
  975 
  976 void WorksheetDock::loadConfig(KConfig& config) {
  977     KConfigGroup group = config.group( "Worksheet" );
  978 
  979     // Geometry
  980     ui.chScaleContent->setChecked(group.readEntry("ScaleContent", false));
  981     ui.sbWidth->setValue(Worksheet::convertFromSceneUnits(group.readEntry("Width", m_worksheet->pageRect().width()), m_worksheetUnit));
  982     ui.sbHeight->setValue(Worksheet::convertFromSceneUnits(group.readEntry("Height", m_worksheet->pageRect().height()), m_worksheetUnit));
  983     if (group.readEntry("UseViewSize", false))
  984         ui.cbSize->setCurrentIndex(0);
  985     else
  986         updatePaperSize();
  987 
  988     // Background-tab
  989     ui.cbBackgroundType->setCurrentIndex( group.readEntry("BackgroundType", (int) m_worksheet->backgroundType()) );
  990     ui.cbBackgroundColorStyle->setCurrentIndex( group.readEntry("BackgroundColorStyle", (int) m_worksheet->backgroundColorStyle()) );
  991     ui.cbBackgroundImageStyle->setCurrentIndex( group.readEntry("BackgroundImageStyle", (int) m_worksheet->backgroundImageStyle()) );
  992     ui.cbBackgroundBrushStyle->setCurrentIndex( group.readEntry("BackgroundBrushStyle", (int) m_worksheet->backgroundBrushStyle()) );
  993     ui.leBackgroundFileName->setText( group.readEntry("BackgroundFileName", m_worksheet->backgroundFileName()) );
  994     ui.kcbBackgroundFirstColor->setColor( group.readEntry("BackgroundFirstColor", m_worksheet->backgroundFirstColor()) );
  995     ui.kcbBackgroundSecondColor->setColor( group.readEntry("BackgroundSecondColor", m_worksheet->backgroundSecondColor()) );
  996     ui.sbBackgroundOpacity->setValue( qRound(group.readEntry("BackgroundOpacity", m_worksheet->backgroundOpacity())*100) );
  997 
  998     // Layout
  999     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 }