Logo Search packages:      
Sourcecode: canorus version File versions  Download package

void CAMainWin::onTextEditKeyPressEvent ( QKeyEvent *  e  )  [private, slot]

Function called when user types the text of the syllable or hits control keys.

The following behaviour is implemented:

  • alphanumeric keys are pressed - writes text
  • spacebar is pressed - creates the current syllable and jumps to the next syllable
  • return is pressed - creates the current syllable and hides the syllable edit widget
  • left key is pressed - if cursorPosition()==0, jumps to the previous syllable
  • right key is pressed - if cursorPosition()==length(), same as spacebar
  • escape key is pressed - hides the syllable edit and cancels any changes to syllable

Todo:
GUI for syllable specific associated voice - current is the default lyrics context's one

Definition at line 3220 of file mainwin.cpp.

References CALyricsContext::associatedVoice(), CASyllable::associatedVoice(), CAScoreViewPort::createTextEdit(), CAScoreViewPort::currentContext(), CASyllable::lyricsContext(), CAMark::markType(), CAMusElement::musElementType(), CALyricsContext::next(), CALyricsContext::previous(), CAScoreViewPort::removeTextEdit(), CAScoreViewPort::selection(), CAScoreViewPort::selectMElement(), CASyllable::setHyphenStart(), CASyllable::setMelismaStart(), CASyllable::setText(), and CAScoreViewPort::textEdit().

Referenced by initViewPort().

                                                    {
      if (!currentScoreViewPort()) return;
      CATextEdit *textEdit = static_cast<CATextEdit*>(sender());

      CAScoreViewPort *v = currentScoreViewPort();
      CADrawableContext *dContext = v->currentContext();
      CAMusElement *elt = (v->selection().size()?v->selection().front()->musElement():0);

      if ( elt->musElementType()==CAMusElement::Syllable ) {
            CASyllable *syllable = static_cast<CASyllable*>(elt);

            QString text = textEdit->text().simplified(); // remove any trailing whitespaces

            bool hyphen = false;
            if (text.right(1)=="-") { hyphen = true; text.chop(1); }

            bool melisma = false;
            if (text.right(1)=="_") { melisma = true; text.chop(1); }

            CAVoice *voice = 0; /// \todo GUI for syllable specific associated voice - current is the default lyrics context's one

            CALyricsContext *lc = static_cast<CALyricsContext*>(dContext->context());

            // create or edit syllable
            if ( e->key()==Qt::Key_Space  ||
                 e->key()==Qt::Key_Return ||
                 e->key()==Qt::Key_Right && textEdit->cursorPosition()==textEdit->text().size() ||
                 (e->key()==Qt::Key_Left || e->key()==Qt::Key_Backspace) && textEdit->cursorPosition()==0 ||
                 CACanorus::settings()->finaleLyricsBehaviour() && e->key()==Qt::Key_Minus
            ) {
                  CACanorus::undo()->createUndoCommand( document(), tr("lyrics edit", "undo") );
                  syllable->setText(text);
                  syllable->setHyphenStart(hyphen);
                  syllable->setMelismaStart(melisma);

                  v->removeTextEdit();

                  CAVoice *voice = (syllable->associatedVoice()?syllable->associatedVoice():lc->associatedVoice());
                  CAMusElement *nextSyllable = 0;
                  if (syllable) {
                        if (e->key()==Qt::Key_Space || e->key()==Qt::Key_Right || e->key()==Qt::Key_Return) { // next right note
                              nextSyllable = syllable->lyricsContext()->next(syllable);
                        } else  if (e->key()==Qt::Key_Left || e->key()==Qt::Key_Backspace) {                  // next left note
                              nextSyllable = syllable->lyricsContext()->previous(syllable);
                        } else if (e->key()==Qt::Key_Minus) {
                              syllable->setHyphenStart(true);
                              nextSyllable = syllable->lyricsContext()->next(syllable);
                        }
                        CACanorus::undo()->pushUndoCommand();
                        CACanorus::rebuildUI( document(), currentSheet() );
                        if (nextSyllable) {
                              CADrawableMusElement *dNextSyllable = v->selectMElement(nextSyllable);
                              v->createTextEdit( dNextSyllable );
                              if ( e->key()==Qt::Key_Space || e->key()==Qt::Key_Right || e->key()==Qt::Key_Return )
                                    v->textEdit()->setCursorPosition(0); // go to the beginning if moving to the right next syllable
                        }
                  }
            }
      } else if (elt->musElementType()==CAMusElement::Mark && static_cast<CAMark*>(elt)->markType()==CAMark::Text || static_cast<CAMark*>(elt)->markType()==CAMark::BookMark) {
            if (e->key()==Qt::Key_Return) {
                  CAMark *mark = static_cast<CAMark*>(elt);
                  CACanorus::undo()->createUndoCommand( document(), tr("text edit", "undo") );
                  if (mark->markType()==CAMark::Text) {
                        static_cast<CAText*>(mark)->setText( textEdit->text() );
                  } else if (mark->markType()==CAMark::BookMark) {
                        static_cast<CABookMark*>(mark)->setText( textEdit->text() );
                  }
                  v->removeTextEdit();
                  CACanorus::undo()->pushUndoCommand();
                  CACanorus::rebuildUI( document(), currentSheet() );
            }
      } else {
            v->removeTextEdit();
      }

      // escape key - cancel
      if (e->key()==Qt::Key_Escape) {
            v->removeTextEdit();
      }
}


Generated by  Doxygen 1.6.0   Back to index