Warning, file /office/calligra/libs/widgets/KoZoomWidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*  
0002     Copyright (C) 2004 Ariya Hidayat <ariya@kde.org>
0003     Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.com>
0004     Copyright (C) 2006-2007 C. Boemann <cbo@boemann.dk>
0005     Copyright (C) 2014 Sven Langkamp <sven.langkamp@gmail.com>
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License version 2 as published by the Free Software Foundation.
0010 
0011     This library is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014     Library General Public License for more details.
0015 
0016     You should have received a copy of the GNU Library General Public License
0017     along with this library; see the file COPYING.LIB.  If not, write to
0018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019     Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "KoZoomWidget.h"
0023 
0024 #include <QSlider>
0025 #include <QToolButton>
0026 #include <QBoxLayout>
0027 
0028 #include <klocalizedstring.h>
0029 
0030 #include "KoZoomInput.h"
0031 #include "KoIcon.h"
0032 
0033 class KoZoomWidget::Private
0034 {
0035 public:
0036 
0037     Private()
0038         : slider(nullptr)
0039         , input(nullptr)
0040         , aspectButton(nullptr)
0041     {}
0042 
0043     QSlider* slider;
0044     KoZoomInput* input;
0045     QToolButton* aspectButton;
0046 
0047     qreal effectiveZoom;
0048 };
0049 
0050 KoZoomWidget::KoZoomWidget(QWidget* parent, KoZoomAction::SpecialButtons specialButtons, int maxZoom )
0051     : QWidget(parent)
0052     , d(new Private)
0053 {
0054     QHBoxLayout *layout = new QHBoxLayout(this);
0055     //layout->setSizeConstraint(QLayout::SetFixedSize);
0056     layout->setMargin(0);
0057     layout->setSpacing(0);
0058 
0059     d->input = new KoZoomInput(this);
0060     connect(d->input, SIGNAL(zoomLevelChanged(QString)), this, SIGNAL(zoomLevelChanged(QString)));
0061     layout->addWidget(d->input);
0062 
0063     d->slider = new QSlider(Qt::Horizontal);
0064     d->slider->setToolTip(i18n("Zoom"));
0065     d->slider->setMinimum(0);
0066     d->slider->setMaximum(maxZoom);
0067     d->slider->setValue(0);
0068     d->slider->setSingleStep(1);
0069     d->slider->setPageStep(1);
0070     d->slider->setMinimumWidth(80);
0071     layout->addWidget(d->slider);
0072     layout->setStretch(1, 1);
0073 
0074     if (specialButtons & KoZoomAction::AspectMode) {
0075         d->aspectButton = new QToolButton(this);
0076         d->aspectButton->setIcon(koIcon("zoom-pixels"));
0077         d->aspectButton->setIconSize(QSize(16,16));
0078         d->aspectButton->setCheckable(true);
0079         d->aspectButton->setChecked(true);
0080         d->aspectButton->setAutoRaise(true);
0081         d->aspectButton->setToolTip(i18n("Use same aspect as pixels"));
0082         connect(d->aspectButton, SIGNAL(toggled(bool)), this, SIGNAL(aspectModeChanged(bool)));
0083         layout->addWidget(d->aspectButton);
0084     }
0085     if (specialButtons & KoZoomAction::ZoomToSelection) {
0086         QToolButton * zoomToSelectionButton = new QToolButton(this);
0087         zoomToSelectionButton->setIcon(koIcon("zoom-select"));
0088         zoomToSelectionButton->setIconSize(QSize(16,16));
0089         zoomToSelectionButton->setAutoRaise(true);
0090         zoomToSelectionButton->setToolTip(i18n("Zoom to Selection"));
0091         connect(zoomToSelectionButton, SIGNAL(clicked(bool)), this, SIGNAL(zoomedToSelection()));
0092         layout->addWidget(zoomToSelectionButton);
0093     }
0094     if (specialButtons & KoZoomAction::ZoomToAll) {
0095         QToolButton * zoomToAllButton = new QToolButton(this);
0096         zoomToAllButton->setIcon(koIcon("zoom-draw"));
0097         zoomToAllButton->setIconSize(QSize(16,16));
0098         zoomToAllButton->setAutoRaise(true);
0099         zoomToAllButton->setToolTip(i18n("Zoom to All"));
0100         connect(zoomToAllButton, SIGNAL(clicked(bool)), this, SIGNAL(zoomedToAll()));
0101         layout->addWidget(zoomToAllButton);
0102     }
0103     connect(d->slider, SIGNAL(valueChanged(int)), this, SIGNAL(sliderValueChanged(int)));
0104 }
0105 
0106 KoZoomWidget::~KoZoomWidget()
0107 {
0108 }
0109 
0110 void KoZoomWidget::setZoomLevels(const QStringList &values)
0111 {
0112     d->input->setZoomLevels(values);
0113 }
0114 
0115 void KoZoomWidget::setCurrentZoomLevel(const QString &valueString)
0116 {
0117     d->input->setCurrentZoomLevel(valueString);
0118 }
0119 
0120 void KoZoomWidget::setSliderValue(int value)
0121 {
0122     d->slider->blockSignals(true);
0123     d->slider->setValue(value);
0124     d->slider->blockSignals(false);
0125 }
0126 
0127 void KoZoomWidget::setAspectMode(bool status)
0128 {
0129     if(d->aspectButton && d->aspectButton->isChecked() != status) {
0130         d->aspectButton->blockSignals(true);
0131         d->aspectButton->setChecked(status);
0132         d->aspectButton->blockSignals(false);
0133     }
0134 }