Drawing window pan & zoom
This commit is contained in:
parent
958686d7b9
commit
664168992f
|
@ -145,7 +145,6 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
|
||||||
this , SLOT (selectionChanged())
|
this , SLOT (selectionChanged())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP
|
// A fresh page is added and we iterate through its collected children and add these to Canvas View -MLP
|
||||||
// if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children,
|
// if docobj is a featureviewcollection (ex orthogroup), add its child views. if there are ever children that have children,
|
||||||
// we'll have to make this recursive. -WF
|
// we'll have to make this recursive. -WF
|
||||||
|
@ -168,9 +167,13 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
|
||||||
App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue();
|
App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue();
|
||||||
auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
|
auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
|
||||||
if( pageTemplate ) {
|
if( pageTemplate ) {
|
||||||
|
//make sceneRect 1 pagesize bigger in every direction
|
||||||
|
double width = pageTemplate->Width.getValue();
|
||||||
|
double height = pageTemplate->Height.getValue();
|
||||||
|
m_view->scene()->setSceneRect(QRectF(-width,-2.0 * height,3.0*width,3.0*height));
|
||||||
attachTemplate(pageTemplate);
|
attachTemplate(pageTemplate);
|
||||||
|
viewAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,11 +253,9 @@ void MDIViewPage::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
|
||||||
void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
|
void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
|
||||||
{
|
{
|
||||||
//why doesn't setting the template set the papersize???
|
|
||||||
m_view->setPageTemplate(obj);
|
m_view->setPageTemplate(obj);
|
||||||
double width = obj->Width.getValue();
|
double width = obj->Width.getValue();
|
||||||
double height = obj->Height.getValue();
|
double height = obj->Height.getValue();
|
||||||
m_view->scene()->setSceneRect(QRectF(-1.,-height,width+1.,height)); //the +/- 1 is because of the way the template is define???
|
|
||||||
m_paperSize = getPaperSize(int(round(width)),int(round(height)));
|
m_paperSize = getPaperSize(int(round(width)),int(round(height)));
|
||||||
if (width > height) {
|
if (width > height) {
|
||||||
m_orientation = QPrinter::Landscape;
|
m_orientation = QPrinter::Landscape;
|
||||||
|
@ -263,6 +264,23 @@ void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF MDIViewPage::getTemplateCenter(TechDraw::DrawTemplate *obj)
|
||||||
|
{
|
||||||
|
double cx = obj->Width.getValue()/2.0;
|
||||||
|
double cy = -obj->Height.getValue()/2.0;
|
||||||
|
QPointF result(cx,cy);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MDIViewPage::centerOnPage(void)
|
||||||
|
{
|
||||||
|
App::DocumentObject *obj = m_vpPage->getDrawPage()->Template.getValue();
|
||||||
|
auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
|
||||||
|
if( pageTemplate ) {
|
||||||
|
QPointF viewCenter = getTemplateCenter(pageTemplate);
|
||||||
|
m_view->centerOn(viewCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool MDIViewPage::attachView(App::DocumentObject *obj)
|
bool MDIViewPage::attachView(App::DocumentObject *obj)
|
||||||
{
|
{
|
||||||
|
@ -795,7 +813,8 @@ void MDIViewPage::setRenderer(QAction *action)
|
||||||
|
|
||||||
void MDIViewPage::viewAll()
|
void MDIViewPage::viewAll()
|
||||||
{
|
{
|
||||||
m_view->fitInView(m_view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
//m_view->fitInView(m_view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||||
|
m_view->fitInView(m_view->scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QAction;
|
class QAction;
|
||||||
|
@ -82,6 +83,10 @@ public:
|
||||||
|
|
||||||
QGraphicsScene* m_scene;
|
QGraphicsScene* m_scene;
|
||||||
|
|
||||||
|
QPointF getTemplateCenter(TechDraw::DrawTemplate *obj);
|
||||||
|
void centerOnPage(void);
|
||||||
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setRenderer(QAction *action);
|
void setRenderer(QAction *action);
|
||||||
void viewAll();
|
void viewAll();
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
# include <cmath>
|
# include <cmath>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <App/Application.h>
|
||||||
|
#include <App/Material.h>
|
||||||
#include <Base/Console.h>
|
#include <Base/Console.h>
|
||||||
#include <Base/Stream.h>
|
#include <Base/Stream.h>
|
||||||
#include <Gui/FileDialog.h>
|
#include <Gui/FileDialog.h>
|
||||||
|
@ -92,18 +94,26 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent)
|
||||||
setObjectName(QString::fromLocal8Bit(name));
|
setObjectName(QString::fromLocal8Bit(name));
|
||||||
|
|
||||||
setScene(s);
|
setScene(s);
|
||||||
|
|
||||||
|
setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
|
||||||
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
||||||
|
//setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
|
||||||
setCacheMode(QGraphicsView::CacheBackground);
|
setCacheMode(QGraphicsView::CacheBackground);
|
||||||
setTransformationAnchor(AnchorUnderMouse);
|
//setTransformationAnchor(AnchorUnderMouse);
|
||||||
|
//setTransformationAnchor(NoAnchor);
|
||||||
|
setTransformationAnchor(AnchorViewCenter);
|
||||||
|
setResizeAnchor(AnchorViewCenter);
|
||||||
|
setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
setDragMode(ScrollHandDrag);
|
setDragMode(ScrollHandDrag);
|
||||||
setCursor(QCursor(Qt::ArrowCursor));
|
setCursor(QCursor(Qt::ArrowCursor));
|
||||||
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
bkgBrush = new QBrush(QColor::fromRgb(70,70,70));
|
bkgBrush = new QBrush(getBackgroundColor());
|
||||||
|
|
||||||
resetCachedContent();
|
resetCachedContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
QGVPage::~QGVPage()
|
QGVPage::~QGVPage()
|
||||||
{
|
{
|
||||||
delete bkgBrush;
|
delete bkgBrush;
|
||||||
|
@ -126,7 +136,7 @@ void QGVPage::drawBackground(QPainter *p, const QRectF &)
|
||||||
|
|
||||||
|
|
||||||
p->setBrush(*bkgBrush);
|
p->setBrush(*bkgBrush);
|
||||||
p->drawRect(viewport()->rect());
|
p->drawRect(viewport()->rect().adjusted(-2,-2,2,2)); //just bigger than viewport to prevent artifacts
|
||||||
|
|
||||||
if(!m_vpPage) {
|
if(!m_vpPage) {
|
||||||
return;
|
return;
|
||||||
|
@ -544,10 +554,26 @@ void QGVPage::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
void QGVPage::wheelEvent(QWheelEvent *event)
|
void QGVPage::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
qreal factor = std::pow(1.2, -event->delta() / 240.0);
|
//Delta is the distance that the wheel is rotated, in eighths of a degree.
|
||||||
|
//positive indicates rotation forwards away from the user; negative backwards toward the user.
|
||||||
|
//Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
|
||||||
|
//1 click = 15 degrees. 15 degrees = 120 deltas. delta/240 -> 1 click = 0.5 ==> factor = 1.2^0.5 = 1.095
|
||||||
|
// 1 click = -0.5 ==> factor = 1.2^-0.5 = 0.91
|
||||||
|
//so to change wheel direction, multiply (event->delta() / 240.0) by +/-1
|
||||||
|
double mouseBase = 1.2; //magic numbers. change for different mice?
|
||||||
|
double mouseAdjust = 240.0;
|
||||||
|
|
||||||
|
QPointF center = mapToScene(viewport()->rect().center());
|
||||||
|
qreal factor = std::pow(mouseBase, event->delta() / mouseAdjust);
|
||||||
scale(factor, factor);
|
scale(factor, factor);
|
||||||
|
|
||||||
|
QPointF newCenter = mapToScene(viewport()->rect().center());
|
||||||
|
QPointF change = newCenter - center;
|
||||||
|
translate(change.x(), change.y());
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGVPage::enterEvent(QEvent *event)
|
void QGVPage::enterEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
QGraphicsView::enterEvent(event);
|
QGraphicsView::enterEvent(event);
|
||||||
|
@ -571,5 +597,13 @@ TechDraw::DrawPage* QGVPage::getDrawPage()
|
||||||
return m_vpPage->getDrawPage();
|
return m_vpPage->getDrawPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QColor QGVPage::getBackgroundColor()
|
||||||
|
{
|
||||||
|
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||||
|
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
|
||||||
|
App::Color fcColor;
|
||||||
|
fcColor.setPackedValue(hGrp->GetUnsigned("Background", 0x70707000));
|
||||||
|
return fcColor.asValue<QColor>();
|
||||||
|
}
|
||||||
|
|
||||||
#include <Mod/TechDraw/Gui/moc_QGVPage.cpp>
|
#include <Mod/TechDraw/Gui/moc_QGVPage.cpp>
|
||||||
|
|
|
@ -102,6 +102,7 @@ protected:
|
||||||
|
|
||||||
static QColor SelectColor;
|
static QColor SelectColor;
|
||||||
static QColor PreselectColor;
|
static QColor PreselectColor;
|
||||||
|
QColor getBackgroundColor();
|
||||||
|
|
||||||
QGITemplate *pageTemplate;
|
QGITemplate *pageTemplate;
|
||||||
std::vector<QGIView *> views;
|
std::vector<QGIView *> views;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user