]>
cloud.milkyroute.net Git - dolphin.git/blob - src/iconsviewsettingspage.cpp
3492b3a651bb7467004e2f8c188844ec81f57e13
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>
42 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow
* mainWindow
,
45 m_mainWindow(mainWindow
),
51 m_textlinesCountBox(0),
55 const int spacing
= KDialog::spacingHint();
56 const int margin
= KDialog::marginHint();
57 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
62 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
63 Q_ASSERT(settings
!= 0);
64 m_iconSize
= settings
->iconSize();
65 m_previewSize
= settings
->previewSize();
67 m_iconSizeButton
= new QPushButton(i18n("Change Icon && Preview Size..."), this);
68 connect(m_iconSizeButton
, SIGNAL(clicked()),
69 this, SLOT(openIconSizeDialog()));
71 // create 'Text' group for selecting the font, the number of lines
73 QGroupBox
* textGroup
= new QGroupBox(i18n("Text"), this);
74 textGroup
->setSizePolicy(sizePolicy
);
76 QLabel
* fontLabel
= new QLabel(i18n("Font:"), textGroup
);
77 m_fontRequester
= new KFontRequester(textGroup
);
78 QFont
font(settings
->fontFamily(),
79 settings
->fontSize());
80 font
.setItalic(settings
->italicFont());
81 font
.setBold(settings
->boldFont());
82 m_fontRequester
->setFont(font
);
84 QLabel
* textlinesCountLabel
= new QLabel(i18n("Number of lines:"), textGroup
);
85 m_textlinesCountBox
= new QSpinBox(1, 5, 1, textGroup
);
86 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
88 QLabel
* textWidthLabel
= new QLabel(i18n("Text width:"), textGroup
);
89 m_textWidthBox
= new QComboBox(textGroup
);
90 m_textWidthBox
->addItem(i18n("Small"));
91 m_textWidthBox
->addItem(i18n("Medium"));
92 m_textWidthBox
->addItem(i18n("Large"));
94 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
95 int textWidthIndex
= 0;
96 const int remainingWidth
= settings
->gridWidth() - settings
->iconSize();
97 if (leftToRightArrangement
) {
98 textWidthIndex
= (remainingWidth
- LeftToRightBase
) / LeftToRightInc
;
101 textWidthIndex
= (remainingWidth
- TopToBottomBase
) / TopToBottomInc
;
103 // ensure that chosen index is always valid
104 textWidthIndex
= qMax(textWidthIndex
,0);
105 textWidthIndex
= qMin(textWidthIndex
,m_textWidthBox
->count()-1);
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"