]> git.lyx.org Git - features.git/commitdiff
Delimiter dilaog: Cleanup the code and rework the dialog a bit.
authorAbdelrazak Younes <younes@lyx.org>
Thu, 5 Apr 2007 09:26:09 +0000 (09:26 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 5 Apr 2007 09:26:09 +0000 (09:26 +0000)
Most of the change is about using the new private member delimiters_ instead of the "delim" table.  Also, we don't display an icon when the delimiter is one character.
I did not manage to let the combos expand to the maximum.

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

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

index 82102e9e16e2f0c45db2b59f26a5ed0ebc45ba51..997c74954031051940c65993b4537b271b46b811 100644 (file)
@@ -49,7 +49,7 @@ char const * const biggui[]   = {N_("big[[delimiter size]]"), N_("Big[[delimiter
        N_("bigg[[delimiter size]]"), N_("Bigg[[delimiter size]]"), ""};
 
 
-string do_match(const string & str)
+QString do_match(QString const & str)
 {
        if (str == "(") return ")";
        if (str == ")") return "(";
@@ -70,18 +70,18 @@ string do_match(const string & str)
 }
 
 
-string fix_name(const string & str, bool big)
+string fix_name(QString const & str, bool big)
 {
        if (str == "slash")
                return "/";
        if (str == "backslash")
                return "\\";
-       if (str.empty())
+       if (str.isEmpty())
                return ".";
        if (!big || str == "(" || str == ")" || str == "[" || str == "]")
-               return str;
+               return fromqstr(str);
 
-       return "\\" + str;
+       return "\\" + fromqstr(str);
 }
 
 } // namespace anon
@@ -97,15 +97,24 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
 
        setWindowTitle(qt_("LyX: Delimiters"));
 
-       for (int i = 0; *delim[i]; ++i) {
-               QPixmap pm = QPixmap(toqstr(find_xpm(delim[i])));
-               leftCO->addItem(QIcon(pm), "");
-               rightCO->addItem(QIcon(pm), "");
+       for (size_t i = 0; i != 21; ++i)
+               delimiters_.append(toqstr(delim[i]));
+
+       // 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]);
+               } else {
+                       QPixmap pm = QPixmap(toqstr(find_xpm(fromqstr(delimiters_[i]))));
+                       leftCO->addItem(QIcon(pm), delimiters_[i]);
+                       rightCO->addItem(QIcon(pm), delimiters_[i]);
+               }
        }
 
-       string empty_xpm(find_xpm("empty"));
-       leftCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
-       rightCO->addItem(QIcon(QPixmap(toqstr(empty_xpm))), qt_("(None)"));
+       leftCO->addItem(qt_("(None)"));
+       rightCO->addItem(qt_("(None)"));
 
        sizeCO->addItem(qt_("Variable"));
 
@@ -118,8 +127,8 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form)
 
 void QDelimiterDialog::insertClicked()
 {
-       string const left_ = delim[leftCO->currentIndex()];
-       string const right_ = delim[rightCO->currentIndex()];
+       QString const left_ = delimiters_[leftCO->currentIndex()];
+       QString const right_ = delimiters_[rightCO->currentIndex()];
        int const size_ = sizeCO->currentIndex();
 
        if (size_ == 0) {
@@ -141,11 +150,8 @@ void QDelimiterDialog::insertClicked()
 void QDelimiterDialog::on_leftCO_activated(int item)
 {
        if (matchCB->isChecked()) {
-               string const match = do_match(delim[item]);
-               int k = 0;
-               while (delim[k] && delim[k] != match)
-                       ++k;
-               rightCO->setCurrentIndex(k);
+               QString const match = do_match(delimiters_[item]);
+               rightCO->setCurrentIndex(delimiters_.indexOf(match));
        }
 }
 
@@ -153,11 +159,8 @@ void QDelimiterDialog::on_leftCO_activated(int item)
 void QDelimiterDialog::on_rightCO_activated(int item)
 {
        if (matchCB->isChecked()) {
-               string const match = do_match(delim[item]);
-               int k = 0;
-               while (delim[k] && delim[k] != match)
-                       ++k;
-               leftCO->setCurrentIndex(k);
+               QString const match = do_match(delimiters_[item]);
+               leftCO->setCurrentIndex(delimiters_.indexOf(match));
        }
 }
 
index c11264d2237671f1d843526604b8fe3e2df10a9f..013a8e3ed1c90f6ad1df9c549c86262f3d49b94a 100644 (file)
@@ -13,6 +13,9 @@
 #define QDELIMITERDIALOG_H
 
 #include "ui/QDelimiterUi.h"
+
+#include <QStringList>
+
 #include <string>
 
 namespace lyx {
@@ -32,6 +35,8 @@ public Q_SLOTS:
 private:
        /// owning form
        QMathDelimiter * form_;
+       ///
+       QStringList delimiters_;
 };
 
 } // namespace frontend
index e47c63d19f26584dfbbb3d38719a59febeda4f6e..a2598a6c4485e85b63f5a0f7ba53690520d9995b 100644 (file)
@@ -1,7 +1,4 @@
 <ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
  <class>QDelimiterUi</class>
  <widget class="QDialog" name="QDelimiterUi" >
   <property name="geometry" >
      </property>
      <item>
       <widget class="QComboBox" name="leftCO" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>4</hsizetype>
+         <vsizetype>4</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="minimumSize" >
         <size>
          <width>42</width>
          <height>42</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>
      </item>
      <item>
       <widget class="QComboBox" name="rightCO" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>4</hsizetype>
+         <vsizetype>4</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
        <property name="minimumSize" >
         <size>
          <width>42</width>
          <height>42</height>
         </size>
        </property>
+       <property name="maxVisibleItems" >
+        <number>100</number>
+       </property>
        <property name="iconSize" >
         <size>
          <width>32</width>
    </item>
   </layout>
  </widget>
- <pixmapfunction></pixmapfunction>
- <includes>
-  <include location="local" >qt_helpers.h</include>
- </includes>
  <tabstops>
   <tabstop>leftCO</tabstop>
   <tabstop>rightCO</tabstop>
   <tabstop>insertPB</tabstop>
   <tabstop>closePB</tabstop>
  </tabstops>
+ <includes>
+  <include location="local" >qt_helpers.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>