From 806fd2eafba492fb92737aacffafbf4ddb4292d5 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Fri, 27 Jul 2012 12:36:53 +0200 Subject: [PATCH] Allow nameless tools (which default to predefined names) Removed name attribute from default tools (ie those from tools.xml), so that they now get default names, which automatically translated if the application language is switched. With this patch, tools.xml no longer contains strings to be translated. NOTE: Messages.sh was not tested --- Messages.sh | 2 -- conf/okular.kcfg | 3 -- conf/settings.kcfgc | 2 +- conf/widgetannottools.cpp | 62 ++++++++++++--------------------------- ui/data/tools.xml | 18 ++++++------ ui/pageviewannotator.cpp | 37 ++++++++++++++++++++++- ui/pageviewannotator.h | 1 + 7 files changed, 66 insertions(+), 59 deletions(-) diff --git a/Messages.sh b/Messages.sh index 6d0d0b08c..d4a47052a 100644 --- a/Messages.sh +++ b/Messages.sh @@ -1,6 +1,4 @@ #!/bin/sh $EXTRACTRC *.rc */*.rc >> rc.cpp || exit 11 $EXTRACTRC $(find conf/ -name "*.ui") $(find core/ -name "*.ui") $(find ui/ -name "*.ui") $(ls . | grep -E '\.ui') >> rc.cpp || exit 12 -$EXTRACTRC --tag=tooltip --context='Annotation tool' ui/data/tools.xml >> rc.cpp || exit 13 -$EXTRACTATTR -attr=tool,name ui/data/tools.xml >> rc.cpp || exit 14 $XGETTEXT $(find conf/ -name "*.cpp" -o -name "*.h") $(find core/ -name "*.cpp" -o -name "*.h") $(find ui/ -name "*.cpp" -o -name "*.h") $(find shell/ -name "*.cpp" -o -name "*.h") $(ls . | grep -E '\.cpp$') $(ls . | grep -E '\.h$') -o $podir/okular.pot diff --git a/conf/okular.kcfg b/conf/okular.kcfg index 0669f1c89..ac82028c7 100644 --- a/conf/okular.kcfg +++ b/conf/okular.kcfg @@ -255,9 +255,6 @@ QDomElement toolElement = toolDescription.toElement(); if ( toolElement.tagName() == "tool" ) { - // Translate strings - toolElement.setAttribute( "name", i18n( toolElement.attribute("name").toUtf8() ) ); - QDomDocument temp; temp.appendChild( temp.importNode( toolElement, true) ); // add each <tool>...</tool> as XML string diff --git a/conf/settings.kcfgc b/conf/settings.kcfgc index b353b689f..24c31bb64 100644 --- a/conf/settings.kcfgc +++ b/conf/settings.kcfgc @@ -5,5 +5,5 @@ Inherits=SettingsCore Mutators=true Singleton=true IncludeFiles=core/okular_export.h, settings_core.h -SourceIncludeFiles=klocalizedstring.h,kstandarddirs.h,qdom.h +SourceIncludeFiles=kstandarddirs.h,qdom.h MemberVariables=dpointer diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index 05bfc1bb2..82aaa1960 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -73,7 +73,7 @@ WidgetAnnotTools::~WidgetAnnotTools() { } -/* Before returning the XML strings, this functions updates the name, id and +/* Before returning the XML strings, this functions updates the id and * shortcut properties. * Note: The shortcut is only assigned to the first nine tools */ QStringList WidgetAnnotTools::tools() const @@ -89,9 +89,8 @@ QStringList WidgetAnnotTools::tools() const QDomDocument doc; doc.setContent( listEntry->data( ToolXmlRole ).value() ); - // Set name and id + // Set id QDomElement toolElement = doc.documentElement(); - toolElement.setAttribute( "name", listEntry->text() ); toolElement.setAttribute( "id", i+1 ); // Remove old shortcut, if any @@ -132,7 +131,9 @@ void WidgetAnnotTools::setTools(const QStringList& items) if ( toolElement.tagName() == "tool" ) { // Create list item and attach the source XML string as data - const QString itemText = toolElement.attribute( "name" ); + QString itemText = toolElement.attribute( "name" ); + if ( itemText.isEmpty() ) + itemText = PageViewAnnotator::defaultToolName( toolElement ); QListWidgetItem * listEntry = new QListWidgetItem( itemText, m_list ); listEntry->setData( ToolXmlRole, qVariantFromValue(toolXml) ); listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) ); @@ -168,8 +169,16 @@ void WidgetAnnotTools::slotAdd( bool ) entryParser.setContent( t.toolXml() ); QDomElement toolElement = entryParser.documentElement(); + QString itemText = t.name(); + + // Store name attribute only if the user specified a customized name + if ( !itemText.isEmpty() ) + toolElement.setAttribute( "name", itemText ); + else + itemText = PageViewAnnotator::defaultToolName( toolElement ); + // Create list entry and attach XML string as data - QListWidgetItem * listEntry = new QListWidgetItem( t.name(), m_list ); + QListWidgetItem * listEntry = new QListWidgetItem( itemText, m_list ); listEntry->setData( ToolXmlRole, qVariantFromValue( entryParser.toString(-1) ) ); listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) ); @@ -257,10 +266,7 @@ NewAnnotToolDialog::~NewAnnotToolDialog() QString NewAnnotToolDialog::name() const { - QString userText = m_name->text(); - if ( userText.isEmpty() ) - userText = m_name->placeholderText(); - return userText; + return m_name->text(); } QString NewAnnotToolDialog::toolXml() const @@ -476,40 +482,10 @@ void NewAnnotToolDialog::rebuildAppearanceBox() void NewAnnotToolDialog::updateDefaultName() { - const QByteArray toolType = m_type->itemData( m_type->currentIndex() ).toByteArray(); - QString defaultName = m_type->currentText(); - - if ( toolType == "text-markup" ) - { - Okular::HighlightAnnotation * ha = static_cast( m_stubann ); - - switch ( ha->highlightType() ) - { - case Okular::HighlightAnnotation::Highlight: - defaultName = i18n( "Highlight" ); - break; - case Okular::HighlightAnnotation::Squiggly: - defaultName = i18n( "Squiggly" ); - break; - case Okular::HighlightAnnotation::Underline: - defaultName = i18n( "Underline" ); - break; - case Okular::HighlightAnnotation::StrikeOut: - defaultName = i18n( "Strike out" ); - break; - } - } - else if ( toolType == "geometrical-shape" ) - { - Okular::GeomAnnotation * ga = static_cast( m_stubann ); - - if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle ) - defaultName = i18n( "Ellipse" ); - else - defaultName = i18n( "Rectangle" ); - } - - m_name->setPlaceholderText( defaultName ); + QDomDocument entryParser; + entryParser.setContent( toolXml() ); + QDomElement toolElement = entryParser.documentElement(); + m_name->setPlaceholderText( PageViewAnnotator::defaultToolName( toolElement ) ); } void NewAnnotToolDialog::slotTypeChanged() diff --git a/ui/data/tools.xml b/ui/data/tools.xml index 70a1a5a08..2e7aeea60 100644 --- a/ui/data/tools.xml +++ b/ui/data/tools.xml @@ -17,55 +17,55 @@ Engine/Annotation Types [specific attributes]: Geom --> - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 - + 7 - + 8 - + diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 47f8a8995..a3c44ddff 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -663,7 +663,10 @@ void PageViewAnnotator::reparseConfig() { AnnotationToolItem item; item.id = toolElement.attribute("id").toInt(); - item.text = toolElement.attribute( "name" ); + if ( toolElement.hasAttribute( "name" ) ) + item.text = toolElement.attribute( "name" ); + else + item.text = defaultToolName( toolElement ); item.pixmap = makeToolPixmap( toolElement ); QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 ); if ( shortcutNode.isElement() ) @@ -1036,6 +1039,38 @@ void PageViewAnnotator::detachAnnotation() m_toolBar->selectButton( -1 ); } +QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) +{ + const QString annotType = toolElement.attribute( "type" ); + + if ( annotType == "ellipse" ) + return i18n( "Ellipse" ); + else if ( annotType == "highlight" ) + return i18n( "Highlighter" ); + else if ( annotType == "ink" ) + return i18n( "Freehand Line" ); + else if ( annotType == "note-inline" ) + return i18n( "Inline Note" ); + else if ( annotType == "note-linked" ) + return i18n( "Note" ); + else if ( annotType == "polygon" ) + return i18n( "Polygon" ); + else if ( annotType == "rectangle" ) + return i18n( "Rectangle" ); + else if ( annotType == "squiggly" ) + return i18n( "Squiggly" ); + else if ( annotType == "stamp" ) + return i18n( "Stamp" ); + else if ( annotType == "straight-line" ) + return i18n( "Straight Line" ); + else if ( annotType == "strikeout" ) + return i18n( "Strike out" ); + else if ( annotType == "underline" ) + return i18n( "Underline" ); + else + return QString(); +} + QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) { QPixmap pixmap( 32, 32 ); diff --git a/ui/pageviewannotator.h b/ui/pageviewannotator.h index 568f90ccc..33e42a7b5 100644 --- a/ui/pageviewannotator.h +++ b/ui/pageviewannotator.h @@ -77,6 +77,7 @@ class PageViewAnnotator : public QObject void reparseConfig(); + static QString defaultToolName( const QDomElement &toolElement ); static QPixmap makeToolPixmap( const QDomElement &toolElement ); private slots: