Commit 4b2845b0 authored by Casper Boemann's avatar Casper Boemann

Change KoZoomAction to emit and use double based zoom values rather than

100% based int values

Krita has no problem as it uses the new KoZoomController, but 
other apps may break due to this - good reason to follow changes i guess


svn path=/trunk/koffice/; revision=644216
parent b7d0e2bd
......@@ -110,8 +110,8 @@ void KisZoomManager::setup( KActionCollection * actionCollection )
connect( m_canvasController, SIGNAL( canvasMousePositionChanged(const QPoint & ) ), this, SLOT( mousePositionChanged( const QPoint & ) ) );
connect(m_zoomController, SIGNAL(zoomChanged(KoZoomMode::Mode, int)),
this, SLOT(slotZoomChanged(KoZoomMode::Mode, int)));
connect(m_zoomController, SIGNAL(zoomChanged(KoZoomMode::Mode, double)),
this, SLOT(slotZoomChanged(KoZoomMode::Mode, double)));
}
void KisZoomManager::mousePositionChanged(const QPoint &pos)
......@@ -139,7 +139,7 @@ void KisZoomManager::updateGUI()
m_verticalRuler->setRulerLength(img->height() / img->yRes());
}
void KisZoomManager::slotZoomChanged(KoZoomMode::Mode mode, int zoom)
void KisZoomManager::slotZoomChanged(KoZoomMode::Mode mode, double zoom)
{
KisImageSP img = m_view->image();
......
......@@ -55,7 +55,7 @@ public:
private slots:
void slotZoomChanged(KoZoomMode::Mode mode, int zoom);
void slotZoomChanged(KoZoomMode::Mode mode, double zoom);
void slotActualSize();
void toggleShowRulers(bool show);
void mousePositionChanged(const QPoint &pos);
......
......@@ -22,6 +22,7 @@
#include "KoZoomAction.h"
#include <QString>
#include <QLocale>
#include <QStringList>
#include <QRegExp>
#include <QList>
......@@ -75,7 +76,7 @@ void KoZoomAction::setZoom( const QString& text )
setCurrentAction( text );
}
void KoZoomAction::setZoom( int zoom )
void KoZoomAction::setZoom( double zoom )
{
setZoom( i18n( "%1%", zoom ) );
}
......@@ -102,7 +103,7 @@ void KoZoomAction::triggered( const QString& text )
}
}
emit zoomChanged( mode, zoom );
emit zoomChanged( mode, zoom/100.0 );
}
void KoZoomAction::init(KActionCollection* parent, const QString &name)
......@@ -132,12 +133,12 @@ void KoZoomAction::init(KActionCollection* parent, const QString &name)
setMaxComboViewCount( 15 );
for(int i = 0; i<33; i++)
m_sliderLookup[i] = int(0.5 + 100 * pow(1.1892071, i - 16));
m_sliderLookup[i] = pow(1.1892071, i - 16);
regenerateItems(0);
setCurrentAction( i18n( "%1%", 100 ) );
m_effectiveZoom = 100;
m_effectiveZoom = 1.0;
connect( this, SIGNAL( triggered( const QString& ) ), SLOT( triggered( const QString& ) ) );
}
......@@ -214,7 +215,7 @@ void KoZoomAction::numberValueChanged()
kDebug(30004) << "number widget has changed to " << m_number->text() << endl;
setZoom(m_number->text());
int zoom = m_number->text().toInt();
double zoom = m_number->text().toDouble()/100.0;
emit zoomChanged( KoZoomMode::ZOOM_CONSTANT, zoom);
}
......@@ -229,7 +230,7 @@ void KoZoomAction::zoomIn()
i++;
// else i is the next zoom level already
int zoom = m_sliderLookup[i];
double zoom = m_sliderLookup[i];
setZoom(zoom);
emit zoomChanged( KoZoomMode::ZOOM_CONSTANT, zoom);
}
......@@ -243,7 +244,7 @@ void KoZoomAction::zoomOut()
if(i>0)
i--;
int zoom = m_sliderLookup[i];
double zoom = m_sliderLookup[i];
setZoom(zoom);
emit zoomChanged( KoZoomMode::ZOOM_CONSTANT, zoom);
}
......@@ -266,7 +267,7 @@ QWidget * KoZoomAction::createWidget( QWidget * _parent )
m_slider->setMinimumWidth(80);
m_slider->setMaximumWidth(80);
QValidator *validator = new QIntValidator(1, 1600, this);
QValidator *validator = new QDoubleValidator(1.0, 1600.0, 0, this);
m_number = new ExtLineEdit("100", group);
m_number->setValidator(validator);
m_number->setMaxLength(5);
......@@ -343,10 +344,9 @@ QWidget * KoZoomAction::createWidget( QWidget * _parent )
connect(numLabel, SIGNAL(customContextMenuRequested(const QPoint &)), m_number, SLOT(setFocus()));
connect(numLabel, SIGNAL(customContextMenuRequested(const QPoint &)), numLabel, SLOT(hide()));
connect(m_zoomButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(zoomModeButtonClicked(int)));
connect(this, SIGNAL(zoomChanged(KoZoomMode::Mode, int)), this, SLOT(updateWidgets(KoZoomMode::Mode, int)));
connect(this, SIGNAL(zoomChanged(KoZoomMode::Mode, double)), this, SLOT(updateWidgets(KoZoomMode::Mode, double)));
return group;
}
void KoZoomAction::zoomModeButtonClicked(int id)
......@@ -354,7 +354,7 @@ void KoZoomAction::zoomModeButtonClicked(int id)
triggered(KoZoomMode::toString(static_cast<KoZoomMode::Mode>(id)));
}
void KoZoomAction::updateWidgets(KoZoomMode::Mode mode, int zoom)
void KoZoomAction::updateWidgets(KoZoomMode::Mode mode, double zoom)
{
if(mode != KoZoomMode::ZOOM_CONSTANT) {
m_zoomButtonGroup->button(mode)->setChecked(true);
......@@ -372,12 +372,15 @@ void KoZoomAction::updateWidgets(KoZoomMode::Mode mode, int zoom)
}
}
void KoZoomAction::setEffectiveZoom(int zoom)
void KoZoomAction::setEffectiveZoom(double zoom)
{
m_effectiveZoom = zoom;
if(m_number) {
m_number->setText(QString::number(zoom));
if(zoom>0.1)
m_number->setText(KGlobal::locale()->formatNumber(zoom*100, 0));
else
m_number->setText(KGlobal::locale()->formatNumber(zoom*100, 1));
}
if(m_slider) {
......
......@@ -85,7 +85,7 @@ public Q_SLOTS:
* into the list at proper place so that the the values remain sorted.
* emits zoomChanged
*/
void setZoom( int zoom );
void setZoom( double zoom );
/**
* Change the zoom modes that should be shown
......@@ -110,7 +110,7 @@ public Q_SLOTS:
* Set the actual zoom value used in the app. This is needed when using @ref zoomIn() , @ref zoomOut() and/or when
* plugged into the viewbar.
*/
void setEffectiveZoom(int zoom);
void setEffectiveZoom(double zoom);
protected Q_SLOTS:
......@@ -118,7 +118,7 @@ protected Q_SLOTS:
void sliderValueChanged(int value);
void numberValueChanged();
void zoomModeButtonClicked(int id);
void updateWidgets(KoZoomMode::Mode mode, int zoom);
void updateWidgets(KoZoomMode::Mode mode, double zoom);
Q_SIGNALS:
......@@ -126,9 +126,9 @@ Q_SIGNALS:
* Signal zoomChanged is triggered when user changes the zoom value, either by
* choosing it from the list or by entering new value.
* @param mode The selected zoom mode
* @param zoom the zoom in percent, only defined if @p mode is KoZoomMode::ZOOM_CONSTANT
* @param zoom the zoom, only defined if @p mode is KoZoomMode::ZOOM_CONSTANT
*/
void zoomChanged( KoZoomMode::Mode mode, int zoom );
void zoomChanged( KoZoomMode::Mode mode, double zoom );
protected:
......@@ -142,10 +142,10 @@ protected:
KoZoomMode::Modes m_zoomModes;
ExtLineEdit *m_number;
QSlider *m_slider;
int m_sliderLookup[33];
double m_sliderLookup[33];
QButtonGroup* m_zoomButtonGroup;
int m_effectiveZoom;
double m_effectiveZoom;
};
class KoZoomAction::ExtLineEdit : public QLineEdit
......
......@@ -38,8 +38,8 @@ KoZoomController::KoZoomController(KoCanvasController *co, KoZoomHandler *zh, KA
KShortcut(),
actionCollection,
"zoom" );
connect(m_action, SIGNAL(zoomChanged(KoZoomMode::Mode, int)),
this, SLOT(setZoom(KoZoomMode::Mode, int)));
connect(m_action, SIGNAL(zoomChanged(KoZoomMode::Mode, double)),
this, SLOT(setZoom(KoZoomMode::Mode, double)));
connect(m_canvasController, SIGNAL( sizeChanged(const QSize & ) ), this, SLOT( setAvailableSize( const QSize & ) ) );
......@@ -69,34 +69,31 @@ void KoZoomController::setPageSize(const QSizeF &pageSize)
setZoom(KoZoomMode::ZOOM_PAGE, 0);
}
void KoZoomController::setZoom(KoZoomMode::Mode mode, int zoom)
void KoZoomController::setZoom(KoZoomMode::Mode mode, double zoom)
{
m_zoomHandler->setZoomMode(mode);
double zoomF;
if(mode == KoZoomMode::ZOOM_CONSTANT)
{
zoomF = zoom / 100.0;
if(zoomF == 0.0) return;
if(zoom == 0.0) return;
}
else if(mode == KoZoomMode::ZOOM_WIDTH)
{
zoomF = m_canvasController->viewport()->size().width()
zoom = m_canvasController->viewport()->size().width()
/ (m_zoomHandler->resolutionX() * m_pageSize.width());
m_action->setEffectiveZoom(int(100*zoomF+0.5));
m_action->setEffectiveZoom(zoom);
}
else if(mode == KoZoomMode::ZOOM_PAGE)
{
zoomF = m_canvasController->viewport()->size().width()
zoom = m_canvasController->viewport()->size().width()
/ (m_zoomHandler->resolutionX() * m_pageSize.width());
zoomF = qMin(zoomF, m_canvasController->viewport()->size().height()
zoom = qMin(zoom, m_canvasController->viewport()->size().height()
/ (m_zoomHandler->resolutionY() * m_pageSize.height()));
m_action->setEffectiveZoom(int(100*zoomF+0.5));
m_action->setEffectiveZoom(zoom);
}
m_zoomHandler->setZoom(zoomF);
m_zoomHandler->setZoom(zoom);
emit zoomChanged(mode, zoom);
// Tell the canvasController that the zoom has changed
......@@ -120,10 +117,10 @@ void KoZoomController::setAvailableSize(const QSize &/*size*/)
void KoZoomController::requestZoomBy(const double factor)
{
int zoom = m_zoomHandler->zoomInPercent();
m_action->setZoom(int(factor*zoom));
setZoom(KoZoomMode::ZOOM_CONSTANT, int(factor*zoom));
m_action->setEffectiveZoom(int(factor*zoom));
double zoom = m_zoomHandler->zoomInPercent() / 100.0;
m_action->setZoom(factor*zoom);
setZoom(KoZoomMode::ZOOM_CONSTANT, factor*zoom);
m_action->setEffectiveZoom(factor*zoom);
}
#include "KoZoomController.moc"
......@@ -74,12 +74,12 @@ public slots:
signals:
// the document can use the emitted data for persistency purposes.
void zoomChanged (KoZoomMode::Mode mode, int zoom);
void zoomChanged (KoZoomMode::Mode mode, double zoom);
private slots:
// should realy be on d pointer..
/// slot for the zoomAction to connect to.
void setZoom(KoZoomMode::Mode mode, int zoom);
void setZoom(KoZoomMode::Mode mode, double zoom);
/// so we know when the canvasController changes size
void setAvailableSize(const QSize &Size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment