Background grid: initialize to *approximately* 1cm upon startup

preferencesAboutTextFull
Craig Watson 8 years ago
parent 12a91e8cf6
commit 145a7238c0
  1. 31
      src/board/UBBoardController.cpp
  2. 1
      src/board/UBBoardController.h
  3. 14
      src/board/UBBoardView.cpp
  4. 2
      src/core/UBSettings.cpp
  5. 2
      src/tools/UBAbstractDrawRuler.h
  6. 2
      src/tools/UBGraphicsRuler.cpp
  7. 2
      src/tools/UBGraphicsTriangle.cpp

@ -152,6 +152,8 @@ void UBBoardController::init()
setActiveDocumentScene(doc); setActiveDocumentScene(doc);
initBackgroundGridSize();
undoRedoStateChange(true); undoRedoStateChange(true);
} }
@ -162,6 +164,35 @@ UBBoardController::~UBBoardController()
delete mDisplayView; delete mDisplayView;
} }
/**
* @brief Set the default background grid size to appear as roughly 1cm on screen
*/
void UBBoardController::initBackgroundGridSize()
{
// Besides adjusting for DPI, we also need to scale the grid size by the ratio of the control view size
// to document size. However the control view isn't available as soon as the boardController is created,
// so we approximate this ratio as (document resolution) / (screen resolution).
// Later on, this is calculated by `updateSystemScaleFactor` and stored in `mSystemScaleFactor`.
QDesktopWidget* desktop = UBApplication::desktop();
qreal dpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2.;
//qDebug() << "dpi: " << dpi;
// The display manager isn't initialized yet so we have to just assume the control view is on the main display
qreal screenY = desktop->screenGeometry(mControlView).height();
qreal documentY = mActiveScene->nominalSize().height();
qreal resolutionRatio = documentY / screenY;
//qDebug() << "resolution ratio: " << resolutionRatio;
int gridSize = (resolutionRatio * 10. * dpi) / UBGeometryUtils::inchSize;
UBSettings::settings()->crossSize = gridSize;
mActiveScene->setBackgroundGridSize(gridSize);
//qDebug() << "grid size: " << gridSize;
}
int UBBoardController::currentPage() int UBBoardController::currentPage()
{ {

@ -284,6 +284,7 @@ class UBBoardController : public UBDocumentContainer
void appMainModeChanged(UBApplicationController::MainMode); void appMainModeChanged(UBApplicationController::MainMode);
private: private:
void initBackgroundGridSize();
void updatePageSizeState(); void updatePageSizeState();
void saveViewState(); void saveViewState();
void adjustDisplayViews(); void adjustDisplayViews();

@ -1607,20 +1607,22 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms bgCrossColor.setAlpha (alpha); // fade the crossing on small zooms
} }
qreal gridSize = scene()->backgroundGridSize();
painter->setPen (bgCrossColor); painter->setPen (bgCrossColor);
if (scene () && scene ()->pageBackground() == UBPageBackground::crossed) if (scene () && scene ()->pageBackground() == UBPageBackground::crossed)
{ {
qreal firstY = ((int) (rect.y () / scene()->backgroundGridSize())) * scene()->backgroundGridSize(); qreal firstY = ((int) (rect.y () / gridSize)) * gridSize;
for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += scene()->backgroundGridSize()) for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += gridSize)
{ {
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
} }
qreal firstX = ((int) (rect.x () / scene()->backgroundGridSize())) * scene()->backgroundGridSize(); qreal firstX = ((int) (rect.x () / gridSize)) * gridSize;
for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += scene()->backgroundGridSize()) for (qreal xPos = firstX; xPos < rect.x () + rect.width (); xPos += gridSize)
{ {
painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ());
} }
@ -1628,9 +1630,9 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
if (scene() && scene()->pageBackground() == UBPageBackground::ruled) if (scene() && scene()->pageBackground() == UBPageBackground::ruled)
{ {
qreal firstY = ((int) (rect.y () / scene()->backgroundGridSize())) * scene()->backgroundGridSize(); qreal firstY = ((int) (rect.y () / gridSize)) * gridSize;
for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += scene()->backgroundGridSize()) for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += gridSize)
{ {
painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos);
} }

@ -48,7 +48,7 @@ QPointer<UBSettings> UBSettings::sSingleton = 0;
int UBSettings::pointerDiameter = 40; int UBSettings::pointerDiameter = 40;
int UBSettings::crossSize = 24; int UBSettings::crossSize = 24;
int UBSettings::minCrossSize = 12; int UBSettings::minCrossSize = 12;
int UBSettings::maxCrossSize = 64; int UBSettings::maxCrossSize = 96; //TODO: user-settable?
int UBSettings::colorPaletteSize = 5; int UBSettings::colorPaletteSize = 5;
int UBSettings::objectFrameWidth = 20; int UBSettings::objectFrameWidth = 20;
int UBSettings::boardMargin = 10; int UBSettings::boardMargin = 10;

@ -92,7 +92,7 @@ protected:
static const int sFillTransparency; static const int sFillTransparency;
static const int sDrawTransparency; static const int sDrawTransparency;
static const int sRoundingRadius; static const int sRoundingRadius;
int sPixelsPerCentimeter; qreal sPixelsPerCentimeter;
}; };
#endif #endif

@ -180,7 +180,7 @@ void UBGraphicsRuler::paintGraduations(QPainter *painter)
// Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not) // Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not)
sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize(); sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
double pixelsPerMillimeter = double(sPixelsPerCentimeter)/10.0; qreal pixelsPerMillimeter = sPixelsPerCentimeter/10.0;
int rulerLengthInMillimeters = (rect().width() - sLeftEdgeMargin - sRoundingRadius)/pixelsPerMillimeter; int rulerLengthInMillimeters = (rect().width() - sLeftEdgeMargin - sRoundingRadius)/pixelsPerMillimeter;
// When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark // When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark

@ -351,7 +351,7 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
// Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not) // Update the width of one "centimeter" to correspond to the width of the background grid (whether it is displayed or not)
sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize(); sPixelsPerCentimeter = UBApplication::boardController->activeScene()->backgroundGridSize();
double pixelsPerMillimeter = double(sPixelsPerCentimeter)/10.0; double pixelsPerMillimeter = sPixelsPerCentimeter/10.0;
// When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark // When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark
double numbersWidth = fontMetrics.width("00"); double numbersWidth = fontMetrics.width("00");

Loading…
Cancel
Save