Crossfire Server, Trunk
HelpManager.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "HelpManager.h"
14 #include <QApplication>
15 #include <QtGui>
16 #include <QDialog>
17 #include <QHelpContentWidget>
18 #include <QHelpIndexWidget>
19 #include <QWidget>
20 #include <QVBoxLayout>
21 #include <QSplitter>
22 #include "HelpBrowser.h"
23 
24 const char *HelpManager::helpIdProperty = "cre_help_id";
25 
26 HelpManager::HelpManager(const QString &helpRoot) : QHelpEngine(helpRoot + "/cre.qhc") {
27  myDisplay = new QDialog();
28  QVBoxLayout *layout = new QVBoxLayout(myDisplay);
29  QSplitter *horizSplitter = new QSplitter(Qt::Horizontal, myDisplay);
30  layout->addWidget(horizSplitter);
31 
32  QTabWidget* tWidget = new QTabWidget(horizSplitter);
33  tWidget->addTab(contentWidget(), tr("Contents"));
34  tWidget->addTab(indexWidget(), tr("Index"));
35 
36  myBrowser = new HelpBrowser(this, horizSplitter);
37  connect(contentWidget(), SIGNAL(linkActivated(QUrl)), myBrowser, SLOT(setSource(QUrl)));
38  connect(indexWidget(), SIGNAL(linkActivated(QUrl, QString)), myBrowser, SLOT(setSource(QUrl)));
39 
40  horizSplitter->insertWidget(0, tWidget);
41  horizSplitter->insertWidget(1, myBrowser);
42 
43  myDisplay->setVisible(false);
44 }
45 
47  delete myDisplay;
48 }
49 
51  myDisplay->setVisible(true);
52  myDisplay->setFocus();
53  myDisplay->activateWindow();
54  myDisplay->raise();
55  myBrowser->setSource(computeUrlToDisplay());
56 }
57 
58 void HelpManager::setHelpId(QWidget *widget, const QString &id) {
59  widget->setProperty(helpIdProperty, id);
60 }
61 
62 
63 QUrl HelpManager::computeUrlForWidget(QWidget *widget) const {
64  if (!widget) {
65  return QUrl();
66  }
67  auto helpId = widget->property(helpIdProperty);
68  if (!helpId.isNull()) {
69  auto links = linksForIdentifier(helpId.toString());
70  if (!links.empty()) {
71  return links.begin().value();
72  }
73  }
74  return computeUrlForWidget(widget->parentWidget());
75 }
76 
78  auto widget = QApplication::focusWidget();
79  auto url = computeUrlForWidget(widget);
80  if (url.isValid()) {
81  return url;
82  }
83  return QUrl("qthelp://com.real-time.crossfire/cre/index.html");
84 }
layout
Definition: main.cpp:84
HelpBrowser.h
HelpManager::myDisplay
QDialog * myDisplay
Definition: HelpManager.h:41
HelpManager::computeUrlToDisplay
QUrl computeUrlToDisplay() const
Definition: HelpManager.cpp:77
HelpManager::computeUrlForWidget
QUrl computeUrlForWidget(QWidget *widget) const
Definition: HelpManager.cpp:63
HelpManager::HelpManager
HelpManager(const QString &helpRoot)
Definition: HelpManager.cpp:26
HelpBrowser
Definition: HelpBrowser.h:20
HelpManager::helpIdProperty
static const char * helpIdProperty
Definition: HelpManager.h:27
HelpManager.h
HelpManager::setHelpId
static void setHelpId(QWidget *widget, const QString &id)
Definition: HelpManager.cpp:58
HelpManager::~HelpManager
virtual ~HelpManager()
Definition: HelpManager.cpp:46
HelpManager::displayHelp
void displayHelp()
Definition: HelpManager.cpp:50
HelpManager::myBrowser
HelpBrowser * myBrowser
Definition: HelpManager.h:42
connect
Definition: connect.py:1