Changeset View
Changeset View
Standalone View
Standalone View
views/kpUnzoomedThumbnailView.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 85 | { | |||
---|---|---|---|---|---|
86 | return i18n ("Unzoomed Mode - Thumbnail"); | 86 | return i18n ("Unzoomed Mode - Thumbnail"); | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | //--------------------------------------------------------------------- | 89 | //--------------------------------------------------------------------- | ||
90 | 90 | | |||
91 | // public slot virtual [base kpView] | 91 | // public slot virtual [base kpView] | ||
92 | void kpUnzoomedThumbnailView::adjustToEnvironment () | 92 | void kpUnzoomedThumbnailView::adjustToEnvironment () | ||
93 | { | 93 | { | ||
94 | if (!buddyView () || !buddyViewScrollableContainer () || !document ()) | 94 | if (!buddyView () || !buddyViewScrollableContainer () || !document ()) { | ||
95 | return; | 95 | return; | ||
96 | } | ||||
96 | 97 | | |||
97 | const int scrollViewContentsX = | 98 | const int scrollViewContentsX = | ||
98 | buddyViewScrollableContainer()->horizontalScrollBar()->value(); | 99 | buddyViewScrollableContainer()->horizontalScrollBar()->value(); | ||
99 | const int scrollViewContentsY = | 100 | const int scrollViewContentsY = | ||
100 | buddyViewScrollableContainer ()->verticalScrollBar()->value(); | 101 | buddyViewScrollableContainer ()->verticalScrollBar()->value(); | ||
101 | 102 | | |||
102 | #if 1 | 103 | #if 1 | ||
103 | int x; | 104 | int x; | ||
104 | if (document ()->width () > width ()) | 105 | if (document ()->width () > width ()) | ||
105 | { | 106 | { | ||
106 | x = static_cast<int> (buddyView ()->transformViewToDocX (scrollViewContentsX)); | 107 | x = static_cast<int> (buddyView ()->transformViewToDocX (scrollViewContentsX)); | ||
107 | const int rightMostAllowedX = qMax (0, document ()->width () - width ()); | 108 | const int rightMostAllowedX = qMax (0, document ()->width () - width ()); | ||
108 | qCDebug(kpLogViews) << "\tdocX=" << x | 109 | qCDebug(kpLogViews) << "\tdocX=" << x | ||
109 | << " docWidth=" << document ()->width () | 110 | << " docWidth=" << document ()->width () | ||
110 | << " rightMostAllowedX=" << rightMostAllowedX | 111 | << " rightMostAllowedX=" << rightMostAllowedX; | ||
111 | << endl; | 112 | if (x > rightMostAllowedX) { | ||
112 | if (x > rightMostAllowedX) | | |||
113 | x = rightMostAllowedX; | 113 | x = rightMostAllowedX; | ||
114 | } | 114 | } | ||
115 | } | ||||
115 | // Thumbnail width <= doc width | 116 | // Thumbnail width <= doc width | ||
116 | else | 117 | else | ||
117 | { | 118 | { | ||
118 | // Center X (rather than flush left to be consistent with | 119 | // Center X (rather than flush left to be consistent with | ||
119 | // kpZoomedThumbnailView) | 120 | // kpZoomedThumbnailView) | ||
120 | x = -(width () - document ()->width ()) / 2; | 121 | x = -(width () - document ()->width ()) / 2; | ||
121 | } | 122 | } | ||
122 | 123 | | |||
123 | 124 | | |||
124 | int y; | 125 | int y; | ||
125 | if (document ()->height () > height ()) | 126 | if (document ()->height () > height ()) | ||
126 | { | 127 | { | ||
127 | y = static_cast<int> (buddyView ()->transformViewToDocY (scrollViewContentsY)); | 128 | y = static_cast<int> (buddyView ()->transformViewToDocY (scrollViewContentsY)); | ||
128 | const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); | 129 | const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); | ||
129 | qCDebug(kpLogViews) << "\tdocY=" << y | 130 | qCDebug(kpLogViews) << "\tdocY=" << y | ||
130 | << " docHeight=" << document ()->height () | 131 | << " docHeight=" << document ()->height () | ||
131 | << " bottomMostAllowedY=" << bottomMostAllowedY | 132 | << " bottomMostAllowedY=" << bottomMostAllowedY; | ||
132 | << endl; | 133 | if (y > bottomMostAllowedY) { | ||
133 | if (y > bottomMostAllowedY) | | |||
134 | y = bottomMostAllowedY; | 134 | y = bottomMostAllowedY; | ||
135 | } | 135 | } | ||
136 | } | ||||
136 | // Thumbnail height <= doc height | 137 | // Thumbnail height <= doc height | ||
137 | else | 138 | else | ||
138 | { | 139 | { | ||
139 | // Center Y (rather than flush top to be consistent with | 140 | // Center Y (rather than flush top to be consistent with | ||
140 | // kpZoomedThumbnailView) | 141 | // kpZoomedThumbnailView) | ||
141 | y = -(height () - document ()->height ()) / 2; | 142 | y = -(height () - document ()->height ()) / 2; | ||
142 | } | 143 | } | ||
143 | // Prefer to keep visible area centred in thumbnail instead of flushed left. | 144 | // Prefer to keep visible area centred in thumbnail instead of flushed left. | ||
144 | // Gives more editing context to the left and top. | 145 | // Gives more editing context to the left and top. | ||
145 | // But feels awkward for left-to-right users. So disabled for now. | 146 | // But feels awkward for left-to-right users. So disabled for now. | ||
146 | // Not totally tested. | 147 | // Not totally tested. | ||
147 | #else | 148 | #else | ||
148 | if (!buddyViewScrollableContainer ()) | 149 | if (!buddyViewScrollableContainer ()) { | ||
149 | return; | 150 | return; | ||
151 | } | ||||
150 | 152 | | |||
151 | QRect docRect = buddyView ()->transformViewToDoc ( | 153 | QRect docRect = buddyView ()->transformViewToDoc ( | ||
152 | QRect (buddyViewScrollableContainer ()->horizontalScrollBar()->value(), | 154 | QRect (buddyViewScrollableContainer ()->horizontalScrollBar()->value(), | ||
153 | buddyViewScrollableContainer ()->verticalScrollBar()->value(), | 155 | buddyViewScrollableContainer ()->verticalScrollBar()->value(), | ||
154 | qMin (buddyView ()->width (), buddyViewScrollableContainer ()->viewport()->width ()), | 156 | qMin (buddyView ()->width (), buddyViewScrollableContainer ()->viewport()->width ()), | ||
155 | qMin (buddyView ()->height (), buddyViewScrollableContainer ()->viewport()->height ()))); | 157 | qMin (buddyView ()->height (), buddyViewScrollableContainer ()->viewport()->height ()))); | ||
156 | 158 | | |||
157 | x = docRect.x () - (width () - docRect.width ()) / 2; | 159 | x = docRect.x () - (width () - docRect.width ()) / 2; | ||
158 | qCDebug(kpLogViews) << "\tnew suggest x=" << x; | 160 | qCDebug(kpLogViews) << "\tnew suggest x=" << x; | ||
159 | const int rightMostAllowedX = qMax (0, document ()->width () - width ()); | 161 | const int rightMostAllowedX = qMax (0, document ()->width () - width ()); | ||
160 | if (x < 0) | 162 | if (x < 0) { | ||
161 | x = 0; | 163 | x = 0; | ||
162 | if (x > rightMostAllowedX) | 164 | } | ||
165 | if (x > rightMostAllowedX) { | ||||
163 | x = rightMostAllowedX; | 166 | x = rightMostAllowedX; | ||
167 | } | ||||
164 | 168 | | |||
165 | y = docRect.y () - (height () - docRect.height ()) / 2; | 169 | y = docRect.y () - (height () - docRect.height ()) / 2; | ||
166 | qCDebug(kpLogViews) << "\tnew suggest y=" << y; | 170 | qCDebug(kpLogViews) << "\tnew suggest y=" << y; | ||
167 | const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); | 171 | const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); | ||
168 | if (y < 0) | 172 | if (y < 0) { | ||
169 | y = 0; | 173 | y = 0; | ||
170 | if (y > bottomMostAllowedY) | 174 | } | ||
175 | if (y > bottomMostAllowedY) { | ||||
171 | y = bottomMostAllowedY; | 176 | y = bottomMostAllowedY; | ||
177 | } | ||||
172 | #endif | 178 | #endif | ||
173 | 179 | | |||
174 | 180 | | |||
175 | if (viewManager ()) | 181 | if (viewManager ()) | ||
176 | { | 182 | { | ||
177 | viewManager ()->setFastUpdates (); | 183 | viewManager ()->setFastUpdates (); | ||
178 | viewManager ()->setQueueUpdates (); | 184 | viewManager ()->setQueueUpdates (); | ||
179 | } | 185 | } | ||
180 | 186 | | |||
181 | { | 187 | { | ||
182 | // OPT: scrollView impl would be much, much faster | 188 | // OPT: scrollView impl would be much, much faster | ||
183 | setOrigin (QPoint (-x, -y)); | 189 | setOrigin (QPoint (-x, -y)); | ||
184 | setMaskToCoverDocument (); | 190 | setMaskToCoverDocument (); | ||
185 | 191 | | |||
186 | // Above might be a NOP even if e.g. doc size changed so force | 192 | // Above might be a NOP even if e.g. doc size changed so force | ||
187 | // update | 193 | // update | ||
188 | if (viewManager ()) | 194 | if (viewManager ()) { | ||
189 | viewManager ()->updateView (this); | 195 | viewManager ()->updateView (this); | ||
190 | } | 196 | } | ||
197 | } | ||||
191 | 198 | | |||
192 | if (viewManager ()) | 199 | if (viewManager ()) | ||
193 | { | 200 | { | ||
194 | viewManager ()->restoreQueueUpdates (); | 201 | viewManager ()->restoreQueueUpdates (); | ||
195 | viewManager ()->restoreFastUpdates (); | 202 | viewManager ()->restoreFastUpdates (); | ||
196 | } | 203 | } | ||
197 | } | 204 | } |