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 #include "kwhatsthismanager_p.h"
00020 #include "qwhatsthis.h"
00021 #include <qvariant.h>
00022 #include <kdebug.h>
00023 #include <qtextedit.h>
00024 #include <klocale.h>
00025 #include <kapplication.h>
00026
00027 KWhatsThisManager *KWhatsThisManager::s_instance = 0;
00028
00029 class KWhatsThisUndefined : public QWhatsThis
00030 {
00031 public:
00032 KWhatsThisUndefined (QWidget *);
00033 QString text (const QPoint &);
00034 public slots:
00035 bool clicked (const QString &);
00036 protected:
00037 QWidget *m_widget;
00038 };
00039
00040 KWhatsThisUndefined::KWhatsThisUndefined (QWidget *w)
00041 : QWhatsThis (w)
00042 {
00043 m_widget = w;
00044 }
00045
00046 QString KWhatsThisUndefined::text (const QPoint &)
00047 {
00048 if (!m_widget)
00049 return "";
00050 QString txt = i18n ("<b>Not Defined</b><br>There is no \"What's This?\""
00051 " help assigned to this widget. If you want to help us to "
00052 " describe the widget, you are welcome to <a href=\"submit"
00053 "-whatsthis\">send us your own \"What's This?\" help</a> for it.");
00054 QString parent;
00055 if (m_widget -> parentWidget ())
00056 parent = QWhatsThis::textFor (m_widget -> parentWidget ());
00057 if (parent != txt)
00058 if (! parent . isEmpty ())
00059 return parent;
00060 return txt;
00061 }
00062
00063 bool KWhatsThisUndefined::clicked (const QString& href)
00064 {
00065 if (href == "submit-whatsthis") {
00066 QWidget *w = m_widget;
00067 QString body;
00068 body . append ("Widget text: '" + (m_widget -> property ("text") . toString ()) + "'\n");
00069 QString dsc = QString ("current --> ") + m_widget -> name ();
00070 dsc . append (QString (" (") + m_widget -> className () + ")\n");
00071 for (w = m_widget; w && w != m_widget -> topLevelWidget (); w = w -> parentWidget ()) {
00072 dsc . append (w -> name ());
00073 dsc . append (QString (" (") + w -> className () + ")\n");
00074 }
00075 w = m_widget -> topLevelWidget ();
00076 if (w) {
00077 dsc . append ("toplevel --> ");
00078 dsc . append (w -> name ());
00079 dsc . append (QString (" (") + w -> className () + ")\n");
00080 }
00081 body . append (dsc);
00082 QString subj ("What's This submission: ");
00083 subj . append (qApp -> argv () [0]);
00084 body . append ("\nPlease type in your what's this help between these lines: "
00085 "\n--%-----------------------------------------------------------------------\n"
00086 "\n--%-----------------------------------------------------------------------");
00087 kapp -> invokeMailer ("quality-whatsthis@kde.org", "", "", subj, body);
00088 }
00089 return TRUE;
00090 }
00091
00092 void KWhatsThisManager::init ()
00093 {
00094 if (s_instance)
00095 return;
00096 s_instance = new KWhatsThisManager;
00097 }
00098
00099 KWhatsThisManager::KWhatsThisManager ()
00100 {
00101
00102
00103 }
00104
00105 bool KWhatsThisManager::eventFilter (QObject * , QEvent *e)
00106 {
00107 if (e -> type () == QEvent::ChildInserted) {
00108 QChildEvent *ce = (QChildEvent *)e;
00109
00110 if (ce -> child () -> isWidgetType ()) {
00111 QWidget *w = (QWidget *) (ce -> child ());
00112
00113 if (QWhatsThis::textFor (w) . isEmpty ())
00114 new KWhatsThisUndefined (w);
00115 }
00116 }
00117 return false;
00118 }
00119
00120 #include "kwhatsthismanager_p.moc"
00121