-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2edc7e0
commit 42420f0
Showing
7 changed files
with
214 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "searchComboBox.h" | ||
#include "musescore.h" | ||
#include "scoreview.h" | ||
#include "libmscore/score.h" | ||
#include "scoreaccessibility.h" | ||
|
||
namespace Ms { | ||
|
||
SearchComboBox::SearchComboBox(QWidget* p) : QComboBox(p) | ||
{ | ||
setAccessibleName(tr("Search Box")); | ||
setAccessibleDescription(tr("Type to search. Press Enter to return to score.")); | ||
setEditable(true); | ||
setInsertPolicy(QComboBox::InsertAtTop); | ||
_found = false; | ||
_searchType = SearchType::NO_SEARCH; | ||
connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(searchTextChanged(QString))); | ||
} | ||
|
||
void SearchComboBox::searchInit() | ||
{ | ||
_searchType = SearchType::NO_SEARCH; | ||
_found = false; | ||
} | ||
|
||
void SearchComboBox::setSearchType(SearchType s) | ||
{ | ||
_searchType = s; | ||
} | ||
|
||
void SearchComboBox::searchTextChanged(const QString& s) | ||
{ | ||
searchInit(); | ||
if (s.isEmpty()) | ||
return; | ||
ScoreView* cv = mscore->currentScoreView(); | ||
if (cv == 0) | ||
return; | ||
|
||
bool ok; | ||
|
||
int n = s.toInt(&ok); | ||
if (ok && n >= 0) { | ||
setSearchType(SearchType::SEARCH_MEASURE); | ||
_found = cv->searchMeasure(n); | ||
} | ||
else { | ||
if (s.size() >= 2 && s[0].toLower() == 'p' && s[1].isNumber()) { | ||
n = s.mid(1).toInt(&ok); | ||
if (ok && n >= 0) { | ||
setSearchType(SearchType::SEARCH_PAGE); | ||
_found = cv->searchPage(n); | ||
} | ||
} | ||
|
||
if (searchType() != SearchType::SEARCH_PAGE) { | ||
setSearchType(SearchType::SEARCH_REHEARSAL_MARK); | ||
_found = cv->searchRehearsalMark(s); | ||
} | ||
} | ||
//updating status bar | ||
ScoreAccessibility::instance()->updateAccessibilityInfo(); | ||
emit currentSearchFinished(); | ||
} | ||
|
||
AccessibleSearchBox::AccessibleSearchBox(SearchComboBox *comboBox) : QAccessibleWidget(comboBox) | ||
{ | ||
searchBox = comboBox; | ||
} | ||
|
||
QAccessibleInterface* AccessibleSearchBox::SearchBoxFactory(const QString &classname, QObject *object) | ||
{ | ||
QAccessibleInterface *iface = 0; | ||
if (classname == QLatin1String("Ms::SearchComboBox") && object && object->isWidgetType()){ | ||
qDebug("Creating interface for SearchComboBox object"); | ||
SearchComboBox* s = static_cast<SearchComboBox*>(object); | ||
AccessibleSearchBox* a = new AccessibleSearchBox(s); | ||
QObject::connect(s, SIGNAL(currentSearchFinished()), a, SLOT(searchFinished())); | ||
iface = static_cast<QAccessibleInterface*>(a); | ||
} | ||
|
||
return iface; | ||
} | ||
|
||
QString AccessibleSearchBox::text(QAccessible::Text t) const | ||
{ | ||
QString type; | ||
QString value = searchBox->currentText(); | ||
if (t == QAccessible::Value) { | ||
switch (searchBox->searchType()) { | ||
case SearchComboBox::SearchType::NO_SEARCH: | ||
return QString(); | ||
case SearchComboBox::SearchType::SEARCH_MEASURE: | ||
type = tr("Measure"); | ||
break; | ||
case SearchComboBox::SearchType::SEARCH_PAGE: | ||
type = tr("Page"); | ||
value = value.mid(1); | ||
break; | ||
case SearchComboBox::SearchType::SEARCH_REHEARSAL_MARK: | ||
type = tr("Rehearsal Mark"); | ||
break; | ||
} | ||
QString found = searchBox->found() ? "" : tr("Not found "); | ||
return QString("%1 %2 %3%4").arg(type).arg(value).arg(found).arg(mscore->currentScoreView()->score()->accessibleInfo()); | ||
} | ||
|
||
return QAccessibleWidget::text(t); | ||
} | ||
|
||
void AccessibleSearchBox::searchFinished() | ||
{ | ||
QAccessibleValueChangeEvent ev(searchBox, text(QAccessible::Value)); | ||
QAccessible::updateAccessibility(&ev); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef __SEARCHCOMBOBOX__ | ||
#define __SEARCHCOMBOBOX__ | ||
#include <QAccessibleWidget> | ||
|
||
namespace Ms { | ||
|
||
class SearchComboBox : public QComboBox { | ||
Q_OBJECT | ||
public: | ||
enum SearchType { | ||
SEARCH_MEASURE, | ||
SEARCH_PAGE, | ||
SEARCH_REHEARSAL_MARK, | ||
NO_SEARCH | ||
}; | ||
private: | ||
SearchType _searchType; | ||
bool _found; | ||
void searchInit(); | ||
void setSearchType(SearchType s); | ||
private slots: | ||
void searchTextChanged(const QString& s); | ||
public: | ||
SearchType searchType() { return _searchType; } | ||
bool found() { return _found; } | ||
SearchComboBox(QWidget* p = 0); | ||
signals: | ||
void currentSearchFinished(); | ||
}; | ||
|
||
class AccessibleSearchBox : public QObject, QAccessibleWidget { | ||
Q_OBJECT | ||
SearchComboBox* searchBox; | ||
QAccessible::Role role() const Q_DECL_OVERRIDE { return QAccessible::ComboBox; } | ||
QString text(QAccessible::Text t) const Q_DECL_OVERRIDE; | ||
public: | ||
AccessibleSearchBox(SearchComboBox* comboBox); | ||
static QAccessibleInterface* SearchBoxFactory(const QString &classname, QObject *object); | ||
|
||
public slots: | ||
void searchFinished(); | ||
}; | ||
|
||
} | ||
|
||
#endif |