1002
else // instead load form the correct child on, m_childCountBeforeInsert has the be set
1004
QPtrListIterator<KoDocumentChild> it( children() );
1005
for( int i = 0; it.current(); ++it, ++i ) {
1006
if ( i < m_childCountBeforeInsert )
1008
if ( !((KoDocumentChild*)it.current())->loadDocument( _store ) )
1015
bool KPresenterDoc::saveOasis( KoStore* store, KoXmlWriter* manifestWriter )
1018
//todo necessary for new format ?
1019
if ( saveOnlyPage == -1 ) {
1020
emit sigProgress( 0 );
1022
if ( !store->open( "content.xml" ) )
1024
m_pictureCollection.assignUniqueIds();
1025
KoStoreDevice contentDev( store );
1026
KoXmlWriter* contentWriter = createOasisXmlWriter( &contentDev, "office:document-content" );
1029
m_varColl->variableSetting()->setModificationDate(QDateTime::currentDateTime());
1030
recalcVariables( VT_DATE );
1031
recalcVariables( VT_TIME );
1033
KoGenStyles mainStyles;
1034
KoSavingContext savingContext( mainStyles, 0, false, KoSavingContext::Store );
1036
// Save user styles as KoGenStyle objects
1037
KoSavingContext::StyleNameMap map = m_styleColl->saveOasis( mainStyles, KoGenStyle::STYLE_USER, savingContext );
1038
savingContext.setStyleNameMap( map );
1040
KTempFile contentTmpFile;
1041
contentTmpFile.setAutoDelete( true );
1042
QFile* tmpFile = contentTmpFile.file();
1043
KoXmlWriter contentTmpWriter( tmpFile, 1 );
1046
//For sticky objects
1047
KTempFile stickyTmpFile;
1048
stickyTmpFile.setAutoDelete( true );
1049
QFile* tmpStickyFile = stickyTmpFile.file();
1050
KoXmlWriter stickyTmpWriter( tmpStickyFile, 1 );
1053
contentTmpWriter.startElement( "office:body" );
1054
contentTmpWriter.startElement( "office:presentation" );
1057
int partIndexObj = 0;
1060
if ( saveOnlyPage != -1 )
1062
m_pageList.at( saveOnlyPage )->saveOasisPage( store, contentTmpWriter, ( saveOnlyPage+1 ), savingContext, indexObj, partIndexObj , manifestWriter);
1066
for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
1068
m_pageList.at( i )->saveOasisPage( store, contentTmpWriter, ( i+1 ), savingContext, indexObj, partIndexObj , manifestWriter);
1071
QString styleMasterNamePage;
1072
if ( !_duplicatePage )
1074
m_masterPage->saveOasisStickyPage( store, stickyTmpWriter , savingContext, indexObj,partIndexObj, manifestWriter );
1075
styleMasterNamePage = m_masterPage->saveOasisPageStyle( store, savingContext.mainStyles() );
1078
if ( saveOnlyPage == -1 ) //don't save setting when we save on page
1080
saveOasisHeaderFooter( stickyTmpWriter , savingContext );
1081
saveOasisPresentationSettings( contentTmpWriter );
1084
contentTmpWriter.endElement(); //office:presentation
1085
contentTmpWriter.endElement(); //office:body
1087
writeAutomaticStyles( *contentWriter, mainStyles, savingContext );
1089
// And now we can copy over the contents from the tempfile to the real one
1091
contentWriter->addCompleteElement( tmpFile );
1092
contentTmpFile.close();
1094
contentWriter->endElement(); // root element
1095
contentWriter->endDocument();
1096
delete contentWriter;
1098
if ( !store->close() ) // done with content.xml
1102
KoGenStyle pageLayout = m_pageLayout.saveOasis();
1103
pageLayout.addAttribute( "style:page-usage", "all" ); // needed?
1104
mainStyles.lookup( pageLayout, "pm" );
1107
//add manifest line for content.xml
1108
manifestWriter->addManifestEntry( "content.xml", "text/xml" );
1110
if ( !store->open( "styles.xml" ) )
1113
manifestWriter->addManifestEntry( "styles.xml", "text/xml" );
1116
tmpStickyFile->close();
1117
saveOasisDocumentStyles( store, mainStyles, tmpStickyFile, styleMasterNamePage);
1118
stickyTmpFile.close();
1120
if ( !store->close() ) // done with styles.xml
1124
if ( saveOnlyPage == -1 )
1125
emit sigProgress( 90 );
1127
// Save sound file list.
1131
makeUsedPixmapList();
1133
m_pictureCollection.saveOasisToStore( store, usedPictures, manifestWriter);
1135
if(!store->open("settings.xml"))
1138
KoXmlWriter& settingsWriter = *createOasisXmlWriter(&contentDev, "office:document-settings");
1139
settingsWriter.startElement("office:settings");
1141
settingsWriter.startElement("config:config-item-set");
1142
settingsWriter.addAttribute("config:name", "view-settings");
1144
KoUnit::saveOasis(&settingsWriter, m_unit);
1145
saveOasisSettings( settingsWriter );
1147
settingsWriter.endElement(); // config:config-item-set
1149
settingsWriter.startElement("config:config-item-set");
1150
settingsWriter.addAttribute("config:name", "configuration-settings");
1151
settingsWriter.addConfigItem("SpellCheckerIgnoreList", m_spellCheckIgnoreList.join( "," ) );
1152
settingsWriter.endElement(); // config:config-item-set
1154
m_varColl->variableSetting()->saveOasis( settingsWriter );
1156
settingsWriter.endElement(); // office:settings
1157
settingsWriter.endElement(); // Root:Element
1158
settingsWriter.endDocument();
1159
delete &settingsWriter;
1164
manifestWriter->addManifestEntry("settings.xml", "text/xml");
1167
emit sigProgress( 100 );
1168
emit sigProgress( -1 );
1170
setModified( false );
1175
void KPresenterDoc::loadOasisIgnoreList( const KoOasisSettings& settings )
1177
KoOasisSettings::Items configurationSettings = settings.itemSet( "configuration-settings" );
1178
if ( !configurationSettings.isNull() )
1180
const QString ignorelist = configurationSettings.parseConfigItemString( "SpellCheckerIgnoreList" );
1181
m_spellCheckIgnoreList = QStringList::split( ',', ignorelist );
1185
void KPresenterDoc::writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles, KoSavingContext& context )
1187
context.writeFontFaces( contentWriter );
1188
contentWriter.startElement( "office:automatic-styles" );
1189
QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_AUTO );
1190
QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
1191
for ( ; it != styles.end() ; ++it ) {
1192
(*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
1195
styles = mainStyles.styles( KoGenStyle::STYLE_AUTO_LIST );
1196
it = styles.begin();
1197
for ( ; it != styles.end() ; ++it ) {
1198
( *it ).style->writeStyle( &contentWriter, mainStyles, "text:list-style", (*it).name, 0 );
1201
styles = mainStyles.styles( STYLE_BACKGROUNDPAGEAUTO );
1202
it = styles.begin();
1203
for ( ; it != styles.end() ; ++it ) {
1204
(*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name, "style:drawing-page-properties" );
1207
styles = mainStyles.styles( KoGenStyle::STYLE_GRAPHICAUTO );
1208
it = styles.begin();
1209
for ( ; it != styles.end() ; ++it ) {
1210
(*it).style->writeStyle( &contentWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties" );
1213
styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_DATE );
1214
it = styles.begin();
1215
for ( ; it != styles.end() ; ++it ) {
1216
(*it).style->writeStyle( &contentWriter, mainStyles, "number:date-style", (*it).name, 0 /*TODO ????*/ );
1218
styles = mainStyles.styles( KoGenStyle::STYLE_NUMERIC_TIME );
1219
it = styles.begin();
1220
for ( ; it != styles.end() ; ++it ) {
1221
(*it).style->writeStyle( &contentWriter, mainStyles, "number:time-style", (*it).name, 0 /*TODO ????*/ );
1224
contentWriter.endElement(); // office:automatic-styles
1227
void KPresenterDoc::saveOasisHeaderFooter( KoXmlWriter & stickyTmpWriter , KoSavingContext& context )
1229
stickyTmpWriter.startElement( "style:header" );
1230
header()->textObject()->saveOasisContent( stickyTmpWriter, context );
1231
stickyTmpWriter.endElement();
1233
stickyTmpWriter.startElement( "style:footer" );
1234
footer()->textObject()->saveOasisContent( stickyTmpWriter, context );
1235
stickyTmpWriter.endElement();
1238
void KPresenterDoc::loadOasisHeaderFooter(QDomNode & drawPage, KoOasisContext & context)
1240
QDomNode tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "header" );
1241
if ( !tmp.isNull() )
1243
//kdDebug()<<" there is a header \n";
1244
_header->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
1246
tmp = KoDom::namedItemNS( drawPage, KoXmlNS::style, "footer" );
1247
if ( !tmp.isNull() )
1249
//kdDebug()<<" there is a footer \n";
1250
_footer->textObject()->loadOasisContent( tmp.toElement(), context, styleCollection() );
1254
void KPresenterDoc::saveOasisSettings( KoXmlWriter &settingsWriter )
1256
settingsWriter.startElement("config:config-item-map-indexed");
1257
settingsWriter.addAttribute("config:name", "Views");
1258
settingsWriter.startElement( "config:config-item-map-entry" );
1260
//ooimpress save it as this line.
1261
//<config:config-item config:name="SnapLinesDrawing" config:type="string">H2260V14397H7693H12415H15345H1424</config:config-item>
1262
QString helpLineOasis;
1263
//save in mm as in oo
1264
for(QValueList<double>::Iterator it = m_vertHelplines.begin(); it != m_vertHelplines.end(); ++it)
1266
int tmpX = ( int ) ( KoUnit::toMM( *it )*100 );
1267
helpLineOasis+="V"+QString::number( tmpX );
1270
for(QValueList<double>::Iterator it = m_horizHelplines.begin(); it != m_horizHelplines.end(); ++it)
1272
int tmpY = ( int ) ( KoUnit::toMM( *it )*100 );
1273
helpLineOasis+="H"+QString::number( tmpY );
1275
for(QValueList<KoPoint>::Iterator it = m_helpPoints.begin(); it != m_helpPoints.end(); ++it)
1277
QString str( "P%1,%2" );
1278
int tmpX = ( int ) ( KoUnit::toMM( ( *it ).x() )*100 );
1279
int tmpY = ( int ) ( KoUnit::toMM( ( *it ).y() )*100 );
1280
helpLineOasis+=str.arg( QString::number( tmpX ) ).arg( QString::number( tmpY ) );
1282
if ( !helpLineOasis.isEmpty() )
1284
settingsWriter.addConfigItem("SnapLinesDrawing", helpLineOasis );
1286
//<config:config-item config:name="IsSnapToGrid" config:type="boolean">false</config:config-item>
1287
settingsWriter.addConfigItem( "IsSnapToGrid", m_bSnapToGrid );
1289
//<config:config-item config:name="GridFineWidth" config:type="int">500</config:config-item>
1290
settingsWriter.addConfigItem( "GridFineWidth", ( ( int ) ( KoUnit::toMM( ( m_gridX ) )*100 ) ) );
1293
//<config:config-item config:name="GridFineHeight" config:type="int">500</config:config-item>
1294
settingsWriter.addConfigItem( "GridFineHeight", ( ( int ) ( KoUnit::toMM( ( m_gridY ) )*100 ) ) );
1296
//<config:config-item config:name="SelectedPage" config:type="short">3</config:config-item>
1297
//store first view parameter.
1299
if ( m_initialActivePage )
1300
activePage=m_pageList.findRef(m_initialActivePage);
1301
activePage = QMAX( activePage, 0);
1302
settingsWriter.addConfigItem( "SelectedPage", activePage );
1304
//not define into oo spec
1305
settingsWriter.addConfigItem( "SnapLineIsVisible", showHelplines() );
1306
settingsWriter.endElement();
1307
settingsWriter.endElement();
1310
void KPresenterDoc::loadOasisSettings(const QDomDocument&settingsDoc)
1312
kdDebug()<<"void KPresenterDoc::loadOasisSettings(const QDomDocument&settingsDoc)**********\n";
1313
KoOasisSettings settings( settingsDoc );
1314
KoOasisSettings::Items viewSettings = settings.itemSet( "view-settings" );
1315
setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
1316
KoOasisSettings::IndexedMap viewMap = viewSettings.indexedMap( "Views" );
1317
KoOasisSettings::Items firstView = viewMap.entry( 0 );
1318
if ( !firstView.isNull() )
1320
parseOasisHelpLine( firstView.parseConfigItemString( "SnapLinesDrawing" ) );
1321
setShowHelplines( firstView.parseConfigItemBool( "SnapLineIsVisible" ) );
1322
int valx = firstView.parseConfigItemInt( "GridFineWidth" );
1323
m_gridX = MM_TO_POINT( valx / 100.0 );
1324
int valy = firstView.parseConfigItemInt( "GridFineHeight" );
1325
m_gridY = MM_TO_POINT( valy / 100.0 );
1327
m_bSnapToGrid = firstView.parseConfigItemBool( "IsSnapToGrid" );
1329
int activePage = firstView.parseConfigItemInt( "SelectedPage" );
1330
kdDebug()<<" activePage :"<<activePage<<endl;
1332
m_initialActivePage=m_pageList.at(activePage);
1335
loadOasisIgnoreList( settings );
1336
m_varColl->variableSetting()->loadOasis( settings );
1339
void KPresenterDoc::parseOasisHelpLine( const QString &text )
1342
int newPos = text.length()-1; //start to element = 1
1343
for ( int pos = text.length()-1; pos >=0;--pos )
1345
if ( text[pos]=='P' )
1348
str = text.mid( pos+1, ( newPos-pos ) );
1349
//kdDebug()<<" point element :"<< str <<endl;
1350
QStringList listVal = QStringList::split( ",", str );
1351
int posX = ( listVal[0].toInt()/100 );
1352
int posY = ( listVal[1].toInt()/100 );
1353
m_helpPoints.append( KoPoint( MM_TO_POINT( posX ), MM_TO_POINT( posY )));
1356
else if ( text[pos]=='V' )
1359
str = text.mid( pos+1, ( newPos-pos ) );
1360
//kdDebug()<<" vertical :"<< str <<endl;
1361
int posX = ( str.toInt()/100 );
1362
m_vertHelplines.append( MM_TO_POINT( posX ) );
1365
else if ( text[pos]=='H' )
1367
//horizontal element
1368
str = text.mid( pos+1, ( newPos-pos ) );
1369
//kdDebug()<<" horizontal :"<< str <<endl;
1370
int posY = ( str.toInt()/100 );
1371
m_horizHelplines.append( MM_TO_POINT( posY ) );
1377
void KPresenterDoc::loadOasisPresentationSettings( QDomNode &settingsDoc )
1379
//kdDebug()<<"presentation:settings ********************************************* \n";
1380
QDomElement settings( settingsDoc.toElement() );
1381
//kdDebug()<<"settings.attribute(presentation:endless) :"<<settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)<<endl;
1382
if (settings.attributeNS( KoXmlNS::presentation, "endless", QString::null)=="true")
1383
_spInfiniteLoop = true;
1385
if (settings.attributeNS( KoXmlNS::presentation, "force-manual", QString::null)=="true")
1386
_spManualSwitch = true;
1387
if ( settings.hasAttributeNS( KoXmlNS::presentation, "start-page" ) )
1389
//TODO allow to start presentation to specific page
1390
//???? = settings.attributeNS( KoXmlNS::presentation, "start-page", QString::null );
1392
if ( settings.hasAttributeNS( KoXmlNS::presentation, "show" ) )
1394
m_presentationName = settings.attributeNS( KoXmlNS::presentation, "show", QString::null );
1395
kdDebug()<<" default presentation name :"<<m_presentationName<<endl;
1397
loadOasisPresentationCustomSlideShow( settingsDoc );
1400
void KPresenterDoc::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )
1402
//kdDebug()<<"void KPresenterDoc::loadOasisPresentationCustomSlideShow( QDomNode &settingsDoc )**********\n";
1403
for ( QDomNode element = settingsDoc.firstChild(); !element.isNull(); element = element.nextSibling() )
1405
QDomElement e = element.toElement();
1406
QCString tagName = e.tagName().latin1();
1407
//kdDebug()<<" tagName :"<<tagName<<endl;
1408
if ( tagName == "show" && e.namespaceURI() == KoXmlNS::presentation)
1410
//kdDebug()<<" e.attribute(presentation:name) :"<<e.attributeNS( KoXmlNS::presentation, "name", QString::null)<< " e.attribute(presentation:pages) :"<<e.attributeNS( KoXmlNS::presentation, "pages", QString::null)<<endl;
1411
QStringList tmp = QStringList::split( ",", e.attributeNS( KoXmlNS::presentation, "pages", QString::null) );
1412
m_loadingInfo->m_tmpCustomListMap.insert( e.attributeNS( KoXmlNS::presentation, "name", QString::null), tmp );
1417
void KPresenterDoc::saveOasisPresentationSettings( KoXmlWriter &contentTmpWriter )
1419
//todo don't save when is not value by default (check with oo)
1421
contentTmpWriter.startElement( "presentation:settings" );
1422
contentTmpWriter.addAttribute( "presentation:endless", ( _spInfiniteLoop ? "true" : "false" ) );
1423
contentTmpWriter.addAttribute( "presentation:force-manual", ( _spManualSwitch ? "true" : "false" ) );
1424
//add for default presentation
1425
if ( !m_presentationName.isEmpty() )
1426
contentTmpWriter.addAttribute( "presentation:show", m_presentationName );
1428
saveOasisPresentationCustomSlideShow( contentTmpWriter );
1429
contentTmpWriter.endElement();
1432
void KPresenterDoc::saveOasisPresentationCustomSlideShow( KoXmlWriter &contentTmpWriter )
1434
if ( m_customListSlideShow.isEmpty() )
1437
ListCustomSlideShow::Iterator it;
1438
for ( it = m_customListSlideShow.begin(); it != m_customListSlideShow.end(); ++it )
1440
contentTmpWriter.startElement( "presentation:show" );
1441
contentTmpWriter.addAttribute( "presentation:name", it.key() );
1443
QValueListIterator<KPrPage*> itPage ;
1444
for( itPage = ( *it ).begin(); itPage != ( *it ).end(); ++itPage )
1446
int posPage = m_pageList.find(*itPage );
1447
if ( posPage != -1 )
1448
tmp+=( *itPage )->oasisNamePage(posPage+1)+",";
1450
contentTmpWriter.addAttribute( "presentation:pages", tmp );
1451
contentTmpWriter.endElement();
1453
//<presentation:show presentation:name="New Custom Slide Show" presentation:pages="page1,page1,page1,page1,page1"/>
1456
void KPresenterDoc::saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles, QFile* tmpStyckyFile, const QString &_styleMasterPageName ) const
1458
QString pageLayoutName;
1459
KoStoreDevice stylesDev( store );
1460
KoXmlWriter* stylesWriter = createOasisXmlWriter( &stylesDev, "office:document-styles" );
1462
stylesWriter->startElement( "office:styles" );
1463
QValueList<KoGenStyles::NamedStyle> styles = mainStyles.styles( KoGenStyle::STYLE_USER );
1464
QValueList<KoGenStyles::NamedStyle>::const_iterator it = styles.begin();
1465
for ( ; it != styles.end() ; ++it ) {
1466
(*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name, "style:paragraph-properties" );
1468
styles = mainStyles.styles( KoGenStyle::STYLE_LIST );
1469
it = styles.begin();
1470
for ( ; it != styles.end() ; ++it ) {
1471
(*it).style->writeStyle( stylesWriter, mainStyles, "text:list-style", (*it).name, 0 );
1473
styles = mainStyles.styles( KoGenStyle::STYLE_HATCH );
1474
it = styles.begin();
1475
for ( ; it != styles.end() ; ++it ) {
1476
(*it).style->writeStyle( stylesWriter, mainStyles, "draw:hatch", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1478
styles = mainStyles.styles( STYLE_GRADIENT );
1479
it = styles.begin();
1480
for ( ; it != styles.end() ; ++it ) {
1481
(*it).style->writeStyle( stylesWriter, mainStyles, "draw:gradient", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1484
styles = mainStyles.styles( STYLE_STROKE );
1485
it = styles.begin();
1486
for ( ; it != styles.end() ; ++it ) {
1487
(*it).style->writeStyle( stylesWriter, mainStyles, "draw:stroke-dash", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1490
styles = mainStyles.styles( STYLE_MARKER );
1491
it = styles.begin();
1492
for ( ; it != styles.end() ; ++it ) {
1493
(*it).style->writeStyle( stylesWriter, mainStyles, "draw:marker", (*it).name, "style:graphic-properties" , true, true /*add draw:name*/);
1495
styles = mainStyles.styles( STYLE_PICTURE );
1496
it = styles.begin();
1497
for ( ; it != styles.end() ; ++it ) {
1498
(*it).style->writeStyle( stylesWriter, mainStyles, "draw:fill-image", (*it).name, "style:image-properties" , true, true /*add draw:name*/);
1501
stylesWriter->endElement(); // office:styles
1503
stylesWriter->startElement( "office:automatic-styles" );
1504
styles = mainStyles.styles( STYLE_BACKGROUNDPAGE );
1505
it = styles.begin();
1506
for ( ; it != styles.end() ; ++it ) {
1507
(*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:drawing-page-properties" );
1510
styles = mainStyles.styles( KoGenStyle::STYLE_PAGELAYOUT );
1511
Q_ASSERT( styles.count() == 1 );
1512
it = styles.begin();
1513
for ( ; it != styles.end() ; ++it ) {
1514
(*it).style->writeStyle( stylesWriter, mainStyles, "style:page-layout", (*it).name, "style:page-layout-properties", false /*don't close*/ );
1515
stylesWriter->endElement();
1516
Q_ASSERT( pageLayoutName.isEmpty() ); // if there's more than one pagemaster we need to rethink all this
1517
pageLayoutName = (*it).name;
1520
styles = mainStyles.styles( STYLE_PRESENTATIONSTICKYOBJECT );
1521
it = styles.begin();
1522
for ( ; it != styles.end() ; ++it ) {
1523
//TODO fix me graphic-properties ???
1524
(*it).style->writeStyle( stylesWriter, mainStyles, "style:style", (*it).name , "style:graphic-properties" );
1527
stylesWriter->endElement(); // office:automatic-styles
1530
stylesWriter->startElement( "office:master-styles" );
1531
stylesWriter->startElement( "style:master-page" );
1532
stylesWriter->addAttribute( "style:name", "Standard" );
1533
stylesWriter->addAttribute( "style:page-layout-name", pageLayoutName );
1534
kdDebug()<<" styleMasterNamePage :"<<_styleMasterPageName<<endl;
1535
if ( !_styleMasterPageName.isEmpty() )
1536
stylesWriter->addAttribute( "draw:style-name", _styleMasterPageName );
1539
//save sticky object
1540
stylesWriter->addCompleteElement( tmpStyckyFile );
1541
stylesWriter->endElement();
1542
stylesWriter->endElement(); // office:master-style
1545
stylesWriter->endElement(); // root element (office:document-styles)
1546
stylesWriter->endDocument();
1547
delete stylesWriter;
1550
bool KPresenterDoc::loadOasis( const QDomDocument& doc, KoOasisStyles&oasisStyles, const QDomDocument&settingsDoc, KoStore*store )
1554
m_loadingInfo = new KPRLoadingInfo;
1555
ignoreSticky = FALSE;
1556
emit sigProgress( 0 );
1559
bool allSlides = false;
1562
__pgLayout = KoPageLayout::standardLayout();
1563
_spInfiniteLoop = false;
1564
_spManualSwitch = true;
1565
_showPresentationDuration = false;
1568
urlIntern = url().path();
1571
m_spellCheckIgnoreList.clear();
1572
emit sigProgress( 5 );
1574
QDomElement content = doc.documentElement();
1575
QDomElement body (KoDom::namedItemNS( content, KoXmlNS::office, "body" ) );
1576
if ( body.isNull() )
1578
kdError(33001) << "No office:body found!" << endl;
1579
setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
1582
body = KoDom::namedItemNS( body, KoXmlNS::office, "presentation" );
1583
if ( body.isNull() )
1585
kdError(33001) << "No office:presentation found!" << endl;
1586
setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
1590
QDomNode settings = KoDom::namedItemNS( body, KoXmlNS::presentation, "settings" );
1591
kdDebug()<<"settings :"<<settings.isNull()<<endl;
1592
if (!settings.isNull() && _clean /*don't load settings when we copy/paste a page*/)
1593
loadOasisPresentationSettings( settings );
1595
// it seems that ooimpress has different paper-settings for every slide.
1596
// we take the settings of the first slide for the whole document.
1597
QDomNode drawPage = KoDom::namedItemNS( body, KoXmlNS::draw, "page" );
1598
if ( drawPage.isNull() ) // no slides? give up.
1600
QDomElement dp = drawPage.toElement();
1603
// TODO variable settings
1604
// By default display real variable value
1605
if ( !isReadWrite())
1606
getVariableCollection()->variableSetting()->setDisplayFieldCode(false);
1608
KoOasisContext context( this, *m_varColl, oasisStyles, store );
1609
Q_ASSERT( !oasisStyles.officeStyle().isNull() );
1611
// Load all styles before the corresponding paragraphs try to use them!
1612
m_styleColl->loadOasisStyleTemplates( context );
1617
QString masterPageName = drawPage.toElement().attributeNS( KoXmlNS::draw, "master-page-name", QString::null );
1618
QDomElement *master = oasisStyles.masterPages()[ masterPageName];
1620
kdDebug()<<" master :"<<master<<endl;
1621
kdDebug()<<" masterPageName:"<<masterPageName<<endl;
1624
masterPageName = "Standard"; // use default layout as fallback (default in kpresenter)
1625
master = oasisStyles.masterPages()[ masterPageName];
1626
if ( !master ) //last test...
1627
master = oasisStyles.masterPages()["Default"];
1629
kdDebug()<<" load sticky oasis object \n";
1630
kdDebug()<<" master.isNull() :"<<master->isNull()<<endl;
1631
QDomNode node = *master;
1632
kdDebug()<<" node.isNull() :"<<node.isNull()<<endl;
1633
loadOasisObject( m_masterPage, node , context);
1634
loadOasisHeaderFooter( node,context );
1636
kdDebug()<<" end load sticky oasis object \n";
1639
QDomElement *style =master ? oasisStyles.styles()[master->attributeNS( KoXmlNS::style, "page-layout-name", QString::null )] : 0;
1640
QDomElement *backgroundStyle = oasisStyles.styles()[ "Standard-background"];
1641
kdDebug()<<"Standard background "<<backgroundStyle<<endl;
1646
__pgLayout.loadOasis( *style );
1647
kdDebug()<<"Page size __pgLayout.ptWidth :"<<__pgLayout.ptWidth<<" __pgLayout.ptHeight :"<<__pgLayout.ptHeight<<endl;
1648
kdDebug()<<"Page orientation :"<<(( __pgLayout.orientation== PG_LANDSCAPE )? " landscape " : " portrait ")<<endl;
1650
kdDebug()<<" margin right:"<< __pgLayout.ptRight <<" __pgLayout.ptBottom :"<<__pgLayout.ptBottom<<" __pgLayout.ptLeft :"<<__pgLayout.ptLeft<<" __pgLayout.ptTop :"<<__pgLayout.ptTop<<endl;
1654
/// ### this has already been done, no?
1655
setPageLayout( __pgLayout );
1660
for ( drawPage = body.firstChild(); !drawPage.isNull(); drawPage = drawPage.nextSibling() )
1662
dp = drawPage.toElement();
1663
kdDebug()<<"dp.tagName() :"<<dp.tagName()<<endl;
1664
if ( dp.tagName()== "page" && dp.namespaceURI() == KoXmlNS::draw ) // don't try to parse "</draw:page>" as page
1666
context.styleStack().clear(); // remove all styles
1667
fillStyleStack( dp, context );
1668
context.styleStack().save();
1669
kdDebug ()<<"insert new page "<<pos<<endl;
1670
KPrPage *newpage = 0L;
1671
if ( m_pageWhereLoadObject )
1673
newpage = m_pageWhereLoadObject;
1679
newpage = new KPrPage( this, m_masterPage );
1680
m_pageList.insert( pos,newpage);
1682
else //we create a first page into KPresenterDoc()
1684
newpage = m_pageList.at(pos);
1687
//m_pageList.at(pos)->insertManualTitle(dp.attributeNS( KoXmlNS::draw, "name", QString::null ));
1689
//necessary to create a unique name for page
1690
QString str = dp.attributeNS( KoXmlNS::draw, "name", QString::null );
1691
QString idPage = dp.attributeNS( KoXmlNS::draw, "id", QString::null );
1692
if ( str != QString( "page%1" ).arg( idPage ) )
1693
newpage->insertManualTitle(str);
1694
context.styleStack().setTypeProperties( "drawing-page" );
1695
if ( context.styleStack().hasAttributeNS( KoXmlNS::draw, "fill" )
1696
|| context.styleStack().hasAttributeNS( KoXmlNS::presentation, "transition-style" ) )
1698
kdDebug()<<" fill or presentation-style found \n";
1699
newpage->loadOasis( context );
1701
else if ( !context.styleStack().hasAttributeNS( KoXmlNS::draw, "fill" ) && backgroundStyle)
1703
context.styleStack().save();
1704
context.addStyles( backgroundStyle );
1705
newpage->loadOasis(context);
1706
context.styleStack().restore();
1707
kdDebug()<<" load standard background \n";
1710
//All animation object for current page is store into this element
1711
createPresentationAnimation(KoDom::namedItemNS( drawPage, KoXmlNS::presentation, "animations"));
1712
// parse all objects
1713
loadOasisObject( newpage, drawPage, context );
1715
context.styleStack().restore();
1716
m_loadingInfo->clearAnimationShowDict(); // clear all show animations style
1717
m_loadingInfo->clearAnimationHideDict(); // clear all hide animations style
1723
ignoreSticky = TRUE;
1724
kdDebug()<<" _clean :"<<_clean<<endl;
1729
//it crashed, I don't know why for the moment.
1730
startBackgroundSpellCheck();
1733
updateCustomListSlideShow( m_loadingInfo->m_tmpCustomListMap, true );
1734
kdDebug(33001) << "Loading took " << (float)(dt.elapsed()) / 1000.0 << " seconds" << endl;
1736
if ( !settingsDoc.isNull() )
1738
loadOasisSettings( settingsDoc );
1740
emit sigProgress( 100 );
1741
recalcVariables( VT_FIELD );
1742
emit sigProgress( -1 );
1744
setModified( false );
1749
void KPresenterDoc::loadOasisObject( KPrPage * newpage, QDomNode & drawPage, KoOasisContext & context, KPGroupObject *groupObject )
1751
for ( QDomNode object = drawPage.firstChild(); !object.isNull(); object = object.nextSibling() )
1753
QDomElement o = object.toElement();
1754
QString name = o.tagName();
1755
kdDebug()<<" name :"<<name<<endl;
1756
context.styleStack().save();
1757
const bool isDrawNS = o.namespaceURI() == KoXmlNS::draw;
1759
if ( name == "frame" && isDrawNS) // textbox
1761
fillStyleStack( o, context );
1763
QDomNode imageBox = KoDom::namedItemNS( o, KoXmlNS::draw, "image" );
1764
kdDebug()<<" imageBox:"<<imageBox.isNull()<<endl;
1765
if ( !imageBox.isNull() )
1767
KPPixmapObject *kppixmapobject = new KPPixmapObject( pictureCollection() );
1768
kppixmapobject->loadOasis( o, context, m_loadingInfo);
1770
groupObject->addObjects( kppixmapobject );
1772
newpage->appendObject(kppixmapobject);
1776
QDomNode object = KoDom::namedItemNS( o, KoXmlNS::draw, "object" );
1777
kdDebug()<<" object:"<<object.isNull()<<endl;
1778
if ( !object.isNull() )
1780
fillStyleStack( o, context );
1781
KPresenterChild *ch = new KPresenterChild( this );
1783
KPPartObject *kppartobject = new KPPartObject( ch );
1784
kppartobject->loadOasis( o, context, m_loadingInfo );
1787
groupObject->addObjects( kppartobject );
1789
newpage->appendObject(kppartobject);
1791
kppartobject->setOrig( r.x(), r.y() );
1792
kppartobject->setSize( r.width(), r.height() );
1796
KPTextObject *kptextobject = new KPTextObject( this );
1797
kptextobject->loadOasis(o, context, m_loadingInfo);
1799
groupObject->addObjects( kptextobject );
1801
newpage->appendObject(kptextobject);
1805
else if ( name == "rect" && isDrawNS) // rectangle
1807
fillStyleStack( o, context );
1808
KPRectObject *kprectobject = new KPRectObject();
1809
kprectobject->loadOasis(o, context , m_loadingInfo);
1811
groupObject->addObjects( kprectobject );
1813
newpage->appendObject(kprectobject);
1815
else if ( ( name == "circle" || name == "ellipse" )&& isDrawNS)
1817
fillStyleStack( o, context );
1818
if ( o.hasAttributeNS( KoXmlNS::draw, "kind" ) ) // pie, chord or arc
1820
KPPieObject *kppieobject = new KPPieObject();
1821
kppieobject->loadOasis(o, context, m_loadingInfo);
1823
groupObject->addObjects( kppieobject );
1825
newpage->appendObject(kppieobject);
1827
else // circle or ellipse
1829
KPEllipseObject *kpellipseobject = new KPEllipseObject();
1830
kpellipseobject->loadOasis(o,context, m_loadingInfo);
1832
groupObject->addObjects( kpellipseobject );
1834
newpage->appendObject(kpellipseobject);
1837
else if ( name == "line" && isDrawNS) // line
1839
fillStyleStack( o, context );
1840
KPLineObject *kplineobject = new KPLineObject();
1841
kplineobject->loadOasis(o, context, m_loadingInfo);
1843
groupObject->addObjects( kplineobject );
1845
newpage->appendObject( kplineobject );
1847
else if (name=="polyline" && isDrawNS) { // polyline
1848
fillStyleStack( o, context );
1849
KPPolylineObject *kppolylineobject = new KPPolylineObject();
1850
kppolylineobject->loadOasis(o, context, m_loadingInfo);
1852
groupObject->addObjects( kppolylineobject );
1854
newpage->appendObject(kppolylineobject);
1856
else if (name=="polygon" && isDrawNS) { // plcloseobject
1857
fillStyleStack( o, context );
1858
KPClosedLineObject *kpClosedObject = new KPClosedLineObject();
1859
kpClosedObject->loadOasis( o, context, m_loadingInfo);
1861
groupObject->addObjects( kpClosedObject );
1863
newpage->appendObject(kpClosedObject);
1865
//FIXME wait that it will ok'ed by oo spec
1866
else if (name=="regular-polygon"&& isDrawNS) { // kppolygone object
1867
fillStyleStack( o, context );
1868
KPPolygonObject *kpPolygoneObject = new KPPolygonObject();
1869
kpPolygoneObject->loadOasis( o, context, m_loadingInfo);
1871
groupObject->addObjects( kpPolygoneObject );
1873
newpage->appendObject(kpPolygoneObject);
1876
else if ( name == "image" && isDrawNS) // image
1878
fillStyleStack( o, context );
1879
KPPixmapObject *kppixmapobject = new KPPixmapObject( pictureCollection() );
1880
kppixmapobject->loadOasis( o, context, m_loadingInfo);
1882
groupObject->addObjects( kppixmapobject );
1884
newpage->appendObject(kppixmapobject);
1887
else if ( name == "path" && isDrawNS)
1889
//we have 4 elements to use here.
1890
//Cubicbeziercurve/Quadricbeziercurve/closeline/KPFreehandObject
1891
//we must parse svd:d argument
1892
// "z" close element
1893
// "c" cubic element
1894
// "q" quadic element
1895
// parse line we use relative position
1896
// see http://www.w3.org/TR/SVG/paths.html#PathData
1897
// see svgpathparser.cc (ksvg)
1898
QString pathDefinition = o.attributeNS( KoXmlNS::svg, "d", QString::null);
1899
kdDebug()<<"pathDefinition :"<<pathDefinition<<endl;
1900
fillStyleStack( o, context );
1902
if ( pathDefinition.contains( "c" ) )
1904
kdDebug()<<"Cubicbeziercurve \n";
1905
KPCubicBezierCurveObject *kpCurveObject = new KPCubicBezierCurveObject();
1906
kpCurveObject->loadOasis( o, context, m_loadingInfo);
1908
groupObject->addObjects( kpCurveObject );
1910
newpage->appendObject( kpCurveObject );
1913
else if ( pathDefinition.contains( "q" ) )
1915
kdDebug()<<"Quadricbeziercurve \n";
1916
KPQuadricBezierCurveObject *kpQuadricObject = new KPQuadricBezierCurveObject();
1917
kpQuadricObject->loadOasis( o, context, m_loadingInfo);
1919
groupObject->addObjects( kpQuadricObject );
1921
newpage->appendObject( kpQuadricObject );
1925
kdDebug()<<"KPFreehandObject \n";
1926
KPFreehandObject *kpFreeHandObject = new KPFreehandObject();
1927
kpFreeHandObject->loadOasis( o, context, m_loadingInfo);
1929
groupObject->addObjects( kpFreeHandObject );
1931
newpage->appendObject( kpFreeHandObject );
1934
else if ( name == "g" && isDrawNS)
1936
fillStyleStack( o, context );
1937
KPGroupObject *kpgroupobject = new KPGroupObject();
1938
QDomNode nodegroup = object.firstChild();
1940
kpgroupobject->loadOasisGroupObject( this, newpage, object, context, m_loadingInfo);
1942
groupObject->addObjects( kpgroupobject );
1944
newpage->appendObject(kpgroupobject);
1946
else if ( name == "notes" && o.namespaceURI() == KoXmlNS::presentation ) // notes
1948
//we must extend note attribute
1949
//kdDebug()<<"presentation:notes----------------------------------\n";
1950
QDomNode frameBox = KoDom::namedItemNS( o, KoXmlNS::draw, "frame" );
1951
//todo load layout for note.
1952
QDomNode textBox = KoDom::namedItemNS( frameBox, KoXmlNS::draw, "text-box" );
1954
if ( !textBox.isNull() )
1957
for ( QDomNode text = textBox.firstChild(); !text.isNull(); text = text.nextSibling() )
1959
// We don't care about styles as they are not supported in kpresenter.
1960
// Only add a linebreak for every child.
1961
QDomElement t = text.toElement();
1962
note += t.text() + "\n";
1963
kdDebug()<<" note :"<<note<<endl;
1965
newpage->setNoteText( note );
1968
else if ( ( name == "header" || name == "footer" ) && o.namespaceURI() == KoXmlNS::style )
1974
kdDebug() << "Unsupported object '" << name << "'" << endl;
1975
context.styleStack().restore();
1978
context.styleStack().restore();
1983
int KPresenterDoc::createPresentationAnimation(const QDomElement& element, int order, bool increaseOrder)
1985
kdDebug()<<"void KPresenterDoc::createPresentationAnimation(const QDomElement& element)\n";
1986
int orderAnimation = increaseOrder ? 0 : order;
1987
for ( QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
1989
QDomElement e = n.toElement();
1990
QCString tagName = e.tagName().latin1();
1991
const bool isPresentationNS = e.namespaceURI() == KoXmlNS::presentation;
1992
kdDebug()<<"(createPresentationAnimation) tagName found :"<<tagName<<endl;
1993
if ( tagName == "show-shape" && isPresentationNS )
1995
Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
1996
QString name = e.attributeNS( KoXmlNS::draw, "shape-id", QString::null );
1997
kdDebug()<<" insert animation show style : name :"<<name<<endl;
1998
QDomElement* ep = new QDomElement( e );
1999
lstAnimation *tmp = new lstAnimation;
2001
tmp->order = orderAnimation;
2002
m_loadingInfo->storePresentationShowAnimation( tmp, name );
2003
if ( increaseOrder )
2007
else if ( tagName == "hide-shape" && isPresentationNS)
2009
Q_ASSERT( e.hasAttributeNS( KoXmlNS::draw, "shape-id" ) );
2010
QString name = e.attributeNS( KoXmlNS::draw, "shape-id", QString::null );
2011
kdDebug()<<" insert animation hide style : name :"<<name<<endl;
2012
QDomElement* ep = new QDomElement( e );
2013
lstAnimation *tmp = new lstAnimation;
2015
tmp->order = orderAnimation;
2016
m_loadingInfo->storePresentationHideAnimation( tmp, name );
2017
if ( increaseOrder )
2021
else if ( tagName == "animation-group" && isPresentationNS)
2023
kdDebug()<<" presentation:animation-group exist \n";
2024
orderAnimation = createPresentationAnimation( e, orderAnimation, false );
2025
kdDebug()<<" end presentation:animation-group exist\n";
2028
//increase when we finish it necessary for group object
2030
return orderAnimation;
2033
void KPresenterDoc::fillStyleStack( const QDomElement& object, KoOasisContext & context )
2035
// find all styles associated with an object and push them on the stack
2036
if ( object.hasAttributeNS( KoXmlNS::presentation, "style-name" ))
2038
//kdDebug()<<"Add 'presentation:style-name' \n";
2039
addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::presentation, "style-name", QString::null )], context );
2041
if ( object.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
2043
kdDebug()<<"draw:style-name :"<<object.attributeNS( KoXmlNS::draw, "style-name", QString::null )<<endl;
2044
addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::draw, "style-name", QString::null )], context);
2046
if ( object.hasAttributeNS( KoXmlNS::draw, "text-style-name" ) )
2048
//kdDebug()<<"Add 'draw:text-style-name' \n";
2049
addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::draw, "text-style-name", QString::null )], context );
2051
if ( object.hasAttributeNS( KoXmlNS::text, "style-name" ) )
2053
//kdDebug()<<"Add 'text:style-name' : "<<object.attributeNS( KoXmlNS::text, "style-name", QString::null )<<endl;
2054
addStyles( context.oasisStyles().styles()[object.attributeNS( KoXmlNS::text, "style-name", QString::null )], context );
2058
void KPresenterDoc::addStyles( const QDomElement* style, KoOasisContext & context )
2060
// this function is necessary as parent styles can have parents themself
2061
if ( style->hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
2062
addStyles( context.oasisStyles().styles()[style->attributeNS( KoXmlNS::style, "parent-style-name", QString::null )], context );
2063
context.addStyles( style );
894
2067
bool KPresenterDoc::loadXML( QIODevice * dev, const QDomDocument& doc )
2071
m_loadingInfo = new KPRLoadingInfo( true );
899
2073
ignoreSticky = FALSE;