summaryrefslogtreecommitdiff
path: root/attic/muse2-oom/muse2/muse/widgets/popupmenu.cpp
blob: 862bda91ca9facb588da38f08d33f34e2a4ee194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: popupmenu.cpp,v 1.1.1.1 2010/07/18 03:21:00 terminator356 Exp $
//
//  (C) Copyright 1999-2010 Werner Schweer (ws@seh.de)
//
//  PopupMenu sub-class of QMenu created by Tim.
//=========================================================

//#include <stdio.h>
#include <QMouseEvent>
#include <QAction>
#include <stdio.h>
//#include <QStandardItemModel>

#include "popupmenu.h"
 
//======================
// PopupMenu
//======================

PopupMenu::PopupMenu(QWidget* parent) 
          : QMenu(parent)
{
  // Menus will trigger! Set to make sure our trigger handlers ignore menus.
  menuAction()->setData(-1);
}

PopupMenu::~PopupMenu()
{
  //printf("PopupMenu::~PopupMenu\n");  
}

void PopupMenu::clear()
{
  QList<QAction*> list = actions();
  for(int i = 0; i < list.size(); ++i)
  {
    QAction* act = list[i];
    QMenu* menu = act->menu();
    if(menu)
    {
      menu->clear();
      act->setMenu(0);  // CHECK: Is this OK?
      delete menu;
    }
  }
  
  // Now let QT remove and delete this menu's actions.
  QMenu::clear();
}

QAction* PopupMenu::findActionFromData(QVariant v)
{
  QList<QAction*> list = actions();
  for(int i = 0; i < list.size(); ++i)
  {
    QAction* act = list[i];
    PopupMenu* menu = (PopupMenu*)act->menu();
    if(menu)
    {
      if(QAction* actm = menu->findActionFromData(v))
        return actm;
    }
    if(act->data() == v)
      return act;
  }
  return 0;
}
    
void PopupMenu::mouseReleaseEvent(QMouseEvent *e)
{
    //Q_D(QMenu);
    //if (d->mouseEventTaken(e))
    //    return;

    //d->mouseDown = false;
    //QAction *action = d->actionAt(e->pos());
    QAction *action = actionAt(e->pos());
    
    //for(QWidget *caused = this; caused;) {
    //    if (QMenu *m = qobject_cast<QMenu*>(caused)) {
    //        QAction *currentAction = d->currentAction;
    //        if(currentAction && (!currentAction->isEnabled() || currentAction->menu() || currentAction->isSeparator()))
    //            currentAction = 0;
    //        caused = m->d_func()->causedPopup.widget;
    //        if (m->d_func()->eventLoop)
    //            m->d_func()->syncAction = currentAction; // synchronous operation
    //    } else {
    //        break;
    //    }
    //}
    
    //if (action && action == d->currentAction) {
    if (action && action == activeAction() && !action->isSeparator() && action->isEnabled()) 
    {
        //if (action->menu())
        //    action->menu()->d_func()->setFirstActionActive();
        //else
            //d->activateAction(action, QAction::Trigger);
            action->activate(QAction::Trigger);
    }
    else 
    //if (d->motions > 6) {
    //    d->hideUpToMenuBar();
    //  }
      QMenu::mouseReleaseEvent(e);
}

/*
//======================
// PopupView
//======================

PopupView::PopupView(QWidget* parent) 
          : QColumnView(parent)
{
  _model= new QStandardItemModel(this); 
  // FIXME: After clearing, then re-filling, no items seen. 
  // But if setModel is called FOR THE FIRST TIME after clearing the model,
  //  then it works. Calling setModel any time after that does not work.
  setModel(_model);
}

PopupView::~PopupView()
{
  // Make sure to clear the popup so that any child popups are also deleted !
  //popup->clear();
}

void PopupView::clear()
{
  _model->clear();
}
*/