]> cloud.milkyroute.net Git - dolphin.git/blob - src/iconsviewsettingspage.cpp
implemented cut, copy & paste for sidebar context
[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
25 #include "dolphin_iconsmodesettings.h"
26
27 #include <kdialog.h>
28 #include <kfontrequester.h>
29 #include <kiconloader.h>
30 #include <kglobalsettings.h>
31 #include <klocale.h>
32
33 #include <QComboBox>
34 #include <QGroupBox>
35 #include <QLabel>
36 #include <QListView>
37 #include <QPushButton>
38 #include <QSpinBox>
39 #include <QGridLayout>
40
41 IconsViewSettingsPage::IconsViewSettingsPage(DolphinMainWindow* mainWindow,
42 QWidget* parent) :
43 KVBox(parent),
44 m_mainWindow(mainWindow),
45 m_iconSize(0),
46 m_previewSize(0),
47 m_iconSizeButton(0),
48 m_textWidthBox(0),
49 m_fontRequester(0),
50 m_textlinesCountBox(0),
51 m_arrangementBox(0),
52 m_gridSpacingBox(0)
53 {
54 const int spacing = KDialog::spacingHint();
55 const int margin = KDialog::marginHint();
56 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
57
58 setSpacing(spacing);
59 setMargin(margin);
60
61 IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
62 Q_ASSERT(settings != 0);
63 m_iconSize = settings->iconSize();
64 m_previewSize = settings->previewSize();
65
66 m_iconSizeButton = new QPushButton(i18n("Change icon and preview size..."), this);
67 connect(m_iconSizeButton, SIGNAL(clicked()),
68 this, SLOT(openIconSizeDialog()));
69
70 // create 'Text' group for selecting the font, the number of lines
71 // and the text width
72 QGroupBox* textGroup = new QGroupBox(i18n("Text"), this);
73 textGroup->setSizePolicy(sizePolicy);
74
75 QLabel* fontLabel = new QLabel(i18n("Font:"), textGroup);
76 m_fontRequester = new KFontRequester(textGroup);
77 QFont font(settings->fontFamily(),
78 settings->fontSize());
79 font.setItalic(settings->italicFont());
80 font.setBold(settings->boldFont());
81 m_fontRequester->setFont(font);
82
83 QLabel* textlinesCountLabel = new QLabel(i18n("Number of lines:"), textGroup);
84 m_textlinesCountBox = new QSpinBox(1, 5, 1, textGroup);
85 m_textlinesCountBox->setValue(settings->numberOfTextlines());
86
87 QLabel* textWidthLabel = new QLabel(i18n("Text width:"), textGroup);
88 m_textWidthBox = new QComboBox(textGroup);
89 m_textWidthBox->addItem(i18n("Small"));
90 m_textWidthBox->addItem(i18n("Medium"));
91 m_textWidthBox->addItem(i18n("Large"));
92
93 const bool leftToRightArrangement = (settings->arrangement() == QListView::LeftToRight);
94 int textWidthIndex = 0;
95 const int remainingWidth = settings->gridWidth() - settings->iconSize();
96 if (leftToRightArrangement) {
97 textWidthIndex = (remainingWidth - LeftToRightBase) / LeftToRightInc;
98 }
99 else {
100 textWidthIndex = (remainingWidth - TopToBottomBase) / TopToBottomInc;
101 }
102
103 m_textWidthBox->setCurrentIndex(textWidthIndex);
104
105 QGridLayout* textGroupLayout = new QGridLayout(textGroup);
106 textGroupLayout->addWidget(fontLabel, 0, 0);
107 textGroupLayout->addWidget(m_fontRequester, 0, 1);
108 textGroupLayout->addWidget(textlinesCountLabel, 1, 0);
109 textGroupLayout->addWidget(m_textlinesCountBox, 1, 1);
110 textGroupLayout->addWidget(textWidthLabel, 2, 0);
111 textGroupLayout->addWidget(m_textWidthBox, 2, 1);
112
113 // create the 'Grid' group for selecting the arrangement and the grid spacing
114 QGroupBox* gridGroup = new QGroupBox(i18n("Grid"), this);
115 gridGroup->setSizePolicy(sizePolicy);
116
117 QLabel* arrangementLabel = new QLabel(i18n("Arrangement:"), gridGroup);
118 m_arrangementBox = new QComboBox(gridGroup);
119 m_arrangementBox->addItem(i18n("Left to right"));
120 m_arrangementBox->addItem(i18n("Top to bottom"));
121 m_arrangementBox->setCurrentIndex(leftToRightArrangement ? 0 : 1);
122
123 QLabel* gridSpacingLabel = new QLabel(i18n("Grid spacing:"), gridGroup);
124 m_gridSpacingBox = new QComboBox(gridGroup);
125 m_gridSpacingBox->addItem(i18n("Small"));
126 m_gridSpacingBox->addItem(i18n("Medium"));
127 m_gridSpacingBox->addItem(i18n("Large"));
128 m_gridSpacingBox->setCurrentIndex((settings->gridSpacing() - GridSpacingBase) / GridSpacingInc);
129
130 QGridLayout* gridGroupLayout = new QGridLayout(gridGroup);
131 gridGroupLayout->addWidget(arrangementLabel, 0, 0);
132 gridGroupLayout->addWidget(m_arrangementBox, 0, 1);
133 gridGroupLayout->addWidget(gridSpacingLabel, 1, 0);
134 gridGroupLayout->addWidget(m_gridSpacingBox, 1, 1);
135
136 // Add a dummy widget with no restriction regarding
137 // a vertical resizing. This assures that the dialog layout
138 // is not stretched vertically.
139 new QWidget(this);
140 }
141
142 IconsViewSettingsPage::~IconsViewSettingsPage()
143 {
144 }
145
146 void IconsViewSettingsPage::applySettings()
147 {
148 IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
149 Q_ASSERT(settings != 0);
150
151 settings->setIconSize(m_iconSize);
152 settings->setPreviewSize(m_previewSize);
153
154 const QFont font = m_fontRequester->font();
155 const int fontSize = font.pointSize();
156
157 const int arrangement = (m_arrangementBox->currentIndex() == 0) ?
158 QListView::LeftToRight :
159 QListView::TopToBottom;
160 settings->setArrangement(arrangement);
161
162 const int defaultSize = settings->iconSize();
163 int gridWidth = defaultSize;
164 int gridHeight = defaultSize;
165 const int textSizeIndex = m_textWidthBox->currentIndex();
166 if (arrangement == QListView::TopToBottom) {
167 gridWidth += TopToBottomBase + textSizeIndex * TopToBottomInc;
168 gridHeight += fontSize * 6;
169 }
170 else {
171 gridWidth += LeftToRightBase + textSizeIndex * LeftToRightInc;
172 }
173
174 settings->setGridWidth(gridWidth);
175 settings->setGridHeight(gridHeight);
176
177 settings->setFontFamily(font.family());
178 settings->setFontSize(fontSize);
179 settings->setItalicFont(font.italic());
180 settings->setBoldFont(font.bold());
181
182 settings->setNumberOfTextlines(m_textlinesCountBox->value());
183
184 settings->setGridSpacing(GridSpacingBase +
185 m_gridSpacingBox->currentIndex() * GridSpacingInc);
186 }
187
188 void IconsViewSettingsPage::openIconSizeDialog()
189 {
190 IconSizeDialog dialog(this);
191 if (dialog.exec() == QDialog::Accepted) {
192 m_iconSize = dialog.iconSize();
193 m_previewSize = dialog.previewSize();
194 }
195 }
196
197 #include "iconsviewsettingspage.moc"