labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ReferenceLineDock.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : ReferenceLineDock.cpp
3  Project : LabPlot
4  Description : Dock widget for the reference line on the plot
5  --------------------------------------------------------------------
6  Copyright : (C) 2020 Alexander Semke (alexander.semke@web.de)
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the Free Software *
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
24  * Boston, MA 02110-1301 USA *
25  * *
26  ***************************************************************************/
27 
28 #include "ReferenceLineDock.h"
31 
33 #include "kdefrontend/GuiTools.h"
34 
35 #include <KLocalizedString>
36 #include <KConfig>
37 
38 ReferenceLineDock::ReferenceLineDock(QWidget* parent) : BaseDock(parent) {
39  ui.setupUi(this);
40  m_leName = ui.leName;
41  m_leComment = ui.leComment;
42 
43  ui.cbOrientation->addItem(i18n("Horizontal"));
44  ui.cbOrientation->addItem(i18n("Vertical"));
45 
46  ui.lePosition->setValidator( new QDoubleValidator(ui.lePosition) );
47 
49  ui.sbLineWidth->setLocale(numberLocale);
50 
51  //SLOTS
52  //General
53  connect(ui.leName, &QLineEdit::textChanged, this, &ReferenceLineDock::nameChanged);
54  connect(ui.leComment, &QLineEdit::textChanged, this, &ReferenceLineDock::commentChanged);
55 
56  connect(ui.cbOrientation, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ReferenceLineDock::orientationChanged);
57  connect(ui.lePosition, &QLineEdit::textChanged, this, &ReferenceLineDock::positionChanged);
58  connect(ui.chkVisible, &QCheckBox::clicked, this, &ReferenceLineDock::visibilityChanged);
59 
60  connect(ui.cbLineStyle, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ReferenceLineDock::styleChanged);
61  connect(ui.kcbLineColor, &KColorButton::changed, this, &ReferenceLineDock::colorChanged);
62  connect(ui.sbLineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ReferenceLineDock::widthChanged);
63  connect(ui.sbLineOpacity, QOverload<int>::of(&QSpinBox::valueChanged), this, &ReferenceLineDock::opacityChanged);
64 
65  m_initializing = true;
66  GuiTools::updatePenStyles(ui.cbLineStyle, QColor(Qt::black));
67  m_initializing = false;
68 }
69 
71  m_initializing = true;
72  m_linesList = list;
73  m_line = list.first();
74  m_aspect = list.first();
75  Q_ASSERT(m_line);
76 
77  //if there is more then one point in the list, disable the comment and name widgets in "general"
78  if (list.size() == 1) {
79  ui.lName->setEnabled(true);
80  ui.leName->setEnabled(true);
81  ui.lComment->setEnabled(true);
82  ui.leComment->setEnabled(true);
83  ui.leName->setText(m_line->name());
84  ui.leComment->setText(m_line->comment());
85  } else {
86  ui.lName->setEnabled(false);
87  ui.leName->setEnabled(false);
88  ui.lComment->setEnabled(false);
89  ui.leComment->setEnabled(false);
90  ui.leName->setText(QString());
91  ui.leComment->setText(QString());
92  }
93  ui.leName->setStyleSheet("");
94  ui.leName->setToolTip("");
95 
96  //show the properties of the first reference line
97  this->load();
98 
99  //SIGNALs/SLOTs
102 
103  //position
106 
107  //line
110 }
111 
112 /*
113  * updates the locale in the widgets. called when the application settins are changed.
114  */
117  ui.sbLineWidth->setLocale(numberLocale);
118 
119  Lock lock(m_initializing);
120  ui.lePosition->setText(numberLocale.toString(m_line->position()));
121 }
122 
123 //**********************************************************
124 //*** SLOTs for changes triggered in ReferenceLineDock *****
125 //**********************************************************
126 //Position
128  auto orientation{ReferenceLine::Orientation(index)};
129  if (orientation == ReferenceLine::Orientation::Horizontal)
130  ui.lPosition->setText(QLatin1String("y:"));
131  else
132  ui.lPosition->setText(QLatin1String("x:"));
133 
134  if (m_initializing)
135  return;
136 
137  for (auto* line : m_linesList)
138  line->setOrientation(orientation);
139 }
140 
142  if (m_initializing)
143  return;
144 
145  bool ok;
147  const double pos{ numberLocale.toDouble(ui.lePosition->text(), &ok) };
148  if (ok) {
149  for (auto* line : m_linesList)
150  line->setPosition(pos);
151  }
152 }
153 
154 //Line
156  if (m_initializing)
157  return;
158 
159  const auto penStyle = Qt::PenStyle(index);
160  QPen pen;
161  for (auto* line : m_linesList) {
162  pen = line->pen();
163  pen.setStyle(penStyle);
164  line->setPen(pen);
165  }
166 }
167 
168 void ReferenceLineDock::colorChanged(const QColor& color) {
169  if (m_initializing)
170  return;
171 
172  for (auto* line : m_linesList) {
173  QPen pen = line->pen();
174  pen.setColor(color);
175  line->setPen(pen);
176  }
177 
178  m_initializing = true;
179  GuiTools::updatePenStyles(ui.cbLineStyle, color);
180  m_initializing = false;
181 }
182 
184  if (m_initializing)
185  return;
186 
187  for (auto* line : m_linesList) {
188  QPen pen = line->pen();
190  line->setPen(pen);
191  }
192 }
193 
195  if (m_initializing)
196  return;
197 
198  qreal opacity = (double)value/100.;
199  for (auto* line : m_linesList)
200  line->setOpacity(opacity);
201 }
202 
204  if (m_initializing)
205  return;
206 
207  for (auto* line : m_linesList)
208  line->setVisible(state);
209 }
210 
211 //*************************************************************
212 //******* SLOTs for changes triggered in ReferenceLine ********
213 //*************************************************************
215  if (m_line != aspect)
216  return;
217 
218  m_initializing = true;
219  if (aspect->name() != ui.leName->text())
220  ui.leName->setText(aspect->name());
221  else if (aspect->comment() != ui.leComment->text())
222  ui.leComment->setText(aspect->comment());
223 
224  m_initializing = false;
225 }
226 
228  m_initializing = true;
229  ui.lePosition->setText(QString::number(position));
230  m_initializing = false;
231 }
232 
234  m_initializing = true;
235  ui.cbOrientation->setCurrentIndex(static_cast<int>(orientation));
236  m_initializing = false;
237 }
238 
239 void ReferenceLineDock::linePenChanged(const QPen& pen) {
240  m_initializing = true;
241  ui.cbLineStyle->setCurrentIndex( (int)pen.style());
242  ui.kcbLineColor->setColor( pen.color());
243  GuiTools::updatePenStyles(ui.cbLineStyle, pen.color());
244  ui.sbLineWidth->setValue( Worksheet::convertFromSceneUnits( pen.widthF(), Worksheet::Unit::Point) );
245  m_initializing = false;
246 }
247 
249  m_initializing = true;
250  ui.sbLineOpacity->setValue( round(opacity*100.0) );
251  m_initializing = false;
252 }
253 
255  m_initializing = true;
256  ui.chkVisible->setChecked(on);
257  m_initializing = false;
258 }
259 
260 //**********************************************************
261 //******************** SETTINGS ****************************
262 //**********************************************************
264  if (!m_line)
265  return;
266 
267  m_initializing = true;
268 
270  ui.cbOrientation->setCurrentIndex(static_cast<int>(m_line->orientation()));
271  ui.lePosition->setText(numberLocale.toString(m_line->position()));
272  ui.cbLineStyle->setCurrentIndex( (int) m_line->pen().style() );
273  ui.kcbLineColor->setColor( m_line->pen().color() );
274  ui.sbLineWidth->setValue( Worksheet::convertFromSceneUnits(m_line->pen().widthF(), Worksheet::Unit::Point) );
275  ui.sbLineOpacity->setValue( round(m_line->opacity()*100.0) );
276  ui.chkVisible->setChecked( m_line->isVisible() );
277 
278  m_initializing = false;
279 }
static const QRgb black
Definition: ImageEditor.cpp:38
Base class of all persistent objects in a Project.
void aspectDescriptionChanged(const AbstractAspect *)
Emitted after the name, comment or caption spec have changed.
QString name() const
QString comment() const
QLineEdit * m_leName
Definition: BaseDock.h:68
QLineEdit * m_leComment
Definition: BaseDock.h:69
void commentChanged()
Definition: BaseDock.cpp:61
AbstractAspect * m_aspect
Definition: BaseDock.h:70
bool m_initializing
Definition: BaseDock.h:67
void nameChanged()
Definition: BaseDock.cpp:47
static void updatePenStyles(QComboBox *, const QColor &)
Definition: GuiTools.cpp:56
void lineDescriptionChanged(const AbstractAspect *)
void lineOpacityChanged(qreal)
void updateLocale() override
void lineVisibilityChanged(bool)
ReferenceLineDock(QWidget *)
Ui::ReferenceLineDock ui
void linePenChanged(const QPen &)
void setReferenceLines(QList< ReferenceLine * >)
void colorChanged(const QColor &)
void lineOrientationChanged(ReferenceLine::Orientation)
ReferenceLine * m_line
void linePositionChanged(double)
QList< ReferenceLine * > m_linesList
void visibleChanged(bool)
void penChanged(const QPen &)
bool isVisible() const override
Return whether the element is (at least) partially visible.
void orientationChanged(Orientation)
void opacityChanged(qreal)
void positionChanged(double)
static double convertFromSceneUnits(const double value, const Worksheet::Unit unit)
Definition: Worksheet.cpp:131
static double convertToSceneUnits(const double value, const Worksheet::Unit unit)
Definition: Worksheet.cpp:113
#define SET_NUMBER_LOCALE
Definition: macros.h:75
#define i18n(m)
Definition: nsl_common.h:38
Definition: BaseDock.h:40