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 eed98daa6a
commit 009b78079b
6 changed files with 113 additions and 93 deletions

View file

@ -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<CGeorgesTreeViewDialog*>(sender()));
i = m_dockedWidgets.size();
int j = i;
if (qobject_cast<CGeorgesTreeViewDialog*>(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<CGeorgesTreeViewDialog*>(dlg);
if(active)
{
//qDebug() << "focusChanged" << active->loadedForm;
m_lastActiveDock = active;
m_saveAction->setEnabled(active->isModified());
}
}
}
}
} /* namespace Plugin */

View file

@ -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<CGeorgesTreeViewDialog*> m_dockedWidgets;
QList<QTabBar*> m_tabBars;
CGeorgesTreeViewDialog *m_lastActiveDock;
}; /* class GeorgesEditorForm */
} /* namespace Plugin */

View file

@ -20,6 +20,7 @@
#include <QtGui/QWidget>
#include <QSettings>
#include <QFileDialog>
#include <QDebug>
// NeL includes
#include <nel/misc/path.h>
@ -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;
m_modified = true;
setWindowTitle(windowTitle() + "*");
Modules::mainWin().setWindowTitle(Modules::mainWin().windowTitle()+"*");
Q_EMIT modified(_modified);
}*/
}
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<CGeorgesFormProxyModel *>(m_ui.treeView->model());
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
if (m) {
m->setShowParents(m_ui.checkBoxParent->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 */

View file

@ -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 );

View file

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

View file

@ -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;