• 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
ktoolbarlabelaction.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2004 Felix Berger <felixberger@beldesign.de>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "ktoolbarlabelaction.h"
20 #include "ktoolbar.h"
21 
22 #include <QtCore/QPointer>
23 #include <QtGui/QApplication>
24 #include <QtGui/QLabel>
25 
26 class KToolBarLabelAction::Private
27 {
28  public:
29  QPointer<QAction> buddy;
30  QPointer<QLabel> label;
31 };
32 
33 KToolBarLabelAction::KToolBarLabelAction(const QString &text, QObject *parent)
34  : KAction(text, parent),
35  d( new Private )
36 {
37  d->label = 0;
38 }
39 
40 KToolBarLabelAction::KToolBarLabelAction(QAction* buddy, const QString &text, QObject *parent)
41  : KAction(text, parent),
42  d( new Private )
43 {
44  setBuddy( buddy );
45 
46  d->label = 0;
47 }
48 
49 KToolBarLabelAction::~KToolBarLabelAction()
50 {
51  delete d;
52 }
53 
54 void KToolBarLabelAction::setBuddy( QAction* buddy )
55 {
56  d->buddy = buddy;
57 
58  QList<QLabel*> labels;
59  foreach ( QWidget* widget, associatedWidgets() )
60  if ( QToolBar* toolBar = qobject_cast<QToolBar*>( widget ) )
61  if ( QLabel* label = qobject_cast<QLabel*>( toolBar->widgetForAction( this ) ) )
62  labels.append( label );
63 
64  foreach ( QWidget* widget, buddy->associatedWidgets() )
65  if ( QToolBar* toolBar = qobject_cast<QToolBar*>( widget ) ) {
66  QWidget* newBuddy = toolBar->widgetForAction( buddy );
67  foreach ( QLabel* label, labels )
68  label->setBuddy( newBuddy );
69  return;
70  }
71 }
72 
73 QAction* KToolBarLabelAction::buddy() const
74 {
75  return d->buddy;
76 }
77 
78 bool KToolBarLabelAction::event( QEvent *event )
79 {
80  if ( event->type() == QEvent::ActionChanged ) {
81  if ( d->label && text() != d->label->text() ) {
82  emit textChanged( text() );
83  d->label->setText(text());
84  }
85  }
86 
87  return KAction::event( event );
88 }
89 
90 bool KToolBarLabelAction::eventFilter( QObject *watched, QEvent *event )
91 {
92  if ( d->label && d->buddy && event->type() == QEvent::PolishRequest && watched == d->label) {
93  foreach ( QWidget* widget, d->buddy->associatedWidgets() ) {
94  if ( QToolBar* toolBar = qobject_cast<QToolBar*>( widget ) ) {
95  QWidget* newBuddy = toolBar->widgetForAction( d->buddy );
96  d->label->setBuddy( newBuddy );
97  }
98  }
99  }
100 
101  return KAction::eventFilter( watched, event );
102 }
103 
104 QWidget *KToolBarLabelAction::createWidget( QWidget* _parent )
105 {
106  QToolBar *parent = qobject_cast<QToolBar *>(_parent);
107  if (!parent)
108  return KAction::createWidget(_parent);
109  if (!d->label) {
110  d->label = new QLabel( parent );
111 
116  d->label->setBackgroundRole( QPalette::Button );
117  d->label->setAlignment( (QApplication::isRightToLeft() ? Qt::AlignRight : Qt::AlignLeft) |
118  Qt::AlignVCenter );
119  d->label->adjustSize();
120  d->label->setText(text());
121  d->label->installEventFilter( this );
122  }
123 
124  return d->label;
125 }
126 
127 #include "ktoolbarlabelaction.moc"
QAction::text
QString text() const
KAction::event
bool event(QEvent *)
Definition: kaction.cpp:115
KToolBarLabelAction::setBuddy
void setBuddy(QAction *buddy)
Sets the label's buddy to buddy.
Definition: ktoolbarlabelaction.cpp:54
QEvent
QWidget
QApplication::isRightToLeft
bool isRightToLeft()
ktoolbarlabelaction.h
QEvent::type
Type type() const
KToolBarLabelAction::~KToolBarLabelAction
virtual ~KToolBarLabelAction()
Destroys the toolbar label.
Definition: ktoolbarlabelaction.cpp:49
KStandardShortcut::label
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
Definition: kstandardshortcut.cpp:267
QPointer< QAction >
KToolBarLabelAction::buddy
QAction * buddy() const
Returns the label's buddy or 0 if no buddy is currently set.
Definition: ktoolbarlabelaction.cpp:73
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QList::append
void append(const T &value)
KToolBarLabelAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: ktoolbarlabelaction.cpp:104
QObject
KToolBarLabelAction::KToolBarLabelAction
KToolBarLabelAction(const QString &text, QObject *parent)
Creates a toolbar label.
Definition: ktoolbarlabelaction.cpp:33
QString
QList
KToolBarLabelAction::textChanged
void textChanged(const QString &newText)
This signal is emmitted whenever the text of this action is changed.
ktoolbar.h
KToolBarLabelAction::event
virtual bool event(QEvent *)
Definition: ktoolbarlabelaction.cpp:78
QWidgetAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
QAction
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
QToolBar
QAction::associatedWidgets
QList< QWidget * > associatedWidgets() const
QLabel
QObject::parent
QObject * parent() const
KToolBarLabelAction::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: ktoolbarlabelaction.cpp:90
QWidgetAction::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event)
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