Browse Source

Create new class: FbMainDock

Kandrashin Denis 12 năm trước cách đây
mục cha
commit
89beb03e36
11 tập tin đã thay đổi với 163 bổ sung102 xóa
  1. 2 3
      CMakeLists.txt
  2. 72 70
      fb2edit.pro
  3. 26 0
      source/fb2dock.cpp
  4. 34 0
      source/fb2dock.hpp
  5. 17 14
      source/fb2head.cpp
  6. 4 3
      source/fb2head.hpp
  7. 2 1
      source/fb2main.cpp
  8. 2 2
      source/fb2main.hpp
  9. 3 1
      source/fb2temp.cpp
  10. 1 2
      source/fb2text.cpp
  11. 0 6
      source/fb2text.hpp

+ 2 - 3
CMakeLists.txt

@@ -28,7 +28,8 @@ file( GLOB FB2_SRCS source/*.cpp     )
 file( GLOB FB2_UIS  source/*.ui      )
 file( GLOB FB2_TSS  source/ts/*.ts   )
 
-set(FB2_DEFINITIONS "PACKAGE_NAME=\"${PACKAGE_NAME}\"; PACKAGE_VENDOR=\"${PACKAGE_VENDOR}\"; PACKAGE_VERSION=\"${PACKAGE_VERSION}\"")
+set(PACKAGE_COMMIT `log --pretty=format:'%ai | %H | %d' --abbrev-commit -1`)
+set(FB2_DEFINITIONS "PACKAGE_NAME=\"${PACKAGE_NAME}\"; PACKAGE_VENDOR=\"${PACKAGE_VENDOR}\"; PACKAGE_VERSION=\"${PACKAGE_VERSION}\"; PACKAGE_COMMIT=\"${PACKAGE_COMMIT}\"")
 set_source_files_properties( source/fb2app.cpp PROPERTIES COMPILE_DEFINITIONS "${FB2_DEFINITIONS}")
 
 set(FB2_RES
@@ -79,5 +80,3 @@ if( UNIX AND NOT APPLE )
     install( CODE "FILE(MAKE_DIRECTORY WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/share/pixmaps/)" )
     install( CODE "EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E create_symlink ../icons/hicolor/48x48/apps/fb2edit.png fb2edit.png WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/share/pixmaps)" )
 endif()
-
-

+ 72 - 70
fb2edit.pro

@@ -1,70 +1,72 @@
-HEADERS = \
-    source/fb2xml.h \
-    source/fb2xml2.h \
-    source/fb2app.hpp \
-    source/fb2code.hpp \
-    source/fb2head.hpp \
-    source/fb2main.hpp \
-    source/fb2read.hpp \
-    source/fb2temp.hpp \
-    source/fb2tree.hpp \
-    source/fb2save.hpp \
-    source/fb2dlgs.hpp \
-    source/fb2html.h \
-    source/fb2text.hpp \
-    source/fb2utils.h
-
-SOURCES = \
-    source/fb2app.cpp \
-    source/fb2code.cpp \
-    source/fb2head.cpp \
-    source/fb2main.cpp \
-    source/fb2read.cpp \
-    source/fb2save.cpp \
-    source/fb2temp.cpp \
-    source/fb2tree.cpp \
-    source/fb2xml.cpp \
-    source/fb2xml2.cpp \
-    source/fb2utils.cpp \
-    source/fb2dlgs.cpp \
-    source/fb2html.cpp \
-    source/fb2text.cpp
-
-RESOURCES = \
-    3rdparty/gnome/gnome.qrc \
-    source/res/fb2edit.qrc \
-    source/js/javascript.qrc \
-    3rdparty/fb2/fb2.qrc
-
-TARGET = fb2edit
-
-TRANSLATIONS = source/ts/ru.ts
-
-QT += xml
-QT += webkit
-QT += network
-
-OTHER_FILES += \
-    source/res/style.css \
-    source/res/blank.fb2 \
-    source/js/export.js \
-    source/js/set_cursor.js \
-    source/js/get_status.js \
-    source/js/insert_title.js \
-    CMakeLists.txt \
-    source/js/new_section1.js \
-    source/js/section_get.js \
-    source/js/section_new.js \
-    source/js/location.js
-
-if (unix) {
-
-    DEFINES += FB2_USE_LIBXML2
-    INCLUDEPATH += /usr/include/libxml2
-    LIBS += -lxml2
-
-}
-
-FORMS += \
-    source/fb2find.ui \
-    source/fb2setup.ui
+HEADERS = \
+    source/fb2xml.h \
+    source/fb2xml2.h \
+    source/fb2app.hpp \
+    source/fb2code.hpp \
+    source/fb2head.hpp \
+    source/fb2main.hpp \
+    source/fb2read.hpp \
+    source/fb2temp.hpp \
+    source/fb2tree.hpp \
+    source/fb2save.hpp \
+    source/fb2dlgs.hpp \
+    source/fb2html.h \
+    source/fb2text.hpp \
+    source/fb2utils.h \
+    source/fb2dock.hpp
+
+SOURCES = \
+    source/fb2app.cpp \
+    source/fb2code.cpp \
+    source/fb2head.cpp \
+    source/fb2main.cpp \
+    source/fb2read.cpp \
+    source/fb2save.cpp \
+    source/fb2temp.cpp \
+    source/fb2tree.cpp \
+    source/fb2xml.cpp \
+    source/fb2xml2.cpp \
+    source/fb2utils.cpp \
+    source/fb2dlgs.cpp \
+    source/fb2html.cpp \
+    source/fb2text.cpp \
+    source/fb2dock.cpp
+
+RESOURCES = \
+    3rdparty/gnome/gnome.qrc \
+    source/res/fb2edit.qrc \
+    source/js/javascript.qrc \
+    3rdparty/fb2/fb2.qrc
+
+TARGET = fb2edit
+
+TRANSLATIONS = source/ts/ru.ts
+
+QT += xml
+QT += webkit
+QT += network
+
+OTHER_FILES += \
+    source/res/style.css \
+    source/res/blank.fb2 \
+    source/js/export.js \
+    source/js/set_cursor.js \
+    source/js/get_status.js \
+    source/js/insert_title.js \
+    CMakeLists.txt \
+    source/js/new_section1.js \
+    source/js/section_get.js \
+    source/js/section_new.js \
+    source/js/location.js
+
+if (unix) {
+
+    DEFINES += FB2_USE_LIBXML2
+    INCLUDEPATH += /usr/include/libxml2
+    LIBS += -lxml2
+
+}
+
+FORMS += \
+    source/fb2find.ui \
+    source/fb2setup.ui

+ 26 - 0
source/fb2dock.cpp

@@ -0,0 +1,26 @@
+#include "fb2dock.hpp"
+#include "fb2code.hpp"
+#include "fb2head.hpp"
+#include "fb2text.hpp"
+
+FbMainDock::FbMainDock(QWidget *parent)
+    : QStackedWidget(parent)
+{
+    addWidget(m_text = new FbTextEdit(this));
+    addWidget(m_head = new FbHeadEdit(this));
+    addWidget(m_code = new FbCodeEdit(this));
+    m_head->setText(m_text);
+}
+
+FbMainDock::Mode FbMainDock::mode() const
+{
+    QWidget * current = currentWidget();
+    if (current == m_text) return Text;
+    if (current == m_head) return Head;
+    if (current == m_code) return Code;
+    return Text;
+}
+
+void FbMainDock::setMode(Mode mode)
+{
+}

+ 34 - 0
source/fb2dock.hpp

@@ -0,0 +1,34 @@
+#ifndef FB2DOCK_H
+#define FB2DOCK_H
+
+#include <QStackedWidget>
+
+class FbTextEdit;
+class FbHeadEdit;
+class FbCodeEdit;
+
+class FbMainDock : public QStackedWidget
+{
+    Q_OBJECT
+
+public:
+    enum Mode { Text = 0, Head, Code };
+    explicit FbMainDock(QWidget *parent = 0);
+    FbTextEdit * text() { return m_text; }
+    FbHeadEdit * head() { return m_head; }
+    FbCodeEdit * code() { return m_code; }
+
+    Mode mode() const;
+    void setMode(Mode mode);
+
+signals:
+    
+public slots:
+
+private:
+    FbTextEdit *m_text;
+    FbHeadEdit *m_head;
+    FbCodeEdit *m_code;
+};
+
+#endif // FB2DOCK_H

+ 17 - 14
source/fb2head.cpp

@@ -554,9 +554,8 @@ bool FbHeadModel::canEdit(const QModelIndex &index) const
 //  FbTreeView
 //---------------------------------------------------------------------------
 
-FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
+FbHeadEdit::FbHeadEdit(QWidget *parent)
     : QTreeView(parent)
-    , m_view(*view)
 {
     QAction * act;
 
@@ -584,33 +583,37 @@ FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
     setRootIsDecorated(false);
     setSelectionBehavior(QAbstractItemView::SelectItems);
     setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
-    connect(&m_view, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
     connect(this, SIGNAL(activated(QModelIndex)), SLOT(activated(QModelIndex)));
     connect(this, SIGNAL(collapsed(QModelIndex)), SLOT(collapsed(QModelIndex)));
 
     header()->setDefaultSectionSize(200);
 }
 
-FbHeadModel * FbHeadView::model() const
+void FbHeadEdit::setText(FbTextEdit *text)
+{
+    connect(m_text = text, SIGNAL(loadFinished(bool)), SLOT(updateTree()));
+}
+
+FbHeadModel * FbHeadEdit::model() const
 {
     return qobject_cast<FbHeadModel*>(QTreeView::model());
 }
 
-void FbHeadView::initToolbar(QToolBar &toolbar)
+void FbHeadEdit::initToolbar(QToolBar &toolbar)
 {
     toolbar.addSeparator();
     toolbar.addAction(actionInsert);
     toolbar.addAction(actionDelete);
 }
 
-void FbHeadView::updateTree()
+void FbHeadEdit::updateTree()
 {
-    FbHeadModel * model = new FbHeadModel(m_view, this);
+    FbHeadModel * model = new FbHeadModel(*m_text, this);
     setModel(model);
     model->expand(this);
 }
 
-void FbHeadView::editCurrent(const QModelIndex &index)
+void FbHeadEdit::editCurrent(const QModelIndex &index)
 {
     FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
     if (!m) return;
@@ -624,19 +627,19 @@ void FbHeadView::editCurrent(const QModelIndex &index)
     }
 }
 
-void FbHeadView::activated(const QModelIndex &index)
+void FbHeadEdit::activated(const QModelIndex &index)
 {
     if (model()->canEdit(index)) edit(index);
     showStatus(index);
 }
 
-void FbHeadView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
+void FbHeadEdit::currentChanged(const QModelIndex &current, const QModelIndex &previous)
 {
     QTreeView::currentChanged(current, previous);
     showStatus(current);
 }
 
-void FbHeadView::showStatus(const QModelIndex &current)
+void FbHeadEdit::showStatus(const QModelIndex &current)
 {
     if (!model()) return;
     if (!current.isValid()) return;
@@ -645,14 +648,14 @@ void FbHeadView::showStatus(const QModelIndex &current)
     emit status(model()->data(index).toString());
 }
 
-void FbHeadView::collapsed(const QModelIndex &index)
+void FbHeadEdit::collapsed(const QModelIndex &index)
 {
     if (model() && !model()->parent(index).isValid()) {
         expand(index);
     }
 }
 
-void FbHeadView::appendNode()
+void FbHeadEdit::appendNode()
 {
     FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
     if (!m) return;
@@ -687,7 +690,7 @@ void FbHeadView::appendNode()
     }
 }
 
-void FbHeadView::removeNode()
+void FbHeadEdit::removeNode()
 {
     FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
     if (m) m->remove(currentIndex());

+ 4 - 3
source/fb2head.hpp

@@ -163,12 +163,13 @@ private:
     FbHeadItem * m_root;
 };
 
-class FbHeadView : public QTreeView
+class FbHeadEdit : public QTreeView
 {
     Q_OBJECT
 
 public:
-    explicit FbHeadView(FbTextEdit *view, QWidget *parent = 0);
+    explicit FbHeadEdit(QWidget *parent = 0);
+    void setText(FbTextEdit *text);
     void initToolbar(QToolBar &toolbar);
     FbHeadModel * model() const;
 
@@ -192,7 +193,7 @@ private:
     void showStatus(const QModelIndex &current);
 
 private:
-    FbTextEdit & m_view;
+    FbTextEdit * m_text;
     QAction * actionInsert;
     QAction * actionModify;
     QAction * actionDelete;

+ 2 - 1
source/fb2main.cpp

@@ -849,7 +849,8 @@ void FbMainWindow::viewHead()
     }
 
     if (!headTree) {
-        headTree = new FbHeadView(textFrame->view(), this);
+        headTree = new FbHeadEdit(this);
+        headTree->setText(textFrame->view());
         connect(headTree, SIGNAL(status(QString)), this, SLOT(status(QString)));
     }
 

+ 2 - 2
source/fb2main.hpp

@@ -16,7 +16,7 @@ QT_END_NAMESPACE
 
 class FbCodeEdit;
 class FbTreeView;
-class FbHeadView;
+class FbHeadEdit;
 class FbTextEdit;
 class FbTextFrame;
 class FbTextPage;
@@ -114,7 +114,7 @@ private:
 
     FbTextFrame *textFrame;
     FbCodeEdit *codeEdit;
-    FbHeadView *headTree;
+    FbHeadEdit *headTree;
     QTextEdit *noteEdit;
     QToolBar *toolEdit;
     QDockWidget *dockTree;

+ 3 - 1
source/fb2temp.cpp

@@ -349,7 +349,9 @@ FbListWidget::FbListWidget(FbTextEdit *text, QWidget* parent)
 
     FbWebFrame *frame = new FbWebFrame(splitter);
     splitter->addWidget(frame);
-    m_view = frame->view();
+
+    m_view = new FbTextBase(frame);
+    frame->layout()->addWidget(m_view);
 
     splitter->setSizes(QList<int>() << 100 << 100);
 

+ 1 - 2
source/fb2text.cpp

@@ -806,7 +806,6 @@ void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
 
 FbWebFrame::FbWebFrame(QWidget *parent)
     : QFrame(parent)
-    , m_view(this)
 {
     setFrameShape(QFrame::StyledPanel);
     setFrameShadow(QFrame::Sunken);
@@ -814,7 +813,7 @@ FbWebFrame::FbWebFrame(QWidget *parent)
     QLayout * layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
     layout->setSpacing(0);
     layout->setMargin(0);
-    layout->addWidget(&m_view);
+    setLayout(layout);
 }
 
 //---------------------------------------------------------------------------

+ 0 - 6
source/fb2text.hpp

@@ -188,14 +188,8 @@ private:
 class FbWebFrame : public QFrame
 {
     Q_OBJECT
-
 public:
     explicit FbWebFrame(QWidget *parent = 0);
-
-    QWebView * view() { return &m_view; }
-
-private:
-    QWebView m_view;
 };
 
 class FbTextFrame : public QFrame