Revert "Working on network-undo"
[dashstudio.git] / src / shell / settingsdialog.cpp
blob2c1e3dce08a94accebcbb4970b79443dd3f8c80f
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() );
79 m_paintAreaPage->showBorder->setChecked(m_paintArea->drawBorder());
81 #ifdef Q_OPENGL_LIB
82 bool openGL = dynamic_cast<QGLWidget *>(m_paintArea->viewport()) != 0;
83 m_paintAreaPage->openGL->setChecked(openGL);
84 #else
85 m_paintAreaPage->openGL->setEnabled(false);
86 #endif
88 m_paintAreaPage->backgroundColor->setColor(m_paintArea->canvasColor());
90 m_paintAreaPage->separation->setValue(m_paintArea->gridSeparation());
92 addPage(paintArea, tr("Paint area"), DGui::IconLoader::self()->load("applications-graphics.svg"));
97 SettingsDialog::~SettingsDialog()
99 delete m_generalPage;
100 delete m_paintAreaPage;
104 void SettingsDialog::apply()
106 ok(); // FIXME
107 accept();
110 void SettingsDialog::ok()
112 // Section: General
113 DCore::Config *config = dApp->config("General");
115 config->setValue("save_project_interval", m_generalPage->autoSaveProject->isChecked() ? m_generalPage->minutes->value() : 0);
116 config->setValue("auto_save_project", m_generalPage->autoSaveProject->isChecked());
118 config->endGroup();
121 // Section: TipOfDay
123 config->beginGroup("TipOfDay");
125 config->setValue("show_on_start", m_generalPage->showTips->isChecked());
127 config->endGroup();
131 m_paintArea->setAntialiasing(m_paintAreaPage->antialiasing->isChecked());
132 m_paintArea->setDrawGrid(m_paintAreaPage->showGrid->isChecked());
133 m_paintArea->setDrawBorder(m_paintAreaPage->showBorder->isChecked());
135 m_paintArea->setUseOpenGL(m_paintAreaPage->openGL->isChecked());
137 m_paintArea->setGridSeparation(m_paintAreaPage->separation->value());
138 m_paintArea->setCanvasColor(m_paintAreaPage->backgroundColor->color());
140 m_paintArea->saveSettings();
143 config->sync();
145 accept();