File indexing completed on 2024-04-28 15:51:39
0001 /* 0002 SPDX-FileCopyrightText: 2006 Chu Xiaodong <xiaodongchu@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "annotationpropertiesdialog.h" 0008 0009 // qt/kde includes 0010 #include <KLineEdit> 0011 #include <KLocalizedString> 0012 #include <QFormLayout> 0013 #include <QFrame> 0014 #include <QHeaderView> 0015 #include <QIcon> 0016 #include <QLabel> 0017 #include <QLayout> 0018 #include <QPushButton> 0019 #include <QTextEdit> 0020 0021 // local includes 0022 #include "annotationwidgets.h" 0023 #include "core/annotations.h" 0024 #include "core/document.h" 0025 #include "core/page.h" 0026 0027 AnnotsPropertiesDialog::AnnotsPropertiesDialog(QWidget *parent, Okular::Document *document, int docpage, Okular::Annotation *ann) 0028 : KPageDialog(parent) 0029 , m_document(document) 0030 , m_page(docpage) 0031 , modified(false) 0032 { 0033 setFaceType(Tabbed); 0034 m_annot = ann; 0035 const bool canEditAnnotations = m_document->canModifyPageAnnotation(ann); 0036 setCaptionTextbyAnnotType(); 0037 if (canEditAnnotations) { 0038 setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel); 0039 button(QDialogButtonBox::Apply)->setEnabled(false); 0040 connect(button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &AnnotsPropertiesDialog::slotapply); 0041 connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &AnnotsPropertiesDialog::slotapply); 0042 } else { 0043 setStandardButtons(QDialogButtonBox::Close); 0044 button(QDialogButtonBox::Close)->setDefault(true); 0045 } 0046 0047 m_annotWidget = AnnotationWidgetFactory::widgetFor(ann); 0048 0049 QLabel *tmplabel; 0050 // 1. Appearance 0051 // BEGIN tab1 0052 QWidget *appearanceWidget = m_annotWidget->appearanceWidget(); 0053 appearanceWidget->setEnabled(canEditAnnotations); 0054 addPage(appearanceWidget, i18n("&Appearance")); 0055 // END tab1 0056 0057 // BEGIN tab 2 0058 QFrame *page = new QFrame(this); 0059 addPage(page, i18n("&General")); 0060 // m_tabitem[1]->setIcon( QIcon::fromTheme( "fonts" ) ); 0061 QFormLayout *gridlayout = new QFormLayout(page); 0062 AuthorEdit = new KLineEdit(ann->author(), page); 0063 AuthorEdit->setEnabled(canEditAnnotations); 0064 gridlayout->addRow(i18n("&Author:"), AuthorEdit); 0065 0066 tmplabel = new QLabel(page); 0067 tmplabel->setText(QLocale().toString(ann->creationDate(), QLocale::LongFormat)); 0068 tmplabel->setTextInteractionFlags(Qt::TextSelectableByMouse); 0069 gridlayout->addRow(i18n("Created:"), tmplabel); 0070 0071 m_modifyDateLabel = new QLabel(page); 0072 m_modifyDateLabel->setText(QLocale().toString(ann->modificationDate(), QLocale::LongFormat)); 0073 m_modifyDateLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); 0074 gridlayout->addRow(i18n("Modified:"), m_modifyDateLabel); 0075 0076 // END tab 2 0077 0078 QWidget *extraWidget = m_annotWidget->extraWidget(); 0079 if (extraWidget) { 0080 addPage(extraWidget, extraWidget->windowTitle()); 0081 } 0082 0083 // BEGIN connections 0084 connect(AuthorEdit, &QLineEdit::textChanged, this, &AnnotsPropertiesDialog::setModified); 0085 connect(m_annotWidget, &AnnotationWidget::dataChanged, this, &AnnotsPropertiesDialog::setModified); 0086 // END 0087 0088 #if 0 0089 qCDebug(OkularUiDebug) << "Annotation details:"; 0090 qCDebug(OkularUiDebug).nospace() << " => unique name: '" << ann->uniqueName() << "'"; 0091 qCDebug(OkularUiDebug) << " => flags:" << QString::number( m_annot->flags(), 2 ); 0092 #endif 0093 0094 resize(sizeHint()); 0095 } 0096 AnnotsPropertiesDialog::~AnnotsPropertiesDialog() 0097 { 0098 delete m_annotWidget; 0099 } 0100 0101 void AnnotsPropertiesDialog::setCaptionTextbyAnnotType() 0102 { 0103 Okular::Annotation::SubType type = m_annot->subType(); 0104 QString captiontext; 0105 switch (type) { 0106 case Okular::Annotation::AText: 0107 if (((Okular::TextAnnotation *)m_annot)->textType() == Okular::TextAnnotation::Linked) { 0108 captiontext = i18n("Pop-up Note Properties"); 0109 } else { 0110 if (((Okular::TextAnnotation *)m_annot)->inplaceIntent() == Okular::TextAnnotation::TypeWriter) { 0111 captiontext = i18n("Typewriter Properties"); 0112 } else { 0113 captiontext = i18n("Inline Note Properties"); 0114 } 0115 } 0116 break; 0117 case Okular::Annotation::ALine: 0118 if (((Okular::LineAnnotation *)m_annot)->linePoints().count() == 2) { 0119 captiontext = i18n("Straight Line Properties"); 0120 } else { 0121 captiontext = i18n("Polygon Properties"); 0122 } 0123 break; 0124 case Okular::Annotation::AGeom: 0125 captiontext = i18n("Geometry Properties"); 0126 break; 0127 case Okular::Annotation::AHighlight: 0128 captiontext = i18n("Text Markup Properties"); 0129 break; 0130 case Okular::Annotation::AStamp: 0131 captiontext = i18n("Stamp Properties"); 0132 break; 0133 case Okular::Annotation::AInk: 0134 captiontext = i18n("Freehand Line Properties"); 0135 break; 0136 case Okular::Annotation::ACaret: 0137 captiontext = i18n("Caret Properties"); 0138 break; 0139 case Okular::Annotation::AFileAttachment: 0140 captiontext = i18n("File Attachment Properties"); 0141 break; 0142 case Okular::Annotation::ASound: 0143 captiontext = i18n("Sound Properties"); 0144 break; 0145 case Okular::Annotation::AMovie: 0146 captiontext = i18n("Movie Properties"); 0147 break; 0148 default: 0149 captiontext = i18n("Annotation Properties"); 0150 break; 0151 } 0152 setWindowTitle(captiontext); 0153 } 0154 0155 void AnnotsPropertiesDialog::setModified() 0156 { 0157 modified = true; 0158 button(QDialogButtonBox::Apply)->setEnabled(true); 0159 } 0160 0161 void AnnotsPropertiesDialog::slotapply() 0162 { 0163 if (!modified) { 0164 return; 0165 } 0166 0167 m_document->prepareToModifyAnnotationProperties(m_annot); 0168 m_annot->setAuthor(AuthorEdit->text()); 0169 m_annot->setModificationDate(QDateTime::currentDateTime()); 0170 0171 m_annotWidget->applyChanges(); 0172 0173 m_document->modifyPageAnnotationProperties(m_page, m_annot); 0174 0175 m_modifyDateLabel->setText(i18n("Modified: %1", QLocale().toString(m_annot->modificationDate(), QLocale::LongFormat))); 0176 0177 modified = false; 0178 button(QDialogButtonBox::Apply)->setEnabled(false); 0179 } 0180 0181 #include "moc_annotationpropertiesdialog.cpp"