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
196
197
198
199
200
201
|
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
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 "TrackLabel.h"
#include <tdelocale.h>
#include "base/Track.h"
#include <klineeditdlg.h>
#include <tqfont.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqregexp.h>
#include <tqstring.h>
#include <tqtimer.h>
#include <tqtooltip.h>
#include <tqwidget.h>
#include <tqwidgetstack.h>
#include <tqvalidator.h>
namespace Rosegarden
{
TrackLabel::TrackLabel(TrackId id,
int position,
TQWidget *parent,
const char *name):
TQWidgetStack(parent, name),
m_instrumentLabel(new TQLabel(this)),
m_trackLabel(new TQLabel(this)),
m_id(id),
m_position(position)
{
TQFont font;
font.setPointSize(font.pointSize() * 95 / 100);
if (font.pixelSize() > 14)
font.setPixelSize(14);
font.setBold(false);
m_instrumentLabel->setFont(font);
m_trackLabel->setFont(font);
addWidget(m_instrumentLabel, ShowInstrument);
addWidget(m_trackLabel, ShowTrack);
raiseWidget(ShowTrack);
m_instrumentLabel->setFrameShape(TQFrame::NoFrame);
m_trackLabel->setFrameShape(TQFrame::NoFrame);
m_pressTimer = new TQTimer(this);
connect(m_pressTimer, TQ_SIGNAL(timeout()),
this, TQ_SIGNAL(changeToInstrumentList()));
TQToolTip::add
(this, i18n("Click and hold with left mouse button to assign this Track to an Instrument."));
}
TrackLabel::~TrackLabel()
{}
void TrackLabel::setIndent(int i)
{
m_instrumentLabel->setIndent(i);
m_trackLabel->setIndent(i);
}
void TrackLabel::setAlternativeLabel(const TQString &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(TQMouseEvent *e)
{
if (e->button() == TQt::RightButton) {
emit clicked();
emit changeToInstrumentList();
} else if (e->button() == TQt::LeftButton) {
// start a timer on this hold
m_pressTimer->start(200, true); // 200ms, single shot
}
}
void
TrackLabel::mouseReleaseEvent(TQMouseEvent *e)
{
// stop the timer if running
if (m_pressTimer->isActive())
m_pressTimer->stop();
if (e->button() == TQt::LeftButton) {
emit clicked();
}
}
void
TrackLabel::mouseDoubleClickEvent(TQMouseEvent *e)
{
if (e->button() != TQt::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;
TQRegExpValidator validator(TQRegExp(".*"), this); // empty is OK
TQString 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);
}
}
#include "TrackLabel.moc"
|