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); }
#else #ifndef HTML_ICON #define HTML_ICON(a) QIcon(a) #endif #endif struct html_editor::action_type html_editor::m_action_definitions[] = { #define QN QT_TR_NOOP #define NA QWebPage::NoWebAction // {name, shortcut, icon, WebAction {QN("Bold"), QN("Ctrl+B"), "icon-bold.png", SLOT(bold()), NA } ,{QN("Italic"), QN("Ctrl+I"), "icon-italic.png", SLOT(italic()), NA } ,{QN("Underline"), QN("Ctrl+U"), "icon-underline.png", SLOT(underline()), NA } ,{QN("Strike through"), QN("Ctrl+S"), "icon-strikethrough.png", SLOT(strikethrough()) , NA} ,{QN("Superscript"), NULL, "icon-superscript.png", SLOT(superscript()), NA } ,{QN("Subscript"), NULL, "icon-subscript.png", SLOT(subscript()), NA } // separator before 6 ,{QN("Set foreground color"), NULL, "icon-foreground-color.png", SLOT(foreground_color()), NA } ,{QN("Set background color"), NULL, "icon-background-color.png", SLOT(background_color()), NA } ,{QN("Insert image"), NULL, "icon-image.png", SLOT(insert_image()), NA } ,{QN("Insert link"), NULL, "icon-link.png", SLOT(insert_link()), NA } ,{QN("Insert horizontal rule"), NULL, "icon-hr.png", SLOT(insert_hr()), NA } ,{QN("Insert unordered list"), NULL, "icon-bullet-list.png", SLOT(insert_unordered_list()), NA } ,{QN("Insert ordered list"), NULL, "icon-ordered-list.png", SLOT(insert_ordered_list()), NA } ,{QN("Remove format"), NULL, "icon-eraser.png", SLOT(remove_format()), NA } ,{QN("Cut"), NULL, "icon-cut.png", NULL, QWebPage::Cut } ,{QN("Copy"), NULL, "icon-copy.png", NULL, QWebPage::Copy } ,{QN("Paste"), NULL, "icon-paste.png", NULL, QWebPage::Paste }