Ver código fonte

Small changes

Kandrashin Denis 12 anos atrás
pai
commit
d6c4c70f19
2 arquivos alterados com 71 adições e 17 exclusões
  1. 52 14
      source/fb2head.cpp
  2. 19 3
      source/fb2head.hpp

+ 52 - 14
source/fb2head.cpp

@@ -486,14 +486,15 @@ FbHeadView::FbHeadView(FbTextEdit *view, QWidget *parent)
 
     //setItemDelegate(new QItemDelegate(this));
     setRootIsDecorated(false);
-    setSelectionBehavior(QAbstractItemView::SelectRows);
+    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);
-    connect(actionModify, SIGNAL(triggered()), SLOT(editCurrent()));
+//    connect(this, SIGNAL(activated(QModelIndex)), SLOT(editCurrent(QModelIndex)));
+//    connect(actionModify, SIGNAL(triggered()), SLOT(editCurrent()));
 }
 
 void FbHeadView::initToolbar(QToolBar &toolbar)
@@ -510,15 +511,18 @@ void FbHeadView::updateTree()
     model->expand(this);
 }
 
-void FbHeadView::editCurrent()
+void FbHeadView::editCurrent(const QModelIndex &index)
 {
-    if (!model()) return;
-    QModelIndex current = currentIndex();
-    if (!current.isValid()) return;
-    QModelIndex parent = model()->parent(current);
-    QModelIndex index = model()->index(current.row(), 1, parent);
-    setCurrentIndex(index);
-    edit(index);
+    FbHeadModel * m = qobject_cast<FbHeadModel*>(model());
+    if (!m) return;
+
+    FbHeadItem * item = m->item(index);
+    if (!item) return;
+
+    FbNodeEditDlg dlg(this, item->scheme(), item->element());
+    if (dlg.exec()) {
+        //TODO
+    }
 }
 
 void FbHeadView::activated(const QModelIndex &index)
@@ -576,7 +580,11 @@ void FbHeadView::appendNode()
     FbNodeDlg dlg(this, item->scheme(), list);
     if (dlg.exec()) {
         current = m->append(current, dlg.value());
-        if (current.isValid()) setCurrentIndex(current);
+        if (current.isValid()) {
+            setCurrentIndex(current);
+            scrollTo(current);
+            expand(current);
+        }
     }
 }
 
@@ -594,7 +602,7 @@ QModelIndex FbHeadModel::append(const QModelIndex &parent, const QString &name)
     beginInsertRows(parent, row, row);
     FbHeadItem * item = owner->append(name);
     endInsertRows();
-    return createIndex(row, 0, (void*)item);
+    return createIndex(row, 1, (void*)item);
 }
 
 void FbHeadModel::remove(const QModelIndex &index)
@@ -611,7 +619,7 @@ void FbHeadModel::remove(const QModelIndex &index)
 //  FbNodeDlg
 //---------------------------------------------------------------------------
 
-FbNodeDlg::FbNodeDlg(QWidget *parent, FbScheme scheme, QStringList &list)
+FbNodeDlg::FbNodeDlg(QWidget *parent, const FbScheme &scheme, const QStringList &list)
     : QDialog(parent)
     , m_scheme(scheme)
 {
@@ -620,7 +628,6 @@ FbNodeDlg::FbNodeDlg(QWidget *parent, FbScheme scheme, QStringList &list)
     QGridLayout * layout = new QGridLayout(this);
 
     QLabel * label = new QLabel(this);
-    label->setObjectName(QString::fromUtf8("label"));
     label->setText(tr("Tag name:"));
     layout->addWidget(label, 0, 0, 1, 1);
 
@@ -663,6 +670,37 @@ QString FbNodeDlg::value() const
     return m_combo->currentText();
 }
 
+//---------------------------------------------------------------------------
+//  FbNodeEditDlg
+//---------------------------------------------------------------------------
+
+FbNodeEditDlg::FbNodeEditDlg(QWidget *parent, const FbScheme &scheme, const QWebElement &element)
+    : QDialog(parent)
+    , m_scheme(scheme)
+    , m_element(element)
+{
+    setWindowTitle(tr("Modify tag"));
+
+    QGridLayout * layout = new QGridLayout(this);
+
+    QLabel *label = new QLabel(this);
+    label->setText(tr("Value:"));
+    layout->addWidget(label, 0, 0, 1, 1);
+
+    QLineEdit *edit = new QLineEdit(this);
+    layout->addWidget(edit, 0, 1, 1, 1);
+
+    QDialogButtonBox * buttons = new QDialogButtonBox(this);
+    buttons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+    buttons->setOrientation(Qt::Horizontal);
+    layout->addWidget(buttons, 2, 0, 1, 2);
+
+    layout->setColumnStretch(1, 1);
+
+    connect(buttons, SIGNAL(accepted()), SLOT(accept()));
+    connect(buttons, SIGNAL(rejected()), SLOT(reject()));
+}
+
 //---------------------------------------------------------------------------
 //  FbAuthorDlg
 //---------------------------------------------------------------------------

+ 19 - 3
source/fb2head.hpp

@@ -87,6 +87,10 @@ public:
         return m_parent;
     }
 
+    QWebElement element() const {
+        return m_element;
+    }
+
     QString text(int col = 0) const;
 
     void setText(const QString &text);
@@ -163,7 +167,7 @@ signals:
     void status(const QString &text);
 
 public slots:
-    void editCurrent();
+    void editCurrent(const QModelIndex &index);
     void updateTree();
 
 private slots:
@@ -190,18 +194,30 @@ class FbNodeDlg : public QDialog
     Q_OBJECT
 
 public:
-    explicit FbNodeDlg(QWidget *parent, FbScheme scheme, QStringList &list);
+    explicit FbNodeDlg(QWidget *parent, const FbScheme &scheme, const QStringList &list);
     QString value() const;
 
 private slots:
     void comboChanged(const QString &text);
 
 private:
-    const FbScheme m_scheme;
+    const FbScheme &m_scheme;
     QComboBox * m_combo;
     QLabel * m_text;
 };
 
+class FbNodeEditDlg : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit FbNodeEditDlg(QWidget *parent, const FbScheme &scheme, const QWebElement &element);
+
+private:
+    const FbScheme &m_scheme;
+    QWebElement m_element;
+};
+
 class FbAuthorDlg : public QDialog
 {
     Q_OBJECT