1 /*
2 * MidiSetupWidget - class for configuring midi sources in the settings window
3 *
4 * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25 #include "MidiSetupWidget.h"
26
27 #include <QLineEdit>
28
29 #include "ConfigManager.h"
30 #include "gui_templates.h"
31
MidiSetupWidget(const QString & caption,const QString & configSection,const QString & devName,QWidget * parent)32 MidiSetupWidget::MidiSetupWidget( const QString & caption, const QString & configSection,
33 const QString & devName, QWidget * parent ) :
34 TabWidget( TabWidget::tr( "Settings for %1" ).arg(
35 tr( caption.toLatin1() ) ).toUpper(), parent ),
36 m_configSection(configSection),
37 m_device(nullptr)
38 {
39 // supply devName=QString::Null() (distinct from QString(""))
40 // to indicate that there is no editable DEVICE field
41 if (!devName.isNull())
42 {
43 m_device = new QLineEdit( devName, this );
44 m_device->setGeometry( 10, 20, 160, 20 );
45
46 QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
47 dev_lbl->setFont( pointSize<7>( dev_lbl->font() ) );
48 dev_lbl->setGeometry( 10, 40, 160, 10 );
49 }
50 }
51
saveSettings()52 void MidiSetupWidget::saveSettings()
53 {
54 if (!m_configSection.isEmpty() && m_device)
55 {
56 ConfigManager::inst()->setValue( m_configSection, "device",
57 m_device->text() );
58 }
59 }
60
show()61 void MidiSetupWidget::show()
62 {
63 // the setup widget should only be visible if the device has some configurable attributes
64 bool visible = !m_configSection.isEmpty();
65 parentWidget()->setVisible(visible);
66 QWidget::setVisible(visible);
67 }
68
69