annotate widgets/RangeInputDialog.cpp @ 1502:62aad7969f8b

Pass the cache pointer through rather than looking it up afresh from the model id for each column
author Chris Cannam
date Thu, 12 Sep 2019 11:53:17 +0100
parents 4edaff85875d
children
rev   line source
Chris@188 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@188 2
Chris@188 3 /*
Chris@188 4 Sonic Visualiser
Chris@188 5 An audio file viewer and annotation editor.
Chris@188 6 Centre for Digital Music, Queen Mary, University of London.
Chris@188 7 This file copyright 2007 QMUL.
Chris@188 8
Chris@188 9 This program is free software; you can redistribute it and/or
Chris@188 10 modify it under the terms of the GNU General Public License as
Chris@188 11 published by the Free Software Foundation; either version 2 of the
Chris@188 12 License, or (at your option) any later version. See the file
Chris@188 13 COPYING included with this distribution for more information.
Chris@188 14 */
Chris@188 15
Chris@188 16 #include "RangeInputDialog.h"
Chris@188 17
Chris@188 18 #include <QDoubleSpinBox>
Chris@188 19 #include <QGridLayout>
Chris@188 20 #include <QLabel>
Chris@188 21 #include <QHBoxLayout>
Chris@282 22 #include <QDialogButtonBox>
Chris@188 23 #include <QPushButton>
Chris@188 24
Chris@188 25 RangeInputDialog::RangeInputDialog(QString title, QString message,
Chris@188 26 QString unit, float min, float max,
Chris@188 27 QWidget *parent) :
Chris@188 28 QDialog(parent)
Chris@188 29 {
Chris@188 30 QGridLayout *grid = new QGridLayout;
Chris@188 31 setLayout(grid);
Chris@188 32
Chris@188 33 setWindowTitle(title);
Chris@188 34
Chris@188 35 QLabel *messageLabel = new QLabel;
Chris@188 36 messageLabel->setText(message);
Chris@188 37 grid->addWidget(messageLabel, 0, 0, 1, 5);
Chris@188 38
Chris@188 39 m_rangeStart = new QDoubleSpinBox;
Chris@188 40 m_rangeStart->setDecimals(4);
Chris@188 41 m_rangeStart->setMinimum(min);
Chris@188 42 m_rangeStart->setMaximum(max);
Chris@188 43 m_rangeStart->setSuffix(unit);
Chris@188 44 grid->addWidget(m_rangeStart, 1, 1);
Chris@188 45 connect(m_rangeStart, SIGNAL(valueChanged(double)),
Chris@188 46 this, SLOT(rangeStartChanged(double)));
Chris@188 47
Chris@188 48 grid->addWidget(new QLabel(tr(" to ")), 1, 2);
Chris@188 49
Chris@188 50 m_rangeEnd = new QDoubleSpinBox;
Chris@188 51 m_rangeEnd->setDecimals(4);
Chris@188 52 m_rangeEnd->setMinimum(min);
Chris@188 53 m_rangeEnd->setMaximum(max);
Chris@188 54 m_rangeEnd->setSuffix(unit);
Chris@188 55 grid->addWidget(m_rangeEnd, 1, 3);
Chris@188 56 connect(m_rangeEnd, SIGNAL(valueChanged(double)),
Chris@188 57 this, SLOT(rangeEndChanged(double)));
Chris@188 58
Chris@282 59 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@282 60 QDialogButtonBox::Cancel);
Chris@282 61 grid->addWidget(bb, 2, 0, 1, 5);
Chris@282 62 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@282 63 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@188 64 }
Chris@188 65
Chris@188 66 RangeInputDialog::~RangeInputDialog()
Chris@188 67 {
Chris@188 68 }
Chris@188 69
Chris@188 70 void
Chris@188 71 RangeInputDialog::getRange(float &min, float &max)
Chris@188 72 {
Chris@188 73 min = float(m_rangeStart->value());
Chris@188 74 max = float(m_rangeEnd->value());
Chris@188 75
Chris@188 76 if (min > max) {
Chris@188 77 float tmp = min;
Chris@188 78 min = max;
Chris@188 79 max = tmp;
Chris@188 80 }
Chris@188 81 }
Chris@188 82
Chris@188 83 void
Chris@188 84 RangeInputDialog::setRange(float start, float end)
Chris@188 85 {
Chris@188 86 if (start > end) {
Chris@188 87 float tmp = start;
Chris@188 88 start = end;
Chris@188 89 end = tmp;
Chris@188 90 }
Chris@188 91
Chris@188 92 blockSignals(true);
Chris@188 93 m_rangeStart->setValue(start);
Chris@188 94 m_rangeEnd->setValue(end);
Chris@188 95 blockSignals(false);
Chris@188 96 }
Chris@188 97
Chris@188 98 void
Chris@188 99 RangeInputDialog::rangeStartChanged(double min)
Chris@188 100 {
Chris@188 101 double max = m_rangeEnd->value();
Chris@188 102 if (min > max) {
Chris@188 103 double tmp = min;
Chris@188 104 min = max;
Chris@188 105 max = tmp;
Chris@188 106 }
Chris@188 107 emit rangeChanged(float(min), float(max));
Chris@188 108 }
Chris@188 109
Chris@188 110
Chris@188 111 void
Chris@188 112 RangeInputDialog::rangeEndChanged(double max)
Chris@188 113 {
Chris@188 114 double min = m_rangeStart->value();
Chris@188 115 if (min > max) {
Chris@188 116 double tmp = min;
Chris@188 117 min = max;
Chris@188 118 max = tmp;
Chris@188 119 }
Chris@188 120 emit rangeChanged(float(min), float(max));
Chris@188 121 }
Chris@188 122