• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kpushbutton.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
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 as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kpushbutton.h"
21
22#include <tqdragobject.h>
23#include <tqwhatsthis.h>
24#include <tqtooltip.h>
25
26#include "config.h"
27
28#include <tdeglobalsettings.h>
29#include <tdeconfig.h>
30#include <tdeglobal.h>
31#include <kipc.h>
32#include <tdeapplication.h>
33
34class KPushButton::KPushButtonPrivate
35{
36public:
37 KGuiItem item;
38 KStdGuiItem::StdItem itemType;
39};
40
41bool KPushButton::s_useIcons = false;
42
43KPushButton::KPushButton( TQWidget *parent, const char *name )
44 : TQPushButton( parent, name ),
45 m_dragEnabled( false )
46{
47 init( KGuiItem( "" ) );
48}
49
50KPushButton::KPushButton( const TQString &text, TQWidget *parent,
51 const char *name)
52 : TQPushButton( parent, name ),
53 m_dragEnabled( false )
54{
55 init( KGuiItem( text ) );
56}
57
58KPushButton::KPushButton( const TQIconSet &icon, const TQString &text,
59 TQWidget *parent, const char *name )
60 : TQPushButton( text, parent, name ),
61 m_dragEnabled( false )
62{
63 init( KGuiItem( text, icon ) );
64}
65
66KPushButton::KPushButton( const KGuiItem &item, TQWidget *parent,
67 const char *name )
68 : TQPushButton( parent, name ),
69 m_dragEnabled( false )
70{
71 init( item );
72}
73
74KPushButton::~KPushButton()
75{
76 if( d )
77 {
78 delete d;
79 d = 0L;
80 }
81}
82
83void KPushButton::init( const KGuiItem &item )
84{
85 d = new KPushButtonPrivate;
86 d->item = item;
87 d->itemType = (KStdGuiItem::StdItem) 0;
88
89 // call QPushButton's implementation since we don't need to
90 // set the GUI items text or check the state of the icon set
91 TQPushButton::setText( d->item.text() );
92
93 static bool initialized = false;
94 if ( !initialized ) {
95 readSettings();
96 initialized = true;
97 }
98
99 setIconSet( d->item.iconSet() );
100
101 setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) );
102
103 TQToolTip::add( this, item.toolTip() );
104
105 TQWhatsThis::add( this, item.whatsThis() );
106
107 if (tdeApp)
108 {
109 connect( tdeApp, TQ_SIGNAL( settingsChanged(int) ),
110 TQ_SLOT( slotSettingsChanged(int) ) );
111 tdeApp->addKipcEventMask( KIPC::SettingsChanged );
112 }
113}
114
115void KPushButton::readSettings()
116{
117 s_useIcons = TDEGlobalSettings::showIconsOnPushButtons();
118}
119
120void KPushButton::setGuiItem( const KGuiItem& item )
121{
122 d->item = item;
123
124 // call QPushButton's implementation since we don't need to
125 // set the GUI items text or check the state of the icon set
126 TQPushButton::setText( d->item.text() );
127 setIconSet( d->item.iconSet() );
128 TQWhatsThis::add( this, d->item.whatsThis() );
129
130 // Do not add a tooltip to the button automatically as 99% of the time the
131 // tooltip is redundant to the button text and it results in QTipManager
132 // invoking an eventHandler on the TQApplication which breaks certain apps
133 // like KDesktop which are sensitive to such things
134// TQToolTip::add( this, d->item.toolTip() );
135}
136
137void KPushButton::setGuiItem( KStdGuiItem::StdItem item )
138{
139 setGuiItem( KStdGuiItem::guiItem(item) );
140 d->itemType = item;
141}
142
143KStdGuiItem::StdItem KPushButton::guiItem() const
144{
145 return d->itemType;
146}
147
148void KPushButton::setText( const TQString &text )
149{
150 TQPushButton::setText(text);
151
152 // we need to re-evaluate the icon set when the text
153 // is removed, or when it is supplied
154 if (text.isEmpty() != d->item.text().isEmpty())
155 setIconSet(d->item.iconSet());
156
157 d->item.setText(text);
158}
159
160void KPushButton::setIconSet( const TQIconSet &iconSet )
161{
162 d->item.setIconSet(iconSet);
163
164 if ( s_useIcons || text().isEmpty() )
165 TQPushButton::setIconSet( iconSet );
166 else
167 TQPushButton::setIconSet( TQIconSet() );
168}
169
170void KPushButton::slotSettingsChanged( int /* category */ )
171{
172 readSettings();
173 setIconSet( d->item.iconSet() );
174}
175
176void KPushButton::setDragEnabled( bool enable )
177{
178 m_dragEnabled = enable;
179}
180
181void KPushButton::mousePressEvent( TQMouseEvent *e )
182{
183 if ( m_dragEnabled )
184 startPos = e->pos();
185 TQPushButton::mousePressEvent( e );
186}
187
188void KPushButton::mouseMoveEvent( TQMouseEvent *e )
189{
190 if ( !m_dragEnabled )
191 {
192 TQPushButton::mouseMoveEvent( e );
193 return;
194 }
195
196 if ( (e->state() & TQt::LeftButton) &&
197 (e->pos() - startPos).manhattanLength() >
198 TDEGlobalSettings::dndEventDelay() )
199 {
200 startDrag();
201 setDown( false );
202 }
203}
204
205TQDragObject * KPushButton::dragObject()
206{
207 return 0L;
208}
209
210void KPushButton::startDrag()
211{
212 TQDragObject *d = dragObject();
213 if ( d )
214 d->dragCopy();
215}
216
217void KPushButton::virtual_hook( int, void* )
218{ /*BASE::virtual_hook( id, data );*/ }
219
220#include "kpushbutton.moc"
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:39
KPushButton::setText
void setText(const TQString &text)
Sets the text of the button.
Definition: kpushbutton.cpp:148
KPushButton::guiItem
KStdGuiItem::StdItem guiItem() const
Reads the standard KGuiItem for this button.
Definition: kpushbutton.cpp:143
KPushButton::~KPushButton
~KPushButton()
Destructs the button.
Definition: kpushbutton.cpp:74
KPushButton::KPushButton
KPushButton(TQWidget *parent, const char *name=0)
Default constructor.
Definition: kpushbutton.cpp:43
KPushButton::mousePressEvent
virtual void mousePressEvent(TQMouseEvent *)
Reimplemented to add drag-support.
Definition: kpushbutton.cpp:181
KPushButton::mouseMoveEvent
virtual void mouseMoveEvent(TQMouseEvent *)
Reimplemented to add drag-support.
Definition: kpushbutton.cpp:188
KPushButton::dragObject
virtual TQDragObject * dragObject()
Reimplement this and return the TQDragObject that should be used for the drag.
Definition: kpushbutton.cpp:205
KPushButton::setGuiItem
void setGuiItem(const KGuiItem &item)
Sets the KGuiItem for this button.
Definition: kpushbutton.cpp:120
KPushButton::setDragEnabled
void setDragEnabled(bool enable)
Enables/disables drag-support.
Definition: kpushbutton.cpp:176
KPushButton::startDrag
virtual void startDrag()
Starts a drag (dragCopy() by default) using dragObject()
Definition: kpushbutton.cpp:210
KPushButton::setIconSet
void setIconSet(const TQIconSet &iconSet)
Sets the Icon Set for this button.
Definition: kpushbutton.cpp:160
KStdGuiItem::StdItem
StdItem
Definition: kstdguiitem.h:48
TDEGlobalSettings::showIconsOnPushButtons
static bool showIconsOnPushButtons()
TDEGlobalSettings::dndEventDelay
static int dndEventDelay()

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.