Make LayoutMapper, row and column sizes persist within Layout

( preparing for quick pageposition lookup ).
presentation
JJones780 7 years ago
parent da80c34954
commit 2e44c36997
  1. 55
      src/gui/Layout.cpp
  2. 19
      src/gui/Layout.h
  3. 48
      src/gui/LayoutMapper.cpp
  4. 49
      src/gui/LayoutMapper.h

@ -6,7 +6,7 @@
#include "pageposition/PagePositionHandler.h"
#include "widgets/XournalWidget.h"
#include "gui/scroll/ScrollHandling.h"
#include "gui/LayoutMapper.h"
/**
@ -199,23 +199,22 @@ void Layout::layoutPages()
Settings* settings = this->view->getControl()->getSettings();
// obtain rows, cols, paired and layout from view settings
LayoutMapper mapper(len, settings);
mapper.configureFromSettings(len, settings);
// get from mapper (some may have changed to accomodate paired setting etc.)
bool isPairedPages = mapper.getPairedPages();
int rows = mapper.getRows();
int columns = mapper.getColumns();
int pagesOffset = mapper.getFirstPageOffset();
this->rows = mapper.getRows();
this->columns = mapper.getColumns();
int sizeCol[columns];
// Needs dynamic initialisation, else clang will not compile...
memset(sizeCol, 0, columns * sizeof(int));
this->sizeCol.assign(this->columns,0); //new size, clear to 0's
int sizeRow[rows];
memset(sizeRow, 0, rows * sizeof(int));
this->sizeRow.assign(this->rows,0);
for (int r = 0; r < rows; r++)
for (int r = 0; r < this->rows; r++)
{
for (int c = 0; c < columns; c++)
for (int c = 0; c < this->columns; c++)
{
int k = mapper.map(c, r);
if (k >= 0)
@ -223,13 +222,13 @@ void Layout::layoutPages()
XojPageView* v = this->view->viewPages[k];
if (sizeCol[c] < v->getDisplayWidth())
if (this->sizeCol[c] < v->getDisplayWidth())
{
sizeCol[c] = v->getDisplayWidth();
this->sizeCol[c] = v->getDisplayWidth();
}
if (sizeRow[r] < v->getDisplayHeight())
if (this->sizeRow[r] < v->getDisplayHeight())
{
sizeRow[r] = v->getDisplayHeight();
this->sizeRow[r] = v->getDisplayHeight();
}
}
@ -259,7 +258,7 @@ void Layout::layoutPages()
int minRequiredWidth = XOURNAL_PADDING_BETWEEN * (columns-1);
for( int c = 0 ; c< columns; c++ )
{
minRequiredWidth += sizeCol[c];
minRequiredWidth += this->sizeCol[c];
}
int centeringXBorder = ( visibleWidth - minRequiredWidth )/2; // this will center if all pages fit on screen.
@ -268,7 +267,7 @@ void Layout::layoutPages()
int minRequiredHeight = XOURNAL_PADDING_BETWEEN * (rows-1);
for( int r = 0 ; r< rows; r++ )
{
minRequiredHeight += sizeRow[r];
minRequiredHeight += this->sizeRow[r];
}
int centeringYBorder = ( visibleHeight - minRequiredHeight )/2; // this will center if all pages fit on screen vertically.
@ -286,9 +285,9 @@ void Layout::layoutPages()
// Iterate over ALL possible rows and columns.
//We don't know which page, if any, is to be displayed in each row, column - ask the mapper object!
//Then assign that page coordinates with center, left or right justify within row,column grid cell as required.
for (int r = 0; r < rows; r++)
for (int r = 0; r < this->rows; r++)
{
for (int c = 0; c < columns; c++)
for (int c = 0; c < this->columns; c++)
{
int pageAtRowCol = mapper.map(c, r);
@ -301,7 +300,7 @@ void Layout::layoutPages()
int paddingLeft;
int paddingRight;
int columnPadding = 0;
columnPadding = (sizeCol[c] - vDisplayWidth);
columnPadding = (this->sizeCol[c] - vDisplayWidth);
if (isPairedPages && len > 1)
{
@ -335,24 +334,24 @@ void Layout::layoutPages()
}
else
{
x += sizeCol[c] + XOURNAL_PADDING_BETWEEN;
x += this->sizeCol[c] + XOURNAL_PADDING_BETWEEN;
}
}
x = borderX;
y += sizeRow[r] + XOURNAL_PADDING_BETWEEN;
y += this->sizeRow[r] + XOURNAL_PADDING_BETWEEN;
}
int totalWidth = borderX * 2 + XOURNAL_PADDING_BETWEEN * (columns-1);
for (int c = 0; c < columns; c++)
int totalWidth = borderX * 2 + XOURNAL_PADDING_BETWEEN * (this->columns-1);
for (int c = 0; c < this->columns; c++)
{
totalWidth += sizeCol[c]; // this includes paddingLeft and paddingRight
totalWidth += this->sizeCol[c]; // this includes paddingLeft and paddingRight
}
int totalHeight = borderY * 2 + XOURNAL_PADDING_BETWEEN * (rows-1);
for (int r = 0; r < rows; r++)
int totalHeight = borderY * 2 + XOURNAL_PADDING_BETWEEN * (this->rows-1);
for (int r = 0; r < this->rows; r++)
{
totalHeight += sizeRow[r];
totalHeight += this->sizeRow[r];
}

@ -16,10 +16,13 @@
#include <gtk/gtk.h>
#include "gui/LayoutMapper.h"
class XojPageView;
class XournalView;
class ScrollHandling;
/**
* @brief The Layout manager for the XournalWidget
*
@ -91,7 +94,9 @@ private:
private:
XOJ_TYPE_ATTRIB;
XournalView* view = NULL;
XournalView* view = NULL;
LayoutMapper mapper;
ScrollHandling* scrollHandling = NULL;
@ -108,4 +113,16 @@ private:
*/
int layoutWidth = 0;
int layoutHeight = 0;
/**
*The following are useful for locating page at a pixel location
*/
int rows;
int columns;
std::vector<int> sizeCol;
std::vector<int> sizeRow;
};

@ -1,40 +1,17 @@
#include "gui/LayoutMapper.h"
/**
* compileLayout - assemble bitflags to create basic layouts
*/
LayoutType compileLayout(bool isVertical, bool isRightToLeft, bool isBottomToTop)
{
int type = isVertical ? LayoutBitFlags::Vertically : 0;
type |= isRightToLeft ? LayoutBitFlags::RightToLeft : 0;
type |= isBottomToTop ? LayoutBitFlags::BottomToTop : 0;
return (LayoutType) type;
LayoutMapper::LayoutMapper(){
this->actualPages = 0;
this->possiblePages = 0;
this->rows = 0;
this->cols = 0;
this->layoutType = Horizontal;
}
LayoutMapper::LayoutMapper(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool isPaired,
int firstPageOffset)
{
XOJ_INIT_TYPE(LayoutMapper);
layoutMapperInit(pages, numRows, numCols, useRows, type, isPaired, firstPageOffset);
}
LayoutMapper::LayoutMapper(int pages, int numRows, int numCols, bool useRows, bool isVertical, bool isRightToLeft,
bool isBottomToTop, bool isPaired, int firstPageOffset)
{
XOJ_INIT_TYPE(LayoutMapper);
LayoutType type = compileLayout(isVertical, isRightToLeft, isBottomToTop);
layoutMapperInit(pages, numRows, numCols, useRows, type, isPaired, firstPageOffset);
}
LayoutMapper::LayoutMapper(int numPages, Settings* settings)
void LayoutMapper::configureFromSettings(int numPages, Settings* settings)
{
XOJ_INIT_TYPE(LayoutMapper);
@ -55,8 +32,13 @@ LayoutMapper::LayoutMapper(int numPages, Settings* settings)
pairsOffset = 0;
}
LayoutType type = compileLayout(isVertical, isRightToLeft, isBottomToTop);
layoutMapperInit(pages, numRows, numCols, fixRows, type, isPairedPages, pairsOffset);
//assemble bitflags for LayoutType
int type = isVertical ? LayoutBitFlags::Vertically : 0;
type |= isRightToLeft ? LayoutBitFlags::RightToLeft : 0;
type |= isBottomToTop ? LayoutBitFlags::BottomToTop : 0;
layoutMapperInit(pages, numRows, numCols, fixRows, (LayoutType)type, isPairedPages, pairsOffset);
}
LayoutMapper::~LayoutMapper()

@ -41,47 +41,40 @@ class LayoutMapper
{
public:
/**
* Initialize mapper of LayoutType with number of pages and of fixed rows or columns
* LayoutMapper
*
* Create a bare mapper to be configured before use.
*/
LayoutMapper();
/**
* configureFromSettings
* configure layoutMapper from user settings settings
*
* @param pages The number of pages in the document
* @param numRows Number of rows ( used if useRows )
* @param numCols Number of columns ( used if !useRows )
* @param useRows use pages/rows to recalculate cols else recalculate rows
* @param type Specify LayoutType desired. Options include: Horizontal, Vertical,
* @param isPaired Display pages in pairs including offset
* @param firstPageOffset Pages to offset - usually one or zero in order to pair up properly
* @param settings The Settings from which users settings are obtained
*/
LayoutMapper(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool isPaired,
int firstPageOffset);
void configureFromSettings(int numPages, Settings* settings);
virtual ~LayoutMapper();
private:
/**
* LayoutMapper with broken out layout arguments
* layoutMapperInit
*
* Initialize mapper of LayoutType with number of pages and of fixed rows or columns
* @param pages The number of pages in the document
* @param numRows Number of rows ( used if useRows )
* @param numCols Number of columns ( used if !useRows )
* @param useRows use pages/rows to recalculate cols else recalculate rows
* @param isVertical lay out pages by filling columns first
* @param isRightToLeft go from right to left
* @param isBottomToTop go from bottom to top
* @param type Specify LayoutType desired. Options include: Horizontal, Vertical,
* @param isPaired Display pages in pairs including offset
* @param firstPageOffset Pages to offset - usually one or zero in order to pair up properly
*/
LayoutMapper(int pages, int numRows, int numCols, bool useRows, bool isVertical, bool isRightToLeft,
bool isBottomToTop, bool isPaired, int firstPageOffset);
/**
* LayoutMapper using view to get settings
*
* @param pages The number of pages in the document
* @param settings The Settings from which users settings are obtained
*/
LayoutMapper(int pages, Settings* settings);
virtual ~LayoutMapper();
private:
// called by constructors
void layoutMapperInit(int pages, int numRows, int numCols, bool useRows, LayoutType type, bool paired,
int firstPageOffset);
int firstPageOffset);
public:
/**

Loading…
Cancel
Save