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
This commit is contained in:
Pino Toscano 2007-12-08 15:59:04 +00:00
parent be088ab698
commit 995972052d
5 changed files with 38 additions and 27 deletions

View file

@ -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() );

View file

@ -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<AnnotationToolItem> filteredItems( const QLinkedList<AnnotationToolItem> &items, bool textTools )
{
if ( textTools )
{
return items;
}
else
{
QLinkedList<AnnotationToolItem> newitems;
QLinkedList<AnnotationToolItem>::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

View file

@ -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<AnnotationToolItem> m_items;
bool m_textToolsEnabled;
bool m_toolsEnabled;
// creation related variables
int m_lastToolID;

View file

@ -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"

View file

@ -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: