~ubuntu-branches/ubuntu/precise/fritzing/precise

« back to all changes in this revision

Viewing changes to src/utils/zoomslider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2011-08-26 10:11:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110826101105-w5hmn7zcf93ig5v6
Tags: 0.6.3b-1
* upgrapded to the newer upstream version
* parameters of the function GraphicsUtils::distanceFromLine in 
  src/svg/groundplanegenerator.cpp:767 are now declared as doubles,
  which Closes: #636441
* the new version fixes src/utils/folderutils.cpp, which
  Closes: #636061

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************
2
 
 
3
 
Part of the Fritzing project - http://fritzing.org
4
 
Copyright (c) 2007-2010 Fachhochschule Potsdam - http://fh-potsdam.de
5
 
 
6
 
Fritzing is free software: you can redistribute it and/or modify
7
 
it under the terms of the GNU General Public License as published by
8
 
the Free Software Foundation, either version 3 of the License, or
9
 
(at your option) any later version.
10
 
 
11
 
Fritzing is distributed in the hope that it will be useful,
12
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
GNU General Public License for more details.
15
 
 
16
 
You should have received a copy of the GNU General Public License
17
 
along with Fritzing.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
********************************************************************
20
 
 
21
 
$Revision: 5153 $:
22
 
$Author: cohen@irascible.com $:
23
 
$Date: 2011-07-02 00:46:20 +0200 (Sat, 02 Jul 2011) $
24
 
 
25
 
********************************************************************/
26
 
 
27
 
#include <QLineEdit>
28
 
#include <QKeyEvent>
29
 
#include <QFile>
30
 
#include <QTextStream>
31
 
#include <QTimer>
32
 
#include <QHBoxLayout>
33
 
#include <QValidator>
34
 
#include <QLabel>
35
 
#include <limits>
36
 
 
37
 
#include "zoomslider.h"
38
 
#include "../debugdialog.h"
39
 
 
40
 
qreal ZoomSlider::ZoomStep;
41
 
QList<qreal> ZoomSlider::ZoomFactors;
42
 
 
43
 
static const int MIN_VALUE = 10;
44
 
static const int MAX_VALUE = 2010;
45
 
static const int STARTING_VALUE = 100;
46
 
static const int HEIGHT = 16;
47
 
static const int STEP = 100;
48
 
 
49
 
static int AutoRepeatDelay = 0;
50
 
static int AutoRepeatInterval = 0;
51
 
 
52
 
///////////////////////////////////////////////
53
 
 
54
 
ZoomLabel::ZoomLabel(QWidget * parent) : QLabel(parent)
55
 
{
56
 
        if (AutoRepeatDelay == 0) {
57
 
                QPushButton button;
58
 
                AutoRepeatInterval = button.autoRepeatInterval();
59
 
                AutoRepeatDelay = button.autoRepeatDelay();
60
 
        }
61
 
        m_autoRepeat = m_mouseIsDown = m_mouseIsIn = m_repeated = false;
62
 
        m_timer.setSingleShot(false);
63
 
        m_timer.setInterval(AutoRepeatInterval);
64
 
        connect(&m_timer, SIGNAL(timeout()), this, SLOT(repeat()));
65
 
}
66
 
 
67
 
ZoomLabel::~ZoomLabel()
68
 
{
69
 
}
70
 
 
71
 
void ZoomLabel::setAutoRepeat(bool autoRepeat)
72
 
{
73
 
        m_autoRepeat = autoRepeat;
74
 
}
75
 
 
76
 
void ZoomLabel::setImages(const QString & normal, const QString & pressed)
77
 
{
78
 
        m_normal.load(normal);
79
 
        m_pressed.load(pressed);
80
 
        setPixmap(m_normal);
81
 
}
82
 
 
83
 
 
84
 
void ZoomLabel::repeat()
85
 
{
86
 
        if (m_mouseIsIn && m_mouseIsDown) {
87
 
                m_repeated = true;      
88
 
                emit clicked();
89
 
        }
90
 
}
91
 
 
92
 
void ZoomLabel::mousePressEvent(QMouseEvent * event)
93
 
{
94
 
        m_timer.stop();
95
 
        this->setMouseTracking(true);
96
 
        this->setPixmap(m_pressed);
97
 
        QLabel::mousePressEvent(event);
98
 
        m_mouseIsDown = m_mouseIsIn = true;
99
 
        m_repeated = false;
100
 
        if (m_autoRepeat) {
101
 
                m_timer.start(AutoRepeatDelay);
102
 
        }
103
 
}
104
 
 
105
 
void ZoomLabel::mouseMoveEvent(QMouseEvent * event)
106
 
{
107
 
        QLabel::mouseMoveEvent(event);
108
 
        if (m_mouseIsDown) {
109
 
                QPoint p = event->pos();
110
 
                bool mouseIsIn = p.x() >= 0 && p.y() >= 0 && p.x() <= width() && p.y() <= height();
111
 
                if (m_mouseIsIn && !mouseIsIn) {
112
 
                        m_timer.stop();
113
 
                        this->setPixmap(m_normal);
114
 
                        m_mouseIsIn = false;
115
 
                }
116
 
                else if (!m_mouseIsIn && mouseIsIn) {
117
 
                        this->setPixmap(m_pressed);
118
 
                        m_mouseIsIn = true;
119
 
                        m_timer.start(AutoRepeatDelay);
120
 
                }
121
 
        }
122
 
}
123
 
 
124
 
void ZoomLabel::mouseReleaseEvent(QMouseEvent * event)
125
 
{
126
 
        m_timer.stop();
127
 
        this->setMouseTracking(false);
128
 
        m_mouseIsDown = false;
129
 
        this->setPixmap(m_normal);
130
 
        QLabel::mouseReleaseEvent(event);
131
 
        if (!m_repeated && m_mouseIsIn) {
132
 
                emit clicked();
133
 
        }
134
 
}
135
 
 
136
 
/////////////////////////////////////////////
137
 
 
138
 
ZoomSlider::ZoomSlider(QWidget * parent) : QFrame(parent) 
139
 
{
140
 
        // layout doesn't seem to work: the slider appears too far down in the status bar
141
 
        // because the status bar layout is privileged for the message text
142
 
 
143
 
        m_firstTime = true;
144
 
        if (ZoomFactors.size() == 0) {
145
 
                loadFactors();
146
 
        }
147
 
 
148
 
        this->setObjectName("ZoomSliderFrame");
149
 
 
150
 
 
151
 
        m_lineEdit = new QLineEdit(this);
152
 
    m_lineEdit->setObjectName("ZoomSliderValue");
153
 
        m_lineEdit->setText(QString("%1").arg(STARTING_VALUE));
154
 
        m_lineEdit->setValidator(new QIntValidator(MIN_VALUE, MAX_VALUE, this));
155
 
        m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, 0);
156
 
        m_lineEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
157
 
 
158
 
    m_suffix = new QLabel(tr("%"), this);
159
 
    m_suffix->setObjectName("ZoomSliderLabel");
160
 
 
161
 
    m_minusButton = new ZoomLabel(this);
162
 
        m_minusButton->setImages(":/resources/images/icons/zoomSliderMinus.png", ":/resources/images/icons/zoomSliderMinusPressed.png");
163
 
    m_minusButton->setAutoRepeat(true);
164
 
        m_minusButton->setObjectName("ZoomSliderButton");
165
 
        connect(m_minusButton, SIGNAL(clicked()), this, SLOT(minusClicked()));
166
 
 
167
 
    m_slider = new QSlider(this);
168
 
        m_slider->setObjectName("ZoomSliderSlider");
169
 
        m_slider->setOrientation(Qt::Horizontal);
170
 
        m_slider->setRange(MIN_VALUE, MAX_VALUE);
171
 
        m_slider->setValue(STARTING_VALUE);
172
 
    m_slider->setTickPosition(QSlider::TicksBelow);
173
 
    m_slider->setTickInterval(500);
174
 
 
175
 
    m_plusButton = new ZoomLabel(this);
176
 
        m_plusButton->setImages(":/resources/images/icons/zoomSliderPlus.png", ":/resources/images/icons/zoomSliderPlusPressed.png");
177
 
    m_plusButton->setAutoRepeat(true);
178
 
        m_plusButton->setObjectName("ZoomSliderButton");
179
 
        connect(m_plusButton, SIGNAL(clicked()), this, SLOT(plusClicked()));
180
 
 
181
 
        connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
182
 
        connect(m_lineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(sliderTextEdited(const QString &)));
183
 
 
184
 
        //m_userStillWriting = false;
185
 
 
186
 
        //m_valueBackup = editText();
187
 
        //m_indexBackup = itemIndex(m_valueBackup);
188
 
}
189
 
 
190
 
void ZoomSlider::loadFactors() {
191
 
        QFile file(":/resources/zoomfactors.txt");
192
 
        file.open(QFile::ReadOnly);
193
 
        QTextStream stream( &file );
194
 
        int lineNumber = 0;
195
 
        while(!stream.atEnd()) {
196
 
                QString line = stream.readLine();
197
 
                if(lineNumber != 0) {
198
 
                        ZoomFactors << line.toDouble();
199
 
                } 
200
 
                else 
201
 
                {
202
 
                        ZoomStep = line.toDouble();
203
 
                }
204
 
                lineNumber++;
205
 
        }
206
 
        file.close();
207
 
}
208
 
 
209
 
 
210
 
void ZoomSlider::setValue(qreal value) {
211
 
        QString newText = QString("%1").arg(qRound(value));
212
 
        m_lineEdit->setText(newText);
213
 
        sliderTextEdited(newText, false);
214
 
}
215
 
 
216
 
qreal ZoomSlider::value() {
217
 
        return m_lineEdit->text().toDouble();
218
 
}
219
 
 
220
 
void ZoomSlider::minusClicked() {
221
 
        step(-1);
222
 
}
223
 
 
224
 
void ZoomSlider::plusClicked() {
225
 
        step(1);
226
 
}
227
 
 
228
 
void ZoomSlider::step(int direction) {
229
 
        int minIndex = 0;
230
 
        qreal minDiff = std::numeric_limits<double>::max();
231
 
        qreal v = value();
232
 
        for (int i = 0; i < ZoomFactors.count(); i++) {
233
 
                qreal f = ZoomFactors[i];
234
 
                if (qAbs(f - v) < minDiff) {
235
 
                        minDiff = qAbs(f - v);
236
 
                        minIndex = i;
237
 
                }
238
 
        }
239
 
 
240
 
        minIndex += direction;
241
 
        if (minIndex < 0) {
242
 
                minIndex = 0;
243
 
        }
244
 
        else if (minIndex >= ZoomFactors.count()) {
245
 
                minIndex = ZoomFactors.count() - 1;
246
 
        }
247
 
 
248
 
        setValue(ZoomFactors[minIndex]);
249
 
        emit zoomChanged(ZoomFactors[minIndex]);
250
 
}
251
 
 
252
 
void ZoomSlider::sliderValueChanged(int newValue) {
253
 
        newValue = (newValue / 10) * 10;                                        // make it so moving the slider outputs nice rounded values
254
 
        QString newText = QString("%1").arg(newValue);
255
 
        if (newText.compare(m_lineEdit->text()) != 0) {
256
 
                m_lineEdit->setText(newText);
257
 
                emit zoomChanged(newValue);
258
 
        }
259
 
}
260
 
 
261
 
void ZoomSlider::sliderTextEdited(const QString & newText) {
262
 
        sliderTextEdited(newText, true);
263
 
}
264
 
 
265
 
void ZoomSlider::sliderTextEdited(const QString & newText, bool doEmit) 
266
 
{
267
 
        int value = newText.toInt();
268
 
        if (m_slider->value() != value) {
269
 
                disconnect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
270
 
                m_slider->setValue(value);
271
 
                connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
272
 
                if (doEmit) emit zoomChanged(value);
273
 
        }
274
 
}
275
 
 
276
 
void ZoomSlider::zoomIn () {
277
 
        plusClicked();
278
 
}
279
 
 
280
 
void ZoomSlider::zoomOut () {
281
 
        minusClicked();
282
 
}
283
 
 
284
 
void ZoomSlider::showEvent(QShowEvent * event) 
285
 
{
286
 
        // can't get QHLayout to work, so shoving widgets into place here
287
 
        // because widths aren't set at constructor time
288
 
        QFrame::showEvent(event);
289
 
        if (m_firstTime) {
290
 
                m_firstTime = false;
291
 
                int soFar = 0;
292
 
                m_lineEdit->move(soFar, -2);
293
 
                soFar += m_lineEdit->width();
294
 
                m_suffix->move(soFar, 0);
295
 
                soFar += m_suffix->width();
296
 
                m_minusButton->move(soFar, 0);
297
 
                soFar += m_minusButton->width();
298
 
                m_slider->move(soFar, 0);
299
 
                soFar += m_slider->width();
300
 
                m_plusButton->move(soFar, 0);
301
 
        }
302
 
}
 
1
/*******************************************************************
 
2
 
 
3
Part of the Fritzing project - http://fritzing.org
 
4
Copyright (c) 2007-2011 Fachhochschule Potsdam - http://fh-potsdam.de
 
5
 
 
6
Fritzing is free software: you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation, either version 3 of the License, or
 
9
(at your option) any later version.
 
10
 
 
11
Fritzing is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with Fritzing.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
********************************************************************
 
20
 
 
21
$Revision: 5309 $:
 
22
$Author: cohen@irascible.com $:
 
23
$Date: 2011-07-30 21:17:22 +0200 (Sat, 30 Jul 2011) $
 
24
 
 
25
********************************************************************/
 
26
 
 
27
#include <QLineEdit>
 
28
#include <QKeyEvent>
 
29
#include <QFile>
 
30
#include <QTextStream>
 
31
#include <QTimer>
 
32
#include <QHBoxLayout>
 
33
#include <QValidator>
 
34
#include <QLabel>
 
35
#include <limits>
 
36
 
 
37
#include "zoomslider.h"
 
38
#include "../debugdialog.h"
 
39
 
 
40
double ZoomSlider::ZoomStep;
 
41
QList<double> ZoomSlider::ZoomFactors;
 
42
 
 
43
static const int MIN_VALUE = 10;
 
44
static const int MAX_VALUE = 2010;
 
45
static const int STARTING_VALUE = 100;
 
46
static const int HEIGHT = 16;
 
47
static const int STEP = 100;
 
48
 
 
49
static int AutoRepeatDelay = 0;
 
50
static int AutoRepeatInterval = 0;
 
51
 
 
52
///////////////////////////////////////////////
 
53
 
 
54
ZoomLabel::ZoomLabel(QWidget * parent) : QLabel(parent)
 
55
{
 
56
        if (AutoRepeatDelay == 0) {
 
57
                QPushButton button;
 
58
                AutoRepeatInterval = button.autoRepeatInterval();
 
59
                AutoRepeatDelay = button.autoRepeatDelay();
 
60
        }
 
61
        m_autoRepeat = m_mouseIsDown = m_mouseIsIn = m_repeated = false;
 
62
        m_timer.setSingleShot(false);
 
63
        m_timer.setInterval(AutoRepeatInterval);
 
64
        connect(&m_timer, SIGNAL(timeout()), this, SLOT(repeat()));
 
65
}
 
66
 
 
67
ZoomLabel::~ZoomLabel()
 
68
{
 
69
}
 
70
 
 
71
void ZoomLabel::setAutoRepeat(bool autoRepeat)
 
72
{
 
73
        m_autoRepeat = autoRepeat;
 
74
}
 
75
 
 
76
void ZoomLabel::setImages(const QString & normal, const QString & pressed)
 
77
{
 
78
        m_normal.load(normal);
 
79
        m_pressed.load(pressed);
 
80
        setPixmap(m_normal);
 
81
}
 
82
 
 
83
 
 
84
void ZoomLabel::repeat()
 
85
{
 
86
        if (m_mouseIsIn && m_mouseIsDown) {
 
87
                m_repeated = true;      
 
88
                emit clicked();
 
89
        }
 
90
}
 
91
 
 
92
void ZoomLabel::mousePressEvent(QMouseEvent * event)
 
93
{
 
94
        m_timer.stop();
 
95
        this->setMouseTracking(true);
 
96
        this->setPixmap(m_pressed);
 
97
        QLabel::mousePressEvent(event);
 
98
        m_mouseIsDown = m_mouseIsIn = true;
 
99
        m_repeated = false;
 
100
        if (m_autoRepeat) {
 
101
                m_timer.start(AutoRepeatDelay);
 
102
        }
 
103
}
 
104
 
 
105
void ZoomLabel::mouseMoveEvent(QMouseEvent * event)
 
106
{
 
107
        QLabel::mouseMoveEvent(event);
 
108
        if (m_mouseIsDown) {
 
109
                QPoint p = event->pos();
 
110
                bool mouseIsIn = p.x() >= 0 && p.y() >= 0 && p.x() <= width() && p.y() <= height();
 
111
                if (m_mouseIsIn && !mouseIsIn) {
 
112
                        m_timer.stop();
 
113
                        this->setPixmap(m_normal);
 
114
                        m_mouseIsIn = false;
 
115
                }
 
116
                else if (!m_mouseIsIn && mouseIsIn) {
 
117
                        this->setPixmap(m_pressed);
 
118
                        m_mouseIsIn = true;
 
119
                        m_timer.start(AutoRepeatDelay);
 
120
                }
 
121
        }
 
122
}
 
123
 
 
124
void ZoomLabel::mouseReleaseEvent(QMouseEvent * event)
 
125
{
 
126
        m_timer.stop();
 
127
        this->setMouseTracking(false);
 
128
        m_mouseIsDown = false;
 
129
        this->setPixmap(m_normal);
 
130
        QLabel::mouseReleaseEvent(event);
 
131
        if (!m_repeated && m_mouseIsIn) {
 
132
                emit clicked();
 
133
        }
 
134
}
 
135
 
 
136
/////////////////////////////////////////////
 
137
 
 
138
ZoomSlider::ZoomSlider(QWidget * parent) : QFrame(parent) 
 
139
{
 
140
        // layout doesn't seem to work: the slider appears too far down in the status bar
 
141
        // because the status bar layout is privileged for the message text
 
142
 
 
143
        m_firstTime = true;
 
144
        if (ZoomFactors.size() == 0) {
 
145
                loadFactors();
 
146
        }
 
147
 
 
148
        this->setObjectName("ZoomSliderFrame");
 
149
 
 
150
 
 
151
        m_lineEdit = new QLineEdit(this);
 
152
    m_lineEdit->setObjectName("ZoomSliderValue");
 
153
        m_lineEdit->setText(QString("%1").arg(STARTING_VALUE));
 
154
        m_lineEdit->setValidator(new QIntValidator(MIN_VALUE, MAX_VALUE, this));
 
155
        m_lineEdit->setAttribute(Qt::WA_MacShowFocusRect, 0);
 
156
        m_lineEdit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
 
157
 
 
158
    m_suffix = new QLabel(tr("%"), this);
 
159
    m_suffix->setObjectName("ZoomSliderLabel");
 
160
 
 
161
    m_minusButton = new ZoomLabel(this);
 
162
        m_minusButton->setImages(":/resources/images/icons/zoomSliderMinus.png", ":/resources/images/icons/zoomSliderMinusPressed.png");
 
163
    m_minusButton->setAutoRepeat(true);
 
164
        m_minusButton->setObjectName("ZoomSliderButton");
 
165
        connect(m_minusButton, SIGNAL(clicked()), this, SLOT(minusClicked()));
 
166
 
 
167
    m_slider = new QSlider(this);
 
168
        m_slider->setObjectName("ZoomSliderSlider");
 
169
        m_slider->setOrientation(Qt::Horizontal);
 
170
        m_slider->setRange(MIN_VALUE, MAX_VALUE);
 
171
        m_slider->setValue(STARTING_VALUE);
 
172
    m_slider->setTickPosition(QSlider::TicksBelow);
 
173
    m_slider->setTickInterval(500);
 
174
 
 
175
    m_plusButton = new ZoomLabel(this);
 
176
        m_plusButton->setImages(":/resources/images/icons/zoomSliderPlus.png", ":/resources/images/icons/zoomSliderPlusPressed.png");
 
177
    m_plusButton->setAutoRepeat(true);
 
178
        m_plusButton->setObjectName("ZoomSliderButton");
 
179
        connect(m_plusButton, SIGNAL(clicked()), this, SLOT(plusClicked()));
 
180
 
 
181
        connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
 
182
        connect(m_lineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(sliderTextEdited(const QString &)));
 
183
 
 
184
        //m_userStillWriting = false;
 
185
 
 
186
        //m_valueBackup = editText();
 
187
        //m_indexBackup = itemIndex(m_valueBackup);
 
188
}
 
189
 
 
190
void ZoomSlider::loadFactors() {
 
191
        QFile file(":/resources/zoomfactors.txt");
 
192
        file.open(QFile::ReadOnly);
 
193
        QTextStream stream( &file );
 
194
        int lineNumber = 0;
 
195
        while(!stream.atEnd()) {
 
196
                QString line = stream.readLine();
 
197
                if(lineNumber != 0) {
 
198
                        ZoomFactors << line.toDouble();
 
199
                } 
 
200
                else 
 
201
                {
 
202
                        ZoomStep = line.toDouble();
 
203
                }
 
204
                lineNumber++;
 
205
        }
 
206
        file.close();
 
207
}
 
208
 
 
209
 
 
210
void ZoomSlider::setValue(double value) {
 
211
        QString newText = QString("%1").arg(qRound(value));
 
212
        m_lineEdit->setText(newText);
 
213
        sliderTextEdited(newText, false);
 
214
}
 
215
 
 
216
double ZoomSlider::value() {
 
217
        return m_lineEdit->text().toDouble();
 
218
}
 
219
 
 
220
void ZoomSlider::minusClicked() {
 
221
        step(-1);
 
222
}
 
223
 
 
224
void ZoomSlider::plusClicked() {
 
225
        step(1);
 
226
}
 
227
 
 
228
void ZoomSlider::step(int direction) {
 
229
        int minIndex = 0;
 
230
        double minDiff = std::numeric_limits<double>::max();
 
231
        double v = value();
 
232
        for (int i = 0; i < ZoomFactors.count(); i++) {
 
233
                double f = ZoomFactors[i];
 
234
                if (qAbs(f - v) < minDiff) {
 
235
                        minDiff = qAbs(f - v);
 
236
                        minIndex = i;
 
237
                }
 
238
        }
 
239
 
 
240
        minIndex += direction;
 
241
        if (minIndex < 0) {
 
242
                minIndex = 0;
 
243
        }
 
244
        else if (minIndex >= ZoomFactors.count()) {
 
245
                minIndex = ZoomFactors.count() - 1;
 
246
        }
 
247
 
 
248
        setValue(ZoomFactors[minIndex]);
 
249
        emit zoomChanged(ZoomFactors[minIndex]);
 
250
}
 
251
 
 
252
void ZoomSlider::sliderValueChanged(int newValue) {
 
253
        newValue = (newValue / 10) * 10;                                        // make it so moving the slider outputs nice rounded values
 
254
        QString newText = QString("%1").arg(newValue);
 
255
        if (newText.compare(m_lineEdit->text()) != 0) {
 
256
                m_lineEdit->setText(newText);
 
257
                emit zoomChanged(newValue);
 
258
        }
 
259
}
 
260
 
 
261
void ZoomSlider::sliderTextEdited(const QString & newText) {
 
262
        sliderTextEdited(newText, true);
 
263
}
 
264
 
 
265
void ZoomSlider::sliderTextEdited(const QString & newText, bool doEmit) 
 
266
{
 
267
        int value = newText.toInt();
 
268
        if (m_slider->value() != value) {
 
269
                disconnect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
 
270
                m_slider->setValue(value);
 
271
                connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
 
272
                if (doEmit) emit zoomChanged(value);
 
273
        }
 
274
}
 
275
 
 
276
void ZoomSlider::zoomIn () {
 
277
        plusClicked();
 
278
}
 
279
 
 
280
void ZoomSlider::zoomOut () {
 
281
        minusClicked();
 
282
}
 
283
 
 
284
void ZoomSlider::showEvent(QShowEvent * event) 
 
285
{
 
286
        // can't get QHLayout to work, so shoving widgets into place here
 
287
        // because widths aren't set at constructor time
 
288
        QFrame::showEvent(event);
 
289
        if (m_firstTime) {
 
290
                m_firstTime = false;
 
291
                int soFar = 0;
 
292
                m_lineEdit->move(soFar, -2);
 
293
                soFar += m_lineEdit->width();
 
294
                m_suffix->move(soFar, 0);
 
295
                soFar += m_suffix->width();
 
296
                m_minusButton->move(soFar, 0);
 
297
                soFar += m_minusButton->width();
 
298
                m_slider->move(soFar, 0);
 
299
                soFar += m_slider->width();
 
300
                m_plusButton->move(soFar, 0);
 
301
        }
 
302
}