kwave  18.07.70
SelectionBorderItem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * SelectionBorderItem.cpp - selection border within a SignalView
3  * -------------------
4  * begin : Sat Mar 11 2017
5  * copyright : (C) 2017 by Thomas Eschenbacher
6  * email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include "libkwave/SignalManager.h"
21 #include "libkwave/String.h"
22 #include "libkwave/Utils.h"
23 
25 #include "libgui/SignalView.h"
26 
27 //***************************************************************************
29  Kwave::SignalView &view,
30  Kwave::SignalManager &signal_manager,
31  sample_index_t pos
32 )
33  :Kwave::ViewItem(view, signal_manager),
34  m_selection()
35 {
37  signal_manager.selection().first(),
38  signal_manager.selection().last()
39  );
40  m_selection.grep(pos);
41 }
42 
43 //***************************************************************************
45 {
46 }
47 
48 //***************************************************************************
49 Kwave::ViewItem::Flags Kwave::SelectionBorderItem::flags() const
50 {
52 }
53 
54 //***************************************************************************
56 {
59  if (first == last) return QString(); // empty selection
60 
61  sample_index_t d_left = (first < ofs) ? (ofs - first) : (first - ofs);
62  sample_index_t d_right = (last < ofs) ? (ofs - last) : (last - ofs);
63 
64  QString which;
65  if (d_left <= d_right) {
66  which = i18n("Selection, left border");
67  ofs = first;
68  } else {
69  which = i18n("Selection, right border");
70  ofs = last;
71  }
72 
73  QString hms = Kwave::ms2hms(m_view.samples2ms(ofs));
74  return _("%1\n%2\n%3").arg(which).arg(ofs).arg(hms);
75 }
76 
77 //***************************************************************************
79 {
80  return Qt::SizeHorCursor;
81 }
82 
83 //***************************************************************************
84 void Kwave::SelectionBorderItem::moveTo(const QPoint &mouse_pos)
85 {
86  const sample_index_t new_pos = m_view.offset() +
87  m_view.pixels2samples(mouse_pos.x());
88  m_selection.update(new_pos);
90 }
91 
92 //***************************************************************************
93 //***************************************************************************
void selectRange(sample_index_t offset, sample_index_t length)
virtual void moveTo(const QPoint &mouse_pos) Q_DECL_OVERRIDE
sample_index_t first() const
Definition: Selection.h:71
void set(sample_index_t l, sample_index_t r)
Definition: MouseMark.cpp:36
Definition: App.h:33
SelectionBorderItem(SignalView &view, Kwave::SignalManager &signal_manager, sample_index_t pos)
sample_index_t right() const
Definition: MouseMark.cpp:49
sample_index_t last() const
Definition: Selection.h:76
QString Q_DECL_EXPORT ms2hms(double ms)
Definition: Utils.cpp:104
Kwave::Selection & selection()
void grep(sample_index_t x)
Definition: MouseMark.cpp:55
quint64 sample_index_t
Definition: Sample.h:28
sample_index_t offset() const
Definition: SignalView.h:110
Kwave::SignalManager & m_signal_manager
Definition: ViewItem.h:119
Kwave::SignalView & m_view
Definition: ViewItem.h:116
double samples2ms(sample_index_t samples)
Definition: SignalView.cpp:162
virtual Kwave::ViewItem::Flags flags() const Q_DECL_OVERRIDE
virtual QCursor mouseCursor() const Q_DECL_OVERRIDE
virtual QString toolTip(sample_index_t &ofs) Q_DECL_OVERRIDE
void update(sample_index_t x)
Definition: MouseMark.cpp:67
sample_index_t pixels2samples(int pixels) const
Definition: SignalView.cpp:155
sample_index_t length() const
Definition: MouseMark.h:77
virtual ~SelectionBorderItem() Q_DECL_OVERRIDE
#define _(m)
Definition: memcpy.c:66
sample_index_t left() const
Definition: MouseMark.cpp:43