]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/iconsizegroupbox.cpp
Use capitalized KDE includes
[dolphin.git] / src / settings / viewmodes / iconsizegroupbox.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 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 "iconsizegroupbox.h"
21
22 #include <KLocale>
23
24 #include <QApplication>
25 #include <QGridLayout>
26 #include <QHelpEvent>
27 #include <QLabel>
28 #include <QPoint>
29 #include <QRect>
30 #include <QSlider>
31
32 #include <views/zoomlevelinfo.h>
33
34 IconSizeGroupBox::IconSizeGroupBox(QWidget* parent) :
35 QGroupBox(i18nc("@title:group", "Icon Size"), parent),
36 m_defaultSizeSlider(0),
37 m_previewSizeSlider(0)
38 {
39 QLabel* defaultLabel = new QLabel(i18nc("@label:listbox", "Default:"), this);
40 m_defaultSizeSlider = new QSlider(Qt::Horizontal, this);
41 m_defaultSizeSlider->setPageStep(1);
42 m_defaultSizeSlider->setTickPosition(QSlider::TicksBelow);
43 connect(m_defaultSizeSlider, SIGNAL(valueChanged(int)),
44 this, SLOT(slotDefaultSliderMoved(int)));
45
46 QLabel* previewLabel = new QLabel(i18nc("@label:listbox", "Preview:"), this);
47 m_previewSizeSlider = new QSlider(Qt::Horizontal, this);
48 m_previewSizeSlider->setPageStep(1);
49 m_previewSizeSlider->setTickPosition(QSlider::TicksBelow);
50 connect(m_previewSizeSlider, SIGNAL(valueChanged(int)),
51 this, SLOT(slotPreviewSliderMoved(int)));
52
53 QGridLayout* layout = new QGridLayout(this);
54 layout->addWidget(defaultLabel, 0, 0, Qt::AlignRight);
55 layout->addWidget(m_defaultSizeSlider, 0, 1);
56 layout->addWidget(previewLabel, 1, 0, Qt::AlignRight);
57 layout->addWidget(m_previewSizeSlider, 1, 1);
58 }
59
60 IconSizeGroupBox::~IconSizeGroupBox()
61 {
62 }
63
64 void IconSizeGroupBox::setDefaultSizeRange(int min, int max)
65 {
66 m_defaultSizeSlider->setRange(min, max);
67 }
68
69 void IconSizeGroupBox::setPreviewSizeRange(int min, int max)
70 {
71 m_previewSizeSlider->setRange(min, max);
72 }
73
74 void IconSizeGroupBox::setDefaultSizeValue(int value)
75 {
76 m_defaultSizeSlider->setValue(value);
77 }
78
79 int IconSizeGroupBox::defaultSizeValue() const
80 {
81 return m_defaultSizeSlider->value();
82 }
83
84 void IconSizeGroupBox::setPreviewSizeValue(int value)
85 {
86 m_previewSizeSlider->setValue(value);
87 }
88
89 int IconSizeGroupBox::previewSizeValue() const
90 {
91 return m_previewSizeSlider->value();
92 }
93
94 void IconSizeGroupBox::slotDefaultSliderMoved(int value)
95 {
96 showToolTip(m_defaultSizeSlider, value);
97 emit defaultSizeChanged(value);
98 }
99
100 void IconSizeGroupBox::slotPreviewSliderMoved(int value)
101 {
102 showToolTip(m_previewSizeSlider, value);
103 emit previewSizeChanged(value);
104 }
105
106 void IconSizeGroupBox::showToolTip(QSlider* slider, int value)
107 {
108 const int size = ZoomLevelInfo::iconSizeForZoomLevel(value);
109 slider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size));
110 if (!slider->isVisible()) {
111 return;
112 }
113 QPoint global = slider->rect().topLeft();
114 global.ry() += slider->height() / 2;
115 QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), slider->mapToGlobal(global));
116 QApplication::sendEvent(slider, &toolTipEvent);
117 }
118
119 #include "iconsizegroupbox.moc"