1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 "settings/dolphinsettings.h"
24 #include "iconsizegroupbox.h"
25 #include "zoomlevelinfo.h"
27 #include "dolphin_iconsmodesettings.h"
30 #include <kiconloader.h>
31 #include <kglobalsettings.h>
33 #include <kcombobox.h>
39 #include <QPushButton>
41 #include <QGridLayout>
42 #include <QVBoxLayout>
44 IconsViewSettingsPage::IconsViewSettingsPage(QWidget
* parent
) :
45 ViewSettingsPageBase(parent
),
46 m_iconSizeGroupBox(0),
49 m_textlinesCountBox(0),
53 const int spacing
= KDialog::spacingHint();
54 const int margin
= KDialog::marginHint();
55 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
60 // Create "Icon" properties
61 m_iconSizeGroupBox
= new IconSizeGroupBox(this);
62 m_iconSizeGroupBox
->setSizePolicy(sizePolicy
);
64 const int min
= ZoomLevelInfo::minimumLevel();
65 const int max
= ZoomLevelInfo::maximumLevel();
66 m_iconSizeGroupBox
->setDefaultSizeRange(min
, max
);
67 m_iconSizeGroupBox
->setPreviewSizeRange(min
, max
);
69 connect(m_iconSizeGroupBox
, SIGNAL(defaultSizeChanged(int)),
70 this, SIGNAL(changed()));
71 connect(m_iconSizeGroupBox
, SIGNAL(previewSizeChanged(int)),
72 this, SIGNAL(changed()));
74 // create 'Text' group for selecting the font, the number of lines
76 QGroupBox
* textGroup
= new QGroupBox(i18nc("@title:group", "Text"), this);
77 textGroup
->setSizePolicy(sizePolicy
);
79 QLabel
* fontLabel
= new QLabel(i18nc("@label:listbox", "Font:"), textGroup
);
80 m_fontRequester
= new DolphinFontRequester(textGroup
);
81 connect(m_fontRequester
, SIGNAL(changed()), this, SIGNAL(changed()));
83 QLabel
* textlinesCountLabel
= new QLabel(i18nc("@label:textbox", "Number of lines:"), textGroup
);
84 m_textlinesCountBox
= new QSpinBox(textGroup
);
85 m_textlinesCountBox
->setMinimum(1);
86 m_textlinesCountBox
->setMaximum(5);
87 connect(m_textlinesCountBox
, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
89 QLabel
* textWidthLabel
= new QLabel(i18nc("@label:listbox", "Text width:"), textGroup
);
90 m_textWidthBox
= new KComboBox(textGroup
);
91 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Small"));
92 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Medium"));
93 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Large"));
94 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Huge"));
95 connect(m_textWidthBox
, SIGNAL(activated(int)), this, SIGNAL(changed()));
97 QGridLayout
* textGroupLayout
= new QGridLayout(textGroup
);
98 textGroupLayout
->addWidget(fontLabel
, 0, 0, Qt::AlignRight
);
99 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
100 textGroupLayout
->addWidget(textlinesCountLabel
, 1, 0, Qt::AlignRight
);
101 textGroupLayout
->addWidget(m_textlinesCountBox
, 1, 1);
102 textGroupLayout
->addWidget(textWidthLabel
, 2, 0, Qt::AlignRight
);
103 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
105 // create the 'Grid' group for selecting the arrangement and the grid spacing
106 QGroupBox
* gridGroup
= new QGroupBox(i18nc("@title:group", "Grid"), this);
107 gridGroup
->setSizePolicy(sizePolicy
);
109 QLabel
* arrangementLabel
= new QLabel(i18nc("@label:listbox", "Arrangement:"), gridGroup
);
110 m_arrangementBox
= new KComboBox(gridGroup
);
111 m_arrangementBox
->addItem(i18nc("@item:inlistbox Arrangement", "Columns"));
112 m_arrangementBox
->addItem(i18nc("@item:inlistbox Arrangement", "Rows"));
113 connect(m_arrangementBox
, SIGNAL(activated(int)), this, SIGNAL(changed()));
115 QLabel
* gridSpacingLabel
= new QLabel(i18nc("@label:listbox", "Grid spacing:"), gridGroup
);
116 m_gridSpacingBox
= new KComboBox(gridGroup
);
117 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "None"));
118 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Small"));
119 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Medium"));
120 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Large"));
121 connect(m_gridSpacingBox
, SIGNAL(activated(int)), this, SIGNAL(changed()));
123 QGridLayout
* gridGroupLayout
= new QGridLayout(gridGroup
);
124 gridGroupLayout
->addWidget(arrangementLabel
, 0, 0, Qt::AlignRight
);
125 gridGroupLayout
->addWidget(m_arrangementBox
, 0, 1);
126 gridGroupLayout
->addWidget(gridSpacingLabel
, 1, 0, Qt::AlignRight
);
127 gridGroupLayout
->addWidget(m_gridSpacingBox
, 1, 1);
129 // Add a dummy widget with no restriction regarding
130 // a vertical resizing. This assures that the dialog layout
131 // is not stretched vertically.
137 IconsViewSettingsPage::~IconsViewSettingsPage()
141 void IconsViewSettingsPage::applySettings()
143 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
145 const int iconSize
= ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox
->defaultSizeValue());
146 const int previewSize
= ZoomLevelInfo::iconSizeForZoomLevel(m_iconSizeGroupBox
->previewSizeValue());
147 settings
->setIconSize(iconSize
);
148 settings
->setPreviewSize(previewSize
);
150 const QFont font
= m_fontRequester
->font();
151 const int fontHeight
= QFontMetrics(font
).height();
153 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
154 QListView::LeftToRight
:
155 QListView::TopToBottom
;
156 settings
->setArrangement(arrangement
);
158 const int numberOfTextlines
= m_textlinesCountBox
->value();
160 const int defaultSize
= settings
->iconSize();
161 int itemWidth
= defaultSize
;
162 int itemHeight
= defaultSize
;
163 const int textSizeIndex
= m_textWidthBox
->currentIndex();
164 if (arrangement
== QListView::TopToBottom
) {
165 itemWidth
+= TopToBottomBase
+ textSizeIndex
* TopToBottomInc
;
166 itemHeight
+= fontHeight
* numberOfTextlines
+ 10;
168 itemWidth
+= LeftToRightBase
+ textSizeIndex
* LeftToRightInc
;
171 settings
->setItemWidth(itemWidth
);
172 settings
->setItemHeight(itemHeight
);
174 settings
->setUseSystemFont(m_fontRequester
->mode() == DolphinFontRequester::SystemFont
);
175 settings
->setFontFamily(font
.family());
176 settings
->setFontSize(font
.pointSize());
177 settings
->setItalicFont(font
.italic());
178 settings
->setFontWeight(font
.weight());
180 settings
->setNumberOfTextlines(numberOfTextlines
);
182 const int index
= m_gridSpacingBox
->currentIndex();
185 settings
->setGridSpacing(0);
187 settings
->setGridSpacing(GridSpacingBase
+ (index
- 1) * GridSpacingInc
);
191 void IconsViewSettingsPage::restoreDefaults()
193 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
194 settings
->setDefaults();
198 void IconsViewSettingsPage::loadSettings()
200 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
202 const QSize
iconSize(settings
->iconSize(), settings
->iconSize());
203 const int iconSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(iconSize
);
204 m_iconSizeGroupBox
->setDefaultSizeValue(iconSizeValue
);
206 const QSize
previewSize(settings
->previewSize(), settings
->previewSize());
207 const int previewSizeValue
= ZoomLevelInfo::zoomLevelForIconSize(previewSize
);
208 m_iconSizeGroupBox
->setPreviewSizeValue(previewSizeValue
);
210 if (settings
->useSystemFont()) {
211 m_fontRequester
->setMode(DolphinFontRequester::SystemFont
);
213 QFont
font(settings
->fontFamily(),
214 settings
->fontSize());
215 font
.setItalic(settings
->italicFont());
216 font
.setWeight(settings
->fontWeight());
217 m_fontRequester
->setMode(DolphinFontRequester::CustomFont
);
218 m_fontRequester
->setCustomFont(font
);
221 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
223 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
224 int textWidthIndex
= 0;
225 const int remainingWidth
= settings
->itemWidth() - settings
->iconSize();
226 if (leftToRightArrangement
) {
227 textWidthIndex
= (remainingWidth
- LeftToRightBase
) / LeftToRightInc
;
229 textWidthIndex
= (remainingWidth
- TopToBottomBase
) / TopToBottomInc
;
231 // ensure that chosen index is always valid
232 textWidthIndex
= qMax(textWidthIndex
, 0);
233 textWidthIndex
= qMin(textWidthIndex
, m_textWidthBox
->count() - 1);
235 m_textWidthBox
->setCurrentIndex(textWidthIndex
);
236 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
238 const int spacing
= settings
->gridSpacing();
239 const int index
= (spacing
<= 0) ? 0 : 1 + (spacing
- GridSpacingBase
) / GridSpacingInc
;
240 m_gridSpacingBox
->setCurrentIndex(index
);
243 #include "iconsviewsettingspage.moc"