• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • actions
ktoolbarpopupaction.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3 (C) 1999 Simon Hausmann <hausmann@kde.org>
4 (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5 (C) 2000 Kurt Granroth <granroth@kde.org>
6 (C) 2000 Michael Koch <koch@kde.org>
7 (C) 2001 Holger Freyther <freyther@kde.org>
8 (C) 2002 Ellis Whitehead <ellis@kde.org>
9 (C) 2002 Joseph Wenninger <jowenn@kde.org>
10 (C) 2003 Andras Mantia <amantia@kde.org>
11 (C) 2005-2006 Hamish Rodda <rodda@kde.org>
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Library General Public
15 License version 2 as published by the Free Software Foundation.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
21
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.
26*/
27
28#include "ktoolbarpopupaction.h"
29#include "kmenu.h"
30
31#include <QtGui/QToolBar>
32#include <QtGui/QToolButton>
33
34#include <kdebug.h>
35#include <klocale.h>
36#include <kicon.h>
37
38class KToolBarPopupAction::Private
39{
40 public:
41 Private()
42 : delayed( true ), stickyMenu( true )
43 {
44 }
45
46 bool delayed:1;
47 bool stickyMenu:1;
48};
49
50KToolBarPopupAction::KToolBarPopupAction(const KIcon& icon, const QString& text, QObject *parent)
51 : KAction(icon, text, parent),
52 d( new Private )
53{
54 setMenu( new KMenu );
55}
56
57KToolBarPopupAction::~KToolBarPopupAction()
58{
59 delete d;
60 delete menu();
61}
62
63#ifndef KDE_NO_DEPRECATED
64KMenu* KToolBarPopupAction::popupMenu() const
65{
66 return qobject_cast<KMenu*>( menu() );
67}
68#endif
69
70QWidget * KToolBarPopupAction::createWidget( QWidget * _parent )
71{
72 QToolBar *parent = qobject_cast<QToolBar *>(_parent);
73 if (!parent)
74 return KAction::createWidget(_parent);
75 QToolButton* button = new QToolButton( parent );
76 button->setAutoRaise( true );
77 button->setFocusPolicy( Qt::NoFocus );
78 button->setIconSize( parent->iconSize() );
79 button->setToolButtonStyle( parent->toolButtonStyle() );
80 button->setDefaultAction( this );
81
82 connect( parent, SIGNAL(iconSizeChanged(QSize)),
83 button, SLOT(setIconSize(QSize)) );
84 connect( parent, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
85 button, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)) );
86 connect( button, SIGNAL(triggered(QAction*)),
87 parent, SIGNAL(actionTriggered(QAction*)) );
88
89 if ( d->delayed )
90 if ( d->stickyMenu )
91 button->setPopupMode( QToolButton::MenuButtonPopup );
92 else
93 button->setPopupMode( QToolButton::DelayedPopup );
94 else
95 button->setPopupMode( QToolButton::InstantPopup );
96
97 return button;
98}
99
100bool KToolBarPopupAction::delayed() const
101{
102 return d->delayed;
103}
104
105void KToolBarPopupAction::setDelayed( bool delayed )
106{
107 d->delayed = delayed;
108}
109
110bool KToolBarPopupAction::stickyMenu() const
111{
112 return d->stickyMenu;
113}
114
115void KToolBarPopupAction::setStickyMenu( bool sticky )
116{
117 d->stickyMenu = sticky;
118}
119
120#include "ktoolbarpopupaction.moc"
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KAction::triggered
void triggered(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
Emitted when the action is triggered.
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
KToolBarPopupAction::delayed
bool delayed
Definition: ktoolbarpopupaction.h:51
KToolBarPopupAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: ktoolbarpopupaction.cpp:70
KToolBarPopupAction::setStickyMenu
void setStickyMenu(bool sticky)
If set to true, this action will create a sticky popup menu when plugged in a KToolBar.
Definition: ktoolbarpopupaction.cpp:115
KToolBarPopupAction::KToolBarPopupAction
KToolBarPopupAction(const KIcon &icon, const QString &text, QObject *parent)
Create a KToolBarPopupAction, with a text, an icon, a parent and a name.
Definition: ktoolbarpopupaction.cpp:50
KToolBarPopupAction::setDelayed
void setDelayed(bool delayed)
If set to true, this action will create a delayed popup menu when plugged in a KToolBar.
Definition: ktoolbarpopupaction.cpp:105
KToolBarPopupAction::popupMenu
KMenu * popupMenu() const
The popup menu that is shown when clicking (some time) on the toolbar button.
Definition: ktoolbarpopupaction.cpp:64
KToolBarPopupAction::stickyMenu
bool stickyMenu
Definition: ktoolbarpopupaction.h:52
KToolBarPopupAction::~KToolBarPopupAction
virtual ~KToolBarPopupAction()
Destroys the toolbar popup action.
Definition: ktoolbarpopupaction.cpp:57
QAction
QObject
QToolBar
QToolButton
QWidget
kdebug.h
kicon.h
klocale.h
kmenu.h
ktoolbarpopupaction.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal