From 995972052d8db59d6e8a1c8c55fc6ea6c74ff721 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 8 Dec 2007 15:59:04 +0000 Subject: [PATCH] Review toolbar: - enable/disable (instead of hide/show) the tools that cannot be constructed (eg due to the document not extracting text) - disable the tools when there is no document open svn path=/trunk/KDE/kdegraphics/okular/; revision=746293 --- ui/pageview.cpp | 1 + ui/pageviewannotator.cpp | 39 +++++++++++++-------------------------- ui/pageviewannotator.h | 3 +++ ui/pageviewutils.cpp | 17 ++++++++++++++++- ui/pageviewutils.h | 5 +++++ 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index a6e4030dd..4922443f7 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -769,6 +769,7 @@ void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, int setup bool allowAnnotations = d->document->isAllowed( Okular::AllowNotes ); if ( d->annotator ) { + d->annotator->setToolsEnabled( haspages ); if ( allowAnnotations ) { d->annotator->setTextToolsEnabled( d->document->supportsSearching() ); diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 7c2087d57..35a62ff98 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -578,8 +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_textToolsEnabled( true ), m_lastToolID( -1 ), - m_lockedItem( 0 ) + m_toolBar( 0 ), m_engine( 0 ), m_textToolsEnabled( false ), m_toolsEnabled( false ), + 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") ); @@ -629,25 +629,6 @@ 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 ) @@ -670,7 +651,9 @@ void PageViewAnnotator::setEnabled( bool on ) { 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 ) ); + m_toolBar->setItems( m_items ); + m_toolBar->setToolsEnabled( m_toolsEnabled ); + m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); connect( m_toolBar, SIGNAL( toolSelected(int) ), this, SLOT( slotToolSelected(int) ) ); connect( m_toolBar, SIGNAL( orientationChanged(int) ), @@ -703,12 +686,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 ) ); + m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); +} + +void PageViewAnnotator::setToolsEnabled( bool enabled ) +{ + m_toolsEnabled = enabled; + if ( m_toolBar ) + m_toolBar->setToolsEnabled( m_toolsEnabled ); } bool PageViewAnnotator::routeEvents() const diff --git a/ui/pageviewannotator.h b/ui/pageviewannotator.h index ba1a1a885..b9bc1f8c6 100644 --- a/ui/pageviewannotator.h +++ b/ui/pageviewannotator.h @@ -58,6 +58,8 @@ class PageViewAnnotator : public QObject // called to toggle the usage of text annotating tools void setTextToolsEnabled( bool enabled ); + void setToolsEnabled( bool enabled ); + // methods used when creating the annotation bool routeEvents() const; QRect routeEvent( QMouseEvent * event, PageViewItem * item ); @@ -78,6 +80,7 @@ class PageViewAnnotator : public QObject QDomElement m_toolsDefinition; QLinkedList m_items; bool m_textToolsEnabled; + bool m_toolsEnabled; // creation related variables int m_lastToolID; diff --git a/ui/pageviewutils.cpp b/ui/pageviewutils.cpp index f031899d9..521a6d3f7 100644 --- a/ui/pageviewutils.cpp +++ b/ui/pageviewutils.cpp @@ -332,7 +332,7 @@ void PageViewTopMessage::setActionButton( QAction * action ) /*********************/ ToolBarButton::ToolBarButton( QWidget * parent, const AnnotationToolItem &item ) - : QToolButton( parent ), m_id( item.id ) + : QToolButton( parent ), m_id( item.id ), m_isText( item.isText ) { setCheckable( true ); setAutoRaise( true ); @@ -797,4 +797,19 @@ void ToolBarPrivate::selectButton( ToolBarButton * button ) } } +void PageViewToolBar::setToolsEnabled( bool on ) +{ + QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); + for ( ; it != end; ++it ) + (*it)->setEnabled( on ); +} + +void PageViewToolBar::setTextToolsEnabled( bool on ) +{ + QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); + for ( ; it != end; ++it ) + if ( (*it)->isText() ) + (*it)->setEnabled( on ); +} + #include "pageviewutils.moc" diff --git a/ui/pageviewutils.h b/ui/pageviewutils.h index dd828d098..01991ed03 100644 --- a/ui/pageviewutils.h +++ b/ui/pageviewutils.h @@ -134,9 +134,11 @@ class ToolBarButton : public QToolButton ToolBarButton( QWidget * parent, const AnnotationToolItem &item ); int buttonID() const { return m_id; } + bool isText() const { return m_isText; } private: int m_id; + bool m_isText; }; /** @@ -165,6 +167,9 @@ class PageViewToolBar : public QWidget void selectButton( int id ); + void setToolsEnabled( bool on ); + void setTextToolsEnabled( bool on ); + // query properties signals: