comparison widgets/Thumbwheel.cpp @ 382:06b5f110c5d2

* Speed up spectrogram painting by releasing mutex in FFTDataServer while calculating data prior to writing it, and by adding whole-column value query methods to FFT objects * Add paint cache to Thumbwheel -- repaints of this widget were slowing down the whole spectrogram repaint * More uses of MutexLocker (named and with debug) and more profile points * Make startup much quicker some of the time, with OSC server in place
author Chris Cannam
date Thu, 08 May 2008 14:46:22 +0000
parents c492902dba40
children e233627a923e
comparison
equal deleted inserted replaced
380:a6408c382616 382:06b5f110c5d2
127 127
128 m_default = deft; 128 m_default = deft;
129 if (m_atDefault) { 129 if (m_atDefault) {
130 setValue(m_default); 130 setValue(m_default);
131 m_atDefault = true; // setValue unsets this 131 m_atDefault = true; // setValue unsets this
132 m_cache = QImage();
132 emit valueChanged(getValue()); 133 emit valueChanged(getValue());
133 } 134 }
134 } 135 }
135 136
136 void 137 void
143 m_noMappedUpdate = true; 144 m_noMappedUpdate = true;
144 // std::cerr << "Thumbwheel::setMappedValue(" << mappedValue << "): new value is " << newValue << " (visible " << isVisible() << ")" << std::endl; 145 // std::cerr << "Thumbwheel::setMappedValue(" << mappedValue << "): new value is " << newValue << " (visible " << isVisible() << ")" << std::endl;
145 if (newValue != getValue()) { 146 if (newValue != getValue()) {
146 setValue(newValue); 147 setValue(newValue);
147 changed = true; 148 changed = true;
149 m_cache = QImage();
148 } 150 }
149 if (changed) emit valueChanged(newValue); 151 if (changed) emit valueChanged(newValue);
150 m_noMappedUpdate = false; 152 m_noMappedUpdate = false;
151 } else { 153 } else {
152 int v = int(mappedValue); 154 int v = int(mappedValue);
153 if (v != getValue()) { 155 if (v != getValue()) {
154 setValue(v); 156 setValue(v);
157 m_cache = QImage();
155 emit valueChanged(v); 158 emit valueChanged(v);
156 } 159 }
157 } 160 }
158 } 161 }
159 162
177 if (value > m_max) value = m_max; 180 if (value > m_max) value = m_max;
178 m_value = value; 181 m_value = value;
179 } 182 }
180 183
181 m_rotation = float(m_value - m_min) / float(m_max - m_min); 184 m_rotation = float(m_value - m_min) / float(m_max - m_min);
185 m_cache = QImage();
182 if (isVisible()) update(); 186 if (isVisible()) update();
183 } 187 }
184 188
185 void 189 void
186 Thumbwheel::resetToDefault() 190 Thumbwheel::resetToDefault()
187 { 191 {
188 if (m_default == m_value) return; 192 if (m_default == m_value) return;
189 setValue(m_default); 193 setValue(m_default);
190 m_atDefault = true; 194 m_atDefault = true;
195 m_cache = QImage();
191 emit valueChanged(getValue()); 196 emit valueChanged(getValue());
192 } 197 }
193 198
194 int 199 int
195 Thumbwheel::getValue() const 200 Thumbwheel::getValue() const
434 } 439 }
435 440
436 void 441 void
437 Thumbwheel::paintEvent(QPaintEvent *) 442 Thumbwheel::paintEvent(QPaintEvent *)
438 { 443 {
439 Profiler profiler("Thumbwheel::paintEvent", true); 444 Profiler profiler("Thumbwheel::paintEvent");
445
446 if (!m_cache.isNull()) {
447 QPainter paint(this);
448 paint.drawImage(0, 0, m_cache);
449 return;
450 }
451
452 Profiler profiler2("Thumbwheel::paintEvent (no cache)");
453
454 m_cache = QImage(size(), QImage::Format_ARGB32);
455 m_cache.fill(Qt::transparent);
440 456
441 int bw = 3; 457 int bw = 3;
442 458
443 QRect subclip; 459 QRect subclip;
444 if (m_orientation == Qt::Horizontal) { 460 if (m_orientation == Qt::Horizontal) {
445 subclip = QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2); 461 subclip = QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2);
446 } else { 462 } else {
447 subclip = QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2); 463 subclip = QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2);
448 } 464 }
449 465
450 QPainter paint(this); 466 QPainter paint(&m_cache);
467 paint.setClipRect(rect());
451 paint.fillRect(subclip, palette().background().color()); 468 paint.fillRect(subclip, palette().background().color());
452 469
453 paint.setRenderHint(QPainter::Antialiasing, true); 470 paint.setRenderHint(QPainter::Antialiasing, true);
454 471
455 float w = width(); 472 float w = width();
561 paint.drawRect(QRectF(x0, bw, x1 - x0, height() - bw*2)); 578 paint.drawRect(QRectF(x0, bw, x1 - x0, height() - bw*2));
562 } else { 579 } else {
563 paint.drawRect(QRectF(bw, x0, width() - bw*2, x1 - x0)); 580 paint.drawRect(QRectF(bw, x0, width() - bw*2, x1 - x0));
564 } 581 }
565 } 582 }
583
584 QPainter paint2(this);
585 paint2.drawImage(0, 0, m_cache);
566 } 586 }
567 587
568 QSize 588 QSize
569 Thumbwheel::sizeHint() const 589 Thumbwheel::sizeHint() const
570 { 590 {