Changeset View
Changeset View
Standalone View
Standalone View
src/kdefrontend/widgets/LabelWidget.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 61 | LabelWidget::LabelWidget(QWidget* parent) : QWidget(parent), m_dateTimeMenu(new QMenu(this)) { | |||
---|---|---|---|---|---|
110 | 110 | | |||
111 | ui.cbBorderStyle->addItem(i18n("No line")); | 111 | ui.cbBorderStyle->addItem(i18n("No line")); | ||
112 | ui.cbBorderStyle->addItem(i18n("Solid line")); | 112 | ui.cbBorderStyle->addItem(i18n("Solid line")); | ||
113 | ui.cbBorderStyle->addItem(i18n("Dash line")); | 113 | ui.cbBorderStyle->addItem(i18n("Dash line")); | ||
114 | ui.cbBorderStyle->addItem(i18n("Dot line")); | 114 | ui.cbBorderStyle->addItem(i18n("Dot line")); | ||
115 | ui.cbBorderStyle->addItem(i18n("Dash dot line")); | 115 | ui.cbBorderStyle->addItem(i18n("Dash dot line")); | ||
116 | ui.cbBorderStyle->addItem(i18n("Dash dot dot line")); | 116 | ui.cbBorderStyle->addItem(i18n("Dash dot dot line")); | ||
117 | 117 | | |||
118 | ui.kcbBackgroundColor->setAlphaChannelEnabled(true); | ||||
119 | ui.kcbBackgroundColor->setColor(QColor(0,0,0, 0)); // transparent | ||||
120 | ui.kcbFontColor->setAlphaChannelEnabled(true); | ||||
121 | ui.kcbFontColor->setColor(QColor(255,255,255, 255)); // black | ||||
122 | ui.kcbBorderColor->setAlphaChannelEnabled(true); | ||||
123 | ui.kcbBorderColor->setColor(QColor(255,255,255, 255)); // black | ||||
124 | | ||||
118 | //check whether the used latex compiler is available. | 125 | //check whether the used latex compiler is available. | ||
119 | //Following logic is implemented (s.a. LabelWidget::teXUsedChanged()): | 126 | //Following logic is implemented (s.a. LabelWidget::teXUsedChanged()): | ||
120 | //1. in case latex was used to generate the text label in the stored project | 127 | //1. in case latex was used to generate the text label in the stored project | ||
121 | //and no latex is available on the target system, latex button is toggled and | 128 | //and no latex is available on the target system, latex button is toggled and | ||
122 | //the user still can switch to the non-latex mode. | 129 | //the user still can switch to the non-latex mode. | ||
123 | //2. in case the label was in the non-latex mode and no latex is available, | 130 | //2. in case the label was in the non-latex mode and no latex is available, | ||
124 | //deactivate the latex button so the user cannot switch to this mode. | 131 | //deactivate the latex button so the user cannot switch to this mode. | ||
125 | m_teXEnabled = TeXRenderer::enabled(); | 132 | m_teXEnabled = TeXRenderer::enabled(); | ||
126 | 133 | | |||
127 | #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING | 134 | #ifdef HAVE_KF5_SYNTAX_HIGHLIGHTING | ||
128 | m_highlighter = new KSyntaxHighlighting::SyntaxHighlighter(ui.teLabel->document()); | 135 | m_highlighter = new KSyntaxHighlighting::SyntaxHighlighter(ui.teLabel->document()); | ||
129 | m_highlighter->setDefinition(m_repository.definitionForName(QLatin1String("LaTeX"))); | 136 | m_highlighter->setDefinition(m_repository.definitionForName(QLatin1String("LaTeX"))); | ||
130 | m_highlighter->setTheme( (palette().color(QPalette::Base).lightness() < 128) | 137 | m_highlighter->setTheme( (palette().color(QPalette::Base).lightness() < 128) | ||
131 | ? m_repository.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) | 138 | ? m_repository.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme) | ||
132 | : m_repository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme) ); | 139 | : m_repository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme) ); | ||
133 | #endif | 140 | #endif | ||
134 | 141 | | |||
135 | //SLOTS | 142 | //SLOTS | ||
136 | // text properties | 143 | // text properties | ||
137 | connect(ui.tbTexUsed, SIGNAL(clicked(bool)), this, SLOT(teXUsedChanged(bool)) ); | 144 | connect(ui.tbTexUsed, &QToolButton::clicked, this, &LabelWidget::teXUsedChanged ); | ||
138 | connect(ui.teLabel, SIGNAL(textChanged()), this, SLOT(textChanged())); | 145 | connect(ui.teLabel, &ResizableTextEdit::textChanged, this, &LabelWidget::textChanged); | ||
139 | connect(ui.teLabel, SIGNAL(currentCharFormatChanged(QTextCharFormat)), | 146 | connect(ui.teLabel, &ResizableTextEdit::currentCharFormatChanged, this, &LabelWidget::charFormatChanged); | ||
140 | this, SLOT(charFormatChanged(QTextCharFormat))); | 147 | connect(ui.kcbFontColor, &KColorButton::changed, this, &LabelWidget::fontColorChanged); | ||
141 | connect(ui.kcbFontColor, SIGNAL(changed(QColor)), this, SLOT(fontColorChanged(QColor))); | 148 | connect(ui.kcbBackgroundColor, &KColorButton::changed, this, &LabelWidget::backgroundColorChanged); | ||
142 | connect(ui.kcbBackgroundColor, SIGNAL(changed(QColor)), this, SLOT(backgroundColorChanged(QColor))); | 149 | connect(ui.tbFontBold, &QToolButton::clicked, this, &LabelWidget::fontBoldChanged); | ||
143 | connect(ui.tbFontBold, SIGNAL(clicked(bool)), this, SLOT(fontBoldChanged(bool))); | 150 | connect(ui.tbFontItalic, &QToolButton::clicked, this, &LabelWidget::fontItalicChanged); | ||
144 | connect(ui.tbFontItalic, SIGNAL(clicked(bool)), this, SLOT(fontItalicChanged(bool))); | 151 | connect(ui.tbFontUnderline, &QToolButton::clicked, this, &LabelWidget::fontUnderlineChanged); | ||
145 | connect(ui.tbFontUnderline, SIGNAL(clicked(bool)), this, SLOT(fontUnderlineChanged(bool))); | 152 | connect(ui.tbFontStrikeOut, &QToolButton::clicked, this, &LabelWidget::fontStrikeOutChanged); | ||
146 | connect(ui.tbFontStrikeOut, SIGNAL(clicked(bool)), this, SLOT(fontStrikeOutChanged(bool))); | 153 | connect(ui.tbFontSuperScript, &QToolButton::clicked, this, &LabelWidget::fontSuperScriptChanged); | ||
147 | connect(ui.tbFontSuperScript, SIGNAL(clicked(bool)), this, SLOT(fontSuperScriptChanged(bool))); | 154 | connect(ui.tbFontSubScript, &QToolButton::clicked, this, &LabelWidget::fontSubScriptChanged); | ||
148 | connect(ui.tbFontSubScript, SIGNAL(clicked(bool)), this, SLOT(fontSubScriptChanged(bool))); | 155 | connect(ui.tbSymbols, &QToolButton::clicked, this, &LabelWidget::charMenu); | ||
149 | connect(ui.tbSymbols, SIGNAL(clicked(bool)), this, SLOT(charMenu())); | 156 | connect(ui.tbDateTime, &QToolButton::clicked, this, &LabelWidget::dateTimeMenu); | ||
150 | connect(ui.tbDateTime, SIGNAL(clicked(bool)), this, SLOT(dateTimeMenu())); | 157 | connect(m_dateTimeMenu, &QMenu::triggered, this, &LabelWidget::insertDateTime ); | ||
151 | connect(m_dateTimeMenu, SIGNAL(triggered(QAction*)), this, SLOT(insertDateTime(QAction*)) ); | 158 | connect(ui.kfontRequester, &KFontRequester::fontSelected, this, &LabelWidget::fontChanged); | ||
152 | connect(ui.kfontRequester, SIGNAL(fontSelected(QFont)), this, SLOT(fontChanged(QFont))); | 159 | connect(ui.kfontRequesterTeX, &KFontRequester::fontSelected, this, &LabelWidget::teXFontChanged); | ||
153 | connect(ui.kfontRequesterTeX, SIGNAL(fontSelected(QFont)), this, SLOT(teXFontChanged(QFont))); | 160 | connect(ui.sbFontSize, QOverload<int>::of(&QSpinBox::valueChanged), this, &LabelWidget::fontSizeChanged); | ||
154 | connect(ui.sbFontSize, SIGNAL(valueChanged(int)), this, SLOT(fontSizeChanged(int)) ); | | |||
155 | 161 | | |||
156 | // geometry | 162 | // geometry | ||
157 | connect( ui.cbPositionX, SIGNAL(currentIndexChanged(int)), this, SLOT(positionXChanged(int)) ); | 163 | connect( ui.cbPositionX, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &LabelWidget::positionXChanged); | ||
158 | connect( ui.cbPositionY, SIGNAL(currentIndexChanged(int)), this, SLOT(positionYChanged(int)) ); | 164 | connect( ui.cbPositionY, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &LabelWidget::positionYChanged); | ||
159 | connect( ui.sbPositionX, SIGNAL(valueChanged(double)), this, SLOT(customPositionXChanged(double)) ); | 165 | connect( ui.sbPositionX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &LabelWidget::customPositionXChanged); | ||
160 | connect( ui.sbPositionY, SIGNAL(valueChanged(double)), this, SLOT(customPositionYChanged(double)) ); | 166 | connect( ui.sbPositionY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &LabelWidget::customPositionYChanged); | ||
161 | connect( ui.cbHorizontalAlignment, SIGNAL(currentIndexChanged(int)), this, SLOT(horizontalAlignmentChanged(int)) ); | 167 | connect( ui.cbHorizontalAlignment, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &LabelWidget::horizontalAlignmentChanged); | ||
162 | connect( ui.cbVerticalAlignment, SIGNAL(currentIndexChanged(int)), this, SLOT(verticalAlignmentChanged(int)) ); | 168 | connect( ui.cbVerticalAlignment, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &LabelWidget::verticalAlignmentChanged); | ||
163 | connect( ui.sbRotation, SIGNAL(valueChanged(int)), this, SLOT(rotationChanged(int)) ); | 169 | connect( ui.sbRotation, QOverload<int>::of(&QSpinBox::valueChanged), this, &LabelWidget::rotationChanged); | ||
164 | connect( ui.sbOffsetX, SIGNAL(valueChanged(double)), this, SLOT(offsetXChanged(double)) ); | 170 | connect( ui.sbOffsetX, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &LabelWidget::offsetXChanged); | ||
165 | connect( ui.sbOffsetY, SIGNAL(valueChanged(double)), this, SLOT(offsetYChanged(double)) ); | 171 | connect( ui.sbOffsetY, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &LabelWidget::offsetYChanged); | ||
166 | 172 | | |||
167 | connect( ui.chbVisible, SIGNAL(clicked(bool)), this, SLOT(visibilityChanged(bool)) ); | 173 | connect( ui.chbVisible, &QCheckBox::clicked, this, &LabelWidget::visibilityChanged); | ||
168 | 174 | | |||
169 | //Border | 175 | //Border | ||
170 | connect(ui.cbBorderShape, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &LabelWidget::borderShapeChanged); | 176 | connect(ui.cbBorderShape, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &LabelWidget::borderShapeChanged); | ||
171 | connect(ui.cbBorderStyle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &LabelWidget::borderStyleChanged); | 177 | connect(ui.cbBorderStyle, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &LabelWidget::borderStyleChanged); | ||
172 | connect(ui.kcbBorderColor, &KColorButton::changed, this, &LabelWidget::borderColorChanged); | 178 | connect(ui.kcbBorderColor, &KColorButton::changed, this, &LabelWidget::borderColorChanged); | ||
173 | connect(ui.sbBorderWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &LabelWidget::borderWidthChanged); | 179 | connect(ui.sbBorderWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &LabelWidget::borderWidthChanged); | ||
174 | connect(ui.sbBorderOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &LabelWidget::borderOpacityChanged); | 180 | connect(ui.sbBorderOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &LabelWidget::borderOpacityChanged); | ||
175 | 181 | | |||
Show All 17 Lines | 187 | void LabelWidget::setLabels(QList<TextLabel*> labels) { | |||
193 | 199 | | |||
194 | initConnections(); | 200 | initConnections(); | ||
195 | } | 201 | } | ||
196 | 202 | | |||
197 | void LabelWidget::setAxes(QList<Axis*> axes) { | 203 | void LabelWidget::setAxes(QList<Axis*> axes) { | ||
198 | m_labelsList.clear(); | 204 | m_labelsList.clear(); | ||
199 | for (auto* axis : axes) { | 205 | for (auto* axis : axes) { | ||
200 | m_labelsList.append(axis->title()); | 206 | m_labelsList.append(axis->title()); | ||
201 | connect(axis, SIGNAL(titleOffsetXChanged(qreal)), this, SLOT(labelOffsetxChanged(qreal)) ); | 207 | connect(axis, &Axis::titleOffsetXChanged, this, &LabelWidget::labelOffsetxChanged); | ||
202 | connect(axis, SIGNAL(titleOffsetYChanged(qreal)), this, SLOT(labelOffsetyChanged(qreal)) ); | 208 | connect(axis, &Axis::titleOffsetYChanged, this, &LabelWidget::labelOffsetyChanged ); | ||
203 | connect(axis->title(), SIGNAL(rotationAngleChanged(qreal)), this, SLOT(labelRotationAngleChanged(qreal)) ); | 209 | connect(axis->title(), &TextLabel::rotationAngleChanged, this, &LabelWidget::labelRotationAngleChanged ); | ||
204 | } | 210 | } | ||
205 | 211 | | |||
206 | m_axesList = axes; | 212 | m_axesList = axes; | ||
207 | m_label = m_labelsList.first(); | 213 | m_label = m_labelsList.first(); | ||
208 | 214 | | |||
209 | this->load(); | 215 | this->load(); | ||
210 | initConnections(); | 216 | initConnections(); | ||
211 | } | 217 | } | ||
212 | 218 | | |||
213 | void LabelWidget::initConnections() const { | 219 | void LabelWidget::initConnections() const { | ||
214 | connect( m_label, SIGNAL(textWrapperChanged(TextLabel::TextWrapper)), | 220 | connect( m_label, &TextLabel::textWrapperChanged, this, &LabelWidget::labelTextWrapperChanged); | ||
215 | this, SLOT(labelTextWrapperChanged(TextLabel::TextWrapper)) ); | 221 | connect( m_label, &TextLabel::teXImageUpdated, this, &LabelWidget::labelTeXImageUpdated); | ||
216 | connect( m_label, SIGNAL(teXImageUpdated(bool)), this, SLOT(labelTeXImageUpdated(bool)) ); | 222 | connect( m_label, &TextLabel::teXFontChanged, this, &LabelWidget::labelTeXFontChanged); | ||
217 | connect( m_label, SIGNAL(teXFontChanged(QFont)), | 223 | connect( m_label, &TextLabel::fontColorChanged, this, &LabelWidget::labelFontColorChanged); | ||
218 | this, SLOT(labelTeXFontChanged(QFont)) ); | 224 | connect (m_label, &TextLabel::backgroundColorChanged, this, &LabelWidget::labelBackgroundColorChanged); | ||
219 | connect( m_label, SIGNAL(fontColorChanged(QColor)), | 225 | connect( m_label, &TextLabel::positionChanged, this, &LabelWidget::labelPositionChanged); | ||
220 | this, SLOT(labelFontColorChanged(QColor)) ); | 226 | connect( m_label, &TextLabel::horizontalAlignmentChanged, this, &LabelWidget::labelHorizontalAlignmentChanged); | ||
221 | connect( m_label, SIGNAL(positionChanged(TextLabel::PositionWrapper)), | 227 | connect( m_label, &TextLabel::verticalAlignmentChanged, this, &LabelWidget::labelVerticalAlignmentChanged); | ||
222 | this, SLOT(labelPositionChanged(TextLabel::PositionWrapper)) ); | 228 | connect( m_label, &TextLabel::rotationAngleChanged, this, &LabelWidget::labelRotationAngleChanged); | ||
223 | connect( m_label, SIGNAL(horizontalAlignmentChanged(TextLabel::HorizontalAlignment)), | | |||
224 | this, SLOT(labelHorizontalAlignmentChanged(TextLabel::HorizontalAlignment)) ); | | |||
225 | connect( m_label, SIGNAL(verticalAlignmentChanged(TextLabel::VerticalAlignment)), | | |||
226 | this, SLOT(labelVerticalAlignmentChanged(TextLabel::VerticalAlignment)) ); | | |||
227 | connect( m_label, SIGNAL(rotationAngleChanged(qreal)), this, SLOT(labelRotationAngleChanged(qreal)) ); | | |||
228 | connect(m_label, &TextLabel::borderShapeChanged, this, &LabelWidget::labelBorderShapeChanged); | 229 | connect(m_label, &TextLabel::borderShapeChanged, this, &LabelWidget::labelBorderShapeChanged); | ||
229 | connect(m_label, &TextLabel::borderPenChanged, this, &LabelWidget::labelBorderPenChanged); | 230 | connect(m_label, &TextLabel::borderPenChanged, this, &LabelWidget::labelBorderPenChanged); | ||
230 | connect(m_label, &TextLabel::borderOpacityChanged, this, &LabelWidget::labelBorderOpacityChanged); | 231 | connect(m_label, &TextLabel::borderOpacityChanged, this, &LabelWidget::labelBorderOpacityChanged); | ||
231 | connect( m_label, SIGNAL(visibleChanged(bool)), this, SLOT(labelVisibleChanged(bool)) ); | 232 | connect( m_label, &TextLabel::visibleChanged, this, &LabelWidget::labelVisibleChanged); | ||
233 | connect( m_label, &TextLabel::visibleChanged, this, &LabelWidget::labelVisibleChanged); | ||||
232 | } | 234 | } | ||
233 | 235 | | |||
234 | /*! | 236 | /*! | ||
235 | * enables/disables the "fixed label"-mode, used when displaying | 237 | * enables/disables the "fixed label"-mode, used when displaying | ||
236 | * the properties of axis' title label. | 238 | * the properties of axis' title label. | ||
237 | * In this mode, in the "geometry"-part only the offset (offset to the axis) | 239 | * In this mode, in the "geometry"-part only the offset (offset to the axis) | ||
238 | * and the rotation of the label are available. | 240 | * and the rotation of the label are available. | ||
239 | */ | 241 | */ | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 299 | } else { | |||
298 | //save an empty string instead of a html-string with empty body, if no text available in QTextEdit | 300 | //save an empty string instead of a html-string with empty body, if no text available in QTextEdit | ||
299 | QString text; | 301 | QString text; | ||
300 | if (ui.teLabel->toPlainText().isEmpty()) | 302 | if (ui.teLabel->toPlainText().isEmpty()) | ||
301 | text.clear(); | 303 | text.clear(); | ||
302 | else | 304 | else | ||
303 | text = ui.teLabel->toHtml(); | 305 | text = ui.teLabel->toHtml(); | ||
304 | 306 | | |||
305 | TextLabel::TextWrapper wrapper(text, false); | 307 | TextLabel::TextWrapper wrapper(text, false); | ||
306 | for (auto* label : m_labelsList) | 308 | for (auto* label : m_labelsList) { | ||
307 | label->setText(wrapper); | 309 | label->setText(wrapper); | ||
310 | // Don't set FontColor, because the font color is already in the html code | ||||
311 | // of the text. The font color is used to change the color for unformated | ||||
312 | // text like from themes | ||||
313 | // label->setFontColor(ui.kcbFontColor->color()); | ||||
314 | // label->setBackgroundColor(ui.kcbBackgroundColor->color()); | ||||
315 | } | ||||
308 | } | 316 | } | ||
309 | } | 317 | } | ||
310 | 318 | | |||
319 | /*! | ||||
320 | * \brief LabelWidget::charFormatChanged | ||||
321 | * \param format | ||||
322 | * Used to update the colors, font,... in the color font widgets to show the style of the selected text | ||||
323 | */ | ||||
311 | void LabelWidget::charFormatChanged(const QTextCharFormat& format) { | 324 | void LabelWidget::charFormatChanged(const QTextCharFormat& format) { | ||
312 | if (m_initializing) | 325 | if (m_initializing) | ||
313 | return; | 326 | return; | ||
314 | 327 | | |||
315 | if (ui.tbTexUsed->isChecked()) | 328 | if (ui.tbTexUsed->isChecked()) | ||
316 | return; | 329 | return; | ||
317 | 330 | | |||
318 | m_initializing = true; | 331 | m_initializing = true; | ||
319 | 332 | | |||
320 | // update button state | 333 | // update button state | ||
321 | ui.tbFontBold->setChecked(ui.teLabel->fontWeight() == QFont::Bold); | 334 | ui.tbFontBold->setChecked(ui.teLabel->fontWeight() == QFont::Bold); | ||
322 | ui.tbFontItalic->setChecked(ui.teLabel->fontItalic()); | 335 | ui.tbFontItalic->setChecked(ui.teLabel->fontItalic()); | ||
323 | ui.tbFontUnderline->setChecked(ui.teLabel->fontUnderline()); | 336 | ui.tbFontUnderline->setChecked(ui.teLabel->fontUnderline()); | ||
324 | ui.tbFontStrikeOut->setChecked(format.fontStrikeOut()); | 337 | ui.tbFontStrikeOut->setChecked(format.fontStrikeOut()); | ||
325 | ui.tbFontSuperScript->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSuperScript); | 338 | ui.tbFontSuperScript->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSuperScript); | ||
326 | ui.tbFontSubScript->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSubScript); | 339 | ui.tbFontSubScript->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSubScript); | ||
327 | 340 | | |||
328 | //font and colors | 341 | //font and colors | ||
329 | if (format.foreground().color().isValid()) | 342 | if (format.foreground().color().isValid()) | ||
330 | ui.kcbFontColor->setColor(format.foreground().color()); | 343 | ui.kcbFontColor->setColor(format.foreground().color()); | ||
331 | else | 344 | else | ||
332 | ui.kcbFontColor->setColor(m_label->fontColor()); | 345 | ui.kcbFontColor->setColor(m_label->fontColor()); | ||
346 | | ||||
347 | if (format.background().color().isValid()) | ||||
333 | ui.kcbBackgroundColor->setColor(format.background().color()); | 348 | ui.kcbBackgroundColor->setColor(format.background().color()); | ||
349 | else | ||||
350 | ui.kcbBackgroundColor->setColor(m_label->backgroundColor()); | ||||
351 | | ||||
334 | ui.kfontRequester->setFont(format.font()); | 352 | ui.kfontRequester->setFont(format.font()); | ||
335 | 353 | | |||
336 | m_initializing = false; | 354 | m_initializing = false; | ||
337 | } | 355 | } | ||
338 | 356 | | |||
339 | void LabelWidget::teXUsedChanged(bool checked) { | 357 | void LabelWidget::teXUsedChanged(bool checked) { | ||
340 | //hide text editing elements if TeX-option is used | 358 | //hide text editing elements if TeX-option is used | ||
341 | ui.tbFontBold->setVisible(!checked); | 359 | ui.tbFontBold->setVisible(!checked); | ||
342 | ui.tbFontItalic->setVisible(!checked); | 360 | ui.tbFontItalic->setVisible(!checked); | ||
343 | 361 | | |||
344 | //TODO: https://bugreports.qt.io/browse/QTBUG-25420 | 362 | //TODO: https://bugreports.qt.io/browse/QTBUG-25420 | ||
345 | // ui.tbFontUnderline->setVisible(!checked); | 363 | // ui.tbFontUnderline->setVisible(!checked); | ||
346 | // ui.tbFontStrikeOut->setVisible(!checked); | 364 | // ui.tbFontStrikeOut->setVisible(!checked); | ||
347 | 365 | | |||
348 | ui.tbFontSubScript->setVisible(!checked); | 366 | ui.tbFontSubScript->setVisible(!checked); | ||
349 | ui.tbFontSuperScript->setVisible(!checked); | 367 | ui.tbFontSuperScript->setVisible(!checked); | ||
350 | ui.tbSymbols->setVisible(!checked); | 368 | ui.tbSymbols->setVisible(!checked); | ||
351 | 369 | | |||
352 | ui.lFont->setVisible(!checked); | 370 | ui.lFont->setVisible(!checked); | ||
353 | ui.kfontRequester->setVisible(!checked); | 371 | ui.kfontRequester->setVisible(!checked); | ||
354 | 372 | | |||
373 | //TODO: | ||||
374 | //for normal text we need to hide the background color because of QTBUG-25420 | ||||
375 | ui.kcbBackgroundColor->setVisible(checked); | ||||
376 | ui.lBackgroundColor->setVisible(checked); | ||||
377 | | ||||
355 | if (checked) { | 378 | if (checked) { | ||
356 | //reset all applied formattings when switching from html to tex mode | 379 | //reset all applied formattings when switching from html to tex mode | ||
357 | QTextCursor cursor = ui.teLabel->textCursor(); | 380 | QTextCursor cursor = ui.teLabel->textCursor(); | ||
358 | int position = cursor.position(); | 381 | int position = cursor.position(); | ||
359 | ui.teLabel->selectAll(); | 382 | ui.teLabel->selectAll(); | ||
360 | QTextCharFormat format; | 383 | QTextCharFormat format; | ||
361 | ui.teLabel->setCurrentCharFormat(format); | 384 | ui.teLabel->setCurrentCharFormat(format); | ||
362 | cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, position); | 385 | cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, position); | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
416 | } | 439 | } | ||
417 | 440 | | |||
418 | void LabelWidget::fontColorChanged(const QColor& color) { | 441 | void LabelWidget::fontColorChanged(const QColor& color) { | ||
419 | if (m_initializing) | 442 | if (m_initializing) | ||
420 | return; | 443 | return; | ||
421 | 444 | | |||
422 | //if no selection is done, apply the new color for the whole label, | 445 | //if no selection is done, apply the new color for the whole label, | ||
423 | //apply to the currently selected part of the text only otherwise | 446 | //apply to the currently selected part of the text only otherwise | ||
424 | QTextCursor cursor = ui.teLabel->textCursor(); | 447 | QTextCursor c = ui.teLabel->textCursor(); | ||
425 | if (cursor.selection().isEmpty()) | 448 | if (c.selectedText().isEmpty()) | ||
426 | for (auto* label : m_labelsList) | 449 | ui.teLabel->selectAll(); | ||
427 | label->setFontColor(color); | 450 | | ||
428 | else | | |||
429 | ui.teLabel->setTextColor(color); | 451 | ui.teLabel->setTextColor(color); | ||
430 | } | 452 | } | ||
431 | 453 | | |||
432 | void LabelWidget::backgroundColorChanged(const QColor& color) { | 454 | void LabelWidget::backgroundColorChanged(const QColor& color) { | ||
433 | if (m_initializing) | 455 | if (m_initializing) | ||
434 | return; | 456 | return; | ||
435 | 457 | | |||
458 | QTextCursor c = ui.teLabel->textCursor(); | ||||
459 | if (c.selectedText().isEmpty()) | ||||
460 | ui.teLabel->selectAll(); | ||||
461 | | ||||
436 | ui.teLabel->setTextBackgroundColor(color); | 462 | ui.teLabel->setTextBackgroundColor(color); | ||
437 | for (auto* label : m_labelsList) | | |||
438 | label->setBackgroundColor(color); | | |||
439 | } | 463 | } | ||
440 | 464 | | |||
441 | void LabelWidget::fontSizeChanged(int value) { | 465 | void LabelWidget::fontSizeChanged(int value) { | ||
442 | if (m_initializing) | 466 | if (m_initializing) | ||
443 | return; | 467 | return; | ||
444 | 468 | | |||
469 | QTextCursor c = ui.teLabel->textCursor(); | ||||
470 | if (c.selectedText().isEmpty()) | ||||
471 | ui.teLabel->selectAll(); | ||||
472 | | ||||
445 | QFont font = m_label->teXFont(); | 473 | QFont font = m_label->teXFont(); | ||
446 | font.setPointSize(value); | 474 | font.setPointSize(value); | ||
447 | for (auto* label : m_labelsList) | 475 | for (auto* label : m_labelsList) | ||
448 | label->setTeXFont(font); | 476 | label->setTeXFont(font); | ||
449 | } | 477 | } | ||
450 | 478 | | |||
451 | void LabelWidget::fontBoldChanged(bool checked) { | 479 | void LabelWidget::fontBoldChanged(bool checked) { | ||
452 | if (m_initializing) | 480 | if (m_initializing) | ||
453 | return; | 481 | return; | ||
454 | 482 | | |||
483 | QTextCursor c = ui.teLabel->textCursor(); | ||||
484 | if (c.selectedText().isEmpty()) | ||||
485 | ui.teLabel->selectAll(); | ||||
486 | | ||||
455 | if (checked) | 487 | if (checked) | ||
456 | ui.teLabel->setFontWeight(QFont::Bold); | 488 | ui.teLabel->setFontWeight(QFont::Bold); | ||
457 | else | 489 | else | ||
458 | ui.teLabel->setFontWeight(QFont::Normal); | 490 | ui.teLabel->setFontWeight(QFont::Normal); | ||
459 | } | 491 | } | ||
460 | 492 | | |||
461 | void LabelWidget::fontItalicChanged(bool checked) { | 493 | void LabelWidget::fontItalicChanged(bool checked) { | ||
462 | if (m_initializing) | 494 | if (m_initializing) | ||
463 | return; | 495 | return; | ||
464 | 496 | | |||
497 | QTextCursor c = ui.teLabel->textCursor(); | ||||
498 | if (c.selectedText().isEmpty()) | ||||
499 | ui.teLabel->selectAll(); | ||||
500 | | ||||
465 | ui.teLabel->setFontItalic(checked); | 501 | ui.teLabel->setFontItalic(checked); | ||
466 | } | 502 | } | ||
467 | 503 | | |||
468 | void LabelWidget::fontUnderlineChanged(bool checked) { | 504 | void LabelWidget::fontUnderlineChanged(bool checked) { | ||
469 | if (m_initializing) | 505 | if (m_initializing) | ||
470 | return; | 506 | return; | ||
471 | 507 | | |||
508 | QTextCursor c = ui.teLabel->textCursor(); | ||||
509 | if (c.selectedText().isEmpty()) | ||||
510 | ui.teLabel->selectAll(); | ||||
511 | | ||||
472 | ui.teLabel->setFontUnderline(checked); | 512 | ui.teLabel->setFontUnderline(checked); | ||
473 | } | 513 | } | ||
474 | 514 | | |||
475 | void LabelWidget::fontStrikeOutChanged(bool checked) { | 515 | void LabelWidget::fontStrikeOutChanged(bool checked) { | ||
476 | if (m_initializing) | 516 | if (m_initializing) | ||
477 | return; | 517 | return; | ||
478 | 518 | | |||
519 | QTextCursor c = ui.teLabel->textCursor(); | ||||
520 | if (c.selectedText().isEmpty()) | ||||
521 | ui.teLabel->selectAll(); | ||||
522 | | ||||
479 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | 523 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | ||
480 | format.setFontStrikeOut(checked); | 524 | format.setFontStrikeOut(checked); | ||
481 | ui.teLabel->setCurrentCharFormat(format); | 525 | ui.teLabel->setCurrentCharFormat(format); | ||
482 | } | 526 | } | ||
483 | 527 | | |||
484 | void LabelWidget::fontSuperScriptChanged(bool checked) { | 528 | void LabelWidget::fontSuperScriptChanged(bool checked) { | ||
485 | if (m_initializing) | 529 | if (m_initializing) | ||
486 | return; | 530 | return; | ||
487 | 531 | | |||
532 | QTextCursor c = ui.teLabel->textCursor(); | ||||
533 | if (c.selectedText().isEmpty()) | ||||
534 | ui.teLabel->selectAll(); | ||||
535 | | ||||
488 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | 536 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | ||
489 | if (checked) | 537 | if (checked) | ||
490 | format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); | 538 | format.setVerticalAlignment(QTextCharFormat::AlignSuperScript); | ||
491 | else | 539 | else | ||
492 | format.setVerticalAlignment(QTextCharFormat::AlignNormal); | 540 | format.setVerticalAlignment(QTextCharFormat::AlignNormal); | ||
493 | 541 | | |||
494 | ui.teLabel->setCurrentCharFormat(format); | 542 | ui.teLabel->setCurrentCharFormat(format); | ||
495 | } | 543 | } | ||
496 | 544 | | |||
497 | void LabelWidget::fontSubScriptChanged(bool checked) { | 545 | void LabelWidget::fontSubScriptChanged(bool checked) { | ||
498 | if (m_initializing) | 546 | if (m_initializing) | ||
499 | return; | 547 | return; | ||
500 | 548 | | |||
549 | QTextCursor c = ui.teLabel->textCursor(); | ||||
550 | if (c.selectedText().isEmpty()) | ||||
551 | ui.teLabel->selectAll(); | ||||
552 | | ||||
501 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | 553 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | ||
502 | if (checked) | 554 | if (checked) | ||
503 | format.setVerticalAlignment(QTextCharFormat::AlignSubScript); | 555 | format.setVerticalAlignment(QTextCharFormat::AlignSubScript); | ||
504 | else | 556 | else | ||
505 | format.setVerticalAlignment(QTextCharFormat::AlignNormal); | 557 | format.setVerticalAlignment(QTextCharFormat::AlignNormal); | ||
506 | 558 | | |||
507 | ui.teLabel->setCurrentCharFormat(format); | 559 | ui.teLabel->setCurrentCharFormat(format); | ||
508 | } | 560 | } | ||
509 | 561 | | |||
510 | void LabelWidget::fontChanged(const QFont& font) { | 562 | void LabelWidget::fontChanged(const QFont& font) { | ||
511 | if (m_initializing) | 563 | if (m_initializing) | ||
512 | return; | 564 | return; | ||
513 | 565 | | |||
514 | // underline and strike-out not included | 566 | QTextCursor c = ui.teLabel->textCursor(); | ||
515 | ui.teLabel->setFontFamily(font.family()); | 567 | if (c.selectedText().isEmpty()) | ||
516 | ui.teLabel->setFontPointSize(font.pointSize()); | 568 | ui.teLabel->selectAll(); | ||
517 | ui.teLabel->setFontItalic(font.italic()); | 569 | | ||
518 | ui.teLabel->setFontWeight(font.weight()); | 570 | // use format instead of using ui.teLabel->setFontFamily(font.family()); | ||
571 | // because this calls after every command textChanged() which is inefficient | ||||
572 | QTextCharFormat format = ui.teLabel->currentCharFormat(); | ||||
573 | format.setFontFamily(font.family()); | ||||
574 | format.setFontPointSize(font.pointSize()); | ||||
575 | format.setFontItalic(font.italic()); | ||||
576 | format.setFontWeight(font.weight()); | ||||
577 | if (font.underline()) | ||||
578 | format.setUnderlineStyle(QTextCharFormat::UnderlineStyle::SingleUnderline); | ||||
579 | if (font.strikeOut()) // anytime true. don't know why | ||||
580 | format.setFontStrikeOut(font.strikeOut()); | ||||
581 | ui.teLabel->setCurrentCharFormat(format); | ||||
519 | } | 582 | } | ||
520 | 583 | | |||
521 | void LabelWidget::teXFontChanged(const QFont& font) { | 584 | void LabelWidget::teXFontChanged(const QFont& font) { | ||
522 | if (m_initializing) | 585 | if (m_initializing) | ||
523 | return; | 586 | return; | ||
524 | 587 | | |||
525 | for (auto* label : m_labelsList) | 588 | for (auto* label : m_labelsList) | ||
526 | label->setTeXFont(font); | 589 | label->setTeXFont(font); | ||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Line(s) | 861 | void LabelWidget::labelPositionChanged(const TextLabel::PositionWrapper& position) { | |||
799 | m_initializing = true; | 862 | m_initializing = true; | ||
800 | ui.sbPositionX->setValue( Worksheet::convertFromSceneUnits(position.point.x(), Worksheet::Centimeter) ); | 863 | ui.sbPositionX->setValue( Worksheet::convertFromSceneUnits(position.point.x(), Worksheet::Centimeter) ); | ||
801 | ui.sbPositionY->setValue( Worksheet::convertFromSceneUnits(position.point.y(), Worksheet::Centimeter) ); | 864 | ui.sbPositionY->setValue( Worksheet::convertFromSceneUnits(position.point.y(), Worksheet::Centimeter) ); | ||
802 | ui.cbPositionX->setCurrentIndex( position.horizontalPosition ); | 865 | ui.cbPositionX->setCurrentIndex( position.horizontalPosition ); | ||
803 | ui.cbPositionY->setCurrentIndex( position.verticalPosition ); | 866 | ui.cbPositionY->setCurrentIndex( position.verticalPosition ); | ||
804 | m_initializing = false; | 867 | m_initializing = false; | ||
805 | } | 868 | } | ||
806 | 869 | | |||
870 | void LabelWidget::labelBackgroundColorChanged(const QColor color) { | ||||
871 | m_initializing = true; | ||||
872 | ui.kcbBackgroundColor->setColor(color); | ||||
873 | m_initializing = false; | ||||
874 | } | ||||
875 | | ||||
807 | void LabelWidget::labelHorizontalAlignmentChanged(TextLabel::HorizontalAlignment index) { | 876 | void LabelWidget::labelHorizontalAlignmentChanged(TextLabel::HorizontalAlignment index) { | ||
808 | m_initializing = true; | 877 | m_initializing = true; | ||
809 | ui.cbHorizontalAlignment->setCurrentIndex(index); | 878 | ui.cbHorizontalAlignment->setCurrentIndex(index); | ||
810 | m_initializing = false; | 879 | m_initializing = false; | ||
811 | } | 880 | } | ||
812 | 881 | | |||
813 | void LabelWidget::labelVerticalAlignmentChanged(TextLabel::VerticalAlignment index) { | 882 | void LabelWidget::labelVerticalAlignmentChanged(TextLabel::VerticalAlignment index) { | ||
814 | m_initializing = true; | 883 | m_initializing = true; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 940 | void LabelWidget::load() { | |||
875 | m_initializing = true; | 944 | m_initializing = true; | ||
876 | 945 | | |||
877 | ui.chbVisible->setChecked(m_label->isVisible()); | 946 | ui.chbVisible->setChecked(m_label->isVisible()); | ||
878 | 947 | | |||
879 | //Text/TeX | 948 | //Text/TeX | ||
880 | ui.tbTexUsed->setChecked( (bool) m_label->text().teXUsed ); | 949 | ui.tbTexUsed->setChecked( (bool) m_label->text().teXUsed ); | ||
881 | if (m_label->text().teXUsed) | 950 | if (m_label->text().teXUsed) | ||
882 | ui.teLabel->setText(m_label->text().text); | 951 | ui.teLabel->setText(m_label->text().text); | ||
883 | else | 952 | else { | ||
884 | ui.teLabel->setHtml(m_label->text().text); | 953 | ui.teLabel->setHtml(m_label->text().text); | ||
954 | ui.teLabel->selectAll(); // must be done to retrieve font | ||||
955 | ui.kfontRequester->setFont(ui.teLabel->currentFont()); | ||||
956 | } | ||||
885 | 957 | | |||
886 | ui.kcbFontColor->setColor(m_label->fontColor()); | 958 | QTextCharFormat format = ui.teLabel->currentCharFormat(); // don't use colors from the textlabel, but | ||
887 | ui.kcbBackgroundColor->setColor(m_label->backgroundColor()); | 959 | ui.kcbFontColor->setColor(format.foreground().color()); | ||
960 | ui.kcbBackgroundColor->setColor(format.background().color()); | ||||
888 | this->teXUsedChanged(m_label->text().teXUsed); | 961 | this->teXUsedChanged(m_label->text().teXUsed); | ||
889 | ui.kfontRequesterTeX->setFont(m_label->teXFont()); | 962 | ui.kfontRequesterTeX->setFont(format.font()); | ||
890 | ui.sbFontSize->setValue( m_label->teXFont().pointSize() ); | 963 | ui.sbFontSize->setValue( m_label->teXFont().pointSize() ); | ||
891 | 964 | | |||
892 | //move the cursor to the end and set the focus to the text editor | 965 | //move the cursor to the end and set the focus to the text editor | ||
893 | QTextCursor cursor = ui.teLabel->textCursor(); | 966 | QTextCursor cursor = ui.teLabel->textCursor(); | ||
894 | cursor.movePosition(QTextCursor::End); | 967 | cursor.movePosition(QTextCursor::End); | ||
895 | ui.teLabel->setTextCursor(cursor); | 968 | ui.teLabel->setTextCursor(cursor); | ||
896 | ui.teLabel->setFocus(); | 969 | ui.teLabel->setFocus(); | ||
897 | 970 | | |||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |