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 "AddTracksDialog.h"
20
21 #include "misc/ConfigGroups.h"
22
23 #include <QDialog>
24 #include <QDialogButtonBox>
25 #include <QLabel>
26 #include <QSpinBox>
27 #include <QComboBox>
28 #include <QWidget>
29 #include <QVBoxLayout>
30 #include <QHBoxLayout>
31 #include <QSettings>
32 #include <QGroupBox>
33
34
35 namespace Rosegarden
36 {
37
AddTracksDialog(QWidget * parent,int currentTrack)38 AddTracksDialog::AddTracksDialog(QWidget *parent, int currentTrack) :
39 QDialog(parent),
40 m_currentTrack(currentTrack)
41 {
42 setModal(true);
43 setWindowTitle(tr("Add Tracks"));
44
45 QWidget *vBox = new QWidget(this);
46 QVBoxLayout *vBoxLayout = new QVBoxLayout;
47 setLayout(vBoxLayout);
48
49 // vBoxLayout->addWidget(new QLabel(tr("How many tracks do you want to add?")));
50
51 QGroupBox *gbox = new QGroupBox(tr("How many tracks do you want to add?"), vBox);
52 vBoxLayout->addWidget(gbox);
53
54 QVBoxLayout *gboxLayout = new QVBoxLayout;
55 gbox->setLayout(gboxLayout);
56
57 m_count = new QSpinBox();
58 gboxLayout->addWidget(m_count);
59 m_count->setMinimum(1);
60 m_count->setMaximum(256); // why not 256? 32 seemed like a silly upper bound
61 m_count->setValue(1);
62
63 QWidget *posBox = new QWidget(vBox);
64 gboxLayout->addWidget(posBox);
65
66 QHBoxLayout *posBoxLayout = new QHBoxLayout;
67 posBox->setLayout(posBoxLayout);
68
69 posBoxLayout->addWidget(new QLabel(tr("Add tracks")));
70
71 m_position = new QComboBox(posBox);
72 posBoxLayout->addWidget(m_position);
73 m_position->addItem(tr("At the top"));
74 m_position->addItem(tr("Above the current selected track"));
75 m_position->addItem(tr("Below the current selected track"));
76 m_position->addItem(tr("At the bottom"));
77
78 QString metric(tr("Above the current selected track"));
79 m_position->setMinimumContentsLength(metric.size());
80
81 QSettings settings;
82 settings.beginGroup(GeneralOptionsConfigGroup);
83
84 m_position->setCurrentIndex(settings.value("lastaddtracksposition", 2).toUInt());
85 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
86 vBoxLayout->addWidget(buttonBox);
87
88 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
89 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
90
91 settings.endGroup();
92 }
93
94 int
getTracks()95 AddTracksDialog::getTracks()
96 {
97 return m_count->value();
98 }
99
100 int
getInsertPosition()101 AddTracksDialog::getInsertPosition()
102 {
103 int opt = m_position->currentIndex();
104
105 QSettings settings;
106 settings.beginGroup( GeneralOptionsConfigGroup );
107
108 settings.setValue("lastaddtracksposition", opt);
109
110 int pos = 0;
111
112 switch (opt) {
113 case 0: // at top
114 pos = 0;
115 break;
116 case 1: // above current track
117 pos = m_currentTrack;
118 break;
119 case 2: // below current track
120 pos = m_currentTrack + 1;
121 break;
122 case 3: // at bottom
123 pos = -1;
124 break;
125 }
126
127 settings.endGroup();
128
129 return pos;
130 }
131
132 }
133