PreviewFileDialog::PreviewFileDialog(QWidget *parent) : QFileDialog(parent) { setOption(QFileDialog::DontUseNativeDialog); preview = NULL; vboxlayout = new QVBoxLayout(); checkbox = new QCheckBox(tr("Preview")); checkbox->setChecked(true); preview = new QLabel("", this); preview->setAlignment(Qt::AlignCenter); preview->setObjectName("label_preview"); thumbWidget = new cThumbnailWidget(200, 200, 1, this); info = new QLabel(""); progressBar = new QProgressBar; progressBar->setMaximum(1000); progressBar->setAlignment(Qt::AlignCenter); progressBar->hide(); presetAddButton = new QPushButton; presetAddButton->setText(tr("Add to presets")); queueAddButton = new QPushButton; queueAddButton->setText(tr("Add to queue")); vboxlayout->addWidget(checkbox); vboxlayout->addWidget(preview); vboxlayout->addWidget(thumbWidget); vboxlayout->addWidget(progressBar); vboxlayout->addWidget(info); vboxlayout->addWidget(presetAddButton); vboxlayout->addWidget(queueAddButton); thumbWidget->show(); vboxlayout->addStretch(); //add to existing layout QGridLayout *gridlayout = (QGridLayout*) this->layout(); gridlayout->addLayout(vboxlayout, 1, 3, 3, 1); connect(this, SIGNAL(currentChanged(const QString&)), this, SLOT(OnCurrentChanged(const QString&))); connect(presetAddButton, SIGNAL(clicked()), this, SLOT(OnPresetAdd())); connect(queueAddButton, SIGNAL(clicked()), this, SLOT(OnQueueAdd())); connect(thumbWidget, SIGNAL(thumbnailRendered()), this, SLOT(slotHideProgressBar())); connect(thumbWidget, SIGNAL(updateProgressAndStatus(const QString&, const QString&, double)), this, SLOT(slotUpdateProgressAndStatus(const QString&, const QString&, double))); }
void cThumbnailWidget::slotFullyRendered() { if(!disableThumbnailCache) { QImage qImage((const uchar*) image->ConvertTo8bit(), image->GetWidth(), image->GetHeight(), image->GetWidth() * sizeof(sRGB8), QImage::Format_RGB888); QPixmap pixmap; pixmap.convertFromImage(qImage); QString thumbnailFileName = systemData.thumbnailDir + hash + QString(".png"); pixmap.save(thumbnailFileName, "PNG"); } lastRenderTime = renderingTimeTimer.nsecsElapsed() / 1e9; emit thumbnailRendered(); }
void cThumbnailWidget::AssignParameters(const cParameterContainer &_params, const cFractalContainer &_fractal) { *params = _params; *fractal = _fractal; params->Set("image_width", tWidth * oversample); params->Set("image_height", tHeight * oversample); cSettings tempSettings(cSettings::formatCondensedText); tempSettings.CreateText(params, fractal); oldHash = hash; hash = tempSettings.GetHashCode(); if(hash != oldHash) { stopRequest = true; while (image->IsUsed()) { //just wait and pray } emit settingsChanged(); isRendered = false; hasParameters = true; QString thumbnailFileName = systemData.thumbnailDir + hash + QString(".png"); if (QFileInfo::exists(thumbnailFileName) && !disableThumbnailCache) { stopRequest = true; isRendered = true; while (image->IsUsed()) { //just wait and pray } QPixmap pixmap; pixmap.load(thumbnailFileName); pixmap = pixmap.scaled(tWidth, tHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage qimage = pixmap.toImage(); qimage = qimage.convertToFormat(QImage::Format_RGB888); sRGB8 *bitmap; bitmap = (sRGB8*) (qimage.bits()); int bwidth = qimage.width(); int bheight = qimage.height(); sRGB8 *previewPointer = (sRGB8*) image->GetPreviewPrimaryPtr(); sRGB8 *preview2Pointer = (sRGB8*) image->GetPreviewPtr(); memcpy(previewPointer, bitmap, sizeof(sRGB8) * bwidth * bheight); memcpy(preview2Pointer, bitmap, sizeof(sRGB8) * bwidth * bheight); emit thumbnailRendered(); } else { if(!disableTimer) { //render thumbnail after random time. It forces rendering of widgets when they are not visible. It makes rendering of widgets when they are idle. timer->start(Random(100000) * 10 + 1); } } } }
void cThumbnailWidget::AssignParameters( const cParameterContainer &_params, const cFractalContainer &_fractal) { if (image) { if (!params) params = new cParameterContainer; if (!fractal) fractal = new cFractalContainer; *params = _params; *fractal = _fractal; params->Set("image_width", tWidth * oversample); params->Set("image_height", tHeight * oversample); params->Set("stereo_mode", int(cStereo::stereoRedCyan)); params->Set("DOF_max_noise", params->Get<double>("DOF_max_noise") * 10.0); params->Set("DOF_min_samples", 5); double distance = cInterface::GetDistanceForPoint(params->Get<CVector3>("camera"), params, fractal); if (distance < 1e-5) { params->Set("opencl_mode", 0); } cSettings tempSettings(cSettings::formatCondensedText); tempSettings.CreateText(params, fractal); oldHash = hash; hash = tempSettings.GetHashCode(); if (hash != oldHash) { stopRequest = true; while (image->IsUsed()) { // just wait and pray } emit settingsChanged(); isRendered = false; hasParameters = true; QString thumbnailFileName = GetThumbnailFileName(); if (QFileInfo::exists(thumbnailFileName) && !disableThumbnailCache) { stopRequest = true; isRendered = true; while (image->IsUsed()) { // just wait and pray } QPixmap pixmap; pixmap.load(thumbnailFileName); pixmap = pixmap.scaled(tWidth, tHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage qImage = pixmap.toImage(); qImage = qImage.convertToFormat(QImage::Format_RGB888); sRGB8 *previewPointer = reinterpret_cast<sRGB8 *>(image->GetPreviewPrimaryPtr()); sRGB8 *preview2Pointer = reinterpret_cast<sRGB8 *>(image->GetPreviewPtr()); int bWidth = qImage.width(); int bHeight = qImage.height(); if (!qImage.isNull()) { for (int y = 0; y < bHeight; y++) { sRGB8 *line = reinterpret_cast<sRGB8 *>(qImage.scanLine(y)); for (int x = 0; x < bWidth; x++) { sRGB8 pixel(static_cast<unsigned short>(line[x].R), static_cast<unsigned short>(line[x].G), static_cast<unsigned short>(line[x].B)); previewPointer[x + y * bWidth] = pixel; preview2Pointer[x + y * bWidth] = pixel; } } } delete params; params = nullptr; delete fractal; fractal = nullptr; emit thumbnailRendered(); } else { if (!disableTimer) { // render thumbnail after random time. It forces rendering of widgets when they are not // visible. It makes rendering of widgets when they are idle. timer->start(Random(1000000) * 10 + 60000); } } } } else { qCritical() << "Image not yet allocated!"; } }
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(); }