]>
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"
24 #include "pixmapviewer.h"
26 #include "dolphin_iconsmodesettings.h"
30 #include <q3buttongroup.h>
31 #include <qradiobutton.h>
33 #include <qfontcombobox.h>
35 #include <kfontrequester.h>
36 #include <kiconloader.h>
38 #include <kglobalsettings.h>
42 #include <QPushButton>
45 #define GRID_SPACING_BASE 8
46 #define GRID_SPACING_INC 24
48 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow
* mainWindow
,
51 m_mainWindow(mainWindow
),
57 m_textlinesCountBox(0),
61 const int spacing
= KDialog::spacingHint();
62 const int margin
= KDialog::marginHint();
63 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
68 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
69 Q_ASSERT(settings
!= 0);
70 m_iconSize
= settings
->iconSize();
71 m_previewSize
= settings
->previewSize();
73 KHBox
* sizesLayout
= new KHBox(this);
74 sizesLayout
->setSpacing(spacing
);
75 sizesLayout
->setSizePolicy(sizePolicy
);
77 m_iconSizeButton
= new QPushButton(i18n("Change icon and preview size..."), this);
78 connect(m_iconSizeButton
, SIGNAL(clicked()),
79 this, SLOT(openIconSizeDialog()));
81 Q3GroupBox
* textGroup
= new Q3GroupBox(2, Qt::Horizontal
, i18n("Text"), this);
82 textGroup
->setSizePolicy(sizePolicy
);
83 textGroup
->setMargin(margin
);
85 new QLabel(i18n("Font:"), textGroup
);
86 m_fontRequester
= new KFontRequester(textGroup
);
87 QFont
font(settings
->fontFamily(),
88 settings
->fontSize());
89 font
.setItalic(settings
->italicFont());
90 font
.setBold(settings
->boldFont());
91 m_fontRequester
->setFont(font
);
93 new QLabel(i18n("Number of lines:"), textGroup
);
94 m_textlinesCountBox
= new QSpinBox(1, 5, 1, textGroup
);
95 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
97 new QLabel(i18n("Text width:"), textGroup
);
98 m_textWidthBox
= new QComboBox(textGroup
);
99 m_textWidthBox
->addItem(i18n("Small"));
100 m_textWidthBox
->addItem(i18n("Medium"));
101 m_textWidthBox
->addItem(i18n("Large"));
103 Q3GroupBox
* gridGroup
= new Q3GroupBox(2, Qt::Horizontal
, i18n("Grid"), this);
104 gridGroup
->setSizePolicy(sizePolicy
);
105 gridGroup
->setMargin(margin
);
107 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
108 new QLabel(i18n("Arrangement:"), gridGroup
);
109 m_arrangementBox
= new QComboBox(gridGroup
);
110 m_arrangementBox
->addItem(i18n("Left to right"));
111 m_arrangementBox
->addItem(i18n("Top to bottom"));
112 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
114 new QLabel(i18n("Grid spacing:"), gridGroup
);
115 m_gridSpacingBox
= new QComboBox(gridGroup
);
116 m_gridSpacingBox
->addItem(i18n("Small"));
117 m_gridSpacingBox
->addItem(i18n("Medium"));
118 m_gridSpacingBox
->addItem(i18n("Large"));
119 m_gridSpacingBox
->setCurrentIndex((settings
->gridSpacing() - GRID_SPACING_BASE
) / GRID_SPACING_INC
);
121 // Add a dummy widget with no restriction regarding
122 // a vertical resizing. This assures that the dialog layout
123 // is not stretched vertically.
126 adjustTextWidthSelection();
129 IconsViewSettingsPage::~IconsViewSettingsPage()
133 void IconsViewSettingsPage::applySettings()
135 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
136 Q_ASSERT(settings
!= 0);
138 settings
->setIconSize(m_iconSize
);
139 settings
->setPreviewSize(m_previewSize
);
141 const QFont font
= m_fontRequester
->font();
142 const int fontSize
= font
.pointSize();
144 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
145 QListView::LeftToRight
:
146 QListView::TopToBottom
;
148 settings
->setArrangement(arrangement
);
150 // TODO: this is just a very rough testing code to calculate the grid
152 const int defaultSize
= settings
->iconSize();
153 int gridWidth
= defaultSize
;
154 int gridHeight
= defaultSize
;
155 const int textSizeIndex
= m_textWidthBox
->currentIndex();
156 if (arrangement
== QListView::TopToBottom
) {
157 gridWidth
+= 96 + textSizeIndex
* 32;
161 gridWidth
+= 128 + textSizeIndex
* 64;
164 settings
->setGridWidth(gridWidth
);
165 settings
->setGridHeight(gridHeight
);
167 settings
->setFontFamily(font
.family());
168 settings
->setFontSize(fontSize
);
169 settings
->setItalicFont(font
.italic());
170 settings
->setBoldFont(font
.bold());
172 settings
->setNumberOfTextlines(m_textlinesCountBox
->value());
174 settings
->setGridSpacing(GRID_SPACING_BASE
+
175 m_gridSpacingBox
->currentIndex() * GRID_SPACING_INC
);
178 void IconsViewSettingsPage::openIconSizeDialog()
180 IconSizeDialog
dialog(this);
181 if (dialog
.exec() == QDialog::Accepted
) {
182 m_iconSize
= dialog
.iconSize();
183 m_previewSize
= dialog
.previewSize();
189 void IconsViewSettingsPage::adjustTextWidthSelection()
191 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
192 Q_ASSERT(settings
!= 0);
193 //m_textWidthBox->setCurrentIndex(DolphinSettings::instance().textWidthHint());
196 #include "iconsviewsettingspage.moc"