[Gui] Fix color bar position and text (#10552)

* [Gui] Fix ColorBar position and labelling

* [Gui] Improve formatting

* [Gui] ColorBar adjusts if user squashes window height

* [Gui] Changes following feedback
This commit is contained in:
Syres916
2023-09-20 00:35:22 +01:00
committed by GitHub
parent ab4abab53d
commit 4e466355f1
4 changed files with 172 additions and 12 deletions

View File

@@ -75,6 +75,8 @@ void DlgSettingsViewColor::saveSettings()
ui->checkMidColor->onSave();
ui->TreeEditColor->onSave();
ui->TreeActiveColor->onSave();
ui->CbLabelColor->onSave();
ui->CbLabelTextSize->onSave();
}
void DlgSettingsViewColor::loadSettings()
@@ -89,7 +91,9 @@ void DlgSettingsViewColor::loadSettings()
ui->checkMidColor->onRestore();
ui->TreeEditColor->onRestore();
ui->TreeActiveColor->onRestore();
ui->CbLabelColor->onRestore();
ui->CbLabelTextSize->onRestore();
if (ui->radioButtonSimple->isChecked())
onRadioButtonSimpleToggled(true);
else if(ui->radioButtonGradient->isChecked())

View File

@@ -407,7 +407,140 @@
</widget>
</item>
<item>
<spacer name="spacer_3">
<widget class="QGroupBox" name="groupColorBar">
<property name="title">
<string>Color Bar</string>
</property>
<layout class="QGridLayout">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_CbLabelColor">
<property name="minimumSize">
<size>
<width>240</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Label text color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefColorButton" name="CbLabelColor">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Color Bar (used in Mesh and FEM Wbs) Label text color</string>
</property>
<property name="color" stdset="0">
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</property>
<property name="prefEntry" stdset="0">
<cstring>CbLabelColor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_CbLabelTextSize">
<property name="text">
<string>Label text size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::PrefSpinBox" name="CbLabelTextSize">
<property name="toolTip">
<string>Color Bar (used in Mesh and FEM Wbs) Label Text Size</string>
</property>
<property name="alignment">
<set>Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>36</number>
</property>
<property name="value">
<number>13</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>CbLabelTextSize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>View</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<spacer name="spacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@@ -442,6 +575,11 @@
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>SelectionColor_Background</tabstop>

View File

@@ -123,15 +123,23 @@ float SoFCColorBarBase::getBounds(const SbVec2s& size, float& fMinX, float&fMinY
// The cam height is set in SoFCColorBarBase::getBoundingWidth to 10.
// Therefore the normalized coordinates are in the range [-5, +5] x [-5ratio, +5ratio] if ratio > 1
// and [-5ratio, +5ratio] x [-5, +5] if ratio < 1.
// We don't want the whole height covered by the color bar (to have e.g space to the axis cross)
// thus we take as base 4.
float baseYValue = 4.0f;
// We don't want the whole height covered by the color bar (to have e.g space to the axis cross
// and the Navigation Cube) thus we take as base 3 or if the height reduces significantly it is 2.5.
float baseYValue;
if (fRatio > 3.0f) {
baseYValue = 2.5f;
}
else {
baseYValue = 3.0f;
}
float barWidth = 0.5f;
// we want the color bar at the rightmost position, therefore we take 5 as base
fMinX = 5.0f * fRatio; // must be scaled with the ratio to assure it stays at the right
// we want the color bar at the rightmost position, therefore we take 4.95 as base
fMinX = 4.95f * fRatio; // must be scaled with the ratio to assure it stays at the right
fMaxX = fMinX + barWidth;
fMinY = -baseYValue;
fMinY = -baseYValue - 0.6f; // Extend shortened bar towards axis cross
fMaxY = baseYValue; // bar has the height of almost whole window height
if (fRatio < 1.0f) {

View File

@@ -28,6 +28,7 @@
# include <Inventor/fields/SoMFString.h>
# include <Inventor/nodes/SoBaseColor.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoFont.h>
# include <Inventor/nodes/SoIndexedFaceSet.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoText2.h>
@@ -35,6 +36,7 @@
# include <Inventor/nodes/SoTransparencyType.h>
#endif
#include <Base/Parameter.h>
#include "SoFCColorGradient.h"
#include "SoTextLabel.h"
#include "DlgSettingsColorGradientImp.h"
@@ -99,19 +101,27 @@ void SoFCColorGradient::setMarkerLabel(const SoMFString& label)
SbVec2f minPt = _bbox.getMin();
float fStep = (maxPt[1] - minPt[1]) / ((float)num - 1);
auto trans = new SoTransform;
ParameterGrp::handle hGrp = Gui::WindowParameter::getDefaultParameter()->GetGroup("View");
auto LabelTextSize = hGrp->GetInt("CbLabelTextSize", 13);
auto LabelTextColor =
App::Color((uint32_t)hGrp->GetUnsigned("CbLabelColor", 0xffffffff));
auto textFont = new SoFont;
auto color = new SoBaseColor;
textFont->name.setValue("Helvetica,Arial,Times New Roman");
textFont->size.setValue(LabelTextSize);
trans->translation.setValue(maxPt[0] + 0.1f, maxPt[1] - 0.05f + fStep, 0.0f);
color->rgb.setValue(LabelTextColor.r,LabelTextColor.g,LabelTextColor.b);
labels->addChild(trans);
labels->addChild(color);
labels->addChild(textFont);
for (int i = 0; i < num; i++) {
auto trans = new SoTransform;
auto color = new SoBaseColor;
auto text2 = new SoColorBarLabel;
trans->translation.setValue(0, -fStep, 0);
color->rgb.setValue(0, 0, 0);
text2->string.setValue(label[i]);
labels->addChild(trans);
labels->addChild(color);
labels->addChild(text2);
}
}