]>
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),
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 family:"), textGroup
);
86 m_fontFamilyBox
= new QFontComboBox(textGroup
);
87 m_fontFamilyBox
->setCurrentFont(settings
->fontFamily());
89 new QLabel(i18n("Font size:"), textGroup
);
90 m_fontSizeBox
= new QSpinBox(6, 99, 1, textGroup
);
91 m_fontSizeBox
->setValue(settings
->fontSize());
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 int fontSize
= m_fontSizeBox
->value();
143 const int arrangement
= (m_arrangementBox
->currentIndex() == 0) ?
144 QListView::LeftToRight
:
145 QListView::TopToBottom
;
147 settings
->setArrangement(arrangement
);
149 // TODO: this is just a very rough testing code to calculate the grid
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;
160 gridWidth
+= 128 + textSizeIndex
* 64;
163 settings
->setGridWidth(gridWidth
);
164 settings
->setGridHeight(gridHeight
);
166 settings
->setFontFamily(m_fontFamilyBox
->currentFont().family());
167 settings
->setFontSize(fontSize
);
168 settings
->setNumberOfTextlines(m_textlinesCountBox
->value());
170 settings
->setGridSpacing(GRID_SPACING_BASE
+
171 m_gridSpacingBox
->currentIndex() * GRID_SPACING_INC
);
174 void IconsViewSettingsPage::openIconSizeDialog()
176 IconSizeDialog
dialog(this);
177 if (dialog
.exec() == QDialog::Accepted
) {
178 m_iconSize
= dialog
.iconSize();
179 m_previewSize
= dialog
.previewSize();
185 void IconsViewSettingsPage::adjustTextWidthSelection()
187 IconsModeSettings
* settings
= DolphinSettings::instance().iconsModeSettings();
188 Q_ASSERT(settings
!= 0);
189 //m_textWidthBox->setCurrentIndex(DolphinSettings::instance().textWidthHint());
192 #include "iconsviewsettingspage.moc"