void MainWindow::updateEditButtonsState() { editingEnabled = JS("isOnEditableArea();").toBool(); emit editButtonsStateChanged(editingEnabled); if (editingEnabled) { QString f = JS("document.queryCommandValue('fontName');").toString(); emit updateFont(QFont(f)); int size = JS("document.queryCommandValue('fontSize');").toInt(); emit updateFontSize(size - 1); } }
void MainWindow::insertImg() { QString note = getCurrentNoteGuid(); insertImage dialog(this, note); if (dialog.exec() != QDialog::Accepted) return; if (dialog.getType() == insertImage::IMG_NONE) return; if (dialog.getType() == insertImage::IMG_URL) JS("document.execCommand('insertImage',false,'"+dialog.getUrl()+"');"); else if (dialog.getType() == insertImage::IMG_LOCAL) JS("insertImage('"+ dialog.getBodyHash() + "', '" + dialog.mimeType() + "');"); }
void MainWindow::insertUrl() { URLDialog dialog(this); if (dialog.exec() == QDialog::Accepted) { QString cmd = QString("document.execCommand('CreateLink',false,'%1');").arg(dialog.getURL()); JS(cmd); } }
void MainWindow::newNote() { TreeItem* n = reinterpret_cast<TreeItem*>(ui->notebooks->currentItem()); if (n->getType() == TreeItem::stack) { if (n->childCount() > 0) { n = reinterpret_cast<TreeItem*>(n->child(0)); ui->notebooks->setCurrentItem(n); } else n = NULL; } if ((n->getType() == TreeItem::allNotes) || (n->getType() == TreeItem::trashBin) || (n == NULL)) { if (ui->notebooks->defaultNotebook() == NULL) return; ui->notebooks->setCurrentItem(ui->notebooks->defaultNotebook()); n = ui->notebooks->defaultNotebook(); } QString nb = n->getGUIDs().first(); Note *note = new Note(); QString guid = note->createNewNote(nb); delete note; ui->editButton->setChecked(false); JS(QString("loadNote('%1', true);").arg(guid)); ui->titleBar->show(); ui->toolBox->setCurrentIndex(0); ui->NotesList->switchNotebook(TreeItem::noteBook, n->getGUIDs(), guid); ui->notebooks->updateCounts(); }
void MainWindow::loadAboutInfo() { ui->NotesList->clearSelection(); ui->noteTitle->clear(); ui->titleBar->hide(); clearConflictBar(); ui->actionDelete_Note->setDisabled(true); JS("loadAboutInfo();"); }
void bind_events() { keyboard_event_t kb; joystick_event_t js; joybutton_event_t jb; #define KBD(p, r, k) kb = (keyboard_event_t) {.player = 0, .press_action = p,\ .release_action = r, .keycode = k}; bind_keyboard_event(kb) KBD(ACTION_START_UP, ACTION_END_UP, SDLK_w); KBD(ACTION_START_DOWN, ACTION_END_DOWN, SDLK_s); KBD(ACTION_START_LEFT, ACTION_END_LEFT, SDLK_d); KBD(ACTION_START_RIGHT, ACTION_END_RIGHT, SDLK_a); KBD(ACTION_START_JUMP, ACTION_END_JUMP, SDLK_SPACE); #define JB(s, p, r, b) jb = (joybutton_event_t) { .stick = s, .press_action = p,\ .release_action = r, .button = b}; bind_joybutton_event(jb) bind_joystick_to_player(0, 0); bind_joystick_to_player(1, 1); JB(0, ACTION_START_JUMP, ACTION_END_JUMP, 14); JB(1, ACTION_START_JUMP, ACTION_END_JUMP, 14); #define JS(s, a, t, minp, minf, maxp, maxf) js = (joystick_event_t) {\ .stick = s,\ .action_min_pass = minp, .action_min_fail = minf,\ .action_max_pass = maxp, .action_max_fail = maxf,\ .axis = a, .threshold = t}; bind_joystick_event(js) JS(0, 0, 1000, ACTION_START_RIGHT, ACTION_END_RIGHT, ACTION_START_LEFT, ACTION_END_LEFT); JS(0, 1, 1000, ACTION_START_UP, ACTION_END_UP, ACTION_START_DOWN, ACTION_END_DOWN); JS(1, 0, 1000, ACTION_START_RIGHT, ACTION_END_RIGHT, ACTION_START_LEFT, ACTION_END_LEFT); JS(1, 1, 1000, ACTION_START_UP, ACTION_END_UP, ACTION_START_DOWN, ACTION_END_DOWN); #undef KBD #undef JB #undef JS }
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)); }
void MainWindow::setEditable(bool enabled) { LOG_DEBUG(QVariant(enabled).toString()); QString guid = getCurrentNoteGuid(); if (enabled && guid.isEmpty()) return; ui->editBar->setVisible(enabled); ui->noteTitle->setReadOnly(!enabled); JS("setEditable(" + QVariant(enabled).toString() + ");"); if (enabled) { ui->editor->setFocus(); ui->tagsBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); } else ui->tagsBar->setToolButtonStyle(Qt::ToolButtonTextOnly); }
void MainWindow::editorContextMenuRequested ( const QPoint & pos ) { QString guid = getCurrentNoteGuid(); if (guid == "main") return; QWebHitTestResult element = ui->editor->page()->mainFrame()->hitTestContent(pos); if (element.isNull()) return; QStringList classes = allClasses(element.element()); if (classes.contains("pdfarea")) return; QMenu * menu = new QMenu(ui->editor); menu->addAction(ui->editor->pageAction(QWebPage::SelectAll)); if (element.isContentSelected()) { if (!menu->isEmpty()) menu->addSeparator(); menu->addAction(ui->editor->pageAction(QWebPage::Copy)); if (element.isContentEditable()) { menu->addAction(ui->editor->pageAction(QWebPage::Cut)); menu->addAction(ui->editor->pageAction(QWebPage::Paste)); menu->addSeparator(); menu->addAction(ui->editor->pageAction(QWebPage::ToggleBold)); menu->addAction(ui->editor->pageAction(QWebPage::ToggleItalic)); menu->addAction(ui->editor->pageAction(QWebPage::ToggleUnderline)); } } if(!element.imageUrl().isEmpty() && (element.imageUrl().scheme() != "qrc")) { if (!menu->isEmpty()) menu->addSeparator(); menu->addAction(ui->editor->pageAction(QWebPage::DownloadImageToDisk)); menu->addAction(ui->editor->pageAction(QWebPage::CopyImageToClipboard)); if (element.imageUrl().scheme() == "http" || element.imageUrl().scheme() == "https") menu->addAction(ui->editor->pageAction(QWebPage::CopyImageUrlToClipboard)); QAction * openImage = new QAction(this); openImage->setText("Open Image"); openImage->setObjectName("openImage"); menu->addAction(openImage); if (JS("editMode").toBool()) { menu->addSeparator(); QAction * deleteImage = new QAction(this); deleteImage->setText("Delete Image"); deleteImage->setObjectName("deleteImage"); deleteImage->setIcon(QIcon::fromTheme("edit-delete")); menu->addAction(deleteImage); if (element.imageUrl().scheme() != "resource") { QAction * saveLocally = new QAction(this); saveLocally->setText("Save Locally"); saveLocally->setObjectName("saveLocally"); menu->addAction(saveLocally); } } } if (!element.linkUrl().isEmpty()) { if (!menu->isEmpty()) menu->addSeparator(); menu->addAction(ui->editor->pageAction(QWebPage::CopyLinkToClipboard)); if (element.isContentEditable()) { QAction * deleteURL = new QAction(this); deleteURL->setText("Remove Link"); deleteURL->setObjectName("deleteURL"); menu->addAction(deleteURL); } } if (element.isContentEditable() && !element.isContentSelected() && element.imageUrl().isEmpty()) { Speller *speller = Speller::GetInstance(); if (speller->initialized()) { QHash<QString, QString> languages = speller->availableLanguages(); if (!languages.isEmpty()) { if (!menu->isEmpty()) menu->addSeparator(); QAction* act = menu->addAction(tr("Check &Spelling")); act->setCheckable(true); act->setChecked(speller->isEnabled()); connect(act, SIGNAL(triggered(bool)), speller, SLOT(setEnabled(bool))); if (speller->isEnabled()) { QString word = JS(QString("getSpellingWord(%1,%2);").arg(pos.x()).arg(pos.y())).toString(); if (!word.isEmpty() && speller->isMisspelled(word)) { QStringList wordsList = speller->suggest(word); QFont boldFont = menu->font(); boldFont.setBold(true); QActionGroup *suggestGroup = new QActionGroup(menu); QString suggest; foreach(suggest, wordsList) { QAction* act = menu->addAction(suggest); act->setFont(boldFont); act->setData(suggest); suggestGroup->addAction(act); } connect(suggestGroup, SIGNAL(triggered(QAction*)), this, SLOT(replaceWord(QAction*))); }
void MainWindow::changeNoteGuid(QString oldGuid, QString newGuid) { if (getCurrentNoteGuid() == oldGuid) JS(QString("guid='%1';").arg(newGuid)); }
QString MainWindow::getCurrentNoteGuid() { QString guid = JS("guid").toString(); if (guid != "main") return guid; return ""; }
void MainWindow::changeFontSize(QString fontSize) { JS("document.execCommand('fontSize',false,'"+fontSize+"');"); }
void MainWindow::changeFont(QString font) { JS("document.execCommand('fontName',false,'"+font+"');"); }
void MainWindow::insertHorizontalLine() { JS("document.execCommand('insertHorizontalRule',false,null);"); }
void MainWindow::sync() { JS("checkModified();"); saveSelectionState(); EdamProtocol::GetInstance()->sync(); }
int main(int argc, char **argv) { JS("null"); JS("true"); JS("false"); JS("0"); JS("1"); JS("-1"); JS("1.0"); JS("-1.0"); #ifdef JX_64_BIT JS("1.0000100000000001"); JS("-1.0000100000000001"); JS("9223372036854775807"); JS("-9223372036854775808"); #else JS("1.00001"); JS("-1.00001"); JS("2147483647"); JS("-2147483648"); #endif JS("[]"); JS("{}"); JS("\"hi\""); JS("[null]"); JS("[true]"); JS("[false]"); JS("[1]"); JS("[-1]"); JS("[\"one\"]"); JS("{1:2}"); JS("{-1:-2}"); JS("{\"one\":\"two\"}"); JS("[1,2]"); JS("[-1,-2]"); JS("[1,[2]]"); JS("[1,[2,3]]"); JS("{1:{2:3}}"); JS("[1,[2,3,4,5]]"); JS("{1:{2:3,4:5}}"); JS("[1,[2,\"three\",4,5]]"); /* below are all invalid and should give null */ JF(""); JF("-"); JF("{[]:1}"); JF("{{}:1}"); JF("{[1,2]:1}"); JF("{[1,2]:[3,4]}"); }