1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "webzoomslider_p.h" |
|
20 #include "webzoomslider.h" |
|
21 #include "wrtbrowsercontainer.h" |
|
22 #include "WrtPageManager.h" |
|
23 |
|
24 #define SINGLE_STEP 5 |
|
25 |
|
26 namespace WRT { |
|
27 |
|
28 WebZoomSliderPrivate::WebZoomSliderPrivate(WrtPageManager* pageMgr, QWidget* parent) : |
|
29 m_pageMgr(pageMgr), |
|
30 m_slider(0), |
|
31 m_timer(0), |
|
32 m_widgetParent(parent), |
|
33 m_idleTimeout(0), |
|
34 m_dragging(false) |
|
35 { |
|
36 Q_ASSERT(m_pageMgr); |
|
37 |
|
38 m_slider = new QSlider(m_widgetParent); |
|
39 m_slider->setTickPosition(QSlider::NoTicks); |
|
40 m_slider->setTracking(true); |
|
41 m_slider->setRange(WEBPAGE_ZOOM_RANGE_MIN, WEBPAGE_ZOOM_RANGE_MAX); |
|
42 m_slider->setSingleStep(SINGLE_STEP); |
|
43 m_slider->setPageStep(WEBPAGE_ZOOM_PAGE_STEP); |
|
44 } |
|
45 |
|
46 WebZoomSliderPrivate::~WebZoomSliderPrivate() |
|
47 { |
|
48 } |
|
49 |
|
50 /*! |
|
51 * \class WebZoomSlider |
|
52 * |
|
53 * \brief A control for zooming in and out the page |
|
54 */ |
|
55 |
|
56 /*! |
|
57 * Constructor depends on page manager to select current page |
|
58 * @param pageMgr : handle to the pageMgr for this class |
|
59 * @param parent : widget parent handle for this class |
|
60 */ |
|
61 WebZoomSlider::WebZoomSlider(WrtPageManager* pageMgr, QWidget* parent) : |
|
62 QObject(parent), |
|
63 d(new WebZoomSliderPrivate(pageMgr, parent)) |
|
64 { |
|
65 WrtBrowserContainer *page = d->m_pageMgr->currentPage(); |
|
66 int val = (page) ? page->pageZoomFactor() * 100 : 100; |
|
67 if (val < WEBPAGE_ZOOM_RANGE_MIN && val > WEBPAGE_ZOOM_RANGE_MAX) |
|
68 val = 100; |
|
69 d->m_slider->setValue(val); |
|
70 |
|
71 connect(d->m_slider, SIGNAL(valueChanged(int)), this, SLOT(zoom(int))); |
|
72 connect(d->m_slider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed())); |
|
73 connect(d->m_slider, SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); |
|
74 setGeometry(d->m_widgetParent->geometry()); |
|
75 } |
|
76 |
|
77 /*! |
|
78 * Basic destructor |
|
79 */ |
|
80 WebZoomSlider::~WebZoomSlider() |
|
81 { |
|
82 delete d; |
|
83 } |
|
84 |
|
85 /*! |
|
86 Sets the slider 3/4 of the way to the right and centers vertically |
|
87 so slider is 5% below the top of the view and 5% above the bottom of the view, |
|
88 leaving 90% for the height of the slider. |
|
89 Width and other style/sizing is done in ui's qss |
|
90 @param rect : |
|
91 */ |
|
92 void WebZoomSlider::setGeometry(const QRect& rect) |
|
93 { |
|
94 // calc geometry but don't yet show |
|
95 d->m_slider->setOrientation(Qt::Vertical); |
|
96 d->m_slider->setFixedHeight(rect.height() * .90); |
|
97 d->m_slider->move(QPoint(rect.width() * .75 , rect.height() * .05)); |
|
98 } |
|
99 |
|
100 /*! |
|
101 Show the slider and set idle timeout to time since slider last touched |
|
102 */ |
|
103 void WebZoomSlider::show(int idleTimeout) |
|
104 { |
|
105 d->m_idleTimeout = idleTimeout; |
|
106 |
|
107 d->m_slider->show(); |
|
108 |
|
109 // create timer to keep track of elapsed time since user touched slider |
|
110 d->m_timer = new QTimer(this); |
|
111 connect(d->m_timer, SIGNAL(timeout()), this, SIGNAL(idleTimeout())); |
|
112 d->m_timer->start(d->m_idleTimeout); |
|
113 } |
|
114 |
|
115 /*! |
|
116 set the zoom level on the current page according to value |
|
117 @param value : new zoom level to be set |
|
118 */ |
|
119 void WebZoomSlider::zoom ( int value ) |
|
120 { |
|
121 WrtBrowserContainer *page =d->m_pageMgr->currentPage(); |
|
122 if (page) { |
|
123 if (d->m_dragging) |
|
124 page->setPageDirtyZoomFactor(value / 100.00); |
|
125 else |
|
126 page->setPageZoomFactor(value / 100.00); |
|
127 } |
|
128 // stop timer while the slider is pressed or restart timer if slider is controlled by the keyboard |
|
129 if (d->m_dragging) { |
|
130 if (d->m_timer && d->m_timer->isActive()) |
|
131 d->m_timer->stop(); |
|
132 } |
|
133 else |
|
134 d->m_timer->start(d->m_idleTimeout); |
|
135 } |
|
136 |
|
137 void WebZoomSlider::sliderPressed() |
|
138 { |
|
139 d->m_dragging = true; |
|
140 } |
|
141 |
|
142 void WebZoomSlider::sliderReleased() |
|
143 { |
|
144 WrtBrowserContainer *page =d->m_pageMgr->currentPage(); |
|
145 if (page) { |
|
146 page->setPageZoomFactor(d->m_slider->value() / 100.00); |
|
147 } |
|
148 // reset timer |
|
149 d->m_timer->start(d->m_idleTimeout); |
|
150 d->m_dragging = false; |
|
151 } |
|
152 /*! |
|
153 \fn void ImageView::idleTimeout(); |
|
154 emitted when the slider has been idle for some time |
|
155 */ |
|
156 |
|
157 |
|
158 } // namespace WRT |
|