Compare commits
No commits in common. "fbfc5f2759ec6bd3dcd028ae788cc2f05ee35184" and "c4281a444e2694a16a86724e0f44cae75500dda0" have entirely different histories.
fbfc5f2759
...
c4281a444e
|
@ -202,7 +202,6 @@
|
|||
<QtMoc Include="src\Editor\EditorWidgetComponent\ColorPicker.h" />
|
||||
<QtMoc Include="src\Editor\RightBar\EditorSettingWidget.h" />
|
||||
<QtMoc Include="src\Editor\EditorWidgetComponent\FillStyleWidget.h" />
|
||||
<ClInclude Include="src\ColorHelper.hpp" />
|
||||
<ClInclude Include="src\Editor\LayerWrapper.h" />
|
||||
<ClInclude Include="src\Editor\util\EncodeUtil.hpp" />
|
||||
<ClInclude Include="src\Editor\util\JsonUtil.hpp" />
|
||||
|
|
|
@ -519,9 +519,6 @@
|
|||
<ClInclude Include="src\Editor\LayerWrapper.h">
|
||||
<Filter>Header Files\Editor\Layer</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ColorHelper.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="res\MainWindow.qrc">
|
||||
|
|
|
@ -180,12 +180,6 @@
|
|||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>图层名</string>
|
||||
|
@ -196,11 +190,6 @@
|
|||
<string>关联图元</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>可见</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -1093,7 +1093,6 @@ void main()
|
|||
bool onVeryBegin = false;
|
||||
bool onVeryEnd = false;
|
||||
vec2 tangentEndLast;
|
||||
vec2 tangentFirstBegin;
|
||||
uint lastHitIndex = 0;
|
||||
bool lastHitElement = false;
|
||||
hitElement = false;
|
||||
|
@ -1109,19 +1108,7 @@ void main()
|
|||
pBegin = path[++pathIndex];
|
||||
p3Last = pBegin;
|
||||
p2Last = pBegin;
|
||||
if(endType == 4)
|
||||
{
|
||||
//onVeryBegin = false;
|
||||
vec2 lastP1 = path[pathSize-3];
|
||||
vec2 lastP2 = path[pathSize-2];
|
||||
vec2 lastP3 = path[pathSize-1];
|
||||
if (lastP3 != lastP2)
|
||||
tangentEndLast = normalize(lastP3 - lastP2);
|
||||
else
|
||||
tangentEndLast = normalize(lastP3 - lastP1);
|
||||
}
|
||||
else
|
||||
onVeryBegin = true;
|
||||
onVeryBegin = true;
|
||||
continue;
|
||||
}
|
||||
mat4x2 p = mat4x2(p3Last, pTemp, path[++pathIndex], path[++pathIndex]);
|
||||
|
@ -1132,13 +1119,7 @@ void main()
|
|||
vec2 pTemp = path[pathIndex + 1];
|
||||
if (isinf(pTemp.x))
|
||||
{
|
||||
if(endType == 4)
|
||||
{
|
||||
//onVeryEnd = false;
|
||||
tangentBeginNext = tangentFirstBegin;
|
||||
}
|
||||
else
|
||||
onVeryEnd = true;
|
||||
onVeryEnd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1199,8 +1180,6 @@ void main()
|
|||
}
|
||||
}
|
||||
tangentEndLast = tangentEnd;
|
||||
if(pathIndex == 0)
|
||||
tangentFirstBegin = tangentBegin;
|
||||
}
|
||||
p3Last = p[3];
|
||||
p2Last = p[2];
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
#pragma once
|
||||
#include <lib/qtmaterialstyle.h>
|
||||
#include <lib/qtmaterialtheme.h>
|
||||
#include <QColorDialog>
|
||||
|
||||
class ColorHelper
|
||||
{
|
||||
QtMaterialTheme theme;
|
||||
QColor primary1;
|
||||
public:
|
||||
|
||||
void setPrimary1(const QColor& color)
|
||||
{
|
||||
theme.setColor("primary1", color);
|
||||
primary1 = color;
|
||||
}
|
||||
|
||||
[[nodiscard]] QColor getPrimary1() const
|
||||
{
|
||||
return primary1;
|
||||
}
|
||||
|
||||
ColorHelper()
|
||||
{
|
||||
setPrimary1(QColor::fromRgb(0, 90, 158));
|
||||
QtMaterialStyle::instance().setTheme(&theme);
|
||||
}
|
||||
|
||||
static ColorHelper& instance()
|
||||
{
|
||||
static ColorHelper instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
static QColor execColorDialog(
|
||||
const QColor& initial = instance().getPrimary1(),
|
||||
QWidget* parent = nullptr,
|
||||
const QString& title = ""
|
||||
) {
|
||||
auto dialog = QColorDialog(initial, parent);
|
||||
if (!title.isEmpty())
|
||||
{
|
||||
dialog.setWindowTitle(title);
|
||||
}
|
||||
dialog.adjustSize();
|
||||
dialog.exec();
|
||||
return dialog.selectedColor();
|
||||
}
|
||||
};
|
|
@ -1,6 +1,5 @@
|
|||
#include "ColorPicker.h"
|
||||
#include <QColorDialog>
|
||||
#include <QDebug>
|
||||
|
||||
QString getStyleSheet(const QColor& color)
|
||||
{
|
||||
|
@ -27,8 +26,9 @@ QColor ColorPicker::getColor() const
|
|||
|
||||
void ColorPicker::onClicked()
|
||||
{
|
||||
//const QColor newColor = QColorDialog::getColor(this->color, this);
|
||||
const QColor newColor = ColorHelper::execColorDialog(this->color, this);
|
||||
QColorDialog dialog(this->color, this);
|
||||
dialog.exec();
|
||||
QColor newColor = dialog.selectedColor();
|
||||
if (newColor.isValid() && this->color != newColor)
|
||||
{
|
||||
this->color = newColor;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "../ColorHelper.hpp"
|
||||
#include <QPushButton>
|
||||
class ColorPicker : public QPushButton
|
||||
{
|
||||
|
@ -7,7 +6,7 @@ class ColorPicker : public QPushButton
|
|||
private:
|
||||
QColor color;
|
||||
public:
|
||||
ColorPicker(const QColor& color = ColorHelper::instance().getPrimary1(), QWidget* parent = nullptr);
|
||||
ColorPicker(const QColor& color = QColor::fromRgb(0, 0, 0), QWidget* parent = nullptr);
|
||||
QColor getColor() const;
|
||||
public slots:
|
||||
void onClicked();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QLabel>
|
||||
#include <qtmaterialtextfield.h>
|
||||
|
||||
FillStyleWidget::FillStyleWidget(std::shared_ptr<MaterialStyleFill> fill, QWidget* parent)
|
||||
FillStyleWidget::FillStyleWidget(std::shared_ptr<Renderer::MaterialStyleFill> fill, QWidget* parent)
|
||||
: QWidget(parent), fill(fill)
|
||||
{
|
||||
auto* layout = new QGridLayout(this);
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#include "LayerStyleDialog.h"
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
|
||||
LayerStyleDialog::LayerStyleDialog(
|
||||
LayerStyleContainer& styles,
|
||||
const std::shared_ptr<LayerStyle>& existedStyle,
|
||||
std::shared_ptr<LayerStyle> existedStyle,
|
||||
QWidget* parent
|
||||
) : QDialog(parent), styles(&styles)
|
||||
{
|
||||
dialogLayout = new QGridLayout;
|
||||
auto* dialogLayout = new QVBoxLayout(this);
|
||||
dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->setLayout(dialogLayout);
|
||||
|
||||
|
@ -17,9 +18,11 @@ LayerStyleDialog::LayerStyleDialog(
|
|||
{
|
||||
this->modifyingStyle = existedStyle->clone();
|
||||
|
||||
this->styleContainer = nullptr;
|
||||
this->styleWidget = modifyingStyle->getInputWidget();
|
||||
this->styleWidget->setParent(this);
|
||||
dialogLayout->addWidget(styleWidget, 1, 0);
|
||||
dialogLayout->addWidget(styleWidget);
|
||||
// do something
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -31,12 +34,13 @@ LayerStyleDialog::LayerStyleDialog(
|
|||
typeSelector->addItems(unusedStyleNames);
|
||||
this->modifyingStyle = std::move(styles.makeUnusedStyle(unusedStyleNames[0]));
|
||||
|
||||
dialogLayout->addWidget(typeSelector, 0, 0);
|
||||
|
||||
dialogLayout->addWidget(typeSelector);
|
||||
this->styleContainer = new QGridLayout(this);
|
||||
dialogLayout->addLayout(styleContainer);
|
||||
|
||||
this->styleWidget = this->modifyingStyle->getInputWidget();
|
||||
this->styleWidget->setParent(this);
|
||||
this->dialogLayout->addWidget(styleWidget, 1, 0);
|
||||
this->styleContainer->addWidget(styleWidget);
|
||||
connect(typeSelector, &QComboBox::currentTextChanged,
|
||||
this, &LayerStyleDialog::onStyleTypeSelectorChanged);
|
||||
}
|
||||
|
@ -44,8 +48,7 @@ LayerStyleDialog::LayerStyleDialog(
|
|||
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &LayerStyleDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &LayerStyleDialog::reject);
|
||||
dialogLayout->addWidget(buttonBox, 2, 0);
|
||||
this->adjustSize();
|
||||
dialogLayout->addWidget(buttonBox);
|
||||
}
|
||||
|
||||
void LayerStyleDialog::accept()
|
||||
|
@ -58,14 +61,14 @@ void LayerStyleDialog::onStyleTypeSelectorChanged(const QString& current)
|
|||
{
|
||||
if (this->styleWidget)
|
||||
{
|
||||
this->dialogLayout->removeWidget(this->styleWidget);
|
||||
this->styleContainer->removeWidget(this->styleWidget);
|
||||
this->styleWidget->setParent(nullptr);
|
||||
delete styleWidget;
|
||||
}
|
||||
this->modifyingStyle = std::move(styles->makeUnusedStyle(current));
|
||||
this->styleWidget = this->modifyingStyle->getInputWidget();
|
||||
this->styleWidget->setParent(this);
|
||||
this->dialogLayout->addWidget(styleWidget, 1, 0);
|
||||
this->styleContainer->addWidget(styleWidget, 0, 0, 1, 1);
|
||||
this->styleWidget->adjustSize();
|
||||
this->adjustSize();
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ class LayerStyleDialog : public QDialog
|
|||
Q_OBJECT
|
||||
private:
|
||||
QWidget* styleWidget;
|
||||
QGridLayout* dialogLayout;
|
||||
QGridLayout* styleContainer;
|
||||
LayerStyleContainer* styles;
|
||||
std::unique_ptr<LayerStyle> modifyingStyle;
|
||||
public:
|
||||
LayerStyleDialog(
|
||||
LayerStyleContainer& styles,
|
||||
const std::shared_ptr<LayerStyle>& existedStyle = nullptr,
|
||||
std::shared_ptr<LayerStyle> existedStyle = nullptr,
|
||||
QWidget* parent = nullptr
|
||||
);
|
||||
std::shared_ptr<LayerStyle> layerStyle;
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#include "StrokeStyleWidget.h"
|
||||
#include "ColorPicker.h"
|
||||
#include "../ColorHelper.hpp"
|
||||
#include <qtmaterialraisedbutton.h>
|
||||
#include <limits>
|
||||
#include <array>
|
||||
#include <ranges>
|
||||
#include <utility>
|
||||
#include <lib/qtmaterialstyle.h>
|
||||
|
||||
constexpr int COLUMN_WIDTH = 0;
|
||||
constexpr int COLUMN_COLOR = 1;
|
||||
|
@ -13,27 +10,11 @@ constexpr int COLUMN_METALLIC = 2;
|
|||
constexpr int COLUMN_ROUGHNESS = 3;
|
||||
constexpr int COLUMN_OPERATIONS = 4;
|
||||
|
||||
inline Renderer::Material newMaterial()
|
||||
{
|
||||
return {ColorHelper::instance().getPrimary1()};
|
||||
}
|
||||
|
||||
inline bool isClosedStroke(const std::shared_ptr<MaterialStyleStroke>& stroke)
|
||||
{
|
||||
return stroke->endType == Renderer::StrokeEndType::kClosed;
|
||||
}
|
||||
|
||||
StrokeStyleWidget::StrokeStyleWidget(
|
||||
const std::shared_ptr<MaterialStyleStroke>& stroke,
|
||||
std::shared_ptr<MaterialStyleStroke> stroke,
|
||||
QWidget* parent
|
||||
) : QWidget(parent), stroke(stroke)
|
||||
{
|
||||
auto& materialMap = radialStroke(stroke)->materialMap;
|
||||
if (materialMap.empty())
|
||||
{
|
||||
materialMap[1.f] = newMaterial();
|
||||
}
|
||||
|
||||
auto* viewLayout = new QVBoxLayout(this);
|
||||
this->setLayout(viewLayout);
|
||||
|
||||
|
@ -44,20 +25,13 @@ StrokeStyleWidget::StrokeStyleWidget(
|
|||
|
||||
strokeProperties->setLayout(strokePropertiesLayout);
|
||||
strokePropertiesLayout->addWidget(enableGradual);
|
||||
if (!isClosedStroke(stroke))
|
||||
{
|
||||
strokePropertiesLayout->addWidget(endTypeBox);
|
||||
}
|
||||
strokePropertiesLayout->addWidget(endTypeBox);
|
||||
|
||||
viewLayout->addWidget(strokeProperties);
|
||||
viewLayout->addWidget(widthField);
|
||||
|
||||
initTable(radialStroke(stroke));
|
||||
initTable(std::dynamic_pointer_cast<Renderer::StrokeRadialGradient>(stroke->materialStroke));
|
||||
viewLayout->addWidget(strokeTable);
|
||||
|
||||
initAddButton();
|
||||
viewLayout->addWidget(addButton);
|
||||
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
|
@ -70,23 +44,30 @@ void StrokeStyleWidget::initStrokeSettings()
|
|||
radialStroke(this->stroke)->gradual = checked;
|
||||
});
|
||||
|
||||
if (!isClosedStroke(stroke))
|
||||
{
|
||||
this->endTypeBox = new QComboBox(this);
|
||||
for (const auto& displayName : MaterialStyleStroke::strokeEndTypeNames | std::views::keys)
|
||||
#define endTypeBoxLabel(start, end) QStringLiteral(start##" -> "##end)
|
||||
this->endTypeBox = new QComboBox(this);
|
||||
endTypeBox->addItem(endTypeBoxLabel("圆头", "圆头")); // kRound
|
||||
endTypeBox->addItem(endTypeBoxLabel("平头", "圆头")); // kFlatRound
|
||||
endTypeBox->addItem(endTypeBoxLabel("圆头", "平头")); // kRoundFlat
|
||||
endTypeBox->addItem(endTypeBoxLabel("平头", "平头")); // kFlat
|
||||
endTypeBox->setCurrentIndex(static_cast<int>(this->stroke->endType));
|
||||
connect(endTypeBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
switch (index)
|
||||
{
|
||||
endTypeBox->addItem(displayName);
|
||||
case 0:
|
||||
this->stroke->endType = Renderer::StrokeEndType::kRound;
|
||||
break;
|
||||
case 1:
|
||||
this->stroke->endType = Renderer::StrokeEndType::kFlatRound;
|
||||
break;
|
||||
case 2:
|
||||
this->stroke->endType = Renderer::StrokeEndType::kRoundFlat;
|
||||
break;
|
||||
case 3:
|
||||
this->stroke->endType = Renderer::StrokeEndType::kFlat;
|
||||
break;
|
||||
}
|
||||
endTypeBox->setCurrentIndex(static_cast<int>(this->stroke->endType));
|
||||
connect(endTypeBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
const auto& [displayName, endType] = MaterialStyleStroke::strokeEndTypeNames[index];
|
||||
this->stroke->endType = endType;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this->endTypeBox = nullptr;
|
||||
}
|
||||
});
|
||||
|
||||
this->widthField = new QtMaterialTextField(this);
|
||||
widthField->setLabel(QStringLiteral("本侧描边宽度"));
|
||||
|
@ -102,12 +83,13 @@ void StrokeStyleWidget::initStrokeSettings()
|
|||
});
|
||||
}
|
||||
|
||||
void StrokeStyleWidget::initTable(const std::shared_ptr<Renderer::StrokeRadialGradient>& materialStroke)
|
||||
// TODO: 新增时参数校验
|
||||
void StrokeStyleWidget::initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke)
|
||||
{
|
||||
this->strokeTable = new QTableWidget(this);
|
||||
strokeTable->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
|
||||
strokeTable->setColumnCount(5);
|
||||
strokeTable->setRowCount(materialStroke->materialMap.size());
|
||||
strokeTable->setRowCount(materialStroke->materialMap.size() + 1);
|
||||
QStringList headers;
|
||||
headers << QStringLiteral("离心距离占比")
|
||||
<< QStringLiteral("颜色")
|
||||
|
@ -115,45 +97,44 @@ void StrokeStyleWidget::initTable(const std::shared_ptr<Renderer::StrokeRadialGr
|
|||
<< QStringLiteral("粗糙度")
|
||||
<< QStringLiteral("其他操作");
|
||||
strokeTable->setHorizontalHeaderLabels(headers);
|
||||
strokeTable->setMinimumHeight(strokeTable->rowHeight(0) * 5);
|
||||
strokeTable->setMinimumWidth(strokeTable->sizeHint().width());
|
||||
int row = 0;
|
||||
// 内容
|
||||
for (auto& [width, material] : std::views::reverse(materialStroke->materialMap))
|
||||
for (auto & strokePair : materialStroke->materialMap)
|
||||
{
|
||||
setTableRow(row, width, material);
|
||||
setTableRow(row, strokePair.first, strokePair.second);
|
||||
row++;
|
||||
}
|
||||
connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged);
|
||||
connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged);
|
||||
}
|
||||
|
||||
void StrokeStyleWidget::initAddButton()
|
||||
{
|
||||
this->addButton = new QtMaterialRaisedButton("+", strokeTable);
|
||||
addButton->setFixedHeight(this->strokeTable->rowHeight(0));
|
||||
addButton->setBackgroundColor(ColorHelper::instance().getPrimary1());
|
||||
connect(addButton, &QtMaterialRaisedButton::clicked, [this] {
|
||||
// 新增按钮
|
||||
QtMaterialRaisedButton* addButton = new QtMaterialRaisedButton("+", strokeTable);
|
||||
addButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1"));
|
||||
strokeTable->setSpan(row, 0, 1, 5);
|
||||
strokeTable->setCellWidget(row, 0, addButton);
|
||||
strokeTable->setMinimumHeight(strokeTable->rowHeight(row) * 5);
|
||||
strokeTable->setMinimumWidth(strokeTable->sizeHint().width());
|
||||
addButton->setFixedHeight(strokeTable->rowHeight(row));
|
||||
connect(addButton, &QtMaterialRaisedButton::clicked, [this]() {
|
||||
handlingRowInsert = true;
|
||||
auto& materialMap = radialStroke(this->stroke)->materialMap;
|
||||
float newWidth;
|
||||
if (materialMap.empty())
|
||||
auto materialMap = &(radialStroke(this->stroke)->materialMap);
|
||||
float newWidth = 0;
|
||||
if (materialMap->size() == 0)
|
||||
{
|
||||
newWidth = 1.f;
|
||||
newWidth = 0.1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto firstPair = materialMap.begin();
|
||||
newWidth = firstPair->first / 2;
|
||||
auto lastPair = materialMap->rbegin();
|
||||
newWidth = lastPair->first + 0.01;
|
||||
}
|
||||
const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1());
|
||||
materialMap[newWidth] = newMaterial;
|
||||
const int newRow = this->strokeTable->rowCount();
|
||||
Renderer::Material newMaterial(QColor::fromRgb(0, 0, 0));
|
||||
(*materialMap)[newWidth] = newMaterial;
|
||||
int newRow = this->strokeTable->rowCount() - 1;
|
||||
this->strokeTable->insertRow(newRow);
|
||||
setTableRow(newRow, newWidth, materialMap[newWidth]);
|
||||
setTableRow(newRow, newWidth, (*materialMap)[newWidth]);
|
||||
this->strokeTable->update();
|
||||
handlingRowInsert = false;
|
||||
});
|
||||
connect(strokeTable, &QTableWidget::currentItemChanged, this, &StrokeStyleWidget::onCurrentItemChanged);
|
||||
connect(strokeTable, &QTableWidget::cellChanged, this, &StrokeStyleWidget::onCellChanged);
|
||||
}
|
||||
|
||||
void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& material)
|
||||
|
@ -162,14 +143,14 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma
|
|||
widthItem->setData(Qt::EditRole, width);
|
||||
strokeTable->setItem(row, COLUMN_WIDTH, widthItem);
|
||||
|
||||
QColor* colorPtr = &material.color;
|
||||
QColor* colorPtr = &(material.color);
|
||||
auto* colorItem = new QTableWidgetItem;
|
||||
colorItem->setData(Qt::DisplayRole, *colorPtr);
|
||||
strokeTable->setItem(row, COLUMN_COLOR, colorItem);
|
||||
auto* colorPicker = new ColorPicker(*colorPtr, strokeTable);
|
||||
strokeTable->setCellWidget(row, COLUMN_COLOR, colorPicker);
|
||||
connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) {
|
||||
*colorPtr = std::move(color);
|
||||
*colorPtr = color;
|
||||
this->strokeTable->update();
|
||||
});
|
||||
|
||||
|
@ -182,10 +163,10 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma
|
|||
strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem);
|
||||
|
||||
auto* removeButton = new QtMaterialRaisedButton("-", strokeTable);
|
||||
removeButton->setBackgroundColor(ColorHelper::instance().getPrimary1());
|
||||
removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1"));
|
||||
removeButton->setFixedSize(20, 20);
|
||||
strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton);
|
||||
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row] {
|
||||
connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() {
|
||||
radialStroke(this->stroke)->materialMap.erase(this->strokeTable->item(row, COLUMN_WIDTH)->text().toFloat());
|
||||
this->strokeTable->removeRow(row);
|
||||
});
|
||||
|
@ -194,7 +175,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma
|
|||
void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous)
|
||||
{
|
||||
if (!current) return;
|
||||
const int column = current->column();
|
||||
int column = current->column();
|
||||
if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS)
|
||||
{
|
||||
this->currentItemValue = current->data(Qt::EditRole);
|
||||
|
@ -204,27 +185,23 @@ void StrokeStyleWidget::onCurrentItemChanged(QTableWidgetItem* current, QTableWi
|
|||
void StrokeStyleWidget::onCellChanged(int row, int column)
|
||||
{
|
||||
if (handlingRowInsert) return;
|
||||
const auto changedItem = strokeTable->item(row, column);
|
||||
const auto changedItemValue = changedItem->text().toFloat();
|
||||
auto changedItem = strokeTable->item(row, column);
|
||||
auto changedItemValue = changedItem->text().toFloat();
|
||||
if (changedItemValue < 0 || 1 < changedItemValue)
|
||||
{
|
||||
changedItem->setData(Qt::EditRole, this->currentItemValue.toFloat());
|
||||
return;
|
||||
}
|
||||
const auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->data(Qt::EditRole).toFloat();
|
||||
auto changedWidth = strokeTable->item(row, COLUMN_WIDTH)->data(Qt::EditRole).toFloat();
|
||||
switch (column)
|
||||
{
|
||||
case COLUMN_WIDTH:
|
||||
{
|
||||
float oldWidth = this->currentItemValue.toFloat();
|
||||
auto node = radialStroke(stroke)->materialMap.extract(oldWidth);
|
||||
if (node.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
node.key() = changedWidth;
|
||||
radialStroke(stroke)->materialMap.insert(std::move(node));
|
||||
strokeTable->sortItems(COLUMN_WIDTH, Qt::DescendingOrder);
|
||||
strokeTable->sortItems(COLUMN_WIDTH);
|
||||
break;
|
||||
}
|
||||
case COLUMN_METALLIC:
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <QComboBox>
|
||||
#include <qtmaterialtextfield.h>
|
||||
#include <qtmaterialcheckbox.h>
|
||||
#include <qtmaterialraisedbutton.h>
|
||||
class StrokeStyleWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -17,17 +16,15 @@ private:
|
|||
QComboBox* endTypeBox;
|
||||
QtMaterialTextField* widthField;
|
||||
QTableWidget* strokeTable;
|
||||
QtMaterialRaisedButton* addButton;
|
||||
bool handlingRowInsert = false;
|
||||
|
||||
void initStrokeSettings();
|
||||
void initTable(const std::shared_ptr<Renderer::StrokeRadialGradient>& materialStroke);
|
||||
void initAddButton();
|
||||
void initTable(std::shared_ptr<Renderer::StrokeRadialGradient> materialStroke);
|
||||
void setTableRow(int row, float width, Renderer::Material& material);
|
||||
|
||||
public:
|
||||
StrokeStyleWidget(const std::shared_ptr<MaterialStyleStroke>& stroke, QWidget* parent = nullptr);
|
||||
std::shared_ptr<MaterialStyleStroke> stroke;
|
||||
StrokeStyleWidget(std::shared_ptr<Renderer::MaterialStyleStroke> stroke, QWidget* parent = nullptr);
|
||||
std::shared_ptr<Renderer::MaterialStyleStroke> stroke;
|
||||
|
||||
protected slots:
|
||||
void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous);
|
||||
|
|
|
@ -25,7 +25,6 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
treeWidget->refresh();
|
||||
previewWindow->refresh();
|
||||
};
|
||||
connect(previewWindow, &PreviewWindow::triggerCentralRefresh, centralRefresh);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh);
|
||||
connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh);
|
||||
connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh);
|
||||
|
@ -34,15 +33,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex);
|
||||
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||
connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged);
|
||||
//connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange);
|
||||
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
|
||||
// &EditorWidgetItem::triggerRefreshPreview);
|
||||
// connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
|
||||
// &EditorWidgetItem::triggerRefreshPreview);
|
||||
//connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||
// connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
|
||||
&EditorWidgetItem::triggerRefreshPreview);
|
||||
connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this,
|
||||
&EditorWidgetItem::triggerRefreshPreview);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||
connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh);
|
||||
// &EditorWidget::triggerRefreshPreview);
|
||||
// test
|
||||
QFile settingFile;
|
||||
|
@ -74,10 +73,9 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
this->projectName = source.value("project-name").toString();
|
||||
qDebug() << this->backgroundColor;
|
||||
qDebug() << this->projectName;
|
||||
QTimer::singleShot(300, this, [this, centralRefresh]() {
|
||||
QTimer::singleShot(300, this, [this]() {
|
||||
handleBackgroundColorChange(this->backgroundColor);
|
||||
handleProjectNameChange(this->projectName);
|
||||
centralRefresh();
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ bool SimpleElement::isClosed() const
|
|||
|
||||
void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles)
|
||||
{
|
||||
sourceLayer->paint(painter, transform, true);
|
||||
sourceLayer->paint(painter, transform);
|
||||
}
|
||||
|
||||
bool GroupElement::isClosed() const
|
||||
|
|
|
@ -13,21 +13,8 @@ LayerWrapper *LayerManager::getRoot() const
|
|||
}
|
||||
void LayerManager::paint(QPainter *painter, QSize size,LayerWrapper* selecetedLayer) const
|
||||
{
|
||||
painter->save();
|
||||
root->getCache();
|
||||
root->paint(painter);
|
||||
painter->restore();
|
||||
painter->save();
|
||||
// painter->setBrush(QBrush(Qt::white));
|
||||
//painter->setCompositionMode(QPainter::CompositionMode_Difference);
|
||||
if (selecetedLayer != nullptr)
|
||||
{
|
||||
painter->setPen(QPen(Qt::gray, 2, Qt::DashLine));
|
||||
selecetedLayer->paintVisualBounding(painter);
|
||||
//painter->setPen(QPen(Qt::gray, 2, Qt::DashDotLine));
|
||||
//selecetedLayer->paintVisualBounding(painter);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
bool LayerManager::singleSelectedCheck() const
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "./EditorWidgetComponent/StrokeStyleWidget.h"
|
||||
#include "./EditorWidgetComponent/FillStyleWidget.h"
|
||||
#include "./util/EncodeUtil.hpp"
|
||||
#include "../ColorHelper.hpp"
|
||||
#include <qtmaterialcheckbox.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
@ -207,11 +206,11 @@ bool LayerStyleContainer::dropStyle(const QString& styleName)
|
|||
|
||||
float LayerStyleContainer::boundingBoxAffectValue() const {
|
||||
float maxLineWidth = 0;
|
||||
const auto strokeStyle = styles.find(StrokeElementLayerStyle::displayName());
|
||||
if (strokeStyle != styles.end())
|
||||
const auto strokeStyle = styles.at(StrokeElementLayerStyle::displayName());
|
||||
if (strokeStyle != nullptr)
|
||||
{
|
||||
if (const auto strokeElementLayerStyle =
|
||||
std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle->second);
|
||||
std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle);
|
||||
strokeElementLayerStyle != nullptr)
|
||||
{
|
||||
const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first;
|
||||
|
@ -248,18 +247,18 @@ std::unique_ptr<StrokeElementLayerStyle> StrokeElementLayerStyle::fromJson(const
|
|||
return ptr;
|
||||
}
|
||||
|
||||
StrokeElementLayerStyle::StrokeElementLayerStyle(bool isClosed)
|
||||
StrokeElementLayerStyle::StrokeElementLayerStyle()
|
||||
{
|
||||
const auto materialMap = std::map<float, Renderer::Material>();
|
||||
this->strokePair.first = std::make_shared<MaterialStyleStroke>(
|
||||
7,
|
||||
Renderer::StrokeType::kLeftSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat,
|
||||
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
|
||||
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||
);
|
||||
|
||||
this->strokePair.second = std::make_shared<MaterialStyleStroke>(
|
||||
7,
|
||||
Renderer::StrokeType::kRightSide, isClosed ? Renderer::StrokeEndType::kClosed : Renderer::StrokeEndType::kFlat,
|
||||
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
|
||||
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||
);
|
||||
|
||||
|
@ -537,7 +536,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater
|
|||
if (!fillMaterialStyle)
|
||||
{
|
||||
this->fillMaterialStyle = std::make_shared<MaterialStyleFill>(
|
||||
std::make_shared<Renderer::FillPlain>(ColorHelper::instance().getPrimary1())
|
||||
std::make_shared<Renderer::FillPlain>(Renderer::Material(QColor::fromRgb(0, 0, 0)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
STYLE_NAME("Ãè±ß", "stroke")
|
||||
static std::unique_ptr<StrokeElementLayerStyle> fromJson(const QJsonObject& json);
|
||||
|
||||
StrokeElementLayerStyle(bool isClosed);
|
||||
StrokeElementLayerStyle();
|
||||
StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right = nullptr);
|
||||
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
|
||||
~StrokeElementLayerStyle() override = default;
|
||||
|
@ -88,23 +88,17 @@ public:
|
|||
class LayerStyleContainer : public Renderer::ElementStyle
|
||||
{
|
||||
using DisplayNameWithSupplier = std::map<QString, std::function<std::unique_ptr<LayerStyle>()>>;
|
||||
|
||||
private:
|
||||
inline const static DisplayNameWithSupplier commonStyles = { };
|
||||
inline const static DisplayNameWithSupplier closedOnlyStyles = {
|
||||
{
|
||||
FillElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<FillElementLayerStyle>(); }
|
||||
},
|
||||
{
|
||||
StrokeElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<StrokeElementLayerStyle>(true); }
|
||||
}
|
||||
};
|
||||
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { {
|
||||
|
||||
inline const static DisplayNameWithSupplier commonStyles = { {
|
||||
StrokeElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<StrokeElementLayerStyle>(false); }
|
||||
[] { return std::make_unique<StrokeElementLayerStyle>(); }
|
||||
} };
|
||||
inline const static DisplayNameWithSupplier closedOnlyStyles = { {
|
||||
FillElementLayerStyle::displayName(),
|
||||
[] { return std::make_unique<FillElementLayerStyle>(); }
|
||||
} };
|
||||
inline const static DisplayNameWithSupplier unclosedOnlyStyles = { };
|
||||
|
||||
DisplayNameWithSupplier unusedStyles;
|
||||
DisplayNameWithSupplier usedStyles;
|
||||
|
|
|
@ -47,7 +47,6 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
|
|||
transformJson.value("scale").toObject().value("y").toDouble()};
|
||||
property.rotation = {transformJson.value("rotation").toDouble()};
|
||||
selected = false;
|
||||
hidden = false;
|
||||
}
|
||||
|
||||
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
|
||||
|
@ -200,7 +199,6 @@ void FolderLayerWrapper::delSelf() {
|
|||
QTreeWidgetItem* LayerWrapper::getQTreeItem()
|
||||
{
|
||||
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
|
||||
this->qTreeWidgetItem->setCheckState(0, Qt::Checked);
|
||||
return this->qTreeWidgetItem;
|
||||
}
|
||||
|
||||
|
@ -282,34 +280,31 @@ int FolderLayerWrapper::getReferencedBy()const
|
|||
return -1;
|
||||
}
|
||||
|
||||
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
|
||||
void LayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
|
||||
{
|
||||
// if (this->selected)
|
||||
// {
|
||||
// painter->save();
|
||||
//painter->setPen(QPen(Qt::red, 2));
|
||||
//painter->setTransform(transform);
|
||||
//painter->drawRect(this->cache.getBoundingRect());
|
||||
//painter->restore();
|
||||
// }
|
||||
if (!ignoreSelected && this->selected)
|
||||
{
|
||||
painter->save();
|
||||
painter->setTransform(transform, ignoreSelected);
|
||||
painter->setPen(QPen(Qt::gray, 2));
|
||||
painter->setPen(Qt::DashLine);
|
||||
painter->drawRect(cache.getBoundingRect());
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
|
||||
void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
|
||||
{
|
||||
if (hidden && !force)
|
||||
return;
|
||||
LayerWrapper::paint(painter, transform, force);
|
||||
LayerWrapper::paint(painter, transform, ignoreSelected);
|
||||
transform = property.transform * transform;
|
||||
//qDebug() << transform;
|
||||
for (auto& child : children)
|
||||
child->paint(painter, transform, force);
|
||||
child->paint(painter, transform, ignoreSelected);
|
||||
}
|
||||
|
||||
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force)
|
||||
void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected)
|
||||
{
|
||||
if (hidden && !force)
|
||||
return;
|
||||
LayerWrapper::paint(painter, transform, force);
|
||||
LayerWrapper::paint(painter, transform, ignoreSelected);
|
||||
transform = property.transform * transform;
|
||||
//qDebug() << transform;
|
||||
if (wrappedElement != nullptr)
|
||||
|
@ -352,12 +347,11 @@ void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable
|
|||
|
||||
void LayerWrapper::refreshTreeItem()
|
||||
{
|
||||
hidden = qTreeWidgetItem->checkState(0) == Qt::Unchecked;
|
||||
|
||||
}
|
||||
|
||||
void LeafLayerWrapper::refreshTreeItem()
|
||||
{
|
||||
LayerWrapper::refreshTreeItem();
|
||||
if (typeid(*wrappedElement) == typeid(GroupElement))
|
||||
{
|
||||
this->qTreeWidgetItem->setText(0, "@ " + this->property.name);
|
||||
|
@ -372,7 +366,6 @@ void LeafLayerWrapper::refreshTreeItem()
|
|||
|
||||
void FolderLayerWrapper::refreshTreeItem()
|
||||
{
|
||||
LayerWrapper::refreshTreeItem();
|
||||
for (auto& child : this->children) {
|
||||
child->refreshTreeItem();
|
||||
}
|
||||
|
@ -436,20 +429,3 @@ bool LayerWrapper::canApplyStyles() const
|
|||
{
|
||||
return typeid(*this) == typeid(LeafLayerWrapper) && !referencingGroupElement();
|
||||
}
|
||||
|
||||
void LayerWrapper::paintVisualBounding(QPainter* painter) const
|
||||
{
|
||||
if (hidden)
|
||||
return;
|
||||
QTransform transform;
|
||||
auto layer = this->parent;
|
||||
while (layer != nullptr)
|
||||
{
|
||||
transform = transform * layer->property.transform;
|
||||
layer = layer->parent;
|
||||
}
|
||||
painter->save();
|
||||
painter->setTransform(transform);
|
||||
painter->drawRect(cache.getBoundingRect());
|
||||
painter->restore();
|
||||
}
|
|
@ -37,7 +37,6 @@ class LayerWrapper
|
|||
public:
|
||||
QTreeWidgetItem* qTreeWidgetItem;
|
||||
bool selected;
|
||||
bool hidden;
|
||||
struct SimpleProperty
|
||||
{
|
||||
QString name = "";
|
||||
|
@ -59,7 +58,7 @@ class LayerWrapper
|
|||
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
|
||||
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
|
||||
LayerWrapper() = default;
|
||||
virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool force = false);
|
||||
virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool ignoreSelected = false);
|
||||
// TODO : export Function
|
||||
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
||||
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only
|
||||
|
@ -75,7 +74,6 @@ class LayerWrapper
|
|||
virtual size_t referencedCount(bool excludeSelf = false) const;
|
||||
virtual bool deleteable(bool excludeSubTree = false) const;
|
||||
virtual bool referencingGroupElement() const;
|
||||
virtual void paintVisualBounding(QPainter* painter) const;
|
||||
bool canApplyStyles() const;
|
||||
};
|
||||
|
||||
|
@ -99,7 +97,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
QTreeWidgetItem* getQTreeItem() override;
|
||||
QJsonObject toJson() const override;
|
||||
int getReferencedBy()const;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
|
||||
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
|
||||
void refreshTreeItem() override;
|
||||
size_t referencedCount(bool excludeSelf = false) const override;
|
||||
|
@ -117,7 +115,7 @@ class LeafLayerWrapper : public LayerWrapper
|
|||
void refresh(LayerWrapper* layer = nullptr) override;
|
||||
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
|
||||
QJsonObject toJson() const override;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override;
|
||||
void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override;
|
||||
void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
|
||||
QTreeWidgetItem* getQTreeItem() override;
|
||||
void refreshTreeItem() override;
|
||||
|
|
|
@ -78,8 +78,7 @@ PixelPath PixelPath::trans(QTransform& mat)const
|
|||
painter.setTransform(mat);
|
||||
painter.drawPixmap(0, 0, pixmap);
|
||||
result.painterPath.addPath(this->painterPath);
|
||||
result.painterPath = mat.map(result.painterPath);
|
||||
result.boundingRect = result.painterPath.boundingRect();
|
||||
result.boundingRect = mat.mapRect(boundingRect);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "PreviewWindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||
{
|
||||
|
@ -85,17 +84,7 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
|
|||
int dx = event->x() - m_lastPos.x();
|
||||
int dy = event->y() - m_lastPos.y();
|
||||
if (currentLayer != nullptr) {
|
||||
if (QApplication::keyboardModifiers() == Qt::ControlModifier && (event->buttons() & Qt::LeftButton))
|
||||
{
|
||||
currentLayer->property.scale.setX(std::max(0.0, currentLayer->property.scale.x() + dx / 50.0));
|
||||
currentLayer->property.scale.setY(std::max(0.0, currentLayer->property.scale.y() + dy / 50.0));
|
||||
}
|
||||
else if (QApplication::keyboardModifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && (event->buttons() & Qt::LeftButton))
|
||||
{
|
||||
currentLayer->property.scale.setX(std::max(0.0, currentLayer->property.scale.x() * (1.0 + dx / 50.0)));
|
||||
currentLayer->property.scale.setY(std::max(0.0, currentLayer->property.scale.y() * (1.0 + dx / 50.0)));
|
||||
}
|
||||
else if (event->buttons() & Qt::LeftButton) {
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
// 如果按下的是左键,那么平移图形
|
||||
currentLayer->property.offset.setX(currentLayer->property.offset.x() + dx);
|
||||
currentLayer->property.offset.setY(currentLayer->property.offset.y() + dy);
|
||||
|
@ -111,18 +100,19 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
|
|||
auto index = -1;
|
||||
if (typeid(*layer) == typeid(FolderLayerWrapper))
|
||||
index = dynamic_cast<FolderLayerWrapper*>(layer)->getReferencedBy();
|
||||
if (index != -1)
|
||||
emit refreshElementPreviewByIndex(index);
|
||||
layer = layer->getParent();
|
||||
}
|
||||
}
|
||||
// 更新上一次的位置
|
||||
emit triggerCentralRefresh();
|
||||
m_lastPos = event->pos();
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void PreviewWindow::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
//emit layerInfoChanged();
|
||||
emit layerInfoChanged();
|
||||
}
|
||||
|
||||
void PreviewWindow::setBackgroundColor(QColor color)
|
||||
|
|
|
@ -46,5 +46,4 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
|
|||
void layerInfoChanged();
|
||||
void refreshElementPreview(GraphicElement*);
|
||||
void refreshElementPreviewByIndex(int);
|
||||
void triggerCentralRefresh();
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "EditorSettingWidget.h"
|
||||
#include "../ColorHelper.hpp"
|
||||
#include <QPushButton>
|
||||
#include <QColorDialog>
|
||||
#include <QInputDialog>
|
||||
|
||||
EditorSettingWidget::EditorSettingWidget(QWidget* parent)
|
||||
|
@ -8,7 +8,7 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent)
|
|||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.backgroundColorButton, &QPushButton::clicked, this, [this]() {
|
||||
QColor color = ColorHelper::execColorDialog(Qt::white, this, QString::fromLocal8Bit("Ñ¡Ôñ±³¾°ÑÕÉ«"));
|
||||
QColor color = QColorDialog::getColor(Qt::white, this, QString::fromLocal8Bit("Ñ¡Ôñ±³¾°ÑÕÉ«"));
|
||||
if (color.isValid())
|
||||
{
|
||||
emit backgroundColorChanged(color);
|
||||
|
|
|
@ -21,11 +21,12 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
{
|
||||
while (this->layout()->count() > 0 && (item = this->layout()->takeAt(0)) != nullptr)
|
||||
{
|
||||
item->widget()->deleteLater();
|
||||
delete item;
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
delete this->layout();
|
||||
}
|
||||
|
||||
QFormLayout *layout = new QFormLayout();
|
||||
layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
|
||||
if (this->displayLayer == nullptr)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include "./EditorWidgetComponent/LayerCreateWidget.h"
|
||||
#include <QTimer>
|
||||
|
||||
LayerTreeWidget::LayerTreeWidget(QWidget *parent)
|
||||
{
|
||||
|
@ -27,10 +26,6 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
|
|||
}
|
||||
emit triggerCentralRefresh();
|
||||
});
|
||||
connect(this, &QTreeWidget::itemChanged, this, [=]() {
|
||||
emit triggerCentralRefresh();
|
||||
});
|
||||
|
||||
// connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <queue>
|
||||
|
||||
using Renderer::Painting;
|
||||
using Renderer::BaseElement;
|
||||
using Renderer::Element;
|
||||
using Renderer::ElementTransform;
|
||||
using Renderer::BaseElement;
|
||||
using glm::bvec2;
|
||||
|
@ -18,119 +18,231 @@ using std::queue;
|
|||
const double PaintingUtil::pi = acos(-1);
|
||||
|
||||
struct LayerNode {
|
||||
LayerWrapper* nowLayer;
|
||||
QTransform transfrom;
|
||||
LayerWrapper* nowLayer;
|
||||
QTransform transfrom;
|
||||
};
|
||||
|
||||
QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) {
|
||||
QFile jsonFile(jsonFilePath);
|
||||
qDebug() << jsonFilePath;
|
||||
jsonFile.open(QFile::ReadOnly);
|
||||
QByteArray fileContent = jsonFile.readAll().trimmed();
|
||||
jsonFile.close();
|
||||
QJsonParseError jError;
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(fileContent, &jError));
|
||||
return jsonDoc.object();
|
||||
QFile jsonFile(jsonFilePath);
|
||||
jsonFile.open(QFile::ReadOnly);
|
||||
QByteArray fileContent = jsonFile.readAll().trimmed();
|
||||
jsonFile.close();
|
||||
QJsonParseError jError;
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(fileContent, &jError));
|
||||
return jsonDoc.object();
|
||||
}
|
||||
|
||||
Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
|
||||
Painting painting;
|
||||
glm::bvec2 flip(0, 0);
|
||||
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
||||
qDebug() << jsonObj;
|
||||
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, Renderer::ElementRenderer::instance());
|
||||
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
|
||||
//qDebug() << elementManager->toJson();
|
||||
//qDebug() << layerManager->toJson();
|
||||
Painting painting;
|
||||
glm::bvec2 flip(0, 0);
|
||||
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
||||
qDebug() << jsonObj;
|
||||
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, Renderer::ElementRenderer::instance());
|
||||
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
|
||||
//qDebug() << elementManager->toJson();
|
||||
//qDebug() << layerManager->toJson();
|
||||
//qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath;
|
||||
//qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
|
||||
//qDebug() << elementManager->toJson();
|
||||
//qDebug() << layerManager->toJson();
|
||||
//qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath;
|
||||
//qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
|
||||
queue<LayerNode> layerQueue;
|
||||
LayerWrapper* root = layerManager->getRoot();
|
||||
root->getCache();
|
||||
//double maxLineWidth = getMaxLineWidth(root);
|
||||
layerQueue.push({ root, root->property.transform });
|
||||
while (!layerQueue.empty()) {
|
||||
auto layerNode = layerQueue.front();
|
||||
layerQueue.pop();
|
||||
FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, layerNode.transfrom, painting);
|
||||
if (nowLayer != nullptr) {
|
||||
for (auto sonLayer : nowLayer->children) {
|
||||
layerQueue.push({ sonLayer.get(), layerNode.transfrom });
|
||||
}
|
||||
}
|
||||
}
|
||||
//qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
|
||||
queue<LayerNode> layerQueue;
|
||||
LayerWrapper* root = layerManager->getRoot();
|
||||
root->getCache();
|
||||
double maxLineWidth = getMaxLineWidth(root);
|
||||
layerQueue.push({ root, root->property.transform });
|
||||
while (!layerQueue.empty()) {
|
||||
auto layerNode = layerQueue.front();
|
||||
layerQueue.pop();
|
||||
FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, maxLineWidth, layerNode.transfrom, painting);
|
||||
if (nowLayer != nullptr) {
|
||||
for (auto sonLayer : nowLayer->children) {
|
||||
layerQueue.push({ sonLayer.get(), layerNode.transfrom});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return painting;
|
||||
return painting;
|
||||
}
|
||||
|
||||
FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, Painting& painting) {
|
||||
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
|
||||
FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, double& maxLineWidth, QTransform& transform, Painting& painting) {
|
||||
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
|
||||
|
||||
transform = nowLayer->property.transform * transform;
|
||||
transform = nowLayer->property.transform * transform;
|
||||
|
||||
if (leafLayer != nullptr) {
|
||||
if (leafLayer != nullptr) {
|
||||
|
||||
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
|
||||
if (wrapperElement != nullptr) {
|
||||
transform = wrapperElement->sourceLayer->property.transform * transform;
|
||||
return wrapperElement->sourceLayer;
|
||||
}
|
||||
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
|
||||
if (wrapperElement != nullptr) {
|
||||
transform = wrapperElement->sourceLayer->property.transform * transform;
|
||||
return wrapperElement->sourceLayer;
|
||||
}
|
||||
|
||||
PixelPath pixelPath = nowLayer->getCache();
|
||||
QPainterPath painterPath = pixelPath.getPainterPath();
|
||||
QRectF bound = painterPath.boundingRect();
|
||||
//qDebug() << leafLayer<<"------" << painterPath;
|
||||
// transform to -1£¬ 1
|
||||
QTransform trans;
|
||||
double maxLen = std::max(bound.width(), bound.height());
|
||||
qDebug() << maxLen << bound;
|
||||
trans.scale(1 / maxLen, 1 / maxLen);
|
||||
trans.translate(-bound.center().x(), -bound.center().y());
|
||||
PixelPath pixelPath = nowLayer->getCache();
|
||||
QPainterPath painterPath = pixelPath.getPainterPath();
|
||||
QRectF bound = painterPath.boundingRect();
|
||||
//qDebug() << leafLayer<<"------" << painterPath;
|
||||
//qDebug() << transform;
|
||||
//Element element;
|
||||
//ElementTransform elementTrans;
|
||||
//element.ratio = bound.width() / bound.height();
|
||||
// transform to initial painterPath
|
||||
// transfrom to -1£¬ 1
|
||||
QTransform trans;
|
||||
trans.translate(-centerX, -centerY)
|
||||
.scale(1 / nowLayer->property.scale.x(), 1 / nowLayer->property.scale.y())
|
||||
.rotate(-nowLayer->property.rotation)
|
||||
.translate(centerX, centerY)
|
||||
.translate(-nowLayer->property.offset.x(), -nowLayer->property.offset.y());
|
||||
QPainterPath painterPath = trans.map(pixelPath.getPainterPath());
|
||||
// transfrom to -1£¬ 1
|
||||
QTransform trans;
|
||||
double maxLen = std::max(bound.width(), bound.height()) + maxLineWidth * 2;
|
||||
qDebug() << maxLen << bound;
|
||||
trans.scale(1 / maxLen, 1 / maxLen);
|
||||
trans.translate(-bound.center().x(), -bound.center().y());
|
||||
|
||||
painterPath = trans.map(painterPath);
|
||||
shared_ptr<vector<vector<Renderer::Point> >> contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(painterPath));
|
||||
QSize screenSize = QSize(1024, 1024);
|
||||
qDebug() << trans.map(painterPath);
|
||||
shared_ptr<vector<vector<Renderer::Point> >> contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(trans.map(painterPath)));
|
||||
QSize screenSize = QSize(1024, 1024);
|
||||
//element.style = std::make_shared<Renderer::ElementStyleStrokeDemo>(0.06);
|
||||
|
||||
ElementTransform elementTransform;
|
||||
transform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1);
|
||||
|
||||
auto baseStyles = leafLayer->styles.toBaseStyles();
|
||||
Renderer::BaseElement element;
|
||||
element.contour = contour;
|
||||
for (auto& baseStyle : baseStyles) {
|
||||
double lineWidth = 0;
|
||||
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
|
||||
auto material = std::static_pointer_cast<MaterialStyleStroke>(baseStyle.material);
|
||||
material->halfWidth /= maxLen;
|
||||
lineWidth = material->halfWidth;
|
||||
qDebug() << material->halfWidth;
|
||||
}
|
||||
QPainterPathStroker stroker;
|
||||
stroker.setWidth(lineWidth);
|
||||
stroker.setCapStyle(Qt::RoundCap);
|
||||
QPainterPath strokePath = stroker.createStroke(painterPath);
|
||||
auto rect = transform.map(strokePath).boundingRect();
|
||||
elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
|
||||
qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z;
|
||||
transform = transform.inverted();
|
||||
elementTransform.transform = glm::mat3x2(
|
||||
transform.m11(), transform.m12(), transform.m21(),
|
||||
transform.m22(), transform.m31(), transform.m32()
|
||||
);
|
||||
//qDebug() << transform;
|
||||
elementTransform.zIndex = 0;
|
||||
painterPath = transform.map(painterPath);
|
||||
qDebug() << painterPath;
|
||||
bound = painterPath.boundingRect();
|
||||
|
||||
element.style = baseStyle.material;
|
||||
painting.addElement(element, elementTransform);
|
||||
}
|
||||
ElementTransform elementTransform;
|
||||
transform = transform * trans;
|
||||
//elementTransform.bound = glm::vec4(-1, -1, 1, 1);
|
||||
elementTransform.bound = glm::vec4(
|
||||
2 * (bound.x() - maxLineWidth) / screenSize.width() - 1,
|
||||
2 * (bound.y() - maxLineWidth) / screenSize.height() - 1,
|
||||
2 * (bound.x() + bound.width() + maxLineWidth) / screenSize.width() - 1,
|
||||
2 * (bound.y() + bound.height() + maxLineWidth) / screenSize.height() - 1
|
||||
);
|
||||
qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z;
|
||||
transform = transform.inverted();
|
||||
elementTransform.transform = glm::mat3x2(
|
||||
transform.m11(), transform.m12(), transform.m21(),
|
||||
transform.m22(), transform.m31(), transform.m32()
|
||||
);
|
||||
qDebug() << transform;
|
||||
elementTransform.zIndex = 0;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
auto baseStyles = leafLayer->styles.toBaseStyles();
|
||||
BaseElement element; element.contour = contour;
|
||||
for (auto baseStyle : baseStyles) {
|
||||
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
|
||||
auto material = dynamic_cast<MaterialStyleStroke*>(baseStyle.material.get());
|
||||
material->halfWidth = material->halfWidth / maxLen;
|
||||
qDebug() << material->halfWidth;
|
||||
}
|
||||
element.style = baseStyle.material;
|
||||
painting.addElement(element, elementTransform);
|
||||
}
|
||||
|
||||
FolderLayerWrapper* folderLayer = dynamic_cast<FolderLayerWrapper*>(nowLayer);
|
||||
return folderLayer;
|
||||
//qDebug() << bound;
|
||||
|
||||
// TODO ¸ÄÓþØÕó
|
||||
|
||||
/* elementTrans.center = glm::vec2(
|
||||
(2 * bound.center().x() - screenSize.width()) / screenSize.width(),
|
||||
(2 * bound.center().y() - screenSize.height()) / screenSize.height()
|
||||
);
|
||||
qDebug() << elementTrans.center.x << elementTrans.center.y;
|
||||
decomposeTransform(transform, elementTrans.rotation, elementTrans.scale);
|
||||
elementTrans.scale = glm::vec2(
|
||||
bound.width() * 2 / screenSize.width(),
|
||||
bound.height() * 2 / screenSize.height()
|
||||
);
|
||||
elementTrans.flip = glm::bvec2(
|
||||
nowLayer->property.flipHorizontally,
|
||||
nowLayer->property.flipVertically
|
||||
);
|
||||
qDebug() << elementTrans.scale.x << elementTrans.scale.y;
|
||||
painting.addElement(element, elementTrans);*/
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FolderLayerWrapper* folderLayer = dynamic_cast<FolderLayerWrapper*>(nowLayer);
|
||||
return folderLayer;
|
||||
}
|
||||
void PaintingUtil::decomposeTransform(QTransform trans, float& angle, glm::vec2& scale) {
|
||||
//qDebug() << trans;
|
||||
trans.setMatrix(
|
||||
trans.m11(), trans.m12(), trans.m13(),
|
||||
trans.m21(), trans.m22(), trans.m23(),
|
||||
0, 0, 1);
|
||||
//qDebug() << trans.dx() << trans.dy();
|
||||
int count = 0;
|
||||
double norm = 0, n = 0;
|
||||
QTransform R = trans, Rit, Rnext;
|
||||
do {
|
||||
++count;
|
||||
Rit = R.transposed().inverted();
|
||||
Rnext.setMatrix(
|
||||
(R.m11() + Rit.m11()) / 2,
|
||||
(R.m12() + Rit.m12()) / 2,
|
||||
(R.m13() + Rit.m13()) / 2,
|
||||
(R.m21() + Rit.m21()) / 2,
|
||||
(R.m22() + Rit.m22()) / 2,
|
||||
(R.m23() + Rit.m23()) / 2,
|
||||
(R.m31() + Rit.m31()) / 2,
|
||||
(R.m32() + Rit.m32()) / 2,
|
||||
(R.m33() + Rit.m33()) / 2
|
||||
);
|
||||
norm = 0;
|
||||
norm = max(norm,
|
||||
fabs(R.m11() - Rnext.m11())
|
||||
+ fabs(R.m12() - Rnext.m12())
|
||||
+ fabs(R.m13() - Rnext.m13()));
|
||||
norm = max(norm,
|
||||
fabs(R.m21() - Rnext.m21())
|
||||
+ fabs(R.m22() - Rnext.m22())
|
||||
+ fabs(R.m23() - Rnext.m23()));
|
||||
norm = max(norm,
|
||||
fabs(R.m31() - Rnext.m31())
|
||||
+ fabs(R.m32() - Rnext.m32())
|
||||
+ fabs(R.m33() - Rnext.m33()));
|
||||
R = Rnext;
|
||||
} while (count < 100 && norm > 0.0001);
|
||||
double cosValue = max(-1.0, min(R.m11(), 1.0));
|
||||
double sinValue = max(-1.0, min(R.m12(), 1.0));
|
||||
angle = acos(cosValue) * 180 / pi;
|
||||
if (sinValue < 0) {
|
||||
angle = 360 - angle;
|
||||
}
|
||||
qDebug() << angle;
|
||||
//R = R.inverted() * trans;
|
||||
//scale = glm::vec2(R.m11(), R.m22());
|
||||
//qDebug() << scale.x << scale.y;
|
||||
return;
|
||||
}
|
||||
|
||||
double PaintingUtil::getMaxLineWidth(LayerWrapper* root) {
|
||||
double maxWidth = 0;
|
||||
queue<LayerWrapper* > layerQueue;
|
||||
layerQueue.push(root);
|
||||
while (!layerQueue.empty()) {
|
||||
auto layer = layerQueue.front();
|
||||
layerQueue.pop();
|
||||
FolderLayerWrapper* nextLayer = nullptr;
|
||||
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(layer);
|
||||
if (leafLayer != nullptr) {
|
||||
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
|
||||
if (wrapperElement != nullptr) {
|
||||
nextLayer = wrapperElement->sourceLayer;
|
||||
}
|
||||
else {
|
||||
maxWidth = std::max(maxWidth, (double)leafLayer->styles.boundingBoxAffectValue());
|
||||
}
|
||||
}
|
||||
else {
|
||||
nextLayer = dynamic_cast<FolderLayerWrapper*>(layer);
|
||||
}
|
||||
if (nextLayer != nullptr) {
|
||||
for (auto sonLayer : nextLayer->children) {
|
||||
layerQueue.push(sonLayer.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
return maxWidth;
|
||||
}
|
|
@ -7,9 +7,11 @@ class PaintingUtil
|
|||
private:
|
||||
static const double pi;
|
||||
static QJsonObject readJsonFile(QString jsonFilePath);
|
||||
static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, QTransform& transform, Renderer::Painting& painting);
|
||||
//static double getMaxLineWidth(LayerWrapper* root);
|
||||
static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, double& maxLineWidth, QTransform& transform, Renderer::Painting& painting);
|
||||
static double getMaxLineWidth(LayerWrapper* root);
|
||||
public:
|
||||
static Renderer::Painting transfromToPainting(QString jsonFilePath);
|
||||
static void decomposeTransform(QTransform trans, float& angle, glm::vec2& scale);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -22,8 +22,3 @@ void ::FluentMenu::paintEvent(QPaintEvent* event)
|
|||
}
|
||||
QMenu::paintEvent(event);
|
||||
}
|
||||
|
||||
QAction* FluentMenu::exec(const QPoint& pos, QAction* at)
|
||||
{
|
||||
return QMenu::exec(parentWidget()->mapToGlobal(parentWidget()->mapFromGlobal(pos) + QPoint(-shadowRadius, -shadowRadius)), at);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ class FluentMenu : public QMenu
|
|||
public:
|
||||
explicit FluentMenu(QWidget* parent = nullptr);
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
QAction* exec(const QPoint& pos, QAction* at = nullptr);
|
||||
int shadowRadius = 16;
|
||||
int borderRadius = 6;
|
||||
int itemBorderRadius = 4;
|
||||
|
|
|
@ -244,9 +244,8 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
|||
return iter->second;
|
||||
|
||||
Painting painting;
|
||||
path = "../test.json";
|
||||
if (auto file = QFileInfo(QString(path.c_str())); file.isFile())
|
||||
painting = PaintingUtil::transfromToPainting(file.filePath());
|
||||
painting = PaintingUtil::transfromToPainting(file.path());
|
||||
else
|
||||
{
|
||||
qDebug() << path.c_str() << "Not Found, Using Default Painting";
|
||||
|
|
|
@ -20,7 +20,8 @@ QVector4D BvhTree::Union(QVector4D a, QVector4D b) {
|
|||
|
||||
QVector4D BvhTree::merge(BvhPtr lp, BvhPtr rp) {
|
||||
QVector4D a = lp->bound, b = rp->bound;
|
||||
/*if (lp->isLeaf) {
|
||||
/*
|
||||
if (lp->isLeaf) {
|
||||
a = BvhTreeData::boundWithRotation(a, lp->getRightSon());
|
||||
}
|
||||
if (rp->isLeaf) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "MaterialStyleStroke.h"
|
||||
#include <QDebug>
|
||||
#include <array>
|
||||
|
||||
using namespace Renderer;
|
||||
|
||||
|
@ -118,10 +117,4 @@ float Renderer::MaterialStyleStroke::getHalfWidth() const
|
|||
return halfWidth;
|
||||
}
|
||||
|
||||
#define endTypeBoxLabel(start, end) QStringLiteral(start##" -> "##end)
|
||||
const std::array<std::pair<QString, StrokeEndType>, 4> Renderer::MaterialStyleStroke::strokeEndTypeNames = {
|
||||
std::pair{endTypeBoxLabel("Բͷ", "Բͷ"), StrokeEndType::kRound},
|
||||
std::pair{endTypeBoxLabel("ƽͷ", "Բͷ"), StrokeEndType::kFlatRound},
|
||||
std::pair{endTypeBoxLabel("Բͷ", "ƽͷ"), StrokeEndType::kRoundFlat},
|
||||
std::pair{endTypeBoxLabel("ƽͷ", "ƽͷ"), StrokeEndType::kFlat}
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace Renderer
|
|||
};
|
||||
|
||||
enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 };
|
||||
enum class StrokeEndType { kRound = 0b00, kFlat = 0b11, kRoundFlat = 0b10, kFlatRound = 0b01, kClosed = 0b100/*用于封闭图形*/ };
|
||||
enum class StrokeEndType { kRound = 0b00, kFlat = 0b11, kRoundFlat = 0b10, kFlatRound = 0b01 };
|
||||
|
||||
class MaterialStyleStroke : public MaterialStyle
|
||||
{
|
||||
|
@ -59,6 +59,5 @@ namespace Renderer
|
|||
StrokeType strokeType;
|
||||
StrokeEndType endType;
|
||||
std::shared_ptr<MaterialStroke> materialStroke;
|
||||
static const std::array<std::pair<QString, StrokeEndType>, 4> strokeEndTypeNames;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
|
|||
ui.openButton->setChecked(false);
|
||||
});
|
||||
QObject::connect(ui.openButton, &QPushButton::clicked, [&, menu]() {
|
||||
menu->exec(ui.openButton->mapToGlobal(QPoint(0, ui.openButton->height())));
|
||||
menu->exec(ui.openButton->mapToGlobal(QPoint(-menu->shadowRadius, ui.openButton->height() - menu->shadowRadius)));
|
||||
});
|
||||
|
||||
QObject::connect(ui.horizontalSlider, &QSlider::valueChanged,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "MainWindow.h"
|
||||
#include "ColorHelper.hpp"
|
||||
#include <QGuiApplication>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <FramelessHelper/Core/private/framelessconfig_p.h>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
#include "consoleapi2.h"
|
||||
#include <lib/qtmaterialstyle.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -51,7 +51,9 @@ int main(int argc, char* argv[])
|
|||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
QApplication a(argc, argv);
|
||||
Q_INIT_RESOURCE(resources);
|
||||
ColorHelper::instance();
|
||||
QtMaterialTheme theme;
|
||||
theme.setColor("primary1", QColor(0, 90, 158));
|
||||
QtMaterialStyle::instance().setTheme(&theme);
|
||||
//FramelessHelper::Core::setApplicationOSThemeAware();
|
||||
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
|
||||
//FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
|
||||
|
|
|
@ -42,38 +42,17 @@ namespace UnitTest
|
|||
{
|
||||
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
|
||||
{
|
||||
return { BaseStyle(std::make_shared<TransformStyle>(),
|
||||
std::make_shared<MaterialStyleFill>(std::make_shared<FillPlain>(Material(QColor(255,255,0))))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
TEST_METHOD(TestFillPlainAndStrokeRadialGradient)
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
class Style : public Renderer::ElementStyle
|
||||
{
|
||||
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
|
||||
{
|
||||
std::map<float, Material> materialMap = {
|
||||
{0.20, Material{QColor(255,255,255)}},
|
||||
{0.60, Material{QColor(165,176,207)}},
|
||||
{1.00, Material{QColor(58,64,151)}}
|
||||
};
|
||||
|
||||
return { BaseStyle(std::make_shared<TransformStyle>(),
|
||||
std::make_shared<MaterialStyleFill>(
|
||||
std::make_shared<FillPlain>(Material(QColor(255,255,0))))),
|
||||
BaseStyle(std::make_shared<TransformStyle>(),
|
||||
std::make_shared<MaterialStyleStroke>(10, StrokeType::kBothSides, StrokeEndType::kRound,
|
||||
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
|
||||
std::make_shared<FillPlain>(Material(QColor(255,255,0))))) };
|
||||
}
|
||||
} style;
|
||||
TestGLWidget w(style, path);
|
||||
w.show();
|
||||
a.exec();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST_CLASS(ElementRendererStokeTypeTest)
|
||||
|
|
|
@ -122,6 +122,20 @@ namespace UnitTest
|
|||
};
|
||||
TEST_CLASS(PaintingUtilTest)
|
||||
{
|
||||
|
||||
TEST_METHOD(TransfromTest)
|
||||
{
|
||||
qInstallMessageHandler(messageHandler);
|
||||
QPainterPath path;
|
||||
path.addRect(0, 0, 20, 20);
|
||||
QTransform trans;
|
||||
qDebug() << path.boundingRect();
|
||||
//qDebug() << trans;
|
||||
//qDebug() << acos(-0.707107);
|
||||
glm::vec2 scale;
|
||||
float rotate;
|
||||
PaintingUtil::decomposeTransform(trans, rotate, scale);
|
||||
qDebug() << rotate;
|
||||
qDebug() << scale.x << scale.y;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
46
test.json
46
test.json
|
@ -24,7 +24,7 @@
|
|||
}
|
||||
],
|
||||
"height": 1080,
|
||||
"project-name": "ÑùÀý1",
|
||||
"project-name": "",
|
||||
"root-layer": {
|
||||
"children": [
|
||||
{
|
||||
|
@ -36,7 +36,7 @@
|
|||
"styles": [
|
||||
{
|
||||
"enableEachSideIndependent": false,
|
||||
"left": "AAAAQAEAIZwAf///qqr//w==",
|
||||
"left": "AACgQAEAIZwAf///AAAA/w==",
|
||||
"right": "AADgQAAACJw=",
|
||||
"type": "stroke"
|
||||
}
|
||||
|
@ -52,30 +52,6 @@
|
|||
"y": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"element": 0,
|
||||
"is-folder": false,
|
||||
"name": "Leaf2",
|
||||
"styles": [
|
||||
{
|
||||
"enableEachSideIndependent": true,
|
||||
"left": "AAAAQAEAIZwAf////1UA/w==",
|
||||
"right": "AADgQAAACJw=",
|
||||
"type": "stroke"
|
||||
}
|
||||
],
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 150,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 0,
|
||||
"scale": {
|
||||
"x": 1.5,
|
||||
"y": 1.5
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"is-folder": true,
|
||||
|
@ -92,24 +68,6 @@
|
|||
"y": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"element": 1,
|
||||
"is-folder": false,
|
||||
"name": "ReferencingGroupLayer",
|
||||
"styles": [
|
||||
],
|
||||
"transform": {
|
||||
"offset": {
|
||||
"x": 100,
|
||||
"y": 0
|
||||
},
|
||||
"rotation": 45,
|
||||
"scale": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"is-folder": true,
|
||||
|
|
Loading…
Reference in New Issue