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 ); | ||
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") ) ); | ||
180 | ta->setTextFont( f ); | 160 | ta->setTextFont( f ); | ||
181 | } | 161 | } | ||
162 | // set font color | ||||
163 | if ( m_annotElement.hasAttribute( QStringLiteral("textColor") ) ) | ||||
164 | { | ||||
165 | if ( inplaceIntent == Okular::TextAnnotation::TypeWriter ) | ||||
166 | ta->setTextColor( m_annotElement.attribute( QStringLiteral("textColor") ) ); | ||||
167 | else | ||||
168 | ta->setTextColor( Qt::black ); | ||||
169 | } | ||||
182 | //set width | 170 | //set width | ||
183 | if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) | 171 | if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) | ||
184 | { | 172 | { | ||
185 | ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); | 173 | ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); | ||
186 | } | 174 | } | ||
187 | //set boundary | 175 | //set boundary | ||
188 | rect.left = qMin(startpoint.x,point.x); | 176 | rect.left = qMin(startpoint.x,point.x); | ||
189 | rect.top = qMin(startpoint.y,point.y); | 177 | rect.top = qMin(startpoint.y,point.y); | ||
190 | rect.right = qMax(startpoint.x,point.x); | 178 | rect.right = qMax(startpoint.x,point.x); | ||
191 | rect.bottom = qMax(startpoint.y,point.y); | 179 | rect.bottom = qMax(startpoint.y,point.y); | ||
192 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | 180 | qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; | ||
193 | static const int padding = 2; | 181 | static const int padding = 2; | ||
194 | const QFontMetricsF mf(ta->textFont()); | 182 | 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 ), | 183 | 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() ); | 184 | Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); | ||
197 | rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); | 185 | 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); | 186 | rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); | ||
199 | ta->window().setSummary( i18n( "Inline Note" ) ); | 187 | ta->window().setSummary( summary ); | ||
200 | } | 188 | } | ||
189 | | ||||
190 | QList< Okular::Annotation* > end() override | ||||
191 | { | ||||
192 | // find out annotation's description node | ||||
193 | if ( m_annotElement.isNull() ) | ||||
194 | { | ||||
195 | m_creationCompleted = false; | ||||
196 | clicked = false; | ||||
197 | return QList< Okular::Annotation* >(); | ||||
198 | } | ||||
199 | | ||||
200 | // find out annotation's type | ||||
201 | Okular::Annotation * ann = nullptr; | ||||
202 | const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); | ||||
203 | // create InPlace TextAnnotation from path | ||||
204 | if ( typeString == QLatin1String("FreeText") ) | ||||
205 | { | ||||
206 | bool resok; | ||||
207 | const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); | ||||
208 | if( resok ) | ||||
209 | addInPlaceTextAnnotation( ann, i18n("Inline Note"), content, Okular::TextAnnotation::Unknown ); | ||||
210 | } | ||||
211 | else if ( typeString == QLatin1String("Typewriter") ) | ||||
212 | { | ||||
213 | bool resok; | ||||
214 | const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); | ||||
215 | if( resok ) | ||||
216 | addInPlaceTextAnnotation( ann, i18n("Typewriter"), content, Okular::TextAnnotation::TypeWriter ); | ||||
201 | } | 217 | } | ||
202 | else if ( typeString == QLatin1String("Text")) | 218 | else if ( typeString == QLatin1String("Text") ) | ||
203 | { | 219 | { | ||
204 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | 220 | Okular::TextAnnotation * ta = new Okular::TextAnnotation(); | ||
205 | ann = ta; | 221 | ann = ta; | ||
206 | ta->setTextType( Okular::TextAnnotation::Linked ); | 222 | ta->setTextType( Okular::TextAnnotation::Linked ); | ||
207 | ta->setTextIcon( iconName ); | 223 | ta->setTextIcon( iconName ); | ||
208 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | 224 | //ta->window.flags &= ~(Okular::Annotation::Hidden); | ||
209 | const double iconhei=0.03; | 225 | const double iconhei=0.03; | ||
210 | rect.left = point.x; | 226 | rect.left = point.x; | ||
▲ Show 20 Lines • Show All 812 Lines • ▼ Show 20 Line(s) | 999 | { | |||
1023 | else if ( annotType == QLatin1String("stamp") ) | 1039 | else if ( annotType == QLatin1String("stamp") ) | ||
1024 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | 1040 | tip = i18nc( "Annotation tool", "Put a stamp symbol" ); | ||
1025 | else if ( annotType == QLatin1String("straight-line") ) | 1041 | else if ( annotType == QLatin1String("straight-line") ) | ||
1026 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | 1042 | tip = i18nc( "Annotation tool", "Draw a straight line" ); | ||
1027 | else if ( annotType == QLatin1String("strikeout") ) | 1043 | else if ( annotType == QLatin1String("strikeout") ) | ||
1028 | tip = i18nc( "Annotation tool", "Strike out text" ); | 1044 | tip = i18nc( "Annotation tool", "Strike out text" ); | ||
1029 | else if ( annotType == QLatin1String("underline") ) | 1045 | else if ( annotType == QLatin1String("underline") ) | ||
1030 | tip = i18nc( "Annotation tool", "Underline text" ); | 1046 | tip = i18nc( "Annotation tool", "Underline text" ); | ||
1047 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1048 | tip = i18nc( "Annotation tool", "Typewriter Annotation (drag to select a zone)" ); | ||||
1031 | 1049 | | |||
1032 | if ( !tip.isEmpty() && !m_continuousMode ) | 1050 | if ( !tip.isEmpty() && !m_continuousMode ) | ||
1033 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | 1051 | m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); | ||
1034 | } | 1052 | } | ||
1035 | 1053 | | |||
1036 | // consistancy warning | 1054 | // consistancy warning | ||
1037 | if ( !m_engine ) | 1055 | if ( !m_engine ) | ||
1038 | { | 1056 | { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 1083 | { | |||
1084 | else if ( annotType == QLatin1String("stamp") ) | 1102 | else if ( annotType == QLatin1String("stamp") ) | ||
1085 | return i18n( "Stamp" ); | 1103 | return i18n( "Stamp" ); | ||
1086 | else if ( annotType == QLatin1String("straight-line") ) | 1104 | else if ( annotType == QLatin1String("straight-line") ) | ||
1087 | return i18n( "Straight Line" ); | 1105 | return i18n( "Straight Line" ); | ||
1088 | else if ( annotType == QLatin1String("strikeout") ) | 1106 | else if ( annotType == QLatin1String("strikeout") ) | ||
1089 | return i18n( "Strike out" ); | 1107 | return i18n( "Strike out" ); | ||
1090 | else if ( annotType == QLatin1String("underline") ) | 1108 | else if ( annotType == QLatin1String("underline") ) | ||
1091 | return i18n( "Underline" ); | 1109 | return i18n( "Underline" ); | ||
1110 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1111 | return i18n( "Typewriter" ); | ||||
1092 | else | 1112 | else | ||
1093 | return QString(); | 1113 | return QString(); | ||
1094 | } | 1114 | } | ||
1095 | 1115 | | |||
1096 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | 1116 | QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) | ||
1097 | { | 1117 | { | ||
1098 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | 1118 | QPixmap pixmap( 32 * qApp->devicePixelRatio(), 32 * qApp->devicePixelRatio() ); | ||
1099 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | 1119 | pixmap.setDevicePixelRatio( qApp->devicePixelRatio() ); | ||
1100 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | 1120 | const QString annotType = toolElement.attribute( QStringLiteral("type") ); | ||
1101 | 1121 | | |||
1102 | // Load HiDPI variant on HiDPI screen | 1122 | // Load HiDPI variant on HiDPI screen | ||
1103 | QString imageVariant; | 1123 | QString imageVariant; | ||
1104 | if ( qApp->devicePixelRatio() > 1.05 ) { | 1124 | if ( qApp->devicePixelRatio() > 1.05 ) { | ||
1105 | imageVariant = "@2x"; | 1125 | imageVariant = "@2x"; | ||
1106 | } | 1126 | } | ||
1107 | 1127 | | |||
1108 | // Load base pixmap. We'll draw on top of it | 1128 | // 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") ) ); | 1129 | pixmap.load( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-base-okular" + imageVariant + ".png") ) ); | ||
1110 | 1130 | | |||
1111 | /* Parse color, innerColor and icon (if present) */ | 1131 | /* Parse color, innerColor and icon (if present) */ | ||
1112 | QColor engineColor, innerColor; | 1132 | QColor engineColor, innerColor, annotColor; | ||
1113 | QString icon; | 1133 | QString icon; | ||
1114 | QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); | 1134 | QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); | ||
1115 | if ( engineNodeList.size() > 0 ) | 1135 | if ( engineNodeList.size() > 0 ) | ||
1116 | { | 1136 | { | ||
1117 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | 1137 | QDomElement engineEl = engineNodeList.item( 0 ).toElement(); | ||
1118 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("color") ) ) | 1138 | if ( !engineEl.isNull() && engineEl.hasAttribute( QStringLiteral("color") ) ) | ||
1119 | engineColor = QColor( engineEl.attribute( QStringLiteral("color") ) ); | 1139 | engineColor = QColor( engineEl.attribute( QStringLiteral("color") ) ); | ||
1120 | } | 1140 | } | ||
1121 | QDomNodeList annotationNodeList = toolElement.elementsByTagName( QStringLiteral("annotation") ); | 1141 | QDomNodeList annotationNodeList = toolElement.elementsByTagName( QStringLiteral("annotation") ); | ||
1122 | if ( annotationNodeList.size() > 0 ) | 1142 | if ( annotationNodeList.size() > 0 ) | ||
1123 | { | 1143 | { | ||
1124 | QDomElement annotationEl = annotationNodeList.item( 0 ).toElement(); | 1144 | QDomElement annotationEl = annotationNodeList.item( 0 ).toElement(); | ||
1145 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("color") ) ) | ||||
1146 | annotColor = annotationEl.attribute( QStringLiteral("color") ); | ||||
1125 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("innerColor") ) ) | 1147 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("innerColor") ) ) | ||
1126 | innerColor = QColor( annotationEl.attribute( QStringLiteral("innerColor") ) ); | 1148 | innerColor = QColor( annotationEl.attribute( QStringLiteral("innerColor") ) ); | ||
1127 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("icon") ) ) | 1149 | if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("icon") ) ) | ||
1128 | icon = annotationEl.attribute( QStringLiteral("icon") ); | 1150 | icon = annotationEl.attribute( QStringLiteral("icon") ); | ||
1129 | } | 1151 | } | ||
1130 | 1152 | | |||
1131 | QPainter p( &pixmap ); | 1153 | QPainter p( &pixmap ); | ||
1132 | 1154 | | |||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 1245 | { | |||
1226 | p.drawLine( 0, 17, 19, 17 ); | 1248 | p.drawLine( 0, 17, 19, 17 ); | ||
1227 | } | 1249 | } | ||
1228 | else if ( annotType == QLatin1String("underline") ) | 1250 | else if ( annotType == QLatin1String("underline") ) | ||
1229 | { | 1251 | { | ||
1230 | p.setPen( QPen( engineColor, 1 ) ); | 1252 | p.setPen( QPen( engineColor, 1 ) ); | ||
1231 | p.drawLine( 1, 13, 16, 13 ); | 1253 | p.drawLine( 1, 13, 16, 13 ); | ||
1232 | p.drawLine( 0, 20, 19, 20 ); | 1254 | p.drawLine( 0, 20, 19, 20 ); | ||
1233 | } | 1255 | } | ||
1256 | else if ( annotType == QLatin1String("typewriter") ) | ||||
1257 | { | ||||
1258 | QImage overlay( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-typewriter-okular-colorizable" + imageVariant + ".png") ) ); | ||||
1259 | /* Here we want to colorize the icon with font color instead of background color. Font color is black a.t.m. */ | ||||
1260 | GuiUtils::colorizeImage( overlay, Qt::black ); | ||||
1261 | p.drawImage( QPoint(-2,2), overlay ); | ||||
1262 | } | ||||
1234 | else | 1263 | else | ||
1235 | { | 1264 | { | ||
1236 | /* Unrecognized annotation type -- It shouldn't happen */ | 1265 | /* Unrecognized annotation type -- It shouldn't happen */ | ||
1237 | p.setPen( QPen( engineColor ) ); | 1266 | p.setPen( QPen( engineColor ) ); | ||
1238 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | 1267 | p.drawText( QPoint(20, 31), QStringLiteral("?") ); | ||
1239 | } | 1268 | } | ||
1240 | 1269 | | |||
1241 | return pixmap; | 1270 | return pixmap; | ||
1242 | } | 1271 | } | ||
1243 | 1272 | | |||
1244 | #include "moc_pageviewannotator.cpp" | 1273 | #include "moc_pageviewannotator.cpp" | ||
1245 | 1274 | | |||
1246 | /* kate: replace-tabs on; indent-width 4; */ | 1275 | /* kate: replace-tabs on; indent-width 4; */ |