📄 notationview.cpp
字号:
m_properties, this)), m_vlayout(new NotationVLayout(&doc->getComposition(), m_notePixmapFactory, m_properties, this)), m_chordNameRuler(0), m_tempoRuler(0), m_rawNoteRuler(0), m_annotationsVisible(false), m_lilypondDirectivesVisible(false), m_selectDefaultNote(0), m_fontCombo(0), m_fontSizeCombo(0), m_spacingCombo(0), m_fontSizeActionMenu(0), m_pannerDialog(0), m_renderTimer(0), m_playTracking(false), m_progressDisplayer(PROGRESS_NONE), m_inhibitRefresh(true), m_ok(false), m_printMode(true), m_printSize(8) // set in positionStaffs{ assert(segments.size() > 0); NOTATION_DEBUG << "NotationView print ctor" << endl; // Initialise the display-related defaults that will be needed // by both the actions and the layout toolbar m_config->setGroup(NotationViewConfigGroup); if (referenceView) { m_fontName = referenceView->m_fontName; } else { m_fontName = qstrtostr(m_config->readEntry ("notefont", strtoqstr(NoteFontFactory::getDefaultFontName()))); } // Force largest font size std::vector<int> sizes = NoteFontFactory::getAllSizes(m_fontName); m_fontSize = sizes[sizes.size() - 1]; if (referenceView) { m_hlayout->setSpacing(referenceView->m_hlayout->getSpacing()); m_hlayout->setProportion(referenceView->m_hlayout->getProportion()); } else { int defaultSpacing = m_config->readNumEntry("spacing", 100); m_hlayout->setSpacing(defaultSpacing); int defaultProportion = m_config->readNumEntry("proportion", 60); m_hlayout->setProportion(defaultProportion); } delete m_notePixmapFactory; m_notePixmapFactory = new NotePixmapFactory(m_fontName, m_fontSize); m_hlayout->setNotePixmapFactory(m_notePixmapFactory); m_vlayout->setNotePixmapFactory(m_notePixmapFactory); setBackgroundMode(PaletteBase); m_config->setGroup(NotationViewConfigGroup); QCanvas *tCanvas = new QCanvas(this); tCanvas->resize(width() * 2, height() * 2); //!!! setCanvasView(new NotationCanvasView(*this, tCanvas, getCentralWidget())); canvas()->retune(128); // tune for larger canvas for (unsigned int i = 0; i < segments.size(); ++i) { m_staffs.push_back(new NotationStaff(canvas(), segments[i], 0, // snap i, this, m_fontName, m_fontSize)); } m_currentStaff = 0; m_staffs[0]->setCurrent(true); ProgressDialog* progressDlg = 0; if (parent) { ProgressDialog::processEvents(); NOTATION_DEBUG << "NotationView : setting up progress dialog" << endl; progressDlg = new ProgressDialog(i18n("Preparing to print..."), 100, parent); progressDlg->setAutoClose(false); progressDlg->setAutoReset(true); progressDlg->setMinimumDuration(1000); setupProgress(progressDlg); m_progressDisplayer = PROGRESS_DIALOG; } try { setPageMode(LinedStaff::MultiPageMode); // also positions and renders the staffs! for (unsigned int i = 0; i < m_staffs.size(); ++i) { m_staffs[i]->getSegment().getRefreshStatus (m_segmentsRefreshStatusIds[i]).setNeedsRefresh(false); } m_ok = true; } catch (ProgressReporter::Cancelled c) { // when cancelled, m_ok is false -- checked by calling method NOTATION_DEBUG << "NotationView ctor : layout Cancelled" << endl; } NOTATION_DEBUG << "NotationView ctor : m_ok = " << m_ok << endl; delete progressDlg; if (!isOK()) { setOutOfCtor(); return ; // In case more code is added there later } setOutOfCtor(); // keep this as last call in the ctor}NotationView::~NotationView(){ NOTATION_DEBUG << "-> ~NotationView()" << endl; if (!m_printMode && m_ok) slotSaveOptions(); delete m_chordNameRuler; delete m_renderTimer; for (unsigned int i = 0; i < m_staffs.size(); ++i) { for (Segment::iterator j = m_staffs[i]->getSegment().begin(); j != m_staffs[i]->getSegment().end(); ++j) { removeViewLocalProperties(*j); } delete m_staffs[i]; // this will erase all "notes" canvas items } PixmapArrayGC::deleteAll(); Profiles::getInstance()->dump(); NOTATION_DEBUG << "<- ~NotationView()" << endl;}voidNotationView::removeViewLocalProperties(Event *e){ Event::PropertyNames names(e->getPropertyNames()); std::string prefix(getViewLocalPropertyPrefix()); for (Event::PropertyNames::iterator i = names.begin(); i != names.end(); ++i) { if (i->getName().substr(0, prefix.size()) == prefix) { e->unset(*i); } }}const NotationProperties &NotationView::getProperties() const{ return m_properties;}void NotationView::positionStaffs(){ NOTATION_DEBUG << "NotationView::positionStaffs" << endl; m_config->setGroup(NotationViewConfigGroup); m_printSize = m_config->readUnsignedNumEntry("printingnotesize", 5); int minTrack = 0, maxTrack = 0; bool haveMinTrack = false; typedef std::map<int, int> TrackIntMap; TrackIntMap trackHeights; TrackIntMap trackCoords; int pageWidth, pageHeight, leftMargin, topMargin; pageWidth = getPageWidth(); pageHeight = getPageHeight(); leftMargin = 0, topMargin = 0; getPageMargins(leftMargin, topMargin); int accumulatedHeight; int rowsPerPage = 1; int legerLines = 8; if (m_pageMode != LinedStaff::LinearMode) legerLines = 7; int rowGapPercent = (m_staffs.size() > 1 ? 40 : 10); int aimFor = -1; bool done = false; int titleHeight = 0; if (m_title) delete m_title; if (m_subtitle) delete m_subtitle; if (m_composer) delete m_composer; if (m_copyright) delete m_copyright; m_title = m_subtitle = m_composer = m_copyright = 0; if (m_pageMode == LinedStaff::MultiPageMode) { const Configuration &metadata = getDocument()->getComposition().getMetadata(); QFont defaultFont(NotePixmapFactory::defaultSerifFontFamily); m_config->setGroup(NotationViewConfigGroup); QFont font = m_config->readFontEntry("textfont", &defaultFont); font.setPixelSize(m_fontSize * 5); QFontMetrics metrics(font); if (metadata.has(CompositionMetadataKeys::Title)) { QString title(strtoqstr(metadata.get<String> (CompositionMetadataKeys::Title))); m_title = new QCanvasText(title, font, canvas()); m_title->setX(m_leftGutter + pageWidth / 2 - metrics.width(title) / 2); m_title->setY(20 + topMargin / 4 + metrics.ascent()); m_title->show(); titleHeight += metrics.height() * 3 / 2 + topMargin / 4; } font.setPixelSize(m_fontSize * 3); metrics = QFontMetrics(font); if (metadata.has(CompositionMetadataKeys::Subtitle)) { QString subtitle(strtoqstr(metadata.get<String> (CompositionMetadataKeys::Subtitle))); m_subtitle = new QCanvasText(subtitle, font, canvas()); m_subtitle->setX(m_leftGutter + pageWidth / 2 - metrics.width(subtitle) / 2); m_subtitle->setY(20 + titleHeight + metrics.ascent()); m_subtitle->show(); titleHeight += metrics.height() * 3 / 2; } if (metadata.has(CompositionMetadataKeys::Composer)) { QString composer(strtoqstr(metadata.get<String> (CompositionMetadataKeys::Composer))); m_composer = new QCanvasText(composer, font, canvas()); m_composer->setX(m_leftGutter + pageWidth - metrics.width(composer) - leftMargin); m_composer->setY(20 + titleHeight + metrics.ascent()); m_composer->show(); titleHeight += metrics.height() * 3 / 2; } font.setPixelSize(m_fontSize * 2); metrics = QFontMetrics(font); if (metadata.has(CompositionMetadataKeys::Copyright)) { QString copyright(strtoqstr(metadata.get<String> (CompositionMetadataKeys::Copyright))); m_copyright = new QCanvasText(copyright, font, canvas()); m_copyright->setX(m_leftGutter + leftMargin); m_copyright->setY(20 + pageHeight - topMargin - metrics.descent()); m_copyright->show(); } } while (1) { accumulatedHeight = 0; int maxTrackHeight = 0; trackHeights.clear(); for (unsigned int i = 0; i < m_staffs.size(); ++i) { m_staffs[i]->setLegerLineCount(legerLines); int height = m_staffs[i]->getHeightOfRow(); TrackId trackId = m_staffs[i]->getSegment().getTrack(); Track *track = m_staffs[i]->getSegment().getComposition()-> getTrackById(trackId); if (!track) continue; // This Should Not Happen, My Friend int trackPosition = track->getPosition(); TrackIntMap::iterator hi = trackHeights.find(trackPosition); if (hi == trackHeights.end()) { trackHeights.insert(TrackIntMap::value_type (trackPosition, height)); } else if (height > hi->second) { hi->second = height; } if (height > maxTrackHeight) maxTrackHeight = height; if (trackPosition < minTrack || !haveMinTrack) { minTrack = trackPosition; haveMinTrack = true; } if (trackPosition > maxTrack) { maxTrack = trackPosition; } } for (int i = minTrack; i <= maxTrack; ++i) { TrackIntMap::iterator hi = trackHeights.find(i); if (hi != trackHeights.end()) { trackCoords[i] = accumulatedHeight; accumulatedHeight += hi->second; } } accumulatedHeight += maxTrackHeight * rowGapPercent / 100; if (done) break; if (m_pageMode != LinedStaff::MultiPageMode) { rowsPerPage = 0; done = true; break; } else { // Check how well all this stuff actually fits on the // page. If things don't fit as well as we'd like, modify // at most one parameter so as to save some space, then // loop around again and see if it worked. This iterative // approach is inefficient but the time spent here is // neglible in context, and it's a simple way to code it. int staffPageHeight = pageHeight - topMargin * 2 - titleHeight; rowsPerPage = staffPageHeight / accumulatedHeight; if (rowsPerPage < 1) { if (legerLines > 5) --legerLines; else if (rowGapPercent > 20) rowGapPercent -= 10; else if (legerLines > 4) --legerLines; else if (rowGapPercent > 0) rowGapPercent -= 10; else if (legerLines > 3) --legerLines; else if (m_printSize > 3) --m_printSize; else { // just accept that we'll have to overflow rowsPerPage = 1; done = true; } } else { if (aimFor == rowsPerPage) { titleHeight += (staffPageHeight - (rowsPerPage * accumulatedHeight)) / 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -