kwave  18.07.70
LabelPropertiesWidget.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  LabelPropertiesWidget.cpp - dialog for editing label properties
3  -------------------
4  begin : Sun Sep 03 2006
5  copyright : (C) 2006 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 #include "math.h"
20 
21 #include <QApplication>
22 #include <QPushButton>
23 
24 #include <KConfig>
25 #include <KConfigGroup>
26 #include <QLineEdit>
27 #include <KSharedConfig>
28 
29 #include "libkwave/String.h"
30 
33 
35 #define CONFIG_SECTION "LabelProperties"
36 
37 //***************************************************************************
39  :QDialog(parent), LabelPropertiesWidgetBase(),
40  m_length(0), m_sample_rate(0)
41 {
42  setupUi(this);
43  Q_ASSERT(time);
44  if (time) time->setTitle(QString());
45  setFixedSize(sizeHint());
46 
47  // set the focus onto the "OK" button
48  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
49 }
50 
51 //***************************************************************************
53 {
54 }
55 
56 //***************************************************************************
58 {
59  Q_ASSERT(lblIndex);
60  if (lblIndex) lblIndex->setText(QString::number(index));
61 }
62 
63 //***************************************************************************
65  sample_index_t length, double rate)
66 {
67  Q_ASSERT(time);
68  if (!time) return;
69 
70  // store the length and rate, for calls to labelPosition()
71  m_length = length;
72  m_sample_rate = rate;
73 
74  // set the current position, always by samples
75  time->init(Kwave::SelectTimeWidget::bySamples, pos, rate, 0, length);
76 
77  // restore the previous selection mode and set it
78  const KConfigGroup cfg = KSharedConfig::openConfig()->group(CONFIG_SECTION);
79  bool ok;
80  QString str = cfg.readEntry("mode");
81  unsigned int m = str.toUInt(&ok);
82  if (!ok) return;
84  static_cast<Kwave::SelectTimeWidget::Mode>(m);
85 
86  // check if we stay on the requested location when switching to percent
87  // mode. If the position would change, give the position precedence and
88  // switch the mode back to "samples"
90  quint64 p = time->samplesToTime(
91  Kwave::SelectTimeWidget::bySamples, pos, rate, length);
92  sample_index_t s = time->timeToSamples(mode, p, rate, length);
93  if (s != pos) return;
94  }
95 
96  // else: precise enough, use the previous mode
97  time->setMode(mode);
98 }
99 
100 //***************************************************************************
102 {
103  Q_ASSERT(edDescription);
104  if (edDescription) edDescription->setText(name);
105 }
106 
107 //***************************************************************************
109 {
110  Q_ASSERT(time);
111  return (time) ? time->samples() : 0;
112 }
113 
114 //***************************************************************************
116 {
117  Q_ASSERT(edDescription);
118  return (edDescription) ? edDescription->text() : _("");
119 }
120 
121 //***************************************************************************
123 {
124  // restore the previous selection mode and set it
125  KConfigGroup cfg = KSharedConfig::openConfig()->group(CONFIG_SECTION);
126  QString str;
127  str.setNum(static_cast<int>(time->mode()));
128  cfg.writeEntry("mode", str);
129  cfg.sync();
130 }
131 
132 //***************************************************************************
133 //***************************************************************************
virtual void setLabelPosition(sample_index_t pos, sample_index_t length, double rate)
quint64 sample_index_t
Definition: Sample.h:28
const char name[16]
Definition: memcpy.c:510
#define CONFIG_SECTION
virtual sample_index_t labelPosition()
#define _(m)
Definition: memcpy.c:66
virtual void setLabelIndex(unsigned int index)
virtual void setLabelName(const QString &name)