From a2335506e2502aaba7319516c4e2ea673b7dff1b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud guennebaud Date: Fri, 24 Apr 2009 09:36:40 +0000 Subject: [PATCH] make the layer menu available from the layer dialog via both a pushbutton and contextual menu (right click) --- src/meshlab/layerDialog.cpp | 74 ++++++++++++++++++++++++++--------- src/meshlab/layerDialog.h | 9 +++-- src/meshlab/mainwindow.h | 4 +- src/meshlab/ui/layerDialog.ui | 15 +++++-- 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/src/meshlab/layerDialog.cpp b/src/meshlab/layerDialog.cpp index aafab0d05..85a2f332e 100644 --- a/src/meshlab/layerDialog.cpp +++ b/src/meshlab/layerDialog.cpp @@ -36,44 +36,51 @@ $Log: stdpardialog.cpp,v $ using namespace std; -LayerDialog::LayerDialog(QWidget *parent ) : QDockWidget(parent) -{ +LayerDialog::LayerDialog(QWidget *parent ) : QDockWidget(parent) +{ setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint | Qt::SubWindow); setVisible(false); LayerDialog::ui.setupUi(this); gla=qobject_cast(parent); mw=qobject_cast(gla->parentWidget()->parentWidget()); - + connect(ui.layerTableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(toggleStatus(int,int)) ); connect(ui.addButton, SIGNAL(clicked()), mw, SLOT(openIn()) ); connect(ui.deleteButton, SIGNAL(clicked()), mw, SLOT(delCurrentMesh()) ); + this->setContextMenuPolicy(Qt::CustomContextMenu); + ui.layerTableWidget->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(ui.layerTableWidget, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(showContextMenu(const QPoint&))); + connect(ui.menuButton, SIGNAL(clicked()), this, SLOT(showLayerMenu())); + //connect( ui.deleteButton, SIGNAL(cellClicked(int, int)) , this, SLOT(openIn(int,int)) ); } void LayerDialog::toggleStatus(int row, int col) { switch(col) - { + { case 0 : //the user has chosen to switch the layer gla->meshDoc.setCurrentMesh(row); break; - case 1 : + case 1 : { //the user has clicke on one of the eyes QList &meshList=gla->meshDoc.meshList; // NICE TRICK. // If the user has pressed ctrl when clicking on the eye icon, only that layer will remain visible // Very useful for comparing meshes - + if(QApplication::keyboardModifiers() == Qt::ControlModifier) foreach(MeshModel *mp, meshList) { mp->visible=false; } - + if(meshList.at(row)->visible) meshList.at(row)->visible = false; - else meshList.at(row)->visible = true; + else meshList.at(row)->visible = true; } } //make sure the right row is colored or that they right eye is drawn (open or closed) @@ -86,11 +93,40 @@ void LayerDialog::showEvent ( QShowEvent * /* event*/ ) updateTable(); } +void LayerDialog::showLayerMenu() +{ + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + MainWindow* mainwindow = dynamic_cast(widget); + if (mainwindow) + { + mainwindow->layerMenu()->popup(ui.menuButton->mapToGlobal(QPoint(10,10))); + return; + } + } +} + +void LayerDialog::showContextMenu(const QPoint& pos) +{ + // switch layer + int row = ui.layerTableWidget->rowAt(pos.y()); + if (row>=0) + gla->meshDoc.setCurrentMesh(row); + + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + MainWindow* mainwindow = dynamic_cast(widget); + if (mainwindow) + { + mainwindow->layerMenu()->popup(ui.layerTableWidget->mapToGlobal(pos)); + return; + } + } +} + void LayerDialog::updateLog(GLLogStream &log) { QList< pair > &logStringList=log.S; ui.logPlainTextEdit->clear(); - //ui.logPlainTextEdit->setFont(QFont("Courier",10)); + //ui.logPlainTextEdit->setFont(QFont("Courier",10)); pair logElem; QString preWarn = " Warning: " ; @@ -101,9 +137,9 @@ void LayerDialog::updateLog(GLLogStream &log) foreach(logElem, logStringList){ QString logText = logElem.second; - if(logElem.first == GLLogStream::SYSTEM) logText = preSystem + logText + post; - if(logElem.first == GLLogStream::WARNING) logText = preWarn + logText + post; - if(logElem.first == GLLogStream::FILTER) logText = preFilter + logText + post; + if(logElem.first == GLLogStream::SYSTEM) logText = preSystem + logText + post; + if(logElem.first == GLLogStream::WARNING) logText = preWarn + logText + post; + if(logElem.first == GLLogStream::FILTER) logText = preFilter + logText + post; ui.logPlainTextEdit->appendHtml(logText); } } @@ -124,26 +160,26 @@ void LayerDialog::updateTable() { QTableWidgetItem *item; //qDebug("Filename %s", meshList.at(i)->fileName.c_str()); - + item = new QTableWidgetItem(QFileInfo(meshList.at(i)->fileName.c_str()).fileName()); if(meshList.at(i)==gla->mm()) { item->setBackground(QBrush(Qt::yellow)); - item->setForeground(QBrush(Qt::blue)); - } + item->setForeground(QBrush(Qt::blue)); + } ui.layerTableWidget->setItem(i,0,item ); - + if(meshList.at(i)->visible){ item = new QTableWidgetItem(QIcon(":/images/layer_eye_open.png"),""); } else { item = new QTableWidgetItem(QIcon(":/images/layer_eye_close.png"),""); - } + } item->setFlags(Qt::ItemIsEnabled); - ui.layerTableWidget->setItem(i,1,item ); + ui.layerTableWidget->setItem(i,1,item ); item = new QTableWidgetItem(QIcon(":/images/layer_edit_unlocked.png"),QString()); item->setFlags(Qt::ItemIsEnabled); ui.layerTableWidget->setItem(i,2,item ); - + } ui.layerTableWidget->resizeColumnsToContents(); //ui.layerTableWidget->adjustSize(); diff --git a/src/meshlab/layerDialog.h b/src/meshlab/layerDialog.h index 1c474c8fb..a9af88f46 100644 --- a/src/meshlab/layerDialog.h +++ b/src/meshlab/layerDialog.h @@ -47,11 +47,14 @@ class LayerDialog : public QDockWidget public slots: void toggleStatus(int row, int column); - void showEvent ( QShowEvent * event ); + void showEvent ( QShowEvent * event ); + void showContextMenu(const QPoint& pos); + void showLayerMenu(); + private: Ui::layerDialog ui; - GLArea *gla; - MainWindow *mw; + GLArea *gla; + MainWindow *mw; }; diff --git a/src/meshlab/mainwindow.h b/src/meshlab/mainwindow.h index 7b66b991a..4e362de04 100644 --- a/src/meshlab/mainwindow.h +++ b/src/meshlab/mainwindow.h @@ -323,7 +323,7 @@ private: QByteArray toolbarState; //stato delle toolbar e dockwidgets QDir lastUsedDirectory; //This will hold the last directory that was used to load/save a file/project in - + public: GLArea *GLA() const { if(mdiarea->currentSubWindow()==0) return 0; @@ -339,6 +339,8 @@ public: static QStatusBar *_qsb=0; return _qsb; } + QMenu* layerMenu() { return filterMenuLayer; } + private: //////// ToolBars /////////////// QToolBar *mainToolBar; diff --git a/src/meshlab/ui/layerDialog.ui b/src/meshlab/ui/layerDialog.ui index 41f55da66..6818be071 100644 --- a/src/meshlab/ui/layerDialog.ui +++ b/src/meshlab/ui/layerDialog.ui @@ -5,8 +5,8 @@ 0 0 - 182 - 391 + 178 + 407 @@ -26,12 +26,19 @@ - 13 - 17 + 28 + 23 + + + + ... + + +