]>
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 m_iconSizeButton
= new QPushButton(i18n("Change icon and preview size..."), this);
67 connect(m_iconSizeButton
, SIGNAL(clicked()),
68 this, SLOT(openIconSizeDialog()));
70 // create 'Text' group for selecting the font, the number of lines
72 QGroupBox
* textGroup
= new QGroupBox(i18n("Text"), this);
73 textGroup
->setSizePolicy(sizePolicy
);
75 QLabel
* fontLabel
= new QLabel(i18n("Font:"), textGroup
);
76 m_fontRequester
= new KFontRequester(textGroup
);
77 QFont
font(settings
->fontFamily(),
78 settings
->fontSize());
79 font
.setItalic(settings
->italicFont());
80 font
.setBold(settings
->boldFont());
81 m_fontRequester
->setFont(font
);
83 QLabel
* textlinesCountLabel
= new QLabel(i18n("Number of lines:"), textGroup
);
84 m_textlinesCountBox
= new QSpinBox(1, 5, 1, textGroup
);
85 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
87 QLabel
* textWidthLabel
= new QLabel(i18n("Text width:"), textGroup
);
88 m_textWidthBox
= new QComboBox(textGroup
);
89 m_textWidthBox
->addItem(i18n("Small"));
90 m_textWidthBox
->addItem(i18n("Medium"));
91 m_textWidthBox
->addItem(i18n("Large"));
93 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
94 int textWidthIndex
= 0;
95 const int remainingWidth
= settings
->gridWidth() - settings
->iconSize();
96 if (leftToRightArrangement
) {
97 textWidthIndex
= (remainingWidth
- LeftToRightBase
) / LeftToRightInc
;
100 textWidthIndex
= (remainingWidth
- TopToBottomBase
) / TopToBottomInc
;
103 m_textWidthBox
->setCurrentIndex(textWidthIndex
);
105 QGridLayout
* textGroupLayout
= new QGridLayout(textGroup
);
106 textGroupLayout
->addWidget(fontLabel
, 0, 0);
107 textGroupLayout
->addWidget(m_fontRequester
, 0, 1);
108 textGroupLayout
->addWidget(textlinesCountLabel
, 1, 0);
109 textGroupLayout
->addWidget(m_textlinesCountBox
, 1, 1);
110 textGroupLayout
->addWidget(textWidthLabel
, 2, 0);
111 textGroupLayout
->addWidget(m_textWidthBox
, 2, 1);
113 // create the 'Grid' group for selecting the arrangement and the grid spacing
114 QGroupBox
* gridGroup
= new QGroupBox(i18n("Grid"), this);
115 gridGroup
->setSizePolicy(sizePolicy
);
117 QLabel
* arrangementLabel
= new QLabel(i18n("Arrangement:"), gridGroup
);
118 m_arrangementBox
= new QComboBox(gridGroup
);
119 m_arrangementBox
->addItem(i18n("Left to right"));
120 m_arrangementBox
->addItem(i18n("Top to bottom"));
121 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
123 QLabel
* gridSpacingLabel
= new QLabel(i18n("Grid spacing:"), gridGroup
);
124 m_gridSpacingBox
= new QComboBox(gridGroup
);
125 m_gridSpacingBox
->addItem(i18n("Small"));
126 m_gridSpacingBox
->addItem(i18n("Medium"));
127 m_gridSpacingBox
->addItem(i18n("Large"));
128 m_gridSpacingBox
->setCurrentIndex((settings
->gridSpacing() - GridSpacingBase
) / GridSpacingInc
);
130 QGridLayout
* gridGroupLayout
= new QGridLayout(gridGroup
);
131 gridGroupLayout
->addWidget(arrangementLabel
, 0, 0);
132 gridGroupLayout
->addWidget(m_arrangementBox
, 0, 1);
133 gridGroupLayout
->addWidget(gridSpacingLabel
, 1, 0);
134 gridGroupLayout
->addWidget(m_gridSpacingBox
, 1, 1);
136 // Add a dummy widget with no restriction regarding
137 // a vertical resizing. This assures that the dialog layout
138 // is not stretched vertically.
142 IconsViewSettingsPage::~IconsViewSettingsPage()
146 void IconsViewSettingsPage::applySettings()
148 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
149 Q_ASSERT(settings
!= 0);
151 settings
->setIconSize(m_iconSize
);
152 settings
->setPreviewSize(m_previewSize
);
154 const QFont font
= m_fontRequester
->font();
155 const int fontSize
= font
.pointSize();
157 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
158 QListView::LeftToRight
:
159 QListView::TopToBottom
;
160 settings
->setArrangement(arrangement
);
162 const int defaultSize
= settings
->iconSize();
163 int gridWidth
= defaultSize
;
164 int gridHeight
= defaultSize
;
165 const int textSizeIndex
= m_textWidthBox
->currentIndex();
166 if (arrangement
== QListView::TopToBottom
) {
167 gridWidth
+= TopToBottomBase
+ textSizeIndex
* TopToBottomInc
;
168 gridHeight
+= fontSize
* 6;
171 gridWidth
+= LeftToRightBase
+ textSizeIndex
* LeftToRightInc
;
174 settings
->setGridWidth(gridWidth
);
175 settings
->setGridHeight(gridHeight
);
177 settings
->setFontFamily(font
.family());
178 settings
->setFontSize(fontSize
);
179 settings
->setItalicFont(font
.italic());
180 settings
->setBoldFont(font
.bold());
182 settings
->setNumberOfTextlines(m_textlinesCountBox
->value());
184 settings
->setGridSpacing(GridSpacingBase
+
185 m_gridSpacingBox
->currentIndex() * GridSpacingInc
);
188 void IconsViewSettingsPage::openIconSizeDialog()
190 IconSizeDialog
dialog(this);
191 if (dialog
.exec() == QDialog::Accepted
) {
192 m_iconSize
= dialog
.iconSize();
193 m_previewSize
= dialog
.previewSize();
197 #include "iconsviewsettingspage.moc"