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

List:       kde-commits
Subject:    playground/base/nepomuk-kde/simple-file-tagger
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2006-12-15 14:27:29
Message-ID: 1166192849.512279.10436.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 613872 by trueg:

* Use the same shortcuts as the simple-annotator (ESC -> no save, CTRL+Return -> \
                save)
* Properly remember checked tags between tag creation.


 M  +33 -7     mainwindow.cpp  
 M  +3 -1      mainwindow.h  


--- trunk/playground/base/nepomuk-kde/simple-file-tagger/mainwindow.cpp \
#613871:613872 @@ -79,12 +79,16 @@
 }
 
 
-bool MainWindow::load()
+void MainWindow::createTagCheckBoxes()
 {
-  // clear the tag map
+  // save the current checked tags
+  // and clear the tag map
+  QStringList checkedTags;
   QMapIterator<QString, QCheckBox*> it( m_tagCheckBoxes );
   while( it.hasNext() ) {
     it.next();
+    if( it.value()->isChecked() )
+      checkedTags.append( it.key() );
     delete it.value();
   }
   m_tagCheckBoxes.clear();
@@ -100,10 +104,24 @@
     m_tagBox->layout()->addWidget( m_tagCheckBoxes[tag.uri()] );
   }
 
+  // recheck the previously remembered tags
+  QStringListIterator sit( checkedTags );
+  while( sit.hasNext() ) {
+    const QString& tag = sit.next();
+    if( m_tagCheckBoxes.contains( tag ) )
+      m_tagCheckBoxes[tag]->setChecked( true );
+  }
+}
+
+
+bool MainWindow::load()
+{
+  createTagCheckBoxes();
+
   // check the tags the resource is tagged with
-  l = File( m_resource.url() ).getTags();
+  QList<Tag> l = File( m_resource.url() ).getTags();
   qDebug() << "Loading " << l.count() << " tags for resource " << m_resource.url() \
                << endl;
-  tagIt = l;
+  QListIterator<Tag> tagIt( l );
   while( tagIt.hasNext() )
     m_tagCheckBoxes[tagIt.next().uri()]->setChecked( true );
 
@@ -127,9 +145,17 @@
 }
 
 
-bool MainWindow::eventFilter( QObject* obj, QEvent* event )
+void MainWindow::keyPressEvent( QKeyEvent* keyEvent )
 {
-  return QWidget::eventFilter( obj, event );
+  if( ( keyEvent->key() == Qt::Key_Enter ||
+	keyEvent->key() == Qt::Key_Return ) &&
+      keyEvent->modifiers() == Qt::ControlModifier ) {
+    qApp->quit();
+  }
+  else if( keyEvent->key() == Qt::Key_Escape ) {
+    m_bSaveData = false;
+    qApp->quit();
+  }
 }
 
 
@@ -149,7 +175,7 @@
 
     Tag( QString("http://nepomuk-kde.semanticdesktop.org/tags/FIXME_use_a_decent_tag_uri#%1").arg(s) \
).setName( s );  
-    load();
+    createTagCheckBoxes();
   }
 }
 
--- trunk/playground/base/nepomuk-kde/simple-file-tagger/mainwindow.h #613871:613872
@@ -36,11 +36,13 @@
   void addTag();
 
  private:
-  bool eventFilter( QObject* obj, QEvent* event );
+  void keyPressEvent( QKeyEvent* keyEvent );
 
   bool load();
   bool save();
 
+  void createTagCheckBoxes();
+
   Nepomuk::Backbone::Registry* m_registry;
   KUrl m_resource;
   bool m_bSaveData;


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

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