]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/iconsviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 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 "iconsviewsettingspage.h"
22 #include "dolphinfontrequester.h"
23 #include "iconsizegroupbox.h"
25 #include "dolphin_iconsmodesettings.h"
28 #include <KIconLoader>
29 #include <KGlobalSettings>
37 #include <QPushButton>
38 #include <QGridLayout>
40 #include <views/zoomlevelinfo.h>
42 IconsViewSettingsPage::IconsViewSettingsPage(QWidget
* parent
) :
43 ViewSettingsPageBase(parent
),
44 m_iconSizeGroupBox(0),
48 const int spacing
= KDialog::spacingHint();
49 const int margin
= KDialog::marginHint();
50 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
55 // Create "Icon" properties
56 m_iconSizeGroupBox
= new IconSizeGroupBox(this);
57 m_iconSizeGroupBox
->setSizePolicy(sizePolicy
);
59 const int min
= ZoomLevelInfo::minimumLevel();
60 const int max
= ZoomLevelInfo::maximumLevel();
61 m_iconSizeGroupBox
->setDefaultSizeRange(min
, max
);
62 m_iconSizeGroupBox
->setPreviewSizeRange(min
, max
);
64 // Create 'Text' group for selecting the font, the number of lines
66 QGroupBox
* textGroup
= new QGroupBox(i18nc("@title:group", "Text"), this);
67 textGroup
->setSizePolicy(sizePolicy
);
69 QLabel
* fontLabel
= new QLabel(i18nc("@label:listbox", "Font:"), textGroup
);
70 m_fontRequester
= new DolphinFontRequester(textGroup
);
72 QLabel
* textWidthLabel
= new QLabel(i18nc("@label:listbox", "Text width:"), textGroup
);
73 m_textWidthBox
= new KComboBox(textGroup
);
74 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Small"));
75 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Medium"));
76 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Large"));
77 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Huge"));
79 QGridLayout
* textGroupLayout
= new QGridLayout(textGroup
);
80 textGroupLayout
->addWidget(fontLabel
, 0, 0, Qt::AlignRight
);
81 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
82 textGroupLayout
->addWidget(textWidthLabel
, 2, 0, Qt::AlignRight
);
83 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
85 // Add a dummy widget with no restriction regarding
86 // a vertical resizing. This assures that the dialog layout
87 // is not stretched vertically.
92 connect(m_iconSizeGroupBox
, SIGNAL(defaultSizeChanged(int)), this, SIGNAL(changed()));
93 connect(m_iconSizeGroupBox
, SIGNAL(previewSizeChanged(int)), this, SIGNAL(changed()));
94 connect(m_fontRequester
, SIGNAL(changed()), this, SIGNAL(changed()));
95 connect(m_textWidthBox
, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
98 IconsViewSettingsPage::~IconsViewSettingsPage()
102 void IconsViewSettingsPage::applySettings()
104 const int iconSize
= ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox
->defaultSizeValue());
105 const int previewSize
= ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox
->previewSizeValue());
106 IconsModeSettings::setIconSize(iconSize
);
107 IconsModeSettings::setPreviewSize(previewSize
);
109 const QFont font
= m_fontRequester
->font();
110 IconsModeSettings::setUseSystemFont(m_fontRequester
->mode() == DolphinFontRequester::SystemFont
);
111 IconsModeSettings::setFontFamily(font
.family());
112 IconsModeSettings::setFontSize(font
.pointSizeF());
113 IconsModeSettings::setItalicFont(font
.italic());
114 IconsModeSettings::setFontWeight(font
.weight());
116 IconsModeSettings::setTextWidthIndex(m_textWidthBox
->currentIndex());
118 IconsModeSettings::self()->writeConfig();
121 void IconsViewSettingsPage::restoreDefaults()
123 IconsModeSettings::self()->useDefaults(true);
125 IconsModeSettings::self()->useDefaults(false);
128 void IconsViewSettingsPage::loadSettings()
130 const QSize
iconSize(IconsModeSettings::iconSize(), IconsModeSettings::iconSize());
131 const int iconSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(iconSize
);
132 m_iconSizeGroupBox
->setDefaultSizeValue(iconSizeValue
);
134 const QSize
previewSize(IconsModeSettings::previewSize(), IconsModeSettings::previewSize());
135 const int previewSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(previewSize
);
136 m_iconSizeGroupBox
->setPreviewSizeValue(previewSizeValue
);
138 if (IconsModeSettings::useSystemFont()) {
139 m_fontRequester
->setMode(DolphinFontRequester::SystemFont
);
141 QFont
font(IconsModeSettings::fontFamily(),
142 qRound(IconsModeSettings::fontSize()));
143 font
.setItalic(IconsModeSettings::italicFont());
144 font
.setWeight(IconsModeSettings::fontWeight());
145 font
.setPointSizeF(IconsModeSettings::fontSize());
146 m_fontRequester
->setMode(DolphinFontRequester::CustomFont
);
147 m_fontRequester
->setCustomFont(font
);
150 m_textWidthBox
->setCurrentIndex(IconsModeSettings::textWidthIndex());
153 #include "iconsviewsettingspage.moc"