]> git.lyx.org Git - features.git/commitdiff
Rework the delimiter dialog:
authorAbdelrazak Younes <younes@lyx.org>
Thu, 5 Apr 2007 12:12:07 +0000 (12:12 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 5 Apr 2007 12:12:07 +0000 (12:12 +0000)
- ListWidget instead of combo,
- matched delimiters on the same row,
- immediate insertion on "enter" or "double-click" if the 'match' option is checked.
- simplification of the code.

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

src/frontends/qt4/QDelimiterDialog.C
src/frontends/qt4/QDelimiterDialog.h
src/frontends/qt4/ui/QDelimiterUi.ui

index 997c74954031051940c65993b4537b271b46b811..e9abd5def44ceb77ae2d33943bf175c4ef9ccdf0 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <QPixmap>
 #include <QCheckBox>
-
+#include <QListWidgetItem>
 
 #include <sstream>
 
@@ -31,7 +31,7 @@ namespace frontend {
 
 namespace {
 
-char const * delim[] = {
+string const delim[] = {
        "(", ")", "{", "}", "[", "]",
        "lceil", "rceil", "lfloor", "rfloor", "langle", "rangle",
        "uparrow", "Uparrow", "downarrow", "Downarrow",
@@ -96,39 +96,41 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
        connect(insertPB, SIGNAL(clicked()), this, SLOT(insertClicked()));
 
        setWindowTitle(qt_("LyX: Delimiters"));
-
-       for (size_t i = 0; i != 21; ++i)
-               delimiters_.append(toqstr(delim[i]));
+       setFocusProxy(leftLW);
 
        // The last element is the empty one.
-       size_t end = delimiters_.size() - 1;
-       for (size_t i = 0; i != end; ++i) {
-               if (delimiters_[i].size() == 1) {
-                       leftCO->addItem(delimiters_[i]);
-                       rightCO->addItem(delimiters_[i]);
+       for (size_t i = 0; !delim[i].empty(); ++i) {
+               QString const left_d = toqstr(delim[i]);
+               QString const right_d = do_match(left_d);
+               if (left_d.size() == 1) {
+                       leftLW->addItem(left_d);
+                       rightLW->addItem(right_d);
                } else {
-                       QPixmap pm = QPixmap(toqstr(find_xpm(fromqstr(delimiters_[i]))));
-                       leftCO->addItem(QIcon(pm), delimiters_[i]);
-                       rightCO->addItem(QIcon(pm), delimiters_[i]);
+                       QPixmap left_pm = QPixmap(toqstr(find_xpm(fromqstr(left_d))));
+                       leftLW->addItem(new QListWidgetItem(QIcon(left_pm), left_d));
+                       QPixmap right_pm = QPixmap(toqstr(find_xpm(fromqstr(right_d))));
+                       rightLW->addItem(new QListWidgetItem(QIcon(right_pm), right_d));
                }
        }
 
-       leftCO->addItem(qt_("(None)"));
-       rightCO->addItem(qt_("(None)"));
+       leftLW->addItem(qt_("(None)"));
+       rightLW->addItem(qt_("(None)"));
 
        sizeCO->addItem(qt_("Variable"));
 
        for (int i = 0; *biggui[i]; ++i)
                sizeCO->addItem(qt_(biggui[i]));
 
-       on_leftCO_activated(0);
+       on_leftLW_currentRowChanged(0);
 }
 
 
 void QDelimiterDialog::insertClicked()
 {
-       QString const left_ = delimiters_[leftCO->currentIndex()];
-       QString const right_ = delimiters_[rightCO->currentIndex()];
+       QString const left_ = (leftLW->currentRow() < leftLW->count() - 1)?
+               leftLW->currentItem()->text(): QString();
+       QString const right_ = (rightLW->currentRow() < rightLW->count() - 1)?
+               rightLW->currentItem()->text(): QString();
        int const size_ = sizeCO->currentIndex();
 
        if (size_ == 0) {
@@ -143,32 +145,37 @@ void QDelimiterDialog::insertClicked()
                   << fix_name(right_, true) << '"';
                form_->controller().dispatchBigDelim(os.str());
        }
+}
+
 
+void QDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
+{
+       if (!matchCB->isChecked())
+               return;
+
+       insertClicked();
+       accept();
 }
 
 
-void QDelimiterDialog::on_leftCO_activated(int item)
+void QDelimiterDialog::on_leftLW_currentRowChanged(int item)
 {
-       if (matchCB->isChecked()) {
-               QString const match = do_match(delimiters_[item]);
-               rightCO->setCurrentIndex(delimiters_.indexOf(match));
-       }
+       if (matchCB->isChecked())
+               rightLW->setCurrentRow(item);
 }
 
 
-void QDelimiterDialog::on_rightCO_activated(int item)
+void QDelimiterDialog::on_rightLW_currentRowChanged(int item)
 {
-       if (matchCB->isChecked()) {
-               QString const match = do_match(delimiters_[item]);
-               leftCO->setCurrentIndex(delimiters_.indexOf(match));
-       }
+       if (matchCB->isChecked())
+               leftLW->setCurrentRow(item);
 }
 
 
 void QDelimiterDialog::on_matchCB_stateChanged(int state)
 {
        if (state == Qt::Checked)
-               on_leftCO_activated(leftCO->currentIndex());
+               on_leftLW_currentRowChanged(leftLW->currentRow());
 }
 
 
index 013a8e3ed1c90f6ad1df9c549c86262f3d49b94a..3a32e7dea04b788361dcea3f0212b28e870045bc 100644 (file)
 
 #include "ui/QDelimiterUi.h"
 
-#include <QStringList>
-
 #include <string>
 
+class QListWidgetItem;
+
 namespace lyx {
 namespace frontend {
 
@@ -28,15 +28,14 @@ class QDelimiterDialog : public QDialog, public Ui::QDelimiterUi {
 public:
        QDelimiterDialog(QMathDelimiter * form);
 public Q_SLOTS:
-       void on_leftCO_activated(int);
-       void on_rightCO_activated(int);
+       void on_leftLW_itemActivated(QListWidgetItem *);
+       void on_leftLW_currentRowChanged(int);
+       void on_rightLW_currentRowChanged(int);
        void on_matchCB_stateChanged(int);
        void insertClicked();
 private:
        /// owning form
        QMathDelimiter * form_;
-       ///
-       QStringList delimiters_;
 };
 
 } // namespace frontend
index a2598a6c4485e85b63f5a0f7ba53690520d9995b..2e8f8b2a45d5faee4a72c3f3c8fa07c8b434f5cf 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>206</width>
-    <height>153</height>
+    <width>193</width>
+    <height>430</height>
    </rect>
   </property>
   <property name="minimumSize" >
       <number>6</number>
      </property>
      <item>
-      <widget class="QComboBox" name="leftCO" >
+      <widget class="QListWidget" name="leftLW" >
        <property name="sizePolicy" >
         <sizepolicy>
-         <hsizetype>4</hsizetype>
-         <vsizetype>4</vsizetype>
+         <hsizetype>0</hsizetype>
+         <vsizetype>7</vsizetype>
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="minimumSize" >
+       <property name="maximumSize" >
         <size>
-         <width>42</width>
-         <height>42</height>
+         <width>110</width>
+         <height>16777215</height>
         </size>
        </property>
-       <property name="maxVisibleItems" >
-        <number>100</number>
-       </property>
-       <property name="sizeAdjustPolicy" >
-        <enum>QComboBox::AdjustToContents</enum>
-       </property>
        <property name="iconSize" >
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>16</width>
+         <height>16</height>
         </size>
        </property>
+       <property name="resizeMode" >
+        <enum>QListView::Adjust</enum>
+       </property>
+       <property name="spacing" >
+        <number>1</number>
+       </property>
+       <property name="currentRow" >
+        <number>-1</number>
+       </property>
       </widget>
      </item>
      <item>
-      <widget class="QComboBox" name="rightCO" >
+      <widget class="QListWidget" name="rightLW" >
        <property name="sizePolicy" >
         <sizepolicy>
-         <hsizetype>4</hsizetype>
-         <vsizetype>4</vsizetype>
+         <hsizetype>0</hsizetype>
+         <vsizetype>7</vsizetype>
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="minimumSize" >
+       <property name="maximumSize" >
         <size>
-         <width>42</width>
-         <height>42</height>
+         <width>110</width>
+         <height>16777215</height>
         </size>
        </property>
-       <property name="maxVisibleItems" >
-        <number>100</number>
-       </property>
        <property name="iconSize" >
         <size>
-         <width>32</width>
-         <height>32</height>
+         <width>16</width>
+         <height>16</height>
         </size>
        </property>
+       <property name="spacing" >
+        <number>1</number>
+       </property>
       </widget>
      </item>
     </layout>
   </layout>
  </widget>
  <tabstops>
-  <tabstop>leftCO</tabstop>
-  <tabstop>rightCO</tabstop>
   <tabstop>matchCB</tabstop>
   <tabstop>sizeCO</tabstop>
   <tabstop>insertPB</tabstop>