Пример #1
0
ListItem* NotesWidget::getNoteWithGuid(QString guid)
{
    ListItem* item = reinterpret_cast<ListItem*>(this->currentItem());
    if ((item != NULL) && (item->getGUID() == guid))
        return item;

    for (int i = 0; i < count(); i++) {
        ListItem* item = reinterpret_cast<ListItem*>(this->item(i));
        if (item->getGUID() == guid) {
            return item;
        }
    }
    return NULL;
}
Пример #2
0
void MainWindow::saveSelectionState(QString notebook) {

    QSqlQuery query;
    if (!query.exec("DELETE FROM syncStatus WHERE option IN ('selNotebook', 'selTab', 'selNote', 'selTag')"))
        LOG_ERROR("SQL: " + query.lastError().text());

    sql::updateSyncStatus("selTab", ui->toolBox->currentIndex());

    if (notebook.isEmpty() && (ui->notebooks->currentItem() != NULL)) {
        TreeItem* n = reinterpret_cast<TreeItem*>(ui->notebooks->currentItem());
        notebook = n->getName();
    }
    if (!notebook.isEmpty())
        sql::updateSyncStatus("selNotebook", notebook);

    QStringList tagGuids = ui->tags->currentGuids();
    if (!tagGuids.isEmpty())
        sql::updateSyncStatus("selTag", tagGuids.first());

    if (ui->NotesList->currentItem() == NULL)
        return;

    ListItem* l = reinterpret_cast<ListItem*>(ui->NotesList->currentItem());
    sql::updateSyncStatus("selNote", l->getGUID());
}
Пример #3
0
void MainWindow::switchNote()
{
    ListItem* l = reinterpret_cast<ListItem*>(ui->NotesList->currentItem());
    QString id = l->getGUID();

    if (id.isEmpty())
        return;

    ui->noteTitle->clear();
    ui->titleBar->show();
    ui->editButton->setChecked(false);
    clearConflictBar();

    JS(QString("loadNote('%1', false);").arg(id));
}
Пример #4
0
void NotesWidget::contextMenuEvent (QContextMenuEvent * event)
{

    ListItem* item = reinterpret_cast<ListItem*>(this->itemAt(event->pos()));

    QMenu menu(this);

    QMenu *sortMenu = menu.addMenu(QIcon::fromTheme("view-sort-ascending"), "Sort By");
    QActionGroup *sortActions = new QActionGroup(this);
    sortActions->setExclusive(true);

    QAction *sortByTitle = new QAction("Title", this);
    sortByTitle->setObjectName("sortByTitle");
    sortByTitle->setCheckable(true);
    sortByTitle->setChecked(sortType == byTitle);
    sortMenu->addAction(sortByTitle);
    sortActions->addAction(sortByTitle);

    QAction *sortByTitleDesc = new QAction("Title Desc...", this);
    sortByTitleDesc->setObjectName("sortByTitleDesc");
    sortByTitleDesc->setCheckable(true);
    sortByTitleDesc->setChecked(sortType == byTitleDesc);
    sortMenu->addAction(sortByTitleDesc);
    sortActions->addAction(sortByTitleDesc);

    QAction *sortByCreated = new QAction("Created Date", this);
    sortByCreated->setObjectName("sortByCreated");
    sortByCreated->setCheckable(true);
    sortByCreated->setChecked(sortType == byCreated);
    sortMenu->addAction(sortByCreated);
    sortActions->addAction(sortByCreated);

    QAction *sortByCreatedDesc = new QAction("Created Date Desc...", this);
    sortByCreatedDesc->setObjectName("sortByCreatedDesc");
    sortByCreatedDesc->setCheckable(true);
    sortByCreatedDesc->setChecked(sortType == byCreatedDesc);
    sortMenu->addAction(sortByCreatedDesc);
    sortActions->addAction(sortByCreatedDesc);

    QAction *sortByModified = new QAction("Modified Date", this);
    sortByModified->setObjectName("sortByModified");
    sortByModified->setCheckable(true);
    sortByModified->setChecked(sortType == byModified);
    sortMenu->addAction(sortByModified);
    sortActions->addAction(sortByModified);

    QAction *sortByModifiedDesc = new QAction("Modified Date Desc...", this);
    sortByModifiedDesc->setObjectName("sortByModifiedDesc");
    sortByModifiedDesc->setCheckable(true);
    sortByModifiedDesc->setChecked(sortType == byModifiedDesc);
    sortMenu->addAction(sortByModifiedDesc);
    sortActions->addAction(sortByModifiedDesc);


    if (item == NULL) {
        QAction *newNote = new QAction(QIcon::fromTheme("document-new"), "New Note...", this);
        newNote->setObjectName("new");
        newNote->setDisabled(listType == TreeItem::trashBin);
        menu.addAction(newNote);
    } else {
        if (item->isActive()) {
            QAction *del = new QAction(QIcon::fromTheme("edit-delete"), "Delete Note", this);
            del->setObjectName("delete");
            menu.addAction(del);
        } else {
            QAction *res = new QAction("Restore", this);
            res->setObjectName("restore");
            menu.addAction(res);
        }
    }

    QAction *ret = menu.exec(event->globalPos());

    if (ret == NULL) {
        event->ignore();
        return;
    }

    if (ret->objectName() == "delete")
        emit noteDeleted(item->getGUID());
    else if (ret->objectName() == "restore")
        emit noteRestored(item->getGUID());
    else if (ret->objectName() == "new")
        emit noteCreated();
    else if (ret->objectName() == "sortByTitle")
        setNoteSortType(byTitle);
    else if (ret->objectName() == "sortByCreated")
        setNoteSortType(byCreated);
    else if (ret->objectName() == "sortByModified")
        setNoteSortType(byModified);
    else if (ret->objectName() == "sortByTitleDesc")
        setNoteSortType(byTitleDesc);
    else if (ret->objectName() == "sortByCreatedDesc")
        setNoteSortType(byCreatedDesc);
    else if (ret->objectName() == "sortByModifiedDesc")
        setNoteSortType(byModifiedDesc);

    event->accept();
}