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
remotes/origin/epub-qtextdoc
Fabio D'Urso 14 years ago
parent def23dd0ba
commit 806fd2eafb
  1. 2
      Messages.sh
  2. 3
      conf/okular.kcfg
  3. 2
      conf/settings.kcfgc
  4. 62
      conf/widgetannottools.cpp
  5. 18
      ui/data/tools.xml
  6. 37
      ui/pageviewannotator.cpp
  7. 1
      ui/pageviewannotator.h

@ -1,6 +1,4 @@
#!/bin/sh #!/bin/sh
$EXTRACTRC *.rc */*.rc >> rc.cpp || exit 11 $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 $(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 $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

@ -255,9 +255,6 @@
QDomElement toolElement = toolDescription.toElement(); QDomElement toolElement = toolDescription.toElement();
if ( toolElement.tagName() == "tool" ) if ( toolElement.tagName() == "tool" )
{ {
// Translate strings
toolElement.setAttribute( "name", i18n( toolElement.attribute("name").toUtf8() ) );
QDomDocument temp; QDomDocument temp;
temp.appendChild( temp.importNode( toolElement, true) ); temp.appendChild( temp.importNode( toolElement, true) );
// add each <tool>...</tool> as XML string // add each <tool>...</tool> as XML string

@ -5,5 +5,5 @@ Inherits=SettingsCore
Mutators=true Mutators=true
Singleton=true Singleton=true
IncludeFiles=core/okular_export.h, settings_core.h IncludeFiles=core/okular_export.h, settings_core.h
SourceIncludeFiles=klocalizedstring.h,kstandarddirs.h,qdom.h SourceIncludeFiles=kstandarddirs.h,qdom.h
MemberVariables=dpointer MemberVariables=dpointer

@ -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. * shortcut properties.
* Note: The shortcut is only assigned to the first nine tools */ * Note: The shortcut is only assigned to the first nine tools */
QStringList WidgetAnnotTools::tools() const QStringList WidgetAnnotTools::tools() const
@ -89,9 +89,8 @@ QStringList WidgetAnnotTools::tools() const
QDomDocument doc; QDomDocument doc;
doc.setContent( listEntry->data( ToolXmlRole ).value<QString>() ); doc.setContent( listEntry->data( ToolXmlRole ).value<QString>() );
// Set name and id // Set id
QDomElement toolElement = doc.documentElement(); QDomElement toolElement = doc.documentElement();
toolElement.setAttribute( "name", listEntry->text() );
toolElement.setAttribute( "id", i+1 ); toolElement.setAttribute( "id", i+1 );
// Remove old shortcut, if any // Remove old shortcut, if any
@ -132,7 +131,9 @@ void WidgetAnnotTools::setTools(const QStringList& items)
if ( toolElement.tagName() == "tool" ) if ( toolElement.tagName() == "tool" )
{ {
// Create list item and attach the source XML string as data // 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 ); QListWidgetItem * listEntry = new QListWidgetItem( itemText, m_list );
listEntry->setData( ToolXmlRole, qVariantFromValue(toolXml) ); listEntry->setData( ToolXmlRole, qVariantFromValue(toolXml) );
listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) ); listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) );
@ -168,8 +169,16 @@ void WidgetAnnotTools::slotAdd( bool )
entryParser.setContent( t.toolXml() ); entryParser.setContent( t.toolXml() );
QDomElement toolElement = entryParser.documentElement(); 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 // 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->setData( ToolXmlRole, qVariantFromValue( entryParser.toString(-1) ) );
listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) ); listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) );
@ -257,10 +266,7 @@ NewAnnotToolDialog::~NewAnnotToolDialog()
QString NewAnnotToolDialog::name() const QString NewAnnotToolDialog::name() const
{ {
QString userText = m_name->text(); return m_name->text();
if ( userText.isEmpty() )
userText = m_name->placeholderText();
return userText;
} }
QString NewAnnotToolDialog::toolXml() const QString NewAnnotToolDialog::toolXml() const
@ -476,40 +482,10 @@ void NewAnnotToolDialog::rebuildAppearanceBox()
void NewAnnotToolDialog::updateDefaultName() void NewAnnotToolDialog::updateDefaultName()
{ {
const QByteArray toolType = m_type->itemData( m_type->currentIndex() ).toByteArray(); QDomDocument entryParser;
QString defaultName = m_type->currentText(); entryParser.setContent( toolXml() );
QDomElement toolElement = entryParser.documentElement();
if ( toolType == "text-markup" ) m_name->setPlaceholderText( PageViewAnnotator::defaultToolName( toolElement ) );
{
Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( 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<Okular::GeomAnnotation*>( m_stubann );
if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle )
defaultName = i18n( "Ellipse" );
else
defaultName = i18n( "Rectangle" );
}
m_name->setPlaceholderText( defaultName );
} }
void NewAnnotToolDialog::slotTypeChanged() void NewAnnotToolDialog::slotTypeChanged()

@ -17,55 +17,55 @@ Engine/Annotation Types [specific attributes]:
Geom Geom
--> -->
<annotatingTools> <annotatingTools>
<tool id="1" name="Note" type="note-linked"> <tool id="1" type="note-linked">
<engine type="PickPoint" color="#FFFF00" hoverIcon="tool-note"> <engine type="PickPoint" color="#FFFF00" hoverIcon="tool-note">
<annotation type="Text" color="#FFFF00" icon="Note" /> <annotation type="Text" color="#FFFF00" icon="Note" />
</engine> </engine>
<shortcut>1</shortcut> <shortcut>1</shortcut>
</tool> </tool>
<tool id="2" name="Inline Note" type="note-inline"> <tool id="2" type="note-inline">
<engine type="PickPoint" color="#FFFF00" hoverIcon="tool-note-inline" block="true"> <engine type="PickPoint" color="#FFFF00" hoverIcon="tool-note-inline" block="true">
<annotation type="FreeText" color="#FFFF00" /> <annotation type="FreeText" color="#FFFF00" />
</engine> </engine>
<shortcut>2</shortcut> <shortcut>2</shortcut>
</tool> </tool>
<tool id="3" name="Green Freehand Line" type="ink"> <tool id="3" type="ink">
<engine type="SmoothLine" color="#00FF00"> <engine type="SmoothLine" color="#00FF00">
<annotation type="Ink" color="#00FF00" width="2" /> <annotation type="Ink" color="#00FF00" width="2" />
</engine> </engine>
<shortcut>3</shortcut> <shortcut>3</shortcut>
</tool> </tool>
<tool id="4" name="Yellow Highlighter" type="highlight"> <tool id="4" type="highlight">
<engine type="TextSelector" color="#FFFF00"> <engine type="TextSelector" color="#FFFF00">
<annotation type="Highlight" color="#FFFF00" /> <annotation type="Highlight" color="#FFFF00" />
</engine> </engine>
<shortcut>4</shortcut> <shortcut>4</shortcut>
</tool> </tool>
<tool id="5" name="Straight Yellow Line" type="straight-line"> <tool id="5" type="straight-line">
<engine type="PolyLine" color="#FFE000" points="2"> <engine type="PolyLine" color="#FFE000" points="2">
<annotation type="Line" width="1" color="#FFE000" /> <annotation type="Line" width="1" color="#FFE000" />
</engine> </engine>
<shortcut>5</shortcut> <shortcut>5</shortcut>
</tool> </tool>
<tool id="6" name="Blue Polygon" type="polygon"> <tool id="6" type="polygon">
<engine type="PolyLine" color="#007EEE" points="-1"> <engine type="PolyLine" color="#007EEE" points="-1">
<annotation type="Line" width="1" color="#007EEE" /> <annotation type="Line" width="1" color="#007EEE" />
</engine> </engine>
<shortcut>6</shortcut> <shortcut>6</shortcut>
</tool> </tool>
<tool id="7" name="Stamp" type="stamp"> <tool id="7" type="stamp">
<engine type="PickPoint" hoverIcon="okular" size="64" block="true"> <engine type="PickPoint" hoverIcon="okular" size="64" block="true">
<annotation type="Stamp" icon="okular"/> <annotation type="Stamp" icon="okular"/>
</engine> </engine>
<shortcut>7</shortcut> <shortcut>7</shortcut>
</tool> </tool>
<tool id="8" name="Black Underlining" type="underline"> <tool id="8" type="underline">
<engine type="TextSelector" color="#000000"> <engine type="TextSelector" color="#000000">
<annotation type="Underline" color="#000000" /> <annotation type="Underline" color="#000000" />
</engine> </engine>
<shortcut>8</shortcut> <shortcut>8</shortcut>
</tool> </tool>
<tool id="9" name="Cyan Ellipse" type="ellipse"> <tool id="9" type="ellipse">
<engine type="PickPoint" color="#00ffff" block="true"> <engine type="PickPoint" color="#00ffff" block="true">
<annotation type="GeomCircle" width="5" color="#00ffff" /> <annotation type="GeomCircle" width="5" color="#00ffff" />
</engine> </engine>

@ -663,7 +663,10 @@ void PageViewAnnotator::reparseConfig()
{ {
AnnotationToolItem item; AnnotationToolItem item;
item.id = toolElement.attribute("id").toInt(); 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 ); item.pixmap = makeToolPixmap( toolElement );
QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 ); QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 );
if ( shortcutNode.isElement() ) if ( shortcutNode.isElement() )
@ -1036,6 +1039,38 @@ void PageViewAnnotator::detachAnnotation()
m_toolBar->selectButton( -1 ); 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 PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement )
{ {
QPixmap pixmap( 32, 32 ); QPixmap pixmap( 32, 32 );

@ -77,6 +77,7 @@ class PageViewAnnotator : public QObject
void reparseConfig(); void reparseConfig();
static QString defaultToolName( const QDomElement &toolElement );
static QPixmap makeToolPixmap( const QDomElement &toolElement ); static QPixmap makeToolPixmap( const QDomElement &toolElement );
private slots: private slots:

Loading…
Cancel
Save