Merge pull request 'fix/Tensor-luminosity-gradient' (#326) from fix/Tensor-luminosity-gradient into release/v9.0.0

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/326
This commit is contained in:
Oleg Korshul
2025-05-27 18:38:41 +00:00
10 changed files with 479 additions and 102 deletions

View File

@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
listOfCheckBox = ui->centralwidget->findChildren<QCheckBox*>();
listOfColorLabels = ui->centralwidget->findChildren<CustomColorLabel*>();
listOfParametricLines = ui->centralwidget->findChildren<CustomParametrLineEdit*>();
listOfAlphas = ui->centralwidget->findChildren<CustomAlphaLineEdit*>();
connect(ui->label_test, SIGNAL(mousePressed()), this, SLOT(on_label_test_clicked()));
@ -61,6 +62,9 @@ QImage GenerateImg(std::vector<NSStructures::Point> &points, Info &info, const i
NSStructures::GradientInfo ginfo = info.ginfo;
ginfo.shading.f_type = NSStructures::ShadingInfo::UseNew;
NSStructures::CBrush brush;
brush.m_oGradientInfo = ginfo;
//pRasterRenderer->RestoreBrush(brush);
pRasterRenderer->put_BrushGradInfo(&ginfo);
auto a = info.c;
auto b = info.p;
@ -96,6 +100,7 @@ void MainWindow::initializeColors(bool Triangle)
{
listOfColorLabels[3]->setColor(QColor(Qt::yellow));
}
listOfColorLabels[4]->setColor(QColor(Qt::black));
}
void MainWindow::on_actionLinear_Gradient_triggered()
@ -189,6 +194,18 @@ void MainWindow::on_actionTensor_Coons_Patch_Parametric_triggered()
ui->statusbar->showMessage("Tensor Coons Patch Parametric");
}
void MainWindow::on_actionactionLuminocity_Gradient_triggered()
{
ui->stackedWidget_1->setCurrentIndex(4);
ui->stackedWidget_2->setCurrentIndex(6);
ui->stackedWidget_3->setCurrentIndex(2);
info.gradient = Luminosity;
info.offset = TensorCoonsPatchOffset;
info.gradient_type = c_BrushTypeTensorCurveGradient;
initializeColors(false);
ui->statusbar->showMessage("Tensor Coons Patch");
}
inline agg::rgba8 getRGB(CustomColorLabel *label)
{
return {static_cast<unsigned int>(label->getColor().red()),
@ -230,6 +247,24 @@ std::vector<std::vector<agg::rgba8>> MainWindow::qColor2rgbaMatrix()
return colors;
}
std::vector<std::vector<agg::rgba8>> MainWindow::setAlphas()
{
std::vector<std::vector<agg::rgba8>> colors;
size_t size = listOfAlphas.size() / 2;
for (int i = 0; i < size; i++)
{
std::vector<agg::rgba8> sub_colors;
for (int j = 0; j < size; j++)
{
sub_colors.push_back({0, 0, 0, listOfAlphas[2 * i + j]->text().toUInt()});
}
colors.push_back(sub_colors);
}
return colors;
}
NSStructures::Point MainWindow::scaleCoord(NSStructures::Point p)
{
return {p.x * MM_TO_COORD(ui->label_test->width()), p.y * MM_TO_COORD(ui->label_test->height())};
@ -279,6 +314,7 @@ void MainWindow::setPoints(QImage *image)
break;
case TensorCoonsPatch:
case TensorCoonsPatchParametric:
case Luminosity:
for (std::vector<NSStructures::Point> v : info.tensorcurve)
{
for (NSStructures::Point p : v)
@ -440,6 +476,11 @@ void MainWindow::on_pushButton_clicked()
info.ginfo = NSStructures::GInfoConstructor::get_tensor_curve(info.tensorcurve, info.tensor_curve_parametrs,
qColor2rgbaMatrix(), info.gradient == TensorCoonsPatchParametric);
break;
case Luminosity:
info.ginfo = NSStructures::GInfoConstructor::get_tensor_curve(info.tensorcurve, info.tensor_curve_parametrs,
setAlphas(), false, true);
info.ginfo.setFillColor(getRGB(listOfColorLabels[4]));
break;
default:
break;
}
@ -479,3 +520,6 @@ void MainWindow::on_pushButton_clicked()
ui->label_test->setPixmap(QPixmap::fromImage(pm));
ui->label_test->setScaledContents(true);
}

View File

@ -64,6 +64,25 @@ public slots:
}
};
class CustomAlphaLineEdit : public QLineEdit
{
Q_OBJECT
public:
CustomAlphaLineEdit(QWidget *parent = nullptr) : QLineEdit(parent)
{
connect(this, &QLineEdit::editingFinished, this, &CustomAlphaLineEdit::onEditingFinished);
}
~CustomAlphaLineEdit() {}
public slots:
void onEditingFinished()
{
if (this->text() == "")
this->setText(this->placeholderText());
if (this->text().toUInt() > 255)
this->setText("255");
}
};
class CustomLabel : public QLabel
{
Q_OBJECT
@ -198,7 +217,8 @@ typedef enum
CoonsPatch,
CoonsPatchParametric,
TensorCoonsPatch,
TensorCoonsPatchParametric
TensorCoonsPatchParametric,
Luminosity
} GradientType;
typedef enum
@ -246,6 +266,7 @@ public:
void initializeColors(bool triangle);
std::vector<agg::rgba8> qColor2rgba(bool triangle);
std::vector<std::vector<agg::rgba8>> qColor2rgbaMatrix();
std::vector<std::vector<agg::rgba8>> setAlphas();
void setPoints(QImage *image);
NSStructures::Point scaleCoord(NSStructures::Point p);
@ -278,6 +299,8 @@ private slots:
void on_actionTensor_Coons_Patch_Parametric_triggered();
void on_actionactionLuminocity_Gradient_triggered();
private:
QImage img;
Info info;
@ -287,6 +310,7 @@ private:
QList<CustomLineEdit *> listOfLines;
QList<CustomColorLabel *> listOfColorLabels;
QList<CustomParametrLineEdit *> listOfParametricLines;
QList<CustomAlphaLineEdit *> listOfAlphas;
Ui::MainWindow *ui;
};

View File

@ -55,7 +55,7 @@
</rect>
</property>
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="Linear_Page">
<widget class="QGroupBox" name="groupBox">
@ -2468,7 +2468,7 @@
</rect>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="page_11">
<widget class="QGroupBox" name="groupBox_Linear">
@ -2607,6 +2607,111 @@
</widget>
</widget>
</widget>
<widget class="QWidget" name="page_9">
<widget class="QGroupBox" name="groupBox_26">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>201</width>
<height>101</height>
</rect>
</property>
<property name="title">
<string>Set alphas and fill color</string>
</property>
<widget class="CustomColorLabel" name="label_125">
<property name="geometry">
<rect>
<x>70</x>
<y>70</y>
<width>30</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="CustomAlphaLineEdit" name="lineEdit_88">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>31</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>0</string>
</property>
<property name="placeholderText">
<string>0</string>
</property>
</widget>
<widget class="CustomAlphaLineEdit" name="lineEdit_89">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>31</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>150</string>
</property>
<property name="placeholderText">
<string>150</string>
</property>
</widget>
<widget class="CustomAlphaLineEdit" name="lineEdit_90">
<property name="geometry">
<rect>
<x>100</x>
<y>30</y>
<width>31</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>150</string>
</property>
<property name="placeholderText">
<string>150</string>
</property>
</widget>
<widget class="CustomAlphaLineEdit" name="lineEdit_91">
<property name="geometry">
<rect>
<x>140</x>
<y>30</y>
<width>31</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>255</string>
</property>
<property name="placeholderText">
<string>255</string>
</property>
</widget>
<widget class="QLabel" name="label_35">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>49</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Fill color</string>
</property>
</widget>
</widget>
</widget>
</widget>
</widget>
<widget class="QStackedWidget" name="stackedWidget_2">
@ -3360,7 +3465,7 @@
<x>0</x>
<y>0</y>
<width>1126</width>
<height>25</height>
<height>21</height>
</rect>
</property>
</widget>
@ -3383,6 +3488,7 @@
<addaction name="actionCoons_Patch_Parametric"/>
<addaction name="actionTensor_Coons_Patch_Gradient"/>
<addaction name="actionTensor_Coons_Patch_Parametric"/>
<addaction name="actionactionLuminocity_Gradient"/>
</widget>
<action name="actionLinear_Gradient">
<property name="text">
@ -3442,6 +3548,17 @@
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionactionLuminocity_Gradient">
<property name="text">
<string>Luminocity Gradient</string>
</property>
<property name="toolTip">
<string>TensorPatchLuminosity</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
@ -3467,6 +3584,11 @@
<slot>onMouseClicked()</slot>
</slots>
</customwidget>
<customwidget>
<class>CustomAlphaLineEdit</class>
<extends>QLineEdit</extends>
<header>mainwindow.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>