void Menu::alignItemsInColumns(fzPoint paddings, fzUInt *sizes, fzUInt nuColumns) { // Calculate total size fzSize size(-paddings.x, 0); Node *node = (Node*)m_children.front(); fzFloat widths[nuColumns]; for(fzUInt i = 0; i < nuColumns; ++i) { fzFloat width = 0; fzFloat height = -paddings.y; for(fzUInt w = 0; w < sizes[i]; ++i) { if(node == NULL) { FZ_ASSERT(false, "Too many items."); return; } width = MAX(width, node->getContentSize().width); height += node->getContentSize().height + paddings.y; node = (Node*)node->next(); } size.width += width + paddings.x; widths[i] = size.width + width/2 + paddings.x; size.height = MAX(height, size.height); } setContentSize(size); fzUInt index = 0; for(fzUInt i = 0; i < nuColumns; ++i) { alignVertically(paddings.y, fzPoint(widths[i], m_contentSize.height/2), fzRange(index, sizes[i])); index += sizes[i]; } }
void Page::LayOutTranscription(bool force) { if (m_layoutDone && !force) { return; } Doc *doc = dynamic_cast<Doc *>(GetParent()); assert(doc); // Doc::SetDrawingPage should have been called before // Make sure we have the correct page assert(this == doc->GetDrawingPage()); // Reset the horizontal alignment Functor resetHorizontalAlignment(&Object::ResetHorizontalAlignment); this->Process(&resetHorizontalAlignment, NULL); // Reset the vertical alignment Functor resetVerticalAlignment(&Object::ResetVerticalAlignment); this->Process(&resetVerticalAlignment, NULL); // Align the content of the page using measure aligners // After this: // - each LayerElement object will have its Alignment pointer initialized Functor alignHorizontally(&Object::AlignHorizontally); Functor alignHorizontallyEnd(&Object::AlignHorizontallyEnd); AlignHorizontallyParams alignHorizontallyParams(&alignHorizontally); this->Process(&alignHorizontally, &alignHorizontallyParams, &alignHorizontallyEnd); // Align the content of the page using system aligners // After this: // - each Staff object will then have its StaffAlignment pointer initialized Functor alignVertically(&Object::AlignVertically); Functor alignVerticallyEnd(&Object::AlignVerticallyEnd); AlignVerticallyParams alignVerticallyParams(doc, &alignVerticallyEnd); this->Process(&alignVertically, &alignVerticallyParams, &alignVerticallyEnd); // Set the pitch / pos alignement SetAlignmentPitchPosParams setAlignmentPitchPosParams(doc); Functor setAlignmentPitchPos(&Object::SetAlignmentPitchPos); this->Process(&setAlignmentPitchPos, &setAlignmentPitchPosParams); CalcStemParams calcStemParams(doc); Functor calcStem(&Object::CalcStem); this->Process(&calcStem, &calcStemParams); FunctorDocParams calcChordNoteHeadsParams(doc); Functor calcChordNoteHeads(&Object::CalcChordNoteHeads); this->Process(&calcChordNoteHeads, &calcChordNoteHeadsParams); CalcDotsParams calcDotsParams(doc); Functor calcDots(&Object::CalcDots); this->Process(&calcDots, &calcDotsParams); // Render it for filling the bounding box View view; view.SetDoc(doc); BBoxDeviceContext bBoxDC(&view, 0, 0, BBOX_HORIZONTAL_ONLY); // Do not do the layout in this view - otherwise we will loop... view.SetPage(this->GetIdx(), false); view.DrawCurrentPage(&bBoxDC, false); Functor adjustXRelForTranscription(&Object::AdjustXRelForTranscription); this->Process(&adjustXRelForTranscription, NULL); FunctorDocParams calcLegerLinesParams(doc); Functor calcLedgerLines(&Object::CalcLedgerLines); this->Process(&calcLedgerLines, &calcLegerLinesParams); m_layoutDone = true; }
void Page::LayOutHorizontally() { Doc *doc = dynamic_cast<Doc *>(GetParent()); assert(doc); // Doc::SetDrawingPage should have been called before // Make sure we have the correct page assert(this == doc->GetDrawingPage()); // Reset the horizontal alignment Functor resetHorizontalAlignment(&Object::ResetHorizontalAlignment); this->Process(&resetHorizontalAlignment, NULL); // Reset the vertical alignment Functor resetVerticalAlignment(&Object::ResetVerticalAlignment); this->Process(&resetVerticalAlignment, NULL); // Align the content of the page using measure aligners // After this: // - each LayerElement object will have its Alignment pointer initialized Functor alignHorizontally(&Object::AlignHorizontally); Functor alignHorizontallyEnd(&Object::AlignHorizontallyEnd); AlignHorizontallyParams alignHorizontallyParams(&alignHorizontally); this->Process(&alignHorizontally, &alignHorizontallyParams, &alignHorizontallyEnd); // Align the content of the page using system aligners // After this: // - each Staff object will then have its StaffAlignment pointer initialized Functor alignVertically(&Object::AlignVertically); Functor alignVerticallyEnd(&Object::AlignVerticallyEnd); AlignVerticallyParams alignVerticallyParams(doc, &alignVerticallyEnd); this->Process(&alignVertically, &alignVerticallyParams, &alignVerticallyEnd); // Unless duration-based spacing is disabled, set the X position of each Alignment. // Does non-linear spacing based on the duration space between two Alignment objects. if (!doc->GetEvenSpacing()) { int longestActualDur = DUR_4; // Get the longest duration in the piece AttDurExtreme durExtremeComparison(LONGEST); Object *longestDur = this->FindChildExtremeByAttComparison(&durExtremeComparison); if (longestDur) { DurationInterface *interface = longestDur->GetDurationInterface(); assert(interface); longestActualDur = interface->GetActualDur(); // LogDebug("Longest duration is DUR_* code %d", longestActualDur); } Functor setAlignmentX(&Object::SetAlignmentXPos); SetAlignmentXPosParams setAlignmentXPosParams(doc, &setAlignmentX); setAlignmentXPosParams.m_longestActualDur = longestActualDur; this->Process(&setAlignmentX, &setAlignmentXPosParams); } // Set the pitch / pos alignement SetAlignmentPitchPosParams setAlignmentPitchPosParams(doc); Functor setAlignmentPitchPos(&Object::SetAlignmentPitchPos); this->Process(&setAlignmentPitchPos, &setAlignmentPitchPosParams); CalcStemParams calcStemParams(doc); Functor calcStem(&Object::CalcStem); this->Process(&calcStem, &calcStemParams); FunctorDocParams calcChordNoteHeadsParams(doc); Functor calcChordNoteHeads(&Object::CalcChordNoteHeads); this->Process(&calcChordNoteHeads, &calcChordNoteHeadsParams); CalcDotsParams calcDotsParams(doc); Functor calcDots(&Object::CalcDots); this->Process(&calcDots, &calcDotsParams); // Render it for filling the bounding box View view; view.SetDoc(doc); BBoxDeviceContext bBoxDC(&view, 0, 0, BBOX_HORIZONTAL_ONLY); // Do not do the layout in this view - otherwise we will loop... view.SetPage(this->GetIdx(), false); view.DrawCurrentPage(&bBoxDC, false); // Adjust the x position of the LayerElement where multiple layer collide // Look at each LayerElement and change the m_xShift if the bounding box is overlapping Functor adjustLayers(&Object::AdjustLayers); AdjustLayersParams adjustLayersParams(doc, &adjustLayers, doc->m_scoreDef.GetStaffNs()); this->Process(&adjustLayers, &adjustLayersParams); // Adjust the X position of the accidentals, including in chords Functor adjustAccidX(&Object::AdjustAccidX); AdjustAccidXParams adjustAccidXParams(doc, &adjustAccidX); this->Process(&adjustAccidX, &adjustAccidXParams); // Adjust the X shift of the Alignment looking at the bounding boxes // Look at each LayerElement and change the m_xShift if the bounding box is overlapping Functor adjustXPos(&Object::AdjustXPos); Functor adjustXPosEnd(&Object::AdjustXPosEnd); AdjustXPosParams adjustXPosParams(doc, &adjustXPos, &adjustXPosEnd, doc->m_scoreDef.GetStaffNs()); this->Process(&adjustXPos, &adjustXPosParams, &adjustXPosEnd); // Adjust the X shift of the Alignment looking at the bounding boxes // Look at each LayerElement and change the m_xShift if the bounding box is overlapping Functor adjustGraceXPos(&Object::AdjustGraceXPos); Functor adjustGraceXPosEnd(&Object::AdjustGraceXPosEnd); AdjustGraceXPosParams adjustGraceXPosParams( doc, &adjustGraceXPos, &adjustGraceXPosEnd, doc->m_scoreDef.GetStaffNs()); this->Process(&adjustGraceXPos, &adjustGraceXPosParams, &adjustGraceXPosEnd); // We need to populate processing lists for processing the document by Layer (for matching @tie) and // by Verse (for matching syllable connectors) PrepareProcessingListsParams prepareProcessingListsParams; Functor prepareProcessingLists(&Object::PrepareProcessingLists); this->Process(&prepareProcessingLists, &prepareProcessingListsParams); this->AdjustSylSpacingByVerse(prepareProcessingListsParams, doc); // Adjust measure X position AlignMeasuresParams alignMeasuresParams; Functor alignMeasures(&Object::AlignMeasures); Functor alignMeasuresEnd(&Object::AlignMeasuresEnd); this->Process(&alignMeasures, &alignMeasuresParams, &alignMeasuresEnd); }
void Page::LayOutVertically() { Doc *doc = dynamic_cast<Doc *>(GetParent()); assert(doc); // Doc::SetDrawingPage should have been called before // Make sure we have the correct page assert(this == doc->GetDrawingPage()); // Reset the vertical alignment Functor resetVerticalAlignment(&Object::ResetVerticalAlignment); this->Process(&resetVerticalAlignment, NULL); FunctorDocParams calcLegerLinesParams(doc); Functor calcLedgerLines(&Object::CalcLedgerLines); this->Process(&calcLedgerLines, &calcLegerLinesParams); // Align the content of the page using system aligners // After this: // - each Staff object will then have its StaffAlignment pointer initialized Functor alignVertically(&Object::AlignVertically); Functor alignVerticallyEnd(&Object::AlignVerticallyEnd); AlignVerticallyParams alignVerticallyParams(doc, &alignVerticallyEnd); this->Process(&alignVertically, &alignVerticallyParams, &alignVerticallyEnd); // Adjust the position of outside articulations FunctorDocParams calcArticParams(doc); Functor calcArtic(&Object::CalcArtic); this->Process(&calcArtic, &calcArticParams); // Render it for filling the bounding box View view; BBoxDeviceContext bBoxDC(&view, 0, 0); view.SetDoc(doc); // Do not do the layout in this view - otherwise we will loop... view.SetPage(this->GetIdx(), false); view.DrawCurrentPage(&bBoxDC, false); // Adjust the position of outside articulations with slurs end and start positions FunctorDocParams adjustArticWithSlursParams(doc); Functor adjustArticWithSlurs(&Object::AdjustArticWithSlurs); this->Process(&adjustArticWithSlurs, &adjustArticWithSlursParams); // Fill the arrays of bounding boxes (above and below) for each staff alignment for which the box overflows. SetOverflowBBoxesParams setOverflowBBoxesParams(doc); Functor setOverflowBBoxes(&Object::SetOverflowBBoxes); Functor setOverflowBBoxesEnd(&Object::SetOverflowBBoxesEnd); this->Process(&setOverflowBBoxes, &setOverflowBBoxesParams, &setOverflowBBoxesEnd); // Adjust the positioners of floationg elements (slurs, hairpin, dynam, etc) Functor adjustFloatingPostioners(&Object::AdjustFloatingPostioners); AdjustFloatingPostionersParams adjustFloatingPostionersParams(doc, &adjustFloatingPostioners); this->Process(&adjustFloatingPostioners, &adjustFloatingPostionersParams); // Adjust the overlap of the staff aligmnents by looking at the overflow bounding boxes params.clear(); Functor adjustStaffOverlap(&Object::AdjustStaffOverlap); AdjustStaffOverlapParams adjustStaffOverlapParams(&adjustStaffOverlap); this->Process(&adjustStaffOverlap, &adjustStaffOverlapParams); // Set the Y position of each StaffAlignment // Adjust the Y shift to make sure there is a minimal space (staffMargin) between each staff Functor adjustYPos(&Object::AdjustYPos); AdjustYPosParams adjustYPosParams(doc, &adjustYPos); this->Process(&adjustYPos, &adjustYPosParams); // Adjust system Y position AlignSystemsParams alignSystemsParams; alignSystemsParams.m_shift = doc->m_drawingPageHeight - doc->m_drawingPageTopMar; alignSystemsParams.m_systemMargin = (doc->GetSpacingSystem()) * doc->GetDrawingUnit(100); Functor alignSystems(&Object::AlignSystems); this->Process(&alignSystems, &alignSystemsParams); }
//BEGIN class ItemView ItemView::ItemView(ItemDocument * itemDocument, ViewContainer *viewContainer, uint viewAreaId, const char *name) : View(itemDocument, viewContainer, viewAreaId, name) { KActionCollection * ac = actionCollection(); KStdAction::selectAll(itemDocument, SLOT(selectAll()), ac); KStdAction::zoomIn(this, SLOT(zoomIn()), ac); KStdAction::zoomOut(this, SLOT(zoomOut()), ac); KStdAction::actualSize(this, SLOT(actualSize()), ac)->setEnabled(false); KAccel *pAccel = new KAccel(this); pAccel->insert("Cancel", i18n("Cancel"), i18n("Cancel the current operation"), Qt::Key_Escape, itemDocument, SLOT(cancelCurrentOperation())); pAccel->readSettings(); new KAction(i18n("Delete"), "editdelete", Qt::Key_Delete, itemDocument, SLOT(deleteSelection()), ac, "edit_delete"); new KAction(i18n("Export as Image..."), 0, 0, itemDocument, SLOT(exportToImage()), ac, "file_export_image"); //BEGIN Item Alignment actions new KAction(i18n("Align Horizontally"), 0, 0, itemDocument, SLOT(alignHorizontally()), ac, "align_horizontally"); new KAction(i18n("Align Vertically"), 0, 0, itemDocument, SLOT(alignVertically()), ac, "align_vertically"); new KAction(i18n("Distribute Horizontally"), 0, 0, itemDocument, SLOT(distributeHorizontally()), ac, "distribute_horizontally"); new KAction(i18n("Distribute Vertically"), 0, 0, itemDocument, SLOT(distributeVertically()), ac, "distribute_vertically"); //END Item Alignment actions //BEGIN Draw actions KToolBarPopupAction * pa = new KToolBarPopupAction(i18n("Draw"), "paintbrush", 0, 0, 0, ac, "edit_draw"); pa->setDelayed(false); KPopupMenu * m = pa->popupMenu(); m->insertTitle(i18n("Draw")); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_text", KIcon::Small), i18n("Text"), DrawPart::da_text); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_line", KIcon::Small), i18n("Line"), DrawPart::da_line); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_arrow", KIcon::Small), i18n("Arrow"), DrawPart::da_arrow); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_ellipse", KIcon::Small), i18n("Ellipse"), DrawPart::da_ellipse); m->insertItem(KGlobal::iconLoader()->loadIcon("tool_rectangle", KIcon::Small), i18n("Rectangle"), DrawPart::da_rectangle); m->insertItem(KGlobal::iconLoader()->loadIcon("imagegallery", KIcon::Small), i18n("Image"), DrawPart::da_image); connect(m, SIGNAL(activated(int)), itemDocument, SLOT(slotSetDrawAction(int))); //END Draw actions //BEGIN Item Control actions new KAction(i18n("Raise Selection"), "bring_forward", Qt::Key_PageUp, itemDocument, SLOT(raiseZ()), ac, "edit_raise"); new KAction(i18n("Lower Selection"), "send_backward", Qt::Key_PageDown, itemDocument, SLOT(lowerZ()), ac, "edit_lower"); //END Item Control actions KAction * na = new KAction("", 0, 0, 0, 0, ac, "null_action"); na->setEnabled(false); setXMLFile("ktechlabitemviewui.rc"); m_pUpdateStatusTmr = new QTimer(this); connect(m_pUpdateStatusTmr, SIGNAL(timeout()), this, SLOT(updateStatus())); connect(this, SIGNAL(unfocused()), this, SLOT(stopUpdatingStatus())); m_pDragItem = 0l; p_itemDocument = itemDocument; m_zoomLevel = 1.; m_CVBEditor = new CVBEditor(p_itemDocument->canvas(), this, "cvbEditor"); m_CVBEditor->setLineWidth(1); connect(m_CVBEditor, SIGNAL(horizontalSliderReleased()), itemDocument, SLOT(requestCanvasResize())); connect(m_CVBEditor, SIGNAL(verticalSliderReleased()), itemDocument, SLOT(requestCanvasResize())); m_layout->insertWidget(0, m_CVBEditor); setAcceptDrops(true); setFocusWidget(m_CVBEditor->viewport()); }