mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
DocDiff application: colors
This commit is contained in:
@ -18,14 +18,31 @@
|
||||
#include "settingsdockwidget.h"
|
||||
#include "ui_settingsdockwidget.h"
|
||||
|
||||
#include "pdfutils.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
|
||||
namespace pdfdocdiff
|
||||
{
|
||||
|
||||
SettingsDockWidget::SettingsDockWidget(QWidget *parent) :
|
||||
SettingsDockWidget::SettingsDockWidget(Settings* settings, QWidget* parent) :
|
||||
QDockWidget(parent),
|
||||
ui(new Ui::SettingsDockWidget)
|
||||
ui(new Ui::SettingsDockWidget),
|
||||
m_settings(settings),
|
||||
m_loadingColors(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
auto colorNames = QColor::colorNames();
|
||||
for (QComboBox* comboBox : findChildren<QComboBox*>())
|
||||
{
|
||||
for (const QString& colorName : colorNames)
|
||||
{
|
||||
QColor color(colorName);
|
||||
comboBox->addItem(getIconForColor(color), colorName, color);
|
||||
}
|
||||
|
||||
connect(comboBox, &QComboBox::editTextChanged, this, &SettingsDockWidget::onEditColorChanged);
|
||||
}
|
||||
}
|
||||
|
||||
SettingsDockWidget::~SettingsDockWidget()
|
||||
@ -33,4 +50,94 @@ SettingsDockWidget::~SettingsDockWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SettingsDockWidget::setCompareTextsAsVectorGraphics(bool enabled)
|
||||
{
|
||||
ui->compareTextsAsVectorGraphicsCheckBox->setChecked(enabled);
|
||||
}
|
||||
|
||||
bool SettingsDockWidget::isCompareTextAsVectorGraphics() const
|
||||
{
|
||||
return ui->compareTextsAsVectorGraphicsCheckBox->isChecked();
|
||||
}
|
||||
|
||||
void SettingsDockWidget::setCompareTextCharactersInsteadOfWords(bool enabled)
|
||||
{
|
||||
ui->compareCharactersInsteadOfWordsCheckBox->setChecked(enabled);
|
||||
}
|
||||
|
||||
bool SettingsDockWidget::isCompareTextCharactersInsteadOfWords() const
|
||||
{
|
||||
return ui->compareCharactersInsteadOfWordsCheckBox->isChecked();
|
||||
}
|
||||
|
||||
QLineEdit* SettingsDockWidget::getLeftPageSelectionEdit() const
|
||||
{
|
||||
return ui->leftPageSelectionEdit;
|
||||
}
|
||||
|
||||
QLineEdit* SettingsDockWidget::getRightPageSelectionEdit() const
|
||||
{
|
||||
return ui->rightPageSelectionEdit;
|
||||
}
|
||||
|
||||
void SettingsDockWidget::loadColors()
|
||||
{
|
||||
pdf::PDFTemporaryValueChange guard(&m_loadingColors, true);
|
||||
|
||||
auto loadColor = [](QComboBox* comboBox, QColor color)
|
||||
{
|
||||
auto index = comboBox->findData(color);
|
||||
comboBox->setCurrentIndex(index);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
comboBox->setCurrentText(color.name());
|
||||
}
|
||||
};
|
||||
|
||||
loadColor(ui->removeColorCombo, m_settings->colorRemoved);
|
||||
loadColor(ui->addColorCombo, m_settings->colorAdded);
|
||||
loadColor(ui->replaceColorCombo, m_settings->colorReplaced);
|
||||
loadColor(ui->moveColorCombo, m_settings->colorPageMove);
|
||||
}
|
||||
|
||||
QIcon SettingsDockWidget::getIconForColor(QColor color) const
|
||||
{
|
||||
QIcon icon;
|
||||
|
||||
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(this, QSize(16, 16));
|
||||
|
||||
QPixmap pixmap(iconSize.width(), iconSize.height());
|
||||
pixmap.fill(color);
|
||||
icon.addPixmap(pixmap);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
void SettingsDockWidget::onEditColorChanged()
|
||||
{
|
||||
if (m_loadingColors)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isChanged = false;
|
||||
auto saveColor = [&isChanged](QComboBox* comboBox, QColor& color)
|
||||
{
|
||||
QColor oldColor = color;
|
||||
color.setNamedColor(comboBox->currentText());
|
||||
isChanged = isChanged || oldColor != color;
|
||||
};
|
||||
|
||||
saveColor(ui->removeColorCombo, m_settings->colorRemoved);
|
||||
saveColor(ui->addColorCombo, m_settings->colorAdded);
|
||||
saveColor(ui->replaceColorCombo, m_settings->colorReplaced);
|
||||
saveColor(ui->moveColorCombo, m_settings->colorPageMove);
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
emit colorsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pdfdocdiff
|
||||
|
Reference in New Issue
Block a user