1 #include "sheetzoom.h"
2 #include "ui_sheetzoom.h"
3 
SheetZoom(Information * information,QWidget * parent)4 SheetZoom::SheetZoom(Information *information, QWidget *parent) :
5     QWidget(parent),
6     ui(new Ui::SheetZoom)
7 {
8     ui->setupUi(this);
9     this->information = information;
10 
11     connect(ui->zoomIn, &QPushButton::released, this, &SheetZoom::zoomIn);
12     connect(ui->zoomOut, &QPushButton::released, this, &SheetZoom::zoomOut);
13     connect(ui->zoomPercentage, SIGNAL(valueChanged(double)), this, SLOT(onZoomValueChange()));
14     connect(ui->fitSheet, SIGNAL(toggled(bool)), this, SLOT(updateZoomSettings()));
15 
16     connect(information, SIGNAL(graphZoomSettingsChanged()), this, SLOT(onExternalZoomSettingsChange()));
17 
18     updateZoomSettings();
19 }
20 
resetZoom()21 void SheetZoom::resetZoom()
22 {
23     ui->zoomPercentage->setValue(100);
24 }
25 
updateZoomSettings()26 void SheetZoom::updateZoomSettings()
27 {
28     zoomSettings.zoom = ui->zoomPercentage->value() / 100;
29     zoomSettings.zoomingType = ui->fitSheet->isChecked() ? ZeZoomSettings::FITSHEET : ZeZoomSettings::CUSTOM;
30 
31     information->setGraphZoomSettings(zoomSettings);
32 }
33 
activateRealSizePreview()34 void SheetZoom::activateRealSizePreview()
35 {
36     ui->fitSheet->setChecked(false);
37     ui->zoomPercentage->setValue(100);
38 
39     updateZoomSettings();
40 }
41 
zoomIn()42 void SheetZoom::zoomIn()
43 {
44     ui->zoomPercentage->setValue(ui->zoomPercentage->value() + 5);
45 }
46 
zoomOut()47 void SheetZoom::zoomOut()
48 {
49     ui->zoomPercentage->setValue(ui->zoomPercentage->value() - 5);
50     // Method onZoomValueChange will be automatically called with signal slot mechanism
51 }
52 
onExternalZoomSettingsChange()53 void SheetZoom::onExternalZoomSettingsChange()
54 {
55     zoomSettings = information->getGraphZoomSettings();
56 
57     const QSignalBlocker blocker(ui->fitSheet);
58     const QSignalBlocker blocker2(ui->zoomPercentage);
59 
60     ui->fitSheet->setChecked(zoomSettings.zoomingType == ZeZoomSettings::FITSHEET);
61     ui->zoomPercentage->setValue(zoomSettings.zoom * 100);
62 }
63 
onZoomValueChange()64 void SheetZoom::onZoomValueChange()
65 {
66     ui->fitSheet->setChecked(false);
67 
68     updateZoomSettings();
69 }
70 
71 
~SheetZoom()72 SheetZoom::~SheetZoom()
73 {
74     delete ui;
75 }
76