[3e4acc]: libgui / LabelItem.cpp Maximize Restore History

Download this file

LabelItem.cpp    140 lines (113 with data), 4.5 kB

  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
/***************************************************************************
LabelItem.cpp - label item within a SignalView
-------------------
begin : Sat Mar 26 2011
copyright : (C) 2011 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "config.h"
#include <math.h>
#include <QAction>
#include <QList>
#include <QMenu>
#include "kiconloader.h"
#include "klocalizedstring.h"
#include "libkwave/Label.h"
#include "libkwave/Utils.h"
#include "libgui/LabelItem.h"
//***************************************************************************
Kwave::LabelItem::LabelItem(unsigned int index, double ms, const Label &label)
:Kwave::ViewItem(),
m_index(index), m_pos(label.pos()), m_ms(ms),
m_description(label.name())
{
}
//***************************************************************************
Kwave::LabelItem::~LabelItem()
{
}
//***************************************************************************
Qt::ItemFlags Kwave::LabelItem::flags()
{
return Qt::ItemIsEditable;
}
//***************************************************************************
sample_index_t Kwave::LabelItem::first()
{
return m_pos;
}
//***************************************************************************
sample_index_t Kwave::LabelItem::last()
{
return m_pos;
}
//***************************************************************************
QString Kwave::LabelItem::toolTip(sample_index_t ofs)
{
Q_UNUSED(ofs);
QString description = (m_description.length()) ?
i18nc("tooltip of a label, %1=index, %2=description/name",
"Label #%1 (%2)", m_index, m_description) :
i18nc("tooltip of a label, without description, %1=index",
"Label #%1", m_index);
QString hms = Kwave::ms2hms(m_ms);
QString text = QString("%1\n%2\n%3").arg(description).arg(m_pos).arg(hms);
return text;
}
//***************************************************************************
void Kwave::LabelItem::appendContextMenu(QMenu *parent)
{
Q_ASSERT(parent);
if (!parent) return;
// locate the "label" menu
QMenu *label_menu = 0;
foreach (const QAction *action, parent->actions()) {
if (action->text() == i18n("&Label")) {
label_menu = action->menu();
break;
}
}
// the context menu of a label has been activated
if (label_menu) {
KIconLoader icon_loader;
// find the "New" action and disable it
foreach (QAction *action, label_menu->actions()) {
if (action->text() == i18n("&New")) {
action->setEnabled(false);
break;
}
}
QAction *action_label_delete = label_menu->addAction(
icon_loader.loadIcon("list-remove", KIconLoader::Toolbar),
i18n("&Delete"), this, SLOT(contextMenuLabelDelete()));
Q_ASSERT(action_label_delete);
if (!action_label_delete) return;
QAction *action_label_properties = label_menu->addAction(
icon_loader.loadIcon("configure", KIconLoader::Toolbar),
i18n("&Properties..."), this, SLOT(contextMenuLabelProperties()));
Q_ASSERT(action_label_properties);
if (!action_label_properties) return;
}
}
//***************************************************************************
void Kwave::LabelItem::contextMenuLabelDelete()
{
emit sigCommand(QString("delete_label(%1)").arg(m_index));
}
//***************************************************************************
void Kwave::LabelItem::contextMenuLabelProperties()
{
emit sigCommand(QString("nomacro:edit_label(%1)").arg(m_index));
}
//***************************************************************************
#include "LabelItem.moc"
//***************************************************************************
//***************************************************************************