1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A MIDI and audio sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7
8 Other copyrights also apply to some parts of this work. Please
9 see the AUTHORS file and individual file headers for details.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18
19 #include "CompositionLengthDialog.h"
20
21 #include "base/Composition.h"
22
23 #include <QDialog>
24 #include <QDialogButtonBox>
25 #include <QLabel>
26 #include <QSpinBox>
27 #include <QCheckBox>
28 #include <QWidget>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
31 #include <QGroupBox>
32
33
34 namespace Rosegarden
35 {
36
CompositionLengthDialog(QWidget * parent,Composition * composition)37 CompositionLengthDialog::CompositionLengthDialog(
38 QWidget *parent,
39 Composition *composition):
40 QDialog(parent),
41 m_composition(composition)
42 {
43 setModal(true);
44 setWindowTitle(tr("Change Composition Length"));
45
46 //###
47 // This note applies in many other places, but since this is the nth time
48 // I've gotten rid of the QWidget + metagrid + QWidget + layout paradigm, I
49 // thought I'd explain. We have a QWidget coming in here, the QDialog. We
50 // can set its layout. If we create something like a QFrame or a QGroupBox,
51 // we have a widget there, too, and can set that widget's layout. It won't
52 // be that often we really have to make a random QWidget just to hold a
53 // layout, and also there's no real need to have an overall grid layout just
54 // to contain sublayouts. We used to lay out most simple dialogs on an HBox
55 // or VBox, and we can still do that directly, without the extra
56 // complication.
57 QVBoxLayout *vboxLayout = new QVBoxLayout;
58 setLayout(vboxLayout);
59
60 vboxLayout->addWidget(new QLabel(tr("Change the start and end markers for the composition:")));
61
62 // GROUP BOX BEGIN
63
64 QGroupBox *gbox = new QGroupBox(this);
65 vboxLayout->addWidget(gbox);
66
67 QGridLayout *gboxLayout = new QGridLayout;
68 gboxLayout->setVerticalSpacing(10);
69 gbox->setLayout(gboxLayout);
70
71 // ROW 0, Start Bar
72
73 gboxLayout->addWidget(new QLabel(tr("Start Bar")), 0, 0);
74
75 m_startMarkerSpinBox = new QSpinBox(gbox);
76 m_startMarkerSpinBox->setMinimum( -10);
77 m_startMarkerSpinBox->setMaximum(10000);
78 m_startMarkerSpinBox->setValue(m_composition->getBarNumber(m_composition->getStartMarker()) + 1);
79 gboxLayout->addWidget(m_startMarkerSpinBox, 0, 1);
80
81 // ROW 1, End Bar
82
83 gboxLayout->addWidget(new QLabel(tr("End Bar")), 1, 0);
84
85 m_endMarkerSpinBox = new QSpinBox(gbox);
86 m_endMarkerSpinBox->setMinimum( -10);
87 m_endMarkerSpinBox->setMaximum(10000);
88 m_endMarkerSpinBox->setValue(m_composition->getBarNumber(m_composition->getEndMarker()));
89 gboxLayout->addWidget(m_endMarkerSpinBox, 1, 1);
90
91 // ROW 2, Auto-Expand when Editing
92
93 gboxLayout->addWidget(new QLabel(tr("Auto-Expand when Editing")), 2, 0);
94
95 m_autoExpandCheckBox = new QCheckBox(gbox);
96 m_autoExpandCheckBox->setChecked(m_composition->autoExpandEnabled());
97 gboxLayout->addWidget(m_autoExpandCheckBox, 2, 1);
98
99 // GROUP BOX END
100
101 // Now the button box on the bottom, outside the group box and any of the
102 // previous layouts, just gets added to the vbox under the QDialog widget
103 // we're coming in with. No overall grid layout required.
104 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
105 vboxLayout->addWidget(buttonBox);
106
107 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
108 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
109 }
110
111 timeT
getStartMarker()112 CompositionLengthDialog::getStartMarker()
113 {
114 return m_composition->getBarStart(m_startMarkerSpinBox->value() - 1);
115 }
116
117 timeT
getEndMarker()118 CompositionLengthDialog::getEndMarker()
119 {
120 return m_composition->getBarStart(m_endMarkerSpinBox->value());
121 }
122
123 bool
autoExpandEnabled()124 CompositionLengthDialog::autoExpandEnabled()
125 {
126 return m_autoExpandCheckBox->isChecked();
127 }
128
129 }
130