summaryrefslogtreecommitdiffstats
path: root/src/iconsviewsettingspage.cpp
blob: bbe052254ef1d667d5aa910dfbca2eb71d222b04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/***************************************************************************
 *   Copyright (C) 2006 by Peter Penz                                      *
 *   peter.penz@gmx.at                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include "iconsviewsettingspage.h"

#include <tqlabel.h>
#include <tqslider.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>
#include <tqspinbox.h>
#include <kiconloader.h>
#include <tdefontcombo.h>
#include <kdialog.h>
#include <klocale.h>
#include <assert.h>

#include "dolphiniconsviewsettings.h"
#include "dolphinsettings.h"
#include "pixmapviewer.h"

#define GRID_SPACING_BASE 8
#define GRID_SPACING_INC 12

IconsViewSettingsPage::IconsViewSettingsPage(DolphinIconsView::LayoutMode mode,
                                             TQWidget* parent) :
    TQVBox(parent),
    m_mode(mode),
    m_iconSizeSlider(0),
    m_previewSizeSlider(0),
    m_textWidthBox(0),
    m_gridSpacingBox(0),
    m_fontFamilyBox(0),
    m_fontSizeBox(0),
    m_textlinesCountBox(0),
    m_arrangementBox(0)
{
    const int spacing = KDialog::spacingHint();
    const int margin = KDialog::marginHint();
    const TQSizePolicy sizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed);

    setSpacing(spacing);
    setMargin(margin);

    DolphinIconsViewSettings* settings = DolphinSettings::instance().iconsView(m_mode);
    assert(settings != 0);

    TQHBox* sizesLayout = new TQHBox(this);
    sizesLayout->setSpacing(spacing);
    sizesLayout->setSizePolicy(sizePolicy);

    // create 'Icon Size' group including slider and preview
    TQGroupBox* iconSizeGroup = new TQGroupBox(2, Qt::Vertical, i18n("Icon Size"), sizesLayout);
    iconSizeGroup->setSizePolicy(sizePolicy);
    iconSizeGroup->setMargin(margin);

    const TQColor iconBackgroundColor(TDEGlobalSettings::baseColor());

    TQHBox* iconSizeVBox = new TQHBox(iconSizeGroup);
    iconSizeVBox->setSpacing(spacing);
    new TQLabel(i18n("Small"), iconSizeVBox);
    m_iconSizeSlider = new TQSlider(0, 5, 1, 0,  Qt::Horizontal, iconSizeVBox);
    m_iconSizeSlider->setValue(sliderValue(settings->iconSize()));
    m_iconSizeSlider->setTickmarks(TQSlider::Below);
    connect(m_iconSizeSlider, TQT_SIGNAL(valueChanged(int)),
            this, TQT_SLOT(slotIconSizeChanged(int)));
    new TQLabel(i18n("Large"), iconSizeVBox);

    m_iconSizeViewer = new PixmapViewer(iconSizeGroup);
    m_iconSizeViewer->setMinimumWidth(TDEIcon::SizeEnormous);
    m_iconSizeViewer->setFixedHeight(TDEIcon::SizeEnormous);
    m_iconSizeViewer->setEraseColor(iconBackgroundColor);
    slotIconSizeChanged(m_iconSizeSlider->value());

    if (m_mode == DolphinIconsView::Previews) {
        // create 'Preview Size' group including slider and preview
        TQGroupBox* previewSizeGroup = new TQGroupBox(2, Qt::Vertical, i18n("Preview Size"), sizesLayout);
        previewSizeGroup->setSizePolicy(sizePolicy);
        previewSizeGroup->setMargin(margin);

        TQHBox* previewSizeVBox = new TQHBox(previewSizeGroup);
        previewSizeVBox->setSpacing(spacing);
        new TQLabel(i18n("Small"), previewSizeVBox);
        m_previewSizeSlider = new TQSlider(0, 5, 1, 0,  Qt::Horizontal, previewSizeVBox);
        m_previewSizeSlider->setValue(sliderValue(settings->previewSize()));
        m_previewSizeSlider->setTickmarks(TQSlider::Below);
        connect(m_previewSizeSlider, TQT_SIGNAL(valueChanged(int)),
                this, TQT_SLOT(slotPreviewSizeChanged(int)));
        new TQLabel(i18n("Large"), previewSizeVBox);

        m_previewSizeViewer = new PixmapViewer(previewSizeGroup);
        m_previewSizeViewer->setMinimumWidth(TDEIcon::SizeEnormous);
        m_previewSizeViewer->setFixedHeight(TDEIcon::SizeEnormous);
        m_previewSizeViewer->setEraseColor(iconBackgroundColor);

        slotPreviewSizeChanged(m_previewSizeSlider->value());
    }

    TQGroupBox* textGroup = new TQGroupBox(2, Qt::Horizontal, i18n("Text"), this);
    textGroup->setSizePolicy(sizePolicy);
    textGroup->setMargin(margin);

    new TQLabel(i18n("Font family:"), textGroup);
    m_fontFamilyBox = new TDEFontCombo(textGroup);
    m_fontFamilyBox->setCurrentFont(settings->fontFamily());

    new TQLabel(i18n("Font size:"), textGroup);
    m_fontSizeBox = new TQSpinBox(6, 99, 1, textGroup);
    m_fontSizeBox->setValue(settings->fontSize());

    new TQLabel(i18n("Number of lines:"), textGroup);
    m_textlinesCountBox = new TQSpinBox(1, 5, 1, textGroup);
    m_textlinesCountBox->setValue(settings->textlinesCount());

    new TQLabel(i18n("Text width:"), textGroup);
    m_textWidthBox = new TQComboBox(textGroup);
    m_textWidthBox->insertItem(i18n("Small"));
    m_textWidthBox->insertItem(i18n("Medium"));
    m_textWidthBox->insertItem(i18n("Large"));

    TQGroupBox* gridGroup = new TQGroupBox(2, Qt::Horizontal, i18n("Grid"), this);
    gridGroup->setSizePolicy(sizePolicy);
    gridGroup->setMargin(margin);

    const bool leftToRightArrangement = (settings->arrangement() == TQIconView::LeftToRight);
    new TQLabel(i18n("Arrangement:"), gridGroup);
    m_arrangementBox = new TQComboBox(gridGroup);
    m_arrangementBox->insertItem(i18n("Left to right"));
    m_arrangementBox->insertItem(i18n("Top to bottom"));
    m_arrangementBox->setCurrentItem(leftToRightArrangement ? 0 : 1);

    new TQLabel(i18n("Grid spacing:"), gridGroup);
    m_gridSpacingBox = new TQComboBox(gridGroup);
    m_gridSpacingBox->insertItem(i18n("Small"));
    m_gridSpacingBox->insertItem(i18n("Medium"));
    m_gridSpacingBox->insertItem(i18n("Large"));
    m_gridSpacingBox->setCurrentItem((settings->gridSpacing() - GRID_SPACING_BASE) / GRID_SPACING_INC);

    // Add a dummy widget with no restriction regarding
    // a vertical resizing. This assures that the dialog layout
    // is not stretched vertically.
    new TQWidget(this);

    adjustTextWidthSelection();
}

IconsViewSettingsPage::~IconsViewSettingsPage()
{
}

void IconsViewSettingsPage::applySettings()
{
    DolphinIconsViewSettings* settings = DolphinSettings::instance().iconsView(m_mode);
    assert(settings != 0);

    const int defaultSize = iconSize(m_iconSizeSlider->value());
    settings->setIconSize(defaultSize);

    int previewSize = (m_mode == DolphinIconsView::Previews) ?
                      iconSize(m_previewSizeSlider->value()) :
                      defaultSize;
    if (previewSize < defaultSize) {
        // assure that the preview size is never smaller than the icon size
        previewSize = defaultSize;
    }
    settings->setPreviewSize(previewSize);

    const int fontSize = m_fontSizeBox->value();

    TQIconView::Arrangement arrangement = (m_arrangementBox->currentItem() == 0) ?
                                         TQIconView::LeftToRight :
                                         TQIconView::TopToBottom;
    settings->setArrangement(arrangement);
    settings->calculateGridSize(m_textWidthBox->currentItem());

    settings->setFontFamily(m_fontFamilyBox->currentFont());
    settings->setFontSize(fontSize);
    settings->setTextlinesCount(m_textlinesCountBox->value());

    settings->setGridSpacing(GRID_SPACING_BASE +
                             m_gridSpacingBox->currentItem() * GRID_SPACING_INC);
}

void IconsViewSettingsPage::slotIconSizeChanged(int value)
{
    TDEIconLoader iconLoader;
    m_iconSizeViewer->setPixmap(iconLoader.loadIcon("folder", TDEIcon::Desktop, iconSize(value)));

    if (m_previewSizeSlider != 0) {
        int previewSizeValue = m_previewSizeSlider->value();
        if (previewSizeValue < value) {
            // assure that the preview size is never smaller than the icon size
            previewSizeValue = value;
        }
        slotPreviewSizeChanged(previewSizeValue);
    }
}

void IconsViewSettingsPage::slotPreviewSizeChanged(int value)
{
    TDEIconLoader iconLoader;
    const int iconSizeValue = m_iconSizeSlider->value();
    if (value < iconSizeValue) {
        // assure that the preview size is never smaller than the icon size
        value = iconSizeValue;
    }
    m_previewSizeViewer->setPixmap(iconLoader.loadIcon("preview", TDEIcon::Desktop, iconSize(value)));
}

int IconsViewSettingsPage::iconSize(int sliderValue) const
{
    int size = TDEIcon::SizeMedium;
    switch (sliderValue) {
        case 0: size = TDEIcon::SizeSmall; break;
        case 1: size = TDEIcon::SizeSmallMedium; break;
        case 2: size = TDEIcon::SizeMedium; break;
        case 3: size = TDEIcon::SizeLarge; break;
        case 4: size = TDEIcon::SizeHuge; break;
        case 5: size = TDEIcon::SizeEnormous; break;
    }
    return size;
}

int IconsViewSettingsPage::sliderValue(int iconSize) const
{
    int value = 0;
    switch (iconSize) {
        case TDEIcon::SizeSmall: value = 0; break;
        case TDEIcon::SizeSmallMedium: value = 1; break;
        case TDEIcon::SizeMedium: value = 2; break;
        case TDEIcon::SizeLarge: value = 3; break;
        case TDEIcon::SizeHuge: value = 4; break;
        case TDEIcon::SizeEnormous: value = 5; break;
        default: break;
    }
    return value;
}

void IconsViewSettingsPage::adjustTextWidthSelection()
{
    DolphinIconsViewSettings* settings = DolphinSettings::instance().iconsView(m_mode);
    assert(settings != 0);
    m_textWidthBox->setCurrentItem(settings->textWidthHint());
}

#include "iconsviewsettingspage.moc"