Editor plugin: Bugfixing

This commit is contained in:
Jakub Melka 2024-06-23 17:37:55 +02:00
parent 72962f2513
commit 178ef02cc8
6 changed files with 92 additions and 48 deletions

View File

@ -50,8 +50,6 @@ EditorPlugin::EditorPlugin() :
}
// TODO: When text is edited, old text remains
// TODO: Color of the text is unchanged
// TODO: Moznost nastavit fill / stroke bool
void EditorPlugin::setWidget(pdf::PDFWidget* widget)
{

View File

@ -971,6 +971,14 @@ void PDFBLPaintEngine::setBLPen(BLContext& context, const QPen& pen)
break;
}
case Qt::CustomDashLine:
{
auto dashPattern = pen.dashPattern();
strokeOptions.dashArray.assignData(dashPattern.data(), dashPattern.size());
strokeOptions.dashOffset = pen.dashOffset();
break;
}
default:
break;
}

View File

@ -143,11 +143,19 @@ void PDFPainterHelper::applyPenToGraphicState(PDFPageContentProcessorState* grap
}
else
{
// TODO: Line Dash Pattern
/*
pen.setStyle(Qt::CustomDashLine);
pen.setDashPattern(lineDashPattern.createForQPen(pen.widthF()));
pen.setDashOffset(lineDashPattern.getDashOffset());*/
PDFLineDashPattern lineDashPattern;
QList<qreal> penPattern = pen.dashPattern();
PDFReal penWidth = pen.widthF();
std::vector<PDFReal> dashArray;
for (qreal value : penPattern)
{
dashArray.push_back(value * penWidth);
}
lineDashPattern.setDashArray(std::move(dashArray));
lineDashPattern.setDashOffset(pen.dashOffset());
graphicState->setLineDashPattern(std::move(lineDashPattern));
}
}
}

View File

@ -48,14 +48,12 @@ PDFPageContentEditorEditedItemSettings::PDFPageContentEditorEditedItemSettings(Q
ui->brushColorCombo->addItem(icon, colorName, color);
}
ui->penStyleCombo->addItem(tr("None"), int(Qt::NoPen));
ui->penStyleCombo->addItem(tr("Solid"), int(Qt::SolidLine));
ui->penStyleCombo->addItem(tr("Dashed"), int(Qt::DashLine));
ui->penStyleCombo->addItem(tr("Dotted"), int(Qt::DotLine));
ui->penStyleCombo->addItem(tr("Dash-dot"), int(Qt::DashDotLine));
ui->penStyleCombo->addItem(tr("Dash-dot-dot"), int(Qt::DashDotDotLine));
ui->brushStyleCombo->addItem(tr("None"), int(Qt::NoBrush));
ui->penStyleCombo->addItem(tr("Custom"), int(Qt::CustomDashLine));
ui->brushStyleCombo->addItem(tr("Solid"), int(Qt::SolidPattern));
connect(ui->selectPenColorButton, &QToolButton::clicked, this, &PDFPageContentEditorEditedItemSettings::onSelectPenColorButtonClicked);
@ -137,6 +135,7 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
features.setFlag(Pen);
features.setFlag(PenColor);
features.setFlag(Brush);
features.setFlag(StrokeFill);
}
if (element->asText())
@ -147,6 +146,7 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
const bool hasPen = features.testFlag(Pen);
const bool hasPenColor = features.testFlag(PenColor);
const bool hasBrush = features.testFlag(Brush);
const bool hasStrokeFill = features.testFlag(StrokeFill);
ui->penWidthEdit->setEnabled(hasPen);
ui->penWidthLabel->setEnabled(hasPen);
@ -165,6 +165,15 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
ui->brushColorLabel->setEnabled(hasBrush);
ui->selectBrushColorButton->setEnabled(hasBrush);
ui->strokePathCheckBox->setEnabled(hasStrokeFill);
ui->fillPathCheckBox->setEnabled(hasStrokeFill);
if (const PDFEditedPageContentElementPath* pathElement = element->asPath())
{
ui->strokePathCheckBox->setChecked(pathElement->getStrokePath());
ui->fillPathCheckBox->setChecked(pathElement->getFillPath());
}
const PDFPageContentProcessorState& graphicState = element->getState();
QPen pen = pdf::PDFPainterHelper::createPenFromState(&graphicState, graphicState.getAlphaStroking());
@ -241,6 +250,12 @@ void PDFPageContentEditorEditedItemSettings::saveToElement(PDFPageContentElement
textElement->setItemsAsText(ui->plainTextEdit->toPlainText());
}
if (PDFEditedPageContentElementPath* pathElement = editedElement->getElement()->asPath())
{
pathElement->setStrokePath(ui->strokePathCheckBox->isChecked());
pathElement->setFillPath(ui->fillPathCheckBox->isChecked());
}
PDFTransformationDecomposition decomposedTransformation;
decomposedTransformation.rotationAngle = ui->rotationAngleEdit->value();
decomposedTransformation.shearFactor = ui->shearFactorEdit->value();

View File

@ -69,7 +69,8 @@ private:
None = 0,
Pen = 1 << 0,
PenColor = 1 << 1,
Brush = 1 << 2
Brush = 1 << 2,
StrokeFill = 1 << 3,
};
Q_DECLARE_FLAGS(StyleFeatures, StyleFeature)

View File

@ -139,13 +139,16 @@
<string>Style</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QComboBox" name="penColorCombo">
<property name="editable">
<bool>true</bool>
<item row="4" column="2">
<widget class="QToolButton" name="selectBrushColorButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="brushStyleCombo"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="penStyleLabel">
<property name="text">
@ -153,20 +156,10 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="penWidthEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="brushColorLabel">
<item row="1" column="0">
<widget class="QLabel" name="penColorLabel">
<property name="text">
<string>Brush Color</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QToolButton" name="selectBrushColorButton">
<property name="text">
<string>...</string>
<string>Pen Color</string>
</property>
</widget>
</item>
@ -180,13 +173,6 @@
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="penStyleCombo"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="penWidthLabel">
<property name="text">
<string>Pen Width</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="brushStyleLabel">
<property name="text">
@ -194,24 +180,21 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="penColorLabel">
<item row="0" column="0">
<widget class="QLabel" name="penWidthLabel">
<property name="text">
<string>Pen Color</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="brushStyleCombo"/>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="brushColorCombo">
<property name="editable">
<bool>true</bool>
<string>Pen Width</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="strokePathCheckBox">
<property name="text">
<string>Stroke path</string>
</property>
</widget>
</item>
<item row="7" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -224,6 +207,37 @@
</property>
</spacer>
</item>
<item row="0" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="penWidthEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="brushColorLabel">
<property name="text">
<string>Brush Color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="penColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="brushColorCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="fillPathCheckBox">
<property name="text">
<string>Fill path</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="transformationTab">