1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/***************************************************************************
* Copyright (C) 2008, 2009, 2010, 2012 by Glad Deschrijver *
* <glad.deschrijver@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "configdialog.h"
#include <QCheckBox>
#include <QSettings>
#include <KConfigGroup>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include "configgeneralwidget.h"
namespace KtikZ
{
PartConfigDialog::PartConfigDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18nc("@title:window", "Configure KtikZ Viewer"));
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Apply);
QVBoxLayout *mainLayout = new QVBoxLayout;
m_configGeneralWidget = new PartConfigGeneralWidget(this);
mainLayout->addWidget(viewerWidget());
mainLayout->addWidget(m_configGeneralWidget);
QPushButton *okButton = m_buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
//PORTING SCRIPT: WARNING mainLayout->addWidget(buttonBox) must be last item in layout. Please move it.
mainLayout->addWidget(m_buttonBox);
setLayout(mainLayout);
connect(m_buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(writeSettings()));
connect(okButton, SIGNAL(clicked()), this, SLOT(writeSettings()));
connect(m_buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(setDefaults()));
connect(m_configGeneralWidget, SIGNAL(changed(bool)), this, SLOT(buttonBox->button(QDialogButtonBox::Apply)->setEnabled(bool)));
m_buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
}
PartConfigDialog::~PartConfigDialog()
{
}
QWidget *PartConfigDialog::viewerWidget()
{
QGroupBox *viewerGroupBox = new QGroupBox(i18nc("@title:group", "Viewer"));
QVBoxLayout *viewerLayout = new QVBoxLayout(viewerGroupBox);
m_watchFileCheckBox = new QCheckBox(i18nc("@option:check", "&Reload document on file change"));
m_watchFileCheckBox->setObjectName("watchFileCheckBox");
m_watchFileCheckBox->setWhatsThis(i18nc("@info:whatsthis", "<para>When this option is checked, "
"the TikZ image will be reloaded each time that the file is modified "
"by another program.</para>"));
viewerLayout->addWidget(m_watchFileCheckBox);
connect(m_watchFileCheckBox, SIGNAL(toggled(bool)), this, SLOT(setModified()));
return viewerGroupBox;
}
void PartConfigDialog::setDefaults()
{
m_configGeneralWidget->setDefaults();
m_watchFileCheckBox->setChecked(true);
}
void PartConfigDialog::readSettings()
{
m_configGeneralWidget->readSettings();
QSettings settings(ORGNAME, APPNAME);
m_watchFileCheckBox->setChecked(settings.value("WatchFile", true).toBool());
}
void PartConfigDialog::setModified()
{
QWidget *sendingWidget = qobject_cast<QWidget*>(sender());
QSettings settings(ORGNAME, APPNAME);
if (sendingWidget->objectName() == QLatin1String("watchFileCheckBox"))
m_buttonBox->button(QDialogButtonBox::Apply)->setEnabled(m_watchFileCheckBox->isChecked() != settings.value("WatchFile", true).toBool());
}
void PartConfigDialog::writeSettings()
{
m_configGeneralWidget->writeSettings();
QSettings settings(ORGNAME, APPNAME);
settings.setValue("WatchFile", m_watchFileCheckBox->isChecked());
m_buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
emit settingsChanged("preferences");
}
} // namespace KtikZ
|