91 |
91 |
92 void BrowserWindow::setSlideValue(qreal slideRatio) |
92 void BrowserWindow::setSlideValue(qreal slideRatio) |
93 { |
93 { |
94 // we use a ratio to handle resize corectly |
94 // we use a ratio to handle resize corectly |
95 const int pos = -qRound(slideRatio * width()); |
95 const int pos = -qRound(slideRatio * width()); |
96 m_slidingSurface->scroll(pos - m_browserView->x(), 0); |
96 m_slidingSurface->scroll(pos - m_homeView->x(), 0); |
97 |
97 |
98 if (qFuzzyCompare(slideRatio, static_cast<qreal>(0.0f))) { |
98 if (qFuzzyCompare(slideRatio, static_cast<qreal>(1.0f))) { |
99 m_browserView->show(); |
99 m_browserView->show(); |
100 m_homeView->hide(); |
100 m_homeView->hide(); |
101 } else if (qFuzzyCompare(slideRatio, static_cast<qreal>(1.0f))) { |
101 } else if (qFuzzyCompare(slideRatio, static_cast<qreal>(0.0f))) { |
102 m_homeView->show(); |
102 m_homeView->show(); |
103 m_browserView->hide(); |
103 m_browserView->hide(); |
104 } else { |
104 } else { |
105 m_browserView->show(); |
105 m_browserView->show(); |
106 m_homeView->show(); |
106 m_homeView->show(); |
108 } |
108 } |
109 |
109 |
110 qreal BrowserWindow::slideValue() const |
110 qreal BrowserWindow::slideValue() const |
111 { |
111 { |
112 Q_ASSERT(m_slidingSurface->x() < width()); |
112 Q_ASSERT(m_slidingSurface->x() < width()); |
113 return static_cast<qreal>(qAbs(m_browserView->x())) / width(); |
113 return static_cast<qreal>(qAbs(m_homeView->x())) / width(); |
114 } |
114 } |
115 |
115 |
116 void BrowserWindow::showHomeView() |
116 void BrowserWindow::showHomeView() |
117 { |
117 { |
118 m_animation->setStartValue(slideValue()); |
118 m_animation->setStartValue(slideValue()); |
119 m_animation->setEndValue(1.0f); |
119 m_animation->setEndValue(0.0f); |
120 m_animation->start(); |
120 m_animation->start(); |
121 m_homeView->setFocus(); |
121 m_homeView->setFocus(); |
122 } |
122 } |
123 |
123 |
124 void BrowserWindow::showBrowserView() |
124 void BrowserWindow::showBrowserView() |
125 { |
125 { |
126 m_animation->setStartValue(slideValue()); |
126 m_animation->setStartValue(slideValue()); |
127 m_animation->setEndValue(0.0f); |
127 m_animation->setEndValue(1.0f); |
128 m_animation->start(); |
128 m_animation->start(); |
129 |
129 |
130 m_browserView->setFocus(); |
130 m_browserView->setFocus(); |
131 } |
131 } |
132 |
132 |
138 if (m_animation->state() == QAbstractAnimation::Running) { |
138 if (m_animation->state() == QAbstractAnimation::Running) { |
139 const QAbstractAnimation::Direction direction = m_animation->direction() == QAbstractAnimation::Forward |
139 const QAbstractAnimation::Direction direction = m_animation->direction() == QAbstractAnimation::Forward |
140 ? QAbstractAnimation::Forward |
140 ? QAbstractAnimation::Forward |
141 : QAbstractAnimation::Backward; |
141 : QAbstractAnimation::Backward; |
142 m_animation->setDirection(direction); |
142 m_animation->setDirection(direction); |
143 } else if (qFuzzyCompare(slideValue(), static_cast<qreal>(0.0f))) |
143 } else if (qFuzzyCompare(slideValue(), static_cast<qreal>(1.0f))) |
144 showHomeView(); |
144 showHomeView(); |
145 else |
145 else |
146 showBrowserView(); |
146 showBrowserView(); |
147 event->accept(); |
147 event->accept(); |
148 } |
148 } |
149 } |
149 } |
150 |
150 |
151 void BrowserWindow::resizeEvent(QResizeEvent *event) |
151 void BrowserWindow::resizeEvent(QResizeEvent *event) |
152 { |
152 { |
153 const QSize oldSize = event->oldSize(); |
153 const QSize oldSize = event->oldSize(); |
154 const qreal oldSlidingRatio = static_cast<qreal>(qAbs(m_browserView->x())) / oldSize.width(); |
154 const qreal oldSlidingRatio = static_cast<qreal>(qAbs(m_homeView->x())) / oldSize.width(); |
155 |
155 |
156 const QSize newSize = event->size(); |
156 const QSize newSize = event->size(); |
157 m_slidingSurface->resize(newSize.width() * 2, newSize.height()); |
157 m_slidingSurface->resize(newSize.width() * 2, newSize.height()); |
158 |
158 |
159 m_homeView->resize(newSize); |
159 m_homeView->resize(newSize); |
160 m_homeView->move(newSize.width(), 0); |
160 m_homeView->move(0, 0); |
161 |
161 |
162 m_browserView->resize(newSize); |
162 m_browserView->resize(newSize); |
163 m_browserView->move(0, 0); |
163 m_browserView->move(newSize.width(), 0); |
164 |
164 |
165 setSlideValue(oldSlidingRatio); |
165 setSlideValue(oldSlidingRatio); |
166 } |
166 } |