Basic zoom implementation.
This commit is contained in:
+25
-22
@@ -31,7 +31,6 @@
|
||||
#include "Icons.h"
|
||||
#include "File.h"
|
||||
#include "Help.h"
|
||||
#include "View.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -42,6 +41,7 @@ namespace glabels
|
||||
/////////////// TEMPORARY TESTING ///////////////
|
||||
#if 0
|
||||
QLabel* tmp = new QLabel( "Coming Soon..." );
|
||||
setCentralWidget( tmp );
|
||||
#else
|
||||
LabelModel* model = new LabelModel();
|
||||
const libglabels::Template* tmplate = libglabels::Db::lookupTemplateFromName( "Avery 3612" );
|
||||
@@ -61,10 +61,11 @@ namespace glabels
|
||||
object->setShadow( true );
|
||||
model->addObject( object );
|
||||
|
||||
View* tmp = new View();
|
||||
tmp->setModel( model );
|
||||
view = new View();
|
||||
view->setModel( model );
|
||||
|
||||
setCentralWidget( view );
|
||||
#endif
|
||||
setCentralWidget( tmp );
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
createActions();
|
||||
@@ -72,7 +73,7 @@ namespace glabels
|
||||
createToolBars();
|
||||
createStatusBar();
|
||||
|
||||
setDocVerbsEnabled( false );
|
||||
setDocVerbsEnabled( true );
|
||||
setPasteVerbsEnabled( false );
|
||||
|
||||
readSettings();
|
||||
@@ -240,10 +241,10 @@ namespace glabels
|
||||
viewZoomOutAction->setStatusTip( tr("Decrease magnification") );
|
||||
connect( viewZoomOutAction, SIGNAL(triggered()), this, SLOT(viewZoomOut()) );
|
||||
|
||||
viewZoom1to1Action = new QAction( tr("Zoom &1 to 1"), this );
|
||||
viewZoom1to1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) );
|
||||
viewZoom1to1Action->setStatusTip( tr("Restore scale to 100%") );
|
||||
connect( viewZoom1to1Action, SIGNAL(triggered()), this, SLOT(viewZoom1to1()) );
|
||||
viewZoom1To1Action = new QAction( tr("Zoom &1 to 1"), this );
|
||||
viewZoom1To1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) );
|
||||
viewZoom1To1Action->setStatusTip( tr("Restore scale to 100%") );
|
||||
connect( viewZoom1To1Action, SIGNAL(triggered()), this, SLOT(viewZoom1To1()) );
|
||||
|
||||
viewZoomToFitAction = new QAction( tr("Zoom to &Fit"), this );
|
||||
viewZoomToFitAction->setIcon( QIcon::fromTheme( "zoom-fit-best", Icons::Fallback::ZoomBestFit() ) );
|
||||
@@ -419,7 +420,7 @@ namespace glabels
|
||||
viewMenu->addSeparator();
|
||||
viewMenu->addAction( viewZoomInAction );
|
||||
viewMenu->addAction( viewZoomOutAction );
|
||||
viewMenu->addAction( viewZoom1to1Action );
|
||||
viewMenu->addAction( viewZoom1To1Action );
|
||||
viewMenu->addAction( viewZoomToFitAction );
|
||||
|
||||
objectsMenu = menuBar()->addMenu( tr("&Objects") );
|
||||
@@ -489,7 +490,7 @@ namespace glabels
|
||||
viewToolBar = addToolBar( tr("&View") );
|
||||
viewToolBar->addAction( viewZoomInAction );
|
||||
viewToolBar->addAction( viewZoomOutAction );
|
||||
viewToolBar->addAction( viewZoom1to1Action );
|
||||
viewToolBar->addAction( viewZoom1To1Action );
|
||||
viewToolBar->addAction( viewZoomToFitAction );
|
||||
}
|
||||
|
||||
@@ -508,10 +509,12 @@ namespace glabels
|
||||
statusBar()->addWidget( zoomInfoLabel );
|
||||
statusBar()->addWidget( cursorInfoLabel, 1 );
|
||||
|
||||
updateZoomInfo( 1, false, false );
|
||||
updateZoomInfo();
|
||||
updateCursorInfo();
|
||||
|
||||
/* TODO: connect cursor and zoom signals to appropriate slots. */
|
||||
connect( view, SIGNAL(zoomChanged()), this, SLOT(updateZoomInfo()) );
|
||||
|
||||
/* TODO: connect cursor signals to appropriate slots. */
|
||||
}
|
||||
|
||||
|
||||
@@ -535,7 +538,7 @@ namespace glabels
|
||||
editUnSelectAllAction->setEnabled( enabled );
|
||||
viewZoomInAction->setEnabled( enabled );
|
||||
viewZoomOutAction->setEnabled( enabled );
|
||||
viewZoom1to1Action->setEnabled( enabled );
|
||||
viewZoom1To1Action->setEnabled( enabled );
|
||||
viewZoomToFitAction->setEnabled( enabled );
|
||||
viewGridAction->setEnabled( enabled );
|
||||
viewMarkupAction->setEnabled( enabled );
|
||||
@@ -807,19 +810,19 @@ namespace glabels
|
||||
|
||||
void MainWindow::viewZoomIn()
|
||||
{
|
||||
std::cout << "ACTION: edit->Zoom in" << std::endl;
|
||||
view->zoomIn();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::viewZoomOut()
|
||||
{
|
||||
std::cout << "ACTION: edit->Zoom out" << std::endl;
|
||||
view->zoomOut();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::viewZoom1to1()
|
||||
void MainWindow::viewZoom1To1()
|
||||
{
|
||||
std::cout << "ACTION: edit->Zoom 1 to 1" << std::endl;
|
||||
view->zoom1To1();
|
||||
}
|
||||
|
||||
|
||||
@@ -973,12 +976,12 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateZoomInfo( double zoom, bool min_flag, bool max_flag )
|
||||
void MainWindow::updateZoomInfo()
|
||||
{
|
||||
zoomInfoLabel->setText( QString( " %1% " ).arg(100*zoom, 0, 'f', 0) );
|
||||
zoomInfoLabel->setText( QString( " %1% " ).arg(100*view->zoom(), 0, 'f', 0) );
|
||||
|
||||
viewZoomInAction->setEnabled( !max_flag );
|
||||
viewZoomOutAction->setEnabled( !min_flag );
|
||||
viewZoomInAction->setEnabled( !view->isZoomMax() );
|
||||
viewZoomOutAction->setEnabled( !view->isZoomMin() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-3
@@ -29,6 +29,8 @@
|
||||
#include <QToolBar>
|
||||
#include <QLabel>
|
||||
|
||||
#include "View.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
@@ -74,7 +76,7 @@ namespace glabels
|
||||
void viewMarkup();
|
||||
void viewZoomIn();
|
||||
void viewZoomOut();
|
||||
void viewZoom1to1();
|
||||
void viewZoom1To1();
|
||||
void viewZoomToFit();
|
||||
|
||||
void objectsArrowMode();
|
||||
@@ -103,7 +105,7 @@ namespace glabels
|
||||
void helpContents();
|
||||
void helpAbout();
|
||||
|
||||
void updateZoomInfo( double, bool, bool );
|
||||
void updateZoomInfo();
|
||||
void updateCursorInfo();
|
||||
void updateCursorInfo( double, double );
|
||||
|
||||
@@ -140,6 +142,8 @@ namespace glabels
|
||||
QToolBar* editToolBar;
|
||||
QToolBar* viewToolBar;
|
||||
|
||||
View* view;
|
||||
|
||||
QLabel* zoomInfoLabel;
|
||||
QLabel* cursorInfoLabel;
|
||||
|
||||
@@ -171,7 +175,7 @@ namespace glabels
|
||||
QAction* viewMarkupAction;
|
||||
QAction* viewZoomInAction;
|
||||
QAction* viewZoomOutAction;
|
||||
QAction *viewZoom1to1Action;
|
||||
QAction* viewZoom1To1Action;
|
||||
QAction* viewZoomToFitAction;
|
||||
|
||||
QAction* objectsArrowModeAction;
|
||||
|
||||
+92
-1
@@ -20,12 +20,24 @@
|
||||
|
||||
#include "View.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
const int nZoomLevels = 14;
|
||||
const double zoomLevels[nZoomLevels] = { 8, 6, 4, 3, 2, 1.5, 1, 0.75, 0.67, 0.50, 0.33, 0.25, 0.15, 0.10 };
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
View::View( QWidget *parent ) : QGraphicsView(parent), mScale(1), mModel(0)
|
||||
View::View( QWidget *parent ) : QGraphicsView(parent)
|
||||
{
|
||||
setZoomReal( 1, false );
|
||||
mModel = 0;
|
||||
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
}
|
||||
@@ -42,4 +54,83 @@ namespace glabels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void View::zoomIn()
|
||||
{
|
||||
// Find closest standard zoom level to our current zoom
|
||||
// Start with 2nd largest scale
|
||||
int i_min = 1;
|
||||
double dist_min = fabs( zoomLevels[1] - mZoom );
|
||||
|
||||
for ( int i = 2; i < nZoomLevels; i++ )
|
||||
{
|
||||
double dist = fabs( zoomLevels[i] - mZoom );
|
||||
if ( dist < dist_min )
|
||||
{
|
||||
i_min = i;
|
||||
dist_min = dist;
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom in one notch
|
||||
setZoomReal( zoomLevels[i_min-1], false );
|
||||
}
|
||||
|
||||
|
||||
void View::zoomOut()
|
||||
{
|
||||
// Find closest standard zoom level to our current zoom
|
||||
// Start with largest scale, end on 2nd smallest
|
||||
int i_min = 0;
|
||||
double dist_min = fabs( zoomLevels[0] - mZoom );
|
||||
|
||||
for ( int i = 1; i < (nZoomLevels-1); i++ )
|
||||
{
|
||||
double dist = fabs( zoomLevels[i] - mZoom );
|
||||
if ( dist < dist_min )
|
||||
{
|
||||
i_min = i;
|
||||
dist_min = dist;
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom out one notch
|
||||
setZoomReal( zoomLevels[i_min+1], false );
|
||||
}
|
||||
|
||||
|
||||
void View::zoom1To1()
|
||||
{
|
||||
setZoomReal( 1.0, false );
|
||||
}
|
||||
|
||||
|
||||
void View::zoomToFit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool View::isZoomMax() const
|
||||
{
|
||||
return ( mZoom >= zoomLevels[0] );
|
||||
}
|
||||
|
||||
|
||||
bool View::isZoomMin() const
|
||||
{
|
||||
return ( mZoom <= zoomLevels[nZoomLevels-1] );
|
||||
}
|
||||
|
||||
|
||||
void View::setZoomReal( double zoom, bool zoomToFitFlag )
|
||||
{
|
||||
mZoom = zoom;
|
||||
mZoomToFitFlag = zoomToFitFlag;
|
||||
|
||||
resetTransform();
|
||||
scale( mZoom*physicalDpiX()/72.0, mZoom*physicalDpiY()/72.0 );
|
||||
|
||||
emit zoomChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-1
@@ -37,16 +37,44 @@ namespace glabels
|
||||
public:
|
||||
View( QWidget *parent = 0 );
|
||||
|
||||
|
||||
signals:
|
||||
void zoomChanged();
|
||||
|
||||
|
||||
public:
|
||||
inline double zoom() const;
|
||||
|
||||
void setModel( LabelModel* model );
|
||||
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void zoom1To1();
|
||||
void zoomToFit();
|
||||
bool isZoomMax() const;
|
||||
bool isZoomMin() const;
|
||||
private:
|
||||
void setZoomReal( double zoom, bool zoomToFitFlag );
|
||||
|
||||
|
||||
private:
|
||||
QGraphicsScene* mScene;
|
||||
double mScale;
|
||||
|
||||
double mZoom;
|
||||
bool mZoomToFitFlag;
|
||||
|
||||
LabelModel* mModel;
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline double View::zoom() const
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // glabels_View_h
|
||||
|
||||
Reference in New Issue
Block a user