📄 compositionview.cpp
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//* Rosegarden A MIDI and audio sequencer and musical notation editor. This program is Copyright 2000-2007 Guillaume Laurent <glaurent@telegraph-road.org>, Chris Cannam <cannam@all-day-breakfast.com>, Richard Bown <richard.bown@ferventsoftware.com> The moral rights of Guillaume Laurent, Chris Cannam, and Richard Bown to claim authorship of this work have been asserted. Other copyrights also apply to some parts of this work. Please see the AUTHORS file and individual file headers for details. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information.*/#include "CompositionView.h"#include "misc/Debug.h"#include "AudioPreviewThread.h"#include "base/RulerScale.h"#include "base/Segment.h"#include "base/Selection.h"#include "base/SnapGrid.h"#include "CompositionColourCache.h"#include "CompositionItemHelper.h"#include "CompositionItemImpl.h"#include "CompositionModel.h"#include "CompositionModelImpl.h"#include "CompositionRect.h"#include "AudioPreviewPainter.h"#include "document/RosegardenGUIDoc.h"#include "document/ConfigGroups.h"#include "gui/general/GUIPalette.h"#include "gui/general/RosegardenCanvasView.h"#include "gui/general/RosegardenScrollView.h"#include "SegmentSelector.h"#include "SegmentToolBox.h"#include "SegmentTool.h"#include <kmessagebox.h>#include <qbrush.h>#include <qcolor.h>#include <qevent.h>#include <qfont.h>#include <qfontmetrics.h>#include <qmemarray.h>#include <qpainter.h>#include <qpen.h>#include <qpixmap.h>#include <qpoint.h>#include <qrect.h>#include <qscrollbar.h>#include <qscrollview.h>#include <qsize.h>#include <qstring.h>#include <qwidget.h>#include <kapplication.h>#include <kconfig.h>#include <algorithm>namespace Rosegarden{class PreviewRect : public QRect {public: PreviewRect(int left, int top, int width, int height) : QRect(left, top, width, height) {}; PreviewRect(const QRect& r) : QRect(r) {}; const QColor& getColor() const { return m_color; } void setColor(QColor c) { m_color = c; }protected: QColor m_color;};CompositionView::CompositionView(RosegardenGUIDoc* doc, CompositionModel* model, QWidget * parent, const char * name, WFlags f)#if KDE_VERSION >= KDE_MAKE_VERSION(3,2,0) : RosegardenScrollView(parent, name, f | WNoAutoErase | WStaticContents),#else : RosegardenScrollView(parent, name, f | WRepaintNoErase | WResizeNoErase | WStaticContents),#endif m_model(model), m_currentItem(0), m_tool(0), m_toolBox(0), m_showPreviews(false), m_showSegmentLabels(true), m_fineGrain(false), m_minWidth(m_model->getLength()), m_stepSize(0), m_rectFill(0xF0, 0xF0, 0xF0), m_selectedRectFill(0x00, 0x00, 0xF0), m_pointerPos(0), m_pointerColor(GUIPalette::getColour(GUIPalette::Pointer)), m_pointerWidth(4), m_pointerPen(QPen(m_pointerColor, m_pointerWidth)), m_tmpRect(QRect(QPoint(0, 0), QPoint( -1, -1))), m_tmpRectFill(CompositionRect::DefaultBrushColor), m_drawGuides(false), m_guideColor(GUIPalette::getColour(GUIPalette::MovementGuide)), m_topGuidePos(0), m_foreGuidePos(0), m_drawSelectionRect(false), m_drawTextFloat(false), m_segmentsDrawBuffer(visibleWidth(), visibleHeight()), m_artifactsDrawBuffer(visibleWidth(), visibleHeight()), m_segmentsDrawBufferRefresh(0, 0, visibleWidth(), visibleHeight()), m_artifactsDrawBufferRefresh(0, 0, visibleWidth(), visibleHeight()), m_lastBufferRefreshX(0), m_lastBufferRefreshY(0), m_lastPointerRefreshX(0), m_contextHelpShown(false){ if (doc) { m_toolBox = new SegmentToolBox(this, doc); connect(m_toolBox, SIGNAL(showContextHelp(const QString &)), this, SLOT(slotToolHelpChanged(const QString &))); } setDragAutoScroll(true); setBackgroundMode(NoBackground); viewport()->setBackgroundMode(NoBackground); viewport()->setPaletteBackgroundColor(GUIPalette::getColour(GUIPalette::SegmentCanvas)); slotUpdateSize(); QScrollBar* hsb = horizontalScrollBar(); // dynamically adjust content size when scrolling past current composition's end connect(hsb, SIGNAL(nextLine()), this, SLOT(scrollRight())); connect(hsb, SIGNAL(prevLine()), this, SLOT(scrollLeft())); // connect(this, SIGNAL(contentsMoving(int, int)), // this, SLOT(slotAllDrawBuffersNeedRefresh())); // connect(this, SIGNAL(contentsMoving(int, int)), // this, SLOT(slotContentsMoving(int, int))); connect(model, SIGNAL(needContentUpdate()), this, SLOT(slotUpdateSegmentsDrawBuffer())); connect(model, SIGNAL(needContentUpdate(const QRect&)), this, SLOT(slotUpdateSegmentsDrawBuffer(const QRect&))); connect(model, SIGNAL(needArtifactsUpdate()), this, SLOT(slotArtifactsDrawBufferNeedsRefresh())); connect(model, SIGNAL(needSizeUpdate()), this, SLOT(slotUpdateSize())); if (doc) { connect(doc, SIGNAL(docColoursChanged()), this, SLOT(slotRefreshColourCache())); // recording-related signals connect(doc, SIGNAL(newMIDIRecordingSegment(Segment*)), this, SLOT(slotNewMIDIRecordingSegment(Segment*))); connect(doc, SIGNAL(newAudioRecordingSegment(Segment*)), this, SLOT(slotNewAudioRecordingSegment(Segment*))); // connect(doc, SIGNAL(recordMIDISegmentUpdated(Segment*, timeT)), // this, SLOT(slotRecordMIDISegmentUpdated(Segment*, timeT))); connect(doc, SIGNAL(stoppedAudioRecording()), this, SLOT(slotStoppedRecording())); connect(doc, SIGNAL(stoppedMIDIRecording()), this, SLOT(slotStoppedRecording())); connect(doc, SIGNAL(audioFileFinalized(Segment*)), getModel(), SLOT(slotAudioFileFinalized(Segment*))); } CompositionModelImpl* cmi = dynamic_cast<CompositionModelImpl*>(model); if (cmi) { cmi->setAudioPreviewThread(&doc->getAudioPreviewThread()); } if (doc) { doc->getAudioPreviewThread().setEmptyQueueListener(this); } m_segmentsDrawBuffer.setOptimization(QPixmap::BestOptim); m_artifactsDrawBuffer.setOptimization(QPixmap::BestOptim); viewport()->setMouseTracking(true);}void CompositionView::endAudioPreviewGeneration(){ CompositionModelImpl* cmi = dynamic_cast<CompositionModelImpl*>(m_model); if (cmi) { cmi->setAudioPreviewThread(0); }}void CompositionView::setBackgroundPixmap(const QPixmap &m){ m_backgroundPixmap = m; // viewport()->setErasePixmap(m_backgroundPixmap);}void CompositionView::initStepSize(){ QScrollBar* hsb = horizontalScrollBar(); m_stepSize = hsb->lineStep();}void CompositionView::slotUpdateSize(){ int vStep = getModel()->grid().getYSnap(); int height = std::max(getModel()->getNbRows() * vStep, (unsigned)visibleHeight()); RulerScale *ruler = grid().getRulerScale(); int minWidth = sizeHint().width(); int computedWidth = int(nearbyint(ruler->getTotalWidth())); int width = std::max(computedWidth, minWidth); resizeContents(width, height);}void CompositionView::scrollRight(){ RG_DEBUG << "CompositionView::scrollRight()\n"; if (m_stepSize == 0) initStepSize(); if (horizontalScrollBar()->value() == horizontalScrollBar()->maxValue()) { resizeContents(contentsWidth() + m_stepSize, contentsHeight()); setContentsPos(contentsX() + m_stepSize, contentsY()); getModel()->setLength(contentsWidth()); }}void CompositionView::scrollLeft(){ RG_DEBUG << "CompositionView::scrollLeft()\n"; if (m_stepSize == 0) initStepSize(); int cWidth = contentsWidth(); if (horizontalScrollBar()->value() < cWidth && cWidth > m_minWidth) { resizeContents(cWidth - m_stepSize, contentsHeight()); getModel()->setLength(contentsWidth()); }}void CompositionView::setSelectionRectPos(const QPoint& pos){ m_selectionRect.setRect(pos.x(), pos.y(), 0, 0); getModel()->setSelectionRect(m_selectionRect);}void CompositionView::setSelectionRectSize(int w, int h){ m_selectionRect.setSize(QSize(w, h)); getModel()->setSelectionRect(m_selectionRect);}void CompositionView::setDrawSelectionRect(bool d){ if (m_drawSelectionRect != d) { m_drawSelectionRect = d; slotArtifactsDrawBufferNeedsRefresh(); slotUpdateSegmentsDrawBuffer(m_selectionRect); }}void CompositionView::clearSegmentRectsCache(bool clearPreviews){ dynamic_cast<CompositionModelImpl*>(getModel())->clearSegmentRectsCache(clearPreviews);}SegmentSelectionCompositionView::getSelectedSegments(){ return (dynamic_cast<CompositionModelImpl*>(m_model))->getSelectedSegments();}void CompositionView::updateSelectionContents(){ if (!haveSelection()) return ; QRect selectionRect = getModel()->getSelectionContentsRect(); updateContents(selectionRect);}void CompositionView::slotContentsMoving(int x, int y){ // qDebug("contents moving : x=%d", x);}void CompositionView::slotSetTool(const QString& toolName){ RG_DEBUG << "CompositionView::slotSetTool(" << toolName << ")" << this << "\n"; if (m_tool) m_tool->stow(); m_toolContextHelp = ""; m_tool = m_toolBox->getTool(toolName); if (m_tool) m_tool->ready(); else { KMessageBox::error(0, QString("CompositionView::slotSetTool() : unknown tool name %1").arg(toolName)); }}void CompositionView::slotSelectSegments(const SegmentSelection &segments){ RG_DEBUG << "CompositionView::slotSelectSegments\n"; static QRect dummy; getModel()->clearSelected(); for (SegmentSelection::iterator i = segments.begin(); i != segments.end(); ++i) { getModel()->setSelected(CompositionItem(new CompositionItemImpl(**i, dummy))); } slotUpdateSegmentsDrawBuffer();}SegmentSelector*CompositionView::getSegmentSelectorTool(){ return dynamic_cast<SegmentSelector*>(getToolBox()->getTool(SegmentSelector::ToolName));}void CompositionView::slotSetSelectAdd(bool value){ SegmentSelector* selTool = getSegmentSelectorTool(); if (!selTool) return ; selTool->setSegmentAdd(value);}void CompositionView::slotSetSelectCopy(bool value){ SegmentSelector* selTool = getSegmentSelectorTool(); if (!selTool) return ; selTool->setSegmentCopy(value);}void CompositionView::slotShowSplitLine(int x, int y){ m_splitLinePos.setX(x); m_splitLinePos.setY(y);}void CompositionView::slotHideSplitLine(){ m_splitLinePos.setX( -1); m_splitLinePos.setY( -1);}void CompositionView::slotExternalWheelEvent(QWheelEvent* e){ e->accept();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -