App::App(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { showFullScreen = false; setCaption("IQNotes"); toolbar = new QPEToolBar(this); toolbar->setVerticalStretchable(false); toolbar->setHorizontalStretchable(false); setToolBarsMovable(false); multiTB = new QToolButton(toolbar); // File menu filePopupMenu = new QPopupMenu(this); menu = new QPEMenuBar(this); int fileID; fileID = menu->insertItem("File", filePopupMenu); #ifndef DEMO newID = filePopupMenu->insertItem("New", this, SLOT(newFile()), SHIFT+Key_N); openID = filePopupMenu->insertItem("Open", this, SLOT(openFile()), SHIFT+Key_O); saveID = filePopupMenu->insertItem("Save", this, SLOT(saveFile()), SHIFT+Key_S); // file->insertItem("Save as", this, SLOT(saveAsFile())); closeID = filePopupMenu->insertItem("Close", this, SLOT(closeFileMenu())); filePopupMenu->insertSeparator(); #endif filePopupMenu->insertItem("Quit", this, SLOT(goodBye())); // Tree menu treePopupMenu = new QPopupMenu(this); treeID = menu->insertItem("Tree", treePopupMenu); searchA = new QAction("Search", ToolBarIcon::prepare("iqnotes/find"), QString::null, Key_F, this, 0 ); connect(searchA, SIGNAL(activated()), this, SLOT(search())); // searchA->addTo(toolbar); searchA->addTo(treePopupMenu); multiTB->setIconSet(ToolBarIcon::prepare("iqnotes/find")); connect(multiTB, SIGNAL(clicked()), this, SLOT(search())); // toolbar->addSeparator(); // no room for this treePopupMenu->insertSeparator(); quickAddA = new QAction("Quick add", ToolBarIcon::prepare("iqnotes/quick_add"), QString::null, Key_Q, this, 0 ); connect(quickAddA, SIGNAL(activated()), this, SLOT(quickAdd())); quickAddA->addTo(toolbar); quickAddA->addTo(treePopupMenu); addBeforeA = new QAction("Add before", ToolBarIcon::prepare("iqnotes/add_before"), QString::null, 0, this, 0 ); connect(addBeforeA, SIGNAL(activated()), this, SLOT(addBefore())); addBeforeA->addTo(toolbar); addBeforeA->addTo(treePopupMenu); addAfterA = new QAction("Add after", ToolBarIcon::prepare("iqnotes/add_after"), QString::null, Key_A, this, 0 ); connect(addAfterA, SIGNAL(activated()), this, SLOT(addAfter())); addAfterA->addTo(toolbar); addAfterA->addTo(treePopupMenu); addChildA = new QAction("Add child", ToolBarIcon::prepare("iqnotes/add_child"), QString::null, Key_E, this, 0 ); connect(addChildA, SIGNAL(activated()), this, SLOT(addChild())); addChildA->addTo(toolbar); addChildA->addTo(treePopupMenu); treePopupMenu->insertSeparator(); sortID = treePopupMenu->insertItem("Sort", this, SLOT(sort())); treePopupMenu->insertSeparator(); expandTreeID = treePopupMenu->insertItem("Expand tree", this, SLOT(expandTree())); collapseTreeID = treePopupMenu->insertItem("Collapse tree", this, SLOT(collapseTree())); treePopupMenu->insertSeparator(); taskListPopupMenu = new QPopupMenu(this); taskListPopupMenu->insertItem("From whole tree", this, SLOT(taskListWholeTree())); taskListPopupMenu->insertItem("From current note down", this, SLOT(taskListCurrent())); eventListPopupMenu = new QPopupMenu(this); eventListPopupMenu->insertItem("From whole tree", this, SLOT(eventListWholeTree())); eventListPopupMenu->insertItem("From current note down", this, SLOT(eventListCurrent())); taskListID = treePopupMenu->insertItem("Task list", taskListPopupMenu); eventListID = treePopupMenu->insertItem("Event list", eventListPopupMenu); treePopupMenu->insertSeparator(); reminderID = treePopupMenu->insertItem("Reminder", this, SLOT(showReminder())); toolbar->addSeparator(); /* closeSearchTreeA = new QAction("Close search tree", Resource::loadPixmap("iqnotes/close_search_tree"), QString::null, 0, this, 0 ); connect(closeSearchTreeA, SIGNAL(activated()), this, SLOT(closeSearchTree())); closeSearchTreeA->addTo(tree);*/ // Note menu notePopupMenu = new QPopupMenu(this); noteID = menu->insertItem("Note", notePopupMenu); renameNoteID = notePopupMenu->insertItem("Rename", this, SLOT(renameNote()), Key_R); editA = new QAction("Edit", ToolBarIcon::prepare("iqnotes/edit"), QString::null, Key_Return, this, 0 ); editA->setToolTip("Edit note"); connect(editA, SIGNAL(activated()), this, SLOT(editNote())); editA->addTo(toolbar); editA->addTo(notePopupMenu); cutA = new QAction("Cut", ToolBarIcon::prepare("iqnotes/bin"), QString::null, Key_X, this, 0 ); cutA->setToolTip("Cut note"); connect(cutA, SIGNAL(activated()), this, SLOT(cutNote())); cutA->addTo(toolbar); cutA->addTo(notePopupMenu); copyNotePopupMenu = new QPopupMenu(this); copyNotePopupMenu->insertItem("Only current note", this, SLOT(copyNoteOnlyCurrent())); copyNotePopupMenu->insertItem("Current note and down", this, SLOT(copyNoteCurrentAndDown())); copyNoteID = notePopupMenu->insertItem("Copy", copyNotePopupMenu); pasteNotePopupMenu = new QPopupMenu(this); pasteNotePopupMenu->insertItem("Before", this, SLOT(pasteNoteBefore())); pasteNotePopupMenu->insertItem("After", this, SLOT(pasteNoteAfter()), SHIFT+Key_A); pasteNotePopupMenu->insertItem("As child", this, SLOT(pasteNoteChild()), SHIFT+Key_E); pasteNoteID = notePopupMenu->insertItem("Paste", pasteNotePopupMenu); notePopupMenu->insertSeparator(); setPictureA = new QAction("Set picture", ToolBarIcon::prepare("iqnotes/set_picture"), QString::null, CTRL+Key_P, this, 0); setPictureA->setToolTip("Set picture"); connect(setPictureA, SIGNAL(activated()), this, SLOT(setPicture())); //setPictureA->addTo(toolbar); setPictureA->addTo(notePopupMenu); notePopupMenu->insertSeparator(); setTaskA = new QAction("Set task", ToolBarIcon::prepare("iqnotes/set_task"), QString::null, CTRL+Key_T, this, 0); setTaskA->setToolTip("Set task"); connect(setTaskA, SIGNAL(activated()), this, SLOT(setTask())); //setTaskA->addTo(toolbar); setTaskA->addTo(notePopupMenu); setEventA = new QAction("Set event", ToolBarIcon::prepare("iqnotes/set_event"), QString::null, CTRL+Key_E, this, 0); setEventA->setToolTip("Set event"); connect(setEventA, SIGNAL(activated()), this, SLOT(setEvent())); //setEventA->addTo(toolbar); setEventA->addTo(notePopupMenu); unsetTaskEventID = notePopupMenu->insertItem("Unset", this, SLOT(unsetTaskEvent())); notePopupMenu->insertSeparator(); setReminderID = notePopupMenu->insertItem("Set reminder", this, SLOT(setReminder())); unsetReminderID = notePopupMenu->insertItem("Unset reminder", this, SLOT(unsetReminder())); // View menu viewPopupMenu = new QPopupMenu(this); viewID = menu->insertItem("View", viewPopupMenu); toolbar->addSeparator(); hideNoteA = new QAction("Hide note", ToolBarIcon::prepare("iqnotes/hide_note"), QString::null, Key_1, this, 0 ); hideNoteA->setToolTip("Hide note"); connect(hideNoteA, SIGNAL(activated()), this, SLOT(hideNote())); hideNoteA->addTo(toolbar); hideNoteA->addTo(viewPopupMenu); hideTreeA = new QAction("Hide tree", ToolBarIcon::prepare("iqnotes/hide_tree"), QString::null, Key_2, this, 0 ); hideTreeA->setToolTip("Hide tree"); connect(hideTreeA, SIGNAL(activated()), this, SLOT(hideTree())); hideTreeA->addTo(toolbar); hideTreeA->addTo(viewPopupMenu); halfViewA = new QAction("Half view", ToolBarIcon::prepare("iqnotes/half_view"), QString::null, Key_3, this, 0 ); halfViewA->setToolTip("Half view"); connect(halfViewA, SIGNAL(activated()), this, SLOT(halfView())); halfViewA->addTo(toolbar); halfViewA->addTo(viewPopupMenu); /* viewPopupMenu->insertSeparator(); toggleToolBarID = viewPopupMenu->insertItem("Toggle toolbar", this, SLOT(toggleToolBar())); toggleFullScreenID = viewPopupMenu->insertItem("Toggle fullscreen", this, SLOT(toggleFullScreen())); */ // Options menu optionsPopupMenu = new QPopupMenu(this); optionsID = menu->insertItem("Options", optionsPopupMenu); optionsPopupMenu->insertItem("Define new entry", this, SLOT(defineNewEntry())); optionsPopupMenu->insertItem("Change entry", this, SLOT(changeEntry())); optionsPopupMenu->insertItem("Delete entry", this, SLOT(deleteEntry())); optionsPopupMenu->insertSeparator(); optionsPopupMenu->insertItem("Preferences", this, SLOT(preferenc())); // Help menu helpPopupMenu = new QPopupMenu(this); menu->insertItem("Help", helpPopupMenu); helpPopupMenu->insertItem("About", this, SLOT(about())); addToolBar(toolbar); IQApp = this; // notes = new Notes(this, "bla"); setCentralWidget(notes); connect(notes, SIGNAL(emptyNoteTree()), this, SLOT(isEmptyNoteTree())); connect(notes, SIGNAL(noEmptyNoteTree()), this, SLOT(isNotEmptyNoteTree())); connect(notes, SIGNAL(searchTreeShown()), this, SLOT(searchTreeShown())); connect(notes, SIGNAL(searchTreeClosed()), this, SLOT(searchTreeClosed())); connect(notes, SIGNAL(taskListShown()), this, SLOT(taskListShown())); connect(notes, SIGNAL(taskListClosed()), this, SLOT(taskListClosed())); connect(notes, SIGNAL(eventListShown()), this, SLOT(eventListShown())); connect(notes, SIGNAL(eventListClosed()), this, SLOT(eventListClosed())); connect(notes, SIGNAL(reminderShown()), this, SLOT(reminderShown())); connect(notes, SIGNAL(reminderClosed()), this, SLOT(reminderClosed())); connect(notes, SIGNAL(noteModified(bool)), this, SLOT(setModified(bool))); readConfig(); changeFont(); noNoteTree(); }
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); }