File: treeview.cpp

package info (click to toggle)
vibes 0.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,684 kB
  • sloc: cpp: 6,120; python: 412; makefile: 214; sh: 13
file content (91 lines) | stat: -rw-r--r-- 2,162 bytes parent folder | download
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
#include "treeview.h"

TreeView::TreeView(QWidget *parent) : QTreeView(parent)
{
	contextMenuFigure = new QMenu;
    contextMenuGroup = new QMenu;
    contextMenuFigure->addAction("Hide figure");
    contextMenuFigure->addAction("Open figure");
    contextMenuFigure->addAction("Close figure");
    contextMenuGroup->addAction("Edit properties");
	this->setContextMenuPolicy(Qt::CustomContextMenu); //Enable menu
	connect(this,SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(openMenu(const QPoint &)));
	connect(contextMenuFigure,SIGNAL(triggered(QAction *)),this,SLOT(contextMenuTrigger(QAction *)));
	connect(contextMenuGroup,SIGNAL(triggered(QAction *)),this,SLOT(contextMenuTrigger(QAction *)));
}

TreeView::~TreeView()
{
	delete contextMenuFigure;
	delete contextMenuGroup;
}

void TreeView::contextMenuTrigger(QAction *action)
{
	if(action->text() == "Hide figure")
	{
		emit hideFigureEvent();
	}
	else if(action->text() == "Open figure")
	{
		emit showFigureEvent();
	}
	else if(action->text() == "Close figure")
	{
		emit deleteFigureEvent();
	}
	else if(action->text() == "Edit properties")
	{
		emit propertiesEvent();
	}
}

void TreeView::openMenu(const QPoint &point)
{
	//Open menu on right click
 	QModelIndex index = this->indexAt(point);
    if(index.isValid())
    {
    	if(index.parent().isValid()) //Check if the selection has a parent and thus is a group
    	{
        	contextMenuGroup->exec(this->viewport()->mapToGlobal(point));
    	}
    	else
    	{
    		contextMenuFigure->exec(this->viewport()->mapToGlobal(point));
    	}   
    } 
}

void TreeView::keyPressEvent(QKeyEvent *event)
{
	//Override keyPressEvent
	if(event->key() == Qt::Key_Delete)
	{
		emit deleteFigureEvent();
	}
	else if(event->key() == Qt::Key_H)
	{
		emit hideFigureEvent();
	}
	else if(event->key() == Qt::Key_O)
	{
		emit showFigureEvent();
	}
	else if(event->key() == Qt::Key_P)
	{
		emit propertiesEvent();
	}
	event->accept();
}

void TreeView::mouseDoubleClickEvent(QMouseEvent *event)
{	
	//Overide mouseDoubleClickEvent
	if(event->button() == Qt::LeftButton)
	{
		emit showFigureEvent();
		emit propertiesEvent();
	}
	event->accept();
}