a b/src/qtgui/rclhelp.cpp
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: rclmain_w.cpp,v 1.57 2008-10-13 07:57:12 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
8
 *   (at your option) any later version.
9
 *
10
 *   This program is distributed in the hope that it will be useful,
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *   GNU General Public License for more details.
14
 *
15
 *   You should have received a copy of the GNU General Public License
16
 *   along with this program; if not, write to the
17
 *   Free Software Foundation, Inc.,
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 */
20
#include "autoconfig.h"
21
#include <time.h>
22
23
#include <qevent.h>
24
#include <qwidget.h>
25
#if (QT_VERSION < 0x040000)
26
#define Q34EVOVERRIDE QEvent::AccelOverride
27
#else
28
#define Q34EVOVERRIDE QEvent::ShortcutOverride
29
#endif
30
31
#include "recoll.h"
32
#include "rclhelp.h"
33
#include "debuglog.h"
34
35
map<string, string> HelpClient::helpmap;
36
37
void HelpClient::installMap(string wname, string section)
38
{
39
    helpmap[wname] = section;
40
}
41
42
HelpClient::HelpClient(QObject *parent, const char *name)
43
    : QObject(parent, name)
44
{
45
    parent->installEventFilter(this);
46
}
47
    
48
bool HelpClient::eventFilter(QObject *obj, QEvent *event)
49
{
50
    static time_t last_start;
51
    if (event->type() == QEvent::KeyPress || event->type() == Q34EVOVERRIDE) {
52
  //  LOGDEB(("HelpClient::eventFilter: %d\n", (int)event->type()));
53
  QKeyEvent *ke = static_cast<QKeyEvent *>(event);
54
  if (ke->key() == Qt::Key_F1 || ke->key() == Qt::Key_Help) {
55
      if (obj->isWidgetType()) {
56
      QWidget *widget = static_cast<QWidget *>(obj)->focusWidget();
57
      map<string, string>::iterator it = helpmap.end();
58
      while (widget) {
59
          it = helpmap.find(widget->name());
60
          if (it != helpmap.end())
61
          break;
62
          widget = widget->parentWidget();
63
      }
64
      if (time(0) - last_start > 5) {
65
          last_start = time(0);
66
          if (it != helpmap.end()) {
67
          LOGDEB(("HelpClient::eventFilter: %s->%s\n",
68
              it->first.c_str(), it->second.c_str()));
69
          startManual(it->second);
70
          } else {
71
          LOGDEB(("HelpClient::eventFilter: no help section\n"));
72
          startManual("");
73
          }
74
      }
75
      }
76
      return true;
77
  }
78
    }
79
    return false;
80
}
81