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

KDEUI

  • 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
26class KToolBarLabelAction::Private
27{
28 public:
29 QPointer<QAction> buddy;
30 QPointer<QLabel> label;
31};
32
33KToolBarLabelAction::KToolBarLabelAction(const QString &text, QObject *parent)
34 : KAction(text, parent),
35 d( new Private )
36{
37 d->label = 0;
38}
39
40KToolBarLabelAction::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
49KToolBarLabelAction::~KToolBarLabelAction()
50{
51 delete d;
52}
53
54void 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
73QAction* KToolBarLabelAction::buddy() const
74{
75 return d->buddy;
76}
77
78bool 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
90bool 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
104QWidget *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"
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KAction::event
bool event(QEvent *)
Definition: kaction.cpp:115
KToolBarLabelAction::~KToolBarLabelAction
virtual ~KToolBarLabelAction()
Destroys the toolbar label.
Definition: ktoolbarlabelaction.cpp:49
KToolBarLabelAction::event
virtual bool event(QEvent *)
Definition: ktoolbarlabelaction.cpp:78
KToolBarLabelAction::setBuddy
void setBuddy(QAction *buddy)
Sets the label's buddy to buddy.
Definition: ktoolbarlabelaction.cpp:54
KToolBarLabelAction::textChanged
void textChanged(const QString &newText)
This signal is emmitted whenever the text of this action is changed.
KToolBarLabelAction::KToolBarLabelAction
KToolBarLabelAction(const QString &text, QObject *parent)
Creates a toolbar label.
Definition: ktoolbarlabelaction.cpp:33
KToolBarLabelAction::buddy
QAction * buddy() const
Returns the label's buddy or 0 if no buddy is currently set.
Definition: ktoolbarlabelaction.cpp:73
KToolBarLabelAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
Reimplemented from.
Definition: ktoolbarlabelaction.cpp:104
KToolBarLabelAction::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: ktoolbarlabelaction.cpp:90
QAction
QLabel
QList
QObject
QToolBar
QWidget
ktoolbar.h
ktoolbarlabelaction.h
KStandardShortcut::label
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
Definition: kstandardshortcut.cpp:267
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