Ver código fonte

Small changes

Kandrashin Denis 12 anos atrás
pai
commit
d078ebcb44
3 arquivos alterados com 63 adições e 36 exclusões
  1. 31 0
      source/fb2dock.cpp
  2. 7 0
      source/fb2dock.hpp
  3. 25 36
      source/fb2main.cpp

+ 31 - 0
source/fb2dock.cpp

@@ -7,6 +7,7 @@
 
 FbMainDock::FbMainDock(QWidget *parent)
     : QStackedWidget(parent)
+    , isSwitched(false)
 {
     textFrame = new FbWebFrame(this);
     m_text = new FbTextEdit(textFrame);
@@ -22,6 +23,23 @@ FbMainDock::FbMainDock(QWidget *parent)
     m_head->setText(m_text);
 }
 
+void FbMainDock::createActions()
+{
+    QAction * act;
+
+    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);
+}
+
 FbMainDock::Mode FbMainDock::mode() const
 {
     QWidget * current = currentWidget();
@@ -55,3 +73,16 @@ bool FbMainDock::load(const QString &filename)
 
     return false;
 }
+
+bool FbMainDock::save(QIODevice *device)
+{
+    if (currentWidget() == m_code) {
+        QTextStream out(device);
+        out << m_code->toPlainText();
+    } else {
+        isSwitched = false;
+        m_text->save(device, codec);
+    }
+    return true;
+}
+

+ 7 - 0
source/fb2dock.hpp

@@ -2,6 +2,7 @@
 #define FB2DOCK_H
 
 #include <QStackedWidget>
+#include <QIODevice>
 
 class FbTextEdit;
 class FbHeadEdit;
@@ -18,6 +19,7 @@ public:
     FbHeadEdit * head() { return m_head; }
     FbCodeEdit * code() { return m_code; }
     bool load(const QString &filename);
+    bool save(QIODevice *device);
     Mode mode() const;
     void setMode(Mode mode);
 
@@ -25,11 +27,16 @@ signals:
     
 public slots:
 
+private slots:
+    void createImgs();
+    void createTree();
+
 private:
     QFrame *textFrame;
     FbTextEdit *m_text;
     FbHeadEdit *m_head;
     FbCodeEdit *m_code;
+    bool isSwitched;
 };
 
 #endif // FB2DOCK_H

+ 25 - 36
source/fb2main.cpp

@@ -185,12 +185,12 @@ void FbMainWindow::about()
 
 void FbMainWindow::documentWasModified()
 {
-    setModified(isSwitched || codeEdit->isModified());
+//    setModified(isSwitched || codeEdit->isModified());
 }
 
 void FbMainWindow::cleanChanged(bool clean)
 {
-    setModified(isSwitched || !clean);
+//    setModified(isSwitched || !clean);
 }
 
 void FbMainWindow::setModified(bool modified)
@@ -508,29 +508,27 @@ void FbMainWindow::openSettings()
 
 void FbMainWindow::createTree()
 {
-    if (textFrame && centralWidget() == textFrame) {
-        dockTree = new FbDockWidget(tr("Contents"), this);
-        dockTree->setWidget(new FbTreeWidget(textFrame->view(), this));
-        connect(dockTree, SIGNAL(visibilityChanged(bool)), actionContents, SLOT(setChecked(bool)));
-        connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
-        addDockWidget(Qt::LeftDockWidgetArea, dockTree);
-    }
+    if (mainDock->mode() != FbMainDock::Text) return;
+    dockTree = new FbDockWidget(tr("Contents"), this);
+    dockTree->setWidget(new FbTreeWidget(mainDock->text(), this));
+    connect(dockTree, SIGNAL(visibilityChanged(bool)), actionContents, SLOT(setChecked(bool)));
+    connect(dockTree, SIGNAL(destroyed()), SLOT(treeDestroyed()));
+    addDockWidget(Qt::LeftDockWidgetArea, dockTree);
 }
 
 void FbMainWindow::createImgs()
 {
-    if (textFrame && centralWidget() == textFrame) {
-        dockImgs = new FbDockWidget(tr("Pictures"), this);
-        dockImgs->setWidget(new FbListWidget(textFrame->view(), this));
-        connect(dockImgs, SIGNAL(visibilityChanged(bool)), actionPictures, SLOT(setChecked(bool)));
-        connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
-        addDockWidget(Qt::RightDockWidgetArea, dockImgs);
-    }
+    if (mainDock->mode() != FbMainDock::Text) return;
+    dockImgs = new FbDockWidget(tr("Pictures"), this);
+    dockImgs->setWidget(new FbListWidget(mainDock->text(), this));
+    connect(dockImgs, SIGNAL(visibilityChanged(bool)), actionPictures, SLOT(setChecked(bool)));
+    connect(dockImgs, SIGNAL(destroyed()), SLOT(imgsDestroyed()));
+    addDockWidget(Qt::RightDockWidgetArea, dockImgs);
 }
 
 void FbMainWindow::selectionChanged()
 {
-    FbTextEdit *view = textFrame->view();
+    FbTextEdit *view = mainDock->text();
     actionCut->setEnabled(view->actionEnabled(QWebPage::Cut));
     actionCopy->setEnabled(view->actionEnabled(QWebPage::Copy));
     statusBar()->showMessage(view->page()->status());
@@ -548,12 +546,12 @@ void FbMainWindow::canRedoChanged(bool canRedo)
 
 void FbMainWindow::undoChanged()
 {
-    actionUndo->setEnabled(textFrame->view()->actionEnabled(QWebPage::Undo));
+    actionUndo->setEnabled(mainDock->text()->actionEnabled(QWebPage::Undo));
 }
 
 void FbMainWindow::redoChanged()
 {
-    actionRedo->setEnabled(textFrame->view()->actionEnabled(QWebPage::Redo));
+    actionRedo->setEnabled(mainDock->text()->actionEnabled(QWebPage::Redo));
 }
 
 void FbMainWindow::createStatusBar()
@@ -579,6 +577,7 @@ void FbMainWindow::writeSettings()
 
 bool FbMainWindow::maybeSave()
 {
+/*
     if (textFrame && textFrame->view()->isModified()) {
         QMessageBox::StandardButton ret;
         ret = QMessageBox::warning(this, qApp->applicationName(),
@@ -591,6 +590,7 @@ bool FbMainWindow::maybeSave()
             return false;
     }
     return true;
+*/  return false;
 }
 
 bool FbMainWindow::saveFile(const QString &fileName, const QString &codec)
@@ -600,22 +600,9 @@ bool FbMainWindow::saveFile(const QString &fileName, const QString &codec)
         QMessageBox::warning(this, qApp->applicationName(), tr("Cannot write file %1: %2.").arg(fileName).arg(file.errorString()));
         return false;
     }
-
-    if (textFrame) {
-        isSwitched = false;
-        textFrame->view()->save(&file, codec);
-        setCurrentFile(fileName);
-        return true;
-    }
-
-    if (codeEdit) {
-        QTextStream out(&file);
-        out << codeEdit->toPlainText();
-        setCurrentFile(fileName);
-        return true;
-    }
-
-    return false;
+    bool ok = mainDock->save(&file);
+    setCurrentFile(fileName);
+    return ok;
 }
 
 void FbMainWindow::setCurrentFile(const QString &filename)
@@ -650,14 +637,16 @@ FbMainWindow *FbMainWindow::findFbMainWindow(const QString &fileName)
 
 void FbMainWindow::checkScintillaUndo()
 {
+/*
     if (!codeEdit) return;
     actionUndo->setEnabled(codeEdit->isUndoAvailable());
     actionRedo->setEnabled(codeEdit->isRedoAvailable());
+*/
 }
 
 void FbMainWindow::createTextToolbar()
 {
-    FbTextEdit * textEdit = textFrame->view();
+    FbTextEdit * textEdit = mainDock->text();
     FbTextPage * textPage = textEdit->page();
 
     connect(textPage->undoStack(), SIGNAL(cleanChanged(bool)), SLOT(cleanChanged(bool)));