]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/viewsettingstab.cpp
1 /***************************************************************************
2 * Copyright (C) 2008-2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "viewsettingstab.h"
22 #include "dolphinfontrequester.h"
23 #include "dolphin_compactmodesettings.h"
24 #include "dolphin_detailsmodesettings.h"
25 #include "dolphin_iconsmodesettings.h"
33 #include <QVBoxLayout>
35 #include <views/zoomlevelinfo.h>
38 void apply(int iconSizeValue
, int previewSizeValue
, const QFont
& font
, bool useSystemFont
)
40 const int iconSize
= ZoomLevelInfo::iconSizeForZoomLevel(iconSizeValue
);
41 const int previewSize
= ZoomLevelInfo::iconSizeForZoomLevel(previewSizeValue
);
42 T::setIconSize(iconSize
);
43 T::setPreviewSize(previewSize
);
45 T::setUseSystemFont(useSystemFont
);
46 T::setFontFamily(font
.family());
47 T::setFontSize(font
.pointSizeF());
48 T::setItalicFont(font
.italic());
49 T::setFontWeight(font
.weight());
51 T::self()->writeConfig();
55 void load(int* iconSizeValue
, int* previewSizeValue
, QFont
* font
, bool* useSystemFont
)
57 const QSize
iconSize(T::iconSize(), T::iconSize());
58 *iconSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(iconSize
);
60 const QSize
previewSize(T::previewSize(), T::previewSize());
61 *previewSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(previewSize
);
63 *useSystemFont
= T::useSystemFont();
65 *font
= QFont(T::fontFamily(), qRound(T::fontSize()));
66 font
->setItalic(T::italicFont());
67 font
->setWeight(T::fontWeight());
68 font
->setPointSizeF(T::fontSize());
72 ViewSettingsTab::ViewSettingsTab(Mode mode
, QWidget
* parent
) :
75 m_defaultSizeSlider(0),
76 m_previewSizeSlider(0),
80 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
82 // Create "Icon Size" group
83 QGroupBox
* iconSizeGroup
= new QGroupBox(this);
84 iconSizeGroup
->setTitle(i18nc("@title:group", "Icon Size"));
86 const int minRange
= ZoomLevelInfo::minimumLevel();
87 const int maxRange
= ZoomLevelInfo::maximumLevel();
89 QLabel
* defaultLabel
= new QLabel(i18nc("@label:listbox", "Default:"), this);
90 m_defaultSizeSlider
= new QSlider(Qt::Horizontal
, this);
91 m_defaultSizeSlider
->setPageStep(1);
92 m_defaultSizeSlider
->setTickPosition(QSlider::TicksBelow
);
93 m_defaultSizeSlider
->setRange(minRange
, maxRange
);
95 QLabel
* previewLabel
= new QLabel(i18nc("@label:listbox", "Preview:"), this);
96 m_previewSizeSlider
= new QSlider(Qt::Horizontal
, this);
97 m_previewSizeSlider
->setPageStep(1);
98 m_previewSizeSlider
->setTickPosition(QSlider::TicksBelow
);
99 m_previewSizeSlider
->setRange(minRange
, maxRange
);
101 QGridLayout
* layout
= new QGridLayout(iconSizeGroup
);
102 layout
->addWidget(defaultLabel
, 0, 0, Qt::AlignRight
);
103 layout
->addWidget(m_defaultSizeSlider
, 0, 1);
104 layout
->addWidget(previewLabel
, 1, 0, Qt::AlignRight
);
105 layout
->addWidget(m_previewSizeSlider
, 1, 1);
107 // Create "Text" group
108 QGroupBox
* textGroup
= new QGroupBox(i18nc("@title:group", "Text"), this);
110 QLabel
* fontLabel
= new QLabel(i18nc("@label:listbox", "Font:"), textGroup
);
111 m_fontRequester
= new DolphinFontRequester(textGroup
);
113 QGridLayout
* textGroupLayout
= new QGridLayout(textGroup
);
114 textGroupLayout
->addWidget(fontLabel
, 0, 0, Qt::AlignRight
);
115 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
117 if (m_mode
== IconsMode
) {
118 QLabel
* textWidthLabel
= new QLabel(i18nc("@label:listbox", "Text width:"), textGroup
);
119 m_textWidthBox
= new KComboBox(textGroup
);
120 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Small"));
121 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Medium"));
122 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Large"));
123 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Huge"));
125 textGroupLayout
->addWidget(textWidthLabel
, 2, 0, Qt::AlignRight
);
126 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
129 topLayout
->addWidget(iconSizeGroup
);
130 topLayout
->addWidget(textGroup
);
131 topLayout
->addStretch(1);
135 connect(m_defaultSizeSlider
, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
136 connect(m_previewSizeSlider
, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
137 connect(m_fontRequester
, SIGNAL(changed()), this, SIGNAL(changed()));
138 if (m_mode
== IconsMode
) {
139 connect(m_textWidthBox
, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
143 ViewSettingsTab::~ViewSettingsTab()
147 void ViewSettingsTab::applySettings()
149 const int defaultSize
= m_defaultSizeSlider
->value();
150 const int previewSize
= m_previewSizeSlider
->value();
151 const QFont font
= m_fontRequester
->currentFont();
152 const bool useSystemFont
= (m_fontRequester
->mode() == DolphinFontRequester::SystemFont
);
156 IconsModeSettings::setTextWidthIndex(m_textWidthBox
->currentIndex());
157 apply
<IconsModeSettings
>(defaultSize
, previewSize
, font
, useSystemFont
);
160 apply
<CompactModeSettings
>(defaultSize
, previewSize
, font
, useSystemFont
);
163 apply
<DetailsModeSettings
>(defaultSize
, previewSize
, font
, useSystemFont
);
171 void ViewSettingsTab::restoreDefaultSettings()
173 KConfigSkeleton
* settings
= 0;
175 case IconsMode
: settings
= IconsModeSettings::self(); break;
176 case CompactMode
: settings
= CompactModeSettings::self(); break;
177 case DetailsMode
: settings
= DetailsModeSettings::self(); break;
178 default: Q_ASSERT(false); break;
181 settings
->useDefaults(true);
183 settings
->useDefaults(false);
186 void ViewSettingsTab::loadSettings()
188 int iconSizeValue
= 0;
189 int previewSizeValue
= 0;
191 bool useSystemFont
= false;
195 m_textWidthBox
->setCurrentIndex(IconsModeSettings::textWidthIndex());
196 load
<IconsModeSettings
>(&iconSizeValue
, &previewSizeValue
, &font
, &useSystemFont
);
199 load
<CompactModeSettings
>(&iconSizeValue
, &previewSizeValue
, &font
, &useSystemFont
);
202 load
<DetailsModeSettings
>(&iconSizeValue
, &previewSizeValue
, &font
, &useSystemFont
);
209 m_defaultSizeSlider
->setValue(iconSizeValue
);
210 m_previewSizeSlider
->setValue(previewSizeValue
);
211 m_fontRequester
->setMode(useSystemFont
? DolphinFontRequester::SystemFont
: DolphinFontRequester::CustomFont
);
212 m_fontRequester
->setCustomFont(font
);
215 #include "viewsettingstab.moc"