Skip to content

Commit

Permalink
Added ability to change the font size and color of the landscape labe…
Browse files Browse the repository at this point in the history
…ls from the GUI

Fix #2941
  • Loading branch information
alex-w committed Jan 10, 2023
1 parent 37cc18a commit b4a96bf
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 58 deletions.
4 changes: 0 additions & 4 deletions src/core/modules/Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ void Landscape::loadCommon(const QSettings& landscapeIni, const QString& landsca
// This line can then be drawn in all classes with the color specified here. If not specified, don't draw it! (flagged by negative red)
horizonPolygonLineColor=Vec3f(landscapeIni.value("landscape/horizon_line_color", "-1,0,0" ).toString());
}
// we must get label color, this is global. (No sense to make that per-landscape!)
QSettings *config = StelApp::getInstance().getSettings();
labelColor=Vec3f(config->value("landscape/label_color", "0.2,0.8,0.2").toString());
fontSize=config->value("landscape/label_font_size", 18).toInt();
loadLabels(landscapeId);
}

Expand Down
12 changes: 9 additions & 3 deletions src/core/modules/Landscape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ class Landscape
void setFlagShowLabels(const bool b) {labelFader=b;}
//! Get whether labels are displayed
bool getFlagShowLabels() const {return static_cast<bool>(labelFader);}
//! change font and fontsize for landscape labels
void setLabelFontSize(const int size){fontSize=size;}
//! Change font and fontsize for landscape labels
void setLabelFontSize(const int size){ fontSize=size; }
//! Get fontsize for landscape labels
int getLabelFontSize() { return fontSize; }
//! Get color for landscape labels
Vec3f getLabelColor() const { return labelColor; }
//! Set color for landscape labels
void setLabelColor(const Vec3f& c) { labelColor=c; };

//! Get landscape name
QString getName() const {return name;}
Expand Down Expand Up @@ -267,7 +273,7 @@ class Landscape
int fontSize; //! Used for landscape labels (optionally indicating landscape features)
Vec3f labelColor; //! Color for the landscape labels.
unsigned int memorySize; //!< holds an approximate value of memory consumption (for cache cost estimate)
bool multisamplingEnabled_;
bool multisamplingEnabled_;
bool initialized = false;
};

Expand Down
32 changes: 28 additions & 4 deletions src/core/modules/LandscapeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ void LandscapeMgr::init()
setFlagLabels(conf->value("landscape/flag_enable_labels", true).toBool());
setFlagPolyLineDisplayed(conf->value("landscape/flag_polyline_only", false).toBool());
setPolyLineThickness(conf->value("landscape/polyline_thickness", 1).toInt());
setLabelFontSize(conf->value("landscape/label_font_size", 18).toInt());
setLabelColor(Vec3f(conf->value("landscape/label_color", "0.2,0.8,0.2").toString()));

cardinalPoints = new Cardinals();
cardinalPoints->setFlagShow4WCRLabels(conf->value("viewing/flag_cardinal_points", true).toBool());
Expand Down Expand Up @@ -843,6 +845,8 @@ bool LandscapeMgr::setCurrentLandscapeID(const QString& id, const double changeL
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
newLandscape->setFlagShowIllumination(landscape->getFlagShowIllumination());
newLandscape->setFlagShowLabels(landscape->getFlagShowLabels());
newLandscape->setLabelFontSize(landscape->getLabelFontSize());
newLandscape->setLabelColor(landscape->getLabelColor());

// If we have an oldLandscape that is not just swapped back, put that into cache.
if (oldLandscape && oldLandscape!=newLandscape)
Expand Down Expand Up @@ -1136,6 +1140,28 @@ bool LandscapeMgr::getFlagLabels() const
return landscape->getFlagShowLabels();
}

void LandscapeMgr::setLabelFontSize(const int size)
{
landscape->setLabelFontSize(size);
emit labelFontSizeChanged(size);
}

int LandscapeMgr::getLabelFontSize() const
{
return landscape->getLabelFontSize();
}

void LandscapeMgr::setLabelColor(const Vec3f& c)
{
landscape->setLabelColor(c);
emit labelColorChanged(c);
}

Vec3f LandscapeMgr::getLabelColor() const
{
return landscape->getLabelColor();
}

void LandscapeMgr::setFlagLandscapeAutoSelection(bool enableAutoSelect)
{
if(enableAutoSelect != flagLandscapeAutoSelection)
Expand Down Expand Up @@ -1440,14 +1466,14 @@ bool LandscapeMgr::getFlagAtmosphere() const
//! Set flag for displaying Atmosphere
void LandscapeMgr::setFlagAtmosphereNoScatter(const bool noScatter)
{
atmosphereNoScatter=noScatter;
atmosphereNoScatter=noScatter;
emit atmosphereNoScatterChanged(noScatter);
}

//! Get flag for displaying Atmosphere
bool LandscapeMgr::getFlagAtmosphereNoScatter() const
{
return atmosphereNoScatter;
return atmosphereNoScatter;
}

QString LandscapeMgr::getAtmosphereModel() const
Expand Down Expand Up @@ -1584,8 +1610,6 @@ Landscape* LandscapeMgr::createFromFile(const QString& landscapeFile, const QStr
}

landscape->load(landscapeIni, landscapeId);
QSettings *conf=StelApp::getInstance().getSettings();
landscape->setLabelFontSize(conf->value("landscape/label_font_size", 15).toInt());
return landscape;
}

Expand Down
20 changes: 19 additions & 1 deletion src/core/modules/LandscapeMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ class LandscapeMgr : public StelModule
READ getDefaultLandscapeID
WRITE setDefaultLandscapeID
NOTIFY defaultLandscapeChanged)
Q_PROPERTY(int labelFontSize
READ getLabelFontSize
WRITE setLabelFontSize
NOTIFY labelFontSizeChanged)
Q_PROPERTY(Vec3f labelColor
READ getLabelColor
WRITE setLabelColor
NOTIFY labelColorChanged)

public:
LandscapeMgr();
Expand Down Expand Up @@ -412,6 +420,14 @@ public slots:
bool getFlagLabels() const;
//! Set flag for displaying landscape labels
void setFlagLabels(const bool on);
//! Get the fontsize for landscape labels
int getLabelFontSize() const;
//! Set the fontsize for landscape labels
void setLabelFontSize(const int size);
//! Get color for landscape labels
Vec3f getLabelColor() const;
//! Set color for landscape labels
void setLabelColor(const Vec3f& c);

//! Retrieve flag for rendering polygonal line (if one is defined)
bool getFlagPolyLineDisplayed() const {return flagPolyLineDisplayedOnly;}
Expand Down Expand Up @@ -642,6 +658,8 @@ public slots:
void landscapeDisplayedChanged(const bool displayed);
void illuminationDisplayedChanged(const bool displayed);
void labelsDisplayedChanged(const bool displayed);
void labelFontSizeChanged(const int size);
void labelColorChanged(const Vec3f &c);
void flagPolyLineDisplayedChanged(const bool enabled);
void polyLineThicknessChanged(const int thickness);
void flagUseLightPollutionFromDatabaseChanged(const bool usage);
Expand Down Expand Up @@ -726,7 +744,7 @@ private slots:
Landscape* oldLandscape; // Used only during transitions to newly loaded landscape.

// Used to display error messages: e.g. when atmosphere model fails
LinearFader messageFader;
LinearFader messageFader;
QString messageToShow;
QTimer* messageTimer = nullptr;

Expand Down
1 change: 1 addition & 0 deletions src/gui/ConfigurationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ void ConfigurationDialog::saveAllSettings()
conf->setValue("landscape/flag_fog", propMgr->getStelPropertyValue("LandscapeMgr.fogDisplayed").toBool());
conf->setValue("landscape/flag_enable_illumination_layer", propMgr->getStelPropertyValue("LandscapeMgr.illuminationDisplayed").toBool());
conf->setValue("landscape/flag_enable_labels", propMgr->getStelPropertyValue("LandscapeMgr.labelsDisplayed").toBool());
conf->setValue("landscape/label_font_size", propMgr->getStelPropertyValue("LandscapeMgr.labelFontSize").toInt());
conf->setValue("landscape/flag_minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.flagLandscapeUseMinimalBrightness").toBool());
conf->setValue("landscape/flag_landscape_sets_minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.flagLandscapeSetsMinimalBrightness").toBool());
conf->setValue("landscape/minimal_brightness", propMgr->getStelPropertyValue("LandscapeMgr.defaultMinimalBrightness").toFloat());
Expand Down
2 changes: 2 additions & 0 deletions src/gui/ViewDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ void ViewDialog::createDialogContent()
connectCheckBox(ui->landscapeLabelsCheckBox, "actionShow_LandscapeLabels");

connectBoolProperty(ui->landscapePositionCheckBox, "LandscapeMgr.flagLandscapeSetsLocation");
connectColorButton(ui->labelsColorButton, "LandscapeMgr.labelColor", "landscape/label_color");
connectIntProperty(ui->labelsFontSizeSpinBox, "LandscapeMgr.labelFontSize");

connectBoolProperty(ui->landscapeBrightnessCheckBox,"LandscapeMgr.flagLandscapeUseMinimalBrightness");
connect(lmgr,SIGNAL(flagLandscapeUseMinimalBrightnessChanged(bool)),ui->localLandscapeBrightnessCheckBox,SLOT(setEnabled(bool)));
Expand Down
147 changes: 101 additions & 46 deletions src/gui/viewDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,27 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QCheckBox" name="showGroundCheckBox">
<property name="text">
<string>Show ground</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="landscapeLabelsCheckBox">
<property name="text">
<string>Show landscape labels</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="showFogCheckBox">
<property name="text">
<string>Show fog</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="landscapePolylineHorizontalLayout">
<item>
Expand Down Expand Up @@ -4810,12 +4831,50 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="landscapeLabelsCheckBox">
<property name="text">
<string>Show landscape labels</string>
</property>
</widget>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QCheckBox" name="landscapeBrightnessCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Use minimal brightness to leave landscape visible also in darkness</string>
</property>
<property name="text">
<string>Minimal brightness:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="landscapeBrightnessSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Value range 0..1 (landscape is black at night - landscape is fully bright)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="landscapeIlluminationCheckBox">
Expand Down Expand Up @@ -4850,66 +4909,62 @@
</item>
</layout>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item row="1" column="0">
<widget class="QCheckBox" name="useAsDefaultLandscapeCheckBox">
<property name="text">
<string>Use this landscape as default</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="landscapeBrightnessCheckBox">
<widget class="QToolButton" name="labelsColorButton">
<property name="toolTip">
<string>Use minimal brightness to leave landscape visible also in darkness</string>
<string>Color of the landscape labels</string>
</property>
<property name="text">
<string>Minimal brightness:</string>
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="landscapeBrightnessSpinBox">
<property name="enabled">
<bool>false</bool>
<widget class="QLabel" name="labelsFontSizeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<property name="text">
<string>Labels font size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="labelsFontSizeSpinBox">
<property name="minimumSize">
<size>
<width>70</width>
<height>16777215</height>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Value range 0..1 (landscape is black at night - landscape is fully bright)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<double>1.000000000000000</double>
<number>48</number>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
<property name="value">
<number>18</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="showFogCheckBox">
<property name="text">
<string>Show fog</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="showGroundCheckBox">
<property name="text">
<string>Show ground</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="useAsDefaultLandscapeCheckBox">
<property name="text">
<string>Use this landscape as default</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -5518,12 +5573,12 @@
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroupDisplayedDSOTypes">
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
<buttongroup name="buttonGroupDisplayedDSOCatalogs">
<buttongroup name="buttonGroupDisplayedDSOTypes">
<property name="exclusive">
<bool>false</bool>
</property>
Expand Down

0 comments on commit b4a96bf

Please sign in to comment.