HelpDialog.cpp   HelpDialog.cpp 
skipping to change at line 36 skipping to change at line 36
#include <QResizeEvent> #include <QResizeEvent>
#include <QSize> #include <QSize>
#include <QMultiMap> #include <QMultiMap>
#include <QList> #include <QList>
#include <QSet> #include <QSet>
#include <QPair> #include <QPair>
#include <QtAlgorithms> #include <QtAlgorithms>
#include <QDebug> #include <QDebug>
#include "ui_helpDialogGui.h" #include "ui_helpDialogGui.h"
#include "HelpDialog.hpp" #include "HelpDialog.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelLocaleMgr.hpp"
#include "StelStyle.hpp"
#include "StelLogger.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelLocaleMgr.hpp"
#include "StelLogger.hpp"
#include "StelShortcutGroup.hpp"
#include "StelShortcutMgr.hpp"
#include "StelStyle.hpp"
HelpDialog::HelpDialog() HelpDialog::HelpDialog() : keyMgr(0)
{ {
ui = new Ui_helpDialogForm; ui = new Ui_helpDialogForm;
keyMgr = StelApp::getInstance().getStelShortcutManager();
// Make some key and mouse bindings translatable. Keys starting with Q_ASSERT(keyMgr);
// "!NUMBER-" are made up; the number is there to keep the entries
// sorted (at least relative to each other).
specialKeys["Space"] = N_("Space");
specialKeys["!01-arrows-and-left-drag"] = N_("Arrow keys & left mous
e drag");
specialKeys["!02-page-up/down"] = N_("Page Up/Down");
specialKeys["!03-ctrl+up/down"] = N_("CTRL + Up/Down");
specialKeys["!04-left-click"] = N_("Left click");
specialKeys["!05-right-click"] = N_("Right click");
specialKeys["!06-ctrl+left-click"] = N_("CTRL + Left click");
// Add keys for those keys which do not have actions.
QString group = N_("Movement and Selection");
setKey(group, "", "!01-arrows-and-left-drag", N_("Pan view around th
e sky"));
setKey(group, "", "!02-page-up/down", N_("Zoom in/out"));
setKey(group, "", "!03-ctrl+up/down", N_("Zoom in/out"));
setKey(group, "", "!04-left-click", N_("Select object"));
setKey(group, "", "!05-right-click", N_("Clear selection"));
#ifdef Q_OS_MAC
setKey(group, "", "!06-ctrl+left-click", N_("Clear selection"));
#endif
group = N_("When a Script is Running");
setKey(group, "", "4", N_("Stop currently running script"));
setKey(group, "", "5", N_("Pause script execution"));
setKey(group, "", "6", N_("Resume script execution"));
setKey(group, "", "J", N_("Slow down the script execution rate"));
setKey(group, "", "L", N_("Speed up the script execution rate"));
setKey(group, "", "K", N_("Set the normal script execution rate"));
// Add keys for those plugins which do not have GUI actions.
group = N_("Plugin Key Bindings");
setKey(group, "", "Alt+M", N_("Text User Interface"));
} }
HelpDialog::~HelpDialog() HelpDialog::~HelpDialog()
{ {
delete ui; delete ui;
ui = NULL; ui = NULL;
} }
void HelpDialog::retranslate() void HelpDialog::retranslate()
{ {
skipping to change at line 138 skipping to change at line 107
void HelpDialog::createDialogContent() void HelpDialog::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate())); connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SL OT(retranslate()));
connect(&StelApp::getInstance(), SIGNAL(colorSchemeChanged(QString)) , this, SLOT(updateIconsColor())); connect(&StelApp::getInstance(), SIGNAL(colorSchemeChanged(QString)) , this, SLOT(updateIconsColor()));
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
updateIconsColor(); updateIconsColor();
ui->stackListWidget->setCurrentRow(0); ui->stackListWidget->setCurrentRow(0);
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
// Help page
updateText(); updateText();
connect(ui->editShortcutsButton, SIGNAL(clicked()),
this, SLOT(showShortcutsWindow()));
// Log page
ui->logPathLabel->setText(QString("%1/log.txt:").arg(StelFileMgr::ge tUserDir())); ui->logPathLabel->setText(QString("%1/log.txt:").arg(StelFileMgr::ge tUserDir()));
connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(u pdateLog(int))); connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(u pdateLog(int)));
connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshLog( ))); connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshLog( )));
connect(ui->stackListWidget, SIGNAL(currentItemChanged(QListWidgetIt em *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWi dgetItem*))); connect(ui->stackListWidget, SIGNAL(currentItemChanged(QListWidgetIt em *, QListWidgetItem *)), this, SLOT(changePage(QListWidgetItem *, QListWi dgetItem*)));
} }
void HelpDialog::showShortcutsWindow()
{
QAction* action =
keyMgr->getGuiAction("actionShow_Shortcuts_Window_Global");
if (action)
{
if (action->isChecked())
action->setChecked(false);
action->setChecked(true);
}
}
void HelpDialog::updateLog(int) void HelpDialog::updateLog(int)
{ {
if(ui->stackedWidget->currentWidget() == ui->page_3) if (ui->stackedWidget->currentWidget() == ui->pageLog)
refreshLog(); refreshLog();
} }
void HelpDialog::refreshLog() void HelpDialog::refreshLog()
{ {
ui->logBrowser->setPlainText(StelLogger::getLog()); ui->logBrowser->setPlainText(StelLogger::getLog());
} }
void HelpDialog::setKey(QString group, QString oldKey, QString newKey, QStr ing description) QString HelpDialog::getHelpText(void)
{ {
// For adding keys like this, the choice of a QMultiMap seems like QString htmlText = "<html><head><title>";
// madness. However, when we update the text it does the grouping htmlText += Qt::escape(q_("Stellarium Help"));
// for us... we have to live with ugliness in one of these functions htmlText += "</title></head><body>\n";
// and it seems easier here.
// WARNING! Section titles are re-used below!
htmlText += "<p align=\"center\"><a href=\"#keys\">" +
Qt::escape(q_("Keys")) +
"</a> &bull; <a href=\"#links\">" +
Qt::escape(q_("Further Reading")) +
"</a></p>\n";
htmlText += "<h2 id='keys'>" + Qt::escape(q_("Keys")) + "</h2>\n";
htmlText += "<table cellpadding=\"10%\">\n";
// Describe keys for those keys which do not have actions.
// navigate
htmlText += "<tr><td>" + Qt::escape(q_("Pan view around the sky")) +
"</td>";
htmlText += "<td><b>" + Qt::escape(q_("Arrow keys & left mouse drag"
)) + "</b></td></tr>\n";
// zoom in/out
htmlText += "<tr><td rowspan='2'>" + Qt::escape(q_("Zoom in/out")) +
"</td>";
htmlText += "<td><b>" + Qt::escape(q_("Page Up/Down")) +
"</b></td></tr>\n";
htmlText += "<tr><td><b>" + Qt::escape(q_("CTRL + Up/Down")) +
"</b></td></tr>\n";
// select object
htmlText += "<tr><td>" + Qt::escape(q_("Select object")) + "</td>";
htmlText += "<td><b>" + Qt::escape(q_("Left click")) + "</b></td></t
r>\n";
// clear selection
htmlText += "<tr>";
#ifdef Q_OS_MAC
htmlText += "<td rowspan='2'>";
#else
htmlText += "<td>";
#endif
htmlText += Qt::escape(q_("Clear selection")) + "</td>";
htmlText += "<td><b>" + Qt::escape(q_("Right click")) + "</b></td></
tr>\n";
#ifdef Q_OS_MAC
htmlText += "<tr><td><b>" + Qt::escape(q_("CTRL + Left click")) + "<
/b></td></tr>\n";
//htmlText += "<td>" + Qt::escape(q_("Clear selection")) + "</td>";
#endif
htmlText += "</table>\n<p>" +
Qt::escape(
q_("Below are listed only the actions with assigned
keys. Further actions may be available via the \"%1\" button.")
.arg(ui->editShortcutsButton->text())
) +
"</p><table cellpadding=\"10%\">\n";
// For new key bindings we just insert and return QList<StelShortcutGroup*> groups = keyMgr->getGroupList();
if (oldKey.isEmpty()) foreach (const StelShortcutGroup* group, groups)
{ {
keyData.insert(group, QPair<QString, QString>(newKey, descri QString groupName= group->getText();
ption)); if (groupName.isEmpty())
// if (ui->helpBrowser!=NULL) groupName = group->getId();
// this->updateText();
return; QList< KeyDescription > descriptions;
} QList<StelShortcut*> shortcuts = group->getActionList();
if (shortcuts.isEmpty())
continue;
// Else delete the old entry if we can find it, and then insert the foreach (const StelShortcut* shortcut, shortcuts)
// new entry. Here's where the multimap makes us wince...
QMultiMap<QString, QPair<QString, QString> >::iterator i = keyData.b
egin();
while (i != keyData.end()) {
QMultiMap<QString, QPair<QString, QString> >::iterator prev
= i;
++i;
if (prev.value().first == oldKey)
{ {
keyData.erase(prev); QString text = q_(shortcut->getText());
QKeySequence primary = shortcut->getPrimaryKey();
if (primary.isEmpty())
{
// TODO: Decide whether to display undefined
actions.
continue;
}
QString keyString = primary.toString(QKeySequence::N
ativeText);
descriptions.append(KeyDescription(text, keyString))
;
}
if (descriptions.isEmpty())
continue;
// Sort by translated description:
// - on one hand, pre-determined order is lost
// - on the other, easier for the users
qSort(descriptions);
htmlText += "<tr></tr><tr><td><b><u>" + Qt::escape(q_(groupN
ame)) +
":</u></b></td></tr>\n";
foreach (const KeyDescription& desc, descriptions)
{
htmlText += "<tr><td>" + Qt::escape(desc.first) + "<
/td>";
htmlText += "<td><b>" + Qt::escape(desc.second) +
"</b></td></tr>\n";
} }
} }
keyData.insert(group, QPair<QString, QString>(newKey, description)); // edit shortcuts
// if (ui->helpBrowser!=NULL) // htmlText += "<tr><td><b>" + Qt::escape(q_("F7")) + "</b></td>";
// this->updateText(); // htmlText += "<td>" + Qt::escape(q_("Show and edit all keyboard short
} cuts")) + "</td></tr>\n";
htmlText += "</table>";
QString HelpDialog::getHeaderText(void)
{
return "<html><head><title>" + Qt::escape(q_("Stellarium Help")) + "
</title></head><body>\n"
+ "<h2>" + Qt::escape(q_("Keys")) + "</h2>\n";
}
QString HelpDialog::getFooterText(void)
{
// Regexp to replace {text} with an HTML link. // Regexp to replace {text} with an HTML link.
QRegExp a_rx = QRegExp("[{]([^{]*)[}]"); QRegExp a_rx = QRegExp("[{]([^{]*)[}]");
QString footer = "<h2>" + Qt::escape(q_("Further Reading")) + "</h2> // WARNING! Section titles are re-used above!
\n"; htmlText += "<h2 id=\"links\">" + Qt::escape(q_("Further Reading"))
footer += Qt::escape(q_("The following links are external web links, + "</h2>\n";
and will launch your web browser:\n")); htmlText += Qt::escape(q_("The following links are external web link
footer += "<p><a href=\"http://stellarium.org/wiki/index.php/Categor s, and will launch your web browser:\n"));
y:User%27s_Guide\">" + Qt::escape(q_("The Stellarium User Guide")) + "</a>" htmlText += "<p><a href=\"http://stellarium.org/wiki/index.php/Categ
; ory:User%27s_Guide\">" + Qt::escape(q_("The Stellarium User Guide")) + "</a
>";
footer += "<p>"; htmlText += "<p>";
// TRANSLATORS: The text between braces is the text of an HTML link. // TRANSLATORS: The text between braces is the text of an HTML link.
footer += Qt::escape(q_("{Frequently Asked Questions} about Stellari htmlText += Qt::escape(q_("{Frequently Asked Questions} about Stella
um. Answers too.")).replace(a_rx, "<a href=\"http://www.stellarium.org/wik rium. Answers too.")).replace(a_rx, "<a href=\"http://www.stellarium.org/w
i/index.php/FAQ\">\\1</a>"); iki/index.php/FAQ\">\\1</a>");
footer += "</p>\n"; htmlText += "</p>\n";
footer += "<p>"; htmlText += "<p>";
// TRANSLATORS: The text between braces is the text of an HTML link. // TRANSLATORS: The text between braces is the text of an HTML link.
footer += Qt::escape(q_("{The Stellarium Wiki} - General information htmlText += Qt::escape(q_("{The Stellarium Wiki} - General informati
. You can also find user-contributed landscapes and scripts here.")).repla on. You can also find user-contributed landscapes and scripts here.")).rep
ce(a_rx, "<a href=\"http://stellarium.org/wiki/\">\\1</a>"); lace(a_rx, "<a href=\"http://stellarium.org/wiki/\">\\1</a>");
footer += "</p>\n"; htmlText += "</p>\n";
footer += "<p>"; htmlText += "<p>";
// TRANSLATORS: The text between braces is the text of an HTML link. // TRANSLATORS: The text between braces is the text of an HTML link.
footer += Qt::escape(q_("{Support ticket system} - if you need help htmlText += Qt::escape(q_("{Support ticket system} - if you need hel
using Stellarium, post a support request here and we'll try to help.")).rep p using Stellarium, post a support request here and we'll try to help.")).r
lace(a_rx, "<a href=\"http://answers.launchpad.net/stellarium/+addquestion\ eplace(a_rx, "<a href=\"http://answers.launchpad.net/stellarium/+addquestio
">\\1</a>"); n\">\\1</a>");
footer += "</p>\n"; htmlText += "</p>\n";
footer += "<p>"; htmlText += "<p>";
// TRANSLATORS: The text between braces is the text of an HTML link. // TRANSLATORS: The text between braces is the text of an HTML link.
footer += Qt::escape(q_("{Bug reporting and feature request system} htmlText += Qt::escape(q_("{Bug reporting and feature request system
- if something doesn't work properly or is missing and is not listed in the } - if something doesn't work properly or is missing and is not listed in t
tracker, you can open bug reports here.")).replace(a_rx, "<a href=\"http:/ he tracker, you can open bug reports here.")).replace(a_rx, "<a href=\"http
/bugs.launchpad.net/stellarium/\">\\1</a>"); ://bugs.launchpad.net/stellarium/\">\\1</a>");
footer += "</p>\n"; htmlText += "</p>\n";
footer += "<p>"; htmlText += "<p>";
// TRANSLATORS: The text between braces is the text of an HTML link. // TRANSLATORS: The text between braces is the text of an HTML link.
footer += Qt::escape(q_("{Forums} - discuss Stellarium with other us htmlText += Qt::escape(q_("{Forums} - discuss Stellarium with other
ers.")).replace(a_rx, "<a href=\"http://sourceforge.net/forum/forum.php?for users.")).replace(a_rx, "<a href=\"http://sourceforge.net/forum/forum.php?f
um_id=278769\">\\1</a>"); orum_id=278769\">\\1</a>");
footer += "</p>\n"; htmlText += "</p>\n";
footer += "</body></html>\n"; htmlText += "</body></html>\n";
return footer; return htmlText;
} }
void HelpDialog::updateText(void) void HelpDialog::updateText(void)
{ {
// Here's how we will build the help text for the keys: QString newHtml = getHelpText();
// 1. Get a unique list of groups by asking for the keys and then c
onverting the
// resulting QList into a QSet.
// 2 Converet back to a QList, sort and move the empty string to t
he end of the
// list if it is present (this is the miscellaneous group).
// 3 Iterate over the QSet of groups names doing:
// 3.1 add the group title
// 3.2 Use QMultiMap::values(key) to get a list of QPair<QString, Q
String>
// which describe the key binding (QPair::first) and the help t
ext for
// that key binding (QPair::second).
// 3.3 Sort this list by the first value in the pait, courtesy of q
Sort and
// HelpDialog::helpItemSort
// 3.4 Iterate over the sorted list adding key and description for
each item
QString newHtml(getHeaderText());
newHtml += "<table cellpadding=\"10%\">\n";
QList<QString> groups = keyData.keys().toSet().toList(); // 1 + 2
qSort(groups.begin(), groups.end(), HelpDialog::helpGroupSort);
// 3
QString lastGroup; // to group "" and "Miscellaneous into one
foreach (QString group, groups)
{
QString groupDescription = group;
if (group.isEmpty())
groupDescription = N_("Miscellaneous");
if (lastGroup!=groupDescription)
{
// 3.1
newHtml += "<tr></tr><tr><td><b><u>" + Qt::escape(q_
(groupDescription)) + ":</u></b></td></tr>\n";
}
lastGroup = groupDescription;
// 3.2
QList< QPair<QString, QString> > keys = keyData.values(group
);
// 3.3
qSort(keys.begin(), keys.end(), HelpDialog::helpItemSort);
// 3.4
for(int i=0; i<keys.size(); i++)
{
QString key = keys.at(i).first; // the string which
holds the key, e.g. "F1"
// For some keys we need to translate from th QT str
ing to something
// more readable
QString specKey = specialKeys[key];
if (!specKey.isEmpty())
key = q_(specKey);
// Finally, add HTML table data for the key as it's
help text
newHtml += "<tr><td><b>" + Qt::escape(key) + "</b></
td>";
newHtml += "<td>" + Qt::escape(q_( keys.at(i).second
)) + "</td></tr>\n";
}
}
newHtml += "</table>";
newHtml += getFooterText();
ui->helpBrowser->clear(); ui->helpBrowser->clear();
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( )); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui( ));
Q_ASSERT(gui); Q_ASSERT(gui);
ui->helpBrowser->document()->setDefaultStyleSheet(QString(gui->getSt elStyle().htmlStyleSheet)); ui->helpBrowser->document()->setDefaultStyleSheet(QString(gui->getSt elStyle().htmlStyleSheet));
ui->helpBrowser->insertHtml(newHtml); ui->helpBrowser->insertHtml(newHtml);
ui->helpBrowser->scrollToAnchor("top"); ui->helpBrowser->scrollToAnchor("top");
// populate About tab // populate About tab
newHtml = "<h1>" + StelUtils::getApplicationName() + "</h1>"; newHtml = "<h1>" + StelUtils::getApplicationName() + "</h1>";
// Note: this legal notice is not suitable for traslation // Note: this legal notice is not suitable for traslation
newHtml += "<h3>Copyright &copy; 2000-2012 Stellarium Developers</h3 >"; newHtml += "<h3>Copyright &copy; 2000-2013 Stellarium Developers</h3 >";
newHtml += "<p>This program is free software; you can redistribute i t and/or "; newHtml += "<p>This program is free software; you can redistribute i t and/or ";
newHtml += "modify it under the terms of the GNU General Public Lice nse "; newHtml += "modify it under the terms of the GNU General Public Lice nse ";
newHtml += "as published by the Free Software Foundation; either ver sion 2 "; newHtml += "as published by the Free Software Foundation; either ver sion 2 ";
newHtml += "of the License, or (at your option) any later version.</ p>"; newHtml += "of the License, or (at your option) any later version.</ p>";
newHtml += "<p>This program is distributed in the hope that it will be useful, "; newHtml += "<p>This program is distributed in the hope that it will be useful, ";
newHtml += "but WITHOUT ANY WARRANTY; without even the implied "; newHtml += "but WITHOUT ANY WARRANTY; without even the implied ";
newHtml += "warranty of MERCHANTABILITY or FITNESS FOR A "; newHtml += "warranty of MERCHANTABILITY or FITNESS FOR A ";
newHtml += "PARTICULAR PURPOSE. See the GNU General Public "; newHtml += "PARTICULAR PURPOSE. See the GNU General Public ";
newHtml += "License for more details.</p>"; newHtml += "License for more details.</p>";
newHtml += "<p>You should have received a copy of the GNU General Pu blic "; newHtml += "<p>You should have received a copy of the GNU General Pu blic ";
skipping to change at line 350 skipping to change at line 332
newHtml += "<li>" + Qt::escape(q_("Developer: %1").arg(QString("Mike Storm"))) + "</li>"; newHtml += "<li>" + Qt::escape(q_("Developer: %1").arg(QString("Mike Storm"))) + "</li>";
newHtml += "<li>" + Qt::escape(q_("OSX Developer: %1").arg(QString(" Nigel Kerr"))) + "</li>"; newHtml += "<li>" + Qt::escape(q_("OSX Developer: %1").arg(QString(" Nigel Kerr"))) + "</li>";
newHtml += "<li>" + Qt::escape(q_("OSX Developer: %1").arg(QString(" Diego Marcos"))) + "</li></ul>"; newHtml += "<li>" + Qt::escape(q_("OSX Developer: %1").arg(QString(" Diego Marcos"))) + "</li></ul>";
newHtml += "<p>"; newHtml += "<p>";
ui->aboutBrowser->clear(); ui->aboutBrowser->clear();
ui->aboutBrowser->document()->setDefaultStyleSheet(QString(gui->getS telStyle().htmlStyleSheet)); ui->aboutBrowser->document()->setDefaultStyleSheet(QString(gui->getS telStyle().htmlStyleSheet));
ui->aboutBrowser->insertHtml(newHtml); ui->aboutBrowser->insertHtml(newHtml);
ui->aboutBrowser->scrollToAnchor("top"); ui->aboutBrowser->scrollToAnchor("top");
} }
bool HelpDialog::helpItemSort(const QPair<QString, QString>& p1, const QPai
r<QString, QString>& p2)
{
// To be 100% proper, we should sort F1 F2 F11 F12 in that order, al
though
// right now we will get F1 F11 F12 F2. However, at time of writing
, no group
// of keys has F1-F9, and one from F10-F12 in it, so it doesn't real
ly matter.
// -MNG 2008-06-01
if (p1.first.split(",").at(0).size()!=p2.first.split(",").at(0).size
())
return p1.first.size() < p2.first.size();
else
return p1.first < p2.first;
}
bool HelpDialog::helpGroupSort(const QString& s1, const QString& s2)
{
QString s1c = s1.toUpper();
QString s2c = s2.toUpper();
if (s1c=="" || s1c==QString(N_("Miscellaneous")).toUpper())
s1c = "ZZZ" + s1c;
if (s2c=="" || s2c==QString(N_("Miscellaneous")).toUpper())
s2c = "ZZZ" + s2c;
if (s1c=="DEBUG")
s1c = "ZZZZ" + s1c;
if (s2c=="DEBUG")
s2c = "ZZZZ" + s2c;
return s1c < s2c;
}
void HelpDialog::changePage(QListWidgetItem *current, QListWidgetItem *prev ious) void HelpDialog::changePage(QListWidgetItem *current, QListWidgetItem *prev ious)
{ {
if (!current) if (!current)
current = previous; current = previous;
ui->stackedWidget->setCurrentIndex(ui->stackListWidget->row(current) ); ui->stackedWidget->setCurrentIndex(ui->stackListWidget->row(current) );
} }
 End of changes. 35 change blocks. 
223 lines changed or deleted 164 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/