1 /***************************************************************************
2 * Copyright (C) 2008 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 "iconsizegroupbox.h"
24 #include <QApplication>
25 #include <QGridLayout>
32 #include "zoomlevelinfo.h"
34 IconSizeGroupBox::IconSizeGroupBox(QWidget
* parent
) :
35 QGroupBox(i18nc("@title:group", "Icon Size"), parent
),
36 m_defaultSizeSlider(0),
37 m_previewSizeSlider(0)
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(sliderMoved(int)),
44 this, SLOT(slotDefaultSliderMoved(int)));
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(sliderMoved(int)),
51 this, SLOT(slotPreviewSliderMoved(int)));
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);
60 IconSizeGroupBox::~IconSizeGroupBox()
64 void IconSizeGroupBox::setDefaultSizeRange(int min
, int max
)
66 m_defaultSizeSlider
->setRange(min
, max
);
69 void IconSizeGroupBox::setPreviewSizeRange(int min
, int max
)
71 m_previewSizeSlider
->setRange(min
, max
);
74 void IconSizeGroupBox::setDefaultSizeValue(int value
)
76 m_defaultSizeSlider
->setValue(value
);
79 int IconSizeGroupBox::defaultSizeValue() const
81 return m_defaultSizeSlider
->value();
84 void IconSizeGroupBox::setPreviewSizeValue(int value
)
86 m_previewSizeSlider
->setValue(value
);
89 int IconSizeGroupBox::previewSizeValue() const
91 return m_previewSizeSlider
->value();
94 void IconSizeGroupBox::slotDefaultSliderMoved(int value
)
96 showToolTip(m_defaultSizeSlider
, value
);
97 emit
defaultSizeChanged(value
);
100 void IconSizeGroupBox::slotPreviewSliderMoved(int value
)
102 showToolTip(m_previewSizeSlider
, value
);
103 emit
previewSizeChanged(value
);
106 void IconSizeGroupBox::showToolTip(QSlider
* slider
, int value
)
108 const int size
= ZoomLevelInfo::iconSizeForZoomLevel(value
);
109 slider
->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size
));
110 QPoint global
= slider
->rect().topLeft();
111 global
.ry() += slider
->height() / 2;
112 QHelpEvent
toolTipEvent(QEvent::ToolTip
, QPoint(0, 0), slider
->mapToGlobal(global
));
113 QApplication::sendEvent(slider
, &toolTipEvent
);
116 #include "iconsizegroupbox.moc"