diff --git a/src/libs/ui/kptcalendareditor.cpp b/src/libs/ui/kptcalendareditor.cpp index 437a4d39..83905d40 100644 --- a/src/libs/ui/kptcalendareditor.cpp +++ b/src/libs/ui/kptcalendareditor.cpp @@ -1,877 +1,877 @@ /* This file is part of the KDE project * Copyright (C) 2007, 2012 Dag Andersen * Copyright (C) 2017 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kptcalendareditor.h" #include "kcalendar/kdatepicker.h" #include "kcalendar/kdatetable.h" //#include "kptcalendarpanel.h" #include "kptcommand.h" #include "kptcalendarmodel.h" #include "kptcalendar.h" #include "kptduration.h" #include "kptnode.h" #include "kptproject.h" #include "kpttask.h" #include "kptdatetime.h" #include "kptintervaledit.h" #include "kptitemviewsettup.h" #include "Help.h" #include "kptdebug.h" #include #include #include #include #include #include #include #include #include #include #include namespace KPlato { //-------------------- CalendarTreeView::CalendarTreeView( QWidget *parent ) : TreeViewBase( parent ) { header()->setContextMenuPolicy( Qt::CustomContextMenu ); setModel( new CalendarItemModel() ); setSelectionBehavior( QAbstractItemView::SelectRows ); setSelectionMode( QAbstractItemView::SingleSelection ); setSelectionModel( new QItemSelectionModel( model() ) ); setItemDelegateForColumn( CalendarItemModel::Scope, new EnumDelegate( this ) ); setItemDelegateForColumn( CalendarItemModel::TimeZone, new EnumDelegate( this ) ); // timezone #ifdef HAVE_KHOLIDAYS setItemDelegateForColumn( CalendarItemModel::HolidayRegion, new EnumDelegate( this ) ); #endif connect( header(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint)) ); } void CalendarTreeView::headerContextMenuRequested( const QPoint &pos ) { emit contextMenuRequested(QModelIndex(), mapToGlobal(pos)); } void CalendarTreeView::contextMenuEvent ( QContextMenuEvent *event ) { emit contextMenuRequested( indexAt(event->pos()), event->globalPos() ); } void CalendarTreeView::focusInEvent ( QFocusEvent *event ) { //debugPlan; TreeViewBase::focusInEvent( event ); emit focusChanged(); } void CalendarTreeView::focusOutEvent ( QFocusEvent * event ) { //debugPlan; TreeViewBase::focusInEvent( event ); emit focusChanged(); } void CalendarTreeView::selectionChanged( const QItemSelection &sel, const QItemSelection &desel ) { //debugPlan<selectedIndexes() ) { debugPlan<selectedIndexes() ); + emit sigSelectionChanged( selectionModel()->selectedIndexes() ); } void CalendarTreeView::currentChanged( const QModelIndex & current, const QModelIndex & previous ) { //debugPlan; TreeViewBase::currentChanged( current, previous ); // possible bug in qt: in QAbstractItemView::SingleSelection you can select multiple items/rows selectionModel()->select( current, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); emit currentChanged( current ); } Calendar *CalendarTreeView::currentCalendar() const { return model()->calendar( currentIndex() ); } Calendar *CalendarTreeView::selectedCalendar() const { QModelIndexList lst = selectionModel()->selectedRows(); if ( lst.count() == 1 ) { return model()->calendar( lst.first() ); } return 0; } QList CalendarTreeView::selectedCalendars() const { QList lst; foreach ( const QModelIndex &i, selectionModel()->selectedRows() ) { Calendar *a = model()->calendar( i ); if ( a ) { lst << a; } } return lst; } void CalendarTreeView::dragMoveEvent(QDragMoveEvent *event) { if (dragDropMode() == InternalMove && (event->source() != this || !(event->possibleActions() & Qt::MoveAction))) { return; } TreeViewBase::dragMoveEvent( event ); if ( ! event->isAccepted() ) { return; } // QTreeView thinks it's ok to drop, but it might not be... event->ignore(); QModelIndex index = indexAt( event->pos() ); if ( ! index.isValid() ) { if ( model()->dropAllowed( 0, event->mimeData() ) ) { event->accept(); } return; } Calendar *c = model()->calendar( index ); if ( c == 0 ) { errorPlan<<"no calendar to drop on!"; return; // hmmm } switch ( dropIndicatorPosition() ) { case AboveItem: case BelowItem: // c == sibling // if siblings parent is me or child of me: illegal if ( model()->dropAllowed( c->parentCal(), event->mimeData() ) ) { event->accept(); } break; case OnItem: // c == new parent if ( model()->dropAllowed( c, event->mimeData() ) ) { event->accept(); } break; default: break; } } //-------------------- CalendarDayView::CalendarDayView( QWidget *parent ) : QTableView( parent ), m_readwrite( false ) { setTabKeyNavigation( false ); setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ); horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch ); m_model = new CalendarDayItemModel( this ); setModel(m_model); verticalHeader()->hide(); actionSetWork = new QAction( i18n( "Work..." ), this ); connect( actionSetWork, SIGNAL(triggered(bool)), SLOT(slotSetWork()) ); actionSetVacation = new QAction( i18n( "Non-working" ), this ); connect( actionSetVacation, SIGNAL(triggered(bool)), SLOT(slotSetVacation()) ); actionSetUndefined = new QAction( i18n( "Undefined" ), this ); connect( actionSetUndefined, SIGNAL(triggered(bool)), SLOT(slotSetUndefined()) ); } QSize CalendarDayView::sizeHint() const { QSize s = QTableView::sizeHint(); s.setHeight( horizontalHeader()->height() + rowHeight( 0 ) + frameWidth() * 2 ); return s; } void CalendarDayView::slotSetWork() { debugPlan; if ( receivers( SIGNAL(executeCommand(KUndo2Command*)) ) == 0 ) { return; } Calendar *cal = model()->calendar(); if ( cal == 0 ) { return; } QModelIndexList lst = selectionModel()->selectedIndexes(); if ( lst.isEmpty() ) { lst << currentIndex(); } if ( lst.isEmpty() ) { return; } QList days; foreach ( const QModelIndex &i, lst ) { CalendarDay *day = model()->day( i ); if ( day == 0 ) { continue; } days << day; } IntervalEditDialog *dlg = new IntervalEditDialog( cal, days, this ); connect(dlg, SIGNAL(finished(int)), SLOT(slotIntervalEditDialogFinished(int))); dlg->show(); dlg->raise(); dlg->activateWindow(); } void CalendarDayView::slotIntervalEditDialogFinished( int result ) { IntervalEditDialog *dlg = qobject_cast( sender() ); if ( dlg == 0 ) { return; } if ( result == QDialog::Accepted ) { MacroCommand *cmd = dlg->buildCommand(); if ( cmd ) { emit executeCommand( cmd ); } } dlg->deleteLater(); } void CalendarDayView::slotSetVacation() { debugPlan; if ( receivers( SIGNAL(executeCommand(KUndo2Command*)) ) == 0 ) { return; } QModelIndexList lst = selectionModel()->selectedIndexes(); if ( lst.isEmpty() ) { lst << currentIndex(); } if ( lst.isEmpty() ) { return; } bool mod = false; MacroCommand *m = new MacroCommand( kundo2_i18n( "Modify Weekday State" ) ); foreach ( const QModelIndex &i, lst ) { CalendarDay *day = model()->day( i ); if ( day == 0 || day->state() == CalendarDay::NonWorking ) { continue; } mod = true; m->addCommand( new CalendarModifyStateCmd( model()->calendar(), day, CalendarDay::NonWorking ) ); } if ( mod ) { emit executeCommand( m ); } else { delete m; } } void CalendarDayView::slotSetUndefined() { debugPlan; if ( receivers( SIGNAL(executeCommand(KUndo2Command*)) ) == 0 ) { return; } QModelIndexList lst = selectionModel()->selectedIndexes(); if ( lst.isEmpty() ) { lst << currentIndex(); } if ( lst.isEmpty() ) { return; } bool mod = false; MacroCommand *m = new MacroCommand( kundo2_i18n( "Modify Weekday State" ) ); foreach ( const QModelIndex &i, lst ) { CalendarDay *day = model()->day( i ); if ( day == 0 || day->state() == CalendarDay::Undefined ) { continue; } mod = true; m->addCommand( new CalendarModifyStateCmd( model()->calendar(), day, CalendarDay::Undefined ) ); } if ( mod ) { emit executeCommand( m ); } else { delete m; } } void CalendarDayView::setCurrentCalendar( Calendar *calendar ) { model()->setCalendar( calendar ); } void CalendarDayView::headerContextMenuRequested( const QPoint &/*pos*/ ) { // debugPlan<logicalIndexAt(pos)<<" at"<calendar() || model()->calendar()->isShared() ) { return; } QMenu menu; menu.addAction( actionSetWork ); menu.addAction( actionSetVacation ); menu.addAction( actionSetUndefined ); menu.exec( event->globalPos(), actionSetWork ); //emit contextMenuRequested( indexAt(event->pos()), event->globalPos() ); } void CalendarDayView::focusInEvent ( QFocusEvent *event ) { //debugPlan; QTableView::focusInEvent( event ); emit focusChanged(); } void CalendarDayView::focusOutEvent ( QFocusEvent * event ) { //debugPlan; QTableView::focusInEvent( event ); emit focusChanged(); } void CalendarDayView::selectionChanged( const QItemSelection &sel, const QItemSelection &desel ) { //debugPlan<selectedIndexes() ) { debugPlan<selectedIndexes() ); + emit sigSelectionChanged( selectionModel()->selectedIndexes() ); } void CalendarDayView::currentChanged( const QModelIndex & current, const QModelIndex & previous ) { //debugPlan; QTableView::currentChanged( current, previous ); // selectionModel()->select( current, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); emit currentChanged( current ); } CalendarDay *CalendarDayView::selectedDay() const { QModelIndexList lst = selectionModel()->selectedIndexes(); if ( lst.count() == 1 ) { return model()->day( lst.first() ); } return 0; } //----------------------------------- CalendarEditor::CalendarEditor(KoPart *part, KoDocument *doc, QWidget *parent ) : ViewBase(part, doc, parent ), m_model( new DateTableDataModel( this ) ) { Help::add(this, xi18nc( "@info:whatsthis", "Work & Vacation Editor" "" "A calendar defines availability for resources or tasks of type Duration. " "A calendar can be specific to a resource or task, or shared by multiple resources or tasks. " "A day can be of type Undefined, Non-working day or Working day. " "A working day has one or more work intervals defined. " "" "A calendar can have sub calendars. If a day is undefined in a calendar, the parent calendar is checked. " "An Undefined day defaults to Non-working if used by a resource, or available all day if used by a task." "" "A calendar can be defined as the Default calendar. " "The default calendar is used by a working resource, when the resources calendar is not explicitly set." "More..." "", Help::page("Manual/Work_and_Vacation_Editor"))); setupGui(); QVBoxLayout *l = new QVBoxLayout( this ); l->setMargin( 0 ); QSplitter *sp = new QSplitter( this ); l->addWidget( sp ); m_calendarview = new CalendarTreeView( sp ); connect(this, SIGNAL(expandAll()), m_calendarview, SLOT(slotExpand())); connect(this, SIGNAL(collapseAll()), m_calendarview, SLOT(slotCollapse())); QFrame *f = new QFrame( sp ); l = new QVBoxLayout( f ); l->setMargin( 0 ); m_dayview = new CalendarDayView( f ); l->addWidget( m_dayview ); sp = new QSplitter( f ); l->addWidget( sp ); m_datePicker = new KDatePicker( sp ); m_datePicker->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); m_datePicker->dateTable()->setWeekNumbersEnabled( true ); m_datePicker->dateTable()->setGridEnabled( true ); m_datePicker->dateTable()->setSelectionMode( KDateTable::ExtendedSelection ); m_datePicker->dateTable()->setDateDelegate( new DateTableDateDelegate( m_datePicker->dateTable() ) ); m_datePicker->dateTable()->setModel( m_model ); m_datePicker->dateTable()->setPopupMenuEnabled( true ); m_calendarview->setDragDropMode( QAbstractItemView::InternalMove ); m_calendarview->setDropIndicatorShown( true ); m_calendarview->setDragEnabled ( true ); m_calendarview->setAcceptDrops( true ); m_calendarview->setAcceptDropsOnView( true ); connect( m_datePicker->dateTable(), SIGNAL(aboutToShowContextMenu(QMenu*,QDate)), SLOT(slotContextMenuDate(QMenu*,QDate)) ); connect( m_datePicker->dateTable(), SIGNAL(aboutToShowContextMenu(QMenu*,QList)), SLOT(slotContextMenuDate(QMenu*,QList)) ); /* const QDate date(2007,7,19); const QColor fgColor(Qt::darkGray); KDateTable::BackgroundMode bgMode = KDateTable::CircleMode; const QColor bgColor( Qt::lightGray); m_datePicker->dateTable()->setCustomDatePainting( date, fgColor, bgMode, bgColor );*/ m_calendarview->setEditTriggers( m_calendarview->editTriggers() | QAbstractItemView::EditKeyPressed ); m_dayview->setEditTriggers( m_dayview->editTriggers() | QAbstractItemView::EditKeyPressed ); m_calendarview->setDragDropMode( QAbstractItemView::InternalMove ); m_calendarview->setDropIndicatorShown ( true ); m_calendarview->setDragEnabled ( true ); m_calendarview->setAcceptDrops( true ); connect( m_calendarview->model(), SIGNAL(executeCommand(KUndo2Command*)), doc, SLOT(addCommand(KUndo2Command*)) ); connect( m_dayview->model(), SIGNAL(executeCommand(KUndo2Command*)), doc, SLOT(addCommand(KUndo2Command*)) ); connect( m_dayview, SIGNAL(executeCommand(KUndo2Command*)), doc, SLOT(addCommand(KUndo2Command*)) ); connect( m_calendarview, SIGNAL(currentChanged(QModelIndex)), this, SLOT(slotCurrentCalendarChanged(QModelIndex)) ); - connect( m_calendarview, SIGNAL(selectionChanged(QModelIndexList)), this, SLOT(slotCalendarSelectionChanged(QModelIndexList)) ); + connect( m_calendarview, SIGNAL(sigSelectionChanged(QModelIndexList)), this, SLOT(slotCalendarSelectionChanged(QModelIndexList)) ); connect( m_calendarview, SIGNAL(contextMenuRequested(QModelIndex,QPoint)), this, SLOT(slotContextMenuCalendar(QModelIndex,QPoint)) ); connect( m_dayview, SIGNAL(currentChanged(QModelIndex)), this, SLOT(slotCurrentDayChanged(QModelIndex)) ); - connect( m_dayview, SIGNAL(selectionChanged(QModelIndexList)), this, SLOT(slotDaySelectionChanged(QModelIndexList)) ); + connect( m_dayview, SIGNAL(sigSelectionChanged(QModelIndexList)), this, SLOT(slotDaySelectionChanged(QModelIndexList)) ); connect( m_dayview, SIGNAL(contextMenuRequested(QModelIndex,QPoint)), this, SLOT(slotContextMenuDay(QModelIndex,QPoint)) ); connect( m_dayview->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotEnableActions()) ); connect( m_calendarview, SIGNAL(focusChanged()), this, SLOT(slotEnableActions()) ); connect( m_dayview, SIGNAL(focusChanged()), this, SLOT(slotEnableActions()) ); } void CalendarEditor::draw( Project &project ) { m_calendarview->setProject( &project ); m_dayview->setProject( &project ); } void CalendarEditor::draw() { } void CalendarEditor::setGuiActive( bool activate ) { //debugPlan<currentIndex().isValid() ) { m_calendarview->selectionModel()->setCurrentIndex(m_calendarview->model()->index( 0, 0 ), QItemSelectionModel::NoUpdate); } //slotSelectionChanged( m_calendarview->selectionModel()->selectedRows() ); } } void CalendarEditor::slotContextMenuDate( QMenu *menu, const QList &dates ) { if ( ! isReadWrite() ) { return; } if (!currentCalendar() || currentCalendar()->isShared()) { return; } if ( dates.isEmpty() ) { m_currentMenuDateList << m_datePicker->date(); } else { m_currentMenuDateList = dates; } menu->addAction( actionSetWork ); menu->addAction( actionSetVacation ); menu->addAction( actionSetUndefined ); } void CalendarEditor::slotContextMenuDate( QMenu *menu, const QDate &date ) { debugPlan<isShared()) { return; } m_currentMenuDateList << date; menu->addAction( actionSetWork ); menu->addAction( actionSetVacation ); menu->addAction( actionSetUndefined ); } void CalendarEditor::slotContextMenuCalendar( const QModelIndex &index, const QPoint& pos ) { if (!index.isValid()) { slotHeaderContextMenuRequested(pos); return; } if ( ! isReadWrite() || !currentCalendar() ) { return; } //debugPlan<model()->calendar( index ); if ( a ) { name = "calendareditor_calendar_popup"; } }*/ //debugPlan<setContextMenuIndex(index); if ( name.isEmpty() ) { slotHeaderContextMenuRequested(pos); m_calendarview->setContextMenuIndex(QModelIndex()); return; } emit requestPopupMenu( name, pos ); m_calendarview->setContextMenuIndex(QModelIndex()); } void CalendarEditor::slotContextMenuDay( const QModelIndex &index, const QPoint& pos ) { if ( ! isReadWrite() ) { return; } debugPlan<model()->day( index ) ) { name = "calendareditor_day_popup"; } } debugPlan<loadContext(m_calendarview->model()->columnMap(), context); } void CalendarEditor::saveContext( QDomElement &context ) const { m_calendarview->saveContext(m_calendarview->model()->columnMap(), context); } Calendar *CalendarEditor::currentCalendar() const { return m_calendarview->currentCalendar(); } void CalendarEditor::slotCurrentCalendarChanged( const QModelIndex & ) { //debugPlan<setCurrentCalendar( currentCalendar() ); if ( m_model ) { m_model->setCalendar( currentCalendar() ); } } void CalendarEditor::slotCalendarSelectionChanged( const QModelIndexList& /*list */) { //debugPlan< lst = m_calendarview->selectedCalendars(); bool one = lst.count() == 1; bool more = lst.count() > 1; actionAddCalendar ->setEnabled( on && !more ); actionAddSubCalendar ->setEnabled( on && one ); actionDeleteSelection->setEnabled( on && ( one || more ) ); } void CalendarEditor::setupGui() { KActionCollection *coll = actionCollection(); QString name = "calendareditor_calendar_list"; actionAddCalendar = new QAction(koIcon("resource-calendar-insert"), i18n("Add Calendar"), this); coll->addAction("add_calendar", actionAddCalendar ); coll->setDefaultShortcut(actionAddCalendar, Qt::CTRL + Qt::Key_I); connect( actionAddCalendar , SIGNAL(triggered(bool)), SLOT(slotAddCalendar()) ); actionAddSubCalendar = new QAction(koIcon("resource-calendar-child-insert"), i18n("Add Subcalendar"), this); coll->addAction("add_subcalendar", actionAddSubCalendar ); coll->setDefaultShortcut(actionAddSubCalendar, Qt::SHIFT + Qt::CTRL + Qt::Key_I); connect( actionAddSubCalendar , SIGNAL(triggered(bool)), SLOT(slotAddSubCalendar()) ); actionDeleteSelection = new QAction(koIcon("edit-delete"), xi18nc("@action", "Delete"), this); coll->addAction("delete_calendar_selection", actionDeleteSelection ); coll->setDefaultShortcut(actionDeleteSelection, Qt::Key_Delete); connect( actionDeleteSelection, SIGNAL(triggered(bool)), SLOT(slotDeleteCalendar()) ); addAction( name, actionAddCalendar ); addAction( name, actionAddSubCalendar ); addAction( name, actionDeleteSelection ); actionSetWork = new QAction( i18n( "Work..." ), this ); connect( actionSetWork, SIGNAL(triggered(bool)), SLOT(slotSetWork()) ); actionSetVacation = new QAction( i18n( "Non-working" ), this ); connect( actionSetVacation, SIGNAL(triggered(bool)), SLOT(slotSetVacation()) ); actionSetUndefined = new QAction( i18n( "Undefined" ), this ); connect( actionSetUndefined, SIGNAL(triggered(bool)), SLOT(slotSetUndefined()) ); createOptionActions(ViewBase::OptionExpand | ViewBase::OptionCollapse | ViewBase::OptionViewConfig); } void CalendarEditor::slotOptions() { ItemViewSettupDialog *dlg = new ItemViewSettupDialog( this, m_calendarview, false, this ); connect(dlg, SIGNAL(finished(int)), SLOT(slotOptionsFinished(int))); dlg->show(); dlg->raise(); dlg->activateWindow(); } void CalendarEditor::updateReadWrite( bool readwrite ) { m_calendarview->setReadWrite( readwrite ); m_dayview->setReadWrite( readwrite ); ViewBase::updateReadWrite( readwrite ); } void CalendarEditor::slotAddCalendar () { //debugPlan; // get parent through sibling Calendar *cal = m_calendarview->selectedCalendar(); Calendar *parent = cal ? cal->parentCal() : 0; int pos = parent ? parent->indexOf( cal ) : project()->indexOf( cal ); if ( pos >= 0 ) { ++pos; // after selected calendar } insertCalendar ( new Calendar(), parent, pos ); } void CalendarEditor::slotAddSubCalendar () { //debugPlan; insertCalendar ( new Calendar (), m_calendarview->selectedCalendar () ); } void CalendarEditor::insertCalendar ( Calendar *calendar, Calendar *parent, int pos ) { m_calendarview->closePersistentEditor( m_calendarview->selectionModel()->currentIndex() ); QModelIndex i = m_calendarview->model()->insertCalendar ( calendar, pos, parent ); if ( i.isValid() ) { QModelIndex p = m_calendarview->model()->parent( i ); //if (parent) debugPlan<<" parent="<name()<<":"<setExpanded( p, true ); m_calendarview->setCurrentIndex( i ); m_calendarview->edit( i ); } } void CalendarEditor::slotDeleteCalendar() { //debugPlan; m_calendarview->model()->removeCalendar( m_calendarview->selectedCalendar() ); } void CalendarEditor::slotAddInterval () { //debugPlan; /* CalendarDay *parent = m_dayview->selectedDay (); if ( parent == 0 ) { TimeInterval *ti = m_dayview->selectedInterval(); if ( ti == 0 ) { return; } parent = m_dayview->model()->parentDay( ti ); if ( parent == 0 ) { return; } } QModelIndex i = m_dayview->model()->insertInterval( new TimeInterval(), parent ); if ( i.isValid() ) { QModelIndex p = m_dayview->model()->index( parent ); m_dayview->setExpanded( p, true ); m_dayview->setCurrentIndex( i ); m_dayview->edit( i ); }*/ } void CalendarEditor::slotDeleteDaySelection() { //debugPlan; /* TimeInterval *ti = m_dayview->selectedInterval(); if ( ti != 0 ) { m_dayview->model()->removeInterval( ti ); return; } CalendarDay *day = m_dayview->selectedDay(); if ( day != 0 ) { m_dayview->model()->removeDay( day ); }*/ } void CalendarEditor::slotAddDay () { //debugPlan; /* Calendar *c = currentCalendar(); if ( c == 0 ) { return; } QDate date = QDate::currentDate(); while ( c->day( date ) ) { date = date.addDays( 1 ); } QModelIndex i = m_dayview->model()->insertDay( new CalendarDay(date, CalendarDay::NonWorking ) ); if ( i.isValid() ) { QModelIndex p = m_dayview->model()->parent( i ); m_dayview->setExpanded( p, true ); m_dayview->setCurrentIndex( i ); m_dayview->edit( i ); }*/ } void CalendarEditor::slotSetWork() { debugPlan<show(); dlg->raise(); dlg->activateWindow(); m_currentMenuDateList.clear(); } void CalendarEditor::slotIntervalEditDialogFinished( int result ) { IntervalEditDialog *dlg = qobject_cast( sender() ); if ( dlg == 0 ) { return; } if ( result == QDialog::Accepted ) { MacroCommand *cmd = dlg->buildCommand(); if ( cmd ) { part()->addCommand( cmd ); } } dlg->deleteLater(); } void CalendarEditor::slotSetVacation() { debugPlan<findDay( date ); if ( day == 0 ) { mod = true; day = new CalendarDay( date, CalendarDay::NonWorking ); m->addCommand( new CalendarAddDayCmd( currentCalendar(), day ) ); if ( m_currentMenuDateList.count() == 1 ) { m->setText( kundo2_i18n( "%1: Set to Non-Working", date.toString() ) ); } } else if ( day->state() != CalendarDay::NonWorking ) { mod = true; m->addCommand( new CalendarModifyStateCmd( currentCalendar(), day, CalendarDay::NonWorking ) ); if ( m_currentMenuDateList.count() == 1 ) { m->setText( kundo2_i18n( "%1: Set to Non-Working", date.toString() ) ); } } } if ( mod ) { part()->addCommand( m ); } else { delete m; } m_currentMenuDateList.clear(); } void CalendarEditor::slotSetUndefined() { debugPlan; if ( m_currentMenuDateList.isEmpty() || currentCalendar() == 0 ) { return; } bool mod = false; MacroCommand *m = new MacroCommand( kundo2_i18n( "Modify Calendar" ) ); foreach ( const QDate &date, m_currentMenuDateList ) { CalendarDay *day = currentCalendar()->findDay( date ); if ( day && day->state() != CalendarDay::Undefined ) { mod = true; m->addCommand( new CalendarRemoveDayCmd( currentCalendar(), day ) ); if ( m_currentMenuDateList.count() == 1 ) { m->setText( kundo2_i18n( "Set %1 to Undefined", date.toString() ) ); } } } if ( mod ) { part()->addCommand( m ); } else { delete m; } m_currentMenuDateList.clear(); } } // namespace KPlato diff --git a/src/libs/ui/kptcalendareditor.h b/src/libs/ui/kptcalendareditor.h index db695023..6e035c90 100644 --- a/src/libs/ui/kptcalendareditor.h +++ b/src/libs/ui/kptcalendareditor.h @@ -1,228 +1,228 @@ /* This file is part of the KDE project Copyright (C) 2007 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KPTCALENDAREDITOR_H #define KPTCALENDAREDITOR_H #include "planui_export.h" #include "kptviewbase.h" #include "kptitemmodelbase.h" #include "kptcalendar.h" #include "kptcalendarmodel.h" #include class QPoint; class KUndo2Command; class KoDocument; namespace KPlato { class View; class Project; class Calendar; class CalendarDay; class DateTableDataModel; class KDatePicker; class PLANUI_EXPORT CalendarTreeView : public TreeViewBase { Q_OBJECT public: explicit CalendarTreeView(QWidget *parent); CalendarItemModel *model() const { return static_cast( TreeViewBase::model() ); } Project *project() const { return model()->project(); } void setProject( Project *project ) { model()->setProject( project ); } Calendar *currentCalendar() const; Calendar *selectedCalendar() const; QList selectedCalendars() const; Q_SIGNALS: void currentChanged( const QModelIndex& ); void currentColumnChanged( const QModelIndex&, const QModelIndex& ); - void selectionChanged( const QModelIndexList& ); + void sigSelectionChanged( const QModelIndexList& ); void contextMenuRequested( const QModelIndex&, const QPoint& ); void focusChanged(); protected Q_SLOTS: void headerContextMenuRequested( const QPoint &pos ); virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); virtual void currentChanged ( const QModelIndex & current, const QModelIndex & previous ); protected: void contextMenuEvent ( QContextMenuEvent * event ); void focusInEvent ( QFocusEvent * event ); void focusOutEvent ( QFocusEvent * event ); void dragMoveEvent(QDragMoveEvent *event); }; class PLANUI_EXPORT CalendarDayView : public QTableView { Q_OBJECT public: explicit CalendarDayView(QWidget *parent); CalendarDayItemModel *model() const { return m_model; } Project *project() const { return model()->project(); } void setProject( Project *project ) { model()->setProject( project ); } CalendarDay *selectedDay() const; TimeInterval *selectedInterval() const; QSize sizeHint() const; void setReadWrite( bool on ) { m_readwrite = on; } bool isReadWrite() const { return m_readwrite; } Q_SIGNALS: void currentChanged( const QModelIndex& ); void currentColumnChanged( const QModelIndex&, const QModelIndex& ); - void selectionChanged( const QModelIndexList& ); + void sigSelectionChanged( const QModelIndexList& ); void contextMenuRequested( const QModelIndex&, const QPoint& ); void focusChanged(); void executeCommand( KUndo2Command *cmd ); public Q_SLOTS: void setCurrentCalendar(KPlato::Calendar *calendar); protected Q_SLOTS: void headerContextMenuRequested( const QPoint &pos ); virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); virtual void currentChanged ( const QModelIndex & current, const QModelIndex & previous ); void slotSetWork(); void slotSetVacation(); void slotSetUndefined(); void slotIntervalEditDialogFinished( int result ); protected: void contextMenuEvent ( QContextMenuEvent * event ); void focusInEvent ( QFocusEvent * event ); void focusOutEvent ( QFocusEvent * event ); private: CalendarDayItemModel *m_model; QAction *actionSetUndefined; QAction *actionSetVacation; QAction *actionSetWork; bool m_readwrite; }; class PLANUI_EXPORT CalendarEditor : public ViewBase { Q_OBJECT public: CalendarEditor(KoPart *part, KoDocument *doc, QWidget *parent); void setupGui(); Project *project() const { return m_calendarview->project(); } virtual void draw( Project &project ); virtual void draw(); virtual void updateReadWrite( bool readwrite ); virtual Calendar *currentCalendar() const; /// Loads context info into this view. virtual bool loadContext( const KoXmlElement &/*context*/ ); /// Save context info from this view. virtual void saveContext( QDomElement &/*context*/ ) const; Q_SIGNALS: void addCalendar(KPlato::Calendar *calendar); void deleteCalendar(const QList&); public Q_SLOTS: /// Activate/deactivate the gui virtual void setGuiActive( bool activate ); protected: void updateActionsEnabled( bool on ); void insertCalendar( Calendar *calendar, Calendar *parent, int pos = -1 ); protected Q_SLOTS: void slotIntervalEditDialogFinished( int result ); void slotOptions(); private Q_SLOTS: void slotContextMenuCalendar( const QModelIndex& index, const QPoint& pos ); void slotContextMenuDay( const QModelIndex& index, const QPoint& pos ); void slotContextMenuDate( QMenu*, const QDate& ); void slotContextMenuDate( QMenu*, const QList& ); void slotCalendarSelectionChanged( const QModelIndexList& ); void slotCurrentCalendarChanged( const QModelIndex& ); void slotDaySelectionChanged( const QModelIndexList& ); void slotCurrentDayChanged( const QModelIndex& ); void slotEnableActions(); void slotAddCalendar(); void slotAddSubCalendar(); void slotDeleteCalendar(); void slotAddDay(); void slotAddInterval(); void slotDeleteDaySelection(); void slotSetWork(); void slotSetVacation(); void slotSetUndefined(); private: CalendarTreeView *m_calendarview; CalendarDayView *m_dayview; KDatePicker *m_datePicker; DateTableDataModel *m_model; QAction *actionAddCalendar; QAction *actionAddSubCalendar; QAction *actionDeleteSelection; QAction *actionAddDay; QAction *actionAddWorkInterval; QAction *actionDeleteDaySelection; QAction *actionSetUndefined; QAction *actionSetVacation; QAction *actionSetWork; QList m_currentMenuDateList; }; } //KPlato namespace #endif