]>
cloud.milkyroute.net Git - dolphin.git/blob - src/iconsviewsettingspage.cpp
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 "dolphinsettings.h"
23 #include "iconsizedialog.h"
25 #include "dolphin_iconsmodesettings.h"
28 #include <kfontrequester.h>
29 #include <kiconloader.h>
30 #include <kglobalsettings.h>
38 #include <QPushButton>
40 #include <QGridLayout>
41 #include <QVBoxLayout>
43 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow
* mainWindow
,
46 m_mainWindow(mainWindow
),
52 m_textlinesCountBox(0),
53 m_showAdditionalInfo(0),
57 const int spacing
= KDialog::spacingHint();
58 const int margin
= KDialog::marginHint();
59 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
64 m_iconSizeButton
= new QPushButton(i18nc("@action:button", "Change Icon && Preview Size..."), this);
65 connect(m_iconSizeButton
, SIGNAL(clicked()),
66 this, SLOT(openIconSizeDialog()));
68 // create 'Text' group for selecting the font, the number of lines
70 QGroupBox
* textGroup
= new QGroupBox(i18nc("@title:group", "Text"), this);
71 textGroup
->setSizePolicy(sizePolicy
);
73 QLabel
* fontLabel
= new QLabel(i18nc("@label:listbox", "Font:"), textGroup
);
74 m_fontRequester
= new KFontRequester(textGroup
);
76 QLabel
* textlinesCountLabel
= new QLabel(i18nc("@label:textbox", "Number of lines:"), textGroup
);
77 m_textlinesCountBox
= new QSpinBox(textGroup
);
78 m_textlinesCountBox
->setMinimum(1);
79 m_textlinesCountBox
->setMaximum(5);
81 QLabel
* textWidthLabel
= new QLabel(i18nc("@label:listbox", "Text width:"), textGroup
);
82 m_textWidthBox
= new QComboBox(textGroup
);
83 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Small"));
84 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Medium"));
85 m_textWidthBox
->addItem(i18nc("@item:inlistbox Text width", "Large"));
87 m_showAdditionalInfo
= new QCheckBox(i18nc("@option:check",
88 "Allow showing of additional information"), textGroup
);
90 QVBoxLayout
* textVBoxLayout
= new QVBoxLayout(textGroup
);
92 QGridLayout
* textGroupLayout
= new QGridLayout();
93 textGroupLayout
->addWidget(fontLabel
, 0, 0);
94 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
95 textGroupLayout
->addWidget(textlinesCountLabel
, 1, 0);
96 textGroupLayout
->addWidget(m_textlinesCountBox
, 1, 1);
97 textGroupLayout
->addWidget(textWidthLabel
, 2, 0);
98 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
100 textVBoxLayout
->addLayout(textGroupLayout
);
101 textVBoxLayout
->addWidget(m_showAdditionalInfo
);
103 // create the 'Grid' group for selecting the arrangement and the grid spacing
104 QGroupBox
* gridGroup
= new QGroupBox(i18nc("@title:group", "Grid"), this);
105 gridGroup
->setSizePolicy(sizePolicy
);
107 QLabel
* arrangementLabel
= new QLabel(i18nc("@label:listbox", "Arrangement:"), gridGroup
);
108 m_arrangementBox
= new QComboBox(gridGroup
);
109 m_arrangementBox
->addItem(i18nc("@item:inlistbox Arrangement", "Left to Right"));
110 m_arrangementBox
->addItem(i18nc("@item:inlistbox Arrangement", "Top to Bottom"));
112 QLabel
* gridSpacingLabel
= new QLabel(i18nc("@label:listbox", "Grid spacing:"), gridGroup
);
113 m_gridSpacingBox
= new QComboBox(gridGroup
);
114 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Small"));
115 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Medium"));
116 m_gridSpacingBox
->addItem(i18nc("@item:inlistbox Grid spacing", "Large"));
118 QGridLayout
* gridGroupLayout
= new QGridLayout(gridGroup
);
119 gridGroupLayout
->addWidget(arrangementLabel
, 0, 0);
120 gridGroupLayout
->addWidget(m_arrangementBox
, 0, 1);
121 gridGroupLayout
->addWidget(gridSpacingLabel
, 1, 0);
122 gridGroupLayout
->addWidget(m_gridSpacingBox
, 1, 1);
124 // Add a dummy widget with no restriction regarding
125 // a vertical resizing. This assures that the dialog layout
126 // is not stretched vertically.
132 IconsViewSettingsPage::~IconsViewSettingsPage()
136 void IconsViewSettingsPage::applySettings()
138 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
140 settings
->setIconSize(m_iconSize
);
141 settings
->setPreviewSize(m_previewSize
);
143 const QFont font
= m_fontRequester
->font();
144 const int fontHeight
= QFontMetrics(font
).height();
146 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
147 QListView::LeftToRight
:
148 QListView::TopToBottom
;
149 settings
->setArrangement(arrangement
);
151 const int numberOfTextlines
= m_textlinesCountBox
->value();
153 const int defaultSize
= settings
->iconSize();
154 int itemWidth
= defaultSize
;
155 int itemHeight
= defaultSize
;
156 const int textSizeIndex
= m_textWidthBox
->currentIndex();
157 if (arrangement
== QListView::TopToBottom
) {
158 itemWidth
+= TopToBottomBase
+ textSizeIndex
* TopToBottomInc
;
159 itemHeight
+= fontHeight
* numberOfTextlines
+ 10;
161 itemWidth
+= LeftToRightBase
+ textSizeIndex
* LeftToRightInc
;
164 settings
->setItemWidth(itemWidth
);
165 settings
->setItemHeight(itemHeight
);
167 settings
->setFontFamily(font
.family());
168 settings
->setFontSize(font
.pointSize());
169 settings
->setItalicFont(font
.italic());
170 settings
->setBoldFont(font
.bold());
172 settings
->setNumberOfTextlines(numberOfTextlines
);
174 settings
->setShowAdditionalInfo(m_showAdditionalInfo
->isChecked());
176 settings
->setGridSpacing(GridSpacingBase
+
177 m_gridSpacingBox
->currentIndex() * GridSpacingInc
);
180 void IconsViewSettingsPage::restoreDefaults()
182 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
183 settings
->setDefaults();
187 void IconsViewSettingsPage::openIconSizeDialog()
189 IconSizeDialog
dialog(this);
190 if (dialog
.exec() == QDialog::Accepted
) {
191 m_iconSize
= dialog
.iconSize();
192 m_previewSize
= dialog
.previewSize();
196 void IconsViewSettingsPage::loadSettings()
198 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
200 m_iconSize
= settings
->iconSize();
201 m_previewSize
= settings
->previewSize();
203 QFont
font(settings
->fontFamily(),
204 settings
->fontSize());
205 font
.setItalic(settings
->italicFont());
206 font
.setBold(settings
->boldFont());
207 m_fontRequester
->setFont(font
);
209 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
211 m_showAdditionalInfo
->setChecked(settings
->showAdditionalInfo());
213 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
214 int textWidthIndex
= 0;
215 const int remainingWidth
= settings
->itemWidth() - settings
->iconSize();
216 if (leftToRightArrangement
) {
217 textWidthIndex
= (remainingWidth
- LeftToRightBase
) / LeftToRightInc
;
219 textWidthIndex
= (remainingWidth
- TopToBottomBase
) / TopToBottomInc
;
221 // ensure that chosen index is always valid
222 textWidthIndex
= qMax(textWidthIndex
, 0);
223 textWidthIndex
= qMin(textWidthIndex
, m_textWidthBox
->count() - 1);
225 m_textWidthBox
->setCurrentIndex(textWidthIndex
);
226 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
227 m_gridSpacingBox
->setCurrentIndex((settings
->gridSpacing() - GridSpacingBase
) / GridSpacingInc
);
230 #include "iconsviewsettingspage.moc"