1 /* This file is part of the KDE project
2 Copyright (C) 2002, 2003 Laurent Montel <lmontel@mandrakesoft.com>
3 Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9 
10 This library 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 GNU
13 Library General Public License for more details.
14 
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20 
21 #include "KarbonConfigInterfacePage.h"
22 
23 #include "KarbonView.h"
24 #include "KarbonPart.h"
25 #include "KarbonDocument.h"
26 #include "KarbonFactory.h"
27 
28 #include <KoConfigGridPage.h>
29 #include <KoConfigDocumentPage.h>
30 #include <KoConfigMiscPage.h>
31 
32 #include <klocalizedstring.h>
33 #include <kconfig.h>
34 #include <kconfiggroup.h>
35 #include <kcolorbutton.h>
36 
37 #include <QSpinBox>
38 #include <QCheckBox>
39 #include <QGroupBox>
40 #include <QFormLayout>
41 
KarbonConfigInterfacePage(KarbonView * view,char * name)42 KarbonConfigInterfacePage::KarbonConfigInterfacePage(KarbonView* view, char* name)
43 {
44     setObjectName(name);
45 
46     m_view = view;
47     m_config = KarbonFactory::karbonConfig();
48 
49     m_oldRecentFiles = 10;
50     m_oldDockerFontSize = 8;
51     m_oldCanvasColor = QColor(Qt::white);
52     bool oldShowStatusBar = true;
53 
54     QGroupBox* tmpQGroupBox = new QGroupBox(i18n("Interface"), this);
55 
56     KConfigGroup emptyGroup = m_config->group("GUI");
57     m_oldDockerFontSize = emptyGroup.readEntry("palettefontsize", m_oldDockerFontSize);
58 
59     if (m_config->hasGroup("Interface")) {
60         KConfigGroup interfaceGroup = m_config->group("Interface");
61 
62         m_oldRecentFiles = interfaceGroup.readEntry("NbRecentFile", m_oldRecentFiles);
63         oldShowStatusBar = interfaceGroup.readEntry("ShowStatusBar", true);
64         m_oldCanvasColor = interfaceGroup.readEntry("CanvasColor", m_oldCanvasColor);
65     }
66 
67     QFormLayout *interfaceLayout = new QFormLayout(tmpQGroupBox);
68 
69     m_showStatusBar = new QCheckBox(tmpQGroupBox);
70     m_showStatusBar->setChecked(oldShowStatusBar);
71     interfaceLayout->addRow(i18n("Show status bar:"), m_showStatusBar);
72 
73     m_recentFiles = new QSpinBox(tmpQGroupBox);
74     m_recentFiles->setRange(1, 20);
75     m_recentFiles->setSingleStep(1);
76     m_recentFiles->setValue(m_oldRecentFiles);
77     interfaceLayout->addRow(i18n("Number of recent files:"), m_recentFiles);
78 
79     m_dockerFontSize = new QSpinBox(tmpQGroupBox);
80     m_dockerFontSize->setRange(5, 20);
81     m_dockerFontSize->setSingleStep(1);
82     m_dockerFontSize->setValue(m_oldDockerFontSize);
83     interfaceLayout->addRow(i18n("Palette font size:"), m_dockerFontSize);
84 
85 // TODO or move or remove?
86 //     m_canvasColor = new KColorButton(m_oldCanvasColor, tmpQGroupBox);
87 //     interfaceLayout->addRow(i18n("Canvas color:"), m_canvasColor);
88 }
89 
apply()90 void KarbonConfigInterfacePage::apply()
91 {
92     bool showStatusBar = m_showStatusBar->isChecked();
93 
94     KarbonDocument* part = m_view->part();
95 
96     KConfigGroup interfaceGroup = m_config->group("Interface");
97 
98     int recent = m_recentFiles->value();
99 
100     if (recent != m_oldRecentFiles) {
101         interfaceGroup.writeEntry("NbRecentFile", recent);
102         m_view->setNumberOfRecentFiles(recent);
103         m_oldRecentFiles = recent;
104     }
105 
106     bool refreshGUI = false;
107 
108     if (showStatusBar != part->showStatusBar()) {
109         interfaceGroup.writeEntry("ShowStatusBar", showStatusBar);
110         part->setShowStatusBar(showStatusBar);
111         refreshGUI = true;
112     }
113 
114     int dockerFontSize = m_dockerFontSize->value();
115 
116     if (dockerFontSize != m_oldDockerFontSize) {
117         m_config->group("GUI").writeEntry("palettefontsize", dockerFontSize);
118         m_oldDockerFontSize = dockerFontSize;
119         refreshGUI = true;
120     }
121 
122 //     QColor canvasColor = m_canvasColor->color();
123 //     if (canvasColor != m_oldCanvasColor) {
124 //         interfaceGroup.writeEntry("CanvasColor", canvasColor);
125 //         refreshGUI = true;
126 //     }
127 
128     if (refreshGUI)
129         part->reorganizeGUI();
130 }
131 
slotDefault()132 void KarbonConfigInterfacePage::slotDefault()
133 {
134     m_recentFiles->setValue(10);
135     m_dockerFontSize->setValue(8);
136     m_showStatusBar->setChecked(true);
137 }
138 
139