krop's commit fixes my problem in a better way, reverting
[kdepim.git] / ktimetracker / treeviewheadercontextmenu.h
blob77d8d9e960a82040a2d16154c9aa933a818cb4b9
1 /*
2 * Copyright (C) 2007 by Mathias Soeken <msoeken@tzi.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the
16 * Free Software Foundation, Inc.
17 * 51 Franklin Street, Fifth Floor
18 * Boston, MA 02110-1301 USA.
22 #ifndef TREEVIEWHEADERCONTEXTMENU_H
23 #define TREEVIEWHEADERCONTEXTMENU_H
25 #include <QObject>
26 #include <QPoint>
27 #include <QHash>
28 #include <QVector>
30 class QAction;
31 class QTreeView;
33 class KMenu;
35 /**
36 * ContextMenu for QTreeView::header() to toggle the
37 * visible state of the columns.
39 * It is possible to exclude columns from inserting in the
40 * menu either by the @p excludedColumns parameter in the constructor,
41 * by #addExcludedColumn or #addExcludedColumns.
43 * You can also change the display style of the items in the menu.
45 * @author Mathias Soeken <msoeken@tzi.de>
47 class TreeViewHeaderContextMenu : public QObject {
48 Q_OBJECT
49 Q_PROPERTY(int style READ style)
50 Q_PROPERTY(KMenu* menu READ menu)
52 public:
53 enum { AlwaysCheckBox, CheckBoxOnChecked, ShowHideText };
55 public:
56 explicit TreeViewHeaderContextMenu( QObject *parent, QTreeView *widget, int style = AlwaysCheckBox, QVector<int> excludedColumns = QVector<int>() );
57 ~TreeViewHeaderContextMenu();
59 private:
60 void updateAction( QAction *action, int column );
62 private Q_SLOTS:
63 void slotCustomContextMenuRequested( const QPoint& );
65 protected Q_SLOTS:
66 void updateActions();
67 void slotTriggered( QAction* );
68 void slotAboutToShow();
70 protected:
71 QTreeView *mWidget;
72 QVector<QAction*> mActions;
73 KMenu *mContextMenu;
74 int mStyle;
75 QHash<QAction*, int> mActionColumnMapping;
76 QVector<int> mExcludedColumns;
78 public:
79 int style() const { return mStyle; }
80 void addExcludedColumn( int column ) { mExcludedColumns << column; updateActions(); }
81 void addExcludedColumns( QVector<int> columns ) { mExcludedColumns << columns; updateActions(); }
82 KMenu *menu() const { return mContextMenu; }
84 Q_SIGNALS:
85 void columnToggled( int );
88 #endif