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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
38 class 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 
50 KToolBarPopupAction::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 
57 KToolBarPopupAction::~KToolBarPopupAction()
58 {
59  delete d;
60  delete menu();
61 }
62 
63 #ifndef KDE_NO_DEPRECATED
64 KMenu* KToolBarPopupAction::popupMenu() const
65 {
66  return qobject_cast<KMenu*>( menu() );
67 }
68 #endif
69 
70 QWidget * 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 
100 bool KToolBarPopupAction::delayed() const
101 {
102  return d->delayed;
103 }
104 
105 void KToolBarPopupAction::setDelayed( bool delayed )
106 {
107  d->delayed = delayed;
108 }
109 
110 bool KToolBarPopupAction::stickyMenu() const
111 {
112  return d->stickyMenu;
113 }
114 
115 void KToolBarPopupAction::setStickyMenu( bool sticky )
116 {
117  d->stickyMenu = sticky;
118 }
119 
120 #include "ktoolbarpopupaction.moc"
KToolBarPopupAction::~KToolBarPopupAction
virtual ~KToolBarPopupAction()
Destroys the toolbar popup action.
Definition: ktoolbarpopupaction.cpp:57
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
QWidget
kdebug.h
QToolButton::setDefaultAction
void setDefaultAction(QAction *action)
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
KMenu
A menu with keyboard searching.
Definition: kmenu.h:42
QAction::setMenu
void setMenu(QMenu *menu)
klocale.h
KToolBarPopupAction::delayed
bool delayed() const
Returns true if this action creates a delayed popup menu when plugged in a KToolBar.
QToolBar::toolButtonStyle
toolButtonStyle
KToolBarPopupAction::popupMenu
KMenu * popupMenu() const
The popup menu that is shown when clicking (some time) on the toolbar button.
Definition: ktoolbarpopupaction.cpp:64
kmenu.h
QObject
QAbstractButton::setIconSize
void setIconSize(const QSize &size)
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
QString
QToolButton::setAutoRaise
void setAutoRaise(bool enable)
QToolButton
QSize
KAction::triggered
void triggered(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
Emitted when the action is triggered.
QWidgetAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
QToolButton::setPopupMode
void setPopupMode(ToolButtonPopupMode mode)
QToolBar
KToolBarPopupAction::stickyMenu
bool stickyMenu() const
Returns true if this action creates a sticky popup menu.
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
QToolBar::iconSize
iconSize
ktoolbarpopupaction.h
KToolBarPopupAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: ktoolbarpopupaction.cpp:70
kicon.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QAction::menu
QMenu * menu() const
QObject::parent
QObject * parent() const
QToolButton::setToolButtonStyle
void setToolButtonStyle(Qt::ToolButtonStyle style)
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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