Esempio n. 1
0
QString FileStorage::createNote(const QString &text)
{
    QString uid = QUuid::createUuid().toString();
    uid = uid.mid(1, uid.length()-2);
    saveNote(uid, text);
    return uid;
}
NoteEditor::NoteEditor(QWidget *parent) :
    QWidget(parent)
{
    id = 0;
    setMaximumSize(450, 150);
    int noteEditorWidth = 450;
    int noteEditorHeight = 200;

    noteEditText = new QTextEdit;
    noteEditText->setStyleSheet("border: 2px solid grey");

    saveButton = new QPushButton(tr("Save"));
    saveButton->setToolTip(tr("Save note"));

    saveButton->setFixedSize(noteEditorWidth / 2, noteEditorHeight / 8);
    saveButton->setEnabled(false);

    noteEditorLayout = new QGridLayout;
    noteEditorLayout->addWidget(noteEditText, 0, 0);
    noteEditorLayout->addWidget(saveButton, 1, 0, Qt::AlignRight);
    setLayout(noteEditorLayout);

    connect(saveButton, SIGNAL(clicked()), this, SLOT(saveNote()));
    connect(noteEditText, SIGNAL(textChanged()), this, SLOT(textChange()));
}
Esempio n. 3
0
/**
 * \brief    Constructeur d'un éditeur de note
 * \details  Construit les parties permettant d'associer un tag à une note,
 *           editer le titre de la note et sauvegarder la note
 * \param    note         Pointeur sur la note à éditer
 */
NoteEditor::NoteEditor(Note *note, QWidget *parent) : resource(note) {
    setParent(parent);

    // top tag row
    QLabel* tagsLabel = new QLabel("Tags associés : ");
    tags = new QComboBox(this);
    QLabel* deleteTagLabel = new QLabel("Supprimer un tag : ");
    deleteTag = new QComboBox(this);
    for(QMultiMap<QString, QString>::iterator it = TagManager::getInstance().getAssociatedTagsBegin() ; it != TagManager::getInstance().getAssociatedTagsEnd(); ++it){
        if (it.value() == note->getId()) {
            tags->addItem(it.key());
            deleteTag->addItem(it.key());
        }
    }
    deleteTagBtn = new QPushButton(this);
    deleteTagBtn->setIcon(QIcon("supprimer.png"));
    QObject::connect(deleteTagBtn, SIGNAL(clicked()), this, SLOT(deleteAssociatedTag()));
    QLabel* addTagLabel = new QLabel("Associer un tag : ");
    addTag = new QComboBox(this);
    for(QSet<QString>::iterator it = TagManager::getInstance().getTagsBegin() ; it != TagManager::getInstance().getTagsEnd(); ++it){
        addTag->addItem((*it));
    }
    addTagBtn = new QPushButton(this);
    addTagBtn->setIcon(QIcon("ajouter.png"));
    QObject::connect(addTagBtn, SIGNAL(clicked()), this, SLOT(addAssociatedTag()));
    QHBoxLayout* tagRowLayout = new QHBoxLayout;
    tagRowLayout->addWidget(tagsLabel);
    tagRowLayout->addWidget(tags);
    tagRowLayout->addWidget(deleteTagLabel);
    tagRowLayout->addWidget(deleteTag);
    tagRowLayout->addWidget(deleteTagBtn);
    tagRowLayout->addWidget(addTagLabel);
    tagRowLayout->addWidget(addTag);
    tagRowLayout->addWidget(addTagBtn);

    // title and save
    title = new QLineEdit;
    save = new QPushButton;
    save->setIcon(QIcon("sauvegarder.png"));

    title->setText(note->getTitle());
    QObject::connect(title, SIGNAL(textChanged(QString)), this, SLOT(enableSave()));
    QObject::connect(title, SIGNAL(textChanged(QString)), this, SLOT(updateNote()));
    save->setEnabled(false);
    QObject::connect(save, SIGNAL(clicked()), this, SLOT(saveNote()));

    layout = new QVBoxLayout;
    QHBoxLayout* hLayout = new QHBoxLayout;
    hLayout->addWidget(title);
    hLayout->addWidget(save);
    layout->addLayout(tagRowLayout);
    layout->addLayout(hLayout);
    this->setLayout(layout);

    QObject::connect(&TagManager::getInstance(), SIGNAL(onTagAdd(QString)), this, SLOT(tagCreated(QString)));
    QObject::connect(&TagManager::getInstance(), SIGNAL(onTagDelete(QString)), this, SLOT(tagDeleted(QString)));
}
Esempio n. 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
	// open database connection
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/Users/jdoud/dev/brainstorm.sqlite");
	if(!db.open())
	{
		qDebug() << db.lastError();
		qFatal("Failed to connect.");
	}

	// setup UI
    ui->setupUi(this);
	ui->toolBar->addWidget(ui->comboFonts);
	ui->toolBar->addWidget(ui->comboFontSizes);
	ui->toolBar->addWidget(ui->comboColors);

	// set text editor defaults
	ui->textNote->document()->setIndentWidth(20);
	ui->textNote->setTabStopWidth(20);
	ui->textNote->setTabChangesFocus(false);
	ui->actionIncrease_Indent->setShortcut(Qt::Key_Tab);
	ui->actionDecrease_Indent->setShortcut(Qt::Key_Backtab);

	// setup comboColors
	QPixmap pix(16, 16);
	pix.fill(Qt::white);
	ui->comboColors->addItem(pix, "");
	pix.fill(Qt::black);
	ui->comboColors->addItem(pix, "");
	pix.fill(Qt::red);
	ui->comboColors->addItem(pix, "");
	pix.fill(Qt::blue);
	ui->comboColors->addItem(pix, "");
	pix.fill(Qt::darkGreen);
	ui->comboColors->addItem(pix, "");
	pix.fill(Qt::gray);
	ui->comboColors->addItem(pix, "");


	// create system tray icon
	createActions();
	createTrayIcon();

	// create models
    categoriesModel = new QSqlTableModel();
	categoriesModel->setTable("categories");
	categoriesModel->setSort(1, Qt::AscendingOrder);
	categoriesModel->select();
	ui->listCategories->setModel(categoriesModel);
	ui->listCategories->setModelColumn(1);

    notesModel = new QSqlTableModel();
	notesModel->setTable("notes");
	ui->listNotes->setModel(notesModel);
	ui->listNotes->setModelColumn(2);

    // set splitter size
    QList<int> sizes;
    sizes << 230 << 150;
    ui->splitterLists->setSizes(sizes);
    sizes.clear();
    sizes << 230 << 600;
    ui->splitterNote->setSizes(sizes);

    // connect File menu slots
    connect(ui->actionNew_Category, SIGNAL(triggered()), this, SLOT(newCategory()));
    connect(ui->actionRename_Category, SIGNAL(triggered()), this, SLOT(renameCategory()));
    connect(ui->actionDelete_Category, SIGNAL(triggered()), this, SLOT(deleteCategory()));
    connect(ui->actionNew_Note, SIGNAL(triggered()), this, SLOT(newNote()));
    connect(ui->actionRename_Note, SIGNAL(triggered()), this, SLOT(renameNote()));
    connect(ui->actionSave_Note, SIGNAL(triggered()), this, SLOT(saveNote()));
    connect(ui->actionDelete_Note, SIGNAL(triggered()), this, SLOT(deleteNote()));
    connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
    // connect Edit menu slots	
    connect(ui->actionFind_Replace, SIGNAL(triggered()), this, SLOT(findAndReplace()));
    // connect Format menu slots
    connect(ui->actionBold, SIGNAL(triggered()), this, SLOT(bold()));
    connect(ui->actionItalic, SIGNAL(triggered()), this, SLOT(italic()));
    connect(ui->actionUnderline, SIGNAL(triggered()), this, SLOT(underline()));
    connect(ui->actionStrikethrough, SIGNAL(triggered()), this, SLOT(strikethrough()));
    connect(ui->actionBullet_List, SIGNAL(triggered()), this, SLOT(bulletList()));
    connect(ui->actionNumber_List, SIGNAL(triggered()), this, SLOT(numberList()));
    connect(ui->actionIncrease_Indent, SIGNAL(triggered()), this, SLOT(increaseIndent()));
    connect(ui->actionDecrease_Indent, SIGNAL(triggered()), this, SLOT(decreaseIndent()));
    connect(ui->actionShow_Colors, SIGNAL(triggered()), this, SLOT(showColors()));
    connect(ui->actionShow_Fonts, SIGNAL(triggered()), this, SLOT(showFonts()));
    connect(ui->actionIncrease_Font, SIGNAL(triggered()), this, SLOT(increaseFont()));
    connect(ui->actionDecrease_Font, SIGNAL(triggered()), this, SLOT(decreaseFont()));
    connect(ui->actionReset_Font, SIGNAL(triggered()), this, SLOT(resetFont()));
    connect(ui->actionAlign_Left, SIGNAL(triggered()), this, SLOT(alignLeft()));
    connect(ui->actionAlign_Center, SIGNAL(triggered()), this, SLOT(alignCenter()));
    connect(ui->actionAlign_Right, SIGNAL(triggered()), this, SLOT(alignRight()));
    connect(ui->actionAlign_Justify, SIGNAL(triggered()), this, SLOT(alignJustify()));
    // connect View menu slots
    connect(ui->actionHide_Window, SIGNAL(triggered()), this, SLOT(hide()));
    connect(ui->actionPrevious_Category, SIGNAL(triggered()), this, SLOT(previousCategory()));
    connect(ui->actionNext_Category, SIGNAL(triggered()), this, SLOT(nextCategory()));
    connect(ui->actionPrevious_Note, SIGNAL(triggered()), this, SLOT(previousNote()));
    connect(ui->actionNext_Note, SIGNAL(triggered()), this, SLOT(nextNote()));
    // connect Help menu slots
    connect(ui->actionAbout_Brainstorm, SIGNAL(triggered()), this, SLOT(aboutBrainstorm()));
    connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
	// connect application slots
	connect(ui->textNote, SIGNAL(cursorPositionChanged()), this, SLOT(updateMenus()));
	connect(ui->textNote, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(updateMenus()));
    connect(ui->comboFonts, SIGNAL(activated(QString)), this, SLOT(setFont(QString)));
    connect(ui->comboFontSizes, SIGNAL(activated(QString)), this, SLOT(setFontSize(QString)));
    connect(ui->comboColors, SIGNAL(activated(int)), this, SLOT(setFontColor(int)));
	// connect category list slots
	connect(ui->listCategories->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateNoteList(QModelIndex)));
	// connect note list slots
	connect(ui->listNotes->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateNoteText(QModelIndex)));
	// connect text slots
	ui->textNote->installEventFilter((this));
	// connect system tray icon
    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

	// initialize default data
	ui->listCategories->selectionModel()->setCurrentIndex(categoriesModel->index(0, 1), QItemSelectionModel::SelectCurrent);

}