PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/rosegarden-12.04/src/gui/dialogs/ConfigureDialogBase.cpp

#
C++ | 165 lines | 96 code | 33 blank | 36 comment | 2 complexity | 39e0509cb403ae00b42bcd134f0d32ba MD5 | raw file
Possible License(s): GPL-2.0
  1. /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
  2. /*
  3. Rosegarden
  4. A MIDI and audio sequencer and musical notation editor.
  5. Copyright 2000-2012 the Rosegarden development team.
  6. Other copyrights also apply to some parts of this work. Please
  7. see the AUTHORS file and individual file headers for details.
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version. See the file
  12. COPYING included with this distribution for more information.
  13. */
  14. #include "ConfigureDialogBase.h"
  15. #include "gui/configuration/ConfigurationPage.h"
  16. #include "gui/widgets/IconStackedWidget.h"
  17. #include "misc/Debug.h"
  18. #include <QDialog>
  19. #include <QDialogButtonBox>
  20. #include <QString>
  21. #include <QWidget>
  22. #include <QTabWidget>
  23. #include <QPushButton>
  24. #include <QMessageBox>
  25. #include <QVBoxLayout>
  26. #include <QHBoxLayout>
  27. #include <QLabel>
  28. #include <QUrl>
  29. #include <QDesktopServices>
  30. namespace Rosegarden
  31. {
  32. ConfigureDialogBase::ConfigureDialogBase(QWidget *parent, QString label, const char *name )
  33. : QDialog(parent)
  34. {
  35. this->setAttribute( Qt::WA_DeleteOnClose );
  36. this->setWindowTitle( tr("Configure Rosegarden") );
  37. this->setObjectName( (name) );
  38. QVBoxLayout *dlgLayout = new QVBoxLayout(this);
  39. // dlgLayout->setMargin(0);
  40. m_iconWidget = new IconStackedWidget(this);
  41. dlgLayout->addWidget(m_iconWidget);
  42. QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Apply |
  43. QDialogButtonBox::Ok |
  44. QDialogButtonBox::Cancel |
  45. QDialogButtonBox::Help);
  46. dlgLayout->addWidget(buttonBox);
  47. connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  48. connect(buttonBox, SIGNAL(rejected()), this, SLOT(slotCancelOrClose()));
  49. connect(buttonBox, SIGNAL( helpRequested() ), this, SLOT ( slotHelpRequested() ) );
  50. m_applyButton = buttonBox->button(QDialogButtonBox::Apply);
  51. m_applyButton->setEnabled(false);
  52. connect(m_applyButton, SIGNAL(clicked()), this, SLOT(slotApply()));
  53. }
  54. // ConfigureDialogBase::addPage(const QString& name, const QString& title, const QPixmap& icon, QWidget *page)
  55. // where:
  56. // name - The name written in the page select icon button
  57. // title - The title placed at the top of the configuration page
  58. // icon - The icon shown on the page select icon button
  59. // page - pointer to a configuration page widget
  60. void ConfigureDialogBase::addPage(const QString& name, const QString& title, const QPixmap& icon, QWidget *page)
  61. {
  62. // New widget to hold the title, dividing line and configuration page
  63. QWidget * titledPage = new QWidget(this);
  64. QLayout * pageLayout = new QVBoxLayout(titledPage);
  65. pageLayout->setMargin(0);
  66. // Create the title label widget for the configration page
  67. QLabel * titleLabel = new QLabel(title, titledPage);
  68. QFont font;
  69. font.setBold(true);
  70. font.setPixelSize(12);
  71. titleLabel->setFont(font);
  72. // Create the dividing line
  73. QFrame * divideLine = new QFrame(titledPage);
  74. divideLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
  75. divideLine->setLineWidth(2);
  76. // Add these widgets to the layout
  77. pageLayout->addWidget(titleLabel);
  78. pageLayout->addWidget(divideLine);
  79. pageLayout->addWidget(page);
  80. // Add the page to the IconStackedWidgget (creating the select button)
  81. m_iconWidget->addPage(name, titledPage, icon);
  82. }
  83. ConfigureDialogBase::~ConfigureDialogBase()
  84. {}
  85. void
  86. ConfigureDialogBase::slotApply()
  87. {
  88. RG_DEBUG << "CONFIGUREDIALOGBASE SLOTAPPLY()" << endl;
  89. for (configurationpages::iterator i = m_configurationPages.begin();
  90. i != m_configurationPages.end(); ++i)
  91. (*i)->apply();
  92. m_applyButton->setEnabled(false);
  93. }
  94. void
  95. ConfigureDialogBase::slotActivateApply()
  96. {
  97. m_applyButton->setEnabled(true);
  98. }
  99. void
  100. ConfigureDialogBase::accept()
  101. {
  102. slotApply();
  103. QDialog::accept();
  104. close();
  105. }
  106. void
  107. ConfigureDialogBase::slotCancelOrClose()
  108. {
  109. close();
  110. }
  111. void
  112. ConfigureDialogBase::slotHelpRequested()
  113. {
  114. // TRANSLATORS: if the manual is translated into your language, you can
  115. // change the two-letter language code in this URL to point to your language
  116. // version, eg. "http://rosegardenmusic.com/wiki/doc:configureDialogBase-es" for the
  117. // Spanish version. If your language doesn't yet have a translation, feel
  118. // free to create one.
  119. // Hrmmm... What to do with this one? Anything? Obviously there's not going
  120. // to be any specific help for a base class.
  121. // QString helpURL = tr("http://rosegardenmusic.com/wiki/doc:configureDialogBase-en");
  122. // QDesktopServices::openUrl(QUrl(helpURL));
  123. }
  124. void
  125. ConfigureDialogBase::setPageByIndex(int index)
  126. {
  127. m_iconWidget->setPageByIndex(index);
  128. }
  129. }
  130. #include "ConfigureDialogBase.moc"