2015-02-02 09:30:17 +01:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015 Werner Schweer
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "help.h"
|
|
|
|
#include "musescore.h"
|
|
|
|
|
|
|
|
namespace Ms {
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// HelpQuery
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
HelpQuery::HelpQuery(QWidget* parent)
|
|
|
|
: QWidgetAction(parent)
|
|
|
|
{
|
2015-02-06 20:38:10 +01:00
|
|
|
mapper = new QSignalMapper(this);
|
|
|
|
|
2015-02-02 09:30:17 +01:00
|
|
|
w = new QWidget(parent);
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout;
|
|
|
|
|
|
|
|
QLabel* label = new QLabel;
|
|
|
|
label->setText(tr("Search for: "));
|
|
|
|
layout->addWidget(label);
|
|
|
|
|
|
|
|
entry = new QLineEdit;
|
|
|
|
layout->addWidget(entry);
|
|
|
|
|
|
|
|
QToolButton* button = new QToolButton;
|
|
|
|
button->setText("x");
|
|
|
|
layout->addWidget(button);
|
|
|
|
|
|
|
|
w->setLayout(layout);
|
|
|
|
setDefaultWidget(w);
|
|
|
|
|
|
|
|
emptyState = true;
|
|
|
|
|
|
|
|
connect(button, SIGNAL(clicked()), entry, SLOT(clear()));
|
|
|
|
connect(entry, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const QString&)));
|
2015-02-09 10:23:21 +01:00
|
|
|
connect(entry, SIGNAL(returnPressed()), SLOT(returnPressed()));
|
2015-02-06 20:38:10 +01:00
|
|
|
connect(mapper, SIGNAL(mapped(QObject*)), SLOT(actionTriggered(QObject*)));
|
2015-02-02 09:30:17 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 10:23:21 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// setFocus
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void HelpQuery::setFocus()
|
|
|
|
{
|
|
|
|
entry->clear();
|
|
|
|
entry->setFocus();
|
|
|
|
}
|
|
|
|
|
2015-02-02 09:30:17 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// textChanged
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-02-09 10:23:21 +01:00
|
|
|
void HelpQuery::textChanged(const QString& ss)
|
2015-02-02 09:30:17 +01:00
|
|
|
{
|
2015-02-09 10:23:21 +01:00
|
|
|
QString s = ss.toLower();
|
2015-02-02 09:30:17 +01:00
|
|
|
QWidget* menu = static_cast<QWidget*>(parent());
|
|
|
|
if (s.isEmpty()) {
|
|
|
|
if (!emptyState) { // restore old menu entries
|
|
|
|
QList<QAction*> al = menu->actions();
|
|
|
|
for (QAction* a : al) {
|
|
|
|
if (a != this)
|
|
|
|
menu->removeAction(a);
|
|
|
|
}
|
|
|
|
for (QAction* a : actions) {
|
|
|
|
if (a != this)
|
|
|
|
menu->addAction(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emptyState = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (emptyState)
|
|
|
|
actions = menu->actions();
|
|
|
|
for (QAction* a : menu->actions()) {
|
|
|
|
if (a != this)
|
|
|
|
menu->removeAction(a);
|
|
|
|
}
|
|
|
|
emptyState = false;
|
2015-02-12 11:55:43 +01:00
|
|
|
if (!mscore->helpEngine())
|
|
|
|
return;
|
|
|
|
QMap<QString,QUrl>list = mscore->helpEngine()->linksForIdentifier(s);
|
|
|
|
// QMap<QString,QUrl>list = mscore->helpEngine()->indexModel()->linksForKeyword(s);
|
2015-02-09 10:23:21 +01:00
|
|
|
int k = 0;
|
2015-02-06 20:38:10 +01:00
|
|
|
for (auto i = list.begin(); i != list.end(); ++i) {
|
|
|
|
QAction* action = new QAction(i.key(), this);
|
|
|
|
action->setData(i.value());
|
2015-02-09 10:23:21 +01:00
|
|
|
// printf("add action <%s> <%s>\n", qPrintable(i.key()), qPrintable(i.value().toString()));
|
2015-02-06 16:36:43 +01:00
|
|
|
menu->addAction(action);
|
2015-02-06 20:38:10 +01:00
|
|
|
connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
|
|
|
|
mapper->setMapping(action, action);
|
2015-02-09 10:23:21 +01:00
|
|
|
if (++k > 10)
|
|
|
|
break;
|
2015-02-06 16:36:43 +01:00
|
|
|
}
|
2015-02-02 09:30:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// actionTriggered
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2015-02-06 20:38:10 +01:00
|
|
|
void HelpQuery::actionTriggered(QObject* obj)
|
2015-02-02 09:30:17 +01:00
|
|
|
{
|
2015-02-06 20:38:10 +01:00
|
|
|
QAction* action = static_cast<QAction*>(obj);
|
2015-02-02 09:30:17 +01:00
|
|
|
if (action->data().isNull())
|
|
|
|
return;
|
2015-02-06 16:36:43 +01:00
|
|
|
QUrl url = action->data().toUrl();
|
2015-02-06 20:38:10 +01:00
|
|
|
if (url.isValid())
|
2015-02-06 17:39:45 +01:00
|
|
|
mscore->showHelp(url);
|
2015-02-06 20:38:10 +01:00
|
|
|
else
|
|
|
|
qDebug("actionTriggered: bad url");
|
|
|
|
entry->clear();
|
2015-02-02 09:30:17 +01:00
|
|
|
}
|
|
|
|
|
2015-02-09 10:23:21 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// return pressed
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void HelpQuery::returnPressed()
|
|
|
|
{
|
2015-02-19 17:29:30 +01:00
|
|
|
QHelpEngine* he = mscore->helpEngine();
|
|
|
|
if (!he)
|
|
|
|
return;
|
|
|
|
QMap<QString,QUrl>list = he->linksForIdentifier(entry->text().toLower());
|
2015-02-09 10:23:21 +01:00
|
|
|
if (!list.isEmpty()) {
|
|
|
|
mscore->showHelp(list.begin().value());
|
|
|
|
}
|
|
|
|
entry->clear();
|
|
|
|
}
|
2015-02-02 09:30:17 +01:00
|
|
|
|
|
|
|
} // end namespace Ms
|
|
|
|
|