]> cloud.milkyroute.net Git - dolphin.git/blob - src/iconsviewsettingspage.cpp
Allow to set the 'AdditionalInformation' property from KFileItemDelegate for each...
[dolphin.git] / src / iconsviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "iconsviewsettingspage.h"
21
22 #include "dolphinsettings.h"
23 #include "iconsizedialog.h"
24 #include "pixmapviewer.h"
25
26 #include "dolphin_iconsmodesettings.h"
27
28 #include <qlabel.h>
29 #include <qslider.h>
30 #include <q3buttongroup.h>
31 #include <qradiobutton.h>
32 #include <qspinbox.h>
33 #include <qfontcombobox.h>
34
35 #include <kiconloader.h>
36 #include <kdialog.h>
37 #include <kglobalsettings.h>
38 #include <klocale.h>
39 #include <kvbox.h>
40
41 #include <QPushButton>
42 #include <QListView>
43
44 #define GRID_SPACING_BASE 8
45 #define GRID_SPACING_INC 24
46
47 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow* mainWindow,
48 QWidget* parent) :
49 KVBox(parent),
50 m_mainWindow(mainWindow),
51 m_iconSize(0),
52 m_previewSize(0),
53 m_iconSizeButton(0),
54 m_textWidthBox(0),
55 m_fontFamilyBox(0),
56 m_fontSizeBox(0),
57 m_textlinesCountBox(0),
58 m_arrangementBox(0),
59 m_gridSpacingBox(0)
60 {
61 const int spacing = KDialog::spacingHint();
62 const int margin = KDialog::marginHint();
63 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
64
65 setSpacing(spacing);
66 setMargin(margin);
67
68 IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
69 Q_ASSERT(settings != 0);
70 m_iconSize = settings->iconSize();
71 m_previewSize = settings->previewSize();
72
73 KHBox* sizesLayout = new KHBox(this);
74 sizesLayout->setSpacing(spacing);
75 sizesLayout->setSizePolicy(sizePolicy);
76
77 m_iconSizeButton = new QPushButton(i18n("Change icon and preview size..."), this);
78 connect(m_iconSizeButton, SIGNAL(clicked()),
79 this, SLOT(openIconSizeDialog()));
80
81 Q3GroupBox* textGroup = new Q3GroupBox(2, Qt::Horizontal, i18n("Text"), this);
82 textGroup->setSizePolicy(sizePolicy);
83 textGroup->setMargin(margin);
84
85 new QLabel(i18n("Font family:"), textGroup);
86 m_fontFamilyBox = new QFontComboBox(textGroup);
87 m_fontFamilyBox->setCurrentFont(settings->fontFamily());
88
89 new QLabel(i18n("Font size:"), textGroup);
90 m_fontSizeBox = new QSpinBox(6, 99, 1, textGroup);
91 m_fontSizeBox->setValue(settings->fontSize());
92
93 new QLabel(i18n("Number of lines:"), textGroup);
94 m_textlinesCountBox = new QSpinBox(1, 5, 1, textGroup);
95 m_textlinesCountBox->setValue(settings->numberOfTextlines());
96
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"));
102
103 Q3GroupBox* gridGroup = new Q3GroupBox(2, Qt::Horizontal, i18n("Grid"), this);
104 gridGroup->setSizePolicy(sizePolicy);
105 gridGroup->setMargin(margin);
106
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);
113
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);
120
121 // Add a dummy widget with no restriction regarding
122 // a vertical resizing. This assures that the dialog layout
123 // is not stretched vertically.
124 new QWidget(this);
125
126 adjustTextWidthSelection();
127 }
128
129 IconsViewSettingsPage::~IconsViewSettingsPage()
130 {
131 }
132
133 void IconsViewSettingsPage::applySettings()
134 {
135 IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
136 Q_ASSERT(settings != 0);
137
138 settings->setIconSize(m_iconSize);
139 settings->setPreviewSize(m_previewSize);
140
141 const int fontSize = m_fontSizeBox->value();
142
143 const int arrangement = (m_arrangementBox->currentIndex() == 0) ?
144 QListView::LeftToRight :
145 QListView::TopToBottom;
146
147 settings->setArrangement(arrangement);
148
149 // TODO: this is just a very rough testing code to calculate the grid
150 // width and height
151 const int defaultSize = settings->iconSize();
152 int gridWidth = defaultSize;
153 int gridHeight = defaultSize;
154 const int textSizeIndex = m_textWidthBox->currentIndex();
155 if (arrangement == QListView::TopToBottom) {
156 gridWidth += 96 + textSizeIndex * 32;
157 gridHeight += 64;
158 }
159 else {
160 gridWidth += 128 + textSizeIndex * 64;
161 }
162
163 settings->setGridWidth(gridWidth);
164 settings->setGridHeight(gridHeight);
165
166 settings->setFontFamily(m_fontFamilyBox->currentFont().family());
167 settings->setFontSize(fontSize);
168 settings->setNumberOfTextlines(m_textlinesCountBox->value());
169
170 settings->setGridSpacing(GRID_SPACING_BASE +
171 m_gridSpacingBox->currentIndex() * GRID_SPACING_INC);
172 }
173
174 void IconsViewSettingsPage::openIconSizeDialog()
175 {
176 IconSizeDialog dialog(this);
177 if (dialog.exec() == QDialog::Accepted) {
178 m_iconSize = dialog.iconSize();
179 m_previewSize = dialog.previewSize();
180 }
181 }
182
183
184
185 void IconsViewSettingsPage::adjustTextWidthSelection()
186 {
187 IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
188 Q_ASSERT(settings != 0);
189 //m_textWidthBox->setCurrentIndex(DolphinSettings::instance().textWidthHint());
190 }
191
192 #include "iconsviewsettingspage.moc"