29 #include <QKeySequence> 31 #include <QMouseEvent> 32 #include <QPaintEvent> 37 #include <QStandardPaths> 39 #include <QStringList> 40 #include <QTextStream> 42 #include <KLocalizedString> 43 #include <KIconLoader> 56 :QWidget(parent), m_width(0), m_height(0), m_curve(), m_menu(Q_NULLPTR),
57 m_preset_menu(Q_NULLPTR), m_current(
Kwave::
Curve::NoPoint),
59 m_down(false), m_knob(), m_selected_knob()
61 KIconLoader *icon_loader = KIconLoader::global();
66 QPalette pal = palette();
67 pal.setColor(QPalette::Window, Qt::black);
72 m_knob = icon_loader->loadIcon(
_(
"knob.xpm"), KIconLoader::Small);
82 QMenu *interpolation =
m_menu->addMenu(i18n(
"Interpolation"));
83 Q_ASSERT(interpolation);
84 if (!interpolation)
return;
87 QMenu *transform =
m_menu->addMenu(i18n(
"Transform"));
89 if (!transform)
return;
90 transform->addAction(i18n(
"Flip horizontal"),
92 transform->addAction(i18n(
"Flip vertical"),
94 transform->addSeparator();
95 transform->addAction(i18n(
"Into first half"),
97 transform->addAction(i18n(
"Into second half"),
100 QMenu *del =
m_menu->addMenu(i18n(
"Delete"));
116 QIcon::fromTheme(
_(
"document-export")),
121 QIcon::fromTheme(
_(
"edit-delete")),
122 i18n(
"Currently Selected Point"),
124 QKeySequence::Delete);
125 del->addAction(i18n(
"Every Second Point"),
130 foreach (
const QString &text, types) {
131 QAction *action =
new QAction(interpolation);
132 action->setText(text);
133 action->setData(
id++);
134 interpolation->addAction(action);
136 connect(interpolation, SIGNAL(triggered(QAction*)),
139 setMouseTracking(
true);
141 QShortcut *delkey =
new QShortcut(
this);
144 delkey->setKey(Qt::Key_Delete);
173 QVariant data = action->data();
174 int index = data.toInt();
184 QString presetSubDir =
_(
"presets") + QDir::separator() +
_(
"curves");
185 QString presetPath = QStandardPaths::writableLocation(
186 QStandardPaths::AppDataLocation) +
187 QDir::separator() + presetSubDir;
188 if (!QDir(presetPath).exists()) {
190 _(
"curve preset directory did not exist, creating '%1'").arg(
192 QDir(presetPath).mkpath(presetPath);
197 _(
"*.curve *.CURVE|") +
198 i18nc(
"Filter description for Kwave curve presets, " 199 "for use in a FileDialog",
200 "Kwave curve preset (*.curve)"),
201 this, QUrl(),
_(
"*.curve"));
203 dlg->setWindowTitle(i18n(
"Save Curve Preset"));
204 if (dlg->exec() != QDialog::Accepted) {
209 QString
name = dlg->selectedUrl().toLocalFile();
213 if (!name.endsWith(
_(
".curve")))
214 name.append(
_(
".curve"));
217 out.open(QIODevice::WriteOnly);
219 out.write(
DBG(cmd), cmd.length());
228 const QChar s = QDir::separator();
229 QString presetSubDir = s +
_(
"kwave") + s +
_(
"presets") + s +
_(
"curves");
231 QStringList presetPaths = QStandardPaths::standardLocations(
232 QStandardPaths::GenericDataLocation);
233 foreach (
const QString &path, presetPaths) {
234 QDir d(path + presetSubDir);
235 QStringList f = d.entryList(QDir::Files, QDir::Name);
236 foreach (
const QString &file, f) {
237 QString preset = d.path() + s + file;
238 if (!files.contains(preset)) files.append(preset);
244 foreach (
const QString &file, files) {
246 QString
name = fi.baseName();
247 QAction *action =
new (std::nothrow) QAction(name,
m_preset_menu);
249 if (!action)
continue;
250 action->setData(file);
261 if (!action->data().isValid())
return;
268 QString filename = action->data().toString();
269 QFileInfo fi(filename);
270 if (!fi.exists(filename))
return;
273 QFile file(filename);
274 if (!file.open(QIODevice::ReadOnly)) {
275 qWarning(
"CurveWidget::loadPreset('%s') - FAILED",
DBG(filename));
278 QTextStream stream(&file);
368 if (e->buttons() == Qt::RightButton) {
370 QPoint popup = QCursor::pos();
372 }
else if (e->buttons() == Qt::LeftButton) {
379 static_cast<double>(
m_height - e->pos().y()) /
404 int x = e->pos().x();
405 int y = e->pos().y();
422 double dx = (1.0 /
static_cast<double>(
m_width - 1));
426 if (qFuzzyCompare(nearest.x(),
m_current.x())) {
441 setCursor(Qt::SizeAllCursor);
443 setCursor(Qt::ArrowCursor);
459 const int kw =
m_knob.width();
460 const int kh =
m_knob.height();
465 qWarning(
"CurveWidget: unable to get interpolation !");
470 p.fillRect(
rect(), QBrush(palette().dark()));
471 p.setPen(palette().text().color());
475 for (
int i = 1; i <
m_width; i++) {
477 p.drawLine (i - 1, ly, i, ay);
489 p.drawPixmap(lx - (kw >> 1), ly - (kh >> 1),
m_knob);
void scaleFit(unsigned int range=1024)
void insert(double x, double y)
void fromCommand(const QString &command)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
static Kwave::interpolation_t findByIndex(int index)
Kwave::Interpolation & interpolation()
void setInterpolationType(Kwave::interpolation_t type)
void deletePoint(Point p, bool check)
Point findPoint(double x, double y, double tol=.05)
static QStringList descriptions(bool localized=false)
static void Q_DECL_EXPORT log(const QObject *sender, LogLevel level, const QString &msg)
static double rect(double param)