예제 #1
0
void AgendaPlug::reload(bool align)
{
    // The first time should always be with alignment
    if (!ui->componentList->model()->rowCount())
        align = true;

    const int scrollPosition = ui->componentList->verticalScrollBar()->value();

    cleanup();

    ui->componentList->setDate(this->date);

    const int daysBack = 7;
    const int daysForward = 14;
    const int totalDays = daysBack + 1 + daysForward;

    QListWidgetItem *todaysHeading = NULL;

    QDateTime date = QDateTime(this->date).addDays(-daysBack);

    const time_t startStamp = date.toTime_t();
    const time_t   endStamp = date.addDays(totalDays).toTime_t() - 1;
    vector<ComponentInstance*> instances;

    CMulticalendar *mc = CMulticalendar::MCInstance();
    vector<CCalendar*> calendars = mc->getListCalFromMc();
    map<int,int> palette;

    // Get components from each calendar
    for (unsigned int i = 0; i < calendars.size(); i++) {
        CCalendar *calendar = calendars[i];
        if (!calendar->IsShown()) continue;

        palette[calendar->getCalendarId()] = calendar->getCalendarColor();

        int offset = 0;
        int error;
        vector<CComponent*> componentsPart = calendar->getAllEventsTodos(startStamp, endStamp, 1024, offset, error);

        for (unsigned int c = 0; c < componentsPart.size(); c++) {
            if (componentsPart[c]->getType() == E_TODO
                    &&  static_cast<CTodo*>(componentsPart[c])->getStatus())
            {
                delete componentsPart[c];
            } else {
                components.push_back(componentsPart[c]);
            }
        }
    }

    CWrapper::expand(components, instances, startStamp, endStamp);
    CWrapper::sort(instances);

    // Populate the list day by day
    for (int d = 0; d < totalDays; d++) {
        const bool onToday = date.date() == this->date;
        const time_t nextDayStamp = date.addDays(1).toTime_t();

        if (onToday || !instances.empty() && instances.front()->stamp < nextDayStamp) {
            // Add date heading
            QListWidgetItem *item = new QListWidgetItem();
            item->setData(DateRole, date.date());
            item->setData(HeadingRole, true);
            ui->componentList->addItem(item);

            if (onToday) {
                todaysHeading = item;

                // Add component creation buttons
                NewComponentWidget *ncw = new NewComponentWidget();
                item = new QListWidgetItem();
                item->setData(DateRole, this->date);
                ui->componentList->addItem(item);
                ui->componentList->setCurrentItem(item);
                ui->componentList->setItemWidget(item, ncw);

                connect(ncw->eventButton, SIGNAL(clicked()), ui->componentList, SLOT(newEvent()));
                connect(ncw->todoButton,  SIGNAL(clicked()), ui->componentList, SLOT(newTodo()));
            }
        }

        unsigned int i = 0;
        while (i < instances.size() && instances[i]->stamp < nextDayStamp) {
            // Add the intance to the list
            QListWidgetItem *item = new QListWidgetItem();
            item->setData(ComponentRole, QVariant::fromValue(instances[i]));
            item->setData(ColorRole, palette[instances[i]->component->getCalendarId()]);
            item->setData(DateRole, date.date());
            ui->componentList->addItem(item);

            if (instances[i]->end() < nextDayStamp
                    ||  instances[i]->end() == nextDayStamp && instances[i]->duration() > 0)
            {
                // If this is the last day of this instance, remove it from the list...
                instances.erase(instances.begin() + i);
            } else {
                // ...otherwise replace it with a copy to use for the next day
                if (nextDayStamp < endStamp)
                    instances[i] = new ComponentInstance(instances[i]->component, instances[i]->stamp);
                i++;
            }
        }

        date = date.addDays(1);
    }

    mc->releaseListCalendars(calendars);

    if (align) {
        // Align the view with the heading of the selected day
        ui->componentList->scrollToItem(todaysHeading, QAbstractItemView::PositionAtTop);
    } else {
        // Restore the original view
        ui->componentList->verticalScrollBar()->setValue(scrollPosition);
    }
}
예제 #2
0
파일: mainwindow.cpp 프로젝트: Fxrh/DoBeeDo
void MainWindow::setupGui()
{
  model = new TreeModel(this);
  model->addSection(i18n("Overdue"), -1 );
  model->addSection(i18n("Today"), 0);
  model->addSection(i18n("Tomorrow"), 1 );
  model->addSection(i18n("Next week"), 7);
  model->addSection(i18n("Next month"), 31);
  model->addSection(i18n("Future"), -2);
  filterModel = new FilterModel(this);
  filterModel->setSourceModel(model);
  view = new QTreeView(this);
  delegate = new TodoDelegate(view, this);
  view->setModel(filterModel);
  view->setHeaderHidden(true);
  view->setIconSize(QSize(0,0));
  view->setAnimated(true);
  view->setStyleSheet("QTreeView::branch{border-image: none; image: none;border-left: 0px;}");
  view->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  view->setEditTriggers(QAbstractItemView::AllEditTriggers);
  //view->setTabKeyNavigation(true);
  view->setSelectionMode(QAbstractItemView::SingleSelection);
  view->setSelectionBehavior(QAbstractItemView::SelectRows);
  view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
  view->setRootIsDecorated(false);
  view->setSortingEnabled(false);
  view->setAllColumnsShowFocus(true);
  view->setExpandsOnDoubleClick(true);
  view->header()->setStretchLastSection(false);
  view->header()->setResizeMode(0,QHeaderView::Stretch);
  view->setItemDelegate(delegate);
  view->setContextMenuPolicy(Qt::CustomContextMenu);
  
  doEdit = new KLineEdit(this);
  doEdit->setClickMessage(i18n("new task..."));
  view->setFocusProxy(doEdit);
//  doAddBtn = new KPushButton(KIcon("list-add"),"",this);
  doAddBtn = new QToolButton();
  doAddBtn->setIcon(KIcon("list-add"));
  doAddBtn->setIconSize(QSize(35,35));
  timeBox = new KComboBox(this);
  timeBox->addItem(i18n("Today"));
  timeBox->addItem(i18n("Tomorrow"));
  timeBox->addItem(i18n("Next Monday"));
  timeBox->addItem(i18n("Next Tuesday"));
  timeBox->addItem(i18n("Next Wednesday"));
  timeBox->addItem(i18n("Next Thursday"));
  timeBox->addItem(i18n("Next Friday"));
  timeBox->addItem(i18n("Next Saturday"));
  timeBox->addItem(i18n("Next Sunday"));
  timeBox->addItem(i18n("Future"));
  timeBox->setFocusProxy(doEdit);
  addSelectCatBox = new KComboBox(this);
  for( int i=0; i<Settings::self()->categories()->count(); i++ ){
    addSelectCatBox->addItem(Settings::self()->categories()->at(i));
  } 
  addSelectCatBox->setCurrentIndex(0);
  addSelectCatBox->setFocusProxy(doEdit);
  addLayout = new QGridLayout;
  addLayout->addWidget(doEdit, 0,0,1,2);
  addLayout->addWidget(timeBox, 1,0);
  addLayout->addWidget(addSelectCatBox, 1, 1);
  addLayout->addWidget(doAddBtn, 0,2,2,1);
  
  categoryBox = new KComboBox();
  categoryBox->addItem(i18nc("category, show all items", "All"));
  for( int i=0; i<Settings::self()->categories()->count(); i++ ){
    categoryBox->addItem(Settings::self()->categories()->at(i));
  }  
  doneBtn = new KPushButton(KIcon("edit-delete"),i18n("Remove"));
  editBtn = new KPushButton(KIcon("document-edit"),i18n("Edit"));
  bottomLayout = new QHBoxLayout;
  bottomLayout->addWidget(categoryBox);
  bottomLayout->addStretch();
  bottomLayout->addWidget(editBtn);
  bottomLayout->addWidget(doneBtn);
  
  mainLayout = new QVBoxLayout;
  mainLayout->addLayout(addLayout);
  mainLayout->addWidget(view);
  mainLayout->addLayout(bottomLayout);
  
  mainWidget = new QWidget(this);
  mainWidget->setLayout(mainLayout);
  setCentralWidget(mainWidget);
  setWindowTitle("DoBeeDo");
  
  doneAct = new KAction(KIcon("edit-delete"),i18n("Remove"), this);
  editAct = new KAction(KIcon("document-edit"),i18n("Edit"), this);
  configAct = new KAction(KIcon("configure"),i18n("Configure DoBeeDo"),this);
  actionCollection()->addAction("done", doneAct);
  actionCollection()->addAction("edit", editAct);
  actionCollection()->addAction("configDobeedo", configAct);
  KStandardAction::quit( kapp, SLOT(quit()), actionCollection() );
  
  KXmlGuiWindow::setupGUI(Default, "dobeedoui.rc");
  
  connect( view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)) );
  connect( view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editTodo()) );
  connect( doEdit, SIGNAL(returnPressed()), doAddBtn, SLOT(animateClick()) );
  connect( doAddBtn, SIGNAL(clicked()), this, SLOT(newTodo()) );
  connect( doneAct, SIGNAL(triggered()), this, SLOT(removeTodo()) );
  connect( doneBtn, SIGNAL(clicked()), this, SLOT(removeTodo()) );
  connect( editAct, SIGNAL(triggered()), this, SLOT(editTodo()) );
  connect( editBtn, SIGNAL(clicked()), this, SLOT(editTodo()) );
  connect( categoryBox, SIGNAL(currentIndexChanged(int)), this, SLOT(showCat(int)) );
  connect( categoryBox, SIGNAL(currentIndexChanged(int)), view, SLOT(expandAll()) );
  connect( configAct, SIGNAL(triggered()), this, SLOT(showConfigDialog()) );
}
예제 #3
0
TodoView::TodoView(CalObject *cal, QWidget *parent, const char *name)
    : KTabListBox(parent, name, 5)
{
  calendar = cal;
  // set up filter for events
  lbox.installEventFilter(this);
  // set up the widget to have 4 columns (one hidden), and
  // only a vertical scrollbar
  clearTableFlags(Tbl_hScrollBar);
  clearTableFlags(Tbl_autoHScrollBar);
  // BL: autoscrollbar in not working...
  setTableFlags(Tbl_hScrollBar);
  setAutoUpdate(TRUE);
  adjustColumns();
  // insert pictures for use to show a checked/not checked todo
  dict().insert("CHECKED", new QPixmap(Icon("checkedbox.xpm")));
  dict().insert("EMPTY", new QPixmap(Icon("emptybox.xpm")));
  dict().insert("CHECKEDMASK", new QPixmap(Icon("checkedbox-mask.xpm")));
  dict().insert("EMPTYMASK", new QPixmap(Icon("emptybox-mask.xpm")));

  // this is the thing that lets you edit the todo text.
  editor = new QLineEdit(this);
  editor->hide();
  connect(editor, SIGNAL(returnPressed()),
	  this, SLOT(updateSummary()));
  connect(editor, SIGNAL(returnPressed()),
	  editor, SLOT(hide()));
  connect(editor, SIGNAL(textChanged(const char *)),
	  this, SLOT(changeSummary(const char *)));
  
  connect(this, SIGNAL(selected(int, int)),
    	  this, SLOT(updateItem(int, int)));
  connect(this, SIGNAL(highlighted(int, int)),
	  this, SLOT(hiliteAction(int, int)));

  priList = new QListBox(this);
  priList->hide();
  priList->insertItem("1");
  priList->insertItem("2");
  priList->insertItem("3");
  priList->insertItem("4");
  priList->insertItem("5");
  priList->setFixedHeight(priList->itemHeight()*5+5);
  priList->setFixedWidth(priList->maxItemWidth()+5);
  connect(priList, SIGNAL(highlighted(int)),
	  priList, SLOT(hide()));
  connect(priList, SIGNAL(highlighted(int)),
	  this, SLOT(changePriority(int)));

  QPixmap pixmap;
  rmbMenu1 = new QPopupMenu;
  pixmap = Icon("checkedbox.xpm");
  rmbMenu1->insertItem(pixmap, i18n("New Todo"), this,
		       SLOT(newTodo()));
  pixmap = Icon("delete.xpm");
  rmbMenu1->insertItem(pixmap, i18n("Purge Completed "), this,
		       SLOT(purgeCompleted()));

  rmbMenu2 = new QPopupMenu;
  pixmap = Icon("checkedbox.xpm");
  rmbMenu2->insertItem(pixmap, i18n("New Todo"), this,
		     SLOT (newTodo()));
  rmbMenu2->insertItem(i18n("Edit Todo"), this,
		     SLOT (editTodo()));
  pixmap = Icon("delete.xpm");
  rmbMenu2->insertItem(pixmap, i18n("Delete Todo"), this,
		     SLOT (deleteTodo()));
  rmbMenu2->insertItem(i18n("Purge Completed "), this,
		       SLOT(purgeCompleted()));


  editingFlag = FALSE;
  connect(this, SIGNAL(headerClicked(int)), this, SLOT(headerAction(int)));
  updateConfig();
  prevRow = updatingRow = -1;
}