File indexing completed on 2024-09-15 10:32:55
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "hotkeys_tree_view.h" 0008 #include "hotkeys_context_menu.h" 0009 0010 #include "hotkeys_model.h" 0011 0012 #include "action_data/action_data_group.h" 0013 #include "action_data/simple_action_data.h" 0014 0015 #include "KDE/KDebug" 0016 #include "KDE/KLocale" 0017 0018 #include <QContextMenuEvent> 0019 0020 HotkeysTreeView::HotkeysTreeView(QWidget *parent) 0021 : QTreeView(parent) 0022 { 0023 setObjectName("khotkeys treeview"); 0024 setAllColumnsShowFocus(true); 0025 setDragEnabled(true); 0026 setAcceptDrops(true); 0027 setDropIndicatorShown(true); 0028 } 0029 0030 HotkeysTreeView::~HotkeysTreeView() 0031 { 0032 } 0033 0034 void HotkeysTreeView::contextMenuEvent(QContextMenuEvent *event) 0035 { 0036 QModelIndex index = indexAt(event->pos()); 0037 // KHotKeys::ActionDataBase *item = model()->indexToActionDataBase(index); 0038 HotkeysTreeViewContextMenu menu(index, this); 0039 menu.exec(event->globalPos()); 0040 } 0041 0042 void HotkeysTreeView::modelReset() 0043 { 0044 resizeColumnToContents(KHotkeysModel::NameColumn); 0045 } 0046 0047 KHotkeysModel *HotkeysTreeView::model() 0048 { 0049 return dynamic_cast<KHotkeysModel *>(QTreeView::model()); 0050 } 0051 0052 void HotkeysTreeView::setModel(QAbstractItemModel *model) 0053 { 0054 if (!dynamic_cast<KHotkeysModel *>(model)) { 0055 Q_ASSERT(dynamic_cast<KHotkeysModel *>(model)); 0056 return; 0057 } 0058 QTreeView::setModel(model); 0059 0060 setAllColumnsShowFocus(true); 0061 setAlternatingRowColors(true); 0062 0063 setSelectionBehavior(QAbstractItemView::SelectRows); 0064 setSelectionMode(QAbstractItemView::SingleSelection); 0065 0066 connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); 0067 0068 resizeColumnToContents(KHotkeysModel::EnabledColumn); 0069 resizeColumnToContents(KHotkeysModel::NameColumn); 0070 } 0071 0072 void HotkeysTreeView::mouseReleaseEvent(QMouseEvent *me) 0073 { 0074 if (me->button() == Qt::LeftButton && !indexAt(me->pos()).isValid()) { 0075 clearSelection(); 0076 setCurrentIndex(QModelIndex()); 0077 } 0078 QTreeView::mouseReleaseEvent(me); 0079 } 0080 0081 #include "moc_hotkeys_tree_view.cpp"