1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/*
Rosegarden-4
A sequencer and musical notation editor.
This program is Copyright 2000-2005
Guillaume Laurent <glaurent@telegraph-road.org>,
Chris Cannam <cannam@all-day-breakfast.com>,
Richard Bown <bownie@bownie.com>
The moral right of the authors to claim authorship of this work
has been asserted.
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 <qlabel.h>
#include <qtimer.h>
#include <qvalidator.h>
#include <qtooltip.h>
#include <klineeditdlg.h>
#include <klocale.h>
#include "rosedebug.h"
#include "tracklabel.h"
TrackLabel::TrackLabel(Rosegarden::TrackId id,
int position,
QWidget *parent,
const char *name):
QWidgetStack(parent, name),
m_instrumentLabel(new QLabel(this)),
m_trackLabel(new QLabel(this)),
m_id(id),
m_position(position)
{
addWidget(m_instrumentLabel, ShowInstrument);
addWidget(m_trackLabel, ShowTrack);
raiseWidget(ShowTrack);
m_instrumentLabel->setFrameShape(QFrame::NoFrame);
m_trackLabel->setFrameShape(QFrame::NoFrame);
m_pressTimer = new QTimer(this);
connect(m_pressTimer, SIGNAL(timeout()),
this, SIGNAL(changeToInstrumentList()));
QToolTip::add(this, i18n("Click and hold with left mouse button to assign this Track to an Instrument."));
}
TrackLabel::~TrackLabel()
{
}
// void TrackLabel::setText(QString s)
// {
// getVisibleLabel()->setText(s);
// }
// QString TrackLabel::text()
// {
// return getVisibleLabel()->text();
// }
void TrackLabel::setIndent(int i)
{
m_instrumentLabel->setIndent(i);
m_trackLabel->setIndent(i);
}
void TrackLabel::setAlternativeLabel(const QString &label)
{
// recover saved original
if (label.isEmpty()) {
if(!m_alternativeLabel.isEmpty())
m_instrumentLabel->setText(m_alternativeLabel);
// do nothing if we've got nothing to swap
return;
}
// Store the current (first) label
//
if(m_alternativeLabel.isEmpty())
m_alternativeLabel = m_instrumentLabel->text();
// set new label
m_instrumentLabel->setText(label);
}
void TrackLabel::clearAlternativeLabel()
{
m_alternativeLabel = "";
}
void TrackLabel::showLabel(InstrumentTrackLabels l)
{
raiseWidget(l);
}
void
TrackLabel::setSelected(bool on)
{
if (on) {
m_selected = true;
m_instrumentLabel->setPaletteBackgroundColor(colorGroup().highlight());
m_instrumentLabel->setPaletteForegroundColor(colorGroup().highlightedText());
m_trackLabel->setPaletteBackgroundColor(colorGroup().highlight());
m_trackLabel->setPaletteForegroundColor(colorGroup().highlightedText());
} else {
m_selected = false;
m_instrumentLabel->setPaletteBackgroundColor(colorGroup().background());
m_trackLabel->setPaletteBackgroundColor(colorGroup().background());
m_instrumentLabel->setPaletteForegroundColor(colorGroup().text());
m_trackLabel->setPaletteForegroundColor(colorGroup().text());
}
if (visibleWidget()) visibleWidget()->update();
}
void
TrackLabel::mousePressEvent(QMouseEvent *e)
{
if (e->button() == RightButton) {
emit clicked();
emit changeToInstrumentList();
} else if (e->button() == LeftButton) {
// start a timer on this hold
m_pressTimer->start(200, true); // 200ms, single shot
}
}
void
TrackLabel::mouseReleaseEvent(QMouseEvent *e)
{
// stop the timer if running
if (m_pressTimer->isActive())
m_pressTimer->stop();
if (e->button() == LeftButton) {
emit clicked();
}
}
void
TrackLabel::mouseDoubleClickEvent(QMouseEvent *e)
{
if (e->button() != LeftButton)
return;
// Highlight this label alone and cheat using
// the clicked signal
//
emit clicked();
// Just in case we've got our timing wrong - reapply
// this label highlight
//
setSelected(true);
bool ok = false;
QRegExpValidator validator(QRegExp(".*"), this); // empty is OK
QString newText = KLineEditDlg::getText(i18n("Change track name"),
i18n("Enter new track name"),
m_trackLabel->text(),
&ok,
this,
&validator);
if ( ok )
emit renameTrack(newText, m_id);
}
QLabel* TrackLabel::getVisibleLabel()
{
return dynamic_cast<QLabel*>(visibleWidget());
}
|