KDEUI
kwhatsthismanager.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kwhatsthismanager_p.h"
00021 #include <kdebug.h>
00022
00023 #include <QtCore/QVariant>
00024 #include <QtGui/QApplication>
00025 #include <QtGui/QWhatsThis>
00026 #include <QtGui/QWhatsThisClickedEvent>
00027
00028 #include <klocale.h>
00029 #include <ktoolinvocation.h>
00030
00031 KWhatsThisManager *KWhatsThisManager::s_instance = 0;
00032
00033 QString KWhatsThisManager::text() const
00034 {
00035 QString txt = i18n ("<b>Not Defined</b><br/>There is no \"What's This\""
00036 " help assigned to this widget. If you want to help us to"
00037 " describe the widget, you are welcome to <a href=\"submit"
00038 "-whatsthis\">send us your own \"What's This\" help</a> for it.");
00039 return txt;
00040 }
00041
00042 void KWhatsThisManager::clicked( const QString& href, QWidget *widget )
00043 {
00044 if ( href == "submit-whatsthis" ) {
00045 QString body;
00046 body.append( QString( "Widget text: '%1'\n" ).arg( widget->property( "text" ).toString() ) );
00047
00048 QString dsc = QString( "current --> %1" ).arg( widget->objectName() );
00049 dsc.append( QString( " (%1)\n" ).arg( widget->metaObject()->className() ) );
00050
00051 QWidget *w;
00052 for ( w = widget; w && w != widget->topLevelWidget(); w = w->parentWidget() ) {
00053 dsc.append( w->objectName() );
00054 dsc.append( QString( " (%1)\n" ).arg( w->metaObject()->className() ) );
00055 }
00056
00057 w = widget->topLevelWidget();
00058
00059 if ( w ) {
00060 dsc.append( "toplevel --> " );
00061 dsc.append( w->objectName() );
00062 dsc.append( QString( " (%1)\n" ).arg( w->metaObject()->className() ) );
00063 }
00064
00065 body.append( dsc );
00066
00067 QString subject( "What's This submission: " );
00068 subject.append( qApp->argv()[ 0 ] );
00069
00070 body.append( "\nPlease type in your what's this help between these lines: "
00071 "\n--%-----------------------------------------------------------------------\n"
00072 "\n--%-----------------------------------------------------------------------" );
00073
00074 KToolInvocation::invokeMailer( "quality-whatsthis@kde.org", "", "", subject, body );
00075 }
00076 }
00077
00078 void KWhatsThisManager::init()
00079 {
00080 if ( s_instance )
00081 return;
00082
00083 s_instance = new KWhatsThisManager;
00084 }
00085
00086 KWhatsThisManager::KWhatsThisManager()
00087 {
00088
00089 qApp->installEventFilter( this );
00090 }
00091
00092 bool KWhatsThisManager::eventFilter( QObject *object, QEvent *event )
00093 {
00094 if ( event->type() == QEvent::WhatsThis ) {
00095 QHelpEvent *he = static_cast<QHelpEvent* >(event);
00096 QWidget *widget = qobject_cast<QWidget*>( object );
00097 if ( widget ) {
00098 QHelpEvent queryEvent(QEvent::QueryWhatsThis, he->pos(), he->globalPos());
00099 const bool sentEvent = QApplication::sendEvent(widget, &queryEvent);
00100 if (!sentEvent || !queryEvent.isAccepted()) {
00101
00102 QWhatsThis::showText(he->globalPos(), text(), widget);
00103 return true;
00104 }
00105 }
00106 } else if ( event->type() == QEvent::WhatsThisClicked ) {
00107 QWhatsThisClickedEvent *wte = static_cast<QWhatsThisClickedEvent* >(event);
00108 QWidget *widget = qobject_cast<QWidget*>( object );
00109 if ( widget ) {
00110 clicked( wte->href(), widget );
00111 return true;
00112 }
00113 }
00114
00115 return false;
00116 }
00117
00118 #include "kwhatsthismanager_p.moc"
00119