File: toolaction.cpp

package info (click to toggle)
okular 4%3A4.8.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,040 kB
  • sloc: cpp: 62,030; ansic: 3,964; xml: 66; sh: 22; makefile: 7
file content (87 lines) | stat: -rw-r--r-- 3,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
 *   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(QSize)),
             button, SLOT(setIconSize(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() );
        button->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
    }

    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"