123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801 |
- #include <QtGui>
- #include <QtDebug>
- #include <QTreeView>
- #include <QWebFrame>
- #include "fb2main.hpp"
- #include "fb2code.hpp"
- #include "fb2read.hpp"
- #include "fb2save.hpp"
- #include "fb2text.hpp"
- #include "fb2tree.hpp"
- #include "fb2head.hpp"
- #include "fb2utils.h"
- FbMainWindow::FbMainWindow()
- {
- init();
- setCurrentFile();
- viewText();
- textFrame->view.load(":blank.fb2");
- }
- FbMainWindow::FbMainWindow(const QString &filename, ViewMode mode)
- {
- init();
- setCurrentFile(filename);
- if (mode == FB2) {
- viewText();
- textFrame->view.load(filename);
- } else {
- viewCode();
- loadXML(filename);
- }
- }
- void FbMainWindow::init()
- {
- connect(qApp, SIGNAL(logMessage(QString)), SLOT(logMessage(QString)));
- setAttribute(Qt::WA_DeleteOnClose);
- setWindowIcon(QIcon(":icon.ico"));
- isUntitled = true;
- createActions();
- createStatusBar();
- textFrame = NULL;
- noteEdit = NULL;
- codeEdit = NULL;
- headTree = NULL;
- toolEdit = NULL;
- dockTree = NULL;
- messageEdit = NULL;
- readSettings();
- setUnifiedTitleAndToolBarOnMac(true);
- }
- void FbMainWindow::logMessage(const QString &message)
- {
- if (!messageEdit) {
- messageEdit = new QTextEdit(this);
- connect(messageEdit, SIGNAL(destroyed()), SLOT(logDestroyed()));
- QDockWidget * dock = new QDockWidget(tr("Message log"), this);
- dock->setAttribute(Qt::WA_DeleteOnClose);
- dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
- dock->setWidget(messageEdit);
- addDockWidget(Qt::BottomDockWidgetArea, dock);
- messageEdit->setMaximumHeight(80);
- }
- messageEdit->append(message);
- }
- void FbMainWindow::logShowed()
- {
- messageEdit->setMaximumHeight(QWIDGETSIZE_MAX);
- }
- void FbMainWindow::logDestroyed()
- {
- messageEdit = NULL;
- }
- void FbMainWindow::treeDestroyed()
- {
- dockTree = NULL;
- }
- bool FbMainWindow::loadXML(const QString &filename)
- {
- if (!filename.isEmpty()) {
- QFile file(filename);
- if (file.open(QFile::ReadOnly | QFile::Text)) {
- codeEdit->clear();
- return codeEdit->read(&file);
- }
- }
- return false;
- }
- void FbMainWindow::closeEvent(QCloseEvent *event)
- {
- if (maybeSave()) {
- writeSettings();
- event->accept();
- } else {
- event->ignore();
- }
- }
- void FbMainWindow::fileNew()
- {
- FbMainWindow *other = new FbMainWindow;
- other->move(x() + 40, y() + 40);
- other->show();
- }
- void FbMainWindow::fileOpen()
- {
- QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), "Fiction book files (*.fb2)");
- if (filename.isEmpty()) return;
- FbMainWindow * existing = findFbMainWindow(filename);
- if (existing) {
- existing->show();
- existing->raise();
- existing->activateWindow();
- return;
- }
- if (textFrame) {
- if (isUntitled && !isWindowModified()) {
- setCurrentFile(filename);
- textFrame->view.load(filename);
- } else {
- FbMainWindow * other = new FbMainWindow(filename, FB2);
- other->move(x() + 40, y() + 40);
- other->show();
- }
- } else if (codeEdit) {
- if (isUntitled && !isWindowModified()) {
- setCurrentFile(filename);
- loadXML(filename);
- } else {
- FbMainWindow * other = new FbMainWindow(filename, XML);
- other->move(x() + 40, y() + 40);
- other->show();
- }
- }
- }
- bool FbMainWindow::fileSave()
- {
- if (isUntitled) {
- return fileSaveAs();
- } else {
- return saveFile(curFile);
- }
- }
- bool FbMainWindow::fileSaveAs()
- {
- FbSaveDialog dlg(this, tr("Save As..."));
- dlg.selectFile(curFile);
- if (!dlg.exec()) return false;
- QString fileName = dlg.fileName();
- if (fileName.isEmpty()) return false;
- return saveFile(fileName, dlg.codec());
- }
- void FbMainWindow::about()
- {
- QMessageBox::about(this, tr("About fb2edit"),
- tr("The <b>fb2edit</b> is application for editing FB2-files."));
- }
- void FbMainWindow::documentWasModified()
- {
- bool modified = false;
- if (codeEdit) modified = codeEdit->isModified();
- QFileInfo info = windowFilePath();
- QString title = info.fileName();
- if (modified) title += QString("[*]");
- title += appTitle();
- setWindowTitle(title);
- setWindowModified(modified);
- }
- void FbMainWindow::cleanChanged(bool clean)
- {
- QFileInfo info = windowFilePath();
- QString title = info.fileName();
- if (!clean) title += QString("[*]");
- title += appTitle();
- setWindowTitle(title);
- setWindowModified(!clean);
- }
- void FbMainWindow::createActions()
- {
- QAction * act;
- QMenu * menu;
- QToolBar * tool;
- QList<QAction*> actions;
- menu = menuBar()->addMenu(tr("&File"));
- tool = addToolBar(tr("File"));
- tool->setMovable(false);
- act = new QAction(FbIcon("document-new"), tr("&New"), this);
- act->setPriority(QAction::LowPriority);
- act->setShortcuts(QKeySequence::New);
- act->setStatusTip(tr("Create a new file"));
- connect(act, SIGNAL(triggered()), this, SLOT(fileNew()));
- menu->addAction(act);
- tool->addAction(act);
- act = new QAction(FbIcon("document-open"), tr("&Open..."), this);
- act->setShortcuts(QKeySequence::Open);
- act->setStatusTip(tr("Open an existing file"));
- connect(act, SIGNAL(triggered()), this, SLOT(fileOpen()));
- menu->addAction(act);
- tool->addAction(act);
- act = new QAction(FbIcon("document-save"), tr("&Save"), this);
- act->setShortcuts(QKeySequence::Save);
- act->setStatusTip(tr("Save the document to disk"));
- connect(act, SIGNAL(triggered()), this, SLOT(fileSave()));
- menu->addAction(act);
- tool->addAction(act);
- act = new QAction(FbIcon("document-save-as"), tr("Save &As..."), this);
- act->setShortcuts(QKeySequence::SaveAs);
- act->setStatusTip(tr("Save the document under a new name"));
- connect(act, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
- menu->addAction(act);
- menu->addSeparator();
- act = new QAction(FbIcon("window-close"), tr("&Close"), this);
- act->setShortcuts(QKeySequence::Close);
- act->setStatusTip(tr("Close this window"));
- connect(act, SIGNAL(triggered()), this, SLOT(close()));
- menu->addAction(act);
- act = new QAction(FbIcon("application-exit"), tr("E&xit"), this);
- act->setShortcuts(QKeySequence::Quit);
- act->setStatusTip(tr("Exit the application"));
- connect(act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
- menu->addAction(act);
- menuEdit = menu = menuBar()->addMenu(tr("&Edit"));
- connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
- actionUndo = act = new QAction(FbIcon("edit-undo"), tr("&Undo"), this);
- act->setPriority(QAction::LowPriority);
- act->setShortcut(QKeySequence::Undo);
- act->setEnabled(false);
- menu->addAction(act);
- actionRedo = act = new QAction(FbIcon("edit-redo"), tr("&Redo"), this);
- act->setPriority(QAction::LowPriority);
- act->setShortcut(QKeySequence::Redo);
- act->setEnabled(false);
- menu->addAction(act);
- menu->addSeparator();
- actionCut = act = new QAction(FbIcon("edit-cut"), tr("Cu&t"), this);
- act->setShortcutContext(Qt::WidgetShortcut);
- act->setPriority(QAction::LowPriority);
- act->setShortcuts(QKeySequence::Cut);
- act->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
- act->setEnabled(false);
- menu->addAction(act);
- actionCopy = act = new QAction(FbIcon("edit-copy"), tr("&Copy"), this);
- act->setShortcutContext(Qt::WidgetShortcut);
- act->setPriority(QAction::LowPriority);
- act->setShortcuts(QKeySequence::Copy);
- act->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
- act->setEnabled(false);
- menu->addAction(act);
- actionPaste = act = new QAction(FbIcon("edit-paste"), tr("&Paste"), this);
- act->setShortcutContext(Qt::WidgetShortcut);
- act->setPriority(QAction::LowPriority);
- act->setShortcuts(QKeySequence::Paste);
- act->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
- menu->addAction(act);
- clipboardDataChanged();
- menu->addSeparator();
- actionFind = act = new QAction(FbIcon("edit-find"), tr("&Find..."), this);
- act->setShortcuts(QKeySequence::Find);
- menu->addAction(act);
- actionReplace = act = new QAction(FbIcon("edit-find-replace"), tr("&Replace..."), this);
- menu->addAction(act);
- menu->addSeparator();
- act = new QAction(FbIcon("preferences-desktop"), tr("&Settings"), this);
- act->setShortcuts(QKeySequence::Preferences);
- act->setStatusTip(tr("Application settings"));
- connect(act, SIGNAL(triggered()), SLOT(openSettings()));
- menu->addAction(act);
- menu = menuBar()->addMenu(tr("&Insert", "Main menu"));
- actionImage = act = new QAction(FbIcon("insert-image"), tr("&Image"), this);
- menu->addAction(act);
- actionNote = act = new QAction(FbIcon("insert-text"), tr("&Footnote"), this);
- menu->addAction(act);
- actionLink = act = new QAction(FbIcon("insert-link"), tr("&Hiperlink"), this);
- menu->addAction(act);
- menu->addSeparator();
- actionSection = act = new QAction(FbIcon("insert-object"), tr("&Section"), this);
- menu->addAction(act);
- actionTitle = act = new QAction(tr("&Title"), this);
- menu->addAction(act);
- actionEpigraph = act = new QAction(tr("&Epigraph"), this);
- menu->addAction(act);
- actionDescr = act = new QAction(tr("&Annotation"), this);
- menu->addAction(act);
- actionSubtitle = act = new QAction(tr("&Subtitle"), this);
- menu->addAction(act);
- actionAuthor = act = new QAction(tr("&Author"), this);
- menu->addAction(act);
- actionPoem = act = new QAction(tr("&Poem"), this);
- menu->addAction(act);
- actionStanza = act = new QAction(tr("&Stanza"), this);
- menu->addAction(act);
- actionBody = act = new QAction(tr("&Body"), this);
- menu->addAction(act);
- menuText = menu = menuBar()->addMenu(tr("Fo&rmat"));
- actionTextBold = act = new QAction(FbIcon("format-text-bold"), tr("&Bold"), this);
- act->setShortcuts(QKeySequence::Bold);
- act->setCheckable(true);
- menu->addAction(act);
- actionTextItalic = act = new QAction(FbIcon("format-text-italic"), tr("&Italic"), this);
- act->setShortcuts(QKeySequence::Italic);
- act->setCheckable(true);
- menu->addAction(act);
- actionTextStrike = act = new QAction(FbIcon("format-text-strikethrough"), tr("&Strikethrough"), this);
- act->setCheckable(true);
- menu->addAction(act);
- actionTextSup = act = new QAction(FbIcon("format-text-superscript"), tr("Su&perscript"), this);
- act->setCheckable(true);
- menu->addAction(act);
- actionTextSub = act = new QAction(FbIcon("format-text-subscript"), tr("Su&bscript"), this);
- act->setCheckable(true);
- menu->addAction(act);
- menuView = menu = menuBar()->addMenu(tr("&View"));
- tool->addSeparator();
- QActionGroup * viewGroup = new QActionGroup(this);
- act = new QAction(tr("&Text"), this);
- act->setCheckable(true);
- act->setChecked(true);
- connect(act, SIGNAL(triggered()), this, SLOT(viewText()));
- viewGroup->addAction(act);
- menu->addAction(act);
- tool->addAction(act);
- act = new QAction(tr("&Head"), this);
- act->setCheckable(true);
- connect(act, SIGNAL(triggered()), this, SLOT(viewHead()));
- viewGroup->addAction(act);
- menu->addAction(act);
- tool->addAction(act);
- act = new QAction(tr("&XML"), this);
- act->setCheckable(true);
- connect(act, SIGNAL(triggered()), this, SLOT(viewCode()));
- viewGroup->addAction(act);
- menu->addAction(act);
- tool->addAction(act);
- menu->addSeparator();
- actionZoomIn = act = new QAction(FbIcon("zoom-in"), tr("Zoom in"), this);
- act->setShortcuts(QKeySequence::ZoomIn);
- menu->addAction(act);
- actionZoomOut = act = new QAction(FbIcon("zoom-out"), tr("Zoom out"), this);
- act->setShortcuts(QKeySequence::ZoomOut);
- menu->addAction(act);
- actionZoomReset = act = new QAction(FbIcon("zoom-original"), tr("Zoom original"), this);
- menu->addAction(act);
- menu->addSeparator();
- act = new QAction(tr("&Contents"), this);
- connect(act, SIGNAL(triggered()), this, SLOT(viewTree()));
- menu->addAction(act);
- actionInspect = act = new QAction(tr("&Web inspector"), this);
- menu->addAction(act);
- menuBar()->addSeparator();
- menu = menuBar()->addMenu(tr("&Help"));
- act = new QAction(FbIcon("help-about"), tr("&About"), this);
- act->setStatusTip(tr("Show the application's About box"));
- connect(act, SIGNAL(triggered()), this, SLOT(about()));
- menu->addAction(act);
- act = new QAction(tr("About &Qt"), this);
- act->setStatusTip(tr("Show the Qt library's About box"));
- connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
- menu->addAction(act);
- }
- void FbMainWindow::openSettings()
- {
- QMessageBox::about(this, tr("Settings"),
- tr("The <b>fb2edit</b> is application for editing FB2-files."));
- }
- void FbMainWindow::createTree()
- {
- if (textFrame && centralWidget() == textFrame) {
- dockTree = new QDockWidget(tr("Contents"), this);
- dockTree->setAttribute(Qt::WA_DeleteOnClose);
- dockTree->setFeatures(QDockWidget::AllDockWidgetFeatures);
- dockTree->setWidget(new FbTreeWidget(textFrame->view, this));
- connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
- addDockWidget(Qt::LeftDockWidgetArea, dockTree);
- }
- }
- void FbMainWindow::selectionChanged()
- {
- actionCut->setEnabled(textFrame->view.CutEnabled());
- actionCopy->setEnabled(textFrame->view.CopyEnabled());
- actionTextBold->setChecked(textFrame->view.BoldChecked());
- actionTextItalic->setChecked(textFrame->view.ItalicChecked());
- actionTextStrike->setChecked(textFrame->view.StrikeChecked());
- actionTextSub->setChecked(textFrame->view.SubChecked());
- actionTextSup->setChecked(textFrame->view.SupChecked());
- statusBar()->showMessage(textFrame->view.page()->status());
- }
- void FbMainWindow::canUndoChanged(bool canUndo)
- {
- actionUndo->setEnabled(canUndo);
- }
- void FbMainWindow::canRedoChanged(bool canRedo)
- {
- actionRedo->setEnabled(canRedo);
- }
- void FbMainWindow::undoChanged()
- {
- actionUndo->setEnabled(textFrame->view.UndoEnabled());
- }
- void FbMainWindow::redoChanged()
- {
- actionRedo->setEnabled(textFrame->view.RedoEnabled());
- }
- void FbMainWindow::createStatusBar()
- {
- statusBar()->showMessage(tr("Ready"));
- }
- void FbMainWindow::readSettings()
- {
- QSettings settings;
- QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
- QSize size = settings.value("size", QSize(400, 400)).toSize();
- move(pos);
- resize(size);
- }
- void FbMainWindow::writeSettings()
- {
- QSettings settings;
- settings.setValue("pos", pos());
- settings.setValue("size", size());
- }
- bool FbMainWindow::maybeSave()
- {
- if (textFrame && textFrame->view.isModified()) {
- QMessageBox::StandardButton ret;
- ret = QMessageBox::warning(this, qApp->applicationName(),
- tr("The document has been modified. Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard
- | QMessageBox::Cancel);
- if (ret == QMessageBox::Save)
- return fileSave();
- else if (ret == QMessageBox::Cancel)
- return false;
- }
- return true;
- }
- bool FbMainWindow::saveFile(const QString &fileName, const QString &codec)
- {
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, qApp->applicationName(), tr("Cannot write file %1: %2.").arg(fileName).arg(file.errorString()));
- return false;
- }
- if (textFrame) {
- textFrame->view.save(&file, codec);
- setCurrentFile(fileName);
- }
- return true;
- /*
- QTextStream out(&file);
- QApplication::setOverrideCursor(Qt::WaitCursor);
- out << textFrame->view.toPlainText();
- QApplication::restoreOverrideCursor();
- setCurrentFile(fileName);
- statusBar()->showMessage(tr("File saved"), 2000);
- */
- }
- void FbMainWindow::setCurrentFile(const QString &filename)
- {
- static int sequenceNumber = 1;
- QString title;
- isUntitled = filename.isEmpty();
- if (isUntitled) {
- curFile = QString("book%1.fb2").arg(sequenceNumber++);
- title = curFile;
- } else {
- QFileInfo info = filename;
- curFile = info.canonicalFilePath();
- title = info.fileName();
- }
- title += appTitle();
- setWindowModified(false);
- setWindowFilePath(curFile);
- setWindowTitle(title);
- }
- QString FbMainWindow::appTitle() const
- {
- return QString(" - ") += qApp->applicationName() += QString(" ") += qApp->applicationVersion();
- }
- FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
- {
- QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
- foreach (QWidget *widget, qApp->topLevelWidgets()) {
- FbMainWindow *mainWin = qobject_cast<FbMainWindow *>(widget);
- if (mainWin && mainWin->curFile == canonicalFilePath)
- return mainWin;
- }
- return 0;
- }
- void FbMainWindow::checkScintillaUndo()
- {
- if (!codeEdit) return;
- actionUndo->setEnabled(codeEdit->isUndoAvailable());
- actionRedo->setEnabled(codeEdit->isRedoAvailable());
- }
- void FbMainWindow::viewCode()
- {
- if (codeEdit && centralWidget() == codeEdit) return;
- bool load = false;
- QByteArray xml;
- QList<int> folds;
- if (textFrame) {
- textFrame->view.save(&xml);
- load = true;
- }
- FB2DELETE(textFrame);
- FB2DELETE(dockTree);
- FB2DELETE(headTree);
- if (!codeEdit) {
- codeEdit = new FbCodeEdit;
- }
- if (load) codeEdit->load(xml, folds);
- setCentralWidget(codeEdit);
- codeEdit->setFocus();
- FB2DELETE(toolEdit);
- QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
- tool->addSeparator();
- tool->addAction(actionUndo);
- tool->addAction(actionRedo);
- tool->addSeparator();
- tool->addAction(actionCut);
- tool->addAction(actionCopy);
- tool->addAction(actionPaste);
- tool->addSeparator();
- tool->addAction(actionZoomIn);
- tool->addAction(actionZoomOut);
- tool->addAction(actionZoomReset);
- tool->setMovable(false);
- connect(codeEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
- connect(codeEdit, SIGNAL(textChanged()), this, SLOT(checkScintillaUndo()));
- connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
- connect(codeEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
- connect(actionUndo, SIGNAL(triggered()), codeEdit, SLOT(undo()));
- connect(actionRedo, SIGNAL(triggered()), codeEdit, SLOT(redo()));
- connect(actionCut, SIGNAL(triggered()), codeEdit, SLOT(cut()));
- connect(actionCopy, SIGNAL(triggered()), codeEdit, SLOT(copy()));
- connect(actionPaste, SIGNAL(triggered()), codeEdit, SLOT(paste()));
- connect(actionFind, SIGNAL(triggered()), codeEdit, SLOT(find()));
- connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
- connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
- connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
- }
- void FbMainWindow::viewText()
- {
- if (textFrame && centralWidget() == textFrame) return;
- QString xml;
- if (codeEdit) xml = codeEdit->text();
- FB2DELETE(codeEdit);
- FB2DELETE(headTree);
- if (!textFrame) {
- textFrame = new FbTextFrame(this);
- }
- setCentralWidget(textFrame);
- textFrame->view.setFocus();
- viewTree();
- connect(textFrame->view.page()->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));
- connect(textFrame->view.page()->undoStack(), SIGNAL(canUndoChanged(bool)), SLOT(canUndoChanged(bool)));
- connect(textFrame->view.page()->undoStack(), SIGNAL(canRedoChanged(bool)), SLOT(canRedoChanged(bool)));
- connect(textFrame->view.page(), SIGNAL(selectionChanged()), SLOT(selectionChanged()));
- connect(textFrame->view.pageAction(QWebPage::Undo), SIGNAL(changed()), SLOT(undoChanged()));
- connect(textFrame->view.pageAction(QWebPage::Redo), SIGNAL(changed()), SLOT(redoChanged()));
- connect(actionUndo, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::Undo), SIGNAL(triggered()));
- connect(actionRedo, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::Redo), SIGNAL(triggered()));
- connect(actionCut, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::Cut), SIGNAL(triggered()));
- connect(actionCopy, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::Copy), SIGNAL(triggered()));
- connect(actionPaste, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::Paste), SIGNAL(triggered()));
- connect(actionTextBold, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::ToggleBold), SIGNAL(triggered()));
- connect(actionTextItalic, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::ToggleItalic), SIGNAL(triggered()));
- connect(actionTextStrike, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::ToggleStrikethrough), SIGNAL(triggered()));
- connect(actionTextSub, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::ToggleSubscript), SIGNAL(triggered()));
- connect(actionTextSup, SIGNAL(triggered()), textFrame->view.pageAction(QWebPage::ToggleSuperscript), SIGNAL(triggered()));
- FbTextEdit * textEdit = &(textFrame->view);
- connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
- connect(actionImage, SIGNAL(triggered()), textEdit, SLOT(insertImage()));
- connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
- connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
- FbTextPage * textPage = textEdit->page();
- connect(actionTitle, SIGNAL(triggered()), textPage, SLOT(insertTitle()));
- connect(actionSubtitle, SIGNAL(triggered()), textPage, SLOT(insertSubtitle()));
- connect(actionSection, SIGNAL(triggered()), textPage, SLOT(insertSection()));
- connect(actionBody, SIGNAL(triggered()), textPage, SLOT(insertBody()));
- connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
- connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
- connect(actionZoomReset, SIGNAL(triggered()), textEdit, SLOT(zoomReset()));
- connect(actionInspect, SIGNAL(triggered()), textFrame, SLOT(showInspector()));
- if (!xml.isEmpty()) textFrame->view.load(curFile, xml);
- FB2DELETE(toolEdit);
- QToolBar *tool = toolEdit = addToolBar(tr("Edit"));
- tool->setMovable(false);
- tool->addSeparator();
- textEdit->addTools(tool);
- tool->addSeparator();
- tool->addAction(actionImage);
- tool->addAction(actionNote);
- tool->addAction(actionLink);
- tool->addAction(actionSection);
- tool->addSeparator();
- tool->addAction(actionZoomIn);
- tool->addAction(actionZoomOut);
- tool->addAction(actionZoomReset);
- }
- void FbMainWindow::viewHead()
- {
- if (headTree && centralWidget() == headTree) return;
- if (textFrame) textFrame->hideInspector();
- QString xml;
- if (codeEdit) xml = codeEdit->text();
- FB2DELETE(dockTree);
- FB2DELETE(codeEdit);
- FB2DELETE(toolEdit);
- if (!textFrame) {
- textFrame = new FbTextFrame(this);
- }
- if (!headTree) {
- headTree = new FbHeadView(textFrame->view, this);
- connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
- }
- this->setFocus();
- textFrame->setParent(NULL);
- setCentralWidget(headTree);
- textFrame->setParent(this);
- headTree->updateTree();
- headTree->setFocus();
- if (!xml.isEmpty()) textFrame->view.load(curFile, xml);
- if (textFrame) {
- actionUndo->disconnect();
- actionRedo->disconnect();
- actionCut->disconnect();
- actionCopy->disconnect();
- actionPaste->disconnect();
- actionTextBold->disconnect();
- actionTextItalic->disconnect();
- actionTextStrike->disconnect();
- actionTextSub->disconnect();
- actionTextSup->disconnect();
- }
- FB2DELETE(toolEdit);
- toolEdit = addToolBar(tr("Edit"));
- headTree->initToolbar(*toolEdit);
- toolEdit->addSeparator();
- toolEdit->setMovable(false);
- }
- void FbMainWindow::viewTree()
- {
- if (dockTree) dockTree->deleteLater(); else createTree();
- }
- void FbMainWindow::clipboardDataChanged()
- {
- if (const QMimeData *md = QApplication::clipboard()->mimeData()) {
- actionPaste->setEnabled(md->hasText());
- }
- }
- void FbMainWindow::status(const QString &text)
- {
- statusBar()->showMessage(text);
- }
|