Basic zoom implementation.
This commit is contained in:
+25
-22
@@ -31,7 +31,6 @@
|
|||||||
#include "Icons.h"
|
#include "Icons.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Help.h"
|
#include "Help.h"
|
||||||
#include "View.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
@@ -42,6 +41,7 @@ namespace glabels
|
|||||||
/////////////// TEMPORARY TESTING ///////////////
|
/////////////// TEMPORARY TESTING ///////////////
|
||||||
#if 0
|
#if 0
|
||||||
QLabel* tmp = new QLabel( "Coming Soon..." );
|
QLabel* tmp = new QLabel( "Coming Soon..." );
|
||||||
|
setCentralWidget( tmp );
|
||||||
#else
|
#else
|
||||||
LabelModel* model = new LabelModel();
|
LabelModel* model = new LabelModel();
|
||||||
const libglabels::Template* tmplate = libglabels::Db::lookupTemplateFromName( "Avery 3612" );
|
const libglabels::Template* tmplate = libglabels::Db::lookupTemplateFromName( "Avery 3612" );
|
||||||
@@ -61,10 +61,11 @@ namespace glabels
|
|||||||
object->setShadow( true );
|
object->setShadow( true );
|
||||||
model->addObject( object );
|
model->addObject( object );
|
||||||
|
|
||||||
View* tmp = new View();
|
view = new View();
|
||||||
tmp->setModel( model );
|
view->setModel( model );
|
||||||
|
|
||||||
|
setCentralWidget( view );
|
||||||
#endif
|
#endif
|
||||||
setCentralWidget( tmp );
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
@@ -72,7 +73,7 @@ namespace glabels
|
|||||||
createToolBars();
|
createToolBars();
|
||||||
createStatusBar();
|
createStatusBar();
|
||||||
|
|
||||||
setDocVerbsEnabled( false );
|
setDocVerbsEnabled( true );
|
||||||
setPasteVerbsEnabled( false );
|
setPasteVerbsEnabled( false );
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
@@ -240,10 +241,10 @@ namespace glabels
|
|||||||
viewZoomOutAction->setStatusTip( tr("Decrease magnification") );
|
viewZoomOutAction->setStatusTip( tr("Decrease magnification") );
|
||||||
connect( viewZoomOutAction, SIGNAL(triggered()), this, SLOT(viewZoomOut()) );
|
connect( viewZoomOutAction, SIGNAL(triggered()), this, SLOT(viewZoomOut()) );
|
||||||
|
|
||||||
viewZoom1to1Action = new QAction( tr("Zoom &1 to 1"), this );
|
viewZoom1To1Action = new QAction( tr("Zoom &1 to 1"), this );
|
||||||
viewZoom1to1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) );
|
viewZoom1To1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) );
|
||||||
viewZoom1to1Action->setStatusTip( tr("Restore scale to 100%") );
|
viewZoom1To1Action->setStatusTip( tr("Restore scale to 100%") );
|
||||||
connect( viewZoom1to1Action, SIGNAL(triggered()), this, SLOT(viewZoom1to1()) );
|
connect( viewZoom1To1Action, SIGNAL(triggered()), this, SLOT(viewZoom1To1()) );
|
||||||
|
|
||||||
viewZoomToFitAction = new QAction( tr("Zoom to &Fit"), this );
|
viewZoomToFitAction = new QAction( tr("Zoom to &Fit"), this );
|
||||||
viewZoomToFitAction->setIcon( QIcon::fromTheme( "zoom-fit-best", Icons::Fallback::ZoomBestFit() ) );
|
viewZoomToFitAction->setIcon( QIcon::fromTheme( "zoom-fit-best", Icons::Fallback::ZoomBestFit() ) );
|
||||||
@@ -419,7 +420,7 @@ namespace glabels
|
|||||||
viewMenu->addSeparator();
|
viewMenu->addSeparator();
|
||||||
viewMenu->addAction( viewZoomInAction );
|
viewMenu->addAction( viewZoomInAction );
|
||||||
viewMenu->addAction( viewZoomOutAction );
|
viewMenu->addAction( viewZoomOutAction );
|
||||||
viewMenu->addAction( viewZoom1to1Action );
|
viewMenu->addAction( viewZoom1To1Action );
|
||||||
viewMenu->addAction( viewZoomToFitAction );
|
viewMenu->addAction( viewZoomToFitAction );
|
||||||
|
|
||||||
objectsMenu = menuBar()->addMenu( tr("&Objects") );
|
objectsMenu = menuBar()->addMenu( tr("&Objects") );
|
||||||
@@ -489,7 +490,7 @@ namespace glabels
|
|||||||
viewToolBar = addToolBar( tr("&View") );
|
viewToolBar = addToolBar( tr("&View") );
|
||||||
viewToolBar->addAction( viewZoomInAction );
|
viewToolBar->addAction( viewZoomInAction );
|
||||||
viewToolBar->addAction( viewZoomOutAction );
|
viewToolBar->addAction( viewZoomOutAction );
|
||||||
viewToolBar->addAction( viewZoom1to1Action );
|
viewToolBar->addAction( viewZoom1To1Action );
|
||||||
viewToolBar->addAction( viewZoomToFitAction );
|
viewToolBar->addAction( viewZoomToFitAction );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,10 +509,12 @@ namespace glabels
|
|||||||
statusBar()->addWidget( zoomInfoLabel );
|
statusBar()->addWidget( zoomInfoLabel );
|
||||||
statusBar()->addWidget( cursorInfoLabel, 1 );
|
statusBar()->addWidget( cursorInfoLabel, 1 );
|
||||||
|
|
||||||
updateZoomInfo( 1, false, false );
|
updateZoomInfo();
|
||||||
updateCursorInfo();
|
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 );
|
editUnSelectAllAction->setEnabled( enabled );
|
||||||
viewZoomInAction->setEnabled( enabled );
|
viewZoomInAction->setEnabled( enabled );
|
||||||
viewZoomOutAction->setEnabled( enabled );
|
viewZoomOutAction->setEnabled( enabled );
|
||||||
viewZoom1to1Action->setEnabled( enabled );
|
viewZoom1To1Action->setEnabled( enabled );
|
||||||
viewZoomToFitAction->setEnabled( enabled );
|
viewZoomToFitAction->setEnabled( enabled );
|
||||||
viewGridAction->setEnabled( enabled );
|
viewGridAction->setEnabled( enabled );
|
||||||
viewMarkupAction->setEnabled( enabled );
|
viewMarkupAction->setEnabled( enabled );
|
||||||
@@ -807,19 +810,19 @@ namespace glabels
|
|||||||
|
|
||||||
void MainWindow::viewZoomIn()
|
void MainWindow::viewZoomIn()
|
||||||
{
|
{
|
||||||
std::cout << "ACTION: edit->Zoom in" << std::endl;
|
view->zoomIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::viewZoomOut()
|
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 );
|
viewZoomInAction->setEnabled( !view->isZoomMax() );
|
||||||
viewZoomOutAction->setEnabled( !min_flag );
|
viewZoomOutAction->setEnabled( !view->isZoomMin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+75
-71
@@ -29,6 +29,8 @@
|
|||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include "View.h"
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
{
|
{
|
||||||
@@ -74,7 +76,7 @@ namespace glabels
|
|||||||
void viewMarkup();
|
void viewMarkup();
|
||||||
void viewZoomIn();
|
void viewZoomIn();
|
||||||
void viewZoomOut();
|
void viewZoomOut();
|
||||||
void viewZoom1to1();
|
void viewZoom1To1();
|
||||||
void viewZoomToFit();
|
void viewZoomToFit();
|
||||||
|
|
||||||
void objectsArrowMode();
|
void objectsArrowMode();
|
||||||
@@ -103,7 +105,7 @@ namespace glabels
|
|||||||
void helpContents();
|
void helpContents();
|
||||||
void helpAbout();
|
void helpAbout();
|
||||||
|
|
||||||
void updateZoomInfo( double, bool, bool );
|
void updateZoomInfo();
|
||||||
void updateCursorInfo();
|
void updateCursorInfo();
|
||||||
void updateCursorInfo( double, double );
|
void updateCursorInfo( double, double );
|
||||||
|
|
||||||
@@ -123,82 +125,84 @@ namespace glabels
|
|||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
QMenu *fileMenu;
|
QMenu* fileMenu;
|
||||||
QMenu *editMenu;
|
QMenu* editMenu;
|
||||||
QMenu *viewMenu;
|
QMenu* viewMenu;
|
||||||
QMenu *viewToolBarsMenu;
|
QMenu* viewToolBarsMenu;
|
||||||
QMenu *objectsMenu;
|
QMenu* objectsMenu;
|
||||||
QMenu *objectsCreateMenu;
|
QMenu* objectsCreateMenu;
|
||||||
QMenu *objectsOrderMenu;
|
QMenu* objectsOrderMenu;
|
||||||
QMenu *objectsXformMenu;
|
QMenu* objectsXformMenu;
|
||||||
QMenu *objectsAlignMenu;
|
QMenu* objectsAlignMenu;
|
||||||
QMenu *objectsCenterMenu;
|
QMenu* objectsCenterMenu;
|
||||||
QMenu *helpMenu;
|
QMenu* helpMenu;
|
||||||
|
|
||||||
QToolBar *fileToolBar;
|
QToolBar* fileToolBar;
|
||||||
QToolBar *objectsToolBar;
|
QToolBar* objectsToolBar;
|
||||||
QToolBar *editToolBar;
|
QToolBar* editToolBar;
|
||||||
QToolBar *viewToolBar;
|
QToolBar* viewToolBar;
|
||||||
|
|
||||||
QLabel *zoomInfoLabel;
|
View* view;
|
||||||
QLabel *cursorInfoLabel;
|
|
||||||
|
|
||||||
QAction *fileNewAction;
|
QLabel* zoomInfoLabel;
|
||||||
QAction *fileOpenAction;
|
QLabel* cursorInfoLabel;
|
||||||
QAction *fileSaveAction;
|
|
||||||
QAction *fileSaveAsAction;
|
|
||||||
QAction *filePrintAction;
|
|
||||||
QAction *filePropertiesAction;
|
|
||||||
QAction *fileTemplateDesignerAction;
|
|
||||||
QAction *fileCloseAction;
|
|
||||||
QAction *fileExitAction;
|
|
||||||
|
|
||||||
QAction *editUndoAction;
|
QAction* fileNewAction;
|
||||||
QAction *editRedoAction;
|
QAction* fileOpenAction;
|
||||||
QAction *editCutAction;
|
QAction* fileSaveAction;
|
||||||
QAction *editCopyAction;
|
QAction* fileSaveAsAction;
|
||||||
QAction *editPasteAction;
|
QAction* filePrintAction;
|
||||||
QAction *editDeleteAction;
|
QAction* filePropertiesAction;
|
||||||
QAction *editSelectAllAction;
|
QAction* fileTemplateDesignerAction;
|
||||||
QAction *editUnSelectAllAction;
|
QAction* fileCloseAction;
|
||||||
QAction *editPreferencesAction;
|
QAction* fileExitAction;
|
||||||
|
|
||||||
QAction *viewFileToolBarAction;
|
QAction* editUndoAction;
|
||||||
QAction *viewObjectsToolBarAction;
|
QAction* editRedoAction;
|
||||||
QAction *viewEditToolBarAction;
|
QAction* editCutAction;
|
||||||
QAction *viewViewToolBarAction;
|
QAction* editCopyAction;
|
||||||
QAction *viewGridAction;
|
QAction* editPasteAction;
|
||||||
QAction *viewMarkupAction;
|
QAction* editDeleteAction;
|
||||||
QAction *viewZoomInAction;
|
QAction* editSelectAllAction;
|
||||||
QAction *viewZoomOutAction;
|
QAction* editUnSelectAllAction;
|
||||||
QAction *viewZoom1to1Action;
|
QAction* editPreferencesAction;
|
||||||
QAction *viewZoomToFitAction;
|
|
||||||
|
|
||||||
QAction *objectsArrowModeAction;
|
QAction* viewFileToolBarAction;
|
||||||
QAction *objectsCreateTextAction;
|
QAction* viewObjectsToolBarAction;
|
||||||
QAction *objectsCreateBoxAction;
|
QAction* viewEditToolBarAction;
|
||||||
QAction *objectsCreateLineAction;
|
QAction* viewViewToolBarAction;
|
||||||
QAction *objectsCreateEllipseAction;
|
QAction* viewGridAction;
|
||||||
QAction *objectsCreateImageAction;
|
QAction* viewMarkupAction;
|
||||||
QAction *objectsCreateBarcodeAction;
|
QAction* viewZoomInAction;
|
||||||
QAction *objectsOrderRaiseAction;
|
QAction* viewZoomOutAction;
|
||||||
QAction *objectsOrderLowerAction;
|
QAction* viewZoom1To1Action;
|
||||||
QAction *objectsXformRotateLeftAction;
|
QAction* viewZoomToFitAction;
|
||||||
QAction *objectsXformRotateRightAction;
|
|
||||||
QAction *objectsXformFlipHorizAction;
|
|
||||||
QAction *objectsXformFlipVertAction;
|
|
||||||
QAction *objectsAlignLeftAction;
|
|
||||||
QAction *objectsAlignHCenterAction;
|
|
||||||
QAction *objectsAlignRightAction;
|
|
||||||
QAction *objectsAlignTopAction;
|
|
||||||
QAction *objectsAlignVCenterAction;
|
|
||||||
QAction *objectsAlignBottomAction;
|
|
||||||
QAction *objectsCenterHorizAction;
|
|
||||||
QAction *objectsCenterVertAction;
|
|
||||||
QAction *objectsMergePropertiesAction;
|
|
||||||
|
|
||||||
QAction *helpContentsAction;
|
QAction* objectsArrowModeAction;
|
||||||
QAction *helpAboutAction;
|
QAction* objectsCreateTextAction;
|
||||||
|
QAction* objectsCreateBoxAction;
|
||||||
|
QAction* objectsCreateLineAction;
|
||||||
|
QAction* objectsCreateEllipseAction;
|
||||||
|
QAction* objectsCreateImageAction;
|
||||||
|
QAction* objectsCreateBarcodeAction;
|
||||||
|
QAction* objectsOrderRaiseAction;
|
||||||
|
QAction* objectsOrderLowerAction;
|
||||||
|
QAction* objectsXformRotateLeftAction;
|
||||||
|
QAction* objectsXformRotateRightAction;
|
||||||
|
QAction* objectsXformFlipHorizAction;
|
||||||
|
QAction* objectsXformFlipVertAction;
|
||||||
|
QAction* objectsAlignLeftAction;
|
||||||
|
QAction* objectsAlignHCenterAction;
|
||||||
|
QAction* objectsAlignRightAction;
|
||||||
|
QAction* objectsAlignTopAction;
|
||||||
|
QAction* objectsAlignVCenterAction;
|
||||||
|
QAction* objectsAlignBottomAction;
|
||||||
|
QAction* objectsCenterHorizAction;
|
||||||
|
QAction* objectsCenterVertAction;
|
||||||
|
QAction* objectsMergePropertiesAction;
|
||||||
|
|
||||||
|
QAction* helpContentsAction;
|
||||||
|
QAction* helpAboutAction;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+92
-1
@@ -20,12 +20,24 @@
|
|||||||
|
|
||||||
#include "View.h"
|
#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
|
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();
|
mScene = new QGraphicsScene();
|
||||||
setScene( mScene );
|
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:
|
public:
|
||||||
View( QWidget *parent = 0 );
|
View( QWidget *parent = 0 );
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void zoomChanged();
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline double zoom() const;
|
||||||
|
|
||||||
void setModel( LabelModel* model );
|
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:
|
private:
|
||||||
QGraphicsScene* mScene;
|
QGraphicsScene* mScene;
|
||||||
double mScale;
|
|
||||||
|
double mZoom;
|
||||||
|
bool mZoomToFitFlag;
|
||||||
|
|
||||||
LabelModel* mModel;
|
LabelModel* mModel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline double View::zoom() const
|
||||||
|
{
|
||||||
|
return mZoom;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // glabels_View_h
|
#endif // glabels_View_h
|
||||||
|
|||||||
Reference in New Issue
Block a user