]>
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 <kiconloader.h>
37 #include <kglobalsettings.h>
41 #include <QPushButton>
44 #define GRID_SPACING_BASE 8
45 #define GRID_SPACING_INC 24
47 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow
* mainWindow
,
50 m_mainWindow(mainWindow
),
57 m_textlinesCountBox(0),
62 const int spacing
= KDialog::spacingHint();
63 const int margin
= KDialog::marginHint();
64 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
69 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
70 Q_ASSERT(settings
!= 0);
71 m_iconSize
= settings
->iconSize();
72 m_previewSize
= settings
->previewSize();
74 KHBox
* sizesLayout
= new KHBox(this);
75 sizesLayout
->setSpacing(spacing
);
76 sizesLayout
->setSizePolicy(sizePolicy
);
78 m_iconSizeButton
= new QPushButton(i18n("Change icon and preview size..."), this);
79 connect(m_iconSizeButton
, SIGNAL(clicked()),
80 this, SLOT(openIconSizeDialog()));
82 Q3GroupBox
* textGroup
= new Q3GroupBox(2, Qt::Horizontal
, i18n("Text"), this);
83 textGroup
->setSizePolicy(sizePolicy
);
84 textGroup
->setMargin(margin
);
86 new QLabel(i18n("Font family:"), textGroup
);
87 m_fontFamilyBox
= new QFontComboBox(textGroup
);
88 m_fontFamilyBox
->setCurrentFont(settings
->fontFamily());
90 new QLabel(i18n("Font size:"), textGroup
);
91 m_fontSizeBox
= new QSpinBox(6, 99, 1, textGroup
);
92 m_fontSizeBox
->setValue(settings
->fontSize());
94 new QLabel(i18n("Number of lines:"), textGroup
);
95 m_textlinesCountBox
= new QSpinBox(1, 5, 1, textGroup
);
96 m_textlinesCountBox
->setValue(settings
->numberOfTextlines());
98 new QLabel(i18n("Text width:"), textGroup
);
99 m_textWidthBox
= new QComboBox(textGroup
);
100 m_textWidthBox
->addItem(i18n("Small"));
101 m_textWidthBox
->addItem(i18n("Medium"));
102 m_textWidthBox
->addItem(i18n("Large"));
104 new QLabel(i18n("Additional information:"), textGroup
);
105 m_additionalInfo
= new QComboBox(textGroup
);
106 m_additionalInfo
->addItem(i18n("No Information"), KFileItemDelegate::NoInformation
);
107 m_additionalInfo
->addItem(i18n("MIME Type"), KFileItemDelegate::FriendlyMimeType
);
108 m_additionalInfo
->addItem(i18n("Size"), KFileItemDelegate::Size
);
109 m_additionalInfo
->addItem(i18n("Date"), KFileItemDelegate::ModificationTime
);
110 const int index
= m_additionalInfo
->findData(settings
->additionalInfo());
111 m_additionalInfo
->setCurrentIndex(index
);
113 Q3GroupBox
* gridGroup
= new Q3GroupBox(2, Qt::Horizontal
, i18n("Grid"), this);
114 gridGroup
->setSizePolicy(sizePolicy
);
115 gridGroup
->setMargin(margin
);
117 const bool leftToRightArrangement
= (settings
->arrangement() == QListView::LeftToRight
);
118 new QLabel(i18n("Arrangement:"), gridGroup
);
119 m_arrangementBox
= new QComboBox(gridGroup
);
120 m_arrangementBox
->addItem(i18n("Left to right"));
121 m_arrangementBox
->addItem(i18n("Top to bottom"));
122 m_arrangementBox
->setCurrentIndex(leftToRightArrangement
? 0 : 1);
124 new QLabel(i18n("Grid spacing:"), gridGroup
);
125 m_gridSpacingBox
= new QComboBox(gridGroup
);
126 m_gridSpacingBox
->addItem(i18n("Small"));
127 m_gridSpacingBox
->addItem(i18n("Medium"));
128 m_gridSpacingBox
->addItem(i18n("Large"));
129 m_gridSpacingBox
->setCurrentIndex((settings
->gridSpacing() - GRID_SPACING_BASE
) / GRID_SPACING_INC
);
131 // Add a dummy widget with no restriction regarding
132 // a vertical resizing. This assures that the dialog layout
133 // is not stretched vertically.
136 adjustTextWidthSelection();
139 IconsViewSettingsPage::~IconsViewSettingsPage()
143 void IconsViewSettingsPage::applySettings()
145 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
146 Q_ASSERT(settings
!= 0);
148 settings
->setIconSize(m_iconSize
);
149 settings
->setPreviewSize(m_previewSize
);
151 const int fontSize
= m_fontSizeBox
->value();
153 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
154 QListView::LeftToRight
:
155 QListView::TopToBottom
;
157 settings
->setArrangement(arrangement
);
159 // TODO: this is just a very rough testing code to calculate the grid
161 const int defaultSize
= settings
->iconSize();
162 int gridWidth
= defaultSize
;
163 int gridHeight
= defaultSize
;
164 const int textSizeIndex
= m_textWidthBox
->currentIndex();
165 if (arrangement
== QListView::TopToBottom
) {
166 gridWidth
+= 96 + textSizeIndex
* 32;
170 gridWidth
+= 128 + textSizeIndex
* 64;
173 settings
->setGridWidth(gridWidth
);
174 settings
->setGridHeight(gridHeight
);
176 settings
->setFontFamily(m_fontFamilyBox
->currentFont().family());
177 settings
->setFontSize(fontSize
);
178 settings
->setNumberOfTextlines(m_textlinesCountBox
->value());
179 const int index
= m_additionalInfo
->currentIndex();
180 settings
->setAdditionalInfo(m_additionalInfo
->itemData(index
).toInt());
182 settings
->setGridSpacing(GRID_SPACING_BASE
+
183 m_gridSpacingBox
->currentIndex() * GRID_SPACING_INC
);
186 void IconsViewSettingsPage::openIconSizeDialog()
188 IconSizeDialog
dialog(this);
189 if (dialog
.exec() == QDialog::Accepted
) {
190 m_iconSize
= dialog
.iconSize();
191 m_previewSize
= dialog
.previewSize();
197 void IconsViewSettingsPage::adjustTextWidthSelection()
199 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
200 Q_ASSERT(settings
!= 0);
201 //m_textWidthBox->setCurrentIndex(DolphinSettings::instance().textWidthHint());
204 #include "iconsviewsettingspage.moc"