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: 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) void EditorPlugin::setWidget(pdf::PDFWidget* widget)
{ {

View File

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

View File

@ -143,11 +143,19 @@ void PDFPainterHelper::applyPenToGraphicState(PDFPageContentProcessorState* grap
} }
else else
{ {
// TODO: Line Dash Pattern PDFLineDashPattern lineDashPattern;
/* QList<qreal> penPattern = pen.dashPattern();
pen.setStyle(Qt::CustomDashLine); PDFReal penWidth = pen.widthF();
pen.setDashPattern(lineDashPattern.createForQPen(pen.widthF()));
pen.setDashOffset(lineDashPattern.getDashOffset());*/ 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->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("Solid"), int(Qt::SolidLine));
ui->penStyleCombo->addItem(tr("Dashed"), int(Qt::DashLine)); ui->penStyleCombo->addItem(tr("Dashed"), int(Qt::DashLine));
ui->penStyleCombo->addItem(tr("Dotted"), int(Qt::DotLine)); ui->penStyleCombo->addItem(tr("Dotted"), int(Qt::DotLine));
ui->penStyleCombo->addItem(tr("Dash-dot"), int(Qt::DashDotLine)); ui->penStyleCombo->addItem(tr("Dash-dot"), int(Qt::DashDotLine));
ui->penStyleCombo->addItem(tr("Dash-dot-dot"), int(Qt::DashDotDotLine)); ui->penStyleCombo->addItem(tr("Dash-dot-dot"), int(Qt::DashDotDotLine));
ui->penStyleCombo->addItem(tr("Custom"), int(Qt::CustomDashLine));
ui->brushStyleCombo->addItem(tr("None"), int(Qt::NoBrush));
ui->brushStyleCombo->addItem(tr("Solid"), int(Qt::SolidPattern)); ui->brushStyleCombo->addItem(tr("Solid"), int(Qt::SolidPattern));
connect(ui->selectPenColorButton, &QToolButton::clicked, this, &PDFPageContentEditorEditedItemSettings::onSelectPenColorButtonClicked); connect(ui->selectPenColorButton, &QToolButton::clicked, this, &PDFPageContentEditorEditedItemSettings::onSelectPenColorButtonClicked);
@ -137,6 +135,7 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
features.setFlag(Pen); features.setFlag(Pen);
features.setFlag(PenColor); features.setFlag(PenColor);
features.setFlag(Brush); features.setFlag(Brush);
features.setFlag(StrokeFill);
} }
if (element->asText()) if (element->asText())
@ -147,6 +146,7 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
const bool hasPen = features.testFlag(Pen); const bool hasPen = features.testFlag(Pen);
const bool hasPenColor = features.testFlag(PenColor); const bool hasPenColor = features.testFlag(PenColor);
const bool hasBrush = features.testFlag(Brush); const bool hasBrush = features.testFlag(Brush);
const bool hasStrokeFill = features.testFlag(StrokeFill);
ui->penWidthEdit->setEnabled(hasPen); ui->penWidthEdit->setEnabled(hasPen);
ui->penWidthLabel->setEnabled(hasPen); ui->penWidthLabel->setEnabled(hasPen);
@ -165,6 +165,15 @@ void PDFPageContentEditorEditedItemSettings::loadFromElement(PDFPageContentEleme
ui->brushColorLabel->setEnabled(hasBrush); ui->brushColorLabel->setEnabled(hasBrush);
ui->selectBrushColorButton->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(); const PDFPageContentProcessorState& graphicState = element->getState();
QPen pen = pdf::PDFPainterHelper::createPenFromState(&graphicState, graphicState.getAlphaStroking()); QPen pen = pdf::PDFPainterHelper::createPenFromState(&graphicState, graphicState.getAlphaStroking());
@ -241,6 +250,12 @@ void PDFPageContentEditorEditedItemSettings::saveToElement(PDFPageContentElement
textElement->setItemsAsText(ui->plainTextEdit->toPlainText()); textElement->setItemsAsText(ui->plainTextEdit->toPlainText());
} }
if (PDFEditedPageContentElementPath* pathElement = editedElement->getElement()->asPath())
{
pathElement->setStrokePath(ui->strokePathCheckBox->isChecked());
pathElement->setFillPath(ui->fillPathCheckBox->isChecked());
}
PDFTransformationDecomposition decomposedTransformation; PDFTransformationDecomposition decomposedTransformation;
decomposedTransformation.rotationAngle = ui->rotationAngleEdit->value(); decomposedTransformation.rotationAngle = ui->rotationAngleEdit->value();
decomposedTransformation.shearFactor = ui->shearFactorEdit->value(); decomposedTransformation.shearFactor = ui->shearFactorEdit->value();

View File

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

View File

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