- Improved palette document spec
[dashstudio.git] / src / shell / settingsdialog.cpp
blobd4b62461ac827c1d1008d18852aa89f9c615e363
1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "settingsdialog.h"
23 #include <QPainter>
25 #ifdef Q_OPENGL_LIB
26 #include <QGLWidget>
27 #endif
29 // DLib
30 #include <dgui/iconloader.h>
31 #include <dgui/application.h>
32 #include <dcore/config.h>
34 // YAMF
35 #include <yamf/drawing/paintarea.h>
37 // Dash
38 #include "ui_general_page.h"
39 #include "ui_paintarea_page.h"
41 SettingsDialog::SettingsDialog(YAMF::Drawing::PaintArea *const paintArea, QWidget *parent)
42 : DGui::ConfigurationDialog(parent), m_paintArea(paintArea)
44 setWindowTitle(tr("Dash settings..."));
46 // Section General
47 DCore::Config *config = dApp->config("General");
49 m_generalPage = new Ui::GeneralPage;
51 QWidget *general = new QWidget;
52 m_generalPage->setupUi(general);
54 m_generalPage->minutes->setValue(config->value("save_project_interval", 15).toInt());
55 m_generalPage->autoSaveProject->setChecked(config->value("auto_save_project", true).toBool());
57 addPage(general, tr("General"), DGui::IconLoader::self()->load("preferences-system.svg"));
59 config->endGroup();
62 // Section: TipOfDay
64 config->beginGroup("TipOfDay");
65 m_generalPage->showTips->setChecked(config->value("show_on_start", true).toBool() );
66 config->endGroup();
69 // Section PaintArea
71 m_paintAreaPage = new Ui::PaintAreaPage;
73 QWidget *paintArea = new QWidget;
74 m_paintAreaPage->setupUi(paintArea);
76 m_paintAreaPage->antialiasing->setChecked(m_paintArea->renderHints() & QPainter::Antialiasing);
78 m_paintAreaPage->showGrid->setChecked( m_paintArea->drawGrid() );
80 #ifdef Q_OPENGL_LIB
81 bool openGL = dynamic_cast<QGLWidget *>(m_paintArea->viewport()) != 0;
82 m_paintAreaPage->openGL->setChecked(openGL);
83 #else
84 m_paintAreaPage->openGL->setEnabled(false);
85 #endif
87 m_paintAreaPage->backgroundColor->setColor(m_paintArea->canvasColor());
89 m_paintAreaPage->separation->setValue(m_paintArea->gridSeparation());
91 addPage(paintArea, tr("Paint area"), DGui::IconLoader::self()->load("applications-graphics.svg"));
96 SettingsDialog::~SettingsDialog()
98 delete m_generalPage;
99 delete m_paintAreaPage;
103 void SettingsDialog::apply()
105 ok(); // FIXME
106 accept();
109 void SettingsDialog::ok()
111 // Section: General
112 DCore::Config *config = dApp->config("General");
114 config->setValue("save_project_interval", m_generalPage->autoSaveProject->isChecked() ? m_generalPage->minutes->value() : 0);
115 config->setValue("auto_save_project", m_generalPage->autoSaveProject->isChecked());
117 config->endGroup();
120 // Section: TipOfDay
122 config->beginGroup("TipOfDay");
124 config->setValue("show_on_start", m_generalPage->showTips->isChecked());
126 config->endGroup();
130 m_paintArea->setAntialiasing(m_paintAreaPage->antialiasing->isChecked());
131 m_paintArea->setDrawGrid(m_paintAreaPage->showGrid->isChecked());
132 m_paintArea->setUseOpenGL(m_paintAreaPage->openGL->isChecked());
134 m_paintArea->setGridSeparation(m_paintAreaPage->separation->value());
135 m_paintArea->setCanvasColor(m_paintAreaPage->backgroundColor->color());
138 m_paintArea->saveSettings();
141 config->sync();
143 accept();