Color percent indicator for output preview

This commit is contained in:
Jakub Melka 2021-03-28 19:12:50 +02:00
parent 94fdd0f63f
commit e3c1492452
5 changed files with 124 additions and 6 deletions

View File

@ -24,6 +24,7 @@
#include "pdfdrawspacecontroller.h" #include "pdfdrawspacecontroller.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QColorDialog>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
namespace pdfplugin namespace pdfplugin
@ -67,10 +68,12 @@ OutputPreviewDialog::OutputPreviewDialog(const pdf::PDFDocument* document, pdf::
connect(ui->displayTilingPatternsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::updatePageImage); connect(ui->displayTilingPatternsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::updatePageImage);
connect(ui->displayVectorGraphicsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::updatePageImage); connect(ui->displayVectorGraphicsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::updatePageImage);
connect(ui->inksTreeWidget->model(), &QAbstractItemModel::dataChanged, this, &OutputPreviewDialog::onInksChanged); connect(ui->inksTreeWidget->model(), &QAbstractItemModel::dataChanged, this, &OutputPreviewDialog::onInksChanged);
connect(ui->alarmColorButton, &QPushButton::clicked, this, &OutputPreviewDialog::onAlarmColorButtonClicked);
updatePageImage(); updatePageImage();
updateInks(); updateInks();
updatePaperColorWidgets(); updatePaperColorWidgets();
updateAlarmColorButtonIcon();
} }
OutputPreviewDialog::~OutputPreviewDialog() OutputPreviewDialog::~OutputPreviewDialog()
@ -175,6 +178,14 @@ void OutputPreviewDialog::updatePaperColorWidgets()
} }
} }
void OutputPreviewDialog::updateAlarmColorButtonIcon()
{
QSize iconSize = ui->alarmColorButton->iconSize();
QPixmap pixmap(iconSize);
pixmap.fill(ui->imageWidget->getAlarmColor());
ui->alarmColorButton->setIcon(QIcon(pixmap));
}
void OutputPreviewDialog::onPaperColorChanged() void OutputPreviewDialog::onPaperColorChanged()
{ {
const bool isPaperColorEnabled = ui->simulatePaperColorCheckBox->isChecked(); const bool isPaperColorEnabled = ui->simulatePaperColorCheckBox->isChecked();
@ -184,6 +195,16 @@ void OutputPreviewDialog::onPaperColorChanged()
} }
} }
void OutputPreviewDialog::onAlarmColorButtonClicked()
{
QColorDialog colorDialog(ui->imageWidget->getAlarmColor(), this);
if (colorDialog.exec() == QColorDialog::Accepted)
{
ui->imageWidget->setAlarmColor(colorDialog.currentColor());
updateAlarmColorButtonIcon();
}
}
void OutputPreviewDialog::onSimulateSeparationsChecked(bool checked) void OutputPreviewDialog::onSimulateSeparationsChecked(bool checked)
{ {
m_inkMapper.setSpotColorsActive(checked); m_inkMapper.setSpotColorsActive(checked);

View File

@ -53,8 +53,10 @@ public:
private: private:
void updateInks(); void updateInks();
void updatePaperColorWidgets(); void updatePaperColorWidgets();
void updateAlarmColorButtonIcon();
void onPaperColorChanged(); void onPaperColorChanged();
void onAlarmColorButtonClicked();
void onSimulateSeparationsChecked(bool checked); void onSimulateSeparationsChecked(bool checked);
void onSimulatePaperColorChecked(bool checked); void onSimulatePaperColorChecked(bool checked);
void onInksChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles); void onInksChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);

View File

@ -252,7 +252,7 @@
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="alarmColorButton"> <widget class="QPushButton" name="alarmColorButton">
<property name="text"> <property name="text">
<string/> <string>Select</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -20,6 +20,7 @@
#include "pdfwidgetutils.h" #include "pdfwidgetutils.h"
#include <QPainter> #include <QPainter>
#include <QMouseEvent>
#include <QFontMetrics> #include <QFontMetrics>
namespace pdfplugin namespace pdfplugin
@ -28,9 +29,10 @@ namespace pdfplugin
OutputPreviewWidget::OutputPreviewWidget(QWidget* parent) : OutputPreviewWidget::OutputPreviewWidget(QWidget* parent) :
BaseClass(parent), BaseClass(parent),
m_inkMapper(nullptr), m_inkMapper(nullptr),
m_displayMode(Separations) m_displayMode(Separations),
m_alarmColor(Qt::red)
{ {
setMouseTracking(true);
} }
QSize OutputPreviewWidget::sizeHint() const QSize OutputPreviewWidget::sizeHint() const
@ -49,6 +51,7 @@ void OutputPreviewWidget::clear()
m_originalProcessBitmap = pdf::PDFFloatBitmapWithColorSpace(); m_originalProcessBitmap = pdf::PDFFloatBitmapWithColorSpace();
m_pageSizeMM = QSizeF(); m_pageSizeMM = QSizeF();
m_infoBoxItems.clear(); m_infoBoxItems.clear();
m_imagePointUnderCursor = std::nullopt;
update(); update();
} }
@ -57,6 +60,16 @@ void OutputPreviewWidget::setPageImage(QImage image, pdf::PDFFloatBitmapWithColo
m_pageImage = qMove(image); m_pageImage = qMove(image);
m_originalProcessBitmap = qMove(originalProcessBitmap); m_originalProcessBitmap = qMove(originalProcessBitmap);
m_pageSizeMM = pageSizeMM; m_pageSizeMM = pageSizeMM;
if (m_imagePointUnderCursor.has_value())
{
QPoint point = m_imagePointUnderCursor.value();
if (point.x() >= image.width() || point.y() >= image.height())
{
m_imagePointUnderCursor = std::nullopt;
}
}
buildInfoBoxItems(); buildInfoBoxItems();
update(); update();
} }
@ -215,6 +228,35 @@ void OutputPreviewWidget::buildInfoBoxItems()
const pdf::PDFPixelFormat pixelFormat = m_originalProcessBitmap.getPixelFormat(); const pdf::PDFPixelFormat pixelFormat = m_originalProcessBitmap.getPixelFormat();
std::vector<pdf::PDFInkMapper::ColorInfo> separations = m_inkMapper->getSeparations(pixelFormat.getProcessColorChannelCount(), true); std::vector<pdf::PDFInkMapper::ColorInfo> separations = m_inkMapper->getSeparations(pixelFormat.getProcessColorChannelCount(), true);
QStringList colorValues;
colorValues.reserve(pixelFormat.getColorChannelCount());
Q_ASSERT(pixelFormat.getColorChannelCount() == separations.size());
if (m_imagePointUnderCursor.has_value())
{
QPoint point = m_imagePointUnderCursor.value();
Q_ASSERT(point.x() >= 0);
Q_ASSERT(point.x() < m_pageImage.width());
Q_ASSERT(point.y() >= 0);
Q_ASSERT(point.y() < m_pageImage.height());
pdf::PDFColorBuffer buffer = m_originalProcessBitmap.getPixel(point.x(), point.y());
for (int i = 0; i < pixelFormat.getColorChannelCount(); ++i)
{
const pdf::PDFColorComponent color = buffer[i] * 100.0f;
const int percent = qRound(color);
colorValues << QString("%1 %").arg(percent);
}
}
else
{
for (int i = 0; i < pixelFormat.getColorChannelCount(); ++i)
{
colorValues << QString();
}
}
// Count process/spot inks // Count process/spot inks
int processInks = 0; int processInks = 0;
@ -232,6 +274,7 @@ void OutputPreviewWidget::buildInfoBoxItems()
} }
} }
int colorValueIndex = 0;
if (processInks > 0) if (processInks > 0)
{ {
addInfoBoxSeparator(); addInfoBoxSeparator();
@ -244,7 +287,7 @@ void OutputPreviewWidget::buildInfoBoxItems()
continue; continue;
} }
addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, QString("100 %")); addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, colorValues[colorValueIndex++]);
} }
} }
@ -260,7 +303,7 @@ void OutputPreviewWidget::buildInfoBoxItems()
continue; continue;
} }
addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, QString("100 %")); addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, colorValues[colorValueIndex++]);
} }
} }
} }
@ -294,6 +337,21 @@ void OutputPreviewWidget::addInfoBoxColoredItem(QColor color, QString caption, Q
m_infoBoxItems.push_back(InfoBoxItem(ColoredItem, color, caption, value)); m_infoBoxItems.push_back(InfoBoxItem(ColoredItem, color, caption, value));
} }
void OutputPreviewWidget::addColoredOval(QColor color)
{
m_infoBoxItems.push_back(InfoBoxItem(ColoredOval, color, QString(), QString()));
}
QColor OutputPreviewWidget::getAlarmColor() const
{
return m_alarmColor;
}
void OutputPreviewWidget::setAlarmColor(const QColor& alarmColor)
{
m_alarmColor = alarmColor;
}
const pdf::PDFInkMapper* OutputPreviewWidget::getInkMapper() const const pdf::PDFInkMapper* OutputPreviewWidget::getInkMapper() const
{ {
return m_inkMapper; return m_inkMapper;
@ -309,4 +367,33 @@ QSize OutputPreviewWidget::getPageImageSizeHint() const
return getPageImageRect(getContentRect()).size(); return getPageImageRect(getContentRect()).size();
} }
void OutputPreviewWidget::mouseMoveEvent(QMouseEvent* event)
{
m_imagePointUnderCursor = std::nullopt;
if (m_pageImage.isNull())
{
// Nothing to do...
return;
}
QPoint position = event->pos();
QRect rect = getPageImageRect(getContentRect());
if (rect.contains(position))
{
int verticalImageOffset = (rect.height() - m_pageImage.height()) / 2;
QPoint imagePoint = position - rect.topLeft() - QPoint(0, verticalImageOffset);
if (imagePoint.x() >= 0 && imagePoint.x() < m_pageImage.width() &&
imagePoint.y() >= 0 && imagePoint.y() < m_pageImage.height())
{
m_imagePointUnderCursor = imagePoint;
}
}
buildInfoBoxItems();
update();
}
} // pdfplugin } // pdfplugin

View File

@ -58,8 +58,12 @@ public:
/// Returns page image size hint (ideal size of page image) /// Returns page image size hint (ideal size of page image)
QSize getPageImageSizeHint() const; QSize getPageImageSizeHint() const;
QColor getAlarmColor() const;
void setAlarmColor(const QColor& alarmColor);
protected: protected:
virtual void paintEvent(QPaintEvent* event) override; virtual void paintEvent(QPaintEvent* event) override;
virtual void mouseMoveEvent(QMouseEvent* event) override;
private: private:
QMargins getDrawMargins() const; QMargins getDrawMargins() const;
@ -73,12 +77,14 @@ private:
void addInfoBoxHeader(QString caption); void addInfoBoxHeader(QString caption);
void addInfoBoxSeparator(); void addInfoBoxSeparator();
void addInfoBoxColoredItem(QColor color, QString caption, QString value); void addInfoBoxColoredItem(QColor color, QString caption, QString value);
void addColoredOval(QColor color);
enum InfoBoxStyle enum InfoBoxStyle
{ {
Header, Header,
Separator, Separator,
ColoredItem ColoredItem,
ColoredOval
}; };
struct InfoBoxItem struct InfoBoxItem
@ -101,6 +107,8 @@ private:
const pdf::PDFInkMapper* m_inkMapper; const pdf::PDFInkMapper* m_inkMapper;
DisplayMode m_displayMode; DisplayMode m_displayMode;
std::vector<InfoBoxItem> m_infoBoxItems; std::vector<InfoBoxItem> m_infoBoxItems;
QColor m_alarmColor;
std::optional<QPoint> m_imagePointUnderCursor;
QImage m_pageImage; QImage m_pageImage;
pdf::PDFFloatBitmapWithColorSpace m_originalProcessBitmap; pdf::PDFFloatBitmapWithColorSpace m_originalProcessBitmap;