// Override the constructor so we always use a NWebPage // rather than a QWebPage NWebView::NWebView(NBrowserWindow *parent) : QWebView(parent) { this->parent = parent; editorPage = new NWebPage(this); setPage(editorPage); isDirty = false; this->setFont(global.getGuiFont(font())); contextMenu = new QMenu(this); openAction = new QAction(tr("Open"), this); contextMenu->addAction(openAction); contextMenu->addSeparator(); contextMenu->setFont(global.getGuiFont(font())); cutAction = new QAction(tr("Cut"), this); this->setupShortcut(cutAction, "Edit_Cut"); contextMenu->addAction(cutAction); connect(cutAction, SIGNAL(triggered()), parent, SLOT(cutButtonPressed())); copyAction = new QAction(tr("Copy"), this); this->setupShortcut(copyAction, "Edit_Copy"); contextMenu->addAction(copyAction); connect(copyAction, SIGNAL(triggered()), parent, SLOT(copyButtonPressed())); pasteAction = new QAction(tr("Paste"), this); setupShortcut(pasteAction, "Edit_Paste"); contextMenu->addAction(pasteAction); connect(pasteAction, SIGNAL(triggered()), parent, SLOT(pasteButtonPressed())); pasteWithoutFormatAction = new QAction(tr("Paste as Unformatted Text"), this); this->setupShortcut(pasteWithoutFormatAction, "Edit_Paste_Without_Formatting"); contextMenu->addAction(pasteWithoutFormatAction); connect(pasteWithoutFormatAction, SIGNAL(triggered()), parent, SLOT(pasteWithoutFormatButtonPressed())); removeFormattingAction = new QAction(tr("Remove Formatting"), this); this->setupShortcut(removeFormattingAction, "Edit_Remove_Formatting"); contextMenu->addAction(removeFormattingAction); connect(removeFormattingAction, SIGNAL(triggered()), parent, SLOT(removeFormatButtonPressed())); contextMenu->addSeparator(); QMenu *colorMenu = new QMenu(tr("Background Color"), this); colorMenu->setFont(global.getGuiFont(font())); QAction *action = setupColorMenuOption(tr("White")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundWhite())); action = setupColorMenuOption(tr("Red")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundRed())); action = setupColorMenuOption(tr("Blue")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundBlue())); action = setupColorMenuOption(tr("Green")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundGreen())); action = setupColorMenuOption(tr("Yellow")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundYellow())); action = setupColorMenuOption(tr("Black")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundBlack())); action = setupColorMenuOption(tr("Grey")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundGrey())); action = setupColorMenuOption(tr("Purple")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundPurple())); action = setupColorMenuOption(tr("Brown")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundBrown())); action = setupColorMenuOption(tr("Orange")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundOrange())); action = setupColorMenuOption(tr("Powder Blue")); colorMenu->addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundPowderBlue())); contextMenu->addMenu(colorMenu); contextMenu->addSeparator(); todoAction = new QAction(tr("To-do"), this); contextMenu->addAction(todoAction); this->setupShortcut(todoAction, "Edit_Insert_Todo"); connect(todoAction, SIGNAL(triggered()), parent, SLOT(todoButtonPressed())); contextMenu->addSeparator(); insertHtmlEntitiesAction = new QAction(tr("HTML Entities"),this); contextMenu->addAction(insertHtmlEntitiesAction); this->setupShortcut(insertHtmlEntitiesAction, "Edit_Insert_Html_Entities"); connect(insertHtmlEntitiesAction, SIGNAL(triggered()), parent, SLOT(insertHtmlEntities())); contextMenu->addSeparator(); encryptAction = new QAction(tr("Encrypted Selected Text"), this); contextMenu->addAction(encryptAction); this->setupShortcut(encryptAction, "Edit_EncryptText"); connect(encryptAction, SIGNAL(triggered()), parent, SLOT(encryptButtonPressed())); insertLinkAction = new QAction(tr("Insert Hyperlink"), this); contextMenu->addAction(insertLinkAction); this->setupShortcut(insertLinkAction, "Edit_InsertHyperlink"); connect(insertLinkAction, SIGNAL(triggered()),parent, SLOT(insertLinkButtonPressed())); insertQuickLinkAction = new QAction(tr("Quick Link"), this); contextMenu->addAction(insertQuickLinkAction); this->setupShortcut(insertQuickLinkAction, "Edit_InsertQuickLink"); connect(insertQuickLinkAction, SIGNAL(triggered()),parent, SLOT(insertQuickLinkButtonPressed())); removeLinkAction = new QAction(tr("Remove Hyperlink"), this); contextMenu->addAction(removeLinkAction); this->setupShortcut(removeLinkAction, "Edit_RemoveHyperlink"); connect(removeLinkAction, SIGNAL(triggered()),parent, SLOT(removeLinkButtonPressed())); attachFileAction = new QAction(tr("Attach File"), this); contextMenu->addAction(attachFileAction); this->setupShortcut(attachFileAction, "Edit_Attach_File"); connect(attachFileAction, SIGNAL(triggered()),parent, SLOT(attachFile())); contextMenu->addSeparator(); insertLatexAction = new QAction(tr("Insert LaTeX Formula"), this); contextMenu->addAction(insertLatexAction); this->setupShortcut(insertLatexAction, "Edit_Insert_Latex"); connect(insertLatexAction, SIGNAL(triggered()),parent, SLOT(insertLatexButtonPressed())); contextMenu->addSeparator(); tableMenu = new QMenu(tr("Table"), this); tableMenu->setFont(global.getGuiFont(font())); contextMenu->addMenu(tableMenu); insertTableAction = new QAction(tr("Insert Table"), this); this->setupShortcut(insertTableAction, "Edit_Insert_Table"); tableMenu->addAction(insertTableAction); connect(insertTableAction, SIGNAL(triggered()), parent, SLOT(insertTableButtonPressed())); tableMenu->addSeparator(); insertTableRowAction = new QAction(tr("Insert Row"), this); this->setupShortcut(insertTableRowAction, "Edit_Insert_Table_Row"); tableMenu->addAction(insertTableRowAction); connect(insertTableRowAction, SIGNAL(triggered()), parent, SLOT(insertTableRowButtonPressed())); insertTableColumnAction = new QAction(tr("Insert Column"), this); this->setupShortcut(insertTableColumnAction, "Edit_Insert_Table_Column"); tableMenu->addAction(insertTableColumnAction); connect(insertTableColumnAction, SIGNAL(triggered()), parent, SLOT(insertTableColumnButtonPressed())); tableMenu->addSeparator(); deleteTableRowAction = new QAction(tr("Delete Row"), this); tableMenu->addAction(deleteTableRowAction); this->setupShortcut(deleteTableRowAction, "Edit_Delete_Table_Row"); connect(deleteTableRowAction, SIGNAL(triggered()), parent, SLOT(deleteTableRowButtonPressed())); deleteTableColumnAction = new QAction(tr("Delete Column"), this); tableMenu->addAction(deleteTableColumnAction); this->setupShortcut(deleteTableColumnAction, "Edit_Delete_Table_Column"); connect(deleteTableColumnAction, SIGNAL(triggered()), parent, SLOT(deleteTableColumnButtonPressed())); contextMenu->addSeparator(); imageMenu = new QMenu(tr("Image"), this); imageMenu->setFont(global.getGuiFont(font())); contextMenu->addMenu(imageMenu); downloadImageAction()->setText(tr("Save Image")); imageMenu->addAction(downloadImageAction()); // Don't connect this signal. The download attachmen signal will handle it. Otherwise // the signal fires twice. //connect(editorPage, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); imageMenu->addSeparator(); rotateImageLeftAction = new QAction(tr("Rotate Left"), this); imageMenu->addAction(rotateImageLeftAction); this->setupShortcut(rotateImageLeftAction, "Edit_Image_Rotate_Left"); connect(rotateImageLeftAction, SIGNAL(triggered()), parent, SLOT(rotateImageLeftButtonPressed())); rotateImageRightAction = new QAction(tr("Rotate Right"), this); this->setupShortcut(rotateImageRightAction, "Edit_Image_Rotate_Right"); imageMenu->addAction(rotateImageRightAction); connect(rotateImageRightAction, SIGNAL(triggered()), parent, SLOT(rotateImageRightButtonPressed())); contextMenu->addSeparator(); downloadAttachmentAction()->setText(tr("Save Attachment")); contextMenu->addAction(downloadAttachmentAction()); connect(editorPage, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); connect(editorPage, SIGNAL(contentsChanged()), this, SLOT(editAlert())); editorPage->setContentEditable(true); // Set some of the menus as disabled until a user selects an image or attachment downloadAttachmentAction()->setEnabled(false); rotateImageRightAction->setEnabled(false); rotateImageLeftAction->setEnabled(false); openAction->setEnabled(false); downloadImageAction()->setEnabled(false); connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(exposeToJavascript())); //this->setStyleSheet("QWebView,html,body { background-color : red; foreground-color : white; }"); QString qss = global.fileManager.getQssDirPathUser(""); if (qss == "") qss = global.fileManager.getQssDirPath(""); this->settings()->setUserStyleSheetUrl(QUrl("file://"+qss+"editor.css")); }
NWebPage::NWebPage(QWidget *parent) : QWebPage(parent) { connect(this,SIGNAL(contentsChanged()), this, SLOT(editAlert())); mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded); }