Przeglądaj źródła

Optimize class: Fb2HeadModel

Kandrashin Denis 13 lat temu
rodzic
commit
a868a29f40
3 zmienionych plików z 14 dodań i 19 usunięć
  1. 5 12
      source/fb2head.cpp
  2. 8 5
      source/fb2main.cpp
  3. 1 2
      source/fb2tree.cpp

+ 5 - 12
source/fb2head.cpp

@@ -14,12 +14,6 @@ Fb2HeadItem::Fb2HeadItem(QWebElement &element, Fb2HeadItem *parent)
     m_name = element.tagName().toLower();
     QString style = element.attribute("class").toLower();
     if (m_name == "div") {
-        if (style == "title") {
-            m_text = element.toPlainText().simplified().left(255);
-            if (m_parent) m_parent->m_text += m_text += " ";
-        } else if (style == "subtitle") {
-            m_text = element.toPlainText().simplified().left(255);
-        }
         if (!style.isEmpty()) m_name = style;
     } else if (m_name == "img") {
         m_text = element.attribute("alt");
@@ -41,8 +35,7 @@ void Fb2HeadItem::addChildren(QWebElement &parent)
     while (!child.isNull()) {
         QString tag = child.tagName().toLower();
         if (tag == "div") {
-            QString style = child.attribute("style");
-            if (style != "display:none") m_list << new Fb2HeadItem(child, this);
+            m_list << new Fb2HeadItem(child, this);
         } else if (tag == "img") {
             m_list << new Fb2HeadItem(child, this);
         } else {
@@ -84,9 +77,9 @@ Fb2HeadModel::Fb2HeadModel(QWebView &view, QObject *parent)
     , m_root(NULL)
 {
     QWebElement doc = view.page()->mainFrame()->documentElement();
-    QWebElement body = doc.findFirst("div.description");
-    if (body.isNull()) return;
-    m_root = new Fb2HeadItem(body);
+    QWebElement head = doc.findFirst("div.description");
+    if (head.isNull()) return;
+    m_root = new Fb2HeadItem(head);
 }
 
 Fb2HeadModel::~Fb2HeadModel()
@@ -101,7 +94,7 @@ void Fb2HeadModel::expand(QTreeView *view)
     for (int i = 0; i < count; i++) {
         QModelIndex child = index(i, 0, parent);
         Fb2HeadItem *node = item(child);
-        if (node && node->name() == "body") view->expand(child);
+        if (node) view->expand(child);
     }
 }
 

+ 8 - 5
source/fb2main.cpp

@@ -130,7 +130,7 @@ void Fb2MainWindow::fileNew()
 
 void Fb2MainWindow::fileOpen()
 {
-    QString filename = QFileDialog::getOpenFileName(this);
+    QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), "Fiction book files (*.fb2)");
     if (filename.isEmpty()) return;
 
     Fb2MainWindow * existing = findFb2MainWindow(filename);
@@ -212,6 +212,7 @@ void Fb2MainWindow::createActions()
 
     menu = menuBar()->addMenu(tr("&File"));
     tool = addToolBar(tr("File"));
+    tool->setMovable(false);
 
     act = new QAction(icon("document-new"), tr("&New"), this);
     act->setPriority(QAction::LowPriority);
@@ -257,6 +258,8 @@ void Fb2MainWindow::createActions()
 
     menu = menuBar()->addMenu(tr("&Edit"));
     tool = addToolBar(tr("Edit"));
+    tool->setMovable(false);
+    tool->addSeparator();
 
     connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
 
@@ -302,7 +305,7 @@ void Fb2MainWindow::createActions()
     clipboardDataChanged();
 
     menu = menuBar()->addMenu(tr("Fo&rmat"));
-    tool = addToolBar(tr("Format"));
+    tool->addSeparator();
 
     actionTextBold = act = new QAction(icon("format-text-bold"), tr("Bold"), this);
     act->setShortcuts(QKeySequence::Bold);
@@ -332,6 +335,7 @@ void Fb2MainWindow::createActions()
     tool->addAction(act);
 
     menu = menuBar()->addMenu(tr("&View"));
+    tool->addSeparator();
 
     QActionGroup * viewGroup = new QActionGroup(this);
 
@@ -356,8 +360,6 @@ void Fb2MainWindow::createActions()
 
     menu->addSeparator();
 
-    tool = addToolBar(tr("Zoom"));
-
     actionZoomIn = act = new QAction(icon("zoom-in"), tr("Zoom in"), this);
     act->setShortcuts(QKeySequence::ZoomIn);
     menu->addAction(act);
@@ -409,6 +411,7 @@ void Fb2MainWindow::createTree()
     dockTree->setFeatures(QDockWidget::AllDockWidgetFeatures);
     dockTree->setWidget(treeView);
     addDockWidget(Qt::LeftDockWidgetArea, dockTree);
+    treeView->setFocus();
 }
 
 void Fb2MainWindow::createHead()
@@ -416,10 +419,10 @@ void Fb2MainWindow::createHead()
     if (headTree) return;
     headTree = new QTreeView(this);
     if (textEdit) {
+        this->setFocus();
         textEdit->setParent(NULL);
         setCentralWidget(headTree);
         textEdit->setParent(this);
-
         Fb2HeadModel *model = new Fb2HeadModel(*textEdit, treeView);
         headTree->setModel(model);
         model->expand(headTree);

+ 1 - 2
source/fb2tree.cpp

@@ -40,8 +40,7 @@ void Fb2TreeItem::addChildren(QWebElement &parent)
     while (!child.isNull()) {
         QString tag = child.tagName().toLower();
         if (tag == "div") {
-            QString style = child.attribute("style");
-            if (style != "display:none") m_list << new Fb2TreeItem(child, this);
+            m_list << new Fb2TreeItem(child, this);
         } else if (tag == "img") {
             m_list << new Fb2TreeItem(child, this);
         } else {