In the scripter, I'm creating a scribus.getColumnGuides(), that returns the column guides settings and list of the "AutoVertical" guides.
It normally works correctly but in one case it fails:
If I create a selection based Column (AutoGuide) with one guide, and then directly trigger scribus.getColumnGuides(), then page->guides.getAutoVerticals(page) gives me indeed a guide, but the position is not correct.
I've investigated the code of getAutoVerticals() and there is one thing that I noticed:
else if (m_verticalAutoRefer == 2)
{
if (qRound(page->guides.gx) != 0)
{
offset = page->guides.gx;
newPageWidth = page->guides.gw;
}
}
https://gitlab.com/scribus/scribus/blob/master/scribus/guidemanagercore.cpp#L275
If I look at
doc->currentPage()->guides.setVerticalAutoRefer(2);
https://gitlab.com/scribus/scribus/blob/master/scribus/guidemanagercore.h#L104
which I'm using to set the refer value, there is nothing that is page->guides.gx that is updating gx!
No way it can work...
The interesting part is that, if I create my selection and then wait a few seconds, then I get the guide at the right position!
Something is updating gx, but I can't figure out where this is done...
So if I run
scribus.newDocument(scribus.PAPER_A4_MM, (10, 10, 10, 10), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_1, 0, 1)
scribus.createRect(20, 20, 50, 50, 'rect')
scribus.selectObject('rect')
scribus.setColumnGuides(1, refer_to=2)
and then
print(scribus.getColumnGuides())
I get a guide at 45.0, but if I run it all in one go, I get the guide at 105.0 .
Does anybody have a clue?
how far off is the guide? a lot? a little? one or two units?
ok, i guess i have found out.
i need to call
GuideManager::resetSelectionForPage()
which would be called when the selection for the "refer to" switches to "selection" (if there was a way to activate that option... (https://bugs.scribus.net/view.php?id=17028)
the problem is that i can't access it from outside...
i have to check if can modify it in some way and make it callable from foreign code (moving most of the function to GuideManagerCore, which is the type for page->guide)?
let's try it...
yes, that was it.
adding (moving)
void GuideManagerCore::resetSelectionForPage(ScPage* page)
{
auto doc = page->doc();
int docSelectionCount = doc->m_Selection->count();
page->guides.gx = page->guides.gy = page->guides.gw = page->guides.gh = 0.0;
// multiselection
if (docSelectionCount > 1)
{
double x, y;
doc->m_Selection->getGroupRect(&x, &y, &page->guides.gw, &page->guides.gh);
page->guides.gx = x - page->xOffset();
page->guides.gy = y - page->yOffset();
}
// only one item selected
else if (docSelectionCount == 1)
{
PageItem *currItem = doc->m_Selection->itemAt(0);
page->guides.gx = currItem->xPos() - page->xOffset();
page->guides.gy = currItem->yPos() - page->yOffset();
page->guides.gw = currItem->width();
page->guides.gh = currItem->height();
}
}
and then using it as
void GuideManager::verticalSelectionAutoButton_toggled(bool state)
{
if (!state)
return;
currentPage->guides.setVerticalAutoRefer(2);
if (verticalSelectionAutoButton->isEnabled())
currentPage->guides.resetSelectionForPage(currentPage);
drawGuides();
m_Doc->changed();
}
make it available also outside of ui/guidemanager.cpp .
oufh!
it looked easy to implement...