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 #define RG_MODULE_STRING "[ConfigureDialogBase]"
19 
20 #include "ConfigureDialogBase.h"
21 
22 #include "gui/configuration/TabbedConfigurationPage.h"
23 #include "gui/widgets/IconStackedWidget.h"
24 #include "misc/Debug.h"
25 
26 #include <QDialog>
27 #include <QDialogButtonBox>
28 #include <QString>
29 #include <QWidget>
30 #include <QTabWidget>
31 #include <QPushButton>
32 #include <QMessageBox>
33 #include <QVBoxLayout>
34 #include <QHBoxLayout>
35 #include <QLabel>
36 #include <QUrl>
37 #include <QDesktopServices>
38 
39 namespace Rosegarden
40 {
41 
42 
ConfigureDialogBase(QWidget * parent,const QString & label,const char * name)43 ConfigureDialogBase::ConfigureDialogBase(QWidget *parent, const QString &label, const char *name  )
44 : QDialog(parent)
45 {
46     this->setAttribute( Qt::WA_DeleteOnClose );
47 
48     this->setWindowTitle(label);
49     this->setObjectName( (name) );
50 
51     QVBoxLayout *dlgLayout = new QVBoxLayout(this);
52 //    dlgLayout->setMargin(0);
53 
54     m_iconWidget = new IconStackedWidget(this);
55     dlgLayout->addWidget(m_iconWidget);
56 
57     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Apply  |
58                                                        QDialogButtonBox::Ok     |
59                                                        QDialogButtonBox::Cancel |
60                                                        QDialogButtonBox::Help);
61     dlgLayout->addWidget(buttonBox);
62 
63     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
64     connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigureDialogBase::slotCancelOrClose);
65     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &ConfigureDialogBase::slotHelpRequested );
66 
67     m_applyButton = buttonBox->button(QDialogButtonBox::Apply);
68     m_applyButton->setEnabled(false);
69     connect(m_applyButton, &QAbstractButton::clicked, this, &ConfigureDialogBase::slotApply);
70 
71 }
72 
73 // ConfigureDialogBase::addPage(const QString& name, const QString& title, const QPixmap& icon, QWidget *page)
74 // where:
75 // name - The name written in the page select icon button
76 // title - The title placed at the top of the configuration page
77 // icon - The icon shown on the page select icon button
78 // page - pointer to a configuration page widget
addPage(const QString & name,const QString & title,const QPixmap & icon,QWidget * page)79 void ConfigureDialogBase::addPage(const QString& name, const QString& title, const QPixmap& icon, QWidget *page)
80 {
81     // New widget to hold the title, dividing line and configuration page
82     QWidget * titledPage = new QWidget(this);
83     QLayout * pageLayout = new QVBoxLayout(titledPage);
84     pageLayout->setContentsMargins(0, 0, 0, 0);
85 
86     // Create the title label widget for the configration page
87     QLabel * titleLabel = new QLabel(title, titledPage);
88     QFont font;
89     font.setBold(true);
90     font.setPixelSize(12);
91     titleLabel->setFont(font);
92 
93     // Create the dividing line
94     QFrame * divideLine = new QFrame(titledPage);
95     divideLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
96     divideLine->setLineWidth(2);
97 
98     // Add these widgets to the layout
99     pageLayout->addWidget(titleLabel);
100     pageLayout->addWidget(divideLine);
101     pageLayout->addWidget(page);
102 
103     // Add the page to the IconStackedWidgget (creating the select button)
104     m_iconWidget->addPage(name, titledPage, icon);
105 }
106 
107 
~ConfigureDialogBase()108 ConfigureDialogBase::~ConfigureDialogBase()
109 {}
110 
111 
112 void
slotApply()113 ConfigureDialogBase::slotApply()
114 {
115     RG_DEBUG << "CONFIGUREDIALOGBASE SLOTAPPLY()";
116     for (ConfigurationPages::iterator i = m_configurationPages.begin();
117             i != m_configurationPages.end(); ++i)
118         (*i)->apply();
119 
120     m_applyButton->setEnabled(false);
121 }
122 
123 void
slotActivateApply()124 ConfigureDialogBase::slotActivateApply()
125 {
126     m_applyButton->setEnabled(true);
127 }
128 
129 void
deactivateApply()130 ConfigureDialogBase::deactivateApply()
131 {
132     m_applyButton->setEnabled(false);
133 }
134 
135 void
accept()136 ConfigureDialogBase::accept()
137 {
138     slotApply();
139     QDialog::accept();
140     close();
141 }
142 
143 void
slotCancelOrClose()144 ConfigureDialogBase::slotCancelOrClose()
145 {
146     close();
147 }
148 
149 void
slotHelpRequested()150 ConfigureDialogBase::slotHelpRequested()
151 {
152     // TRANSLATORS: if the manual is translated into your language, you can
153     // change the two-letter language code in this URL to point to your language
154     // version, eg. "http://rosegardenmusic.com/wiki/doc:configureDialogBase-es" for the
155     // Spanish version. If your language doesn't yet have a translation, feel
156     // free to create one.
157 
158 // Hrmmm...  What to do with this one?  Anything?  Obviously there's not going
159 // to be any specific help for a base class.
160 //    QString helpURL = tr("http://rosegardenmusic.com/wiki/doc:configureDialogBase-en");
161 //    QDesktopServices::openUrl(QUrl(helpURL));
162 }
163 
164 void
setPageByIndex(int index)165 ConfigureDialogBase::setPageByIndex(int index)
166 {
167     m_iconWidget->setPageByIndex(index);
168 }
169 
170 
171 }
172