Commit 0deb03ff authored by Dag Andersen's avatar Dag Andersen
Browse files

Task editor: improve selection strategy

Try hard to always have current index also selected.
This makes it easier for the user to see where new nodes
will be inserted.
BUG:277297
parent 3d5bccf6
......@@ -2257,6 +2257,7 @@ void NodeItemModel::setShowProject( bool on )
{
m_projectshown = on;
reset();
emit projectShownChanged( on );
}
void NodeItemModel::slotNodeToBeInserted( Node *parent, int row )
......
......@@ -297,7 +297,8 @@ public:
signals:
void nodeInserted( Node *node );
void projectShownChanged( bool );
public slots:
virtual void setScheduleManager( ScheduleManager *sm );
void setShowProject( bool on );
......
......@@ -332,6 +332,26 @@ TaskEditor::TaskEditor( KoDocument *part, QWidget *parent )
connect( m_view, SIGNAL( headerContextMenuRequested( const QPoint& ) ), SLOT( slotHeaderContextMenuRequested( const QPoint& ) ) );
Q_ASSERT(connect(baseModel(), SIGNAL(projectShownChanged(bool)), SLOT(slotProjectShown(bool))));
}
void TaskEditor::slotProjectShown( bool on )
{
kDebug()<<proxyModel();
QModelIndex idx;
if ( proxyModel() ) {
if ( proxyModel()->rowCount() > 0 ) {
idx = proxyModel()->index( 0, 0 );
m_view->selectionModel()->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
}
} else if ( baseModel() && baseModel()->rowCount() > 0 ) {
idx = baseModel()->index( 0, 0 );
m_view->selectionModel()->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
}
if ( on && idx.isValid() ) {
m_view->masterView()->expand( idx );
}
slotEnableActions();
}
void TaskEditor::updateReadWrite( bool rw )
......@@ -466,6 +486,7 @@ void TaskEditor::slotEnableActions()
void TaskEditor::updateActionsEnabled( bool on )
{
// kDebug()<<selectedRowCount()<<selectedNode()<<currentNode();
if ( ! on ) {
menuAddTask->setEnabled( false );
actionAddTask->setEnabled( false );
......@@ -483,17 +504,33 @@ void TaskEditor::updateActionsEnabled( bool on )
int selCount = selectedRowCount();
if ( selCount == 0 ) {
menuAddTask->setEnabled( true );
actionAddTask->setEnabled( true );
actionAddMilestone->setEnabled( true );
menuAddSubTask->setEnabled( false );
actionAddSubtask->setEnabled( false );
actionAddSubMilestone->setEnabled( false );
actionDeleteTask->setEnabled( false );
actionMoveTaskUp->setEnabled( false );
actionMoveTaskDown->setEnabled( false );
actionIndentTask->setEnabled( false );
actionUnindentTask->setEnabled( false );
if ( currentNode() ) {
// there are tasks but none is selected
menuAddTask->setEnabled( false );
actionAddTask->setEnabled( false );
actionAddMilestone->setEnabled( false );
menuAddSubTask->setEnabled( false );
actionAddSubtask->setEnabled( false );
actionAddSubMilestone->setEnabled( false );
actionDeleteTask->setEnabled( false );
actionMoveTaskUp->setEnabled( false );
actionMoveTaskDown->setEnabled( false );
actionIndentTask->setEnabled( false );
actionUnindentTask->setEnabled( false );
} else {
// we need to be able to add the first task
menuAddTask->setEnabled( true );
actionAddTask->setEnabled( true );
actionAddMilestone->setEnabled( true );
menuAddSubTask->setEnabled( false );
actionAddSubtask->setEnabled( false );
actionAddSubMilestone->setEnabled( false );
actionDeleteTask->setEnabled( false );
actionMoveTaskUp->setEnabled( false );
actionMoveTaskDown->setEnabled( false );
actionIndentTask->setEnabled( false );
actionUnindentTask->setEnabled( false );
}
return;
}
Node *n = selectedNode(); // 0 if not a single task, summarytask or milestone
......@@ -512,6 +549,22 @@ void TaskEditor::updateActionsEnabled( bool on )
actionUnindentTask->setEnabled( false );
return;
}
if ( selCount == 1 && n != currentNode() ) {
// multi selection in progress
menuAddTask->setEnabled( false );
actionAddTask->setEnabled( false );
actionAddMilestone->setEnabled( false );
menuAddSubTask->setEnabled( false );
actionAddSubtask->setEnabled( false );
actionAddSubMilestone->setEnabled( false );
actionDeleteTask->setEnabled( false );
actionMoveTaskUp->setEnabled( false );
actionMoveTaskDown->setEnabled( false );
actionIndentTask->setEnabled( false );
actionUnindentTask->setEnabled( false );
return;
}
bool baselined = false;
Project *p = m_view->project();
if ( p && p->isBaselined() ) {
......
......@@ -177,7 +177,8 @@ private slots:
void slotMoveTaskDown();
void slotSplitView();
void slotProjectShown( bool );
private:
void edit( QModelIndex index );
......
......@@ -849,7 +849,7 @@ void TreeViewBase::updateSelection( const QModelIndex &oldidx, const QModelIndex
else if (modifiers & Qt::ShiftModifier)
command = QItemSelectionModel::Select | selectionBehaviorFlags();
else
command = QItemSelectionModel::Clear | selectionBehaviorFlags();
command = QItemSelectionModel::ClearAndSelect | selectionBehaviorFlags();
break;
default:
break;
......@@ -857,6 +857,26 @@ void TreeViewBase::updateSelection( const QModelIndex &oldidx, const QModelIndex
selectionModel()->setCurrentIndex( newidx, command );
}
void TreeViewBase::mousePressEvent(QMouseEvent *event)
{
// If the mouse is pressed outside any item, the current item should be/remain selected
QPoint pos = event->pos();
QModelIndex index = indexAt(pos);
kDebug()<<index<<event->pos();
if ( ! index.isValid() ) {
index = selectionModel()->currentIndex();
if ( index.isValid() && ! selectionModel()->isSelected( index ) ) {
pos = visualRect( index ).center();
QMouseEvent e( event->type(), pos, mapToGlobal( pos ), event->button(), event->buttons(), event->modifiers() );
QTreeView::mousePressEvent( &e );
event->setAccepted( e.isAccepted() );
kDebug()<<index<<e.pos();
}
return;
}
QTreeView::mousePressEvent( event );
}
void TreeViewBase::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
{
//kDebug()<<editor<<hint;
......
......@@ -381,6 +381,7 @@ signals:
protected:
void keyPressEvent(QKeyEvent *event);
void mousePressEvent( QMouseEvent *event );
/**
Reimplemented from QTreeView to make tab/backtab in editor work reasonably well.
Move the cursor in the way described by \a cursorAction, *not* using the
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment