improvement: ajust size of grid-dots with zoom-factor

Introduced additional spinboxes in config-page for
setting min- and max-size of grid-dots separately for
diagram- and element-editor.
That assures maximal flexibility for setting the grids.
Don't want the grid-dots to change over zooming-levels?
Set min- and max-values to the same number.
Preset-values for all min-/max-values is "1".
If the adjustable range of 1 to 5 is not sufficient, it
can be easily adjusted. Only need feedback for this.
This commit is contained in:
plc-user
2025-03-07 20:16:21 +01:00
parent 2b0dd1b188
commit 0804d3524a
38 changed files with 2224 additions and 1596 deletions

View File

@@ -227,9 +227,27 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
points << QPoint(gx, gy);
}
}
pen.setWidth(settings.value(QStringLiteral("diagrameditor/grid_pointsize"), 1).toInt());
qreal zoom_factor = p->transform().m11();
int minWidthPen = settings.value(QStringLiteral("diagrameditor/grid_pointsize_min"), 1).toInt();
int maxWidthPen = settings.value(QStringLiteral("diagrameditor/grid_pointsize_max"), 1).toInt();
pen.setWidth(minWidthPen);
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (5.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
}
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
p -> setPen(pen);
p -> drawPoints(points);
if (zoom_factor > 0.5) // no grid below ... !
p -> drawPoints(points);
}
if (use_border_) border_and_titleblock.draw(p);

View File

@@ -480,6 +480,7 @@ bool ElementView::event(QEvent *e) {
/**
Utilise le pincement du trackpad pour zoomer
Use trackpad pinch to zoom
@brief ElementView::gestureEvent
@param event
@return
@@ -502,6 +503,7 @@ bool ElementView::gestureEvent(QGestureEvent *event){
/**
Dessine l'arriere-plan de l'editeur, cad la grille.
Draws the editor background, i.e. the grid.
@param p Le QPainter a utiliser pour dessiner
@param r Le rectangle de la zone a dessiner
*/
@@ -514,20 +516,23 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// dessine un fond blanc
// draw a white background
p -> setPen(Qt::NoPen);
p -> setBrush(Qt::white);
p -> drawRect(r);
// determine le zoom en cours
// determine the zoom-level
qreal zoom_factor = transform().m11();
// choisit la granularite de la grille en fonction du zoom en cours
// selects the grid granularity according to the current zoom level
int drawn_x_grid = 1;//scene_ -> xGrid();
int drawn_y_grid = 1;//scene_ -> yGrid();
bool draw_grid = true;
bool draw_cross = false;
if (zoom_factor < (4.0/3.0)) { //< no grid
if (zoom_factor < 1.0) { //< no grid
draw_grid = false;
} else if (zoom_factor < 4.0) { //< grid 10*10
drawn_x_grid *= 10;
@@ -547,23 +552,38 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
m_scene->setGrid(drawn_x_grid, drawn_y_grid);
if (draw_grid) {
// draw the dot of the grid
// draw the dots of the grid
QPen pen(Qt::black);
pen.setCosmetic(true);
QSettings settings;
pen.setWidth(settings.value(QStringLiteral("diagrameditor/grid_pointsize"), 1).toInt());
int minWidthPen = settings.value(QStringLiteral("elementeditor/grid_pointsize_min"), 1).toInt();
int maxWidthPen = settings.value(QStringLiteral("elementeditor/grid_pointsize_max"), 1).toInt();
pen.setWidth(minWidthPen);
qreal stepPen = (maxWidthPen - minWidthPen) / (qreal)maxWidthPen;
qreal stepZoom = (25.0 - 1.0) / maxWidthPen;
for (int n=0; n<maxWidthPen; n++) {
if ((zoom_factor > (1.0 + n * stepZoom)) && (zoom_factor <= (1.0 + (n+1) * stepZoom))) {
int widthPen = minWidthPen + qRound(n * stepPen);
pen.setWidth(widthPen);
}
}
if (zoom_factor <= 1.0)
pen.setWidth(minWidthPen);
else if (zoom_factor > (1.0 + stepZoom * maxWidthPen))
pen.setWidth(maxWidthPen);
p -> setPen(pen);
p -> setBrush(Qt::NoBrush);
qreal limite_x = r.x() + r.width();
qreal limite_y = r.y() + r.height();
qreal limit_x = r.x() + r.width();
qreal limit_y = r.y() + r.height();
int g_x = (int)ceil(r.x());
while (g_x % drawn_x_grid) ++ g_x;
int g_y = (int)ceil(r.y());
while (g_y % drawn_y_grid) ++ g_y;
for (int gx = g_x ; gx < limite_x ; gx += drawn_x_grid) {
for (int gy = g_y ; gy < limite_y ; gy += drawn_y_grid) {
for (int gx = g_x ; gx < limit_x ; gx += drawn_x_grid) {
for (int gy = g_y ; gy < limit_y ; gy += drawn_y_grid) {
if (draw_cross) {
if (!(gx % 10) && !(gy % 10)) {
p -> drawLine(QLineF(gx - (pen.width()/4.0), gy, gx + (pen.width()/4.0), gy));

View File

@@ -71,7 +71,8 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
ui->DiagramEditor_yKeyGrid_sb->setValue(settings.value("diagrameditor/key_Ygrid", 10).toInt());
ui->DiagramEditor_xKeyGridFine_sb->setValue(settings.value("diagrameditor/key_fine_Xgrid", 1).toInt());
ui->DiagramEditor_yKeyGridFine_sb->setValue(settings.value("diagrameditor/key_fine_Ygrid", 1).toInt());
ui->DiagramEditor_Grid_PointSize_sb->setValue(settings.value("diagrameditor/grid_pointsize", 1).toInt());
ui->DiagramEditor_Grid_PointSize_min_sb->setValue(settings.value("diagrameditor/grid_pointsize_min", 1).toInt());
ui->DiagramEditor_Grid_PointSize_max_sb->setValue(settings.value("diagrameditor/grid_pointsize_max", 1).toInt());
ui->m_use_system_color_cb->setChecked(settings.value("usesystemcolors", "true").toBool());
bool tabbed = settings.value("diagrameditor/viewmode", "tabbed") == "tabbed";
if(tabbed)
@@ -129,7 +130,9 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) :
et que la liste ne sera donc pas mise a jour.
*/
ui->MaxPartsElementEditorList_sb->setValue(settings.value("elementeditor/max-parts-element-editor-list", 200).toInt());
ui->ElementEditor_Grid_PointSize_min_sb->setValue(settings.value("elementeditor/grid_pointsize_min", 1).toInt());
ui->ElementEditor_Grid_PointSize_max_sb->setValue(settings.value("elementeditor/grid_pointsize_max", 1).toInt());
QString path = settings.value("elements-collections/common-collection-path", "default").toString();
if (path != "default")
{
@@ -211,6 +214,8 @@ void GeneralConfigurationPage::applyConf()
//ELEMENT EDITOR
settings.setValue("elementeditor/default-informations", ui->m_default_elements_info->toPlainText());
settings.setValue("elementeditor/max-parts-element-editor-list", ui->MaxPartsElementEditorList_sb->value());
settings.setValue("elementeditor/grid_pointsize_min", ui->ElementEditor_Grid_PointSize_min_sb->value());
settings.setValue("elementeditor/grid_pointsize_max", ui->ElementEditor_Grid_PointSize_max_sb->value());
//DIAGRAM VIEW
settings.setValue("diagramview/gestures", ui->m_use_gesture_trackpad->isChecked());
@@ -238,7 +243,8 @@ void GeneralConfigurationPage::applyConf()
settings.setValue("diagrameditor/key_Ygrid", ui->DiagramEditor_yKeyGrid_sb->value());
settings.setValue("diagrameditor/key_fine_Xgrid", ui->DiagramEditor_xKeyGridFine_sb->value());
settings.setValue("diagrameditor/key_fine_Ygrid", ui->DiagramEditor_yKeyGridFine_sb->value());
settings.setValue("diagrameditor/grid_pointsize", ui->DiagramEditor_Grid_PointSize_sb->value());
settings.setValue("diagrameditor/grid_pointsize_min", ui->DiagramEditor_Grid_PointSize_min_sb->value());
settings.setValue("diagrameditor/grid_pointsize_max", ui->DiagramEditor_Grid_PointSize_max_sb->value());
//Dynamic text item
settings.setValue("diagrameditor/dynamic_text_rotation", ui->m_dyn_text_rotation_sb->value());
settings.setValue("diagrameditor/dynamic_text_width", ui->m_dyn_text_width_sb->value());
@@ -531,3 +537,25 @@ void GeneralConfigurationPage::on_MaxPartsElementEditorList_sb_valueChanged(int
ui->MaxPartsElementEditorList_sb->setStyleSheet("");
}
}
/**
@brief GeneralConfigurationPage::on_DiagramEditor_Grid_PointSize_min_sb_valueChanged
the min-value of the max-SpinBox has to be limited:
may not be smaller than current value of min-SpinBox
@param value - the new value of the min-SpinBox
*/
void GeneralConfigurationPage::on_DiagramEditor_Grid_PointSize_min_sb_valueChanged(int value)
{
ui->DiagramEditor_Grid_PointSize_max_sb->setMinimum(std::max(1, value));
}
/**
@brief GeneralConfigurationPage::on_ElementEditor_Grid_PointSize_min_sb_valueChanged
the min-value of the max-SpinBox has to be limited:
may not be smaller than current value of min-SpinBox
@param value - the new value of the min-SpinBox
*/
void GeneralConfigurationPage::on_ElementEditor_Grid_PointSize_min_sb_valueChanged(int value)
{
ui->ElementEditor_Grid_PointSize_max_sb->setMinimum(std::max(1, value));
}

View File

@@ -48,6 +48,8 @@ class GeneralConfigurationPage : public ConfigPage
void on_m_custom_tbt_path_cb_currentIndexChanged(int index);
void on_m_indi_text_font_pb_clicked();
void on_MaxPartsElementEditorList_sb_valueChanged(int value);
void on_DiagramEditor_Grid_PointSize_min_sb_valueChanged(int value);
void on_ElementEditor_Grid_PointSize_min_sb_valueChanged(int value);
private:
void fillLang();

View File

@@ -887,11 +887,25 @@ Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="DiagramEditor_Grid_PointSize_sb">
<item row="0" column="4">
<widget class="QLabel" name="label_18">
<property name="text">
<string>max:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="Label_Diagram_Grid_PointSize">
<property name="text">
<string>Taille des points de la grille de Diagram-Editor : 1 - 5</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QSpinBox" name="DiagramEditor_Grid_PointSize_max_sb">
<property name="minimumSize">
<size>
<width>80</width>
<width>60</width>
<height>0</height>
</size>
</property>
@@ -903,10 +917,79 @@ Vous pouvez spécifier ici la valeur par défaut de ce champ pour les éléments
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="Label_Diagram_Grid_PointSize">
<item row="0" column="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Taille du point Grille : 1 - 5</string>
<string>min:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="DiagramEditor_Grid_PointSize_min_sb">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Taille des points de la grille de l'éditeur d'éléments : 1 - 5</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSpinBox" name="ElementEditor_Grid_PointSize_max_sb">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_21">
<property name="text">
<string>max:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="ElementEditor_Grid_PointSize_min_sb">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>5</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_22">
<property name="text">
<string>min:</string>
</property>
</widget>
</item>