22 #include <QApplication>
23 #include <QGraphicsSceneMouseEvent>
24 #include <QGraphicsView>
32 class PassagewayViewSizer:
public ColumnLayout::ColumnSizer {
44 m_sizer->init(size - 1);
50 if (!m_size)
return 1.0;
51 if (m_size <= 2)
return 1.0 / m_size;
56 return m_sizer->size();
61 ColumnLayout::ColumnSizer * m_sizer;
66 class PassagewayView::Private {
68 Private(ActionTreeModel * entranceModel,
69 ActionTreeModel * atlasModel,
71 : focusIndex(0), layout(NULL), buttonsLayout(NULL), listsLayout(NULL),
72 parent(p), popup(NULL), popupMenus(false)
74 parent->setLayout(layout =
new NodeLayout());
75 layout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
76 layout->setMaximumSize(INT_MAX, INT_MAX);
79 buttonsLayout =
new ColumnLayout(),
80 NodeLayout::NodeCoordinate(0, 0, 0, 0),
81 NodeLayout::NodeCoordinate(1, 0, 0, 32)
83 buttonsLayout->setSizer(
88 buttonsLayout->setColumnCount(30);
90 buttonsLayout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
91 buttonsLayout->setMaximumSize(INT_MAX, INT_MAX);
103 listsLayout =
new ColumnLayout(),
104 NodeLayout::NodeCoordinate(0, 0, 0, 32),
105 NodeLayout::NodeCoordinate(1, 1, 0, 0)
108 listsLayout->setSizer(
new PassagewayViewSizer());
109 listsLayout->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
110 listsLayout->setMaximumSize(INT_MAX, INT_MAX);
114 next(Step(
"", QIcon(), entranceModel));
115 next(Step(
"", QIcon(), atlasModel));
119 lists.at(0)->setCategoriesActivable(
false);
120 lists.at(1)->setCategoriesActivable(
true);
125 delete buttonsLayout;
137 Step(QString t, QIcon i, ActionTreeModel * m)
141 ActionTreeModel * model;
146 BreadcrumbItem(QIcon
icon, QString
title, QString description,
147 QGraphicsItem * parent, PassagewayView::Private * parent_private)
155 m_mousePos =
event->pos();
159 void mouseMoveEvent(QGraphicsSceneMouseEvent * event)
161 ExtenderButton::mouseMoveEvent(event);
162 if (
isDown() && ((m_mousePos - event->pos()).toPoint().manhattanLength() > QApplication::startDragDistance())) {
164 d->startDrag(
this, event);
169 PassagewayView::Private * d;
173 void back(
int steps,
bool deselectLast =
true)
179 for (
int i = 0; i < steps; ++i) {
180 if (lists.size() == 0) {
184 if (buttons.size() > 2) {
185 buttons.at(buttons.size() - 3)->
setGroupByName(parent->group()->name() +
"-InactiveButton");
188 ExtenderButton * button = buttons.takeLast();
190 lists.last()->setShowsExtendersOutside(
true);
191 ActionListView * list = lists.takeLast();
192 lists.last()->setShowsExtendersOutside(
false);
197 buttonsLayout->pop();
200 buttonsLayout->setGeometry(buttonsLayout->geometry());
204 button->deleteLater();
208 if (focusIndex >= lists.size()) {
209 focusIndex = lists.size() - 1;
213 lists.last()->clearSelection();
217 void next(Step newStep)
219 Step * step =
new Step(newStep);
220 ExtenderButton * button =
221 new BreadcrumbItem(step->icon, step->title, QString(), parent,
this);
222 ActionListView * list =
223 new ActionListView(step->model, parent);
224 list->setGroupByName(parent->group()->name() +
"-Atlas");
226 button->setIconSize(QSize(22, 22));
227 button->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
229 button->setGroupByName(parent->group()->name() +
"-InactiveButton");
232 buttons.append(button);
233 button->setZValue((qreal)buttons.count());
235 if (buttons.size() > 2) {
236 buttons.at(buttons.size() - 3)->
setGroupByName(parent->group()->name() +
"-Button");
239 list->setCategoriesGroupByName(
"ActionListView-CategoriesPass");
240 list->setCategoriesActivable(
true);
242 focusIndex = lists.count();
243 if (lists.size() > 1) {
244 lists.last()->setShowsExtendersOutside(
true);
247 lists.last()->setShowsExtendersOutside(
false);
248 lists.last()->setZValue(- lists.count());
252 buttonsLayout->push(button);
253 listsLayout->push(list);
256 buttonsLayout->setGeometry(buttonsLayout->geometry());
257 listsLayout->setGeometry(listsLayout->geometry());
261 list, SIGNAL(activated(
int)),
266 button, SIGNAL(activated()),
271 void startDrag(BreadcrumbItem * item, QGraphicsSceneMouseEvent * event)
273 if (
Global::self()->immutability() != Plasma::Mutable) {
277 int index = buttons.indexOf(item, 0);
282 QMimeData * data = path.at(index)->model->selfMimeData();
291 QWidget * widget = NULL;
292 if (item->scene() && item->scene()->views().size() > 0) {
293 widget = item->scene()->views().at(0);
296 QDrag * drag =
new QDrag(widget);
297 drag->setMimeData(data);
300 QPixmap pixmap(item->size().toSize());
301 QPainter painter(&pixmap);
302 painter.fillRect(QRect(QPoint(), pixmap.size()), QColor(100, 100, 100));
303 item->paint(&painter, 0, 0);
304 drag->setPixmap(pixmap);
305 drag->setHotSpot(event->pos().toPoint());
311 QList < Step * > path;
312 QList < ExtenderButton * > buttons;
313 QList < ActionListView * > lists;
317 ColumnLayout::ColumnSizer * sizer;
319 ColumnLayout * buttonsLayout;
320 ColumnLayout * listsLayout;
322 QPointer < PopupMenu > popup;
327 :
Panel(parent), d(new Private(NULL, NULL, this))
334 :
Panel(parent), d(new Private(entranceModel, atlasModel, this))
341 for (
int i = d->buttons.size() - 1; i >= 0; --i) {
342 if (d->buttons.at(i) == sender()) {
343 d->back(d->buttons.size() - i - 2);
350 if (listIndex == -1) {
354 if (listIndex == -1) {
358 if (listIndex == 0) {
362 d->back(d->lists.size() - listIndex - 2,
false);
364 d->back(d->lists.size() - listIndex - 1,
false);
369 model = model->
child(index);
375 d->popup->setModel(model);
377 QPoint p = QCursor::pos();
379 if (scene() && scene()->views().size()) {
380 QGraphicsView * view = scene()->views().first();
383 (view->pos() + view->mapFromScene(scenePos())).x()
384 + geometry().width());
393 d->lists.at(listIndex)->clearSelection();
406 if (d->lists.size() < 2)
return;
407 d->path.at(0)->model = model;
408 d->lists.at(0)->setModel(model);
413 if (d->lists.size() < 2)
return;
414 d->path.at(0)->title =
title;
415 d->buttons.at(0)->setTitle(title);
420 if (d->lists.size() < 2)
return;
421 d->path.at(0)->icon =
icon;
422 d->buttons.at(0)->setIcon(icon);
428 if (d->lists.size() < 2)
return;
429 d->path.at(1)->model = model;
430 d->lists.at(1)->setModel(model);
435 if (d->lists.size() < 2)
return;
436 d->path.at(1)->title =
title;
437 d->buttons.at(1)->setTitle(title);
442 if (d->lists.size() < 2)
return;
443 d->path.at(1)->icon =
icon;
444 d->buttons.at(1)->setIcon(icon);
451 int i = d->buttons.size();
508 d->listsLayout->setColumnCount(limit);
509 d->popupMenus =
false;
511 d->listsLayout->setColumnCount(2);
512 d->popupMenus =
true;
519 if (d->lists.size() > 2) {
520 d->back(d->lists.size() - 2);
533 if (event->key() == Qt::Key_Right) {
535 int index = d->lists.at(d->focusIndex)->selectedIndex();
536 if (index >= 0 && model && (model = model->
child(index))) {
543 if (event->key() == Qt::Key_Left) {
544 if (d->focusIndex < d->lists.count() - 1 && d->focusIndex != 0) {
551 int oindex = d->focusIndex;
553 switch (event->key()) {
556 d->lists.at(d->focusIndex)->keyPressEvent(event);
569 if (d->focusIndex < 0) {
572 }
else if (d->focusIndex >= d->lists.size()) {
573 d->focusIndex = d->lists.size() - 1;
577 if (oindex != d->focusIndex) {
578 if ((oindex == 0 || oindex > d->focusIndex) && oindex < d->lists.count()) {
579 d->lists.at(oindex)->clearSelection();
581 if (d->focusIndex == 0 || oindex < d->focusIndex) {
582 d->lists.at(d->focusIndex)->initialSelection();
587 d->lists.at(d->focusIndex)->keyPressEvent(event);
void setEntranceTitle(const QString &title)
void setActivationMethod(int value)
void setColumnLimit(int limit)
L_Override void setGroup(Group *group=NULL)
Sets this widget's group.
Sizer that uses golden ratio for visible column sizes.
virtual void listItemActivated(int itemIndex, int listIndex=-1)
Group * group(const QString &name)
void setAtlasTitle(const QString &title)
L_Override void setGroup(Group *group=NULL)
Sets this widget's group.
Sizer that returns the same size for all visible columns.
int activationMethod() const
void setAtlasIcon(QIcon icon)
void setEntranceModel(ActionTreeModel *model)
virtual ActionTreeModel * child(int index)=0
Represents a group of object.
PassagewayView(QGraphicsItem *parent=0)
A container widget with optional title-bar.
virtual ~PassagewayView()
virtual QIcon selfIcon() const
virtual QString selfTitle() const
void setEntranceIcon(QIcon icon)
L_Override void keyPressEvent(QKeyEvent *event)
virtual void pathButtonActivated()
static ColumnSizer * create(SizerType type)
void setAtlasModel(ActionTreeModel *model)
L_Override void hideEvent(QHideEvent *event)
void setProperty(const QString &property, const QVariant &value, bool persistent=true)
Sets the value of the specified property.