mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Add choice of colors for non parametric gradients
This commit is contained in:
@ -83,10 +83,22 @@ QImage GenerateImg(std::vector<Point> &points, Info &info, const int& w, const i
|
||||
return img;
|
||||
}
|
||||
|
||||
void MainWindow::InitializeColors(bool Triangle)
|
||||
{
|
||||
ui->label_80->SetColor(QColor(Qt::red));
|
||||
ui->label_81->SetColor(QColor(Qt::green));
|
||||
ui->label_114->SetColor(QColor(Qt::blue));
|
||||
if (!Triangle)
|
||||
{
|
||||
ui->label_115->SetColor(QColor(Qt::yellow));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionLinear_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
ui->stackedWidget_2->setCurrentIndex(0);
|
||||
ui->stackedWidget_3->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Linear");
|
||||
info.gradient = Linear;
|
||||
info.gradient_type = c_BrushTypePathNewLinearGradient;
|
||||
@ -96,6 +108,7 @@ void MainWindow::on_actionRadial_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
ui->stackedWidget_2->setCurrentIndex(1);
|
||||
ui->stackedWidget_3->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Radial");
|
||||
info.gradient = Radial;
|
||||
info.gradient_type = c_BrushTypePathRadialGradient;
|
||||
@ -105,6 +118,8 @@ void MainWindow::on_actionTriangle_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(2);
|
||||
ui->stackedWidget_2->setCurrentIndex(2);
|
||||
ui->stackedWidget_3->setCurrentIndex(1);
|
||||
InitializeColors(true);
|
||||
ui->statusbar->showMessage("Triangle");
|
||||
info.gradient = Triangle;
|
||||
info.gradient_type = c_BrushTypeTriagnleMeshGradient;
|
||||
@ -114,6 +129,7 @@ void MainWindow::on_actionTriangle_Parametric_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(2);
|
||||
ui->stackedWidget_2->setCurrentIndex(3);
|
||||
ui->stackedWidget_3->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Triangle Parametric");
|
||||
info.gradient = TriangleParametric;
|
||||
info.gradient_type = c_BrushTypeTriagnleMeshGradient;
|
||||
@ -123,6 +139,8 @@ void MainWindow::on_actionCoons_Patch_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(3);
|
||||
ui->stackedWidget_2->setCurrentIndex(4);
|
||||
ui->stackedWidget_3->setCurrentIndex(1);
|
||||
InitializeColors(false);
|
||||
ui->statusbar->showMessage("Coons Patch");
|
||||
info.gradient = CoonsPatch;
|
||||
info.gradient_type = c_BrushTypePathNewLinearGradient;
|
||||
@ -132,6 +150,7 @@ void MainWindow::on_actionCoons_Patch_Parametric_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(3);
|
||||
ui->stackedWidget_2->setCurrentIndex(5);
|
||||
ui->stackedWidget_3->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Coons Patch Parametric");
|
||||
info.gradient = CoonsPatchParametric;
|
||||
info.gradient_type = c_BrushTypeCurveGradient;
|
||||
@ -141,6 +160,8 @@ void MainWindow::on_actionTensor_Coons_Patch_Gradient_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(4);
|
||||
ui->stackedWidget_2->setCurrentIndex(6);
|
||||
ui->stackedWidget_3->setCurrentIndex(1);
|
||||
InitializeColors(false);
|
||||
ui->statusbar->showMessage("Tensor Coons Patch");
|
||||
info.gradient = TensorCoonsPatch;
|
||||
info.gradient_type = c_BrushTypePathNewLinearGradient;
|
||||
@ -150,11 +171,58 @@ void MainWindow::on_actionTensor_Coons_Patch_Parametric_triggered()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(4);
|
||||
ui->stackedWidget_2->setCurrentIndex(7);
|
||||
ui->stackedWidget_3->setCurrentIndex(0);
|
||||
ui->statusbar->showMessage("Tensor Coons Patch Parametric");
|
||||
info.gradient = TensorCoonsPatchParametric;
|
||||
info.gradient_type = c_BrushTypeTensorCurveGradient;
|
||||
}
|
||||
|
||||
std::vector<agg::rgba8> MainWindow::QColor2rgba(bool triangle)
|
||||
{
|
||||
std::vector<agg::rgba8> colors;
|
||||
colors.push_back({static_cast<unsigned int>(ui->label_80->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_80->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_80->GetColor().blue())});
|
||||
colors.push_back({static_cast<unsigned int>(ui->label_81->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_81->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_81->GetColor().blue())});
|
||||
colors.push_back({static_cast<unsigned int>(ui->label_114->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_114->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_114->GetColor().blue())});
|
||||
if (!triangle)
|
||||
{
|
||||
colors.push_back({static_cast<unsigned int>(ui->label_115->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_115->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_115->GetColor().blue())});
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
std::vector<std::vector<agg::rgba8>> MainWindow::QColor2rgbaMatrix()
|
||||
{
|
||||
std::vector<std::vector<agg::rgba8>> colors;
|
||||
std::vector<agg::rgba8> sub_colors;
|
||||
sub_colors.push_back({static_cast<unsigned int>(ui->label_80->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_80->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_80->GetColor().blue())});
|
||||
sub_colors.push_back({static_cast<unsigned int>(ui->label_81->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_81->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_81->GetColor().blue())});
|
||||
colors.push_back(sub_colors);
|
||||
sub_colors.clear();
|
||||
sub_colors.push_back({static_cast<unsigned int>(ui->label_114->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_114->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_114->GetColor().blue())});
|
||||
sub_colors.push_back({static_cast<unsigned int>(ui->label_115->GetColor().red()),
|
||||
static_cast<unsigned int>(ui->label_115->GetColor().green()),
|
||||
static_cast<unsigned int>(ui->label_115->GetColor().blue())});
|
||||
colors.push_back(sub_colors);
|
||||
sub_colors.clear();
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_clicked()
|
||||
{
|
||||
points = {{0, 0},
|
||||
@ -199,9 +267,8 @@ void MainWindow::on_pushButton_clicked()
|
||||
info.triangle_parametrs[1] = ui->Second_Vertex_Parametr_Input_4->text().toFloat();
|
||||
info.triangle_parametrs[2] = ui->Third_Vertex_Parametr_Input_4->text().toFloat();
|
||||
}
|
||||
|
||||
info.ginfo = NSStructures::GInfoConstructor::get_triangle(info.triangle,
|
||||
{{255, 0, 0}, {0, 255, 0}, {0, 0, 255}},
|
||||
QColor2rgba(true),
|
||||
info.triangle_parametrs,
|
||||
info.gradient == TriangleParametric);
|
||||
points = {};
|
||||
@ -253,12 +320,10 @@ void MainWindow::on_pushButton_clicked()
|
||||
info.curve[j].y *= MM_TO_COORD(ui->lable_test->height());
|
||||
}
|
||||
}
|
||||
|
||||
info.ginfo = NSStructures::GInfoConstructor::get_curve(
|
||||
info.curve,
|
||||
info.curve_parametrs,
|
||||
{{0, 0, 255}, {255, 0, 255},
|
||||
{255, 0, 0}, {0, 255, 0}},
|
||||
QColor2rgba(false),
|
||||
info.gradient == CoonsPatchParametric
|
||||
);
|
||||
}
|
||||
@ -320,7 +385,7 @@ void MainWindow::on_pushButton_clicked()
|
||||
info.ginfo = NSStructures::GInfoConstructor::get_tensor_curve(
|
||||
info.tensorcurve,
|
||||
info.tensor_curve_parametrs,
|
||||
{{{0, 0, 255}, {255, 0, 255}}, {{255, 0, 0}, {0, 255, 0}}},
|
||||
QColor2rgbaMatrix(),
|
||||
info.gradient == TensorCoonsPatchParametric
|
||||
);
|
||||
}
|
||||
@ -453,4 +518,3 @@ void MainWindow::on_pushButton_2_clicked()
|
||||
ui->lable_test->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPoint>
|
||||
#include <QMouseEvent>
|
||||
#include <QColorDialog>
|
||||
#include <QPainter>
|
||||
#include "../../../../DesktopEditor/graphics/structures.h"
|
||||
|
||||
@ -99,6 +100,49 @@ private:
|
||||
std::vector<QPoint> m_points;
|
||||
};
|
||||
|
||||
class CustomColorLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CustomColorLabel(QWidget *parent = nullptr) : QLabel(parent)
|
||||
{
|
||||
connect(this, &CustomColorLabel::mousePressed, this, &CustomColorLabel::onMousePressed);
|
||||
}
|
||||
|
||||
~CustomColorLabel() {}
|
||||
|
||||
void SetColor(QColor color)
|
||||
{
|
||||
m_color = color;
|
||||
this->setStyleSheet("QLabel { background-color : " + m_color.name() + "; border: 1px solid black; padding 10px;}");
|
||||
}
|
||||
|
||||
QColor GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
signals:
|
||||
void mousePressed();
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
emit mousePressed();
|
||||
}
|
||||
public slots:
|
||||
void onMousePressed()
|
||||
{
|
||||
QColorDialog colorDialog;
|
||||
QColor color = colorDialog.getColor();
|
||||
|
||||
if (color.isValid())
|
||||
{
|
||||
SetColor(color);
|
||||
}
|
||||
}
|
||||
private:
|
||||
QColor m_color;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Linear,
|
||||
@ -191,6 +235,9 @@ class MainWindow : public QMainWindow
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
void InitializeColors(bool triangle);
|
||||
std::vector<agg::rgba8> QColor2rgba(bool triangle);
|
||||
std::vector<std::vector<agg::rgba8>> QColor2rgbaMatrix();
|
||||
QImage img;
|
||||
QLabel *lable;
|
||||
std::vector<Point> points;
|
||||
|
||||
@ -42,71 +42,6 @@
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox_Linear">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>0</y>
|
||||
<width>201</width>
|
||||
<height>140</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Choose gradient colorspace</string>
|
||||
</property>
|
||||
<widget class="QRadioButton" name="Rainbow_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>112</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Rainbow</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="BAW_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>50</y>
|
||||
<width>161</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Black and White</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="RAB_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>80</y>
|
||||
<width>131</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Red and Blue</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="Pastel_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>110</y>
|
||||
<width>112</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pastel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -2517,6 +2452,153 @@
|
||||
<string>Set the coordinates from the label and click</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStackedWidget" name="stackedWidget_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>221</width>
|
||||
<height>130</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_11">
|
||||
<widget class="QGroupBox" name="groupBox_Linear">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>201</width>
|
||||
<height>120</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Choose gradient colorspace</string>
|
||||
</property>
|
||||
<widget class="QRadioButton" name="Rainbow_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>112</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Rainbow</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="BAW_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>50</y>
|
||||
<width>161</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Black and White</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="RAB_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>70</y>
|
||||
<width>131</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Red and Blue</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="Pastel_Colorspace_Radio_Button">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>90</y>
|
||||
<width>112</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pastel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_12">
|
||||
<widget class="QGroupBox" name="groupBox_17">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>171</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Set colors in angles</string>
|
||||
</property>
|
||||
<widget class="CustomColorLabel" name="label_80">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>40</y>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="CustomColorLabel" name="label_81">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>50</x>
|
||||
<y>40</y>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="CustomColorLabel" name="label_114">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>40</y>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="CustomColorLabel" name="label_115">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>40</y>
|
||||
<width>30</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QStackedWidget" name="stackedWidget_2">
|
||||
<property name="geometry">
|
||||
@ -3368,6 +3450,14 @@
|
||||
<extends>QLineEdit</extends>
|
||||
<header>mainwindow.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>CustomColorLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>mainwindow.h</header>
|
||||
<slots>
|
||||
<slot>onMouseClicked()</slot>
|
||||
</slots>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user