Refactor a bit the annotating toolbar, so it can handle better its items and cha

nges to its status. This brings us:
- less item reloading (previously done every time the toolbar is shown, now only when needed)
- the toolbar is redrawn correctly if it's shown and a new document is open
- as Albert pointed me yesterday, no need to show the annotating tools that act on text if the document does not support the extraction of text

svn path=/trunk/KDE/kdegraphics/okular/; revision=659722
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 2654c1b16b
commit 2c1d5aa44e
  1. 5
      ui/pageview.cpp
  2. 47
      ui/pageviewannotator.cpp
  3. 6
      ui/pageviewannotator.h
  4. 50
      ui/pageviewutils.cpp
  5. 32
      ui/pageviewutils.h

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

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

@ -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<ToolBarItem> m_items;
QLinkedList<AnnotationItem> m_items;
bool m_textToolsEnabled;
// creation related variables
int m_lastToolID;

@ -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<ToolBarItem> & items )
void PageViewToolBar::setItems( const QLinkedList<AnnotationItem> &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<ToolBarItem> & ite
}
// create new buttons for given items
QLinkedList<ToolBarItem>::const_iterator it = items.begin(), end = items.end();
QLinkedList<AnnotationItem>::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<ToolBarItem> & 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;
}
}
}

@ -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<ToolBarItem> & items );
void setItems( const QLinkedList<AnnotationItem> &items );
void setSide( Side side );
void showAndAnimate();
void hideAndDestroy();
// query properties

Loading…
Cancel
Save