Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewannotator.cpp
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 129 | { | |||
---|---|---|---|---|---|
136 | painter->drawRect( realrect ); | 136 | painter->drawRect( realrect ); | ||
137 | painter->setPen( origpen ); | 137 | painter->setPen( origpen ); | ||
138 | } | 138 | } | ||
139 | if ( !pixmap.isNull() ) | 139 | if ( !pixmap.isNull() ) | ||
140 | painter->drawPixmap( QPointF( rect.left * xScale, rect.top * yScale ), pixmap ); | 140 | painter->drawPixmap( QPointF( rect.left * xScale, rect.top * yScale ), pixmap ); | ||
141 | } | 141 | } | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | QList< Okular::Annotation* > end() override | 144 | void addInPlaceTextAnnotation( Okular::Annotation * &ann, const QString summary, const QString content, Okular::TextAnnotation::InplaceIntent inplaceIntent ) | ||
145 | { | | |||
146 | // find out annotation's description node | | |||
147 | if ( m_annotElement.isNull() ) | | |||
148 | { | | |||
149 | m_creationCompleted = false; | | |||
150 | clicked = false; | | |||
151 | return QList< Okular::Annotation* >(); | | |||
152 | } | | |||
153 | | ||||
154 | // find out annotation's type | | |||
155 | Okular::Annotation * ann = nullptr; | | |||
156 | const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); | | |||
157 | // create TextAnnotation from path | | |||
158 | if ( typeString == QLatin1String("FreeText")) //<annotation type="Text" | | |||
159 | { | | |||
160 | //note dialog | | |||
161 | const QString prompt = i18n( "Text of the new note:" ); | | |||
162 | bool resok; | | |||
163 | const QString note = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), prompt, QString(), &resok); | | |||
164 | if(resok) | | |||
165 | { | 145 | { | ||
166 | //add note | | |||
167 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | 146 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | ||
168 | ann = ta; | 147 | ann = ta; | ||
169 | ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); | 148 | ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); | ||
170 | ta->setContents( note ); | 149 | ta->setContents( content ); | ||
tobiasdeiminger: Getting input from user by dialog and adding the annotation are two different things. Divide it… | |||||
171 | ta->setTextType( Okular::TextAnnotation::InPlace ); | 150 | ta->setTextType( Okular::TextAnnotation::InPlace ); | ||
151 | ta->setInplaceIntent( inplaceIntent ); | ||||
172 | //set alignment | 152 | //set alignment | ||
173 | if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) | 153 | if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) | ||
174 | ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); | 154 | ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); | ||
175 | //set font | 155 | //set font | ||
176 | if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) | 156 | if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) | ||
177 | { | 157 | { | ||
178 | QFont f; | 158 | QFont f; | ||
179 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | 159 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | ||
Show All 11 Lines | |||||
191 | rect.bottom = qMax(startpoint.y,point.y); | 171 | rect.bottom = qMax(startpoint.y,point.y); | ||
192 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | 172 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | ||
193 | static const int padding = 2; | 173 | static const int padding = 2; | ||
194 | const QFontMetricsF mf(ta->textFont()); | 174 | const QFontMetricsF mf(ta->textFont()); | ||
195 | const QRectF rcf = mf.boundingRect( Okular::NormalizedRect( rect.left, rect.top, 1.0, 1.0 ).geometry( (int)pagewidth, (int)pageheight ).adjusted( padding, padding, -padding, -padding ), | 175 | const QRectF rcf = mf.boundingRect( Okular::NormalizedRect( rect.left, rect.top, 1.0, 1.0 ).geometry( (int)pagewidth, (int)pageheight ).adjusted( padding, padding, -padding, -padding ), | ||
196 | Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); | 176 | Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); | ||
197 | rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); | 177 | rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); | ||
198 | rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); | 178 | rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); | ||
199 | ta->window().setSummary( i18n( "Inline Note" ) ); | 179 | ta->window().setSummary( summary ); | ||
180 | } | ||||
181 | | ||||
182 | QList< Okular::Annotation* > end() override | ||||
183 | { | ||||
184 | // find out annotation's description node | ||||
185 | if ( m_annotElement.isNull() ) | ||||
186 | { | ||||
187 | m_creationCompleted = false; | ||||
188 | clicked = false; | ||||
189 | return QList< Okular::Annotation* >(); | ||||
190 | } | ||||
191 | | ||||
192 | // find out annotation's type | ||||
193 | Okular::Annotation * ann = nullptr; | ||||
194 | const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); | ||||
195 | // create InPlace TextAnnotation from path | ||||
196 | if ( typeString == QLatin1String("FreeText") ) | ||||
197 | { | ||||
198 | bool resok; | ||||
199 | const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); | ||||
200 | if( resok ) | ||||
201 | addInPlaceTextAnnotation( ann, i18n("Inline Note"), content, Okular::TextAnnotation::Unknown ); | ||||
200 | } | 202 | } | ||
203 | else if ( typeString == QLatin1String("Typewriter") ) | ||||
204 | { | ||||
205 | bool resok; | ||||
206 | const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); | ||||
207 | if( resok ) | ||||
208 | addInPlaceTextAnnotation( ann, i18n("Typewriter"), content, Okular::TextAnnotation::TypeWriter ); | ||||
201 | } | 209 | } | ||
202 | else if ( typeString == QLatin1String("Text")) | 210 | else if ( typeString == QLatin1String("Text") ) | ||
203 | { | 211 | { | ||
204 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | 212 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | ||
205 | ann = ta; | 213 | ann = ta; | ||
206 | ta->setTextType( Okular::TextAnnotation::Linked ); | 214 | ta->setTextType( Okular::TextAnnotation::Linked ); | ||
207 | ta->setTextIcon( iconName ); | 215 | ta->setTextIcon( iconName ); | ||
208 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | 216 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | ||
209 | const double iconhei=0.03; | 217 | const double iconhei=0.03; | ||
210 | rect.left = point.x; | 218 | rect.left = point.x; | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 257 | { | |||
262 | rect.left = qMin( startpoint.x, point.x ); | 270 | rect.left = qMin( startpoint.x, point.x ); | ||
263 | rect.top = qMin( startpoint.y, point.y ); | 271 | rect.top = qMin( startpoint.y, point.y ); | ||
264 | rect.right = qMax( startpoint.x, point.x ); | 272 | rect.right = qMax( startpoint.x, point.x ); | ||
265 | rect.bottom = qMax( startpoint.y, point.y ); | 273 | rect.bottom = qMax( startpoint.y, point.y ); | ||
266 | } | 274 | } | ||
267 | 275 | | |||
268 | m_creationCompleted = false; | 276 | m_creationCompleted = false; | ||
269 | clicked = false; | 277 | clicked = false; | ||
270 | 278 | | |||
sander: Whitespace change | |||||
271 | // safety check | 279 | // safety check | ||
272 | if ( !ann ) | 280 | if ( !ann ) | ||
273 | return QList< Okular::Annotation* >(); | 281 | return QList< Okular::Annotation* >(); | ||
274 | 282 | | |||
275 | // set common attributes | 283 | // set common attributes | ||
276 | ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | 284 | ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | ||
277 | m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | 285 | m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | ||
278 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | 286 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | ||
▲ Show 20 Lines • Show All 744 Lines • ▼ Show 20 Line(s) | 991 | { | |||
1023 | else if ( annotType == QLatin1String("stamp") ) | 1031 | else if ( annotType == QLatin1String("stamp") ) | ||
1024 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | 1032 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | ||
1025 | else if ( annotType == QLatin1String("straight-line") ) | 1033 | else if ( annotType == QLatin1String("straight-line") ) | ||
1026 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | 1034 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | ||
1027 | else if ( annotType == QLatin1String("strikeout") ) | 1035 | else if ( annotType == QLatin1String("strikeout") ) | ||
1028 | tip = i18nc( "Annotation tool", "Strike out text" ); | 1036 | tip = i18nc( "Annotation tool", "Strike out text" ); | ||
1029 | else if ( annotType == QLatin1String("underline") ) | 1037 | else if ( annotType == QLatin1String("underline") ) | ||
1030 | tip = i18nc( "Annotation tool", "Underline text" ); | 1038 | tip = i18nc( "Annotation tool", "Underline text" ); | ||
1039 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1040 | tip = i18nc( "Annotation tool", "Typewriter Annotation (drag to select a zone)" ); | ||||
1031 | 1041 | | |||
1032 | if ( !tip.isEmpty() && !m_continuousMode ) | 1042 | if ( !tip.isEmpty() && !m_continuousMode ) | ||
1033 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | 1043 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | ||
1034 | } | 1044 | } | ||
1035 | 1045 | | |||
1036 | // consistancy warning | 1046 | // consistancy warning | ||
1037 | if ( !m_engine ) | 1047 | if ( !m_engine ) | ||
1038 | { | 1048 | { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 1075 | { | |||
1084 | else if ( annotType == QLatin1String("stamp") ) | 1094 | else if ( annotType == QLatin1String("stamp") ) | ||
1085 | return i18n( "Stamp" ); | 1095 | return i18n( "Stamp" ); | ||
1086 | else if ( annotType == QLatin1String("straight-line") ) | 1096 | else if ( annotType == QLatin1String("straight-line") ) | ||
1087 | return i18n( "Straight Line" ); | 1097 | return i18n( "Straight Line" ); | ||
1088 | else if ( annotType == QLatin1String("strikeout") ) | 1098 | else if ( annotType == QLatin1String("strikeout") ) | ||
1089 | return i18n( "Strike out" ); | 1099 | return i18n( "Strike out" ); | ||
1090 | else if ( annotType == QLatin1String("underline") ) | 1100 | else if ( annotType == QLatin1String("underline") ) | ||
1091 | return i18n( "Underline" ); | 1101 | return i18n( "Underline" ); | ||
1102 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1103 | return i18n( "Typewriter" ); | ||||
1092 | else | 1104 | else | ||
1093 | return QString(); | 1105 | return QString(); | ||
1094 | } | 1106 | } | ||
1095 | 1107 | | |||
1096 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | 1108 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | ||
1097 | { | 1109 | { | ||
1098 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | 1110 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | ||
1099 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | 1111 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | ||
1100 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1112 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1101 | 1113 | | |||
1102 | // Load HiDPI variant on HiDPI screen | 1114 | // Load HiDPI variant on HiDPI screen | ||
1103 | QString imageVariant; | 1115 | QString imageVariant; | ||
1104 | if ( qApp->devicePixelRatio() > 1.05 ) { | 1116 | if ( qApp->devicePixelRatio() > 1.05 ) { | ||
1105 | imageVariant = "@2x"; | 1117 | imageVariant = "@2x"; | ||
1106 | } | 1118 | } | ||
1107 | 1119 | | |||
1108 | // Load base pixmap. We'll draw on top of it | 1120 | // Load base pixmap. We'll draw on top of it | ||
1109 | pixmap.load( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-base-okular" + imageVariant + ".png") ) ); | 1121 | pixmap.load( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-base-okular" + imageVariant + ".png") ) ); | ||
1110 | 1122 | | |||
1111 | /* Parse color, innerColor and icon (if present) */ | 1123 | /* Parse color, innerColor and icon (if present) */ | ||
1112 | QColor engineColor, innerColor; | 1124 | QColor engineColor, innerColor, annotColor; | ||
1113 | QString icon; | 1125 | QString icon; | ||
1114 | QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); | 1126 | QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); | ||
1115 | if ( engineNodeList.size() > 0 ) | 1127 | if ( engineNodeList.size() > 0 ) | ||
1116 | { | 1128 | { | ||
1117 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | 1129 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | ||
1118 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("color") ) ) | 1130 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("color") ) ) | ||
1119 | engineColor = QColor( engineEl.attribute( QStringLiteral("color") ) ); | 1131 | engineColor = QColor( engineEl.attribute( QStringLiteral("color") ) ); | ||
1120 | } | 1132 | } | ||
1121 | QDomNodeList annotationNodeList = toolElement.elementsByTagName( QStringLiteral("annotation") ); | 1133 | QDomNodeList annotationNodeList = toolElement.elementsByTagName( QStringLiteral("annotation") ); | ||
1122 | if ( annotationNodeList.size() > 0 ) | 1134 | if ( annotationNodeList.size() > 0 ) | ||
1123 | { | 1135 | { | ||
1124 | QDomElement annotationEl = annotationNodeList.item( 0 ).toElement(); | 1136 | QDomElement annotationEl = annotationNodeList.item( 0 ).toElement(); | ||
1137 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("color") ) ) | ||||
1138 | annotColor = annotationEl.attribute( QStringLiteral("color") ); | ||||
1125 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("innerColor") ) ) | 1139 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("innerColor") ) ) | ||
1126 | innerColor = QColor( annotationEl.attribute( QStringLiteral("innerColor") ) ); | 1140 | innerColor = QColor( annotationEl.attribute( QStringLiteral("innerColor") ) ); | ||
1127 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("icon") ) ) | 1141 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("icon") ) ) | ||
1128 | icon = annotationEl.attribute( QStringLiteral("icon") ); | 1142 | icon = annotationEl.attribute( QStringLiteral("icon") ); | ||
1129 | } | 1143 | } | ||
1130 | 1144 | | |||
1131 | QPainter p( &pixmap ); | 1145 | QPainter p( &pixmap ); | ||
1132 | 1146 | | |||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 1237 | { | |||
1226 | p.drawLine( 0, 17, 19, 17 ); | 1240 | p.drawLine( 0, 17, 19, 17 ); | ||
1227 | } | 1241 | } | ||
1228 | else if ( annotType == QLatin1String("underline") ) | 1242 | else if ( annotType == QLatin1String("underline") ) | ||
1229 | { | 1243 | { | ||
1230 | p.setPen( QPen( engineColor, 1 ) ); | 1244 | p.setPen( QPen( engineColor, 1 ) ); | ||
1231 | p.drawLine( 1, 13, 16, 13 ); | 1245 | p.drawLine( 1, 13, 16, 13 ); | ||
1232 | p.drawLine( 0, 20, 19, 20 ); | 1246 | p.drawLine( 0, 20, 19, 20 ); | ||
1233 | } | 1247 | } | ||
1248 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1249 | { | ||||
1250 | QImage overlay( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-typewriter-okular-colorizable" + imageVariant + ".png") ) ); | ||||
1251 | /* Here we want to colorize the icon with font color instead of background color. Font color is black a.t.m. */ | ||||
1252 | GuiUtils::colorizeImage( overlay, Qt::black ); | ||||
1253 | p.drawImage( QPoint(-2,2), overlay ); | ||||
1254 | } | ||||
1234 | else | 1255 | else | ||
1235 | { | 1256 | { | ||
1236 | /* Unrecognized annotation type -- It shouldn't happen */ | 1257 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1237 | p.setPen( QPen( engineColor ) ); | 1258 | p.setPen( QPen( engineColor ) ); | ||
1238 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1259 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1239 | } | 1260 | } | ||
1240 | 1261 | | |||
1241 | return pixmap; | 1262 | return pixmap; | ||
1242 | } | 1263 | } | ||
1243 | 1264 | | |||
1244 | #include "moc_pageviewannotator.cpp" | 1265 | #include "moc_pageviewannotator.cpp" | ||
1245 | 1266 | | |||
1246 | /* kate: replace-tabs on; indent-width 4; */ | 1267 | /* kate: replace-tabs on; indent-width 4; */ |
Getting input from user by dialog and adding the annotation are two different things. Divide it into two methods (or just leave QInputDialog::getMultiLineText in PickPointEngine::end).