Commit 8e88c2b8 authored by Alexander Stippich's avatar Alexander Stippich
Browse files

rework updating the image in the preview viewer

parent 7949d4f8
......@@ -65,7 +65,6 @@ void KSaneImageBuilder::start(const SANE_Parameters &params)
m_image->setDotsPerMeterY(dpm);
}
m_image->fill(0xFFFFFFFF);
m_imageResized = false;
}
void KSaneImageBuilder::beginFrame(const SANE_Parameters &params)
......@@ -252,20 +251,10 @@ bool KSaneImageBuilder::copyToImage(const SANE_Byte readData[], int read_bytes)
return false;
}
bool KSaneImageBuilder::imageResized()
{
if (m_imageResized) {
m_imageResized = false;
return true;
}
return false;
}
void KSaneImageBuilder::renewImage()
{
// resize the image
*m_image = m_image->copy(0, 0, m_image->width(), m_image->height() + m_image->width());
m_imageResized = true;
}
void KSaneImageBuilder::incrementPixelData()
......
......@@ -30,7 +30,6 @@ public:
void start(const SANE_Parameters &params);
void beginFrame(const SANE_Parameters &params);
bool copyToImage(const SANE_Byte readData[], int read_bytes);
bool imageResized();
void setDPI(int dpi);
private:
......@@ -46,9 +45,8 @@ private:
QImage *m_image;
int *m_dpi;
bool m_imageResized = false;
};
}
#endif // KSANE_IMAGE_BUILDER_H
......@@ -79,13 +79,10 @@ void KSaneScanThread::run()
{
m_dataSize = 0;
m_readStatus = ReadOngoing;
m_saneStartDone = false;
// Start the scanning with sane_start
m_saneStatus = sane_start(m_saneHandle);
m_saneStartDone = true;
if (m_readStatus == ReadCancel) {
return;
}
......@@ -121,6 +118,8 @@ void KSaneScanThread::run()
m_frameRead = 0;
m_frame_t_count = 0;
Q_EMIT scanProgressUpdated(0);
while (m_readStatus == ReadOngoing) {
readData();
}
......@@ -141,7 +140,9 @@ void KSaneScanThread::updateScanProgress()
bytesRead = m_frameRead;
}
Q_EMIT scanProgressUpdated(static_cast<int>((static_cast<float>(bytesRead) * 100.0) / m_dataSize));
if (bytesRead > 0) {
Q_EMIT scanProgressUpdated(static_cast<int>((static_cast<float>(bytesRead) * 100.0) / m_dataSize));
}
}
void KSaneScanThread::finishProgress()
......@@ -240,14 +241,4 @@ void KSaneScanThread::copyToScanData(int readBytes)
}
}
bool KSaneScanThread::saneStartDone()
{
return m_saneStartDone;
}
bool KSaneScanThread::imageResized()
{
return m_imageBuilder.imageResized();
}
} // NameSpace KSaneIface
......@@ -47,9 +47,6 @@ public:
void setImageResolution(const QVariant &newValue);
void cancelScan();
bool saneStartDone();
bool imageResized();
ReadStatus frameStatus();
SANE_Status saneStatus();
......@@ -77,7 +74,6 @@ private:
SANE_Parameters m_params;
SANE_Status m_saneStatus = SANE_STATUS_GOOD;
ReadStatus m_readStatus = ReadReady;
bool m_saneStartDone = false;
bool m_invertColors = false;
KSaneImageBuilder m_imageBuilder;
QImage m_image;
......
......@@ -56,6 +56,9 @@ struct KSaneViewer::Private {
bool multiSelectionEnabled = true;
int wheelDelta = 0;
int currentImageWidth;
int currentImageHeight;
};
KSaneViewer::KSaneViewer(QImage *img, QWidget *parent) : QGraphicsView(parent), d(new Private)
......@@ -69,14 +72,18 @@ KSaneViewer::KSaneViewer(QImage *img, QWidget *parent) : QGraphicsView(parent),
// Init the scene
d->scene = new QGraphicsScene(this);
const auto dpr = img->devicePixelRatio();
d->scene->setSceneRect(0, 0, img->width() / dpr, img->height() / dpr);
d->currentImageWidth = img->width();
d->currentImageHeight = img->height();
d->scene->setSceneRect(0, 0, d->currentImageWidth / dpr, d->currentImageHeight / dpr);
setScene(d->scene);
d->selection = new SelectionItem(QRectF());
d->selection->setZValue(10);
d->selection->setSaved(false);
d->selection->setMaxRight(img->width());
d->selection->setMaxBottom(img->height());
d->selection->setMaxRight(d->currentImageWidth);
d->selection->setMaxBottom(d->currentImageHeight);
d->selection->setRect(d->scene->sceneRect());
d->selection->setVisible(false);
......@@ -140,6 +147,18 @@ KSaneViewer::~KSaneViewer()
delete d;
}
// ------------------------------------------------------------------------
int KSaneViewer::currentImageHeight() const
{
return d->currentImageHeight;
}
// ------------------------------------------------------------------------
int KSaneViewer::currentImageWidth() const
{
return d->currentImageWidth;
}
// ------------------------------------------------------------------------
void KSaneViewer::setQImage(QImage *img)
{
......@@ -154,9 +173,13 @@ void KSaneViewer::setQImage(QImage *img)
resetTransform();
const auto dpr = img->devicePixelRatio();
d->scene->setSceneRect(0, 0, img->width() / dpr, img->height() / dpr);
d->selection->setMaxRight(img->width());
d->selection->setMaxBottom(img->height());
d->currentImageWidth = img->width();
d->currentImageHeight = img->height();
d->scene->setSceneRect(0, 0, d->currentImageWidth / dpr, d->currentImageHeight / dpr);
d->selection->setMaxRight(d->currentImageWidth);
d->selection->setMaxBottom(d->currentImageHeight);
d->selection->setDevicePixelRatio(dpr);
d->hideTop->setDevicePixelRatio(dpr);
......
......@@ -33,6 +33,9 @@ public:
QSize sizeHint() const override;
int currentImageHeight() const;
int currentImageWidth() const;
public Q_SLOTS:
void setTLX(float ratio);
......
......@@ -1351,23 +1351,22 @@ void KSaneWidgetPrivate::invertPreview()
void KSaneWidgetPrivate::updateProgress(int progress)
{
if (m_isPreview) {
if (m_scanThread->saneStartDone()) {
if (!m_progressBar->isVisible() || m_scanThread->imageResized()) {
m_warmingUp->hide();
m_activityFrame->show();
// the image size might have changed
m_scanThread->lockScanImage();
m_previewViewer->setQImage(m_scanThread->scanImage());
m_previewViewer->zoom2Fit();
m_scanThread->unlockScanImage();
} else {
m_scanThread->lockScanImage();
m_previewViewer->updateImage();
m_scanThread->unlockScanImage();
}
if (!m_progressBar->isVisible() || m_scanThread->scanImage()->height() != m_previewViewer->currentImageHeight()
|| m_scanThread->scanImage()->width() != m_previewViewer->currentImageWidth() ) {
m_warmingUp->hide();
m_activityFrame->show();
// the image size might have changed
m_scanThread->lockScanImage();
m_previewViewer->setQImage(m_scanThread->scanImage());
m_previewViewer->zoom2Fit();
m_scanThread->unlockScanImage();
} else {
m_scanThread->lockScanImage();
m_previewViewer->updateImage();
m_scanThread->unlockScanImage();
}
} else {
if (!m_progressBar->isVisible() && (m_scanThread->saneStartDone())) {
if (!m_progressBar->isVisible()) {
m_warmingUp->hide();
m_activityFrame->show();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment