kwave  18.07.70
Kwave::LabelItem Class Reference

#include <LabelItem.h>

Inheritance diagram for Kwave::LabelItem:
Inheritance graph
Collaboration diagram for Kwave::LabelItem:
Collaboration graph

Public Member Functions

 LabelItem (Kwave::SignalView &view, Kwave::SignalManager &signal_manager, unsigned int index, const Kwave::Label &label)
 
virtual ~LabelItem () Q_DECL_OVERRIDE
 
virtual Kwave::ViewItem::Flags flags () const Q_DECL_OVERRIDE
 
virtual QString toolTip (sample_index_t &ofs) Q_DECL_OVERRIDE
 
virtual void appendContextMenu (QMenu *parent) Q_DECL_OVERRIDE
 
virtual QCursor mouseCursor () const Q_DECL_OVERRIDE
 
virtual void moveTo (const QPoint &mouse_pos) Q_DECL_OVERRIDE
 
virtual void done () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::ViewItem
 ViewItem (Kwave::SignalView &view, Kwave::SignalManager &signal_manager)
 
virtual ~ViewItem ()
 
virtual void startDragging ()
 

Private Slots

void contextMenuLabelDelete ()
 
void contextMenuLabelProperties ()
 

Private Attributes

unsigned int m_index
 
sample_index_t m_initial_pos
 
sample_index_t m_current_pos
 
QString m_description
 
Kwave::UndoTransactionGuardm_undo_transaction
 

Additional Inherited Members

- Public Types inherited from Kwave::ViewItem
enum  Flag { None = 0, CanGrabAndMove = 1, CanDragAndDrop = 2 }
 
- Signals inherited from Kwave::ViewItem
void sigCommand (const QString &command)
 
- Protected Attributes inherited from Kwave::ViewItem
Kwave::SignalViewm_view
 
Kwave::SignalManagerm_signal_manager
 

Detailed Description

Definition at line 39 of file LabelItem.h.

Constructor & Destructor Documentation

◆ LabelItem()

Kwave::LabelItem::LabelItem ( Kwave::SignalView view,
Kwave::SignalManager signal_manager,
unsigned int  index,
const Kwave::Label label 
)

Constructor

Parameters
viewthe owner (SignalView)
signal_managerthe corresponding SignalManager
indexthe one-based index of the label
labelreference to the label

Definition at line 37 of file LabelItem.cpp.

41  :Kwave::ViewItem(view, signal_manager),
42  m_index(index),
43  m_initial_pos(label.pos()),
44  m_current_pos(label.pos()),
45  m_description(label.name()),
46  m_undo_transaction(Q_NULLPTR)
47 {
48 }
sample_index_t m_current_pos
Definition: LabelItem.h:113
sample_index_t m_initial_pos
Definition: LabelItem.h:110
virtual sample_index_t pos() const
Definition: Label.cpp:56
unsigned int m_index
Definition: LabelItem.h:107
QString m_description
Definition: LabelItem.h:116
virtual QString name() const
Definition: Label.cpp:74
Kwave::UndoTransactionGuard * m_undo_transaction
Definition: LabelItem.h:119

◆ ~LabelItem()

Kwave::LabelItem::~LabelItem ( )
virtual

Destructor

Definition at line 51 of file LabelItem.cpp.

References Kwave::UndoTransactionGuard::abort(), and m_undo_transaction.

52 {
53  if (m_undo_transaction) {
54  // restore the previous data
55  qDebug("Kwave::LabelItem::~LabelItem() -> aborted -> reverting!");
57  delete m_undo_transaction;
58  m_undo_transaction = Q_NULLPTR;
59  }
60 }
Kwave::UndoTransactionGuard * m_undo_transaction
Definition: LabelItem.h:119
Here is the call graph for this function:

Member Function Documentation

◆ appendContextMenu()

void Kwave::LabelItem::appendContextMenu ( QMenu *  parent)
virtual

Called to append entries to a context menu.

Parameters
parentcontext menu to add items

Reimplemented from Kwave::ViewItem.

Definition at line 86 of file LabelItem.cpp.

References _, contextMenuLabelDelete(), and contextMenuLabelProperties().

87 {
88  Q_ASSERT(parent);
89  if (!parent) return;
90 
91  // locate the "label" menu
92  QMenu *label_menu = Q_NULLPTR;
93  foreach (const QAction *action, parent->actions()) {
94  if (action->text() == i18n("Label")) {
95  label_menu = action->menu();
96  break;
97  }
98  }
99 
100  // the context menu of a label has been activated
101  if (label_menu) {
102 
103  // find the "New" action and disable it
104  foreach (QAction *action, label_menu->actions()) {
105  if (action->text() == i18n("New")) {
106  action->setEnabled(false);
107  break;
108  }
109  }
110 
111  QAction *action_label_delete = label_menu->addAction(
112  QIcon::fromTheme(_("list-remove")),
113  i18n("&Delete"), this, SLOT(contextMenuLabelDelete()));
114  Q_ASSERT(action_label_delete);
115  if (!action_label_delete) return;
116 
117  QAction *action_label_properties = label_menu->addAction(
118  QIcon::fromTheme(_("configure")),
119  i18n("&Properties..."), this, SLOT(contextMenuLabelProperties()));
120  Q_ASSERT(action_label_properties);
121  if (!action_label_properties) return;
122  }
123 
124 }
void contextMenuLabelProperties()
Definition: LabelItem.cpp:133
void contextMenuLabelDelete()
Definition: LabelItem.cpp:127
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:

◆ contextMenuLabelDelete

void Kwave::LabelItem::contextMenuLabelDelete ( )
privateslot

context menu: "label / delete"

Definition at line 127 of file LabelItem.cpp.

References _, m_index, and Kwave::ViewItem::sigCommand().

Referenced by appendContextMenu().

128 {
129  emit sigCommand(_("label:delete(%1)").arg(m_index));
130 }
unsigned int m_index
Definition: LabelItem.h:107
void sigCommand(const QString &command)
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ contextMenuLabelProperties

void Kwave::LabelItem::contextMenuLabelProperties ( )
privateslot

context menu: "label / properties..."

Definition at line 133 of file LabelItem.cpp.

References _, m_index, and Kwave::ViewItem::sigCommand().

Referenced by appendContextMenu().

134 {
135  emit sigCommand(_("nomacro:label:edit(%1)").arg(m_index));
136 }
unsigned int m_index
Definition: LabelItem.h:107
void sigCommand(const QString &command)
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ done()

void Kwave::LabelItem::done ( )
virtual

Called when leaving the move mode, when the mouse button has been released.

Reimplemented from Kwave::ViewItem.

Definition at line 184 of file LabelItem.cpp.

References Kwave::UndoTransactionGuard::abort(), m_current_pos, m_initial_pos, and m_undo_transaction.

185 {
186  if (m_undo_transaction) {
187  // close the undo transaction (regularly, with undo action)
190  delete m_undo_transaction;
191  m_undo_transaction = Q_NULLPTR;
192  }
193 }
sample_index_t m_current_pos
Definition: LabelItem.h:113
sample_index_t m_initial_pos
Definition: LabelItem.h:110
Kwave::UndoTransactionGuard * m_undo_transaction
Definition: LabelItem.h:119
Here is the call graph for this function:

◆ flags()

Kwave::ViewItem::Flags Kwave::LabelItem::flags ( ) const
virtual

Returns flags describing the possible interactions with this object

See also
Kwave::ViewItem::Flags

Reimplemented from Kwave::ViewItem.

Definition at line 63 of file LabelItem.cpp.

References Kwave::ViewItem::CanGrabAndMove.

◆ mouseCursor()

QCursor Kwave::LabelItem::mouseCursor ( ) const
virtual

Returns a mouse cursor used when moving the item

Reimplemented from Kwave::ViewItem.

Definition at line 139 of file LabelItem.cpp.

140 {
141  return Qt::SizeHorCursor;
142 }

◆ moveTo()

void Kwave::LabelItem::moveTo ( const QPoint &  mouse_pos)
virtual

handles updates when being moved with the mouse

Parameters
mouse_posposition of the mouse, in pixel coordinates relative to the parent widget

Reimplemented from Kwave::ViewItem.

Definition at line 145 of file LabelItem.cpp.

References Kwave::SignalManager::findLabel(), Kwave::MetaData::isNull(), Kwave::SignalManager::labelIndex(), m_current_pos, m_description, m_index, m_initial_pos, Kwave::ViewItem::m_signal_manager, m_undo_transaction, Kwave::ViewItem::m_view, Kwave::SignalManager::modifyLabel(), Kwave::SignalView::offset(), Kwave::SignalView::pixels2samples(), Kwave::Label::pos(), and Kwave::UndoTransactionGuard::registerUndoAction().

146 {
147  const sample_index_t new_pos = m_view.offset() +
148  m_view.pixels2samples(mouse_pos.x());
149 
150  Kwave::Label label = m_signal_manager.findLabel(new_pos);
151  if (label.isNull()) {
152 
153  // this is the first move ?
154  if (!m_undo_transaction) {
155  // there probably will be something to undo later
156  // create an undo transaction guard
157  m_undo_transaction = new(std::nothrow)
159  m_signal_manager, i18n("Move Label"));
160  Q_ASSERT(m_undo_transaction);
161  if (!m_undo_transaction) return;
162 
163  // save the previous label data for undo
165  if (!m_undo_transaction->registerUndoAction(new(std::nothrow)
166  UndoModifyMetaDataAction(Kwave::MetaDataList(lbl)))) {
167  qWarning("Kwave::LabelItem::done(): saving undo data failed!");
168  return;
169  }
170  }
171 
172  if (m_signal_manager.modifyLabel(m_index, new_pos,
173  m_description, false)) {
174  Kwave::Label lbl = m_signal_manager.findLabel(new_pos);
175  if (!lbl.isNull()) {
177  m_current_pos = lbl.pos();
178  }
179  }
180  }
181 }
sample_index_t m_current_pos
Definition: LabelItem.h:113
sample_index_t m_initial_pos
Definition: LabelItem.h:110
virtual sample_index_t pos() const
Definition: Label.cpp:56
unsigned int m_index
Definition: LabelItem.h:107
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
bool registerUndoAction(UndoAction *action)
int labelIndex(const Kwave::Label &label) const
QString m_description
Definition: LabelItem.h:116
virtual bool isNull() const
Definition: MetaData.cpp:69
sample_index_t pixels2samples(int pixels) const
Definition: SignalView.cpp:155
Kwave::UndoTransactionGuard * m_undo_transaction
Definition: LabelItem.h:119
Kwave::Label findLabel(sample_index_t pos)
bool modifyLabel(int index, sample_index_t pos, const QString &name, bool with_undo)
Here is the call graph for this function:

◆ toolTip()

QString Kwave::LabelItem::toolTip ( sample_index_t ofs)
virtual

Can be overwritten to return a tooltip.

Parameters
ofssample index the tooltip should refer to (unused)
Returns
an already localized tooltip

Reimplemented from Kwave::ViewItem.

Definition at line 69 of file LabelItem.cpp.

References _, m_current_pos, m_description, m_index, Kwave::ViewItem::m_view, Kwave::ms2hms(), and Kwave::SignalView::samples2ms().

70 {
71  Q_UNUSED(ofs);
72 
73  QString description = (m_description.length()) ?
74  i18nc("tooltip of a label, %1=index, %2=description/name",
75  "Label #%1 (%2)", m_index, m_description) :
76  i18nc("tooltip of a label, without description, %1=index",
77  "Label #%1", m_index);
78 
80  QString tip = _("%1\n%2\n%3").arg(description).arg(m_current_pos).arg(hms);
81 
82  return tip;
83 }
sample_index_t m_current_pos
Definition: LabelItem.h:113
QString Q_DECL_EXPORT ms2hms(double ms)
Definition: Utils.cpp:104
unsigned int m_index
Definition: LabelItem.h:107
Kwave::SignalView & m_view
Definition: ViewItem.h:116
double samples2ms(sample_index_t samples)
Definition: SignalView.cpp:162
QString m_description
Definition: LabelItem.h:116
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:

Member Data Documentation

◆ m_current_pos

sample_index_t Kwave::LabelItem::m_current_pos
private

current position of the label, in samples

Definition at line 113 of file LabelItem.h.

Referenced by done(), moveTo(), and toolTip().

◆ m_description

QString Kwave::LabelItem::m_description
private

description of the label

Definition at line 116 of file LabelItem.h.

Referenced by moveTo(), and toolTip().

◆ m_index

unsigned int Kwave::LabelItem::m_index
private

index of the label

Definition at line 107 of file LabelItem.h.

Referenced by contextMenuLabelDelete(), contextMenuLabelProperties(), moveTo(), and toolTip().

◆ m_initial_pos

sample_index_t Kwave::LabelItem::m_initial_pos
private

initial position of the label, in samples

Definition at line 110 of file LabelItem.h.

Referenced by done(), and moveTo().

◆ m_undo_transaction

Kwave::UndoTransactionGuard* Kwave::LabelItem::m_undo_transaction
private

used when we are within a undo transaction (we started)

Definition at line 119 of file LabelItem.h.

Referenced by done(), moveTo(), and ~LabelItem().


The documentation for this class was generated from the following files: