[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/kjots
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2010-06-16 14:37:27
Message-ID: 20100616143727.874E4AC8D4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1138707 by skelly:

Return the KJotsLink dialog to its former glory.

including putting the current url in the status bar.

 M  +1 -1      kjotsedit.cpp  
 M  +43 -49    kjotslinkdialog.cpp  
 M  +4 -1      kjotslinkdialog.h  
 M  +20 -0     kjotswidget.cpp  
 M  +13 -0     kjotswidget.h  


--- trunk/KDE/kdepim/kjots/kjotsedit.cpp #1138706:1138707
@@ -264,7 +264,7 @@
 void KJotsEdit::onLinkify ( void )
 {
     selectLinkText();
-    QPointer<KJotsLinkDialog> linkDialog = new KJotsLinkDialog(this);
+    QPointer<KJotsLinkDialog> linkDialog = new KJotsLinkDialog( \
const_cast<QAbstractItemModel *>(m_selectionModel->model()), this);  \
linkDialog->setLinkText(currentLinkText());  \
linkDialog->setLinkUrl(currentLinkUrl());  
--- trunk/KDE/kdepim/kjots/kjotslinkdialog.cpp #1138706:1138707
@@ -30,12 +30,15 @@
 #include <KComboBox>
 #include <KLineEdit>
 
+#include <Akonadi/Item>
+
 #include "KJotsSettings.h"
 #include "kjotsbookshelfentryvalidator.h"
-// #include "kdescendantsproxymodel_p.h"
+#include "kdescendantsproxymodel_p.h"
+#include <Akonadi/EntityTreeModel>
 
-KJotsLinkDialog::KJotsLinkDialog(QWidget *parent) :
-        KDialog(parent)
+KJotsLinkDialog::KJotsLinkDialog( QAbstractItemModel *kjotsModel, QWidget *parent)
+  : KDialog(parent), m_kjotsModel(kjotsModel)
 {
     setCaption(i18n("Manage Link"));
     setButtons(Ok | Cancel);
@@ -43,10 +46,12 @@
     setModal(true);
     showButtonSeparator(true);
 
-//     KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( this );
-//     proxyModel->setSourceModel(  );
-//     proxyModel->setAncestorSeparator( QLatin1String( " / " ) );
+    KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( this );
+    proxyModel->setSourceModel( kjotsModel );
+    proxyModel->setAncestorSeparator( QLatin1String( " / " ) );
 
+    m_descendantsProxyModel = proxyModel;
+
     QWidget *entries = new QWidget(this);
 
     QGridLayout *layout = new QGridLayout(entries);
@@ -60,18 +65,18 @@
     linkUrlLineEdit->setClearButtonShown(true);
 
     tree = new QTreeView();
-//     tree->setModel(proxyModel);
+    tree->setModel(proxyModel);
     tree->expandAll();
     tree->setColumnHidden(1, true);
-//     hrefCombo->setModel(proxyModel);
+    hrefCombo->setModel(proxyModel);
     hrefCombo->setView(tree);
 
     hrefCombo->setEditable(true);
-//     QCompleter *completer = new QCompleter(proxyModel, this);
-//     completer->setCaseSensitivity(Qt::CaseInsensitive);
-//     hrefCombo->setCompleter(completer);
-//     KJotsBookshelfEntryValidator* validator = new KJotsBookshelfEntryValidator( \
                proxyModel, this );
-//     hrefCombo->setValidator( validator );
+    QCompleter *completer = new QCompleter(proxyModel, this);
+    completer->setCaseSensitivity(Qt::CaseInsensitive);
+    hrefCombo->setCompleter(completer);
+    KJotsBookshelfEntryValidator* validator = new KJotsBookshelfEntryValidator( \
proxyModel, this ); +    hrefCombo->setValidator( validator );
 
     QGridLayout* linkLayout = new QGridLayout();
     linkUrlLineEditRadioButton = new QRadioButton(entries);
@@ -111,40 +116,35 @@
 
 void KJotsLinkDialog::setLinkUrl(const QString &linkUrl)
 {
-// TODO PORT
-#if 0
-    if (KJotsEntry::isKJotsLink(linkUrl)) {
+    Akonadi::Item item = Akonadi::Item::fromUrl(KUrl(linkUrl));
+    Akonadi::Collection collection = Akonadi::Collection::fromUrl(KUrl(linkUrl));
 
-        quint64 id = KJotsEntry::idFromLinkUrl(linkUrl);
-        KJotsEntry* item = mBookshelf->entryFromId(id);
-        if ( item ) {
+    if (!item.isValid() && !collection.isValid()) {
+        linkUrlLineEdit->setText(linkUrl);
+        linkUrlLineEditRadioButton->setChecked(true);
+        return;
+    }
 
-            QModelIndex index = hrefCombo->model()->index(0,1);
-            if ( hrefCombo->model()->data(index).toULongLong() == id )
-            {
-                hrefCombo->view()->setCurrentIndex(index);
-                hrefCombo->setCurrentIndex( index.row() );
-            } else {
-                while ( index.sibling(index.row() + 1, 1).isValid() )
-                {
-                    index = index.sibling(index.row() + 1, 1);
+    QModelIndex idx;
 
-                    if ( hrefCombo->model()->data(index).toULongLong() == id )
-                    {
-                        hrefCombo->view()->setCurrentIndex(index);
-                        hrefCombo->setCurrentIndex( index.row() );
-                        break;
+    if (collection.isValid()) {
+        idx = Akonadi::EntityTreeModel::modelIndexForCollection( \
m_descendantsProxyModel, collection ); +    } else if (item.isValid()) {
+        const QModelIndexList list = Akonadi::EntityTreeModel::modelIndexesForItem( \
m_descendantsProxyModel, item ); +        if (list.isEmpty())
+            return;
+
+        idx = list.first();
                     }
-                }
-            }
-        }
+
+    if (!idx.isValid())
+        return;
+
         hrefComboRadioButton->setChecked(true);
-    } else {
-        linkUrlLineEdit->setText(linkUrl);
-        linkUrlLineEditRadioButton->setChecked(true);
+
+    hrefCombo->view()->setCurrentIndex( idx );
+    hrefCombo->setCurrentIndex( idx.row() );
     }
-#endif
-}
 
 QString KJotsLinkDialog::linkText() const
 {
@@ -166,16 +166,10 @@
 
 QString KJotsLinkDialog::linkUrl() const
 {
-  return QString();
-//  TODO PORT
-#if 0
     if (hrefComboRadioButton->isChecked()){
-        QModelIndex index = hrefCombo->view()->currentIndex();
-        index = index.sibling(index.row(), 1);
-        quint64 id = hrefCombo->model()->data(index).toULongLong();
-        return KJotsEntry::kjotsLinkUrlFromId(id);
+        const QModelIndex index = hrefCombo->view()->currentIndex();
+        return index.data(Akonadi::EntityTreeModel::EntityUrlRole).toString();
     } else {
         return linkUrlLineEdit->text();
     }
-#endif
 }
--- trunk/KDE/kdepim/kjots/kjotslinkdialog.h #1138706:1138707
@@ -24,6 +24,7 @@
 #include <KDialog>
 
 class QLabel;
+class QAbstractItemModel;
 class QString;
 class QRadioButton;
 class QTreeView;
@@ -35,7 +36,7 @@
 {
     Q_OBJECT
 public:
-    explicit KJotsLinkDialog(QWidget *parent = 0 );
+    explicit KJotsLinkDialog (QAbstractItemModel *kjotsModel, QWidget *parent = 0 );
 
 
     /**
@@ -74,6 +75,8 @@
         QRadioButton* linkUrlLineEditRadioButton;
         QRadioButton* hrefComboRadioButton;
         QTreeView* tree;
+        QAbstractItemModel *m_kjotsModel;
+        QAbstractItemModel *m_descendantsProxyModel;
 };
 
 #endif
--- trunk/KDE/kdepim/kjots/kjotswidget.cpp #1138706:1138707
@@ -516,6 +516,26 @@
     activeEditor()->setFocus();
 }
 
+void KJotsWidget::currentCharFormatChanged(const QTextCharFormat & fmt)
+{
+    QString selectedAnchor = fmt.anchorHref();
+    if (selectedAnchor != activeAnchor)
+    {
+        activeAnchor = selectedAnchor;
+        if (!selectedAnchor.isEmpty())
+        {
+            QTextCursor c(editor->textCursor());
+            editor->selectLinkText(&c);
+            QString selectedText = c.selectedText();
+            if (!selectedText.isEmpty())
+            {
+              emit activeAnchorChanged(selectedAnchor, selectedText);
+            }
+        } else {
+            emit activeAnchorChanged(QString(), QString());
+        }
+    }
+}
 
 void KJotsWidget::migrateNoteData( const QString &migrator, const QString &type )
 {
--- trunk/KDE/kdepim/kjots/kjotswidget.h #1138706:1138707
@@ -37,6 +37,7 @@
 class QCheckBox;
 class QTextCursor;
 class QTextEdit;
+class QTextCharFormat;
 class QSplitter;
 class QStackedWidget;
 class QModelIndex;
@@ -105,6 +106,14 @@
 
   void captionChanged( const QString &newCaption );
 
+  /**
+    Signals that the text cursor in the editor is now on a different anchor, or not \
on +    an anchor anymore.
+    @param anchorTarget The href of the focused anchor.
+    @param anchorText The display text of the focused anchor.
+  */
+  void activeAnchorChanged(const QString &anchorTarget, const QString &anchorText);
+
 protected:
   QString renderSelectionToHtml();
   QString renderSelectionToXml();
@@ -161,6 +170,8 @@
   void saveState();
   void restoreState();
 
+  void currentCharFormatChanged(const QTextCharFormat &);
+
 private:
   KXMLGUIClient  *m_xmlGuiClient;
   KJotsEdit      *editor;
@@ -175,6 +186,8 @@
   Akonadi::Session *m_session;
   QSplitter *m_splitter;
 
+  QString activeAnchor;
+
   Grantlee::Engine *m_templateEngine;
   Grantlee::FileSystemTemplateLoader::Ptr m_loader;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic