browsercore/appfw/Api/Bookmarks/modelmenu.h
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MODELMENU_H
       
    20 #define MODELMENU_H
       
    21 
       
    22 #include <QtGui/QMenu>
       
    23 #include <QtCore/QAbstractItemModel>
       
    24 
       
    25 // A QMenu that is dynamically populated from a QAbstractItemModel
       
    26 class ModelMenu : public QMenu
       
    27 {
       
    28     Q_OBJECT
       
    29 
       
    30 signals:
       
    31     void activated(const QModelIndex &index);
       
    32     void hovered(const QString &text);
       
    33 
       
    34 public:
       
    35     ModelMenu(QWidget *parent = 0);
       
    36 
       
    37     void setModel(QAbstractItemModel *model);
       
    38     QAbstractItemModel *model() const;
       
    39 
       
    40     void setMaxRows(int max);
       
    41     int maxRows() const;
       
    42 
       
    43     void setFirstSeparator(int offset);
       
    44     int firstSeparator() const;
       
    45 
       
    46     void setRootIndex(const QModelIndex &index);
       
    47     QModelIndex rootIndex() const;
       
    48 
       
    49     void setHoverRole(int role);
       
    50     int hoverRole() const;
       
    51 
       
    52     void setSeparatorRole(int role);
       
    53     int separatorRole() const;
       
    54 
       
    55     QAction *makeAction(const QIcon &icon, const QString &text, QObject *parent);
       
    56 
       
    57 protected:
       
    58     // add any actions before the tree, return true if any actions are added.
       
    59     virtual bool prePopulated();
       
    60     // add any actions after the tree
       
    61     virtual void postPopulated();
       
    62     // put all of the children of parent into menu up to max
       
    63     void createMenu(const QModelIndex &parent, int max, QMenu *parentMenu = 0, QMenu *menu = 0);
       
    64 
       
    65 private slots:
       
    66     void aboutToShow();
       
    67     void triggered(QAction *action);
       
    68     void hovered(QAction *action);
       
    69 
       
    70 private:
       
    71     QAction *makeAction(const QModelIndex &index);
       
    72     int m_maxRows;
       
    73     int m_firstSeparator;
       
    74     int m_maxWidth;
       
    75     int m_hoverRole;
       
    76     int m_separatorRole;
       
    77     QAbstractItemModel *m_model;
       
    78     QPersistentModelIndex m_root;
       
    79 };
       
    80 
       
    81 #endif // MODELMENU_H
       
    82