~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/hotkeys_tree_view.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library 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 GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
   Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "hotkeys_tree_view.h"
 
21
#include "hotkeys_context_menu.h"
 
22
 
 
23
#include "hotkeys_model.h"
 
24
 
 
25
#include "actions/actions.h"
 
26
#include "action_data/action_data_group.h"
 
27
#include "action_data/simple_action_data.h"
 
28
 
 
29
#include "KDE/KLocale"
 
30
#include "KDE/KDebug"
 
31
 
 
32
#include <QtGui/QContextMenuEvent>
 
33
 
 
34
 
 
35
HotkeysTreeView::HotkeysTreeView( QWidget *parent )
 
36
    : QTreeView(parent)
 
37
    {
 
38
    setObjectName("khotkeys treeview");
 
39
    setAllColumnsShowFocus(true);
 
40
    setDragEnabled(true);
 
41
    setAcceptDrops(true);
 
42
    setDropIndicatorShown(true);
 
43
    }
 
44
 
 
45
 
 
46
HotkeysTreeView::~HotkeysTreeView()
 
47
    {}
 
48
 
 
49
 
 
50
void
 
51
HotkeysTreeView::contextMenuEvent( QContextMenuEvent *event )
 
52
    {
 
53
    QModelIndex index = indexAt(event->pos());
 
54
    // KHotKeys::ActionDataBase *item = model()->indexToActionDataBase(index);
 
55
    HotkeysTreeViewContextMenu menu( index, this );
 
56
    menu.exec(event->globalPos());
 
57
    }
 
58
 
 
59
 
 
60
void
 
61
HotkeysTreeView::modelReset()
 
62
    {
 
63
    resizeColumnToContents(KHotkeysModel::NameColumn);
 
64
    }
 
65
 
 
66
 
 
67
KHotkeysModel *HotkeysTreeView::model()
 
68
    {
 
69
    return dynamic_cast<KHotkeysModel*>( QTreeView::model() );
 
70
    }
 
71
 
 
72
 
 
73
void
 
74
HotkeysTreeView::setModel( QAbstractItemModel *model )
 
75
    {
 
76
    if (!dynamic_cast<KHotkeysModel*>( model ))
 
77
        {
 
78
        Q_ASSERT(dynamic_cast<KHotkeysModel*>( model ));
 
79
        return;
 
80
        }
 
81
    QTreeView::setModel(model);
 
82
 
 
83
    setAllColumnsShowFocus(true);
 
84
    setAlternatingRowColors(true);
 
85
 
 
86
    setSelectionBehavior( QAbstractItemView::SelectRows );
 
87
    setSelectionMode( QAbstractItemView::SingleSelection );
 
88
 
 
89
    connect(
 
90
        model, SIGNAL(modelReset()),
 
91
        this, SLOT(modelReset()));
 
92
 
 
93
    resizeColumnToContents(KHotkeysModel::EnabledColumn);
 
94
    resizeColumnToContents(KHotkeysModel::NameColumn);
 
95
    }
 
96
 
 
97
#include "moc_hotkeys_tree_view.cpp"