Better scroll to fit implementation.
This commit is contained in:
@@ -572,17 +572,18 @@ namespace glabels
|
|||||||
{
|
{
|
||||||
QWidget* page = new QWidget;
|
QWidget* page = new QWidget;
|
||||||
|
|
||||||
mView = new View();
|
mViewScrollArea = new QScrollArea();
|
||||||
|
mViewScrollArea->setMinimumSize( 640, 450 );
|
||||||
|
mViewScrollArea->setWidgetResizable( true );
|
||||||
|
|
||||||
|
mView = new View( mViewScrollArea );
|
||||||
mObjectEditor = new ObjectEditor();
|
mObjectEditor = new ObjectEditor();
|
||||||
|
|
||||||
QScrollArea* scrollArea = new QScrollArea();
|
mViewScrollArea->setWidget( mView );
|
||||||
scrollArea->setMinimumSize( 640, 450 );
|
|
||||||
scrollArea->setWidgetResizable( true );
|
|
||||||
scrollArea->setWidget( mView );
|
|
||||||
|
|
||||||
QVBoxLayout* editorVLayout = new QVBoxLayout;
|
QVBoxLayout* editorVLayout = new QVBoxLayout;
|
||||||
editorVLayout->addWidget( editorToolBar );
|
editorVLayout->addWidget( editorToolBar );
|
||||||
editorVLayout->addWidget( scrollArea );
|
editorVLayout->addWidget( mViewScrollArea );
|
||||||
|
|
||||||
QHBoxLayout* editorHLayout = new QHBoxLayout;
|
QHBoxLayout* editorHLayout = new QHBoxLayout;
|
||||||
editorHLayout->addLayout( editorVLayout );
|
editorHLayout->addLayout( editorVLayout );
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class QMenuBar;
|
|||||||
class QMenu;
|
class QMenu;
|
||||||
class QToolBar;
|
class QToolBar;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
class QScrollArea;
|
||||||
|
|
||||||
|
|
||||||
namespace glabels
|
namespace glabels
|
||||||
@@ -189,6 +190,7 @@ namespace glabels
|
|||||||
|
|
||||||
QTabWidget* mNotebook;
|
QTabWidget* mNotebook;
|
||||||
LabelModel* mModel;
|
LabelModel* mModel;
|
||||||
|
QScrollArea* mViewScrollArea;
|
||||||
View* mView;
|
View* mView;
|
||||||
ObjectEditor* mObjectEditor;
|
ObjectEditor* mObjectEditor;
|
||||||
PrintView* mPrintView;
|
PrintView* mPrintView;
|
||||||
|
|||||||
@@ -175,7 +175,6 @@ namespace glabels
|
|||||||
|
|
||||||
printCropMarks( painter );
|
printCropMarks( painter );
|
||||||
|
|
||||||
qDebug() << "ipage = " << iPage << ", iStart = " << iStart << ", iEnd = " << iEnd;
|
|
||||||
for ( int i = iStart; i < iEnd; i++ )
|
for ( int i = iStart; i < iEnd; i++ )
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|||||||
+5
-5
@@ -74,7 +74,8 @@ namespace
|
|||||||
///
|
///
|
||||||
/// Constructor
|
/// Constructor
|
||||||
///
|
///
|
||||||
glabels::View::View( QWidget *parent ) : QWidget(parent)
|
glabels::View::View( QScrollArea* scrollArea, QWidget* parent )
|
||||||
|
: QWidget(parent), mScrollArea(scrollArea)
|
||||||
{
|
{
|
||||||
mState = IdleState;
|
mState = IdleState;
|
||||||
|
|
||||||
@@ -232,9 +233,8 @@ glabels::View::zoomToFit()
|
|||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
// Assumes parent widget (QScrollArea) exists
|
double wPixels = mScrollArea->maximumViewportSize().width();
|
||||||
double wPixels = parentWidget()->width();
|
double hPixels = mScrollArea->maximumViewportSize().height();
|
||||||
double hPixels = parentWidget()->height();
|
|
||||||
|
|
||||||
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w();
|
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w();
|
||||||
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h();
|
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h();
|
||||||
@@ -280,7 +280,7 @@ glabels::View::setZoomReal( double zoom, bool zoomToFitFlag )
|
|||||||
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
|
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
|
||||||
mScale = zoom * physicalDpiX() / PTS_PER_INCH;
|
mScale = zoom * physicalDpiX() / PTS_PER_INCH;
|
||||||
|
|
||||||
setMinimumSize( mScale*mModel->w(), mScale*mModel->h() );
|
setMinimumSize( mScale*mModel->w() + ZOOM_TO_FIT_PAD, mScale*mModel->h() + ZOOM_TO_FIT_PAD );
|
||||||
|
|
||||||
/* Adjust origin to center label in widget. */
|
/* Adjust origin to center label in widget. */
|
||||||
mX0 = (width()/mScale - mModel->w()) / 2;
|
mX0 = (width()/mScale - mModel->w()) / 2;
|
||||||
|
|||||||
+6
-3
@@ -22,6 +22,7 @@
|
|||||||
#define glabels_View_h
|
#define glabels_View_h
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QScrollArea>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "LabelRegion.h"
|
#include "LabelRegion.h"
|
||||||
@@ -46,7 +47,7 @@ namespace glabels
|
|||||||
// Lifecycle
|
// Lifecycle
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
public:
|
public:
|
||||||
View( QWidget *parent = 0 );
|
View( QScrollArea* scrollArea, QWidget* parent = 0 );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
@@ -142,8 +143,8 @@ namespace glabels
|
|||||||
// Private slots
|
// Private slots
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
private:
|
private:
|
||||||
void onLabelChanged();
|
void onModelChanged();
|
||||||
void onLabelSizeChanged();
|
void onModelSizeChanged();
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
@@ -167,6 +168,8 @@ namespace glabels
|
|||||||
Barcode
|
Barcode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QScrollArea* mScrollArea;
|
||||||
|
|
||||||
double mZoom;
|
double mZoom;
|
||||||
bool mZoomToFitFlag;
|
bool mZoomToFitFlag;
|
||||||
double mScale;
|
double mScale;
|
||||||
|
|||||||
Reference in New Issue
Block a user