예제 #1
0
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);
    }
}
예제 #2
0
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() + "');");
}
예제 #3
0
void MainWindow::insertUrl() {
    URLDialog dialog(this);
    if (dialog.exec() == QDialog::Accepted) {
        QString cmd = QString("document.execCommand('CreateLink',false,'%1');").arg(dialog.getURL());
        JS(cmd);
    }
}
예제 #4
0
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();

}
예제 #5
0
void MainWindow::loadAboutInfo()
{
    ui->NotesList->clearSelection();
    ui->noteTitle->clear();
    ui->titleBar->hide();
    clearConflictBar();
    ui->actionDelete_Note->setDisabled(true);
    JS("loadAboutInfo();");
}
예제 #6
0
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
}
예제 #7
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));
}
예제 #8
0
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);
}
예제 #9
0
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*)));
                    }
예제 #10
0
void MainWindow::changeNoteGuid(QString oldGuid, QString newGuid) {
    if (getCurrentNoteGuid() == oldGuid)
        JS(QString("guid='%1';").arg(newGuid));
}
예제 #11
0
QString MainWindow::getCurrentNoteGuid() {
    QString guid = JS("guid").toString();
    if (guid != "main")
        return guid;
    return "";
}
예제 #12
0
void MainWindow::changeFontSize(QString fontSize) {
    JS("document.execCommand('fontSize',false,'"+fontSize+"');");
}
예제 #13
0
void MainWindow::changeFont(QString font) {
    JS("document.execCommand('fontName',false,'"+font+"');");
}
예제 #14
0
void MainWindow::insertHorizontalLine() {
    JS("document.execCommand('insertHorizontalRule',false,null);");
}
예제 #15
0
void MainWindow::sync() {
    JS("checkModified();");
    saveSelectionState();
    EdamProtocol::GetInstance()->sync();
}
예제 #16
0
파일: test008.c 프로젝트: jjinux/jenarix
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]}");

}