]> git.lyx.org Git - lyx.git/commitdiff
more cleanup:
authorEdwin Leuven <e.leuven@gmail.com>
Fri, 15 Dec 2006 09:58:44 +0000 (09:58 +0000)
committerEdwin Leuven <e.leuven@gmail.com>
Fri, 15 Dec 2006 09:58:44 +0000 (09:58 +0000)
 - clear selected keys on ok/cancel
 - update info when navigating with keyboard
 - add clear search button
 - don't allow search strings that return empty selection

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16277 a592a061-630c-0410-9148-cb99ea01b6c8

Status.15x
src/frontends/qt4/QCitation.C
src/frontends/qt4/QCitation.h
src/frontends/qt4/QCitationDialog.C
src/frontends/qt4/QCitationDialog.h
src/frontends/qt4/ui/QCitationUi.ui

index 767895eb842bef144a7076d8494c283131fc80d9..2324c68c3d12a24ee4ce5f6c0d4433877881f384 100644 (file)
@@ -92,14 +92,6 @@ DIALOGS
 * If you try to view a document as postscript that cannot be typeset because
   of LaTeX errors and export to LaTeX afterwards you will get the old error
   list again, although the export succeded.
-  
-* Citation dialog: Create some citation; open the citation dialog a second time for
-  another new citation => the selected entry from the first citations is
-  already selected for the second citation (which is wrong)
-
-* Citation dialog: If you use the cursor up/down keys to browse through the
-  list of available citations, the "preview" (in the middle of the dialog)
-  is not updated
 
 
 MATH CONTROL PANEL
index dbd5d7333d96a60c1b672dfb7993ab95a9b400f8..d9dba70a581deedaa75a42a19c599d979cfa7826 100644 (file)
@@ -56,7 +56,7 @@ QCitation::QCitation(Dialog & parent)
 void QCitation::apply(int const choice, bool const full, bool const force,
                       QString before, QString after)
 {
-       if (!isValid())
+       if (selected_keys_.rowCount() == 0)
                return;
 
        vector<biblio::CiteStyle> const & styles =
@@ -74,6 +74,12 @@ void QCitation::apply(int const choice, bool const full, bool const force,
 }
 
 
+void QCitation::clearSelection()
+{
+       selected_keys_.setStringList(QStringList());
+}
+
+       
 QString QCitation::textBefore()
 {
        return toqstr(params()["before"]);
@@ -101,12 +107,6 @@ void QCitation::updateModel()
 }
 
 
-bool QCitation::isValid()
-{
-       return selected_keys_.rowCount() > 0;
-}
-
-
 void QCitation::findKey(QString const & str)
 {
        QStringList sl = available_keys_.stringList().filter(str, Qt::CaseInsensitive);
index c6131713ff5752c1de9ab72c9512c82a5293175d..92948ff272d6a7c1c7ba021419a80d3155530db0 100644 (file)
@@ -43,6 +43,9 @@ public:
        /// Get key description
        QString getKeyInfo(QString const &);
 
+       /// Clear selected keys
+       void clearSelection();
+
        /// Find keys containing the string (not case-sens)
        void findKey(QString const &);
 
@@ -61,9 +64,6 @@ public:
        /// List of example cite strings
        QStringList citationStyles(int);
 
-       /// Check whether there are keys to select
-       virtual bool isValid();
-
        /// Set the Params variable for the Controller.
        virtual void apply(int const choice, bool const full, bool const force,
                                          QString before, QString after);
index abf88739d7d90923bbdf05bb3b50dc37d9657fed..d10365ae9c0e8ef8767ec72be83fa94e5ad0b536 100644 (file)
@@ -57,6 +57,14 @@ QCitationDialog::QCitationDialog(Dialog & dialog, QCitation * form)
                this, SLOT(changed()));
     connect(textAfterED, SIGNAL(textChanged(const QString&)),
                this, SLOT(changed()));
+    connect(clearPB, SIGNAL(clicked()),
+               findLE, SLOT(clear()));
+       connect(availableLV->selectionModel(),
+               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+               this, SLOT(availableChanged(const QModelIndex &, const QModelIndex &)));
+       connect(selectedLV->selectionModel(),
+               SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+               this, SLOT(selectedChanged(const QModelIndex &, const QModelIndex &)));
 }
 
 
@@ -100,12 +108,14 @@ bool QCitationDialog::isVisible() const
 void QCitationDialog::on_okPB_clicked()
 {
        apply();
+       form_->clearSelection();
        accept();
 }
 
 
 void QCitationDialog::on_cancelPB_clicked()
 {
+       form_->clearSelection();
        accept();
 }
 
@@ -126,12 +136,12 @@ void QCitationDialog::update()
 {
        form_->updateModel();
 
-       QModelIndex idxa = availableLV->currentIndex();
-       if (!idxa.isValid())
+       QModelIndex const idxa = availableLV->currentIndex();
+       if (form_->available()->rowCount() > 0 && !idxa.isValid())
                availableLV->setCurrentIndex(availableLV->model()->index(0,0));
 
-       QModelIndex idx = selectedLV->currentIndex();
-       if (form_->isValid() && !idx.isValid()) {
+       QModelIndex const idx = selectedLV->currentIndex();
+       if (form_->selected()->rowCount() > 0 && !idx.isValid()) {
                selectedLV->setCurrentIndex(selectedLV->model()->index(0,0));
                updateInfo(selectedLV->currentIndex());
        } else
@@ -158,6 +168,7 @@ void QCitationDialog::updateStyle()
        fulllistCB->setEnabled(natbib_engine);
        forceuppercaseCB->setEnabled(natbib_engine);
        textBeforeED->setEnabled(!basic_engine);
+       textBeforeLA->setEnabled(!basic_engine);
 
        string const & command = form_->params().getCmdName();
 
@@ -200,10 +211,12 @@ void QCitationDialog::fillStyles()
                return;
        }
 
-       if (selectedLV->selectionModel()->selectedIndexes().empty())
+       int curr = selectedLV->model()->rowCount() - 1;
+       if (curr < 0)
                return;
-       
-       int curr = selectedLV->selectionModel()->selectedIndexes()[0].row();//selectedLV->currentItem();
+
+       if (!selectedLV->selectionModel()->selectedIndexes().empty())
+               curr = selectedLV->selectionModel()->selectedIndexes()[0].row();
 
        QStringList sty = form_->citationStyles(curr);
 
@@ -213,6 +226,9 @@ void QCitationDialog::fillStyles()
        citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
        citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
 
+       if (sty.isEmpty() || basic_engine)
+               return;
+
        citationStyleCO->insertItems(0, sty);
 
        if (orig != -1 && orig < citationStyleCO->count())
@@ -254,12 +270,37 @@ void QCitationDialog::updateInfo(const QModelIndex & idx)
 
 void QCitationDialog::on_selectedLV_clicked(const QModelIndex & idx)
 {
+       availableLV->selectionModel()->clear();
+
+       updateInfo(idx);
+       changed();
+}
+
+
+void QCitationDialog::selectedChanged(const QModelIndex & idx, const QModelIndex &)
+{
+       if (!idx.isValid())
+               return;
+
        updateInfo(idx);
        changed();
 }
 
+
 void QCitationDialog::on_availableLV_clicked(const QModelIndex & idx)
 {
+       selectedLV->selectionModel()->clear();
+
+       updateInfo(idx);
+       setButtons();
+}
+
+
+void QCitationDialog::availableChanged(const QModelIndex & idx, const QModelIndex &)
+{
+       if (!idx.isValid())
+               return;
+               
        updateInfo(idx);
        setButtons();
 }
@@ -322,7 +363,15 @@ void QCitationDialog::on_downPB_clicked()
 
 void QCitationDialog::on_findLE_textChanged(const QString & text)
 {
+       clearPB->setDisabled(text.isEmpty());
+       if (text.isEmpty())
+               findLE->setFocus();
+
        form_->findKey(text);
+       if (form_->found()->rowCount() == 0) {
+               findLE->backspace();
+               return;
+       }
        availableLV->setModel(form_->found());
        changed();
 }
index 46fd7ffe0bf146a7cb3ca269de73958f48d4ad83..f1d89e5440eb05048219180684ea2aa771dbb687 100644 (file)
@@ -57,8 +57,10 @@ protected Q_SLOTS:
        void on_downPB_clicked();
        void on_findLE_textChanged(const QString & text);
        void on_selectedLV_clicked(const QModelIndex &);
+       void selectedChanged(const QModelIndex &, const QModelIndex &);
        void on_availableLV_clicked(const QModelIndex &);
        void on_availableLV_activated(const QModelIndex &);
+       void availableChanged(const QModelIndex &, const QModelIndex &);
        virtual void changed();
        /// check whether key is already selected
        bool isSelected(const QModelIndex &);
index a7f5d2ce9eadfb0466b514038c793ca5f4fb4752..16ebeb282d38f13e727611fcdc3a76b9a9d146cb 100644 (file)
   <property name="sizeGripEnabled" >
    <bool>true</bool>
   </property>
-  <layout class="QVBoxLayout" >
+  <layout class="QGridLayout" >
    <property name="margin" >
     <number>9</number>
    </property>
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item>
-    <layout class="QGridLayout" >
+   <item row="1" column="0" >
+    <layout class="QHBoxLayout" >
      <property name="margin" >
       <number>0</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
-     <item row="0" column="0" colspan="2" >
-      <widget class="QLabel" name="availableKeysLA" >
+     <item>
+      <widget class="QLabel" name="findKeysLA" >
        <property name="text" >
-        <string>&amp;Available Citations:</string>
-       </property>
-       <property name="buddy" >
-        <cstring>availableLV</cstring>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="1" >
-      <widget class="QPushButton" name="addPB" >
-       <property name="toolTip" >
-        <string/>
+        <string>&amp;Find:</string>
        </property>
-       <property name="text" >
-        <string>&amp;Add</string>
+       <property name="alignment" >
+        <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
        </property>
-       <property name="autoDefault" >
-        <bool>true</bool>
+       <property name="buddy" >
+        <cstring>selectedLV</cstring>
        </property>
       </widget>
      </item>
-     <item row="0" column="2" >
-      <widget class="QLabel" name="selectedKeysLA" >
+     <item>
+      <widget class="QLineEdit" name="findLE" >
        <property name="text" >
-        <string>&amp;Selected Citations:</string>
-       </property>
-       <property name="buddy" >
-        <cstring>selectedLV</cstring>
+        <string/>
        </property>
       </widget>
      </item>
-     <item row="4" column="1" >
-      <widget class="QPushButton" name="upPB" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>0</hsizetype>
-         <vsizetype>0</vsizetype>
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="toolTip" >
-        <string>Move the selected citation up</string>
+     <item>
+      <widget class="QPushButton" name="clearPB" >
+       <property name="enabled" >
+        <bool>false</bool>
        </property>
        <property name="text" >
-        <string>&amp;Up</string>
-       </property>
-       <property name="icon" >
-        <iconset/>
+        <string>&lt;- Clear</string>
        </property>
       </widget>
      </item>
-     <item rowspan="5" row="1" column="2" >
-      <widget class="QListView" name="selectedLV" >
-       <property name="editTriggers" >
-        <set>QAbstractItemView::NoEditTriggers</set>
+    </layout>
+   </item>
+   <item row="4" column="0" >
+    <layout class="QHBoxLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item>
+      <widget class="QPushButton" name="restorePB" >
+       <property name="text" >
+        <string>&amp;Restore</string>
        </property>
       </widget>
      </item>
-     <item row="3" column="1" >
+     <item>
       <spacer>
        <property name="orientation" >
-        <enum>Qt::Vertical</enum>
+        <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" >
         <size>
-         <width>20</width>
-         <height>16</height>
+         <width>40</width>
+         <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
-     <item rowspan="5" row="1" column="0" >
-      <widget class="QListView" name="availableLV" >
-       <property name="editTriggers" >
-        <set>QAbstractItemView::NoEditTriggers</set>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="1" >
-      <widget class="QPushButton" name="downPB" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>0</hsizetype>
-         <vsizetype>0</vsizetype>
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="toolTip" >
-        <string>Move the selected citation down</string>
-       </property>
+     <item>
+      <widget class="QPushButton" name="okPB" >
        <property name="text" >
-        <string>&amp;Down</string>
+        <string>&amp;OK</string>
        </property>
-       <property name="icon" >
-        <iconset/>
+       <property name="autoDefault" >
+        <bool>true</bool>
        </property>
-      </widget>
-     </item>
-     <item row="2" column="1" >
-      <widget class="QPushButton" name="deletePB" >
-       <property name="text" >
-        <string>D&amp;elete</string>
+       <property name="default" >
+        <bool>true</bool>
        </property>
       </widget>
      </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
      <item>
-      <widget class="QLabel" name="findKeysLA" >
+      <widget class="QPushButton" name="applyPB" >
        <property name="text" >
-        <string>&amp;Find:</string>
-       </property>
-       <property name="alignment" >
-        <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
-       </property>
-       <property name="buddy" >
-        <cstring>selectedLV</cstring>
+        <string>A&amp;pply</string>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLineEdit" name="findLE" >
+      <widget class="QPushButton" name="cancelPB" >
        <property name="text" >
-        <string/>
+        <string>&amp;Cancel</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>false</bool>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item>
-    <widget class="QTextBrowser" name="infoML" />
-   </item>
-   <item>
+   <item row="3" column="0" >
     <widget class="QGroupBox" name="styleGB" >
      <property name="title" >
       <string>Formatting</string>
      </property>
+     <property name="flat" >
+      <bool>true</bool>
+     </property>
      <layout class="QGridLayout" >
       <property name="margin" >
        <number>9</number>
      </layout>
     </widget>
    </item>
-   <item>
-    <layout class="QHBoxLayout" >
+   <item row="2" column="0" >
+    <widget class="QTextBrowser" name="infoML" />
+   </item>
+   <item row="0" column="0" >
+    <layout class="QGridLayout" >
      <property name="margin" >
       <number>0</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
-     <item>
-      <widget class="QPushButton" name="restorePB" >
+     <item row="0" column="0" colspan="2" >
+      <widget class="QLabel" name="availableKeysLA" >
        <property name="text" >
-        <string>&amp;Restore</string>
+        <string>&amp;Available Citations:</string>
+       </property>
+       <property name="buddy" >
+        <cstring>availableLV</cstring>
        </property>
       </widget>
      </item>
-     <item>
+     <item row="1" column="1" >
+      <widget class="QPushButton" name="addPB" >
+       <property name="toolTip" >
+        <string/>
+       </property>
+       <property name="text" >
+        <string>&amp;Add</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="2" >
+      <widget class="QLabel" name="selectedKeysLA" >
+       <property name="text" >
+        <string>&amp;Selected Citations:</string>
+       </property>
+       <property name="buddy" >
+        <cstring>selectedLV</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="4" column="1" >
+      <widget class="QPushButton" name="upPB" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="toolTip" >
+        <string>Move the selected citation up</string>
+       </property>
+       <property name="text" >
+        <string>&amp;Up</string>
+       </property>
+       <property name="icon" >
+        <iconset/>
+       </property>
+      </widget>
+     </item>
+     <item rowspan="5" row="1" column="2" >
+      <widget class="QListView" name="selectedLV" >
+       <property name="editTriggers" >
+        <set>QAbstractItemView::NoEditTriggers</set>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="1" >
       <spacer>
        <property name="orientation" >
-        <enum>Qt::Horizontal</enum>
+        <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" >
         <size>
-         <width>40</width>
-         <height>20</height>
+         <width>20</width>
+         <height>16</height>
         </size>
        </property>
       </spacer>
      </item>
-     <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
-        <string>&amp;OK</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>true</bool>
-       </property>
-       <property name="default" >
-        <bool>true</bool>
+     <item rowspan="5" row="1" column="0" >
+      <widget class="QListView" name="availableLV" >
+       <property name="editTriggers" >
+        <set>QAbstractItemView::NoEditTriggers</set>
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QPushButton" name="applyPB" >
+     <item row="5" column="1" >
+      <widget class="QPushButton" name="downPB" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="toolTip" >
+        <string>Move the selected citation down</string>
+       </property>
        <property name="text" >
-        <string>A&amp;pply</string>
+        <string>&amp;Down</string>
+       </property>
+       <property name="icon" >
+        <iconset/>
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QPushButton" name="cancelPB" >
+     <item row="2" column="1" >
+      <widget class="QPushButton" name="deletePB" >
        <property name="text" >
-        <string>&amp;Cancel</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
+        <string>D&amp;elete</string>
        </property>
       </widget>
      </item>
   </layout>
  </widget>
  <pixmapfunction></pixmapfunction>
- <includes>
-  <include location="local" >qt_helpers.h</include>
- </includes>
  <tabstops>
   <tabstop>availableLV</tabstop>
   <tabstop>selectedLV</tabstop>
   <tabstop>applyPB</tabstop>
   <tabstop>cancelPB</tabstop>
  </tabstops>
+ <includes>
+  <include location="local" >qt_helpers.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>