int AMSimpleBeamConfigurationWizard::nextId() const { int pageId = currentId(); switch(pageId) { case Page_Intro: if(showOptionPage()) return Page_Option; else return pageWait(0); case Page_Final: return -1; default: int id = relativeId(); if(isWaitPage(pageId)) return pageSet(id); else if(isSetPage(pageId)) { if(id == numberOfPages() - 1) return Page_Final; else return pageWait(id + 1); } return -1; } }
AMBeamConfigurationWizard::AMBeamConfigurationWizard(QWidget* parent) : AMGraphicsViewWizard(parent) { /// two points for each square, three squares. setNumberOfPoints(6); setNumberOfPages(numberOfPoints()); setFreePage(Page_Free); setRotationEnabled(false); setPage(Page_Intro, new AMWizardPage); setPage(Page_Final, new AMWizardPage); setPage(Page_Option, new AMWizardOptionPage); for(int i = 0; i < numberOfPages(); i++) { setPage(pageWait(i), new AMBeamWaitPage); /* kind of a dirty hack here, but this makes the wait logic cleaner */ if(i < 3) setPage(pageSet(i), new AMBeamCheckPage); else setPage(pageSet(i), new AMBeamSelectPage); } setStartId(Page_Intro); setOption(HaveHelpButton, true); connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp())); setWindowTitle(message(Wizard_Title)); /* have to disconnect/connect the buttons to get them to work with the new slots */ disconnect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back())); connect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back())); disconnect(button(QWizard::NextButton), SIGNAL(clicked()), this, SLOT(next())); connect(button(QWizard::NextButton), SIGNAL(clicked()), this, SLOT(next())); setMinimumSize(600,600); setting_ = false; reviewBeamShape_ = true; for(int i = 0; i < numberOfPoints(); i++) { pointListAppend(new QPointF(0,0)); } topLeft_ = true; coordinateListAppend(new QVector3D(0,0,0)); coordinateListAppend(new QVector3D(0,-1,0)); coordinateListAppend(new QVector3D(0,1,0)); coordinateListAppend(new QVector3D(0,0,0)); coordinateListAppend(new QVector3D(0,-1,0)); coordinateListAppend(new QVector3D(0,1,0)); addOptionPage(Page_Intro); }
qreal KDReports::TextDocReportLayout::layoutAsOnePage(qreal docWidth) { m_textDocument.layoutWithTextWidth(docWidth); qreal docHeight = m_textDocument.contentDocument().size().height(); #if QT_VERSION <= 0x040300 // Qt-4.2 bug, fixed in Qt-4.3: QTextDocumentLayout::dynamicPageCount() // returns docheight/pageheight + 1. So if the doc is just as high as the page, I get 2 pages. docHeight += 1; #endif // We need to get rid of all page breaks... // Unittest: PageLayout::testEndlessPrinterWithPageBreaks() QTextCursor c(&m_textDocument.contentDocument()); c.beginEditBlock(); QTextBlock block = m_textDocument.contentDocument().firstBlock(); do { //qDebug() << "addBlock: Looking at block" << block.blockNumber(); QTextBlockFormat format = block.blockFormat(); if ( format.pageBreakPolicy() != QTextBlockFormat::PageBreak_Auto ) format.setPageBreakPolicy( QTextBlockFormat::PageBreak_Auto ); c.setPosition( block.position() ); c.setBlockFormat( format ); block = block.next(); } while ( block.isValid() ); c.endEditBlock(); setPageContentSize(QSizeF(docWidth, docHeight)); qDebug() << "m_textDocument.layoutDocument().setPageSize" << docWidth << "x" << docHeight << numberOfPages() << "pages"; qreal newDocHeight = m_textDocument.contentDocument().size().height(); if (newDocHeight > docHeight) { // QTextDocument is playing tricks on us; it was able to layout as docWidth x docHeight // but once we set that as the page size, we end up with more height... // Unittest: PageLayout::testEndlessPrinterBug() qDebug() << "newDocHeight=" << newDocHeight << "expected" << docHeight; setPageContentSize(QSizeF(docWidth, newDocHeight)); newDocHeight = m_textDocument.contentDocument().size().height(); qDebug() << "final newDocHeight=" << newDocHeight << numberOfPages() << "pages"; } Q_ASSERT(numberOfPages() == 1); return newDocHeight; }
bool AMBeamConfigurationWizard::allChecked() const { bool checkedSet = true; for(int i = 0; i < numberOfPages()/2; i++) { checkedSet *= checked(pageSet(i)); } return checkedSet; }
void DSPDFViewer::gotoPage(unsigned int pageNumber) { if ( m_pagenumber != pageNumber && numberOfPages() > pageNumber ) { m_pagenumber = pageNumber; renderPage(); } else { qWarning() << "Requested page number" << pageNumber << "which is out of range! Ignoring request."; } }
bool KDReports::Report::printWithDialog( QWidget* parent ) { QPrinter printer; setupPrinter( &printer ); QPointer<QPrintDialog> dialog = new QPrintDialog( &printer, parent ); dialog->setMinMax( 1, numberOfPages() ); bool ok = false; if ( dialog->exec() == QDialog::Accepted ) { // Well, the user can modify the page size in the printer dialog too - ensure layout matches d->ensureLayouted(); ok = d->doPrint( &printer, parent ); } delete dialog; return ok; }
int AMBeamConfigurationWizard::nextId() const { int pageId = currentId(); switch(pageId) { case Page_Intro: if(showOptionPage()) return Page_Option; else return pageWait(0); default: if(isWaitPage(pageId)) { return pageSet(relativeId()); } else if(isSetPage(pageId)) { if((lastCheckPage() && allChecked()) || (relativeId() >= (numberOfPages() - 1))) { return Page_Final; } else if(isCheckPage() && !allChecked())/* change this to check all lower number pages */ { return pageWait(numberOfPages()/2); } else { return pageWait(relativeId() + 1); } } else { return -1; } } }
AMSimpleBeamConfigurationWizard::AMSimpleBeamConfigurationWizard(QWidget *parent) : AMGraphicsViewWizard(parent) { setNumberOfPoints(3); setNumberOfPages(numberOfPoints()); setFreePage(Page_Free); coordinateListAppend(new QVector3D(0,0,0)); coordinateListAppend(new QVector3D(0,2,0)); coordinateListAppend(new QVector3D(0,-2,0)); setPage(Page_Intro, new AMWizardPage); setPage(Page_Option, new AMWizardOptionPage); setPage(Page_Final, new AMWizardPage); for(int i = 0; i < numberOfPages(); i++) { setPage(pageWait(i), new AMSimpleBeamConfigurationWaitPage); setPage(pageSet(i), new AMSimpleBeamConfigurationSetPage); connect(page(pageSet(i)), SIGNAL(initBeamShape()), this, SLOT(initBeamShape())); connect(page(pageSet(i)), SIGNAL(signalMousePressed(QPointF)), this, SLOT(mousePressedHandler(QPointF))); connect(page(pageSet(i)), SIGNAL(moveBeamShape(QPointF)), this, SLOT(moveBeamShapeHandler(QPointF))); } setStartId(Page_Intro); setOption(HaveHelpButton, true); connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp())); setWindowTitle(message(Wizard_Title)); disconnect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back())); connect(button(QWizard::BackButton), SIGNAL(clicked()), this, SLOT(back())); setMinimumSize(600,600); /// Add options button to intro page addOptionPage(Page_Intro); }
bool AMBeamConfigurationWizard::isCheckPage() const { return currentId() < numberOfPages()/2; }
bool AMBeamConfigurationWizard::lastSetPage() const { return relativeId() >= (numberOfPages() - 1); }
bool AMBeamConfigurationWizard::lastCheckPage() const { return relativeId() == (numberOfPages()/2 - 1); }
void AMBeamConfigurationWizard::back() { int pageId = currentId(); int targetPage; switch(pageId) { case Page_Final: targetPage = pageWait(numberOfPages() - 1); while(currentId() != targetPage) QWizard::back(); if(currentId() == targetPage) initializePage(targetPage); break; default: if(isWaitPage(pageId)) { bool reinitialize = true; ((AMWaitPage*)page(pageId))->stopTimer(); if(relativeId(pageId) == 0) { targetPage = Page_Intro; reinitialize = false; } else { targetPage = pageWait(relativeId(pageId) - 1); } while(currentId() != targetPage) { QWizard::back(); } if(currentId() == targetPage && reinitialize) { initializePage(targetPage); } } else if(isSetPage(pageId)) { bool reinitialize = true; if(relativeId(pageId) == 0) { targetPage = Page_Intro; reinitialize = false; } else { targetPage = pageWait(relativeId(pageId) - 1); } while(currentId() != targetPage) { QWizard::back(); } if(currentId() == targetPage && reinitialize) { initializePage(targetPage); } } else { AMGraphicsViewWizard::back(); } break; } }
QString AMBeamConfigurationWizard::message(int type) { if(type == Wizard_Title) return QString(tr("Beam Configuration Wizard")); else if(type == Help_Title) return QString(tr("Help")); int pageId = currentId(); switch(pageId) { case Page_Intro: switch(type) { case Title: return QString(tr("Beam Configuration Wizard")); case Text: return QString(tr("This wizard will help you to configure the beam settings. \n") + tr("The sample plate will be moved to three different locations. ") + tr("If, at any of the three locations, ") + tr("the rectangle on screen does not match up well to the location of the beamspot uncheck the checkbox on that ") + tr("page. You will then be asked to draw a rectangle around the beamspot in each of the three positions. For further ") + tr("explanation, click the \"Help\" button for detailed information for that page.")); case Help: return QString(tr("To start the configuration of the beam, click next on this page.") + tr(" If all the beamspots correspond to the visible beam, check the boxes") + tr(" to indicate that the beam is correct. If the beamspots do not line up, they") + tr(" can be configured by marking the beam as being incorrect. If there is no") + tr(" visible beam, it may be that the visible beam has not been enabled. If it has") + tr(" and the beam is still not visible, ensure that the beam is on. If the beam is on") + tr(" and is visible, but is not appearing on the sample plate, it may need to be manipulated") + tr(" until it is under the beam. This may require a change in sample points. These can") + tr(" can be configured in 'options' (on this page). Changing these values will change where") + tr(" the sample plate moves to for the beam configuration.")); case Other: case Default: default: break; } break; case Page_Final: switch(type) { case Title: return QString(tr("Configuration complete")); case Text: return QString(tr("Configuration has been completed. The beam path has been recalculated.")); case Help: return QString(tr("If the beam appears to be in the wrong place, this configuration may be rerun. If the beam is known to be divergent") + tr(" it may need to be selected from the main sample camera configuration settings.")); case Other: case Default: default: break; } case Page_Option: switch(type) { case Title: return QString(tr("Movement Configuration")); case Text: return QString(tr("Set the points to move the motor to here. These may need to be changed if something") + tr(" has been moved inside the end station.")); case Help: return QString(tr("Set the coordinates that will be moved to in the wizard here. For the Beam Configuration, all points must have different y values")); case Other: case Default: default: break; } default: if(isWaitPage(pageId)) { switch(type) { case Title: return QString(tr("Please Wait")); case Text: return QString(tr("Moving to position %1")).arg(relativeId() + 1); case Help: return QString(tr("If the configuration is stuck here please check to make sure that motor movement is enabled.") + tr(" If movement is enabled there may be a problem communicating with the sample manipulator motors.")); case Other: case Default: default: break; } break; } else if(isSetPage(pageId)) { if(relativeId(pageId) < numberOfPages()/2) { switch(type) { case Title: return QString(tr("Confirm Beam")); case Text: return QString(tr("Check to see if beam %1 is in the correct configuration.")).arg(relativeId()%3 + 1); case Help: return QString(tr("Check to see if the rectangle appears around the beamspot. \n") + tr("If the beamspot is not visible, ensure that visible light has been turned on. \n") + tr("If the beamspot is still not visible, the beam may be moved drastically away from its usual spot. ") + tr("This may require changing of the coordinates on the options page, accessible from the introduction page.")); case Other: return QString(tr("Is the beam correct?")); case Default: default: break; } break; } else { switch(type) { case Title: return QString(tr("Set Beam")); case Text: return QString(tr("Draw a box over beam position %1")).arg(relativeId()%3 + 1); case Help: return QString(tr("Draw a box over the visible beamspot. To draw a box click and drag to create the corners. ")) + tr("Try to fit the box to best encompass the entire beamspot."); case Other: case Default: default: break; } break; } } return QString(tr("Error - unknown page.")); } return QString(tr("Error - unknown message type.")); }
DSPDFViewer::DSPDFViewer(const RuntimeConfiguration& r): runtimeConfiguration(r), pdfDocument(Poppler::Document::load(r.filePathQString())) , renderFactory(r.filePathQString()), m_pagenumber(0), audienceWindow(0, r.useFullPage()? PagePart::FullPage : PagePart::LeftHalf , false, r), secondaryWindow(1, r.useFullPage()? PagePart::FullPage : PagePart::RightHalf, true, r, r.useSecondScreen() ) { qDebug() << "Starting constructor" ; if ( ! r.useSecondScreen() ) { secondaryWindow.hide(); } audienceWindow.showLoadingScreen(0); secondaryWindow.showLoadingScreen(0); if ( ! pdfDocument || pdfDocument->isLocked() ) { /// FIXME: Error message throw std::runtime_error("I was not able to open the PDF document. Sorry."); } setHighQuality(true); qDebug() << "Connecting audience window"; audienceWindow.setPageNumberLimits(0, numberOfPages()-1); connect( &renderFactory, SIGNAL(pageRendered(QSharedPointer<RenderedPage>)), &audienceWindow, SLOT(renderedPageIncoming(QSharedPointer<RenderedPage>))); connect( &renderFactory, SIGNAL(thumbnailRendered(QSharedPointer<RenderedPage>)), &audienceWindow, SLOT(renderedThumbnailIncoming(QSharedPointer<RenderedPage>))); connect( &audienceWindow, SIGNAL(nextPageRequested()), this, SLOT(goForward())); connect( &audienceWindow, SIGNAL(previousPageRequested()), this, SLOT(goBackward())); connect( &audienceWindow, SIGNAL(pageRequested(uint)), this, SLOT(gotoPage(uint))); connect( &audienceWindow, SIGNAL(quitRequested()), this, SLOT(exit())); connect( &audienceWindow, SIGNAL(rerenderRequested()), this, SLOT(renderPage())); connect( &audienceWindow, SIGNAL(restartRequested()), this, SLOT(goToStartAndResetClocks())); connect( &audienceWindow, SIGNAL(screenSwapRequested()), this, SLOT(swapScreens()) ); if ( r.useSecondScreen() ) { qDebug() << "Connecting secondary window"; secondaryWindow.setPageNumberLimits(0, numberOfPages()-1); connect( &renderFactory, SIGNAL(pageRendered(QSharedPointer<RenderedPage>)), &secondaryWindow, SLOT(renderedPageIncoming(QSharedPointer<RenderedPage>))); connect( &renderFactory, SIGNAL(thumbnailRendered(QSharedPointer<RenderedPage>)), &secondaryWindow, SLOT(renderedThumbnailIncoming(QSharedPointer<RenderedPage>))); connect( &secondaryWindow, SIGNAL(nextPageRequested()), this, SLOT(goForward())); connect( &secondaryWindow, SIGNAL(previousPageRequested()), this, SLOT(goBackward())); connect( &secondaryWindow, SIGNAL(pageRequested(uint)), this, SLOT(gotoPage(uint))); connect( &secondaryWindow, SIGNAL(quitRequested()), this, SLOT(exit())); connect( &secondaryWindow, SIGNAL(rerenderRequested()), this, SLOT(renderPage())); connect( &secondaryWindow, SIGNAL(restartRequested()), this, SLOT(goToStartAndResetClocks())); connect( &secondaryWindow, SIGNAL(screenSwapRequested()), this, SLOT(swapScreens()) ); connect( this, SIGNAL(presentationClockUpdate(QTime)), &secondaryWindow, SLOT(updatePresentationClock(QTime))); connect( this, SIGNAL(slideClockUpdate(QTime)), &secondaryWindow, SLOT(updateSlideClock(QTime))); connect( this, SIGNAL(wallClockUpdate(QTime)), &secondaryWindow, SLOT(updateWallClock(QTime))); } renderPage(); clockDisplayTimer.setInterval(TIMER_UPDATE_INTERVAL); clockDisplayTimer.start(); connect( &clockDisplayTimer, SIGNAL(timeout()), this, SLOT(sendAllClockSignals())); sendAllClockSignals(); }
void DSPDFViewer::renderPage() { qDebug() << "Requesting rendering of page " << m_pagenumber; audienceWindow.showLoadingScreen(m_pagenumber); secondaryWindow.showLoadingScreen(m_pagenumber); if ( runtimeConfiguration.showThumbnails() ) { theFactory()->requestThumbnailRendering(m_pagenumber); } theFactory()->requestPageRendering( toRenderIdent(m_pagenumber, audienceWindow)); if ( runtimeConfiguration.useSecondScreen() ) { theFactory()->requestPageRendering( toRenderIdent(m_pagenumber, secondaryWindow)); } /** Pre-Render next pages **/ for ( unsigned i=m_pagenumber; i<m_pagenumber+runtimeConfiguration.prerenderNextPages() && i < numberOfPages() ; i++) { if ( runtimeConfiguration.showThumbnails() ) { theFactory()->requestThumbnailRendering(i); } theFactory()->requestPageRendering( toRenderIdent(i, audienceWindow)); if ( runtimeConfiguration.useSecondScreen() ) { theFactory()->requestPageRendering( toRenderIdent(i, secondaryWindow)); } } /** Pre-Render previous pages **/ for ( unsigned i= std::max(m_pagenumber,runtimeConfiguration.prerenderPreviousPages())-runtimeConfiguration.prerenderPreviousPages(); i<m_pagenumber; i++) { if ( runtimeConfiguration.showThumbnails() ) { theFactory()->requestThumbnailRendering(i); } theFactory()->requestPageRendering(toRenderIdent(i, audienceWindow)); if ( runtimeConfiguration.useSecondScreen() ) { theFactory()->requestPageRendering(toRenderIdent(i, secondaryWindow)); } } }
void DSPDFViewer::goForward() { resetSlideClock(); if ( pageNumber() < numberOfPages()-1 ) gotoPage(pageNumber()+1); }