~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kdeui/kwhatsthismanager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is part of the KDE Libraries
2
 
 *  Copyright (C) 2004 Peter Rockai (mornfall) <mornfall@danill.sk>
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 <QApplication>
21
 
#include <QVariant>
22
 
#include <QWhatsThis>
23
 
#include <QWhatsThisClickedEvent>
24
 
 
25
 
#include <klocale.h>
26
 
#include <ktoolinvocation.h>
27
 
 
28
 
#include "kwhatsthismanager_p.h"
29
 
 
30
 
KWhatsThisManager *KWhatsThisManager::s_instance = 0;
31
 
 
32
 
QString KWhatsThisManager::text() const
33
 
{
34
 
  QString txt = i18n ("<b>Not Defined</b><br>There is no \"What's This\""
35
 
          " help assigned to this widget. If you want to help us to"
36
 
          " describe the widget, you are welcome to <a href=\"submit"
37
 
          "-whatsthis\">send us your own \"What's This\" help</a> for it.");
38
 
  return txt;
39
 
}
40
 
 
41
 
void KWhatsThisManager::clicked( const QString& href, QWidget *widget )
42
 
{
43
 
  if ( href == "submit-whatsthis" ) {
44
 
    QString body;
45
 
    body.append( QString( "Widget text: '%1'\n" ).arg( widget->property( "text" ).toString() ) );
46
 
 
47
 
    QString dsc = QString( "current --> %1" ).arg( widget->objectName() );
48
 
    dsc.append( QString( " (%1)\n" ).arg( widget->metaObject()->className() ) );
49
 
 
50
 
    QWidget *w;
51
 
    for ( w = widget; w && w != widget->topLevelWidget(); w = w->parentWidget() ) {
52
 
      dsc.append( w->objectName() );
53
 
      dsc.append( QString( " (%1)\n" ).arg( w->metaObject()->className() ) );
54
 
    }
55
 
 
56
 
    w = widget->topLevelWidget();
57
 
 
58
 
    if ( w ) {
59
 
      dsc.append( "toplevel --> " );
60
 
      dsc.append( w->objectName() );
61
 
      dsc.append( QString( " (%1)\n" ).arg( w->metaObject()->className() ) );
62
 
    }
63
 
 
64
 
    body.append( dsc );
65
 
 
66
 
    QString subject( "What's This submission: " );
67
 
    subject.append( qApp->argv()[ 0 ] );
68
 
 
69
 
    body.append( "\nPlease type in your what's this help between these lines: "
70
 
                 "\n--%-----------------------------------------------------------------------\n"
71
 
                 "\n--%-----------------------------------------------------------------------" );
72
 
 
73
 
    KToolInvocation::invokeMailer( "quality-whatsthis@kde.org", "", "", subject, body );
74
 
  }
75
 
}
76
 
 
77
 
void KWhatsThisManager::init()
78
 
{
79
 
  if ( s_instance )
80
 
    return;
81
 
 
82
 
  s_instance = new KWhatsThisManager;
83
 
}
84
 
 
85
 
KWhatsThisManager::KWhatsThisManager()
86
 
{
87
 
  // go away...
88
 
  qApp->installEventFilter( this );
89
 
}
90
 
 
91
 
bool KWhatsThisManager::eventFilter( QObject *object, QEvent *event )
92
 
{
93
 
  if ( event->type() == QEvent::ChildAdded ) {
94
 
 
95
 
    QChildEvent *childEvent = (QChildEvent*)event;
96
 
    if ( childEvent->added() && childEvent->child()->isWidgetType() ) {
97
 
 
98
 
      QWidget *widget = (QWidget *)(childEvent->child());
99
 
      if ( widget->whatsThis().isEmpty() ) {
100
 
        widget->setWhatsThis( text() );
101
 
      }
102
 
    }
103
 
  } else if ( event->type() == QEvent::WhatsThisClicked ) {
104
 
    QWhatsThisClickedEvent *wte = (QWhatsThisClickedEvent*)event;
105
 
    QWidget *widget = qobject_cast<QWidget*>( object );
106
 
    if ( widget ) {
107
 
      clicked( wte->href(), widget );
108
 
      return true;
109
 
    }
110
 
  }
111
 
 
112
 
  return false;
113
 
}
114
 
 
115
 
#include "kwhatsthismanager_p.moc"
116