Commit 7eb8659d authored by Pino Toscano's avatar Pino Toscano

Add a tool button in the toolbar with the "select" actions.

Preparing a bit for separating rectangular text selection and rectangular image selection.

svn path=/trunk/KDE/kdegraphics/okular/; revision=712381
parent cb693241
......@@ -136,6 +136,7 @@ set(okularpart_SRCS
ui/thumbnaillist.cpp
ui/toc.cpp
ui/tocmodel.cpp
ui/toolaction.cpp
)
kde4_add_ui_files(okularpart_SRCS
......
......@@ -87,7 +87,6 @@
<Separator/>
<Action name="mouse_drag"/>
<Action name="mouse_zoom"/>
<Action name="mouse_select"/>
<Action name="mouse_textselect"/>
<Action name="mouse_selecttools"/>
</ToolBar>
</kpartgui>
......@@ -63,6 +63,7 @@
#include "annotationguiutils.h"
#include "annotationpopup.h"
#include "pageviewannotator.h"
#include "toolaction.h"
#include "core/action.h"
#include "core/document.h"
#include "core/form.h"
......@@ -447,6 +448,11 @@ void PageView::setupActions( KActionCollection * ac )
connect( d->aToggleAnnotator, SIGNAL( toggled( bool ) ), SLOT( slotToggleAnnotator( bool ) ) );
d->aToggleAnnotator->setShortcut( Qt::Key_F6 );
ToolAction *ta = new ToolAction( this );
ac->addAction( "mouse_selecttools", ta );
ta->addAction( d->aMouseSelect );
ta->addAction( d->aMouseTextSelect );
// Other actions
KAction * su = new KAction(i18n("Scroll Up"), this);
ac->addAction("view_scroll_up", su );
......@@ -1324,6 +1330,7 @@ void PageView::contentsMouseMoveEvent( QMouseEvent * e )
case MouseZoom:
case MouseSelect:
case MouseImageSelect:
// set second corner of selection
if ( d->mouseSelecting )
selectionEndPoint( e->pos() );
......@@ -1469,6 +1476,7 @@ void PageView::contentsMousePressEvent( QMouseEvent * e )
break;
case MouseSelect: // set first corner of the selection rect
case MouseImageSelect:
if ( leftButton )
{
selectionStart( e->pos(), palette().color( QPalette::Active, QPalette::Highlight ).light( 120 ), false );
......@@ -1674,7 +1682,9 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
}
break;
case MouseSelect:{
case MouseSelect:
case MouseImageSelect:
{
// if mouse is released and selection is null this is a rightClick
if ( rightButton && !d->mouseSelecting )
{
......
......@@ -56,7 +56,7 @@ Q_OBJECT
// Zoom mode ( last 4 are internally used only! )
enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitText,
ZoomIn, ZoomOut, ZoomRefreshCurrent };
enum MouseMode { MouseNormal, MouseZoom, MouseSelect, MouseTextSelect };
enum MouseMode { MouseNormal, MouseZoom, MouseSelect, MouseImageSelect, MouseTextSelect };
// create actions that interact with this widget
void setupBaseActions( KActionCollection * collection );
......
/***************************************************************************
* Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "toolaction.h"
#include <qmenu.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <klocale.h>
ToolAction::ToolAction( QObject *parent )
: KAction( parent )
{
setText( i18n( "Selection Tools" ) );
}
ToolAction::~ToolAction()
{
}
void ToolAction::addAction( QAction *action )
{
bool setDefault = !m_buttons.isEmpty() ? m_buttons.first()->menu()->actions().isEmpty() : false;
foreach ( QToolButton *button, m_buttons )
if ( button )
{
button->menu()->addAction( action );
if ( setDefault )
button->setDefaultAction( action );
}
m_actions.append( action );
}
QWidget* ToolAction::createWidget( QWidget *parent )
{
QToolBar *toolBar = qobject_cast< QToolBar * >( parent );
if ( !toolBar )
return 0;
QToolButton *button = new QToolButton( toolBar );
button->setAutoRaise( true );
button->setFocusPolicy( Qt::NoFocus );
button->setIconSize( toolBar->iconSize() );
button->setToolButtonStyle( toolBar->toolButtonStyle() );
button->setPopupMode( QToolButton::DelayedPopup );
button->setMenu( new QMenu( button ) );
button->setCheckable( true );
connect( toolBar, SIGNAL( iconSizeChanged( const QSize & ) ),
button, SLOT( setIconSize( const QSize & ) ) );
connect( toolBar, SIGNAL( toolButtonStyleChanged( Qt::ToolButtonStyle ) ),
button, SLOT( setToolButtonStyle( Qt::ToolButtonStyle ) ) );
connect( button, SIGNAL( triggered( QAction * ) ), toolBar, SIGNAL( actionTriggered( QAction * ) ) );
connect( button->menu(), SIGNAL( triggered( QAction * ) ), this, SLOT( slotNewDefaultAction( QAction * ) ) );
m_buttons.append( button );
if ( !m_actions.isEmpty() )
{
foreach ( QAction *action, m_actions )
{
button->menu()->addAction( action );
}
button->setDefaultAction( button->menu()->actions().first() );
}
return button;
}
void ToolAction::slotNewDefaultAction( QAction *action )
{
foreach ( QToolButton *button, m_buttons )
if ( button )
{
button->setDefaultAction( action );
button->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
}
}
#include "toolaction.moc"
/***************************************************************************
* Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef TOOLACTION_H
#define TOOLACTION_H
#include <qlist.h>
#include <qpointer.h>
#include <kaction.h>
class QToolButton;
class ToolAction : public KAction
{
Q_OBJECT
public:
ToolAction( QObject *parent = 0 );
virtual ~ToolAction();
void addAction( QAction *action );
protected:
virtual QWidget* createWidget( QWidget *parent );
private slots:
void slotNewDefaultAction( QAction *action );
private:
QList< QPointer< QToolButton > > m_buttons;
QList< QAction * > m_actions;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment