Commits

Zenchreal committed f469d60

Add context menu to the marks window, start working on interpretion more dialog

Comments (0)

Files changed (5)

src/ui/InspectorMoreDialog.cpp

 
 InspectorMoreDialog::InspectorMoreDialog(QWidget* parent) :
     QDialog(parent),
-    ui(new Ui::InspectorMoreDialog)
+    ui(new Ui::InspectorMoreDialog),
+    defaultEndianValue(Interpretation::LITTLE)
 {
 	ui->setupUi(this);
 	ui->buttonBox->addButton(ui->addButton, QDialogButtonBox::ActionRole);
 	delete ui;
 }
 
+void InspectorMoreDialog::setDefaultEndian(Interpretation::Endian flag)
+{
+	defaultEndianValue = flag;
+}
+
+Interpretation::Endian InspectorMoreDialog::defaultEndian() const
+{
+	return defaultEndianValue;
+}
+
+void InspectorMoreDialog::setList(const std::vector<shared_ptr<Interpretation>>& list)
+{
+}
+
 size_t InspectorMoreDialog::result() const
 {
 	return resultOffset;

src/ui/InspectorMoreDialog.hpp

  */
 #pragma once
 #include <cstddef>
+#include <vector>
 #include <QDialog>
+#include "bytes/Interpretation.hpp"
+#include "SmartPtr.hpp"
 
 class QStandardItemModel;
 namespace Ui
 public:
 	explicit InspectorMoreDialog(QWidget* parent = nullptr);
 	virtual ~InspectorMoreDialog();
+
+	/**
+	 * Set the default endian.
+	 */
+	void setDefaultEndian(Interpretation::Endian flag);
+	
+	/**
+	 * Get the default endian.
+	 */
+	Interpretation::Endian defaultEndian() const;
+
+	/**
+	 * Set the list of all interpretations this dialog box will show
+	 */
+	void setList(const std::vector<shared_ptr<Interpretation>>& list);
+	
 	size_t result() const;
     
 protected slots:
 	Ui::InspectorMoreDialog* ui;
 	QStandardItemModel* model;
 	size_t resultOffset;
+	Interpretation::Endian defaultEndianValue;
 };

src/ui/InspectorWindow.cpp

 {
 	assert(event);
 	event->accept();
-
 	contextMenu.exec(event->globalPos());
 }
 
 	//connect(hideAct, SIGNAL(triggered()), this, SLOT(new_()));
 
 	moreAct = new QAction(tr("&More..."), this);
-	//hideAct->setShortcuts(QKeySequence::New);
+	moreAct->setShortcut(QKeySequence(tr("Ctrl+Shift+I")));
 	connect(moreAct, SIGNAL(triggered()), this, SLOT(more()));
 
+	addAction(hideAct);
+	addAction(moreAct);
+
 	contextMenu.addAction(hideAct);
 	contextMenu.addSeparator();
 	contextMenu.addAction(moreAct);

src/ui/MarksWindow.cpp

 #include <QHeaderView>
 #include <QStandardItemModel>
 #include <QStandardItem>
+#include <QContextMenuEvent>
 #include "ComboDelegate.hpp"
 #include "bytes/Mark.hpp"
 #include "bytes/MarksHierarchy.hpp"
 		Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
 	tree(nullptr),
 	model(nullptr),
-	blockItemChanged(false)
+	blockItemChanged(false),
+	contextMenu(this)
 {
 	tree = new QTreeView();
 	model = new QStandardItemModel();
 	
 	setWidget(tree);
 	setWindowTitle(tr("Marks"));
+	createContextMenu();
 	
 	tree->setItemDelegateForColumn(1, new ComboDelegate());
 
 	}
 }
 
-MarkPtr MarksWindow::getMark(const QModelIndex& index) const
-{
-	return getMark(model->itemFromIndex(index));
-}
-
-MarkPtr MarksWindow::getMark(QStandardItem* item) const
-{
-	if (!item)
-		return MarkPtr();
-
-	return item->data().value<MarkUserData>().mark;
-}
-
 void MarksWindow::loadState(const Json::Value& in)
 {
 	const Json::Value& columnWidths = in["columnWidths"];
 	// TODO Save order?
 }
 
+void MarksWindow::contextMenuEvent(QContextMenuEvent* event)
+{
+	assert(event);
+	event->accept();
+	contextMenu.exec(event->globalPos());
+}
+
+void MarksWindow::createContextMenu()
+{
+	editAct = new QAction(tr("&Edit..."), this);
+	//hideAct->setShortcuts(QKeySequence::New);
+	//connect(hideAct, SIGNAL(triggered()), this, SLOT(new_()));
+
+	removeAct = new QAction(tr("&Remove"), this);
+	//hideAct->setShortcuts(QKeySequence::New);
+	//connect(moreAct, SIGNAL(triggered()), this, SLOT(more()));
+
+	contextMenu.addAction(editAct);
+	contextMenu.addAction(removeAct);
+}
+
+MarkPtr MarksWindow::getMark(const QModelIndex& index) const
+{
+	return getMark(model->itemFromIndex(index));
+}
+
+MarkPtr MarksWindow::getMark(QStandardItem* item) const
+{
+	if (!item)
+		return MarkPtr();
+
+	return item->data().value<MarkUserData>().mark;
+}
+
 void MarksWindow::itemChanged(QStandardItem* item)
 {
 	assert(item);
 	if (mark)
 		mark->setCollapsed(true);
 }
+
+
+

src/ui/MarksWindow.hpp

 #pragma once
 #include <vector>
 #include <QDockWidget>
+#include <QMenu>
 #include <json/json.h>
 #include "bytes/Mark.hpp"
 #include "bytes/Document.hpp"
 class QStandardItem;
 class QStandardItemModel;
 class QModelIndex;
+class QContextMenuEvent;
 
 
 class MarksWindow : public QDockWidget
 	void itemClicked(const QModelIndex& index);
 	void itemExpanded(const QModelIndex& index);
 	void itemCollapsed(const QModelIndex& index);
+
+protected:
+	virtual void contextMenuEvent(QContextMenuEvent* event);
 	
 private:
+	void createContextMenu();
+	MarkPtr getMark(const QModelIndex& index) const;
+	MarkPtr getMark(QStandardItem* item) const;
+	
 	/**
 	 * Recursively add QStandardItems to the model based on the given
 	 * MarksHierarchy.
 		QStandardItem* type,
 		QStandardItem* value);
 
-	MarkPtr getMark(const QModelIndex& index) const;
-	MarkPtr getMark(QStandardItem* item) const;
-
 	QTreeView* tree;
 	QStandardItemModel* model;
 	bool blockItemChanged;
+
+	// Context menu actions
+	QAction* editAct;
+	QAction* removeAct;
+	QMenu contextMenu;
 };