Changed: #1306 some focus (in terms of widget focus) related additions, to provide expected usabillity (Tab/Click Focus etc.)

This commit is contained in:
aquiles 2011-09-04 18:48:37 +02:00
parent 5ee9934c95
commit 51ecec85e5
6 changed files with 113 additions and 93 deletions

View file

@ -39,8 +39,8 @@ namespace Plugin
GeorgesEditorForm::GeorgesEditorForm(QWidget *parent) GeorgesEditorForm::GeorgesEditorForm(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
m_georgesDirTreeDialog(0), m_georgesDirTreeDialog(0),
m_emptyDock(0), m_mainDock(0),
m_mainDock(0) m_lastActiveDock(0)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
@ -64,34 +64,26 @@ namespace Plugin
m_undoStack = new QUndoStack(this); m_undoStack = new QUndoStack(this);
Core::IMenuManager *menuManager = Core::ICore::instance()->menuManager(); 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); m_newAction = new QAction(tr("&New..."), this);
_openAction->setIcon(QIcon(Core::Constants::ICON_OPEN)); m_newAction->setIcon(QIcon(Core::Constants::ICON_NEW));
_openAction->setShortcut(QKeySequence::Open); m_newAction->setShortcut(QKeySequence::New);
_openAction->setStatusTip(tr("Open an existing file")); m_newAction->setStatusTip(tr("Create a new file"));
connect(_openAction, SIGNAL(triggered()), this, SLOT(open()));*/ connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile()));
_newAction = new QAction(tr("&New..."), this); m_saveAction = new QAction(tr("&Save..."), this);
_newAction->setIcon(QIcon(Core::Constants::ICON_NEW)); m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
_newAction->setShortcut(QKeySequence::New); m_saveAction->setShortcut(QKeySequence::Save);
_newAction->setStatusTip(tr("Create a new file")); m_saveAction->setStatusTip(tr("Save the current file"));
connect(_newAction, SIGNAL(triggered()), this, SLOT(newFile())); connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save()));
_saveAction = new QAction(tr("&Save..."), this); m_fileToolBar = addToolBar(tr("&File"));
_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE)); m_fileToolBar->addAction(m_openAction);
_saveAction->setShortcut(QKeySequence::Save); m_fileToolBar->addAction(m_newAction);
_saveAction->setStatusTip(tr("Save the current file")); m_fileToolBar->addAction(m_saveAction);
connect(_saveAction, SIGNAL(triggered()), this, SLOT(save()));
_fileToolBar = addToolBar(tr("&File")); m_saveAction->setEnabled(false);
_fileToolBar->addAction(_openAction);
_fileToolBar->addAction(_newAction);
_fileToolBar->addAction(_saveAction);
//_openAction->setEnabled(false);
//_newAction->setEnabled(false);
//_saveAction->setEnabled(false);
readSettings(); readSettings();
@ -104,6 +96,8 @@ namespace Plugin
this, SLOT(settingsChanged())); this, SLOT(settingsChanged()));
connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)), connect(m_georgesDirTreeDialog, SIGNAL(selectedForm(const QString)),
this, SLOT(loadFile(const QString))); this, SLOT(loadFile(const QString)));
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)),
this, SLOT(focusChanged(QWidget*, QWidget*)));
} }
GeorgesEditorForm::~GeorgesEditorForm() GeorgesEditorForm::~GeorgesEditorForm()
@ -196,25 +190,34 @@ namespace Plugin
if (!m_dockedWidgets.size()) 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()); m_mainDock->addDockWidget(Qt::RightDockWidgetArea, m_dockedWidgets.last());
connect(m_dockedWidgets.last(), SIGNAL(closing()), connect(m_dockedWidgets.last(), SIGNAL(closing()),
this, SLOT(closingTreeView())); this, SLOT(closingTreeView()));
connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)),
m_dockedWidgets.last(), SLOT(checkVisibility(bool)));
} }
else 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(); wgt->raise();
return; return;
} }
} }
m_dockedWidgets.append(new CGeorgesTreeViewDialog(m_mainDock)); CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock);
m_dockedWidgets.append(dock);
connect(m_dockedWidgets.last(), SIGNAL(closing()), connect(m_dockedWidgets.last(), SIGNAL(closing()),
this, SLOT(closingTreeView())); this, SLOT(closingTreeView()));
connect(m_dockedWidgets.last(), SIGNAL(visibilityChanged(bool)),
m_dockedWidgets.last(), SLOT(checkVisibility(bool)));
Q_ASSERT(m_dockedWidgets.size() > 1); Q_ASSERT(m_dockedWidgets.size() > 1);
m_mainDock->tabifyDockWidget(m_dockedWidgets.at(m_dockedWidgets.size() - 2), m_dockedWidgets.last()); 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()->setForm(form);
m_dockedWidgets.last()->loadFormIntoDialog(form); m_dockedWidgets.last()->loadFormIntoDialog(form);
QApplication::processEvents(); QApplication::processEvents();
connect(m_dockedWidgets.last(), SIGNAL(modified()),
this, SLOT(setModified()));
m_dockedWidgets.last()->raise(); m_dockedWidgets.last()->raise();
connect(m_dockedWidgets.last(), SIGNAL(changeFile(QString)), connect(m_dockedWidgets.last(), SIGNAL(changeFile(QString)),
m_georgesDirTreeDialog, SLOT(changeFile(QString))); m_georgesDirTreeDialog, SLOT(changeFile(QString)));
@ -236,10 +241,47 @@ namespace Plugin
void GeorgesEditorForm::closingTreeView() void GeorgesEditorForm::closingTreeView()
{ {
int i = m_dockedWidgets.size(); //qDebug() << "closingTreeView";
m_dockedWidgets.removeAll(qobject_cast<CGeorgesTreeViewDialog*>(sender())); m_dockedWidgets.removeAll(qobject_cast<CGeorgesTreeViewDialog*>(sender()));
i = m_dockedWidgets.size(); if (qobject_cast<CGeorgesTreeViewDialog*>(sender()) == m_lastActiveDock)
int j = i; 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<CGeorgesTreeViewDialog*>(dlg);
if(active)
{
//qDebug() << "focusChanged" << active->loadedForm;
m_lastActiveDock = active;
m_saveAction->setEnabled(active->isModified());
}
}
}
}
} /* namespace Plugin */ } /* namespace Plugin */

View file

@ -40,11 +40,14 @@ public:
public Q_SLOTS: public Q_SLOTS:
void open(); void open();
void loadFile(const QString fileName);
void newFile(); void newFile();
void save(); void save();
void settingsChanged(); void settingsChanged();
void loadFile(const QString fileName);
void closingTreeView(); void closingTreeView();
void setModified();
void focusChanged(QWidget *old, QWidget *now);
private: private:
void readSettings(); void readSettings();
@ -54,18 +57,17 @@ private:
Ui::GeorgesEditorForm m_ui; Ui::GeorgesEditorForm m_ui;
CGeorgesDirTreeDialog *m_georgesDirTreeDialog; CGeorgesDirTreeDialog *m_georgesDirTreeDialog;
QToolBar *_fileToolBar; QToolBar *m_fileToolBar;
QAction *_openAction; QAction *m_openAction;
QAction *_newAction; QAction *m_newAction;
QAction *_saveAction; QAction *m_saveAction;
QString m_leveldesignPath; QString m_leveldesignPath;
QDockWidget *m_emptyDock;
QMainWindow *m_mainDock; QMainWindow *m_mainDock;
QList<CGeorgesTreeViewDialog*> m_dockedWidgets; QList<CGeorgesTreeViewDialog*> m_dockedWidgets;
QList<QTabBar*> m_tabBars; CGeorgesTreeViewDialog *m_lastActiveDock;
}; /* class GeorgesEditorForm */ }; /* class GeorgesEditorForm */
} /* namespace Plugin */ } /* namespace Plugin */

View file

@ -20,6 +20,7 @@
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QSettings> #include <QSettings>
#include <QFileDialog> #include <QFileDialog>
#include <QDebug>
// NeL includes // NeL includes
#include <nel/misc/path.h> #include <nel/misc/path.h>
@ -43,12 +44,12 @@ namespace Plugin
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/)
: QDockWidget(parent), : QDockWidget(parent),
m_header(0) m_header(0),
m_modified(false)
{ {
m_georges = new CGeorges; m_georges = new CGeorges;
loadedForm = ""; loadedForm = "";
m_modified = false;
m_ui.setupUi(this); m_ui.setupUi(this);
m_header = new ExpandableHeaderView(Qt::Horizontal, m_ui.treeView); m_header = new ExpandableHeaderView(Qt::Horizontal, m_ui.treeView);
@ -77,6 +78,7 @@ namespace Plugin
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
{ {
delete m_form; delete m_form;
qDebug() << "DTOR";
} }
void CGeorgesTreeViewDialog::headerClicked(int section) void CGeorgesTreeViewDialog::headerClicked(int section)
@ -193,8 +195,8 @@ namespace Plugin
filterRows(); filterRows();
// //_ui.treeView->setRowHidden(0,QModelIndex(),true); // //_ui.treeView->setRowHidden(0,QModelIndex(),true);
// connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
// this, SLOT(modifiedFile())); this, SLOT(modifiedFile()));
setWindowTitle(loadedForm); setWindowTitle(loadedForm);
// //Modules::mainWin().getTabBar(); // //Modules::mainWin().getTabBar();
@ -208,13 +210,12 @@ namespace Plugin
void CGeorgesTreeViewDialog::modifiedFile( ) void CGeorgesTreeViewDialog::modifiedFile( )
{ {
/*if (!_modified) if (!m_modified)
{ {
_modified = true; m_modified = true;
setWindowTitle(windowTitle()+"*"); setWindowTitle(windowTitle() + "*");
Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*"); }
Q_EMIT modified(_modified); Q_EMIT modified();
}*/
} }
void CGeorgesTreeViewDialog::write( ) void CGeorgesTreeViewDialog::write( )
@ -366,52 +367,22 @@ namespace Plugin
deleteLater(); 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() void CGeorgesTreeViewDialog::filterRows()
{ {
nlinfo("CGeorgesTreeViewDialog::filterRows");
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model()); CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel()); CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
if (m) { if (m) {
m->setShowParents(m_ui.checkBoxParent->isChecked()); m->setShowParents(m_ui.checkBoxParent->isChecked());
m->setShowDefaults(m_ui.checkBoxDefaults->isChecked()); m->setShowDefaults(m_ui.checkBoxDefaults->isChecked());
} }
//CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model());
//CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(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 */ } /* namespace NLQT */

View file

@ -50,7 +50,7 @@ namespace Plugin
CGeorgesTreeViewDialog(QWidget *parent = 0); CGeorgesTreeViewDialog(QWidget *parent = 0);
~CGeorgesTreeViewDialog(); ~CGeorgesTreeViewDialog();
bool modified() {return m_modified;} bool isModified() {return m_modified;}
void setModified(bool m) {m_modified = m;} void setModified(bool m) {m_modified = m;}
CForm* getFormByName(const QString); CForm* getFormByName(const QString);
@ -67,13 +67,14 @@ namespace Plugin
Q_SIGNALS: Q_SIGNALS:
void changeFile(QString); void changeFile(QString);
void modified(bool); void modified();
void closing(); void closing();
public Q_SLOTS: public Q_SLOTS:
void setForm(const CForm*); void setForm(const CForm*);
void loadFormIntoDialog(CForm *form = 0); void loadFormIntoDialog(CForm *form = 0);
void modifiedFile( ); void modifiedFile( );
void checkVisibility(bool);
private Q_SLOTS: private Q_SLOTS:
void doubleClicked ( const QModelIndex & index ); void doubleClicked ( const QModelIndex & index );

View file

@ -22,6 +22,9 @@
<height>165</height> <height>165</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string/>
</property> </property>
@ -36,6 +39,9 @@
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="form_tab"> <widget class="QWidget" name="form_tab">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<attribute name="title"> <attribute name="title">
<string>Form</string> <string>Form</string>
</attribute> </attribute>

View file

@ -245,9 +245,7 @@ namespace Plugin
CFormItem *item = getItem(index); CFormItem *item = getItem(index);
bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
// // TODO: ugly hack for updating icon too Q_EMIT dataChanged(index, index);
// if (result)
// Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent()));
//setupModelData(); //setupModelData();
return result; return result;