QWidget* TasksViewDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QWidget* result = QItemDelegate::createEditor( parent, option, index ); m_editing = true; emit editingStateChanged(); return result; }
void TasksViewDelegate::slotCloseEditor(QWidget *, QAbstractItemDelegate::EndEditHint) { m_editing = false; emit editingStateChanged(); }
TasksView::TasksView( QToolBar* toolBar, QWidget* parent ) : QWidget( parent ) // , ViewInterface() , m_delegate( new TasksViewDelegate( this ) ) , m_actionNewTask( this ) , m_actionNewSubTask( this ) , m_actionEditTask( this ) , m_actionDeleteTask( this ) , m_actionExpandTree( this ) , m_actionCollapseTree( this ) , m_showCurrentOnly( new QButton( toolBar, QButton::Recessed ) ) , m_showSubscribedOnly( new QButton( toolBar, QButton::Recessed ) ) , m_treeView( new QTreeView( this ) ) { QVBoxLayout* layout = new QVBoxLayout( this ); layout->setContentsMargins( 0, 0, 0, 0 ); layout->addWidget( m_treeView ); m_treeView->setItemDelegate( m_delegate ); connect( m_delegate, SIGNAL( editingStateChanged() ), SLOT( configureUi() ) ); // set up actions m_actionNewTask.setText( tr( "New &Task" ) ); m_actionNewTask.setShortcut( QKeySequence::New ); m_actionNewTask.setIcon( Data::newTaskIcon() ); toolBar->addAction( &m_actionNewTask ); connect( &m_actionNewTask, SIGNAL( triggered( bool ) ), SLOT( actionNewTask() ) ); m_actionNewSubTask.setText( tr( "New &Subtask" ) ); m_actionNewSubTask.setShortcut( Qt::META + Qt::Key_N ); m_actionNewSubTask.setIcon( Data::newSubtaskIcon() ); toolBar->addAction( &m_actionNewSubTask ); connect( &m_actionNewSubTask, SIGNAL( triggered( bool ) ), SLOT( actionNewSubTask() ) ); m_actionEditTask.setText( tr( "Edit Task" ) ); m_actionEditTask.setShortcut( Qt::CTRL + Qt::Key_E ); m_actionEditTask.setIcon( Data::editTaskIcon() ); toolBar->addAction( &m_actionEditTask ); connect( &m_actionEditTask, SIGNAL( triggered( bool ) ), SLOT( actionEditTask() ) ); m_actionDeleteTask.setText( tr( "Delete Task" ) ); QList<QKeySequence> deleteShortcuts; deleteShortcuts << QKeySequence::Delete; #ifdef Q_WS_MAC deleteShortcuts << Qt::Key_Backspace; #endif m_actionDeleteTask.setShortcuts(deleteShortcuts); m_actionDeleteTask.setIcon( Data::deleteTaskIcon() ); toolBar->addAction( &m_actionDeleteTask ); connect( &m_actionDeleteTask, SIGNAL( triggered( bool ) ), SLOT( actionDeleteTask() ) ); m_actionExpandTree.setText( tr( "Expand All" ) ); connect( &m_actionExpandTree, SIGNAL( triggered ( bool ) ), m_treeView, SLOT( expandAll() ) ); m_actionCollapseTree.setText( tr( "Collapse All" ) ); connect( &m_actionCollapseTree, SIGNAL( triggered ( bool ) ), m_treeView, SLOT( collapseAll() ) ); // filter setup m_showCurrentOnly->setText( tr( "Current" ) ); m_showCurrentOnly->setCheckable( true ); #ifdef Q_WS_MAC m_showCurrentOnly->setMinimumWidth( 60 ); #endif toolBar->addWidget( m_showCurrentOnly ); connect( m_showCurrentOnly, SIGNAL( clicked( bool ) ), SLOT( taskPrefilteringChanged() ) ); m_showSubscribedOnly->setText( tr( "Selected" ) ); m_showSubscribedOnly->setCheckable( true ); #ifdef Q_WS_MAC m_showSubscribedOnly->setMinimumWidth( 70 ); #endif toolBar->addWidget( m_showSubscribedOnly ); connect( m_showSubscribedOnly, SIGNAL( clicked( bool ) ), SLOT( taskPrefilteringChanged() ) ); QWidget *stretch = new QWidget( this ); stretch->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); toolBar->addWidget( stretch ); QSearchField* searchField = new QSearchField( this ); connect( searchField, SIGNAL( textChanged( const QString& ) ), SLOT( slotFiltertextChanged( const QString& ) ) ); toolBar->addWidget( searchField ); m_treeView->setEditTriggers(QAbstractItemView::EditKeyPressed); m_treeView->setExpandsOnDoubleClick(false); m_treeView->setAlternatingRowColors( true ); // The delegate does its own eliding. m_treeView->setTextElideMode( Qt::ElideNone ); m_treeView->setRootIsDecorated( true ); m_treeView->setContextMenuPolicy( Qt::CustomContextMenu ); connect( m_treeView, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( slotContextMenuRequested( const QPoint& ) ) ); // I hate doing this but the stupid default view sizeHints suck badly. setMinimumHeight( 200 ); // A reasonable default depth. m_treeView->expandToDepth( 0 ); }