25 #include <QResizeEvent> 27 #include <QVBoxLayout> 44 #define MINIMUM_HEIGHT 100 59 m_img_signal_needs_refresh(true),
60 m_img_selection_needs_refresh(true),
61 m_img_markers_needs_refresh(true),
62 m_mouse_click_position(0),
74 QVBoxLayout *layout =
new QVBoxLayout(controls);
92 msw, SIGNAL(clicked(
int)),
93 track, SLOT(toggleSelection())
96 track, SIGNAL(sigSelectionChanged(
bool)),
97 msw, SLOT(switchState(
bool))
100 msw->setMinimumSize(20, 20);
102 layout->addWidget(msw);
106 connect(signal_manager, SIGNAL(
109 Qt::QueuedConnection);
123 SIGNAL(sigPlaybackStopped()),
128 connect(track, SIGNAL(sigSelectionChanged(
bool)),
148 Q_ASSERT(zoom >= 0.0);
160 const int old_height = this->height();
176 QSharedPointer<Kwave::ViewItem> item =
177 QSharedPointer<Kwave::ViewItem>(Q_NULLPTR);
183 const double fine_pos =
static_cast<double>(
m_offset) +
184 (static_cast<double>(pos.x()) *
m_zoom);
193 unsigned int nearest_label_index = 0;
194 double d_label = tolerance;
196 unsigned int index = 0;
200 double d = qAbs(static_cast<double>(label.
pos()) - fine_pos);
201 if (d < qMin(d_label, tolerance)) {
203 nearest_label = label;
204 nearest_label_index = index;
211 double selection_first =
static_cast<double>(
213 double selection_last =
static_cast<double>(
216 const double d_selection_left = qAbs(selection_first - fine_pos);
217 const double d_selection_right = qAbs(selection_last - fine_pos);
222 bool prefer_the_label =
223 ((d_selection_left < tolerance) && (fine_pos < selection_first)) ||
224 ((d_selection_right < tolerance) && (fine_pos > selection_last));
225 bool selection_is_nearer =
226 (d_selection_left <= d_label) || (d_selection_right <= d_label);
227 if (selection_is_nearer && !prefer_the_label) {
229 d_label = d_selection_left + d_selection_right;
232 if ( (d_label <= qMin(d_selection_left, d_selection_right)) &&
233 !nearest_label.
isNull() ) {
235 return QSharedPointer<Kwave::ViewItem>(
new(std::nothrow)
237 nearest_label_index, nearest_label));
240 if ( (d_selection_left < qMin(tolerance, d_selection_right)) ||
241 ((d_selection_left < tolerance) && selection_is_empty) )
244 return QSharedPointer<Kwave::ViewItem>(
new(std::nothrow)
250 if (d_selection_right < qMin(tolerance, d_selection_left)) {
252 return QSharedPointer<Kwave::ViewItem>(
new(std::nothrow)
258 if ((offset >= selection_first) && (offset <= selection_last)) {
260 return QSharedPointer<Kwave::ViewItem>(
new(std::nothrow)
265 return QSharedPointer<Kwave::ViewItem>(Q_NULLPTR);
271 QMenu *submenu_label = menu->addMenu(i18n(
"Label"));
272 Q_ASSERT(submenu_label);
273 if (!submenu_label)
return;
276 QAction *action_label_new = submenu_label->addAction(
277 QIcon::fromTheme(
_(
"list-add")),
279 Q_ASSERT(action_label_new);
280 if (!action_label_new)
return;
295 Kwave::SignalView::resizeEvent(event);
344 #ifdef DEBUG_REPAINT_TIMES 350 const int width = QWidget::width();
351 const int height = QWidget::height();
361 const QImage::Format format = QImage::Format_ARGB32_Premultiplied;
367 m_image = QImage(width, height, format);
393 p.setCompositionMode(QPainter::CompositionMode_Source);
405 p.fillRect(0, 0, width, height, Qt::black);
407 int last_marker = -1;
414 if (pos > last_visible)
break;
416 if (x >= width)
break;
420 if (x == last_marker)
continue;
423 p.setCompositionMode(QPainter::CompositionMode_Exclusion);
424 p.drawLine(x, 0, x, height);
439 p.fillRect(0, 0, width, height, Qt::black);
445 if ((right > 0) && (right >=
m_offset)) {
449 if (left <= visible) {
451 if (right > visible) right = visible + 1;
458 if (r >= width) r = width - 1;
461 p.setPen(Qt::yellow);
463 p.drawLine(l, 0, l, height);
465 p.setBrush(Qt::yellow);
466 p.drawRect(l, 0, r - l + 1, height);
477 p.fillRect(0, 0, width, height, Qt::black);
480 p.setCompositionMode(QPainter::CompositionMode_Source);
484 p.setCompositionMode(QPainter::CompositionMode_Exclusion);
488 p.setCompositionMode(QPainter::CompositionMode_Exclusion);
500 if (x >= width)
break;
502 p.setPen(Qt::yellow);
503 p.setCompositionMode(QPainter::CompositionMode_Exclusion);
504 p.drawLine(x, 0, x, height);
514 #ifdef DEBUG_REPAINT_TIMES 515 qDebug(
"TrackView::paintEvent() -- done, t=%d ms --", time.elapsed());
sample_index_t lastVisible() const
bool m_img_signal_needs_refresh
void sigCommand(const QString &command)
bool m_img_markers_needs_refresh
sample_index_t first() const
virtual int width() const
virtual int selectionTolerance() const
virtual const QPixmap & pixmap() const
sample_index_t m_mouse_click_position
sample_index_t last() const
virtual void handleContextMenu(const QPoint &pos, QMenu *menu) Q_DECL_OVERRIDE
Kwave::MetaDataList & metaData()
Kwave::Selection & selection()
virtual sample_index_t pos() const
virtual int height() const
Kwave::PlaybackController & playbackController()
void contentSizeChanged()
virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
sample_index_t offset() const
void setOffset(sample_index_t offset)
virtual void setVerticalZoom(double zoom)
virtual QSharedPointer< Kwave::ViewItem > findItem(const QPoint &pos) Q_DECL_OVERRIDE
virtual void resize(int width, int height)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Kwave::TrackPixmap m_pixmap
void refreshSignalLayer()
sample_index_t length() const
virtual void setZoomAndOffset(double zoom, sample_index_t offset) Q_DECL_OVERRIDE
void contextMenuLabelNew()
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
TrackView(QWidget *parent, QWidget *controls, Kwave::SignalManager *signal_manager, Kwave::Track *track)
void refreshSelectionLayer()
void refreshMarkersLayer()
double verticalZoom() const
sample_index_t pixels2samples(int pixels) const
Kwave::SignalManager * m_signal_manager
virtual bool isModified()
virtual void showCursor(sample_index_t pos=SAMPLE_INDEX_MAX) Q_DECL_OVERRIDE
virtual void refresh() Q_DECL_OVERRIDE
bool m_img_selection_needs_refresh
sample_index_t m_cursor_pos
virtual ~TrackView() Q_DECL_OVERRIDE
virtual void setVerticalZoom(double zoom) Q_DECL_OVERRIDE
void setZoom(double zoom)
virtual void setZoomAndOffset(double zoom, sample_index_t offset)
void sigNeedRepaint(Kwave::SignalView *view)
int samples2pixels(sample_index_t samples) const