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