2542.1.2
by Jason Smith
add missing files |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2012 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
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, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Jason Smith <jason.smith@canonical.com>
|
|
18 |
*/
|
|
19 |
||
20 |
#include "CoverflowResultView.h" |
|
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
21 |
#include <UnityCore/Variant.h> |
2542.1.2
by Jason Smith
add missing files |
22 |
#include "unity-shared/IconLoader.h" |
23 |
#include "unity-shared/IconTexture.h" |
|
2542.1.6
by Jason Smith
change sizing to make fit |
24 |
#include "unity-shared/DashStyle.h" |
2542.1.10
by Jason Smith
make previews pop up |
25 |
#include "unity-shared/UBusMessages.h" |
26 |
#include "unity-shared/UBusWrapper.h" |
|
2542.1.2
by Jason Smith
add missing files |
27 |
#include <Nux/Nux.h> |
28 |
#include <Nux/View.h> |
|
29 |
#include <Nux/Coverflow.h> |
|
30 |
#include <Nux/CoverflowModel.h> |
|
31 |
#include <Nux/CoverflowItem.h> |
|
32 |
#include <Nux/HLayout.h> |
|
33 |
||
34 |
||
35 |
namespace unity |
|
36 |
{
|
|
37 |
namespace dash |
|
38 |
{
|
|
39 |
||
40 |
NUX_IMPLEMENT_OBJECT_TYPE(CoverflowResultView); |
|
41 |
||
42 |
class CoverflowResultItem : public nux::CoverflowItem |
|
43 |
{
|
|
44 |
public: |
|
2542.1.10
by Jason Smith
make previews pop up |
45 |
CoverflowResultItem(Result& result, CoverflowResultView *parent, nux::CoverflowModel::Ptr model); |
2542.1.2
by Jason Smith
add missing files |
46 |
~CoverflowResultItem(); |
47 |
||
48 |
nux::ObjectPtr<nux::BaseTexture> GetTexture() const; |
|
2542.1.9
by Jason Smith
make work with previews |
49 |
virtual void Activate(int button); |
2542.1.2
by Jason Smith
add missing files |
50 |
|
2542.1.10
by Jason Smith
make previews pop up |
51 |
int Index(); |
2542.1.11
by Jason Smith
make browser previews work |
52 |
std::string Uri(); |
2542.1.10
by Jason Smith
make previews pop up |
53 |
|
2542.1.2
by Jason Smith
add missing files |
54 |
Result result_; |
55 |
CoverflowResultView* parent_; |
|
2542.1.10
by Jason Smith
make previews pop up |
56 |
nux::CoverflowModel::Ptr model_; |
2542.1.2
by Jason Smith
add missing files |
57 |
IconTexture *icon_texture_; |
2542.1.10
by Jason Smith
make previews pop up |
58 |
UBusManager ubus_; |
2542.1.2
by Jason Smith
add missing files |
59 |
};
|
60 |
||
61 |
class CoverflowResultView::Impl : public sigc::trackable |
|
62 |
{
|
|
63 |
public: |
|
64 |
Impl(CoverflowResultView *parent); |
|
65 |
~Impl(); |
|
66 |
||
67 |
void ComputeFlatIcons(); |
|
2542.1.11
by Jason Smith
make browser previews work |
68 |
int GetIndexForUri(std::string uri); |
2542.1.12
by Jason Smith
make preview move left/right |
69 |
std::string GetUriForIndex(int index); |
2542.1.2
by Jason Smith
add missing files |
70 |
|
71 |
CoverflowResultView *parent_; |
|
72 |
nux::Coverflow *coverflow_; |
|
73 |
nux::HLayout* layout_; |
|
2542.1.10
by Jason Smith
make previews pop up |
74 |
UBusManager ubus_; |
2542.1.2
by Jason Smith
add missing files |
75 |
};
|
76 |
||
2542.1.10
by Jason Smith
make previews pop up |
77 |
CoverflowResultItem::CoverflowResultItem(Result& result, CoverflowResultView *parent, nux::CoverflowModel::Ptr model) |
2542.1.2
by Jason Smith
add missing files |
78 |
: CoverflowItem(result.name()) |
79 |
, result_(result) |
|
80 |
, parent_(parent) |
|
2542.1.10
by Jason Smith
make previews pop up |
81 |
, model_(model) |
2542.1.2
by Jason Smith
add missing files |
82 |
{
|
2542.1.6
by Jason Smith
change sizing to make fit |
83 |
Style& style = Style::Instance(); |
2542.1.2
by Jason Smith
add missing files |
84 |
std::string const& icon_hint = result.icon_hint; |
85 |
std::string icon_name = !icon_hint.empty() ? icon_hint : ". GThemedIcon text-x-preview"; |
|
2542.1.6
by Jason Smith
change sizing to make fit |
86 |
static const int element_size = style.GetTileHeight(); |
2542.1.2
by Jason Smith
add missing files |
87 |
|
88 |
icon_texture_ = new IconTexture(icon_name.c_str(), element_size, true); |
|
2616.1.1
by Jason Smith
Fix crash |
89 |
icon_texture_->SinkReference(); |
2542.1.2
by Jason Smith
add missing files |
90 |
icon_texture_->LoadIcon(); |
91 |
||
92 |
icon_texture_->texture_updated.connect([&] (nux::BaseTexture *texture) |
|
93 |
{
|
|
94 |
if (parent_) |
|
95 |
parent_->NeedRedraw(); |
|
96 |
});
|
|
97 |
}
|
|
98 |
||
99 |
CoverflowResultItem::~CoverflowResultItem() |
|
100 |
{
|
|
2616.1.1
by Jason Smith
Fix crash |
101 |
icon_texture_->UnReference(); |
2542.1.2
by Jason Smith
add missing files |
102 |
}
|
103 |
||
2542.1.11
by Jason Smith
make browser previews work |
104 |
std::string CoverflowResultItem::Uri() |
105 |
{
|
|
106 |
return result_.uri(); |
|
107 |
}
|
|
108 |
||
2542.1.10
by Jason Smith
make previews pop up |
109 |
int CoverflowResultItem::Index() |
110 |
{
|
|
111 |
int i = 0; |
|
112 |
for (auto item : model_->Items()) |
|
113 |
{
|
|
114 |
if (this == item.GetPointer()) |
|
115 |
return i; |
|
116 |
i++; |
|
117 |
}
|
|
118 |
return -1; |
|
119 |
}
|
|
120 |
||
2542.1.2
by Jason Smith
add missing files |
121 |
nux::ObjectPtr<nux::BaseTexture> CoverflowResultItem::GetTexture() const |
122 |
{
|
|
123 |
return nux::ObjectPtr<nux::BaseTexture>(icon_texture_->texture()); |
|
124 |
}
|
|
125 |
||
2542.1.9
by Jason Smith
make work with previews |
126 |
void CoverflowResultItem::Activate(int button) |
2542.1.2
by Jason Smith
add missing files |
127 |
{
|
2740.6.1
by Nick Dedekind
Preview opens immediately with spinner if takes longer that 300ms. |
128 |
int index = Index(); |
129 |
int size = model_->Items().size(); |
|
130 |
||
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
131 |
glib::Variant data(g_variant_new("(iiii)", 0, 0, index, size - index)); |
132 |
||
2674.4.1
by Nic d'Offay
Fixed mouse selection with Coverflow. |
133 |
//Left and right click take you to previews.
|
134 |
if (button == 1 || button == 3) |
|
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
135 |
parent_->Activate(result_.uri, index, ResultView::ActivateType::PREVIEW); |
2674.4.1
by Nic d'Offay
Fixed mouse selection with Coverflow. |
136 |
//Scroll click opens up music player.
|
137 |
else if (button == 2) |
|
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
138 |
parent_->Activate(result_.uri, index, ResultView::ActivateType::DIRECT); |
139 |
||
2542.1.2
by Jason Smith
add missing files |
140 |
}
|
141 |
||
142 |
CoverflowResultView::Impl::Impl(CoverflowResultView *parent) |
|
143 |
: parent_(parent) |
|
144 |
, coverflow_(new nux::Coverflow) |
|
145 |
, layout_(new nux::HLayout()) |
|
146 |
{
|
|
147 |
layout_->AddView(coverflow_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
|
148 |
parent_->SetLayout(layout_); |
|
149 |
||
150 |
coverflow_->SetCameraDistance(1.44); |
|
151 |
coverflow_->fov = 60; |
|
152 |
coverflow_->folding_angle = 45; |
|
153 |
coverflow_->true_perspective = false; |
|
154 |
coverflow_->camera_motion_drift_enabled = false; |
|
155 |
coverflow_->show_reflection = true; |
|
156 |
coverflow_->folding_depth = .25; |
|
157 |
coverflow_->reflection_strength = .2f; |
|
158 |
//coverflow_->folding_rate = 3.5;
|
|
159 |
coverflow_->kinetic_scroll_rate = 0.05f; |
|
160 |
coverflow_->mouse_drag_rate = 1.5f; |
|
161 |
coverflow_->pinching = 0.2f; |
|
162 |
coverflow_->y_offset = 0.15f; |
|
163 |
coverflow_->reflection_size = .5f; |
|
2542.1.11
by Jason Smith
make browser previews work |
164 |
|
165 |
ubus_.RegisterInterest(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, [&] (GVariant* data) { |
|
166 |
int nav_mode = 0; |
|
2676.2.1
by Andrea Azzarone
Fix bug 1048420 |
167 |
glib::String uri; |
168 |
glib::String proposed_unique_id; |
|
169 |
||
2542.1.11
by Jason Smith
make browser previews work |
170 |
g_variant_get(data, "(iss)", &nav_mode, &uri, &proposed_unique_id); |
171 |
||
2676.2.1
by Andrea Azzarone
Fix bug 1048420 |
172 |
if (proposed_unique_id.Str() != parent_->unique_id()) |
2542.1.11
by Jason Smith
make browser previews work |
173 |
return; |
174 |
||
175 |
unsigned num_results = coverflow_->model()->Items().size(); |
|
176 |
int current_index = GetIndexForUri(uri); |
|
177 |
if (nav_mode == -1) // left |
|
178 |
{
|
|
179 |
current_index--; |
|
180 |
}
|
|
181 |
else if (nav_mode == 1) // right |
|
182 |
{
|
|
183 |
current_index++; |
|
184 |
}
|
|
185 |
||
186 |
if (current_index < 0 || static_cast<unsigned int>(current_index) >= num_results) |
|
187 |
{
|
|
188 |
return; |
|
189 |
}
|
|
190 |
||
191 |
if (nav_mode) |
|
192 |
{
|
|
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
193 |
std::string uri = GetUriForIndex(current_index); |
194 |
parent_->Activate(uri, current_index, ActivateType::PREVIEW); |
|
2542.1.11
by Jason Smith
make browser previews work |
195 |
}
|
196 |
});
|
|
2542.1.2
by Jason Smith
add missing files |
197 |
}
|
198 |
||
199 |
CoverflowResultView::Impl::~Impl() |
|
200 |
{
|
|
201 |
||
202 |
}
|
|
203 |
||
2542.1.11
by Jason Smith
make browser previews work |
204 |
int CoverflowResultView::Impl::GetIndexForUri(std::string uri) |
205 |
{
|
|
206 |
int i = 0; |
|
207 |
for (auto item : coverflow_->model()->Items()) |
|
208 |
{
|
|
209 |
if (uri == static_cast<CoverflowResultItem*>(item.GetPointer())->Uri()) |
|
210 |
return i; |
|
211 |
i++; |
|
212 |
}
|
|
213 |
return -1; |
|
214 |
}
|
|
215 |
||
2542.1.12
by Jason Smith
make preview move left/right |
216 |
std::string CoverflowResultView::Impl::GetUriForIndex(int index) |
217 |
{
|
|
218 |
return static_cast<CoverflowResultItem*>(coverflow_->model()->Items()[index].GetPointer())->Uri(); |
|
219 |
}
|
|
220 |
||
2542.1.2
by Jason Smith
add missing files |
221 |
CoverflowResultView::CoverflowResultView(NUX_FILE_LINE_DECL) |
222 |
: ResultView(NUX_FILE_LINE_PARAM) |
|
223 |
, pimpl(new CoverflowResultView::Impl(this)) |
|
224 |
{
|
|
2542.1.6
by Jason Smith
change sizing to make fit |
225 |
Style& style = Style::Instance(); |
226 |
SetMinimumHeight(style.GetTileHeight()); |
|
2542.1.2
by Jason Smith
add missing files |
227 |
}
|
228 |
||
229 |
CoverflowResultView::~CoverflowResultView() |
|
230 |
{
|
|
231 |
||
232 |
}
|
|
233 |
||
234 |
void CoverflowResultView::SetModelRenderer(ResultRenderer* renderer) |
|
235 |
{
|
|
236 |
return; // abstracting breaks down here. Needs to be reworked. |
|
237 |
}
|
|
238 |
||
239 |
void CoverflowResultView::AddResult(Result& result) |
|
240 |
{
|
|
2542.1.10
by Jason Smith
make previews pop up |
241 |
nux::CoverflowItem::Ptr result_item(new CoverflowResultItem(result, this, pimpl->coverflow_->model())); |
2542.1.2
by Jason Smith
add missing files |
242 |
pimpl->coverflow_->model()->AddItem(result_item); |
243 |
}
|
|
244 |
||
245 |
void CoverflowResultView::RemoveResult(Result& result) |
|
246 |
{
|
|
247 |
// Ineffecient, API needs to be improved in Coverflow?
|
|
248 |
for (nux::CoverflowItem::Ptr item : pimpl->coverflow_->model()->Items()) |
|
249 |
{
|
|
250 |
CoverflowResultItem *result_item = static_cast<CoverflowResultItem*>(item.GetPointer()); |
|
251 |
||
252 |
if (result_item->result_.uri == result.uri) // maybe? |
|
253 |
{
|
|
254 |
pimpl->coverflow_->model()->RemoveItem(item); |
|
255 |
break; |
|
256 |
}
|
|
257 |
}
|
|
258 |
}
|
|
259 |
||
260 |
void CoverflowResultView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
|
261 |
{
|
|
262 |
// do nothing here
|
|
263 |
}
|
|
264 |
||
265 |
void CoverflowResultView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) |
|
266 |
{
|
|
267 |
nux::Geometry base = GetGeometry(); |
|
268 |
GfxContext.PushClippingRectangle(base); |
|
269 |
||
2638.1.2
by Jay Taoko
Work in progress |
270 |
if (RedirectedAncestor()) |
271 |
{
|
|
272 |
// This is necessary when doing redirected rendering. Clean the area below this view.
|
|
273 |
unsigned int current_alpha_blend; |
|
274 |
unsigned int current_src_blend_factor; |
|
275 |
unsigned int current_dest_blend_factor; |
|
276 |
GfxContext.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); |
|
277 |
||
278 |
GfxContext.GetRenderStates().SetBlend(false); |
|
279 |
GfxContext.QRP_Color(GetX(), GetY(), GetWidth(), GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); |
|
280 |
||
281 |
GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); |
|
282 |
}
|
|
283 |
||
2542.1.2
by Jason Smith
add missing files |
284 |
if (GetCompositionLayout()) |
285 |
{
|
|
286 |
nux::Geometry geo = GetCompositionLayout()->GetGeometry(); |
|
287 |
GetCompositionLayout()->ProcessDraw(GfxContext, force_draw); |
|
288 |
}
|
|
289 |
||
290 |
GfxContext.PopClippingRectangle(); |
|
291 |
}
|
|
292 |
||
293 |
void CoverflowResultView::Impl::ComputeFlatIcons() |
|
294 |
{
|
|
295 |
float width = coverflow_->ViewportWidthAtDepth(0); |
|
296 |
width /= coverflow_->space_between_icons(); |
|
297 |
||
298 |
int flat_icons = static_cast<int>(std::floor((width - 2.0f) / 2.0f)); |
|
299 |
coverflow_->flat_icons = flat_icons; |
|
300 |
}
|
|
301 |
||
302 |
long CoverflowResultView::ComputeContentSize() |
|
303 |
{
|
|
304 |
pimpl->ComputeFlatIcons(); |
|
305 |
long ret = ResultView::ComputeContentSize(); |
|
306 |
return ret; |
|
307 |
}
|
|
308 |
||
309 |
||
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
310 |
void CoverflowResultView::Activate(std::string const& uri, int index, ResultView::ActivateType type) |
311 |
{
|
|
312 |
unsigned num_results = pimpl->coverflow_->model()->Items().size(); |
|
313 |
||
314 |
int left_results = index; |
|
315 |
int right_results = num_results ? (num_results - index) - 1 : 0; |
|
316 |
int row_y = GetRootGeometry().y; |
|
317 |
int row_height = renderer_->height; |
|
318 |
||
2740.6.4
by Nick Dedekind
Enabled lenses to open preview from direct activation. |
319 |
glib::Variant data(g_variant_new("(iiii)", row_y, row_height, left_results, right_results)); |
2740.6.3
by Nick Dedekind
Pass data in all dash result uri activations. If lens forces a preview, we will not have the correct info. |
320 |
UriActivated.emit(uri, type, data); |
321 |
}
|
|
322 |
||
323 |
||
2542.1.2
by Jason Smith
add missing files |
324 |
}
|
325 |
}
|