Commit 6da3f072 authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fixed right-click in ge_item_view.

parent bd86b721
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "ge_item_view_qt.h" #include "ge_item_view_qt.h"
#include "ge_graph.h" #include "ge_graph.h"
#include <QHeaderView>
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
#include <QScrollArea> #include <QScrollArea>
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
static pwr_tString80* graph_list_files(); static pwr_tString80* graph_list_files();
GeItemViewQt::GeItemViewQt(Ge* gectx) : ge_ctx(gectx), tree_widget(0) GeItemViewQt::GeItemViewQt(Ge* gectx) : QWidget(), ge_ctx(gectx), tree_widget(0)
{ {
char full_path[256]; char full_path[256];
...@@ -64,6 +65,7 @@ GeItemViewQt::GeItemViewQt(Ge* gectx) : ge_ctx(gectx), tree_widget(0) ...@@ -64,6 +65,7 @@ GeItemViewQt::GeItemViewQt(Ge* gectx) : ge_ctx(gectx), tree_widget(0)
SLOT(activate_tree_widget(QTreeWidgetItem*, int))); SLOT(activate_tree_widget(QTreeWidgetItem*, int)));
tree_widget->setColumnCount(1); tree_widget->setColumnCount(1);
tree_widget->header()->hide();
autosave_button = new QCheckBox("Autosave", this); autosave_button = new QCheckBox("Autosave", this);
connect(autosave_button, SIGNAL(stateChanged(int)), this, connect(autosave_button, SIGNAL(stateChanged(int)), this,
...@@ -88,11 +90,6 @@ GeItemViewQt::GeItemViewQt(Ge* gectx) : ge_ctx(gectx), tree_widget(0) ...@@ -88,11 +90,6 @@ GeItemViewQt::GeItemViewQt(Ge* gectx) : ge_ctx(gectx), tree_widget(0)
SLOT(directory_changed(const QString&))); SLOT(directory_changed(const QString&)));
} }
QWidget* GeItemViewQt::widget()
{
return this;
}
void GeItemViewQt::update() void GeItemViewQt::update()
{ {
char* texts = (char*)graph_list_files(); char* texts = (char*)graph_list_files();
...@@ -327,47 +324,25 @@ void GeItemViewQt::activate_tree_widget(QTreeWidgetItem* item, int idx) ...@@ -327,47 +324,25 @@ void GeItemViewQt::activate_tree_widget(QTreeWidgetItem* item, int idx)
} }
} }
void GeItemViewQt::focusOutEvent(QFocusEvent* event) void GeItemViewQt::contextMenuEvent(QContextMenuEvent *mouseEvent)
{ {
tree_widget->clearSelection();
QWidget::focusOutEvent(event);
}
void GeItemViewQt::mousePressEvent(QMouseEvent* event)
{
static const char* item_text[] = { "Open", " ", "Delete", "" };
if (event->button() != Qt::RightButton) {
return;
}
QMenu* menu = new QMenu(this); QMenu* menu = new QMenu(this);
for (int i = 0; item_text[i][0]; i++) { QAction* a = menu->addAction("Open");
if (item_text[i][0] == ' ') {
menu->addSeparator();
} else {
QAction* a = menu->addAction(item_text[i]);
if (i == 0) {
connect(a, SIGNAL(triggered()), this, SLOT(activate_menu_open())); connect(a, SIGNAL(triggered()), this, SLOT(activate_menu_open()));
} else if (i == 2) { menu->addSeparator();
a = menu->addAction("Delete");
connect(a, SIGNAL(triggered()), this, SLOT(activate_menu_delete())); connect(a, SIGNAL(triggered()), this, SLOT(activate_menu_delete()));
}
}
}
QList<QTreeWidgetItem*> selection = tree_widget->selectedItems(); if (tree_widget->selectedItems().size() == 1) {
int sel_count = selection.size();
if (sel_count <= 1) {
/* Get tree path for row that was clicked */ /* Get tree path for row that was clicked */
QTreeWidgetItem* path = tree_widget->itemAt(event->x(), event->y()); QTreeWidgetItem* path = tree_widget->itemAt(tree_widget->mapFromGlobal(mouseEvent->globalPos()));
tree_widget->clearSelection(); tree_widget->clearSelection();
tree_widget->setCurrentItem(path); tree_widget->setCurrentItem(path);
} }
menu->popup(QPoint()); menu->popup(mouseEvent->globalPos());
QWidget::mousePressEvent(event); QWidget::contextMenuEvent(mouseEvent);
} }
void GeItemViewQt::autosave_toggled(int set) void GeItemViewQt::autosave_toggled(int set)
......
...@@ -54,15 +54,13 @@ private: ...@@ -54,15 +54,13 @@ private:
public: public:
GeItemViewQt(Ge* gectx); GeItemViewQt(Ge* gectx);
QWidget* widget();
void update(); void update();
void update(const char*, int); void update(const char*, int);
QString selected_text(); QString selected_text();
QString selected_text(QTreeWidget*); QString selected_text(QTreeWidget*);
protected: protected:
void focusOutEvent(QFocusEvent* event); void contextMenuEvent(QContextMenuEvent* event);
void mousePressEvent(QMouseEvent* event);
private: private:
QStringList files; QStringList files;
......
...@@ -1965,8 +1965,7 @@ GeQt::GeQt(void* x_parent_ctx, QWidget* x_parent_widget, ...@@ -1965,8 +1965,7 @@ GeQt::GeQt(void* x_parent_ctx, QWidget* x_parent_widget,
((GraphQt*)graph)->create_navigator(); ((GraphQt*)graph)->create_navigator();
vpaned->addWidget(((GraphQt*)graph)->nav_widget); vpaned->addWidget(((GraphQt*)graph)->nav_widget);
GeItemViewQt* item_view = new GeItemViewQt(this); graph_list = new GeItemViewQt(this);
graph_list = item_view->widget();
// Horizontal pane // Horizontal pane
QSplitter* hpaned = new QSplitter(Qt::Horizontal); QSplitter* hpaned = new QSplitter(Qt::Horizontal);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment