Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
145a7238
Commit
145a7238
authored
Oct 09, 2016
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Background grid: initialize to *approximately* 1cm upon startup
parent
12a91e8c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
10 deletions
+44
-10
UBBoardController.cpp
src/board/UBBoardController.cpp
+31
-0
UBBoardController.h
src/board/UBBoardController.h
+1
-0
UBBoardView.cpp
src/board/UBBoardView.cpp
+8
-6
UBSettings.cpp
src/core/UBSettings.cpp
+1
-1
UBAbstractDrawRuler.h
src/tools/UBAbstractDrawRuler.h
+1
-1
UBGraphicsRuler.cpp
src/tools/UBGraphicsRuler.cpp
+1
-1
UBGraphicsTriangle.cpp
src/tools/UBGraphicsTriangle.cpp
+1
-1
No files found.
src/board/UBBoardController.cpp
View file @
145a7238
...
...
@@ -152,6 +152,8 @@ void UBBoardController::init()
setActiveDocumentScene
(
doc
);
initBackgroundGridSize
();
undoRedoStateChange
(
true
);
}
...
...
@@ -162,6 +164,35 @@ UBBoardController::~UBBoardController()
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
()
{
...
...
src/board/UBBoardController.h
View file @
145a7238
...
...
@@ -284,6 +284,7 @@ class UBBoardController : public UBDocumentContainer
void
appMainModeChanged
(
UBApplicationController
::
MainMode
);
private
:
void
initBackgroundGridSize
();
void
updatePageSizeState
();
void
saveViewState
();
void
adjustDisplayViews
();
...
...
src/board/UBBoardView.cpp
View file @
145a7238
...
...
@@ -1607,20 +1607,22 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
bgCrossColor
.
setAlpha
(
alpha
);
// fade the crossing on small zooms
}
qreal
gridSize
=
scene
()
->
backgroundGridSize
();
painter
->
setPen
(
bgCrossColor
);
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
);
}
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
());
}
...
...
@@ -1628,9 +1630,9 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect)
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
);
}
...
...
src/core/UBSettings.cpp
View file @
145a7238
...
...
@@ -48,7 +48,7 @@ QPointer<UBSettings> UBSettings::sSingleton = 0;
int
UBSettings
::
pointerDiameter
=
40
;
int
UBSettings
::
crossSize
=
24
;
int
UBSettings
::
minCrossSize
=
12
;
int
UBSettings
::
maxCrossSize
=
64
;
int
UBSettings
::
maxCrossSize
=
96
;
//TODO: user-settable?
int
UBSettings
::
colorPaletteSize
=
5
;
int
UBSettings
::
objectFrameWidth
=
20
;
int
UBSettings
::
boardMargin
=
10
;
...
...
src/tools/UBAbstractDrawRuler.h
View file @
145a7238
...
...
@@ -92,7 +92,7 @@ protected:
static
const
int
sFillTransparency
;
static
const
int
sDrawTransparency
;
static
const
int
sRoundingRadius
;
int
sPixelsPerCentimeter
;
qreal
sPixelsPerCentimeter
;
};
#endif
src/tools/UBGraphicsRuler.cpp
View file @
145a7238
...
...
@@ -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)
sPixelsPerCentimeter
=
UBApplication
::
boardController
->
activeScene
()
->
backgroundGridSize
();
double
pixelsPerMillimeter
=
double
(
sPixelsPerCentimeter
)
/
10.0
;
qreal
pixelsPerMillimeter
=
sPixelsPerCentimeter
/
10.0
;
int
rulerLengthInMillimeters
=
(
rect
().
width
()
-
sLeftEdgeMargin
-
sRoundingRadius
)
/
pixelsPerMillimeter
;
// When a "centimeter" is too narrow, we only display every 5th number, and every 5th millimeter mark
...
...
src/tools/UBGraphicsTriangle.cpp
View file @
145a7238
...
...
@@ -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)
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
double
numbersWidth
=
fontMetrics
.
width
(
"00"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment