]> git.lyx.org Git - features.git/commitdiff
QVSpace dialog/QBranches: some minor (uncontroversial) bugfixes
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 29 Nov 2003 17:25:31 +0000 (17:25 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 29 Nov 2003 17:25:31 +0000 (17:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8156 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QDocumentDialog.C
src/frontends/qt2/QParagraphDialog.C
src/frontends/qt2/QVSpace.C
src/frontends/qt2/QVSpace.h
src/frontends/qt2/QVSpaceDialog.C
src/frontends/qt2/qt_helpers.C
src/frontends/qt2/ui/QVSpaceDialogBase.ui

index 393489c9d4e12d4b3aeff1b5c8a0199aae909fcb..13c1ef7d737242245617933baeca6d7829b6ad33 100644 (file)
@@ -1,6 +1,14 @@
 2003-11-29  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
 
-       * QParagraph.C: whitespace
+       * qt_helpers.C (widgetsToLength): handle glue lengths
+       * QDocumentDialog.C: use clicked() instead of pressed()
+       for branches color button.
+       * QVSpace.[Ch]: fix a few bugs, simplify the code (by using
+       qt_helpers functions)
+       * QDocumentDialog.C:
+       * ui/QDocumentDialogBase.ui: use lengthcombo instead of
+       QComboBox (which simplifies the code).
+       * QParagraphDialog.C: whitespace
        * ui/QParagraphDialogBase.ui: restore lost connections.
 
 2003-11-29  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
index 12876572cebe5b37f26c53cf58473c86e04c6dfd..efee6907a5f4c2d8db1e4873f4761c2e416ccf92 100644 (file)
@@ -167,7 +167,7 @@ QDocumentDialog::QDocumentDialog(QDocument * form)
        connect(branchesModule->addBranchPB, SIGNAL(pressed()), this, SLOT(addBranchPressed()));
        connect(branchesModule->removePB, SIGNAL(pressed()), this, SLOT(deleteBranchPressed()));
        connect(branchesModule->activatePB, SIGNAL(pressed()), this, SLOT(toggleBranchPressed()));
-       connect(branchesModule->colorPB, SIGNAL(pressed()), this, SLOT(toggleBranchColor()));
+       connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
        branchesModule->branchesLV->setSorting(0);
 }
 
index 78b6dcfbe2d634168d424cfd54b20334ea4bfb26..542138521fe766db9acad1123eb3cd959c2297be 100644 (file)
@@ -66,6 +66,6 @@ void QParagraphDialog::change_adaptor()
 
 void QParagraphDialog::enableLinespacingValue(int)
 {
-       bool const enable = linespacing->currentItem()==4;
+       bool const enable = linespacing->currentItem() == 4;
        linespacingValue->setEnabled(enable);
 }
index 32aa3a4ebc62186a029eab0ec9a4518c662ab9b5..a3b896403f7535776840111fd4a9d3afb59f1c0b 100644 (file)
@@ -20,7 +20,7 @@
 #include "QVSpace.h"
 #include "QVSpaceDialog.h"
 #include "Qt2BC.h"
-#include "lyxrc.h" // to set the deafult length values
+#include "lyxrc.h" // to set the default length values
 #include "qt_helpers.h"
 #include "helper_funcs.h"
 
 #include <qlineedit.h>
 #include <qcheckbox.h>
 #include <qpushbutton.h>
+#include "lengthcombo.h"
 
-using lyx::support::contains_functor;
-using lyx::support::isStrDbl;
-using lyx::support::subst;
-using lyx::support::trim;
 
-using std::bind2nd;
-using std::remove_if;
-
-using std::vector;
 using std::string;
 
 
@@ -52,13 +45,9 @@ namespace {
 void setWidgetsFromVSpace(VSpace const & space,
                          QComboBox * spacing,
                          QLineEdit * value,
-                         QComboBox * unit,
-                         QCheckBox * keep, vector<string> units_)
+                         LengthCombo * unit,
+                         QCheckBox * keep)
 {
-       value->setText("");
-       value->setEnabled(false);
-       unit->setEnabled(false);
-
        int item = 0;
        switch (space.kind()) {
        case VSpace::NONE:
@@ -81,48 +70,33 @@ void setWidgetsFromVSpace(VSpace const & space,
                break;
        case VSpace::LENGTH:
                item = 6;
-               value->setEnabled(true);
-               unit->setEnabled(true);
-               string length = space.length().asString();
-               string const default_unit =
-                       (lyxrc.default_papersize > 3) ? "cm" : "in";
-               string supplied_unit = default_unit;
-               LyXLength len(length);
-               if ((isValidLength(length)
-                    || isStrDbl(length)) && !len.zero()) {
-                       length = tostr(len.value());
-                       supplied_unit = subst(stringFromUnit(len.unit()),
-                                             "%", "%%");
-               }
-
-               int unit_item = 0;
-               int i = 0;
-               for (vector<string>::const_iterator it = units_.begin();
-                    it != units_.end(); ++it) {
-                       if (*it == default_unit) {
-                               unit_item = i;
-                       }
-                       if (*it == supplied_unit) {
-                               unit_item = i;
-                               break;
-                       }
-                       i += 1;
-               }
-               value->setText(toqstr(length));
-               unit->setCurrentItem(unit_item);
                break;
        }
        spacing->setCurrentItem(item);
        keep->setChecked(space.keep());
+
+       LyXLength::UNIT default_unit =
+                       (lyxrc.default_papersize > 3) ? LyXLength::CM : LyXLength::IN;
+       bool const custom_vspace = space.kind() == VSpace::LENGTH;
+       if (custom_vspace) {
+               value->setEnabled(true);
+               unit->setEnabled(true);
+               string length = space.length().asString();
+               lengthToWidgets(value, unit, length, default_unit);
+       } else {
+               lengthToWidgets(value, unit, "", default_unit);
+               value->setEnabled(false);
+               unit->setEnabled(false);
+       }
 }
 
 
 VSpace setVSpaceFromWidgets(int spacing,
-                           string value,
-                           string unit,
+                           QLineEdit * value,
+                           LengthCombo * unit,
                            bool keep)
 {
-       VSpace space;
+       VSpace space = VSpace(VSpace::NONE);
 
        switch (spacing) {
        case 0:
@@ -144,21 +118,12 @@ VSpace setVSpaceFromWidgets(int spacing,
                space = VSpace(VSpace::VFILL);
                break;
        case 6:
-               string s;
-               string const length = trim(value);
-               if (isValidGlueLength(length)) {
-                       s = length;
-               } else if (!length.empty()){
-                       string u = trim(unit);
-                       u = subst(u, "%%", "%");
-                       s = length + u;
-               }
-               space = VSpace(LyXGlueLength(s));
+               space = VSpace(LyXGlueLength(
+                                     widgetsToLength(value, unit)));
                break;
        }
 
        space.setKeep(keep);
-
        return space;
 }
 
@@ -168,7 +133,7 @@ VSpace setVSpaceFromWidgets(int spacing,
 typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
 
 QVSpace::QVSpace(Dialog & parent)
-       : base_class(parent, _("LyX: VSpace Settings"))
+       : base_class(parent, _("LyX: Vertical Space Settings"))
 {}
 
 
@@ -177,19 +142,6 @@ void QVSpace::build_dialog()
        // the tabbed folder
        dialog_.reset(new QVSpaceDialog(this));
 
-       // Create the contents of the unit choices
-       // Don't include the "%" terms...
-       units_ = getLatexUnits();
-       vector<string>::iterator del =
-               remove_if(units_.begin(), units_.end(),
-                         bind2nd(contains_functor(), "%"));
-       units_.erase(del, units_.end());
-
-       for (vector<string>::const_iterator it = units_.begin();
-               it != units_.end(); ++it) {
-               dialog_->unitCO->insertItem(toqstr(*it));
-       }
-
        // Manage the ok, apply, restore and cancel/close buttons
        bcview().setOK(dialog_->okPB);
        bcview().setApply(dialog_->applyPB);
@@ -201,6 +153,15 @@ void QVSpace::build_dialog()
        bcview().addReadOnly(dialog_->valueLE);
        bcview().addReadOnly(dialog_->unitCO);
        bcview().addReadOnly(dialog_->keepCB);
+
+       // remove the %-items from the unit choice
+       int num = dialog_->unitCO->count();
+       for (int i=0; i < num; i++) {
+               if (dialog_->unitCO->text(i).contains("%") > 0) {
+                       dialog_->unitCO->removeItem(i);
+                       i -= 1;
+               }
+       }
 }
 
 
@@ -215,8 +176,8 @@ void QVSpace::apply()
 
        VSpace const space =
                setVSpaceFromWidgets(dialog_->spacingCO->currentItem(),
-                                    fromqstr(dialog_->valueLE->text()),
-                                    fromqstr(dialog_->unitCO->currentText()),
+                                    dialog_->valueLE,
+                                    dialog_->unitCO,
                                     dialog_->keepCB->isChecked());
 
        controller().params() = space;
@@ -229,5 +190,5 @@ void QVSpace::update_contents()
                             dialog_->spacingCO,
                             dialog_->valueLE,
                             dialog_->unitCO,
-                            dialog_->keepCB, units_);
+                            dialog_->keepCB);
 }
index 5f5a377fdf1337b36dd703f0711bf9641b948bdb..f35ad6e668cfc4651862666006c09e57f7790470 100644 (file)
@@ -38,8 +38,6 @@ private:
        virtual void apply();
        /// Update the dialog
        virtual void update_contents();
-
-       std::vector<std::string> units_;
 };
 
 #endif //QVSPACE_H
index 69ecfe65d6ede36dafc3bcc7a44dd62300128ac4..33305a9f09378329a75ec36e7a17b59ea4de5a51 100644 (file)
@@ -19,6 +19,7 @@
 #include <qcombobox.h>
 #include <qpushbutton.h>
 #include <qvalidator.h>
+#include "lengthcombo.h"
 
 #include "qt_helpers.h"
 
index 8aa22cbc0922748c7f3670ff3d9caa1620bb283f..109f0837391288715f9c445549bb9f576a0fa932 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Dekel Tsur
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -11,6 +12,7 @@
 #include <config.h>
 
 #include "support/tostr.h"
+#include "support/lstrings.h"
 #include "gettext.h"
 #include "qt_helpers.h"
 
@@ -21,6 +23,9 @@
 
 #include <algorithm>
 
+
+using lyx::support::isStrDbl;
+
 using std::make_pair;
 using std::string;
 using std::pair;
@@ -79,6 +84,10 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
                // no length (UNIT_NONE)
                combo->setCurrentItem(defaultUnit);
                input->setText("");
+       } else if (!isValidLength(len) && !isStrDbl(len)) {
+               // use input field only for gluelengths
+               combo->setCurrentItem(defaultUnit);
+               input->setText(toqstr(len));
        } else {
                combo->setCurrentItem(LyXLength(len).unit());
                input->setText(toqstr(tostr(LyXLength(len).value())));
index c32640475da255ba47595a6ae848c3bbaf494105..4fc0bca3609a653fdcbfd6ba977ad7cfcca59f81 100644 (file)
@@ -13,7 +13,7 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>345</width>
+            <width>335</width>
             <height>140</height>
         </rect>
     </property>
                 <string>Do not reset the spacing on page break</string>
             </property>
         </widget>
-        <widget row="1"  column="2" >
-            <class>QComboBox</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>unitCO</cstring>
-            </property>
-            <property stdset="1">
-                <name>enabled</name>
-                <bool>false</bool>
-            </property>
-            <property>
-                <name>toolTip</name>
-                <string>Custom value. Needs spacing type "Custom".</string>
-            </property>
-        </widget>
         <widget row="1"  column="1" >
             <class>QLineEdit</class>
             <property stdset="1">
                 <string>Supported spacing types</string>
             </property>
         </widget>
-        <spacer row="0"  column="2" >
+        <spacer row="0"  column="2"  rowspan="1"  colspan="2" >
             <property>
                 <name>name</name>
                 <cstring>Spacer8</cstring>
                 </size>
             </property>
         </spacer>
-        <spacer row="2"  column="2" >
+        <spacer row="2"  column="2"  rowspan="1"  colspan="2" >
             <property>
                 <name>name</name>
                 <cstring>Spacer9</cstring>
                 </size>
             </property>
         </spacer>
-        <widget row="4"  column="0"  rowspan="1"  colspan="3" >
+        <widget row="4"  column="0"  rowspan="1"  colspan="4" >
             <class>QLayoutWidget</class>
             <property stdset="1">
                 <name>name</name>
                 </size>
             </property>
         </spacer>
+        <widget row="1"  column="2" >
+            <class>LengthCombo</class>
+            <property stdset="1">
+                <name>name</name>
+                <cstring>unitCO</cstring>
+            </property>
+        </widget>
+        <spacer row="1"  column="3" >
+            <property>
+                <name>name</name>
+                <cstring>Spacer5</cstring>
+            </property>
+            <property stdset="1">
+                <name>orientation</name>
+                <enum>Horizontal</enum>
+            </property>
+            <property stdset="1">
+                <name>sizeType</name>
+                <enum>Expanding</enum>
+            </property>
+            <property>
+                <name>sizeHint</name>
+                <size>
+                    <width>20</width>
+                    <height>20</height>
+                </size>
+            </property>
+        </spacer>
     </grid>
 </widget>
+<customwidgets>
+    <customwidget>
+        <class>LengthCombo</class>
+        <header location="local">lengthcombo.h</header>
+        <sizehint>
+            <width>-1</width>
+            <height>-1</height>
+        </sizehint>
+        <container>0</container>
+        <sizepolicy>
+            <hordata>5</hordata>
+            <verdata>5</verdata>
+        </sizepolicy>
+        <pixmap>image0</pixmap>
+        <signal>selectionChanged(LyXLength::UNIT)</signal>
+    </customwidget>
+</customwidgets>
+<images>
+    <image>
+        <name>image0</name>
+        <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
+    </image>
+</images>
 <connections>
     <connection>
         <sender>spacingCO</sender>
         <slot>change_adaptor()</slot>
     </connection>
     <connection>
-        <sender>unitCO</sender>
-        <signal>highlighted(const QString&amp;)</signal>
+        <sender>spacingCO</sender>
+        <signal>activated(int)</signal>
         <receiver>QVSpaceDialogBase</receiver>
-        <slot>change_adaptor()</slot>
+        <slot>enableCustom(int)</slot>
     </connection>
     <connection>
         <sender>keepCB</sender>
-        <signal>checked()</signal>
+        <signal>clicked()</signal>
         <receiver>QVSpaceDialogBase</receiver>
         <slot>change_adaptor()</slot>
     </connection>
-       <connection>
-        <sender>spacingCO</sender>
-        <signal>activated(int)</signal>
+    <connection>
+        <sender>unitCO</sender>
+        <signal>selectionChanged(LyXLength::UNIT)</signal>
         <receiver>QVSpaceDialogBase</receiver>
-        <slot>enableCustom(int)</slot>
+        <slot>change_adaptor()</slot>
     </connection>
     <slot access="protected">change_adaptor()</slot>
     <slot access="protected">enableCustom(int)</slot>