Changeset View
Changeset View
Standalone View
Standalone View
ui/annotationwidgets.cpp
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Line(s) | 151 | default: | |||
---|---|---|---|---|---|
152 | ; | 152 | ; | ||
153 | } | 153 | } | ||
154 | // cases not covered yet: return a generic widget | 154 | // cases not covered yet: return a generic widget | ||
155 | return new AnnotationWidget( ann ); | 155 | return new AnnotationWidget( ann ); | ||
156 | } | 156 | } | ||
157 | 157 | | |||
158 | 158 | | |||
159 | AnnotationWidget::AnnotationWidget( Okular::Annotation * ann ) | 159 | AnnotationWidget::AnnotationWidget( Okular::Annotation * ann ) | ||
160 | : QObject(), m_ann( ann ), m_appearanceWidget( nullptr ), m_extraWidget( nullptr ) | 160 | : m_ann( ann ) | ||
161 | { | 161 | { | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | AnnotationWidget::~AnnotationWidget() | 164 | AnnotationWidget::~AnnotationWidget() | ||
165 | { | 165 | { | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | Okular::Annotation::SubType AnnotationWidget::annotationType() const | 168 | Okular::Annotation::SubType AnnotationWidget::annotationType() const | ||
Show All 16 Lines | 184 | if ( m_extraWidget ) | |||
185 | return m_extraWidget; | 185 | return m_extraWidget; | ||
186 | 186 | | |||
187 | m_extraWidget = createExtraWidget(); | 187 | m_extraWidget = createExtraWidget(); | ||
188 | return m_extraWidget; | 188 | return m_extraWidget; | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | void AnnotationWidget::applyChanges() | 191 | void AnnotationWidget::applyChanges() | ||
192 | { | 192 | { | ||
193 | if (m_colorBn) | ||||
tobiasdeiminger: Better handle this in an override in TextAnnotationWidget. | |||||
193 | m_ann->style().setColor( m_colorBn->color() ); | 194 | m_ann->style().setColor( m_colorBn->color() ); | ||
195 | if (m_opacity) | ||||
194 | m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 ); | 196 | m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 ); | ||
195 | } | 197 | } | ||
196 | 198 | | |||
197 | QWidget * AnnotationWidget::createAppearanceWidget() | 199 | QWidget * AnnotationWidget::createAppearanceWidget() | ||
198 | { | 200 | { | ||
199 | QWidget * widget = new QWidget(); | 201 | QWidget * widget = new QWidget(); | ||
200 | QGridLayout * gridlayout = new QGridLayout( widget ); | 202 | QGridLayout * gridlayout = new QGridLayout( widget ); | ||
201 | 203 | if ( hasColorButton() ) | |||
204 | { | ||||
202 | QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget ); | 205 | QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget ); | ||
203 | gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); | 206 | gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); | ||
204 | m_colorBn = new KColorButton( widget ); | 207 | m_colorBn = new KColorButton( widget ); | ||
205 | m_colorBn->setColor( m_ann->style().color() ); | 208 | m_colorBn->setColor( m_ann->style().color() ); | ||
206 | tmplabel->setBuddy( m_colorBn ); | 209 | tmplabel->setBuddy( m_colorBn ); | ||
207 | gridlayout->addWidget( m_colorBn, 0, 1 ); | 210 | gridlayout->addWidget( m_colorBn, 0, 1 ); | ||
208 | 211 | } | |||
209 | tmplabel = new QLabel( i18n( "&Opacity:" ), widget ); | 212 | if ( hasOpacityBox() ) | ||
213 | { | ||||
214 | QLabel * tmplabel = new QLabel( i18n( "&Opacity:" ), widget ); | ||||
210 | gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); | 215 | gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); | ||
211 | m_opacity = new QSpinBox( widget ); | 216 | m_opacity = new QSpinBox( widget ); | ||
212 | m_opacity->setRange( 0, 100 ); | 217 | m_opacity->setRange( 0, 100 ); | ||
213 | m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) ); | 218 | m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) ); | ||
214 | m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) ); | 219 | m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) ); | ||
215 | tmplabel->setBuddy( m_opacity ); | 220 | tmplabel->setBuddy( m_opacity ); | ||
216 | gridlayout->addWidget( m_opacity, 1, 1 ); | 221 | gridlayout->addWidget( m_opacity, 1, 1 ); | ||
222 | } | ||||
Really only if TextAnnotation::Unknown? What about TextAnnotation::Callout? tobiasdeiminger: Really only if TextAnnotation::Unknown? What about TextAnnotation::Callout? | |||||
Those generic signal slot connections must not be dependent on if it's a TextAnnotation. tobiasdeiminger: Those generic signal slot connections must not be dependent on if it's a TextAnnotation. | |||||
217 | 223 | | |||
218 | QWidget * styleWidget = createStyleWidget(); | 224 | QWidget * styleWidget = createStyleWidget(); | ||
219 | if ( styleWidget ) | 225 | if ( styleWidget ) | ||
220 | gridlayout->addWidget( styleWidget, 2, 0, 1, 2 ); | 226 | gridlayout->addWidget( styleWidget, 2, 0, 1, 2 ); | ||
221 | 227 | | |||
222 | gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 ); | 228 | gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 ); | ||
223 | 229 | | |||
230 | if ( m_colorBn ) | ||||
224 | connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); | 231 | connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); | ||
232 | if ( m_opacity ) | ||||
225 | connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) ); | 233 | connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) ); | ||
226 | 234 | | |||
227 | return widget; | 235 | return widget; | ||
228 | } | 236 | } | ||
229 | 237 | | |||
230 | QWidget * AnnotationWidget::createStyleWidget() | 238 | QWidget * AnnotationWidget::createStyleWidget() | ||
231 | { | 239 | { | ||
232 | return nullptr; | 240 | return nullptr; | ||
233 | } | 241 | } | ||
234 | 242 | | |||
235 | QWidget * AnnotationWidget::createExtraWidget() | 243 | QWidget * AnnotationWidget::createExtraWidget() | ||
236 | { | 244 | { | ||
237 | return nullptr; | 245 | return nullptr; | ||
238 | } | 246 | } | ||
239 | 247 | | |||
240 | 248 | | |||
241 | TextAnnotationWidget::TextAnnotationWidget( Okular::Annotation * ann ) | 249 | TextAnnotationWidget::TextAnnotationWidget( Okular::Annotation * ann ) | ||
242 | : AnnotationWidget( ann ), m_pixmapSelector( nullptr ) | 250 | : AnnotationWidget( ann ) | ||
243 | { | 251 | { | ||
244 | m_textAnn = static_cast< Okular::TextAnnotation * >( ann ); | 252 | m_textAnn = static_cast< Okular::TextAnnotation * >( ann ); | ||
245 | } | 253 | } | ||
246 | 254 | | |||
247 | QWidget * TextAnnotationWidget::createStyleWidget() | 255 | QWidget * TextAnnotationWidget::createStyleWidget() | ||
248 | { | 256 | { | ||
249 | QWidget * widget = new QWidget(); | 257 | QWidget * widget = new QWidget(); | ||
250 | QVBoxLayout * lay = new QVBoxLayout( widget ); | 258 | QVBoxLayout * layout = new QVBoxLayout( widget ); | ||
251 | lay->setMargin( 0 ); | 259 | layout->setMargin( 0 ); | ||
260 | | ||||
261 | if ( m_textAnn->textType() == Okular::TextAnnotation::Linked ) | ||||
262 | { | ||||
263 | createPopupNoteStyleUi( widget, layout ); | ||||
264 | } | ||||
265 | else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) | ||||
266 | { | ||||
267 | if ( isTypewriter() ) | ||||
268 | createTypewriterStyleUi( widget, layout ); | ||||
269 | else | ||||
270 | createInlineNoteStyleUi( widget, layout ); | ||||
Leave connect where it was before, don't return early and delegate widget setup to private methods createPopupNoteStyleWidget, createInlineNoteStyleWidget, createTypeWriterStyleWidget. tobiasdeiminger: Leave connect where it was before, don't return early and delegate widget setup to private… | |||||
271 | } | ||||
272 | | ||||
273 | return widget; | ||||
274 | } | ||||
275 | | ||||
276 | bool TextAnnotationWidget::hasColorButton() const { | ||||
277 | return !isTypewriter(); | ||||
278 | } | ||||
279 | | ||||
280 | bool TextAnnotationWidget::hasOpacityBox() const { | ||||
281 | return !isTypewriter(); | ||||
282 | } | ||||
252 | 283 | | |||
284 | void TextAnnotationWidget::applyChanges() | ||||
285 | { | ||||
286 | AnnotationWidget::applyChanges(); | ||||
253 | if ( m_textAnn->textType() == Okular::TextAnnotation::Linked ) | 287 | if ( m_textAnn->textType() == Okular::TextAnnotation::Linked ) | ||
254 | { | 288 | { | ||
289 | m_textAnn->setTextIcon( m_pixmapSelector->icon() ); | ||||
290 | } | ||||
291 | else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) | ||||
292 | { | ||||
293 | m_textAnn->setTextFont( m_fontReq->font() ); | ||||
294 | if ( !isTypewriter() ) | ||||
295 | { | ||||
296 | m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() ); | ||||
297 | m_textAnn->style().setWidth( m_spinWidth->value() ); | ||||
298 | } | ||||
299 | } | ||||
300 | } | ||||
301 | | ||||
302 | void TextAnnotationWidget::createPopupNoteStyleUi( QWidget * widget, QVBoxLayout * layout ) { | ||||
255 | QGroupBox * gb = new QGroupBox( widget ); | 303 | QGroupBox * gb = new QGroupBox( widget ); | ||
256 | lay->addWidget( gb ); | 304 | layout->addWidget( gb ); | ||
257 | gb->setTitle( i18n( "Icon" ) ); | | |||
258 | QHBoxLayout * gblay = new QHBoxLayout( gb ); | 305 | QHBoxLayout * gblay = new QHBoxLayout( gb ); | ||
259 | m_pixmapSelector = new PixmapPreviewSelector( gb ); | 306 | gb->setTitle( i18n( "Icon" ) ); | ||
260 | gblay->addWidget( m_pixmapSelector ); | 307 | addPixmapSelector( gb, gblay ); | ||
308 | } | ||||
309 | | ||||
310 | void TextAnnotationWidget::createInlineNoteStyleUi( QWidget * widget, QVBoxLayout * layout ) { | ||||
311 | QGridLayout * innerlay = new QGridLayout(); | ||||
312 | layout->addLayout( innerlay ); | ||||
313 | addFontRequester(widget, innerlay); | ||||
314 | addTextAlignComboBox(widget, innerlay); | ||||
315 | addWidthSpinBox(widget, innerlay); | ||||
316 | } | ||||
261 | 317 | | |||
318 | void TextAnnotationWidget::createTypewriterStyleUi( QWidget * widget, QVBoxLayout * layout ) { | ||||
319 | QGridLayout * innerlay = new QGridLayout(); | ||||
320 | layout->addLayout( innerlay ); | ||||
321 | addFontRequester(widget, innerlay); | ||||
322 | } | ||||
323 | | ||||
324 | void TextAnnotationWidget::addPixmapSelector( QWidget * widget, QLayout * layout ) | ||||
325 | { | ||||
326 | m_pixmapSelector = new PixmapPreviewSelector( widget ); | ||||
327 | layout->addWidget( m_pixmapSelector ); | ||||
262 | m_pixmapSelector->addItem( i18n( "Comment" ), QStringLiteral("Comment") ); | 328 | m_pixmapSelector->addItem( i18n( "Comment" ), QStringLiteral("Comment") ); | ||
263 | m_pixmapSelector->addItem( i18n( "Help" ), QStringLiteral("Help") ); | 329 | m_pixmapSelector->addItem( i18n( "Help" ), QStringLiteral("Help") ); | ||
264 | m_pixmapSelector->addItem( i18n( "Insert" ), QStringLiteral("Insert") ); | 330 | m_pixmapSelector->addItem( i18n( "Insert" ), QStringLiteral("Insert") ); | ||
265 | m_pixmapSelector->addItem( i18n( "Key" ), QStringLiteral("Key") ); | 331 | m_pixmapSelector->addItem( i18n( "Key" ), QStringLiteral("Key") ); | ||
266 | m_pixmapSelector->addItem( i18n( "New Paragraph" ), QStringLiteral("NewParagraph") ); | 332 | m_pixmapSelector->addItem( i18n( "New Paragraph" ), QStringLiteral("NewParagraph") ); | ||
267 | m_pixmapSelector->addItem( i18n( "Note" ), QStringLiteral("Note") ); | 333 | m_pixmapSelector->addItem( i18n( "Note" ), QStringLiteral("Note") ); | ||
268 | m_pixmapSelector->addItem( i18n( "Paragraph" ), QStringLiteral("Paragraph") ); | 334 | m_pixmapSelector->addItem( i18n( "Paragraph" ), QStringLiteral("Paragraph") ); | ||
269 | m_pixmapSelector->setIcon( m_textAnn->textIcon() ); | 335 | m_pixmapSelector->setIcon( m_textAnn->textIcon() ); | ||
270 | | ||||
271 | connect( m_pixmapSelector, &PixmapPreviewSelector::iconChanged, this, &AnnotationWidget::dataChanged ); | 336 | connect( m_pixmapSelector, &PixmapPreviewSelector::iconChanged, this, &AnnotationWidget::dataChanged ); | ||
272 | } | 337 | } | ||
273 | else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) | | |||
274 | { | | |||
275 | QGridLayout * innerlay = new QGridLayout(); | | |||
276 | lay->addLayout( innerlay ); | | |||
277 | 338 | | |||
339 | void TextAnnotationWidget::addFontRequester( QWidget * widget, QGridLayout * layout ) | ||||
340 | { | ||||
278 | QLabel * tmplabel = new QLabel( i18n( "Font:" ), widget ); | 341 | QLabel * tmplabel = new QLabel( i18n( "Font:" ), widget ); | ||
279 | innerlay->addWidget( tmplabel, 0, 0 ); | 342 | layout->addWidget( tmplabel, 0, 0 ); | ||
280 | m_fontReq = new KFontRequester( widget ); | 343 | m_fontReq = new KFontRequester( widget ); | ||
281 | innerlay->addWidget( m_fontReq, 0, 1 ); | 344 | layout->addWidget( m_fontReq, 0, 1 ); | ||
282 | m_fontReq->setFont( m_textAnn->textFont() ); | 345 | m_fontReq->setFont( m_textAnn->textFont() ); | ||
346 | connect( m_fontReq, &KFontRequester::fontSelected, this, &AnnotationWidget::dataChanged ); | ||||
347 | } | ||||
283 | 348 | | |||
284 | tmplabel = new QLabel( i18n( "Align:" ), widget ); | 349 | void TextAnnotationWidget::addTextAlignComboBox( QWidget * widget, QGridLayout * layout ) | ||
285 | innerlay->addWidget( tmplabel, 1, 0 ); | 350 | { | ||
351 | QLabel * tmplabel = new QLabel( i18n( "Align:" ), widget ); | ||||
352 | layout->addWidget( tmplabel, 1, 0 ); | ||||
286 | m_textAlign = new KComboBox( widget ); | 353 | m_textAlign = new KComboBox( widget ); | ||
287 | innerlay->addWidget( m_textAlign, 1, 1 ); | 354 | layout->addWidget( m_textAlign, 1, 1 ); | ||
288 | m_textAlign->addItem( i18n("Left") ); | 355 | m_textAlign->addItem( i18n("Left") ); | ||
289 | m_textAlign->addItem( i18n("Center") ); | 356 | m_textAlign->addItem( i18n("Center") ); | ||
290 | m_textAlign->addItem( i18n("Right") ); | 357 | m_textAlign->addItem( i18n("Right") ); | ||
291 | m_textAlign->setCurrentIndex( m_textAnn->inplaceAlignment() ); | 358 | m_textAlign->setCurrentIndex( m_textAnn->inplaceAlignment() ); | ||
359 | connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) ); | ||||
360 | } | ||||
292 | 361 | | |||
293 | tmplabel = new QLabel( i18n( "Border Width:" ), widget ); | 362 | void TextAnnotationWidget::addWidthSpinBox( QWidget * widget, QGridLayout * layout ) | ||
294 | innerlay->addWidget( tmplabel, 2, 0, Qt::AlignRight ); | 363 | { | ||
364 | QLabel * tmplabel = new QLabel( i18n( "Border Width:" ), widget ); | ||||
365 | layout->addWidget( tmplabel, 2, 0, Qt::AlignRight ); | ||||
295 | m_spinWidth = new QDoubleSpinBox( widget ); | 366 | m_spinWidth = new QDoubleSpinBox( widget ); | ||
296 | innerlay->addWidget( m_spinWidth, 2, 1 ); | 367 | layout->addWidget( m_spinWidth, 2, 1 ); | ||
297 | tmplabel->setBuddy( m_spinWidth ); | 368 | tmplabel->setBuddy( m_spinWidth ); | ||
298 | m_spinWidth->setRange( 0, 100 ); | 369 | m_spinWidth->setRange( 0, 100 ); | ||
299 | m_spinWidth->setValue( m_textAnn->style().width() ); | 370 | m_spinWidth->setValue( m_textAnn->style().width() ); | ||
300 | m_spinWidth->setSingleStep( 0.1 ); | 371 | m_spinWidth->setSingleStep( 0.1 ); | ||
301 | | ||||
302 | connect( m_fontReq, &KFontRequester::fontSelected, this, &AnnotationWidget::dataChanged ); | | |||
303 | | ||||
304 | connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) ); | | |||
305 | connect( m_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); | 372 | connect( m_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); | ||
306 | } | 373 | } | ||
307 | 374 | | |||
308 | return widget; | | |||
309 | } | | |||
310 | | ||||
311 | void TextAnnotationWidget::applyChanges() | | |||
312 | { | | |||
313 | AnnotationWidget::applyChanges(); | | |||
314 | if ( m_textAnn->textType() == Okular::TextAnnotation::Linked ) | | |||
315 | { | | |||
316 | m_textAnn->setTextIcon( m_pixmapSelector->icon() ); | | |||
317 | } | | |||
318 | else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) | | |||
319 | { | | |||
320 | m_textAnn->setTextFont( m_fontReq->font() ); | | |||
321 | m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() ); | | |||
322 | m_textAnn->style().setWidth( m_spinWidth->value() ); | | |||
323 | } | | |||
324 | } | | |||
325 | | ||||
326 | | ||||
327 | StampAnnotationWidget::StampAnnotationWidget( Okular::Annotation * ann ) | 375 | StampAnnotationWidget::StampAnnotationWidget( Okular::Annotation * ann ) | ||
328 | : AnnotationWidget( ann ), m_pixmapSelector( nullptr ) | 376 | : AnnotationWidget( ann ), m_pixmapSelector( nullptr ) | ||
329 | { | 377 | { | ||
330 | m_stampAnn = static_cast< Okular::StampAnnotation * >( ann ); | 378 | m_stampAnn = static_cast< Okular::StampAnnotation * >( ann ); | ||
331 | } | 379 | } | ||
332 | 380 | | |||
333 | QWidget * StampAnnotationWidget::createStyleWidget() | 381 | QWidget * StampAnnotationWidget::createStyleWidget() | ||
334 | { | 382 | { | ||
▲ Show 20 Lines • Show All 442 Lines • Show Last 20 Lines |
Better handle this in an override in TextAnnotationWidget.