File: searchComboBox.cpp

package info (click to toggle)
musescore 2.0.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 202,532 kB
  • ctags: 58,769
  • sloc: cpp: 257,595; xml: 172,226; ansic: 139,931; python: 6,565; sh: 6,383; perl: 423; makefile: 290; awk: 142; pascal: 67; sed: 3
file content (117 lines) | stat: -rw-r--r-- 3,989 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);
      }

}