[kde-doc-english] KDE/kdeedu/kwordquiz/src

Peter Hedlund peter at peterandlinda.com
Fri Apr 2 01:07:27 CEST 2010


SVN commit 1110116 by hedlund:

GUI: Extension of the Edit->Clear command adding the ability to delete image and sound links.

 M  +11 -8     CMakeLists.txt  
 A             cleardialogbase.ui  
 M  +1 -0      kwordquiz.cpp  
 M  +16 -0     kwordquiz.kcfg  
 A             kwqcleardialog.cpp   [License: GPL (v2+)]
 A             kwqcleardialog.h   [License: GPL (v2+)]
 M  +13 -8     kwqcommands.cpp  
 M  +2 -0      kwqcommands.h  
 M  +28 -0     kwqtableview.cpp  
 M  +1 -0      kwqtableview.h  


--- trunk/KDE/kdeedu/kwordquiz/src/CMakeLists.txt #1110115:1110116
@@ -1,7 +1,7 @@
 
 add_subdirectory( pics ) # private icons
 add_subdirectory( icons ) # global icons
-add_subdirectory( examples ) 
+add_subdirectory( examples )
 
 include_directories( ${CMAKE_SOURCE_DIR}/libkdeedu/keduvocdocument )
 
@@ -37,21 +37,24 @@
    kwqcardscene.cpp
    kwqcardview.cpp
    kwqquizview.cpp
+   kwqcleardialog.cpp
    )
 
 
 kde4_add_ui_files(kwordquiz_SRCS 
-   columndialogbase.ui 
-   flashviewbase.ui 
-   multipleviewbase.ui 
-   qaviewbase.ui 
-   prefeditorbase.ui 
+   columndialogbase.ui
+   flashviewbase.ui
+   multipleviewbase.ui
+   qaviewbase.ui
+   prefeditorbase.ui
    prefquizbase.ui
    kwqscorewidgetbase.ui
-   prefcharacterbase.ui 
+   prefcharacterbase.ui
    prefcardappearancebase.ui
    prefgeneralbase.ui
-   preftutorbase.ui )
+   preftutorbase.ui
+   cleardialogbase.ui
+   )
 
 kde4_add_kcfg_files(kwordquiz_SRCS prefs.kcfgc documentsettings.kcfgc)
 
--- trunk/KDE/kdeedu/kwordquiz/src/kwordquiz.cpp #1110115:1110116
@@ -183,6 +183,7 @@
   editPaste->setStatusTip(editPaste->whatsThis());
 
   editClear = KStandardAction::clear(this, SLOT(slotEditClear()), actionCollection());
+  editClear->setShortcut(Qt::Key_Delete);
   editClear->setWhatsThis(i18n("Clears the content of the selected cells"));
   editClear->setToolTip(editClear->whatsThis());
   editClear->setStatusTip(editClear->whatsThis());
--- trunk/KDE/kdeedu/kwordquiz/src/kwordquiz.kcfg #1110115:1110116
@@ -60,6 +60,22 @@
       <label>Characters for the special character toolbar</label>
       <default>abcdefghi</default>
     </entry>
+    <entry name="ClearAll" type="Bool">
+      <label>Clear all data in selected entries</label>
+      <default>false</default>
+    </entry>
+    <entry name="ClearText" type="Bool">
+      <label>Clear the text in selected entries</label>
+      <default>true</default>
+    </entry>
+    <entry name="ClearImageLink" type="Bool">
+      <label>Clear the image link in selected entries</label>
+      <default>false</default>
+    </entry>
+    <entry name="ClearSoundLink" type="Bool">
+      <label>Clear the sound link in selected entries</label>
+      <default>false</default>
+    </entry>
   </group>
   <group name="Quiz">
     <entry name="AutoCheck" type="Bool">
--- trunk/KDE/kdeedu/kwordquiz/src/kwqcommands.cpp #1110115:1110116
@@ -55,11 +55,12 @@
   m_view = view;
   m_currentIndex = m_view->selectionModel()->currentIndex();  
   m_selectedIndexes = m_view->selectionModel()->selectedIndexes();
-  foreach (const QModelIndex &index, m_selectedIndexes)
-  {
+  foreach (const QModelIndex &index, m_selectedIndexes) {
     IndexAndData id;
     id.index = index;
     id.data = m_view->model()->data(index, Qt::DisplayRole);
+    id.image = m_view->model()->data(index, KWQTableModel::ImageRole);
+    id.sound = m_view->model()->data(index, KWQTableModel::SoundRole);
     id.height = m_view->rowHeight(index.row());
     m_indexAndData.append(id);
   }
@@ -69,9 +70,10 @@
 void KWQUndoCommand::undo()
 {
   m_view->selectionModel()->clear();
-  foreach (const IndexAndData &id, m_indexAndData)
-  {
+  foreach (const IndexAndData &id, m_indexAndData) {
     m_view->model()->setData(id.index, id.data, Qt::EditRole);
+    m_view->model()->setData(id.index, id.image, KWQTableModel::ImageRole);
+    m_view->model()->setData(id.index, id.sound, KWQTableModel::SoundRole);
     m_view->selectionModel()->select(id.index, QItemSelectionModel::Select);
   }
   m_view->selectionModel()->setCurrentIndex(m_currentIndex, QItemSelectionModel::Current);
@@ -87,11 +89,14 @@
 void KWQCommandClear::redo()
 {
   view()->selectionModel()->clear();
-  foreach (const QModelIndex &index, oldSelectedIndexes())
-  {
-    view()->model()->setData(index, QVariant(), Qt::EditRole);
+  foreach (const QModelIndex &index, oldSelectedIndexes()) {
+    if (Prefs::clearText() || Prefs::clearAll())
+      view()->model()->setData(index, QVariant(), Qt::EditRole);
+    if (Prefs::clearImageLink() || Prefs::clearAll())
+      view()->model()->setData(index, QVariant(), KWQTableModel::ImageRole);
+    if (Prefs::clearSoundLink() || Prefs::clearAll())
+      view()->model()->setData(index, QVariant(), KWQTableModel::SoundRole);
     view()->selectionModel()->select(index, QItemSelectionModel::Select);
-
   }
   view()->selectionModel()->setCurrentIndex(oldCurrentIndex(), QItemSelectionModel::Current);
 }
--- trunk/KDE/kdeedu/kwordquiz/src/kwqcommands.h #1110115:1110116
@@ -33,6 +33,8 @@
 {
   QModelIndex index;
   QVariant data;
+  QVariant image;
+  QVariant sound;
   int height;
 };
 
--- trunk/KDE/kdeedu/kwordquiz/src/kwqtableview.cpp #1110115:1110116
@@ -18,6 +18,7 @@
 #include "kwqtableview.h"
 
 #include <QtCore/QFile>
+#include <QtCore/QPointer>
 #include <QPainter>
 #include <QClipboard>
 #include <QLineEdit>
@@ -46,6 +47,7 @@
 #include "kwordquiz.h"
 #include "prefs.h"
 #include "kwqcommands.h"
+#include "kwqcleardialog.h"
 
 //krazy:excludeall=qclasses
 
@@ -311,6 +313,18 @@
   }
   else
   {
+    if (selectionHasMoreThanText()) {
+      QPointer<KWQClearDialog> clearDialog = new KWQClearDialog(this);
+      if (clearDialog->exec() == KDialog::Rejected)
+        return;
+    }
+    else
+    {
+      Prefs::setClearAll(false);
+      Prefs::setClearText(true);
+      Prefs::setClearImageLink(false);
+      Prefs::setClearSoundLink(false);
+    }
     KWQCommandClear *kwqc = new KWQCommandClear(this);
     m_undoStack->push(kwqc);
   }
@@ -732,4 +746,18 @@
     }
 }
 
+bool KWQTableView::selectionHasMoreThanText()
+{
+  bool result = false;
+  QModelIndexList indexes = selectionModel()->selectedIndexes();
+  foreach (QModelIndex idx, indexes) {
+     result = (!model()->data(idx, KWQTableModel::SoundRole).isNull() ||
+               !model()->data(idx, KWQTableModel::ImageRole).isNull());
+     if (result)
+       break;
+  }
+
+  return result;
+}
+
 #include "kwqtableview.moc"
--- trunk/KDE/kdeedu/kwordquiz/src/kwqtableview.h #1110115:1110116
@@ -83,6 +83,7 @@
 
 private:
   void createPages(QPrinter *, QTextDocument *);
+  bool selectionHasMoreThanText();
 
   QString m_currentText;
 



More information about the kde-doc-english mailing list