Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewannotator.cpp
Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | 133 | { | |||
---|---|---|---|---|---|
140 | painter->drawRect( realrect ); | 140 | painter->drawRect( realrect ); | ||
141 | painter->setPen( origpen ); | 141 | painter->setPen( origpen ); | ||
142 | } | 142 | } | ||
143 | if ( pixmap ) | 143 | if ( pixmap ) | ||
144 | painter->drawPixmap( QPointF( rect.left * xScale, rect.top * yScale ), *pixmap ); | 144 | painter->drawPixmap( QPointF( rect.left * xScale, rect.top * yScale ), *pixmap ); | ||
145 | } | 145 | } | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | QList< Okular::Annotation* > end() override | 148 | void addTextNote( Okular::Annotation * &ann, Okular::TextAnnotation::InplaceIntent inplaceIntent, const QString summary ) | ||
149 | { | | |||
150 | // find out annotation's description node | | |||
151 | if ( m_annotElement.isNull() ) | | |||
152 | { | | |||
153 | m_creationCompleted = false; | | |||
154 | clicked = false; | | |||
155 | return QList< Okular::Annotation* >(); | | |||
156 | } | | |||
157 | | ||||
158 | // find out annotation's type | | |||
159 | Okular::Annotation * ann = nullptr; | | |||
160 | const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); | | |||
161 | // create TextAnnotation from path | | |||
162 | if ( typeString == QLatin1String("FreeText")) //<annotation type="Text" | | |||
163 | { | 149 | { | ||
164 | //note dialog | 150 | //note dialog | ||
165 | const QString prompt = i18n( "Text of the new note:" ); | 151 | const QString prompt = i18n( "Text of the new note:" ); | ||
166 | bool resok; | 152 | bool resok; | ||
167 | const QString note = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), prompt, QString(), &resok); | 153 | const QString note = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), prompt, QString(), &resok); | ||
tobiasdeiminger: Getting input from user by dialog and adding the annotation are two different things. Divide it… | |||||
168 | if(resok) | 154 | if(resok) | ||
169 | { | 155 | { | ||
170 | //add note | 156 | //add note | ||
171 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | 157 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | ||
172 | ann = ta; | 158 | ann = ta; | ||
173 | ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); | 159 | ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); | ||
174 | ta->setContents( note ); | 160 | ta->setContents( note ); | ||
175 | ta->setTextType( Okular::TextAnnotation::InPlace ); | 161 | ta->setTextType( Okular::TextAnnotation::InPlace ); | ||
162 | ta->setInplaceIntent( inplaceIntent ); | ||||
176 | //set alignment | 163 | //set alignment | ||
177 | if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) | 164 | if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) | ||
178 | ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); | 165 | ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); | ||
179 | //set font | 166 | //set font | ||
180 | if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) | 167 | if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) | ||
181 | { | 168 | { | ||
182 | QFont f; | 169 | QFont f; | ||
183 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | 170 | f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); | ||
Show All 11 Lines | |||||
195 | rect.bottom = qMax(startpoint.y,point.y); | 182 | rect.bottom = qMax(startpoint.y,point.y); | ||
196 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | 183 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | ||
197 | static const int padding = 2; | 184 | static const int padding = 2; | ||
198 | const QFontMetricsF mf(ta->textFont()); | 185 | const QFontMetricsF mf(ta->textFont()); | ||
199 | 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 ), | 186 | 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 ), | ||
200 | Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); | 187 | Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); | ||
201 | rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); | 188 | rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); | ||
202 | rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); | 189 | rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); | ||
203 | ta->window().setSummary( i18n( "Inline Note" ) ); | 190 | ta->window().setSummary( summary ); | ||
204 | } | 191 | } | ||
205 | } | 192 | } | ||
193 | | ||||
194 | QList< Okular::Annotation* > end() override | ||||
195 | { | ||||
196 | // find out annotation's description node | ||||
197 | if ( m_annotElement.isNull() ) | ||||
198 | { | ||||
199 | m_creationCompleted = false; | ||||
200 | clicked = false; | ||||
201 | return QList< Okular::Annotation* >(); | ||||
202 | } | ||||
203 | | ||||
204 | // find out annotation's type | ||||
205 | Okular::Annotation * ann = nullptr; | ||||
206 | const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); | ||||
207 | // create TextAnnotation from path | ||||
208 | if ( typeString == QLatin1String("FreeText")) //<annotation type="Text" | ||||
209 | addTextNote( ann, Okular::TextAnnotation::Unknown, i18n("Inline Note") ); | ||||
210 | else if ( typeString == QLatin1String("Typewriter")) | ||||
211 | addTextNote( ann, Okular::TextAnnotation::TypeWriter, i18n("Typewriter") ); | ||||
206 | else if ( typeString == QLatin1String("Text")) | 212 | else if ( typeString == QLatin1String("Text")) | ||
207 | { | 213 | { | ||
208 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | 214 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | ||
209 | ann = ta; | 215 | ann = ta; | ||
210 | ta->setTextType( Okular::TextAnnotation::Linked ); | 216 | ta->setTextType( Okular::TextAnnotation::Linked ); | ||
211 | ta->setTextIcon( iconName ); | 217 | ta->setTextIcon( iconName ); | ||
212 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | 218 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | ||
213 | const double iconhei=0.03; | 219 | const double iconhei=0.03; | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 259 | { | |||
266 | rect.left = qMin( startpoint.x, point.x ); | 272 | rect.left = qMin( startpoint.x, point.x ); | ||
267 | rect.top = qMin( startpoint.y, point.y ); | 273 | rect.top = qMin( startpoint.y, point.y ); | ||
268 | rect.right = qMax( startpoint.x, point.x ); | 274 | rect.right = qMax( startpoint.x, point.x ); | ||
269 | rect.bottom = qMax( startpoint.y, point.y ); | 275 | rect.bottom = qMax( startpoint.y, point.y ); | ||
270 | } | 276 | } | ||
271 | 277 | | |||
272 | m_creationCompleted = false; | 278 | m_creationCompleted = false; | ||
273 | clicked = false; | 279 | clicked = false; | ||
274 | | ||||
sander: Whitespace change | |||||
275 | // safety check | 280 | // safety check | ||
276 | if ( !ann ) | 281 | if ( !ann ) | ||
277 | return QList< Okular::Annotation* >(); | 282 | return QList< Okular::Annotation* >(); | ||
278 | 283 | | |||
279 | // set common attributes | 284 | // set common attributes | ||
280 | ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | 285 | ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? | ||
281 | m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | 286 | m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); | ||
282 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | 287 | if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) | ||
▲ Show 20 Lines • Show All 756 Lines • ▼ Show 20 Line(s) | 1004 | { | |||
1039 | else if ( annotType == QLatin1String("stamp") ) | 1044 | else if ( annotType == QLatin1String("stamp") ) | ||
1040 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | 1045 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | ||
1041 | else if ( annotType == QLatin1String("straight-line") ) | 1046 | else if ( annotType == QLatin1String("straight-line") ) | ||
1042 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | 1047 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | ||
1043 | else if ( annotType == QLatin1String("strikeout") ) | 1048 | else if ( annotType == QLatin1String("strikeout") ) | ||
1044 | tip = i18nc( "Annotation tool", "Strike out text" ); | 1049 | tip = i18nc( "Annotation tool", "Strike out text" ); | ||
1045 | else if ( annotType == QLatin1String("underline") ) | 1050 | else if ( annotType == QLatin1String("underline") ) | ||
1046 | tip = i18nc( "Annotation tool", "Underline text" ); | 1051 | tip = i18nc( "Annotation tool", "Underline text" ); | ||
1052 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1053 | tip = i18nc( "Annotation tool", "Typewriter Annotation (drag to select a zone)" ); | ||||
1047 | 1054 | | |||
1048 | if ( !tip.isEmpty() && !m_continuousMode ) | 1055 | if ( !tip.isEmpty() && !m_continuousMode ) | ||
1049 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | 1056 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | ||
1050 | } | 1057 | } | ||
1051 | 1058 | | |||
1052 | // consistancy warning | 1059 | // consistancy warning | ||
1053 | if ( !m_engine ) | 1060 | if ( !m_engine ) | ||
1054 | { | 1061 | { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 1088 | { | |||
1100 | else if ( annotType == QLatin1String("stamp") ) | 1107 | else if ( annotType == QLatin1String("stamp") ) | ||
1101 | return i18n( "Stamp" ); | 1108 | return i18n( "Stamp" ); | ||
1102 | else if ( annotType == QLatin1String("straight-line") ) | 1109 | else if ( annotType == QLatin1String("straight-line") ) | ||
1103 | return i18n( "Straight Line" ); | 1110 | return i18n( "Straight Line" ); | ||
1104 | else if ( annotType == QLatin1String("strikeout") ) | 1111 | else if ( annotType == QLatin1String("strikeout") ) | ||
1105 | return i18n( "Strike out" ); | 1112 | return i18n( "Strike out" ); | ||
1106 | else if ( annotType == QLatin1String("underline") ) | 1113 | else if ( annotType == QLatin1String("underline") ) | ||
1107 | return i18n( "Underline" ); | 1114 | return i18n( "Underline" ); | ||
1115 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1116 | return i18n( "Typewriter" ); | ||||
1108 | else | 1117 | else | ||
1109 | return QString(); | 1118 | return QString(); | ||
1110 | } | 1119 | } | ||
1111 | 1120 | | |||
1112 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | 1121 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | ||
1113 | { | 1122 | { | ||
1114 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | 1123 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | ||
1115 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | 1124 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | 1248 | { | |||
1242 | p.drawLine( 0, 17, 19, 17 ); | 1251 | p.drawLine( 0, 17, 19, 17 ); | ||
1243 | } | 1252 | } | ||
1244 | else if ( annotType == QLatin1String("underline") ) | 1253 | else if ( annotType == QLatin1String("underline") ) | ||
1245 | { | 1254 | { | ||
1246 | p.setPen( QPen( engineColor, 1 ) ); | 1255 | p.setPen( QPen( engineColor, 1 ) ); | ||
1247 | p.drawLine( 1, 13, 16, 13 ); | 1256 | p.drawLine( 1, 13, 16, 13 ); | ||
1248 | p.drawLine( 0, 20, 19, 20 ); | 1257 | p.drawLine( 0, 20, 19, 20 ); | ||
1249 | } | 1258 | } | ||
1259 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1260 | { | ||||
1261 | QImage overlay( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-typewriter-okular-colorizable" + imageVariant + ".png") ) ); | ||||
1262 | GuiUtils::colorizeImage( overlay, engineColor ); | ||||
1263 | p.drawImage( QPoint(-2,2), overlay ); | ||||
1264 | } | ||||
1250 | else | 1265 | else | ||
1251 | { | 1266 | { | ||
1252 | /* Unrecognized annotation type -- It shouldn't happen */ | 1267 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1253 | p.setPen( QPen( engineColor ) ); | 1268 | p.setPen( QPen( engineColor ) ); | ||
1254 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1269 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1255 | } | 1270 | } | ||
1256 | 1271 | | |||
1257 | return pixmap; | 1272 | return pixmap; | ||
1258 | } | 1273 | } | ||
1259 | 1274 | | |||
1260 | #include "moc_pageviewannotator.cpp" | 1275 | #include "moc_pageviewannotator.cpp" | ||
1261 | 1276 | | |||
1262 | /* kate: replace-tabs on; indent-width 4; */ | 1277 | /* 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).