KParts
event.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> 00003 (C) 1999 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 #include <kparts/event.h> 00021 00022 using namespace KParts; 00023 00024 //the answer! 00025 #define KPARTS_EVENT_MAGIC 42 00026 00027 class KParts::EventPrivate 00028 { 00029 public: 00030 EventPrivate( const char *eventName ) : 00031 m_eventName(eventName) 00032 { 00033 } 00034 const char* m_eventName; 00035 }; 00036 00037 Event::Event( const char *eventName ) 00038 : QEvent( (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC) ) 00039 , d( new EventPrivate(eventName) ) 00040 { 00041 } 00042 00043 Event::~Event() 00044 { 00045 delete d; 00046 } 00047 00048 const char *Event::eventName() const 00049 { 00050 return d->m_eventName; 00051 } 00052 00053 bool Event::test( const QEvent *event ) 00054 { 00055 if ( !event ) 00056 return false; 00057 00058 return ( event->type() == (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC ) ); 00059 } 00060 00061 bool Event::test( const QEvent *event, const char *name ) 00062 { 00063 if ( !test( event ) ) 00064 return false; 00065 00066 return ( strcmp( name, ((Event*)event)->eventName() ) == 0 ); 00067 } 00068 00069 00071 00072 class KParts::GUIActivateEventPrivate 00073 { 00074 public: 00075 GUIActivateEventPrivate( bool activated ) 00076 : m_bActivated( activated ) 00077 { 00078 } 00079 static const char *s_strGUIActivateEvent; 00080 bool m_bActivated; 00081 }; 00082 00083 const char *GUIActivateEventPrivate::s_strGUIActivateEvent = "KParts/GUIActivate"; 00084 00085 GUIActivateEvent::GUIActivateEvent( bool activated ) : 00086 Event( GUIActivateEventPrivate::s_strGUIActivateEvent ), 00087 d( new GUIActivateEventPrivate(activated) ) 00088 { 00089 } 00090 00091 GUIActivateEvent::~GUIActivateEvent() 00092 { 00093 delete d; 00094 } 00095 00096 bool GUIActivateEvent::activated() const 00097 { 00098 return d->m_bActivated; 00099 } 00100 00101 bool GUIActivateEvent::test( const QEvent *event ) 00102 { 00103 return Event::test( event, GUIActivateEventPrivate::s_strGUIActivateEvent ); 00104 } 00105 00106 00108 00109 class KParts::PartActivateEventPrivate 00110 { 00111 public: 00112 PartActivateEventPrivate( bool activated, 00113 Part *part, 00114 QWidget *widget ) : 00115 m_bActivated( activated ), 00116 m_part( part ), 00117 m_widget( widget ) 00118 { 00119 } 00120 static const char *s_strPartActivateEvent; 00121 bool m_bActivated; 00122 Part *m_part; 00123 QWidget *m_widget; 00124 }; 00125 00126 const char *PartActivateEventPrivate::s_strPartActivateEvent = "KParts/PartActivateEvent"; 00127 00128 PartActivateEvent::PartActivateEvent( bool activated, 00129 Part *part, 00130 QWidget *widget ) : 00131 Event( PartActivateEventPrivate::s_strPartActivateEvent ), 00132 d( new PartActivateEventPrivate(activated,part,widget) ) 00133 { 00134 } 00135 00136 PartActivateEvent::~PartActivateEvent() 00137 { 00138 delete d; 00139 } 00140 00141 bool PartActivateEvent::activated() const 00142 { 00143 return d->m_bActivated; 00144 } 00145 00146 Part *PartActivateEvent::part() const 00147 { 00148 return d->m_part; 00149 } 00150 00151 QWidget *PartActivateEvent::widget() const 00152 { 00153 return d->m_widget; 00154 } 00155 00156 bool PartActivateEvent::test( const QEvent *event ) 00157 { 00158 return Event::test( event, PartActivateEventPrivate::s_strPartActivateEvent ); 00159 } 00160 00161 00163 00164 class KParts::PartSelectEventPrivate 00165 { 00166 public: 00167 PartSelectEventPrivate( bool selected, 00168 Part *part, 00169 QWidget *widget ) : 00170 m_bSelected( selected ), 00171 m_part( part ), 00172 m_widget( widget ) 00173 { 00174 } 00175 static const char *s_strPartSelectEvent; 00176 bool m_bSelected; 00177 Part *m_part; 00178 QWidget *m_widget; 00179 }; 00180 00181 const char *PartSelectEventPrivate::s_strPartSelectEvent = 00182 "KParts/PartSelectEvent"; 00183 00184 PartSelectEvent::PartSelectEvent( bool selected, 00185 Part *part, 00186 QWidget *widget ) : 00187 Event( PartSelectEventPrivate::s_strPartSelectEvent ), 00188 d( new PartSelectEventPrivate(selected,part,widget) ) 00189 { 00190 } 00191 00192 PartSelectEvent::~PartSelectEvent() 00193 { 00194 delete d; 00195 } 00196 00197 bool PartSelectEvent::selected() const 00198 { 00199 return d->m_bSelected; 00200 } 00201 00202 Part *PartSelectEvent::part() const 00203 { 00204 return d->m_part; 00205 } 00206 00207 QWidget *PartSelectEvent::widget() const 00208 { 00209 return d->m_widget; 00210 } 00211 00212 bool PartSelectEvent::test( const QEvent *event ) 00213 { 00214 return Event::test( event, PartSelectEventPrivate::s_strPartSelectEvent ); 00215 } 00216
KDE 4.6 API Reference