Changeset View
Standalone View
ui/toolaction.cpp
- This file was deleted.
1 | /*************************************************************************** | | |||
---|---|---|---|---|---|
2 | * Copyright (C) 2004-2006 by Albert Astals Cid <aacid@kde.org> * | | |||
3 | * * | | |||
4 | * This program is free software; you can redistribute it and/or modify * | | |||
5 | * it under the terms of the GNU General Public License as published by * | | |||
6 | * the Free Software Foundation; either version 2 of the License, or * | | |||
7 | * (at your option) any later version. * | | |||
8 | ***************************************************************************/ | | |||
9 | | ||||
10 | #include "toolaction.h" | | |||
11 | | ||||
12 | #include <qmenu.h> | | |||
13 | #include <qtoolbar.h> | | |||
14 | #include <qtoolbutton.h> | | |||
15 | | ||||
16 | #include <KLocalizedString> | | |||
17 | | ||||
18 | ToolAction::ToolAction( QObject *parent ) | | |||
19 | : KSelectAction( parent ) | | |||
20 | { | | |||
21 | setText( i18n( "Selection Tools" ) ); | | |||
22 | } | | |||
23 | | ||||
24 | ToolAction::~ToolAction() | | |||
25 | { | | |||
26 | } | | |||
27 | | ||||
28 | void ToolAction::addAction( QAction *action ) | | |||
29 | { | | |||
30 | bool setDefault = !m_buttons.isEmpty() ? m_buttons.first()->menu()->actions().isEmpty() : false; | | |||
31 | foreach ( QToolButton *button, m_buttons ) | | |||
32 | if ( button ) | | |||
33 | { | | |||
34 | button->menu()->addAction( action ); | | |||
35 | if ( setDefault ) | | |||
36 | button->setDefaultAction( action ); | | |||
37 | } | | |||
38 | m_actions.append( action ); | | |||
39 | } | | |||
40 | | ||||
41 | QWidget* ToolAction::createWidget( QWidget *parent ) | | |||
42 | { | | |||
43 | QToolBar *toolBar = qobject_cast< QToolBar * >( parent ); | | |||
44 | if ( !toolBar ) | | |||
45 | return nullptr; | | |||
46 | | ||||
47 | QToolButton *button = new QToolButton( toolBar ); | | |||
48 | button->setAutoRaise( true ); | | |||
49 | button->setFocusPolicy( Qt::NoFocus ); | | |||
50 | button->setIconSize( toolBar->iconSize() ); | | |||
51 | button->setToolButtonStyle( toolBar->toolButtonStyle() ); | | |||
52 | button->setPopupMode( QToolButton::MenuButtonPopup ); | | |||
53 | button->setMenu( new QMenu( button ) ); | | |||
54 | button->setCheckable( true ); | | |||
55 | connect(toolBar, &QToolBar::iconSizeChanged, button, &QToolButton::setIconSize); | | |||
56 | connect(toolBar, &QToolBar::toolButtonStyleChanged, button, &QToolButton::setToolButtonStyle); | | |||
57 | connect(button, &QToolButton::triggered, toolBar, &QToolBar::actionTriggered); | | |||
58 | connect( button->menu(), &QMenu::triggered, this, &ToolAction::slotNewDefaultAction ); | | |||
59 | | ||||
60 | m_buttons.append( button ); | | |||
61 | | ||||
62 | if ( !m_actions.isEmpty() ) | | |||
63 | { | | |||
64 | button->setDefaultAction( m_actions.first() ); | | |||
65 | foreach ( QAction *action, m_actions ) | | |||
66 | { | | |||
67 | button->menu()->addAction( action ); | | |||
68 | if ( action->isChecked() ) | | |||
69 | button->setDefaultAction( action ); | | |||
70 | } | | |||
71 | button->setToolTip( i18n("Click to use the current selection tool\nClick on the arrow to choose another selection tool") ); | | |||
davidhurka: Why remove this tooltip?
To make ToolAction (or my inferior ToggleActionMenu) more universal… | |||||
That tooltip does not appear anywhere in the UI in practice, at least I have not manage to make it appear. Have you? Now I am using ToolAction to show other things, so the tooltips, if needed, need to be set outside. Still a TODO. Where is ToggleActionMenu defined? simgunz: That tooltip does not appear anywhere in the UI in practice, at least I have not manage to make… | |||||
The tooltip should become visible when you hover the toolbar button with the three selection tools. It’s in the main toolbar by default. See also D21622. On my Okular it worked, on yours not? ToggleActionMenu is still a TODO in D21755. ;) What will you use ToolAction for? In that case I probably shouldn’t break it. davidhurka: The tooltip should become visible when you hover the toolbar button with the three selection… | |||||
Currently the tooltip appears only if any of the selection tools is already selected, while it does not appear if another action like "Browse" is selected. Moreover it made sense when one had to click and hold to show the menu, which was quite unintuitive, now that it is enough to click on the arrow, I believe it is redundant. simgunz: Currently the tooltip appears only if any of the selection tools is already selected, while it… | |||||
72 | } | | |||
73 | | ||||
74 | return button; | | |||
75 | } | | |||
76 | | ||||
77 | void ToolAction::slotNewDefaultAction( QAction *action ) | | |||
78 | { | | |||
79 | foreach ( QToolButton *button, m_buttons ) | | |||
80 | if ( button ) | | |||
81 | { | | |||
82 | button->setDefaultAction( action ); | | |||
83 | button->setToolTip( i18n("Click to use the current selection tool\nClick on the arrow to choose another selection tool") ); | | |||
84 | } | | |||
85 | } | | |||
86 | | ||||
87 | #include "moc_toolaction.cpp" | |
Why remove this tooltip?
To make ToolAction (or my inferior ToggleActionMenu) more universal to use it for a Change Colors feature, it would be nice if tooltips are not needed anymore.