diff --git a/ui/pageview.cpp b/ui/pageview.cpp index e129f99f8..761c9edce 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -684,6 +684,8 @@ void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool docu d->aPageSizes->setItems( items ); } d->aToggleForms->setEnabled( !pageSet.isEmpty() && hasformwidgets ); + if ( d->annotator ) + d->annotator->setTextToolsEnabled( d->document->supportsSearching() ); } void PageView::notifyViewportChanged( bool smoothMove ) @@ -2900,7 +2902,10 @@ void PageView::slotToggleAnnotator( bool on ) // create the annotator object if not present if ( !d->annotator ) + { d->annotator = new PageViewAnnotator( this, d->document ); + d->annotator->setTextToolsEnabled( d->document->supportsSearching() ); + } // initialize/reset annotator (and show/hide toolbar) d->annotator->setEnabled( on ); diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 4da1838e3..89cc8af9a 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -578,7 +578,8 @@ class TextSelectorEngine : public AnnotatorEngine PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) : QObject( parent ), m_document( storage ), m_pageView( parent ), - m_toolBar( 0 ), m_engine( 0 ), m_lastToolID( -1 ), m_lockedItem( 0 ) + m_toolBar( 0 ), m_engine( 0 ), m_textToolsEnabled( true ), m_lastToolID( -1 ), + m_lockedItem( 0 ) { // load the tools from the 'xml tools definition' file. store the tree internally. QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") ); @@ -589,20 +590,27 @@ PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * stor { m_toolsDefinition = doc.elementsByTagName("annotatingTools").item( 0 ).toElement(); - // create the ToolBarItems from the XML dom tree + // create the AnnotationItems from the XML dom tree QDomNode toolDescription = m_toolsDefinition.firstChild(); while ( toolDescription.isElement() ) { QDomElement toolElement = toolDescription.toElement(); if ( toolElement.tagName() == "tool" ) { - ToolBarItem item; + AnnotationItem item; item.id = toolElement.attribute("id").toInt(); item.text = toolElement.attribute("name"); item.pixmap = toolElement.attribute("pixmap"); QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 ); if ( shortcutNode.isElement() ) item.shortcut = shortcutNode.toElement().text(); + QDomNodeList engineNodeList = toolElement.elementsByTagName( "engine" ); + if ( engineNodeList.size() > 0 ) + { + QDomElement engineEl = engineNodeList.item( 0 ).toElement(); + if ( !engineEl.isNull() && engineEl.hasAttribute( "type" ) ) + item.isText = engineEl.attribute( "type" ) == QLatin1String( "TextSelector" ); + } m_items.push_back( item ); } toolDescription = toolDescription.nextSibling(); @@ -621,6 +629,25 @@ PageViewAnnotator::~PageViewAnnotator() delete m_engine; } +static QLinkedList filteredItems( const QLinkedList &items, bool textTools ) +{ + if ( textTools ) + { + return items; + } + else + { + QLinkedList newitems; + QLinkedList::ConstIterator it = items.begin(), itEnd = items.end(); + for ( ; it != itEnd; ++it ) + { + if ( !(*it).isText ) + newitems.append( *it ); + } + return newitems; + } +} + void PageViewAnnotator::setEnabled( bool on ) { if ( !on ) @@ -642,6 +669,8 @@ void PageViewAnnotator::setEnabled( bool on ) if ( !m_toolBar ) { m_toolBar = new PageViewToolBar( m_pageView, m_pageView->viewport() ); + m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); + m_toolBar->setItems( filteredItems( m_items, m_textToolsEnabled ) ); connect( m_toolBar, SIGNAL( toolSelected(int) ), this, SLOT( slotToolSelected(int) ) ); connect( m_toolBar, SIGNAL( orientationChanged(int) ), @@ -649,7 +678,7 @@ void PageViewAnnotator::setEnabled( bool on ) } // show the toolBar - m_toolBar->showItems( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement(), m_items ); + m_toolBar->showAndAnimate(); // ask for Author's name if not already set if ( Okular::Settings::identityAuthor().isEmpty() ) @@ -672,6 +701,16 @@ void PageViewAnnotator::setEnabled( bool on ) } } +void PageViewAnnotator::setTextToolsEnabled( bool enabled ) +{ + if ( m_textToolsEnabled == enabled ) + return; + + m_textToolsEnabled = enabled; + if ( m_toolBar ) + m_toolBar->setItems( filteredItems( m_items, m_textToolsEnabled ) ); +} + bool PageViewAnnotator::routeEvents() const { return m_engine && m_toolBar; diff --git a/ui/pageviewannotator.h b/ui/pageviewannotator.h index f9255dab2..e275af17b 100644 --- a/ui/pageviewannotator.h +++ b/ui/pageviewannotator.h @@ -54,6 +54,9 @@ class PageViewAnnotator : public QObject // called to show/hide the editing toolbar void setEnabled( bool enabled ); + // called to toggle the usage of text annotating tools + void setTextToolsEnabled( bool enabled ); + // methods used when creating the annotation bool routeEvents() const; QRect routeEvent( QMouseEvent * event, PageViewItem * item ); @@ -71,7 +74,8 @@ class PageViewAnnotator : public QObject PageViewToolBar * m_toolBar; AnnotatorEngine * m_engine; QDomElement m_toolsDefinition; - QLinkedList m_items; + QLinkedList m_items; + bool m_textToolsEnabled; // creation related variables int m_lastToolID; diff --git a/ui/pageviewutils.cpp b/ui/pageviewutils.cpp index f8b8ae345..2dbf00a5c 100644 --- a/ui/pageviewutils.cpp +++ b/ui/pageviewutils.cpp @@ -329,7 +329,7 @@ void PageViewTopMessage::setActionButton( QAction * action ) /** PageViewToolBar */ /*********************/ -ToolBarButton::ToolBarButton( QWidget * parent, const ToolBarItem & item ) +ToolBarButton::ToolBarButton( QWidget * parent, const AnnotationItem &item ) : QToolButton( parent ), m_id( item.id ) { setCheckable( true ); @@ -382,6 +382,7 @@ public: QPoint currentPosition; QPoint endPosition; bool hiding; + bool visible; // background pixmap and buttons QPixmap backgroundPixmap; @@ -398,6 +399,7 @@ PageViewToolBar::PageViewToolBar( QWidget * parent, QWidget * anchorWidget ) d->anchorWidget = anchorWidget; d->anchorSide = Left; d->hiding = false; + d->visible = false; // create the animation timer d->animTimer = new QTimer( this ); @@ -413,12 +415,8 @@ PageViewToolBar::~PageViewToolBar() delete d; } -void PageViewToolBar::showItems( Side side, const QLinkedList & items ) +void PageViewToolBar::setItems( const QLinkedList &items ) { - // set parameters for sliding in - d->anchorSide = side; - d->hiding = false; - // delete buttons if already present if ( !d->buttons.isEmpty() ) { @@ -429,7 +427,7 @@ void PageViewToolBar::showItems( Side side, const QLinkedList & ite } // create new buttons for given items - QLinkedList::const_iterator it = items.begin(), end = items.end(); + QLinkedList::const_iterator it = items.begin(), end = items.end(); for ( ; it != end; ++it ) { ToolBarButton * button = new ToolBarButton( this, *it ); @@ -438,10 +436,21 @@ void PageViewToolBar::showItems( Side side, const QLinkedList & ite } // rebuild toolbar shape and contents - d->buildToolBar(); - d->currentPosition = d->getOuterPoint(); - d->endPosition = d->getInnerPoint(); - move( d->currentPosition ); + d->reposition(); +} + +void PageViewToolBar::setSide( Side side ) +{ + d->anchorSide = side; + + d->reposition(); +} + +void PageViewToolBar::showAndAnimate() +{ + // set parameters for sliding in + d->hiding = false; + show(); // start scrolling in @@ -632,6 +641,7 @@ void ToolBarPrivate::buildToolBar() ToolBarButton * button = *it; button->move( gridX * toolBarGridSize + xOffset, gridY * toolBarGridSize + yOffset ); + button->show(); if ( ++gridX == myCols ) { gridX = 0; @@ -647,7 +657,16 @@ void ToolBarPrivate::reposition() // note: hiding widget here will gives better gfx, but ends drag operation // rebuild widget and move it to its final place buildToolBar(); - currentPosition = getInnerPoint(); + if ( !visible ) + { + currentPosition = getOuterPoint(); + endPosition = getInnerPoint(); + } + else + { + currentPosition = getInnerPoint(); + endPosition = getOuterPoint(); + } q->move( currentPosition ); // repaint all buttons (to update background) @@ -698,7 +717,14 @@ void PageViewToolBar::slotAnimate() { d->animTimer->stop(); if ( d->hiding ) + { + d->visible = false; deleteLater(); + } + else + { + d->visible = true; + } } } diff --git a/ui/pageviewutils.h b/ui/pageviewutils.h index b8f8771fc..7b153aa14 100644 --- a/ui/pageviewutils.h +++ b/ui/pageviewutils.h @@ -111,20 +111,18 @@ class PageViewTopMessage : public QWidget }; -/** - * @short A widget containing exclusive buttons, that slides in from a side. - * - * This is a shaped widget that slides in from a side of the 'anchor widget' - * it's attached to. It can be dragged and docked on {left,top,right,bottom} - * sides and contains toggable exclusive buttons. - * When a 'tool' of this 'toolBar' is selected, a signal is emitted. - */ -struct ToolBarItem // FIXME TEMP: MOVE OUT OF HERE! +struct AnnotationItem { + AnnotationItem() + : id( -1 ), isText( false ) + { + } + int id; QString text; QString pixmap; QString shortcut; + bool isText; }; class ToolBarButton : public QToolButton @@ -134,13 +132,21 @@ class ToolBarButton : public QToolButton static const int iconSize = 32; static const int buttonSize = 40; - ToolBarButton( QWidget * parent, const ToolBarItem & item ); + ToolBarButton( QWidget * parent, const AnnotationItem &item ); int buttonID() const { return m_id; } private: int m_id; }; +/** + * @short A widget containing exclusive buttons, that slides in from a side. + * + * This is a shaped widget that slides in from a side of the 'anchor widget' + * it's attached to. It can be dragged and docked on {left,top,right,bottom} + * sides and contains toggable exclusive buttons. + * When a 'tool' of this 'toolBar' is selected, a signal is emitted. + */ class PageViewToolBar : public QWidget { Q_OBJECT @@ -150,7 +156,11 @@ class PageViewToolBar : public QWidget // animated widget controls enum Side { Left = 0, Top = 1, Right = 2, Bottom = 3 }; - void showItems( Side side, const QLinkedList & items ); + + void setItems( const QLinkedList &items ); + void setSide( Side side ); + + void showAndAnimate(); void hideAndDestroy(); // query properties