]>
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>
37 #include <QPushButton>
39 #include <QGridLayout>
41 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow
* mainWindow
,
44 m_mainWindow(mainWindow
),
50 m_textlinesCountBox(0),
54 const int spacing
= KDialog::spacingHint();
55 const int margin
= KDialog::marginHint();
56 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
61 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
62 Q_ASSERT(settings
!= 0);
63 m_iconSize
= settings
->iconSize();
64 m_previewSize
= settings
->previewSize();
66 KHBox
* sizesLayout
= new KHBox(this);
67 sizesLayout
->setSpacing(spacing
);
68 sizesLayout
->setSizePolicy(sizePolicy
);
70 m_iconSizeButton
= new QPushButton(i18n("Change icon and preview size..."), this);
71 connect(m_iconSizeButton
, SIGNAL(clicked()),
72 this, SLOT(openIconSizeDialog()));
74 // create 'Text' group for selecting the font, the number of lines
76 QGroupBox
* textGroup
= new QGroupBox(i18n("Text"), this);
77 textGroup
->setSizePolicy(sizePolicy
);
79 QLabel
* fontLabel
= new QLabel(i18n("Font:"), textGroup
);
80 m_fontRequester
= new KFontRequester(textGroup
);
81 QFont
font(settings
->fontFamily(),
82 settings
->fontSize());
83 font
.setItalic(settings
->italicFont());
84 font
.setBold(settings
->boldFont());
85 m_fontRequester
->setFont(font
);
87 QLabel
* textlinesCountLabel
= new QLabel(i18n("Number of lines:"), textGroup
);
88 m_textlinesCountBox
= new QSpinBox(1, 5, 1, textGroup
);
89 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
91 QLabel
* textWidthLabel
= new QLabel(i18n("Text width:"), textGroup
);
92 m_textWidthBox
= new QComboBox(textGroup
);
93 m_textWidthBox
->addItem(i18n("Small"));
94 m_textWidthBox
->addItem(i18n("Medium"));
95 m_textWidthBox
->addItem(i18n("Large"));
97 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
98 int textWidthIndex
= 0;
99 const int remainingWidth
= settings
->gridWidth() - settings
->iconSize();
100 if (leftToRightArrangement
) {
101 textWidthIndex
= (remainingWidth
- LeftToRightBase
) / LeftToRightInc
;
104 textWidthIndex
= (remainingWidth
- TopToBottomBase
) / TopToBottomInc
;
107 m_textWidthBox
->setCurrentIndex(textWidthIndex
);
109 QGridLayout
* textGroupLayout
= new QGridLayout(textGroup
);
110 textGroupLayout
->addWidget(fontLabel
, 0, 0);
111 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
112 textGroupLayout
->addWidget(textlinesCountLabel
, 1, 0);
113 textGroupLayout
->addWidget(m_textlinesCountBox
, 1, 1);
114 textGroupLayout
->addWidget(textWidthLabel
, 2, 0);
115 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
117 // create the 'Grid' group for selecting the arrangement and the grid spacing
118 QGroupBox
* gridGroup
= new QGroupBox(i18n("Grid"), this);
119 gridGroup
->setSizePolicy(sizePolicy
);
121 QLabel
* arrangementLabel
= new QLabel(i18n("Arrangement:"), gridGroup
);
122 m_arrangementBox
= new QComboBox(gridGroup
);
123 m_arrangementBox
->addItem(i18n("Left to right"));
124 m_arrangementBox
->addItem(i18n("Top to bottom"));
125 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
127 QLabel
* gridSpacingLabel
= new QLabel(i18n("Grid spacing:"), gridGroup
);
128 m_gridSpacingBox
= new QComboBox(gridGroup
);
129 m_gridSpacingBox
->addItem(i18n("Small"));
130 m_gridSpacingBox
->addItem(i18n("Medium"));
131 m_gridSpacingBox
->addItem(i18n("Large"));
132 m_gridSpacingBox
->setCurrentIndex((settings
->gridSpacing() - GridSpacingBase
) / GridSpacingInc
);
134 QGridLayout
* gridGroupLayout
= new QGridLayout(gridGroup
);
135 gridGroupLayout
->addWidget(arrangementLabel
, 0, 0);
136 gridGroupLayout
->addWidget(m_arrangementBox
, 0, 1);
137 gridGroupLayout
->addWidget(gridSpacingLabel
, 1, 0);
138 gridGroupLayout
->addWidget(m_gridSpacingBox
, 1, 1);
140 // Add a dummy widget with no restriction regarding
141 // a vertical resizing. This assures that the dialog layout
142 // is not stretched vertically.
146 IconsViewSettingsPage::~IconsViewSettingsPage()
150 void IconsViewSettingsPage::applySettings()
152 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
153 Q_ASSERT(settings
!= 0);
155 settings
->setIconSize(m_iconSize
);
156 settings
->setPreviewSize(m_previewSize
);
158 const QFont font
= m_fontRequester
->font();
159 const int fontSize
= font
.pointSize();
161 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
162 QListView::LeftToRight
:
163 QListView::TopToBottom
;
164 settings
->setArrangement(arrangement
);
166 const int defaultSize
= settings
->iconSize();
167 int gridWidth
= defaultSize
;
168 int gridHeight
= defaultSize
;
169 const int textSizeIndex
= m_textWidthBox
->currentIndex();
170 if (arrangement
== QListView::TopToBottom
) {
171 gridWidth
+= TopToBottomBase
+ textSizeIndex
* TopToBottomInc
;
172 gridHeight
+= fontSize
* 6;
175 gridWidth
+= LeftToRightBase
+ textSizeIndex
* LeftToRightInc
;
178 settings
->setGridWidth(gridWidth
);
179 settings
->setGridHeight(gridHeight
);
181 settings
->setFontFamily(font
.family());
182 settings
->setFontSize(fontSize
);
183 settings
->setItalicFont(font
.italic());
184 settings
->setBoldFont(font
.bold());
186 settings
->setNumberOfTextlines(m_textlinesCountBox
->value());
188 settings
->setGridSpacing(GridSpacingBase
+
189 m_gridSpacingBox
->currentIndex() * GridSpacingInc
);
192 void IconsViewSettingsPage::openIconSizeDialog()
194 IconSizeDialog
dialog(this);
195 if (dialog
.exec() == QDialog::Accepted
) {
196 m_iconSize
= dialog
.iconSize();
197 m_previewSize
= dialog
.previewSize();
201 #include "iconsviewsettingspage.moc"