]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
Allow zooming in and zooming out in the icons view.
[dolphin.git] / src / generalviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
3 * peter.penz@gmx.at *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "generalviewsettingspage.h"
22 #include "dolphinmainwindow.h"
23 #include "dolphinsettings.h"
24 #include "dolphin_generalsettings.h"
25 #include "viewproperties.h"
26
27 #include <assert.h>
28
29 #include <QLabel>
30 #include <QGroupBox>
31 #include <QRadioButton>
32 #include <QSlider>
33 #include <QSpinBox>
34 #include <QVBoxLayout>
35
36 #include <kconfiggroup.h>
37 #include <kdialog.h>
38 #include <kglobal.h>
39 #include <klocale.h>
40 #include <khbox.h>
41
42 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow* mainWindow,
43 QWidget* parent) :
44 KVBox(parent),
45 m_mainWindow(mainWindow),
46 m_localProps(0),
47 m_globalProps(0),
48 m_maxPreviewSize(0)
49 {
50 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
51 assert(settings != 0);
52
53 const int spacing = KDialog::spacingHint();
54 const int margin = KDialog::marginHint();
55 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
56
57 setSpacing(spacing);
58 setMargin(margin);
59
60 QGroupBox* propsBox = new QGroupBox(i18n("View Properties"), this);
61
62 m_localProps = new QRadioButton(i18n("Remember view properties for each folder."), propsBox);
63 m_globalProps = new QRadioButton(i18n("Use common view properties for all folders."), propsBox);
64 if (settings->globalViewProps()) {
65 m_globalProps->setChecked(true);
66 }
67 else {
68 m_localProps->setChecked(true);
69 }
70
71 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
72 propsBoxLayout->addWidget(m_localProps);
73 propsBoxLayout->addWidget(m_globalProps);
74
75 // create 'File Previews' box
76 QGroupBox* previewBox = new QGroupBox(i18n("File Previews"), this);
77
78 QLabel* maxFileSize = new QLabel(i18n("Maximum file size:"), previewBox);
79
80 KHBox* vBox = new KHBox(previewBox);
81 vBox->setSpacing(spacing);
82
83 const int min = 1; // MB
84 const int max = 100; // MB
85 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
86 m_maxPreviewSize->setRange(min, max);
87 m_maxPreviewSize->setPageStep(10);
88 m_maxPreviewSize->setSingleStep(1);
89 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
90
91 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
92 const int maxByteSize = globalConfig.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
93 int maxMByteSize = maxByteSize / (1024 * 1024);
94 if (maxMByteSize < 1) {
95 maxMByteSize = 1;
96 }
97 else if (maxMByteSize > max) {
98 maxMByteSize = max;
99 }
100 m_maxPreviewSize->setValue(maxMByteSize);
101
102 QSpinBox* spinBox = new QSpinBox(vBox);
103 spinBox->setRange(min, max);
104 spinBox->setSingleStep(1);
105 spinBox->setSuffix(" MB");
106 spinBox->setValue(m_maxPreviewSize->value());
107
108 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
109 spinBox, SLOT(setValue(int)));
110 connect(spinBox, SIGNAL(valueChanged(int)),
111 m_maxPreviewSize, SLOT(setValue(int)));
112
113 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
114 previewBoxLayout->addWidget(maxFileSize);
115 previewBoxLayout->addWidget(vBox);
116
117 // Add a dummy widget with no restriction regarding
118 // a vertical resizing. This assures that the dialog layout
119 // is not stretched vertically.
120 new QWidget(this);
121 }
122
123
124 GeneralViewSettingsPage::~GeneralViewSettingsPage()
125 {
126 }
127
128 void GeneralViewSettingsPage::applySettings()
129 {
130 const KUrl& url = m_mainWindow->activeView()->url();
131 ViewProperties props(url); // read current view properties
132
133 const bool useGlobalProps = m_globalProps->isChecked();
134
135 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
136 assert(settings != 0);
137 settings->setGlobalViewProps(useGlobalProps);
138
139 if (useGlobalProps) {
140 // Remember the global view properties by applying the current view properties.
141 // It is important that GeneralSettings::globalViewProps() is set before
142 // the class ViewProperties is used, as ViewProperties uses this setting
143 // to find the destination folder for storing the view properties.
144 ViewProperties globalProps(url);
145 globalProps.setDirProperties(props);
146 }
147
148 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
149 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
150 globalConfig.writeEntry("MaximumSize",
151 byteCount,
152 KConfigBase::Normal | KConfigBase::Global);
153 globalConfig.sync();
154 }
155
156 #include "generalviewsettingspage.moc"