📄 temporuler.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 "TempoRuler.h"#include <klocale.h>#include <kstddirs.h>#include "misc/Debug.h"#include "base/Composition.h"#include "base/NotationTypes.h"#include "base/RealTime.h"#include "base/RulerScale.h"#include "base/SnapGrid.h"#include "document/RosegardenGUIDoc.h"#include "document/MultiViewCommandHistory.h"#include "gui/application/RosegardenGUIApp.h"#include "gui/dialogs/TempoDialog.h"#include "gui/general/GUIPalette.h"#include "gui/widgets/TextFloat.h"#include "TempoColour.h"#include <kaction.h>#include <kglobal.h>#include <kxmlguiclient.h>#include <kxmlguifactory.h>#include <qcolor.h>#include <qcursor.h>#include <qevent.h>#include <qfont.h>#include <qfontmetrics.h>#include <qiconset.h>#include <qobject.h>#include <qpainter.h>#include <qpixmap.h>#include <qpoint.h>#include <qpopupmenu.h>#include <qrect.h>#include <qsize.h>#include <qstring.h>#include <qwidget.h>namespace Rosegarden{TempoRuler::TempoRuler(RulerScale *rulerScale, RosegardenGUIDoc *doc, KMainWindow *parentMainWindow, double xorigin, int height, bool small, QWidget *parent, const char *name) : QWidget(parent, name), m_xorigin(xorigin), m_height(height), m_currentXOffset(0), m_width( -1), m_small(small), m_illuminate( -1), m_illuminatePoint(false), m_illuminateTarget(false), m_refreshLinesOnly(false), m_dragVert(false), m_dragTarget(false), m_dragHoriz(false), m_dragStartY(0), m_dragStartX(0), m_dragFine(false), m_clickX(0), m_dragStartTempo( -1), m_dragStartTarget( -1), m_dragOriginalTempo( -1), m_dragOriginalTarget( -1), m_composition(&doc->getComposition()), m_rulerScale(rulerScale), m_menu(0), m_parentMainWindow(parentMainWindow), m_fontMetrics(m_boldFont){ // m_font.setPointSize(m_small ? 9 : 11); // m_boldFont.setPointSize(m_small ? 9 : 11); // m_font.setPixelSize(m_height * 2 / 3); // m_boldFont.setPixelSize(m_height * 2 / 3); m_font.setPixelSize(m_height / 3); m_boldFont.setPixelSize(m_height * 2 / 5); m_boldFont.setBold(true); m_fontMetrics = QFontMetrics(m_boldFont); m_textFloat = new TextFloat(this); m_textFloat->hide(); // setBackgroundColor(GUIPalette::getColour(GUIPalette::TextRulerBackground)); setBackgroundMode(Qt::NoBackground); QObject::connect (doc->getCommandHistory(), SIGNAL(commandExecuted()), this, SLOT(update())); QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/"); QIconSet icon; icon = QIconSet(QPixmap(pixmapDir + "/toolbar/event-insert-tempo.png")); new KAction(i18n("Insert Tempo Change"), icon, 0, this, SLOT(slotInsertTempoHere()), actionCollection(), "insert_tempo_here"); new KAction(i18n("Insert Tempo Change at Playback Position"), 0, 0, this, SLOT(slotInsertTempoAtPointer()), actionCollection(), "insert_tempo_at_pointer"); icon = QIconSet(QPixmap(pixmapDir + "/toolbar/event-delete.png")); new KAction(i18n("Delete Tempo Change"), icon, 0, this, SLOT(slotDeleteTempoChange()), actionCollection(), "delete_tempo"); new KAction(i18n("Ramp Tempo to Next Tempo"), 0, 0, this, SLOT(slotRampToNext()), actionCollection(), "ramp_to_next"); new KAction(i18n("Un-Ramp Tempo"), 0, 0, this, SLOT(slotUnramp()), actionCollection(), "unramp"); icon = QIconSet(QPixmap(pixmapDir + "/toolbar/event-edit.png")); new KAction(i18n("Edit Tempo..."), icon, 0, this, SLOT(slotEditTempo()), actionCollection(), "edit_tempo"); new KAction(i18n("Edit Time Signature..."), 0, 0, this, SLOT(slotEditTimeSignature()), actionCollection(), "edit_time_signature"); new KAction(i18n("Open Tempo and Time Signature Editor"), 0, 0, this, SLOT(slotEditTempos()), actionCollection(), "edit_tempos"); setMouseTracking(false);}TempoRuler::~TempoRuler(){ // we have to do this so that the menu is re-created properly // when the main window is itself recreated (on a File->New for instance) KXMLGUIFactory* factory = m_parentMainWindow->factory(); if (factory) factory->removeClient(this);}voidTempoRuler::connectSignals(){ connect(this, SIGNAL(doubleClicked(timeT)), RosegardenGUIApp::self(), SLOT(slotEditTempos(timeT))); connect(this, SIGNAL(changeTempo(timeT, tempoT, tempoT, TempoDialog::TempoDialogAction)), RosegardenGUIApp::self(), SLOT(slotChangeTempo(timeT, tempoT, tempoT, TempoDialog::TempoDialogAction))); connect(this, SIGNAL(moveTempo(timeT, timeT)), RosegardenGUIApp::self(), SLOT(slotMoveTempo(timeT, timeT))); connect(this, SIGNAL(deleteTempo(timeT)), RosegardenGUIApp::self(), SLOT(slotDeleteTempo(timeT))); connect(this, SIGNAL(editTempo(timeT)), RosegardenGUIApp::self(), SLOT(slotEditTempo(timeT))); connect(this, SIGNAL(editTimeSignature(timeT)), RosegardenGUIApp::self(), SLOT(slotEditTimeSignature(timeT))); connect(this, SIGNAL(editTempos(timeT)), RosegardenGUIApp::self(), SLOT(slotEditTempos(timeT)));}voidTempoRuler::slotScrollHoriz(int x){ int w = width(), h = height(); int dx = x - ( -m_currentXOffset); m_currentXOffset = -x; if (dx > w*3 / 4 || dx < -w*3 / 4) { update(); return ; } if (dx > 0) { // moving right, so the existing stuff moves left bitBlt(this, 0, 0, this, dx, 0, w - dx, h); repaint(w - dx, 0, dx, h); } else { // moving left, so the existing stuff moves right bitBlt(this, -dx, 0, this, 0, 0, w + dx, h); repaint(0, 0, -dx, h); }}voidTempoRuler::mousePressEvent(QMouseEvent *e){ if (e->button() == LeftButton) { if (e->type() == QEvent::MouseButtonDblClick) { timeT t = m_rulerScale->getTimeForX (e->x() - m_currentXOffset - m_xorigin); emit doubleClicked(t); return ; } int x = e->x() + 1; int y = e->y(); timeT t = m_rulerScale->getTimeForX(x - m_currentXOffset - m_xorigin); int tcn = m_composition->getTempoChangeNumberAt(t); if (tcn < 0 || tcn >= m_composition->getTempoChangeCount()) return ; std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); std::pair<bool, tempoT> tr = m_composition->getTempoRamping(tcn, true); m_dragStartY = y; m_dragStartX = x; m_dragStartTime = tc.first; m_dragPreviousTime = m_dragStartTime; m_dragStartTempo = tc.second; m_dragStartTarget = tr.first ? tr.second : -1; m_dragOriginalTempo = m_dragStartTempo; m_dragOriginalTarget = m_dragStartTarget; m_dragFine = ((e->state() & Qt::ShiftButton) != 0); int px = m_rulerScale->getXForTime(tc.first) + m_currentXOffset + m_xorigin; if (x >= px && x < px + 5) { m_dragHoriz = true; m_dragVert = false; setCursor(Qt::SplitHCursor); } else { timeT nt = m_composition->getEndMarker(); if (tcn < m_composition->getTempoChangeCount() - 1) { nt = m_composition->getTempoChange(tcn + 1).first; } int nx = m_rulerScale->getXForTime(nt) + m_currentXOffset + m_xorigin; if (x > px + 5 && x > nx - 5) { m_dragTarget = true; setCursor(Qt::SizeVerCursor); } else { m_dragTarget = false; setCursor(Qt::SplitVCursor); } m_dragVert = true; m_dragHoriz = false; } } else if (e->button() == RightButton) { m_clickX = e->x(); if (!m_menu) createMenu(); if (m_menu) { // enable 'delete' action only if cursor is actually over a tempo change actionCollection()->action("delete_tempo")->setEnabled(m_illuminatePoint); m_menu->exec(QCursor::pos()); } }}voidTempoRuler::mouseReleaseEvent(QMouseEvent *e){ if (m_dragVert) { m_dragVert = false; unsetCursor(); if (e->x() < 0 || e->x() >= width() || e->y() < 0 || e->y() >= height()) { leaveEvent(0); } // First we make a note of the values that we just set and // restore the tempo to whatever it was previously, so that // the undo for any following command will work correctly. // Then we emit so that our user can issue the right command. int tcn = m_composition->getTempoChangeNumberAt(m_dragStartTime); std::pair<timeT, tempoT> tc = m_composition->getTempoChange(tcn); std::pair<bool, tempoT> tr = m_composition->getTempoRamping(tcn, true); if (tc.second != m_dragOriginalTempo) { m_composition->addTempoAtTime(m_dragStartTime, m_dragOriginalTempo, m_dragOriginalTarget); emit changeTempo(m_dragStartTime, tc.second, tr.first ? tr.second : -1, TempoDialog::AddTempo); } return ; } else if (m_dragHoriz) { m_dragHoriz = false; unsetCursor(); if (e->x() < 0 || e->x() >= width() || e->y() < 0 || e->y() >= height()) { leaveEvent(0); } if (m_dragPreviousTime != m_dragStartTime) { // As above, restore the original tempo and then emit a // signal to ensure a proper command happens. int tcn = m_composition->getTempoChangeNumberAt(m_dragPreviousTime); m_composition->removeTempoChange(tcn); m_composition->addTempoAtTime(m_dragStartTime, m_dragStartTempo, m_dragStartTarget); emit moveTempo(m_dragStartTime, m_dragPreviousTime);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -