From 009b78079b63a3d3db5423ab21a55e7b7f8e26d5 Mon Sep 17 00:00:00 2001 From: aquiles Date: Sun, 4 Sep 2011 18:48:37 +0200 Subject: [PATCH] Changed: #1306 some focus (in terms of widget focus) related additions, to provide expected usabillity (Tab/Click Focus etc.) --- .../georges_editor/georges_editor_form.cpp | 108 ++++++++++++------ .../georges_editor/georges_editor_form.h | 16 +-- .../georges_treeview_dialog.cpp | 67 +++-------- .../georges_editor/georges_treeview_dialog.h | 5 +- .../georges_editor/georges_treeview_form.ui | 6 + .../georges_editor/georgesform_model.cpp | 4 +- 6 files changed, 113 insertions(+), 93 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp index c623d440b..f67be6471 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.cpp @@ -39,8 +39,8 @@ namespace Plugin GeorgesEditorForm::GeorgesEditorForm(QWidget *parent) : QMainWindow(parent), m_georgesDirTreeDialog(0), - m_emptyDock(0), - m_mainDock(0) + m_mainDock(0), + m_lastActiveDock(0) { m_ui.setupUi(this); @@ -64,34 +64,26 @@ namespace Plugin m_undoStack = new QUndoStack(this); Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); - _openAction = menuManager->action(Core::Constants::OPEN); + m_openAction = menuManager->action(Core::Constants::OPEN); - /*_openAction = new QAction(tr("&Open..."), this); - _openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); - _openAction->setShortcut(QKeySequence::Open); - _openAction->setStatusTip(tr("Open an existing file")); - connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));*/ + m_newAction = new QAction(tr("&New..."), this); + m_newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); + m_newAction->setShortcut(QKeySequence::New); + m_newAction->setStatusTip(tr("Create a new file")); + connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile())); - _newAction = new QAction(tr("&New..."), this); - _newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); - _newAction->setShortcut(QKeySequence::New); - _newAction->setStatusTip(tr("Create a new file")); - connect(_newAction, SIGNAL(triggered()), this, SLOT(newFile())); + m_saveAction = new QAction(tr("&Save..."), this); + m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); + m_saveAction->setShortcut(QKeySequence::Save); + m_saveAction->setStatusTip(tr("Save the current file")); + connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save())); - _saveAction = new QAction(tr("&Save..."), this); - _saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); - _saveAction->setShortcut(QKeySequence::Save); - _saveAction->setStatusTip(tr("Save the current file")); - connect(_saveAction, SIGNAL(triggered()), this, SLOT(save())); + m_fileToolBar = addToolBar(tr("&File")); + m_fileToolBar->addAction(m_openAction); + m_fileToolBar->addAction(m_newAction); + m_fileToolBar->addAction(m_saveAction); - _fileToolBar = addToolBar(tr("&File")); - _fileToolBar->addAction(_openAction); - _fileToolBar->addAction(_newAction); - _fileToolBar->addAction(_saveAction); - - //_openAction->setEnabled(false); - //_newAction->setEnabled(false); - //_saveAction->setEnabled(false); + m_saveAction->setEnabled(false); readSettings(); @@ -104,6 +96,8 @@ namespace Plugin this, SLOT(settingsChanged())); connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)), this, SLOT(loadFile(const QString))); + connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), + this, SLOT(focusChanged(QWidget*, QWidget*))); } GeorgesEditorForm::~GeorgesEditorForm() @@ -196,25 +190,34 @@ namespace Plugin if (!m_dockedWidgets.size()) { - m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); + m_lastActiveDock = dock; + m_dockedWidgets.append(dock); + m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last()); connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); + connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), + m_dockedWidgets.last(), SLOT(checkVisibility(bool))); } else { - Q_FOREACH(QDockWidget *wgt, m_dockedWidgets) + Q_FOREACH(CGeorgesTreeViewDialog *wgt, m_dockedWidgets) { - if (info.fileName() == wgt->windowTitle()) + if (info.fileName() == wgt->loadedForm) { wgt->raise(); return; } } - m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); + CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock); + m_dockedWidgets.append(dock); + connect(m_dockedWidgets.last(), SIGNAL(closing()), this, SLOT(closingTreeView())); + connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)), + m_dockedWidgets.last(), SLOT(checkVisibility(bool))); Q_ASSERT(m_dockedWidgets.size() > 1); m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); } @@ -224,6 +227,8 @@ namespace Plugin m_dockedWidgets.last()->setForm(form); m_dockedWidgets.last()->loadFormIntoDialog(form); QApplication::processEvents(); + connect(m_dockedWidgets.last(), SIGNAL(modified()), + this, SLOT(setModified())); m_dockedWidgets.last()->raise(); connect(m_dockedWidgets.last(), SIGNAL(changeFile(QString)), m_georgesDirTreeDialog, SLOT(changeFile(QString))); @@ -236,10 +241,47 @@ namespace Plugin void GeorgesEditorForm::closingTreeView() { - int i = m_dockedWidgets.size(); + //qDebug() << "closingTreeView"; m_dockedWidgets.removeAll(qobject_cast(sender())); - i = m_dockedWidgets.size(); - int j = i; + if (qobject_cast(sender()) == m_lastActiveDock) + m_lastActiveDock = 0; } + void GeorgesEditorForm::setModified () + { + qDebug() << "setModified"; + if (m_lastActiveDock) + m_saveAction->setEnabled(m_lastActiveDock->isModified()); + else + m_saveAction->setEnabled(false); + } + + void GeorgesEditorForm::focusChanged ( QWidget * old, QWidget * now ) + { + if (now) + { + // ugly, UGLY hack for compensating QDockWidgets failure in focus API + if (now->objectName() == "treeView" || + now->objectName() == "checkBoxDefaults" || + now->objectName() == "checkBoxParent" || + now->objectName() == "commentEdit") + { + QWidget *dlg = 0; + QApplication::focusWidget()? + QApplication::focusWidget()->parentWidget()? + QApplication::focusWidget()->parentWidget()->parentWidget()? + QApplication::focusWidget()->parentWidget()->parentWidget()->parentWidget()? + QApplication::focusWidget()->parentWidget()->parentWidget()->parentWidget()->parentWidget()? + QApplication::focusWidget()->parentWidget()->parentWidget()->parentWidget()->parentWidget()->parentWidget()? + dlg=QApplication::focusWidget()->parentWidget()->parentWidget()->parentWidget()->parentWidget()->parentWidget():dlg=0:dlg=0:dlg=0:dlg=0:dlg=0:dlg=0; + CGeorgesTreeViewDialog *active = qobject_cast(dlg); + if(active) + { + //qDebug() << "focusChanged" << active->loadedForm; + m_lastActiveDock = active; + m_saveAction->setEnabled(active->isModified()); + } + } + } + } } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h index 4ed91a5f6..6b270ca3d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_editor_form.h @@ -40,11 +40,14 @@ public: public Q_SLOTS: void open(); + void loadFile(const QString fileName); void newFile(); void save(); void settingsChanged(); - void loadFile(const QString fileName); void closingTreeView(); + void setModified(); + + void focusChanged(QWidget *old, QWidget *now); private: void readSettings(); @@ -54,18 +57,17 @@ private: Ui::GeorgesEditorForm m_ui; CGeorgesDirTreeDialog *m_georgesDirTreeDialog; - QToolBar *_fileToolBar; - QAction *_openAction; - QAction *_newAction; - QAction *_saveAction; + QToolBar *m_fileToolBar; + QAction *m_openAction; + QAction *m_newAction; + QAction *m_saveAction; QString m_leveldesignPath; - QDockWidget *m_emptyDock; QMainWindow *m_mainDock; QList m_dockedWidgets; - QList m_tabBars; + CGeorgesTreeViewDialog *m_lastActiveDock; }; /* class GeorgesEditorForm */ } /* namespace Plugin */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp index bc5dd7487..13b0dab03 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -20,6 +20,7 @@ #include #include #include +#include // NeL includes #include @@ -43,12 +44,12 @@ namespace Plugin CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) : QDockWidget(parent), - m_header(0) + m_header(0), + m_modified(false) { m_georges = new CGeorges; loadedForm = ""; - m_modified = false; m_ui.setupUi(this); m_header = new ExpandableHeaderView(Qt::Horizontal, m_ui.treeView); @@ -77,6 +78,7 @@ namespace Plugin CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() { delete m_form; + qDebug() << "DTOR"; } void CGeorgesTreeViewDialog::headerClicked(int section) @@ -193,8 +195,8 @@ namespace Plugin filterRows(); // //_ui.treeView->setRowHidden(0,QModelIndex(),true); - // connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), - // this, SLOT(modifiedFile())); + connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), + this, SLOT(modifiedFile())); setWindowTitle(loadedForm); // //Modules::mainWin().getTabBar(); @@ -208,13 +210,12 @@ namespace Plugin void CGeorgesTreeViewDialog::modifiedFile( ) { - /*if (!_modified) + if (!m_modified) { - _modified = true; - setWindowTitle(windowTitle()+"*"); - Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*"); - Q_EMIT modified(_modified); - }*/ + m_modified = true; + setWindowTitle(windowTitle() + "*"); + } + Q_EMIT modified(); } void CGeorgesTreeViewDialog::write( ) @@ -366,52 +367,22 @@ namespace Plugin deleteLater(); } + void CGeorgesTreeViewDialog::checkVisibility(bool visible) { + // this prevents invisible docks from getting tab focus + qDebug() << "checkVisibility" << visible; + setEnabled(visible); + //if (visible) + Q_EMIT modified(); + } + void CGeorgesTreeViewDialog::filterRows() { - nlinfo("CGeorgesTreeViewDialog::filterRows"); CGeorgesFormProxyModel * mp = dynamic_cast(m_ui.treeView->model()); CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); if (m) { m->setShowParents(m_ui.checkBoxParent->isChecked()); m->setShowDefaults(m_ui.checkBoxDefaults->isChecked()); } - - //CGeorgesFormProxyModel * mp = dynamic_cast(_ui.treeView->model()); - //CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); - - //for (int i = 0; i < m->rowCount(); i++) - //{ - // const QModelIndex in = m->index(i,0); - // if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) - // { - // if (newState == Qt::Checked) - // { - // _ui.treeView->setRowHidden(in.row(),in.parent(),false); - // } - // else - // { - // _ui.treeView->setRowHidden(in.row(),in.parent(),true); - // } - // } - // else - // { // search childs // recursive? - // for (int j = 0; j < m->rowCount(in); j++) - // { - // const QModelIndex in2 = m->index(j,0,in); - // if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) - // { - // if (newState == Qt::Checked) - // { - // _ui.treeView->setRowHidden(in2.row(),in,false); - // } - // else - // { - // _ui.treeView->setRowHidden(in2.row(),in,true); - // } - // } - // } - // } // end of search childs - //} } } /* namespace NLQT */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h index e4c5dcdf4..4992c9b23 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_dialog.h @@ -50,7 +50,7 @@ namespace Plugin CGeorgesTreeViewDialog(QWidget *parent = 0); ~CGeorgesTreeViewDialog(); - bool modified() {return m_modified;} + bool isModified() {return m_modified;} void setModified(bool m) {m_modified = m;} CForm* getFormByName(const QString); @@ -67,13 +67,14 @@ namespace Plugin Q_SIGNALS: void changeFile(QString); - void modified(bool); + void modified(); void closing(); public Q_SLOTS: void setForm(const CForm*); void loadFormIntoDialog(CForm *form = 0); void modifiedFile( ); + void checkVisibility(bool); private Q_SLOTS: void doubleClicked ( const QModelIndex & index ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui index 71db74326..183b16118 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georges_treeview_form.ui @@ -22,6 +22,9 @@ 165 + + Qt::NoFocus + @@ -36,6 +39,9 @@ 0 + + Qt::NoFocus + Form diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp index 3ae798dea..f6b9c441b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp @@ -245,9 +245,7 @@ namespace Plugin CFormItem *item = getItem(index); bool result = item->setData(index.column(), value); - // // TODO: ugly hack for updating icon too - // if (result) - // Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent())); + Q_EMIT dataChanged(index, index); //setupModelData(); return result;