annotationwidgets.cpp 25.9 KB
Newer Older
Pino Toscano's avatar
Pino Toscano committed
1 2 3 4 5 6 7 8 9
/***************************************************************************
 *   Copyright (C) 2006 by Pino Toscano <pino@kde.org>                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

Albert Astals Cid's avatar
Albert Astals Cid committed
10 11
#include "annotationwidgets.h"

Pino Toscano's avatar
Pino Toscano committed
12
// qt/kde includes
13
#include <qcheckbox.h>
Pino Toscano's avatar
Pino Toscano committed
14 15 16
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
Pino Toscano's avatar
Pino Toscano committed
17
#include <qspinbox.h>
Pino Toscano's avatar
Pino Toscano committed
18
#include <qvariant.h>
19
#include <kcolorbutton.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
20
#include <kcombobox.h>
21
#include <kfontrequester.h>
22
#include <kicon.h>
Pino Toscano's avatar
Pino Toscano committed
23 24
#include <kiconloader.h>
#include <klocale.h>
25
#include <knuminput.h>
Pino Toscano's avatar
Pino Toscano committed
26
#include <kdebug.h>
Pino Toscano's avatar
Pino Toscano committed
27

28
#include "core/document.h"
29 30
#include "guiutils.h"

31 32
#define FILEATTACH_ICONSIZE 48

33 34 35 36 37
PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent )
  : QWidget( parent )
{
    QHBoxLayout * mainlay = new QHBoxLayout( this );
    mainlay->setMargin( 0 );
Albert Astals Cid's avatar
Albert Astals Cid committed
38
    m_comboItems = new KComboBox( this );
39 40 41 42 43 44 45 46
    mainlay->addWidget( m_comboItems );
    m_iconLabel = new QLabel( this );
    mainlay->addWidget( m_iconLabel );
    m_iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    m_iconLabel->setAlignment( Qt::AlignCenter );
    m_iconLabel->setFrameStyle( QFrame::StyledPanel );
    setPreviewSize( 32 );

Laurent Montel's avatar
Laurent Montel committed
47 48
    connect( m_comboItems, SIGNAL(currentIndexChanged(QString)), this, SLOT(iconComboChanged(QString)) );
    connect( m_comboItems, SIGNAL(editTextChanged(QString)), this, SLOT(iconComboChanged(QString)) );
49 50 51 52 53 54 55 56
}

PixmapPreviewSelector::~PixmapPreviewSelector()
{
}

void PixmapPreviewSelector::setIcon( const QString& icon )
{
Pino Toscano's avatar
Pino Toscano committed
57
    int id = m_comboItems->findData( QVariant( icon ), Qt::UserRole, Qt::MatchFixedString );
58
    if ( id == -1 )
Pino Toscano's avatar
Pino Toscano committed
59
        id = m_comboItems->findText( icon, Qt::MatchFixedString );
60 61 62 63
    if ( id > -1 )
    {
        m_comboItems->setCurrentIndex( id );
    }
64 65 66 67 68
    else if ( m_comboItems->isEditable() )
    {
        m_comboItems->addItem( icon, QVariant( icon ) );
        m_comboItems->setCurrentIndex( m_comboItems->findText( icon, Qt::MatchFixedString ) );
    }
69 70 71 72 73 74 75
}

QString PixmapPreviewSelector::icon() const
{
    return m_icon;
}

Pino Toscano's avatar
Pino Toscano committed
76
void PixmapPreviewSelector::addItem( const QString& item, const QString& id )
77
{
Pino Toscano's avatar
Pino Toscano committed
78
    m_comboItems->addItem( item, QVariant( id ) );
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    setIcon( m_icon );
}

void PixmapPreviewSelector::setPreviewSize( int size )
{
    m_previewSize = size;
    m_iconLabel->setFixedSize( m_previewSize + 8, m_previewSize + 8 );
    iconComboChanged( m_icon );
}

int PixmapPreviewSelector::previewSize() const
{
    return m_previewSize;
}

94 95 96 97 98
void PixmapPreviewSelector::setEditable( bool editable )
{
    m_comboItems->setEditable( editable );
}

99 100
void PixmapPreviewSelector::iconComboChanged( const QString& icon )
{
Pino Toscano's avatar
Pino Toscano committed
101
    int id = m_comboItems->findText( icon, Qt::MatchFixedString );
102 103 104 105 106 107 108 109
    if ( id >= 0 )
    {
        m_icon = m_comboItems->itemData( id ).toString();
    }
    else
    {
        m_icon = icon;
    }
Pino Toscano's avatar
Pino Toscano committed
110

111 112 113
    QPixmap pixmap = GuiUtils::loadStamp( m_icon, QSize(), m_previewSize );
    const QRect cr = m_iconLabel->contentsRect();
    if ( pixmap.width() > cr.width() || pixmap.height() > cr.height() )
Pino Toscano's avatar
Pino Toscano committed
114
        pixmap = pixmap.scaled( cr.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
115
    m_iconLabel->setPixmap( pixmap );
116 117

    emit iconChanged( m_icon );
118 119 120
}


121
AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann )
Pino Toscano's avatar
Pino Toscano committed
122 123 124
{
    switch ( ann->subType() )
    {
125
        case Okular::Annotation::AStamp:
Pino Toscano's avatar
Pino Toscano committed
126 127
            return new StampAnnotationWidget( ann );
            break;
128
        case Okular::Annotation::AText:
Pino Toscano's avatar
Pino Toscano committed
129 130
            return new TextAnnotationWidget( ann );
            break;
131
        case Okular::Annotation::ALine:
Pino Toscano's avatar
Pino Toscano committed
132 133
            return new LineAnnotationWidget( ann );
            break;
134 135 136
        case Okular::Annotation::AHighlight:
            return new HighlightAnnotationWidget( ann );
            break;
137 138 139
        case Okular::Annotation::AInk:
            return new InkAnnotationWidget( ann );
            break;
140 141 142
        case Okular::Annotation::AGeom:
            return new GeomAnnotationWidget( ann );
            break;
143 144 145
        case Okular::Annotation::AFileAttachment:
            return new FileAttachmentAnnotationWidget( ann );
            break;
146 147 148
        case Okular::Annotation::ACaret:
            return new CaretAnnotationWidget( ann );
            break;
Pino Toscano's avatar
Pino Toscano committed
149 150 151 152
        // shut up gcc
        default:
            ;
    }
153 154
    // cases not covered yet: return a generic widget
    return new AnnotationWidget( ann );
Pino Toscano's avatar
Pino Toscano committed
155 156 157
}


158
AnnotationWidget::AnnotationWidget( Okular::Annotation * ann )
159
    : QObject(), m_ann( ann ), m_appearanceWidget( 0 ), m_extraWidget( 0 )
Pino Toscano's avatar
Pino Toscano committed
160 161 162 163 164 165 166
{
}

AnnotationWidget::~AnnotationWidget()
{
}

167
Okular::Annotation::SubType AnnotationWidget::annotationType() const
Pino Toscano's avatar
Pino Toscano committed
168 169 170 171
{
    return m_ann->subType();
}

172
QWidget * AnnotationWidget::appearanceWidget()
173
{
174 175
    if ( m_appearanceWidget )
        return m_appearanceWidget;
176

177 178
    m_appearanceWidget = createAppearanceWidget();
    return m_appearanceWidget;
179 180
}

181 182 183 184 185 186 187 188 189
QWidget * AnnotationWidget::extraWidget()
{
    if ( m_extraWidget )
        return m_extraWidget;

    m_extraWidget = createExtraWidget();
    return m_extraWidget;
}

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
void AnnotationWidget::applyChanges()
{
    m_ann->style().setColor( m_colorBn->color() );
    m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 );
}

QWidget * AnnotationWidget::createAppearanceWidget()
{
    QWidget * widget = new QWidget();
    QGridLayout * gridlayout = new QGridLayout( widget );

    QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget );
    gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
    m_colorBn = new KColorButton( widget );
    m_colorBn->setColor( m_ann->style().color() );
    tmplabel->setBuddy( m_colorBn );
    gridlayout->addWidget( m_colorBn, 0, 1 );

    tmplabel = new QLabel( i18n( "&Opacity:" ), widget );
    gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
    m_opacity = new KIntNumInput( widget );
    m_opacity->setRange( 0, 100 );
    m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) );
    m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) );
    tmplabel->setBuddy( m_opacity );
    gridlayout->addWidget( m_opacity, 1, 1 );

    QWidget * styleWidget = createStyleWidget();
    if ( styleWidget )
        gridlayout->addWidget( styleWidget, 2, 0, 1, 2 );

    gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 );

    connect( m_colorBn, SIGNAL(changed(QColor)), this, SIGNAL(dataChanged()) );
    connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) );

    return widget;
}

QWidget * AnnotationWidget::createStyleWidget()
{
    return 0;
}

234 235 236 237 238
QWidget * AnnotationWidget::createExtraWidget()
{
    return 0;
}

Pino Toscano's avatar
Pino Toscano committed
239

240
TextAnnotationWidget::TextAnnotationWidget( Okular::Annotation * ann )
241
    : AnnotationWidget( ann ), m_pixmapSelector( 0 )
Pino Toscano's avatar
Pino Toscano committed
242
{
243
    m_textAnn = static_cast< Okular::TextAnnotation * >( ann );
Pino Toscano's avatar
Pino Toscano committed
244 245
}

246
QWidget * TextAnnotationWidget::createStyleWidget()
Pino Toscano's avatar
Pino Toscano committed
247
{
248 249
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
Pino Toscano's avatar
Pino Toscano committed
250
    lay->setMargin( 0 );
251 252 253

    if ( m_textAnn->textType() == Okular::TextAnnotation::Linked )
    {
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
        QGroupBox * gb = new QGroupBox( widget );
        lay->addWidget( gb );
        gb->setTitle( i18n( "Icon" ) );
        QHBoxLayout * gblay = new QHBoxLayout( gb );
        m_pixmapSelector = new PixmapPreviewSelector( gb );
        gblay->addWidget( m_pixmapSelector );

        m_pixmapSelector->addItem( i18n( "Comment" ), "Comment" );
        m_pixmapSelector->addItem( i18n( "Help" ), "Help" );
        m_pixmapSelector->addItem( i18n( "Insert" ), "Insert" );
        m_pixmapSelector->addItem( i18n( "Key" ), "Key" );
        m_pixmapSelector->addItem( i18n( "New Paragraph" ), "NewParagraph" );
        m_pixmapSelector->addItem( i18n( "Note" ), "Note" );
        m_pixmapSelector->addItem( i18n( "Paragraph" ), "Paragraph" );
        m_pixmapSelector->setIcon( m_textAnn->textIcon() );

        connect( m_pixmapSelector, SIGNAL(iconChanged(QString)), this, SIGNAL(dataChanged()) );
    }
    else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace )
    {
274 275 276
        QGridLayout * innerlay = new QGridLayout();
        lay->addLayout( innerlay );

277
        QLabel * tmplabel = new QLabel( i18n( "Font:" ), widget );
278
        innerlay->addWidget( tmplabel, 0, 0 );
279
        m_fontReq = new KFontRequester( widget );
280
        innerlay->addWidget( m_fontReq, 0, 1 );
281 282
        m_fontReq->setFont( m_textAnn->textFont() );

283 284 285 286 287 288 289 290 291
        tmplabel = new QLabel( i18n( "Align:" ), widget );
        innerlay->addWidget( tmplabel, 1, 0 );
        m_textAlign = new KComboBox( widget );
        innerlay->addWidget( m_textAlign, 1, 1 );
        m_textAlign->addItem( i18n("Left") );
        m_textAlign->addItem( i18n("Center") );
        m_textAlign->addItem( i18n("Right") );
        m_textAlign->setCurrentIndex( m_textAnn->inplaceAlignment() );

292 293 294 295 296 297 298 299 300
        tmplabel = new QLabel( i18n( "Border Width:" ), widget );
        innerlay->addWidget( tmplabel, 2, 0, Qt::AlignRight );
        m_spinWidth = new QDoubleSpinBox( widget );
        innerlay->addWidget( m_spinWidth, 2, 1 );
        tmplabel->setBuddy( m_spinWidth );
        m_spinWidth->setRange( 0, 100 );
        m_spinWidth->setValue( m_textAnn->style().width() );
        m_spinWidth->setSingleStep( 0.1 );

301
        connect( m_fontReq, SIGNAL(fontSelected(QFont)), this, SIGNAL(dataChanged()) );
302
        connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) );
303
        connect( m_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );
304
    }
Pino Toscano's avatar
Pino Toscano committed
305

306
    return widget;
Pino Toscano's avatar
Pino Toscano committed
307 308 309 310
}

void TextAnnotationWidget::applyChanges()
{
311
    AnnotationWidget::applyChanges();
Tobias Koenig's avatar
Tobias Koenig committed
312
    if ( m_textAnn->textType() == Okular::TextAnnotation::Linked )
Pino Toscano's avatar
Pino Toscano committed
313
    {
Tobias Koenig's avatar
Tobias Koenig committed
314
        m_textAnn->setTextIcon( m_pixmapSelector->icon() );
Pino Toscano's avatar
Pino Toscano committed
315
    }
316 317 318
    else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace )
    {
        m_textAnn->setTextFont( m_fontReq->font() );
319
        m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() );
320
        m_textAnn->style().setWidth( m_spinWidth->value() );
321
    }
Pino Toscano's avatar
Pino Toscano committed
322 323 324
}


325
StampAnnotationWidget::StampAnnotationWidget( Okular::Annotation * ann )
326
    : AnnotationWidget( ann ), m_pixmapSelector( 0 )
Pino Toscano's avatar
Pino Toscano committed
327
{
328
    m_stampAnn = static_cast< Okular::StampAnnotation * >( ann );
Pino Toscano's avatar
Pino Toscano committed
329 330
}

331
QWidget * StampAnnotationWidget::createStyleWidget()
Pino Toscano's avatar
Pino Toscano committed
332
{
333 334
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
Pino Toscano's avatar
Pino Toscano committed
335
    lay->setMargin( 0 );
336
    QGroupBox * gb = new QGroupBox( widget );
Pino Toscano's avatar
Pino Toscano committed
337 338 339
    lay->addWidget( gb );
    gb->setTitle( i18n( "Stamp Symbol" ) );
    QHBoxLayout * gblay = new QHBoxLayout( gb );
340 341
    m_pixmapSelector = new PixmapPreviewSelector( gb );
    gblay->addWidget( m_pixmapSelector );
342
    m_pixmapSelector->setEditable( true );
Pino Toscano's avatar
Pino Toscano committed
343

344
    m_pixmapSelector->addItem( i18n( "Okular" ), "okular" );
345
    m_pixmapSelector->addItem( i18n( "Bookmark" ), "bookmarks" );
346 347
    m_pixmapSelector->addItem( i18n( "KDE" ), "kde" );
    m_pixmapSelector->addItem( i18n( "Information" ), "help-about" );
348
    m_pixmapSelector->addItem( i18n( "Approved" ), "Approved" );
Pino Toscano's avatar
Pino Toscano committed
349 350 351 352 353 354 355 356 357 358 359 360 361
    m_pixmapSelector->addItem( i18n( "As Is" ), "AsIs" );
    m_pixmapSelector->addItem( i18n( "Confidential" ), "Confidential" );
    m_pixmapSelector->addItem( i18n( "Departmental" ), "Departmental" );
    m_pixmapSelector->addItem( i18n( "Draft" ), "Draft" );
    m_pixmapSelector->addItem( i18n( "Experimental" ), "Experimental" );
    m_pixmapSelector->addItem( i18n( "Expired" ), "Expired" );
    m_pixmapSelector->addItem( i18n( "Final" ), "Final" );
    m_pixmapSelector->addItem( i18n( "For Comment" ), "ForComment" );
    m_pixmapSelector->addItem( i18n( "For Public Release" ), "ForPublicRelease" );
    m_pixmapSelector->addItem( i18n( "Not Approved" ), "NotApproved" );
    m_pixmapSelector->addItem( i18n( "Not For Public Release" ), "NotForPublicRelease" );
    m_pixmapSelector->addItem( i18n( "Sold" ), "Sold" );
    m_pixmapSelector->addItem( i18n( "Top Secret" ), "TopSecret" );
Tobias Koenig's avatar
Tobias Koenig committed
362
    m_pixmapSelector->setIcon( m_stampAnn->stampIconName() );
363
    m_pixmapSelector->setPreviewSize( 64 );
Pino Toscano's avatar
Pino Toscano committed
364

Laurent Montel's avatar
Laurent Montel committed
365
    connect( m_pixmapSelector, SIGNAL(iconChanged(QString)), this, SIGNAL(dataChanged()) );
Pino Toscano's avatar
Pino Toscano committed
366

367
    return widget;
Pino Toscano's avatar
Pino Toscano committed
368 369 370 371
}

void StampAnnotationWidget::applyChanges()
{
372
    AnnotationWidget::applyChanges();
Tobias Koenig's avatar
Tobias Koenig committed
373
    m_stampAnn->setStampIconName( m_pixmapSelector->icon() );
Pino Toscano's avatar
Pino Toscano committed
374 375 376 377
}



378
LineAnnotationWidget::LineAnnotationWidget( Okular::Annotation * ann )
379
    : AnnotationWidget( ann )
Pino Toscano's avatar
Pino Toscano committed
380
{
381
    m_lineAnn = static_cast< Okular::LineAnnotation * >( ann );
Tobias Koenig's avatar
Tobias Koenig committed
382
    if ( m_lineAnn->linePoints().count() == 2 )
Pino Toscano's avatar
Pino Toscano committed
383
        m_lineType = 0; // line
Tobias Koenig's avatar
Tobias Koenig committed
384
    else if ( m_lineAnn->lineClosed() )
Pino Toscano's avatar
Pino Toscano committed
385 386 387 388 389
        m_lineType = 1; // polygon
    else
        m_lineType = 2; // polyline
}

390
QWidget * LineAnnotationWidget::createStyleWidget()
Pino Toscano's avatar
Pino Toscano committed
391
{
392 393
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
Pino Toscano's avatar
Pino Toscano committed
394
    lay->setMargin( 0 );
395 396
    if ( m_lineType == 0 )
    {
397 398 399 400 401 402 403 404 405 406 407 408 409 410
        QGroupBox * gb = new QGroupBox( widget );
        lay->addWidget( gb );
        gb->setTitle( i18n( "Line Extensions" ) );
        QGridLayout * gridlay = new QGridLayout( gb );
        QLabel * tmplabel = new QLabel( i18n( "Leader Line Length:" ), gb );
        gridlay->addWidget( tmplabel, 0, 0, Qt::AlignRight );
        m_spinLL = new QDoubleSpinBox( gb );
        gridlay->addWidget( m_spinLL, 0, 1 );
        tmplabel->setBuddy( m_spinLL );
        tmplabel = new QLabel( i18n( "Leader Line Extensions Length:" ), gb );
        gridlay->addWidget( tmplabel, 1, 0, Qt::AlignRight );
        m_spinLLE = new QDoubleSpinBox( gb );
        gridlay->addWidget( m_spinLLE, 1, 1 );
        tmplabel->setBuddy( m_spinLLE );
411 412
    }

413
    QGroupBox * gb2 = new QGroupBox( widget );
414 415 416 417
    lay->addWidget( gb2 );
    gb2->setTitle( i18n( "Style" ) );
    QGridLayout * gridlay2 = new QGridLayout( gb2 );
    QLabel * tmplabel2 = new QLabel( i18n( "&Size:" ), gb2 );
418
    gridlay2->addWidget( tmplabel2, 0, 0, Qt::AlignRight );
419 420 421
    m_spinSize = new QDoubleSpinBox( gb2 );
    gridlay2->addWidget( m_spinSize, 0, 1 );
    tmplabel2->setBuddy( m_spinSize );
Pino Toscano's avatar
Pino Toscano committed
422

423 424 425 426 427 428 429 430
    if ( m_lineType == 1 )
    {
        m_useColor = new QCheckBox( i18n( "Inner color:" ), gb2 );
        gridlay2->addWidget( m_useColor, 1, 0 );
        m_innerColor = new KColorButton( gb2 );
        gridlay2->addWidget( m_innerColor, 1, 1 );
    }

431 432
    if ( m_lineType == 0 )
    {
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
        m_spinLL->setRange( -500, 500 );
        m_spinLL->setValue( m_lineAnn->lineLeadingForwardPoint() );
        m_spinLLE->setRange( 0, 500 );
        m_spinLLE->setValue( m_lineAnn->lineLeadingBackwardPoint() );
    }
    else if ( m_lineType == 1 )
    {
        m_innerColor->setColor( m_lineAnn->lineInnerColor() );
        if ( m_lineAnn->lineInnerColor().isValid() )
        {
            m_useColor->setChecked( true );
        }
        else
        {
            m_innerColor->setEnabled( false );
        }
449 450 451
    }
    m_spinSize->setRange( 1, 100 );
    m_spinSize->setValue( m_lineAnn->style().width() );
Pino Toscano's avatar
Pino Toscano committed
452

453 454
    if ( m_lineType == 0 )
    {
455 456 457 458 459 460 461 462
        connect( m_spinLL, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );
        connect( m_spinLLE, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );
    }
    else if ( m_lineType == 1 )
    {
        connect( m_innerColor, SIGNAL(changed(QColor)), this, SIGNAL(dataChanged()) );
        connect( m_useColor, SIGNAL(toggled(bool)), this, SIGNAL(dataChanged()) );
        connect( m_useColor, SIGNAL(toggled(bool)), m_innerColor, SLOT(setEnabled(bool)) );
463
    }
Laurent Montel's avatar
Laurent Montel committed
464
    connect( m_spinSize, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );
Pino Toscano's avatar
Pino Toscano committed
465

466
    return widget;
Pino Toscano's avatar
Pino Toscano committed
467 468 469 470
}

void LineAnnotationWidget::applyChanges()
{
471
    AnnotationWidget::applyChanges();
Pino Toscano's avatar
Pino Toscano committed
472 473
    if ( m_lineType == 0 )
    {
Tobias Koenig's avatar
Tobias Koenig committed
474 475
        m_lineAnn->setLineLeadingForwardPoint( m_spinLL->value() );
        m_lineAnn->setLineLeadingBackwardPoint( m_spinLLE->value() );
Pino Toscano's avatar
Pino Toscano committed
476
    }
477 478 479 480 481 482 483 484 485 486 487
    else if ( m_lineType == 1 )
    {
        if ( !m_useColor->isChecked() )
        {
            m_lineAnn->setLineInnerColor( QColor() );
        }
        else
        {
            m_lineAnn->setLineInnerColor( m_innerColor->color() );
        }
    }
488
    m_lineAnn->style().setWidth( m_spinSize->value() );
Pino Toscano's avatar
Pino Toscano committed
489 490 491 492
}



493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
InkAnnotationWidget::InkAnnotationWidget( Okular::Annotation * ann )
    : AnnotationWidget( ann )
{
    m_inkAnn = static_cast< Okular::InkAnnotation * >( ann );
}

QWidget * InkAnnotationWidget::createStyleWidget()
{
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
    lay->setMargin( 0 );

    QGroupBox * gb2 = new QGroupBox( widget );
    lay->addWidget( gb2 );
    gb2->setTitle( i18n( "Style" ) );
    QGridLayout * gridlay2 = new QGridLayout( gb2 );
    QLabel * tmplabel2 = new QLabel( i18n( "&Size:" ), gb2 );
    gridlay2->addWidget( tmplabel2, 0, 0, Qt::AlignRight );
    m_spinSize = new QDoubleSpinBox( gb2 );
    gridlay2->addWidget( m_spinSize, 0, 1 );
    tmplabel2->setBuddy( m_spinSize );

    m_spinSize->setRange( 1, 100 );
    m_spinSize->setValue( m_inkAnn->style().width() );

    connect( m_spinSize, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );

    return widget;
}

void InkAnnotationWidget::applyChanges()
{
    AnnotationWidget::applyChanges();
    m_inkAnn->style().setWidth( m_spinSize->value() );
}



531
HighlightAnnotationWidget::HighlightAnnotationWidget( Okular::Annotation * ann )
532
    : AnnotationWidget( ann )
533 534 535 536
{
    m_hlAnn = static_cast< Okular::HighlightAnnotation * >( ann );
}

537
QWidget * HighlightAnnotationWidget::createStyleWidget()
538
{
539 540
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
541 542 543
    lay->setMargin( 0 );
    QHBoxLayout * typelay = new QHBoxLayout();
    lay->addLayout( typelay );
544
    QLabel * tmplabel = new QLabel( i18n( "Type:" ), widget );
545
    typelay->addWidget( tmplabel, 0, Qt::AlignRight );
546
    m_typeCombo = new KComboBox( widget );
547 548 549 550
    tmplabel->setBuddy( m_typeCombo );
    typelay->addWidget( m_typeCombo );

    m_typeCombo->addItem( i18n( "Highlight" ) );
551
    m_typeCombo->addItem( i18n( "Squiggle" ) );
552
    m_typeCombo->addItem( i18n( "Underline" ) );
Pino Toscano's avatar
Pino Toscano committed
553
    m_typeCombo->addItem( i18n( "Strike out" ) );
Tobias Koenig's avatar
Tobias Koenig committed
554
    m_typeCombo->setCurrentIndex( m_hlAnn->highlightType() );
555

Laurent Montel's avatar
Laurent Montel committed
556
    connect( m_typeCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) );
557

558
    return widget;
559 560 561 562
}

void HighlightAnnotationWidget::applyChanges()
{
563
    AnnotationWidget::applyChanges();
Tobias Koenig's avatar
Tobias Koenig committed
564
    m_hlAnn->setHighlightType( (Okular::HighlightAnnotation::HighlightType)m_typeCombo->currentIndex() );
565 566 567 568
}



569
GeomAnnotationWidget::GeomAnnotationWidget( Okular::Annotation * ann )
570
    : AnnotationWidget( ann )
571 572 573 574
{
    m_geomAnn = static_cast< Okular::GeomAnnotation * >( ann );
}

575
QWidget * GeomAnnotationWidget::createStyleWidget()
576
{
577 578
    QWidget * widget = new QWidget();
    QGridLayout * lay = new QGridLayout( widget );
579
    lay->setMargin( 0 );
580
    QLabel * tmplabel = new QLabel( i18n( "Type:" ), widget );
581
    lay->addWidget( tmplabel, 0, 0, Qt::AlignRight );
582
    m_typeCombo = new KComboBox( widget );
583 584
    tmplabel->setBuddy( m_typeCombo );
    lay->addWidget( m_typeCombo, 0, 1 );
585
    m_useColor = new QCheckBox( i18n( "Inner color:" ), widget );
586
    lay->addWidget( m_useColor, 1, 0 );
587
    m_innerColor = new KColorButton( widget );
588
    lay->addWidget( m_innerColor, 1, 1 );
589
    tmplabel = new QLabel( i18n( "&Size:" ), widget );
590
    lay->addWidget( tmplabel, 2, 0, Qt::AlignRight );
591
    m_spinSize = new QDoubleSpinBox( widget );
592 593
    lay->addWidget( m_spinSize, 2, 1 );
    tmplabel->setBuddy( m_spinSize );
594 595 596

    m_typeCombo->addItem( i18n( "Rectangle" ) );
    m_typeCombo->addItem( i18n( "Ellipse" ) );
Tobias Koenig's avatar
Tobias Koenig committed
597 598 599
    m_typeCombo->setCurrentIndex( m_geomAnn->geometricalType() );
    m_innerColor->setColor( m_geomAnn->geometricalInnerColor() );
    if ( m_geomAnn->geometricalInnerColor().isValid() )
600 601 602 603 604 605 606
    {
        m_useColor->setChecked( true );
    }
    else
    {
        m_innerColor->setEnabled( false );
    }
607
    m_spinSize->setRange( 0, 100 );
608
    m_spinSize->setValue( m_geomAnn->style().width() );
609

Laurent Montel's avatar
Laurent Montel committed
610 611 612 613 614
    connect( m_typeCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) );
    connect( m_innerColor, SIGNAL(changed(QColor)), this, SIGNAL(dataChanged()) );
    connect( m_useColor, SIGNAL(toggled(bool)), this, SIGNAL(dataChanged()) );
    connect( m_useColor, SIGNAL(toggled(bool)), m_innerColor, SLOT(setEnabled(bool)) );
    connect( m_spinSize, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) );
615

616
    return widget;
617 618 619 620
}

void GeomAnnotationWidget::applyChanges()
{
621
    AnnotationWidget::applyChanges();
Tobias Koenig's avatar
Tobias Koenig committed
622
    m_geomAnn->setGeometricalType( (Okular::GeomAnnotation::GeomType)m_typeCombo->currentIndex() );
623 624
    if ( !m_useColor->isChecked() )
    {
Tobias Koenig's avatar
Tobias Koenig committed
625
        m_geomAnn->setGeometricalInnerColor( QColor() );
626 627 628
    }
    else
    {
Tobias Koenig's avatar
Tobias Koenig committed
629
        m_geomAnn->setGeometricalInnerColor( m_innerColor->color() );
630
    }
631
    m_geomAnn->style().setWidth( m_spinSize->value() );
632 633
}

634 635 636


FileAttachmentAnnotationWidget::FileAttachmentAnnotationWidget( Okular::Annotation * ann )
637
    : AnnotationWidget( ann ), m_pixmapSelector( 0 )
638 639 640 641 642 643
{
    m_attachAnn = static_cast< Okular::FileAttachmentAnnotation * >( ann );
}

QWidget * FileAttachmentAnnotationWidget::createStyleWidget()
{
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
    lay->setMargin( 0 );
    QGroupBox * gb = new QGroupBox( widget );
    lay->addWidget( gb );
    gb->setTitle( i18n( "File Attachment Symbol" ) );
    QHBoxLayout * gblay = new QHBoxLayout( gb );
    m_pixmapSelector = new PixmapPreviewSelector( gb );
    gblay->addWidget( m_pixmapSelector );
    m_pixmapSelector->setEditable( true );

    m_pixmapSelector->addItem( i18nc( "Symbol for file attachment annotations", "Graph" ), "graph" );
    m_pixmapSelector->addItem( i18nc( "Symbol for file attachment annotations", "Push Pin" ), "pushpin" );
    m_pixmapSelector->addItem( i18nc( "Symbol for file attachment annotations", "Paperclip" ), "paperclip" );
    m_pixmapSelector->addItem( i18nc( "Symbol for file attachment annotations", "Tag" ), "tag" );
    m_pixmapSelector->setIcon( m_attachAnn->fileIconName() );

Laurent Montel's avatar
Laurent Montel committed
661
    connect( m_pixmapSelector, SIGNAL(iconChanged(QString)), this, SIGNAL(dataChanged()) );
662 663

    return widget;
664 665 666 667 668 669 670 671 672 673
}

QWidget * FileAttachmentAnnotationWidget::createExtraWidget()
{
    QWidget * widget = new QWidget();
    widget->setWindowTitle( i18nc( "'File' as normal file, that can be opened, saved, etc..", "File" ) );

    Okular::EmbeddedFile *ef = m_attachAnn->embeddedFile();
    const int size = ef->size();
    const QString sizeString = size <= 0 ? i18nc( "Not available size", "N/A" ) : KGlobal::locale()->formatByteSize( size );
674
    const QString descString = ef->description().isEmpty() ? i18n( "No description available." ) : ef->description();
675 676 677 678 679 680 681 682 683 684 685 686 687

    QGridLayout * lay = new QGridLayout( widget );
    lay->setMargin( 0 );
    QLabel * tmplabel = new QLabel( i18n( "Name: %1", ef->name() ), widget );
    tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse );
    lay->addWidget( tmplabel, 0, 0 );

    tmplabel = new QLabel( i18n( "Size: %1", sizeString ), widget );
    tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse );
    lay->addWidget( tmplabel, 1, 0 );

    tmplabel = new QLabel( i18n( "Description:" ), widget );
    lay->addWidget( tmplabel, 2, 0 );
688 689 690 691
    tmplabel = new QLabel( widget );
    tmplabel->setTextFormat( Qt::PlainText );
    tmplabel->setWordWrap( true );
    tmplabel->setText( descString );
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
    tmplabel->setTextInteractionFlags( Qt::TextSelectableByMouse );
    lay->addWidget( tmplabel, 3, 0, 1, 2 );

    KMimeType::Ptr mime = KMimeType::findByPath( ef->name(), 0, true );
    if ( mime )
    {
        tmplabel = new QLabel( widget );
        tmplabel->setPixmap( KIcon( mime->iconName() ).pixmap( FILEATTACH_ICONSIZE, FILEATTACH_ICONSIZE ) );
        tmplabel->setFixedSize( FILEATTACH_ICONSIZE, FILEATTACH_ICONSIZE );
        lay->addWidget( tmplabel, 0, 1, 3, 1, Qt::AlignTop );
    }

    lay->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 4, 0 );

    return widget;
}

void FileAttachmentAnnotationWidget::applyChanges()
{
711
    AnnotationWidget::applyChanges();
712
    m_attachAnn->setFileIconName( m_pixmapSelector->icon() );
713 714 715
}


716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759

static QString caretSymbolToIcon( Okular::CaretAnnotation::CaretSymbol symbol )
{
    switch ( symbol )
    {
        case Okular::CaretAnnotation::None:
            return QString::fromLatin1( "caret-none" );
        case Okular::CaretAnnotation::P:
            return QString::fromLatin1( "caret-p" );
    }
    return QString();
}

static Okular::CaretAnnotation::CaretSymbol caretSymbolFromIcon( const QString &icon )
{
    if ( icon == QLatin1String( "caret-none" ) )
        return Okular::CaretAnnotation::None;
    else if ( icon == QLatin1String( "caret-p" ) )
        return Okular::CaretAnnotation::P;
    return Okular::CaretAnnotation::None;
}

CaretAnnotationWidget::CaretAnnotationWidget( Okular::Annotation * ann )
    : AnnotationWidget( ann ), m_pixmapSelector( 0 )
{
    m_caretAnn = static_cast< Okular::CaretAnnotation * >( ann );
}

QWidget * CaretAnnotationWidget::createStyleWidget()
{
    QWidget * widget = new QWidget();
    QVBoxLayout * lay = new QVBoxLayout( widget );
    lay->setMargin( 0 );
    QGroupBox * gb = new QGroupBox( widget );
    lay->addWidget( gb );
    gb->setTitle( i18n( "Caret Symbol" ) );
    QHBoxLayout * gblay = new QHBoxLayout( gb );
    m_pixmapSelector = new PixmapPreviewSelector( gb );
    gblay->addWidget( m_pixmapSelector );

    m_pixmapSelector->addItem( i18nc( "Symbol for caret annotations", "None" ), "caret-none" );
    m_pixmapSelector->addItem( i18nc( "Symbol for caret annotations", "P" ), "caret-p" );
    m_pixmapSelector->setIcon( caretSymbolToIcon( m_caretAnn->caretSymbol() ) );

Laurent Montel's avatar
Laurent Montel committed
760
    connect( m_pixmapSelector, SIGNAL(iconChanged(QString)), this, SIGNAL(dataChanged()) );
761 762 763 764 765 766

    return widget;
}

void CaretAnnotationWidget::applyChanges()
{
767
    AnnotationWidget::applyChanges();
768 769 770 771 772
    m_caretAnn->setCaretSymbol( caretSymbolFromIcon( m_pixmapSelector->icon() ) );
}



Pino Toscano's avatar
Pino Toscano committed
773
#include "annotationwidgets.moc"