Changes to paragraph settings dialog so that it offers only

options accepted by the current paragraph.

ui/QParagraphUi.ui
  Changed combo box for alignment to radio buttons. Added
  checkbox for default alignment.
QParagraphDialog.[Ch]
  public:
    void checkAlignmentRadioButtons();
    void alignmentToRadioButtons(LyXAlignment);
    LyXAlignment getAlignmentFromDialog();
  private:
    typedef std::map<LyXAlignment, QRadioButton *> QPRadioMap;
    QPRadioMap radioMap;
  protected Q_SLOTS:
    void change_adaptor();
    void enableLinespacingValue(int);
    void on_alignDefaultCB_toggled(bool);
QParagraph.C
  Rework apply() and update_contents() using new functions just
  mentioned.

Thanks to Abdel for his help.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17776 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2007-04-11 14:04:40 +00:00
parent 687bc61934
commit eb07cac2c3
4 changed files with 444 additions and 304 deletions

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Edwin Leuven * \author Edwin Leuven
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -15,8 +16,10 @@
#include "Qt2BC.h" #include "Qt2BC.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "debug.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "Spacing.h" #include "Spacing.h"
#include "layout.h"
#include "controllers/ControlParagraph.h" #include "controllers/ControlParagraph.h"
#include "controllers/helper_funcs.h" #include "controllers/helper_funcs.h"
@ -27,6 +30,7 @@
using std::string; using std::string;
using std::endl;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -56,25 +60,7 @@ void QParagraph::apply()
{ {
ParagraphParameters & params = controller().params(); ParagraphParameters & params = controller().params();
// alignment params.align(dialog_->getAlignmentFromDialog());
LyXAlignment align;
switch (dialog_->align->currentIndex()) {
case 0:
align = LYX_ALIGN_BLOCK;
break;
case 1:
align = LYX_ALIGN_LEFT;
break;
case 2:
align = LYX_ALIGN_RIGHT;
break;
case 3:
align = LYX_ALIGN_CENTER;
break;
default:
align = LYX_ALIGN_BLOCK;
}
params.align(align);
// get spacing // get spacing
Spacing::Space linespacing = Spacing::Default; Spacing::Space linespacing = Spacing::Default;
@ -124,26 +110,15 @@ void QParagraph::update_contents()
} }
// alignment // alignment
int i; LyXAlignment newAlignment = params.align();
switch (params.align()) { LyXAlignment defaultAlignment = controller().alignDefault();
case LYX_ALIGN_LEFT: bool alignmentIsDefault =
i = 1; newAlignment == LYX_ALIGN_LAYOUT || newAlignment == defaultAlignment;
break; dialog_->alignDefaultCB->setChecked(alignmentIsDefault);
case LYX_ALIGN_RIGHT: dialog_->checkAlignmentRadioButtons();
i = 2; dialog_->alignmentToRadioButtons(newAlignment);
break;
case LYX_ALIGN_CENTER:
i = 3;
break;
default:
i = 0;
break;
}
dialog_->align->setCurrentIndex(i);
//LyXAlignment alignpos = controller().alignPossible();
//indentation
dialog_->indentCB->setChecked(!params.noindent()); dialog_->indentCB->setChecked(!params.noindent());
// linespacing // linespacing

View File

@ -5,6 +5,7 @@
* *
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -21,6 +22,11 @@
#include <QCloseEvent> #include <QCloseEvent>
#include "qt_helpers.h" #include "qt_helpers.h"
#include "frontends/controllers/ControlParagraph.h"
#include "debug.h"
#include <map>
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -36,7 +42,17 @@ QParagraphDialog::QParagraphDialog(QParagraph * form)
form_, SLOT(slotApply())); form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()), connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose())); form_, SLOT(slotClose()));
connect(align, SIGNAL( activated(int) ), connect(restorePB, SIGNAL(clicked()),
form_, SLOT(slotRestore()));
connect(alignDefaultCB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(alignJustRB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(alignLeftRB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(alignRightRB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) );
connect(alignCenterRB, SIGNAL( clicked() ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
connect(linespacing, SIGNAL( activated(int) ), connect(linespacing, SIGNAL( activated(int) ),
this, SLOT( change_adaptor() ) ); this, SLOT( change_adaptor() ) );
@ -62,6 +78,11 @@ QParagraphDialog::QParagraphDialog(QParagraph * form)
" items is used. But if you need to, you can" " items is used. But if you need to, you can"
" change it here." " change it here."
)); ));
radioMap[LYX_ALIGN_BLOCK] = alignJustRB;
radioMap[LYX_ALIGN_LEFT] = alignLeftRB;
radioMap[LYX_ALIGN_RIGHT] = alignRightRB;
radioMap[LYX_ALIGN_CENTER] = alignCenterRB;
} }
@ -84,6 +105,64 @@ void QParagraphDialog::enableLinespacingValue(int)
linespacingValue->setEnabled(enable); linespacingValue->setEnabled(enable);
} }
void QParagraphDialog::checkAlignmentRadioButtons() {
if (alignDefaultCB->isChecked()) {
QPRadioMap::const_iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it)
it->second->setDisabled(true);
} else {
LyXAlignment alignPossible = form_->controller().alignPossible();
QPRadioMap::const_iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it)
it->second->setEnabled(it->first & alignPossible);
}
}
void QParagraphDialog::on_alignDefaultCB_toggled(bool)
{
checkAlignmentRadioButtons();
alignmentToRadioButtons();
}
void QParagraphDialog::alignmentToRadioButtons(LyXAlignment align)
{
if (align == LYX_ALIGN_LAYOUT)
align = form_->controller().alignDefault();
QPRadioMap::const_iterator it = radioMap.begin();
for (;it != radioMap.end(); ++it) {
if (align == it->first) {
it->second->setChecked(true);
return;
}
}
lyxerr << BOOST_CURRENT_FUNCTION << "Unknown alignment "
<< align << std::endl;
}
LyXAlignment QParagraphDialog::getAlignmentFromDialog()
{
if (alignDefaultCB->isChecked())
return LYX_ALIGN_LAYOUT;
LyXAlignment alignment = LYX_ALIGN_NONE;
QPRadioMap::const_iterator it = radioMap.begin();
for (; it != radioMap.end(); ++it) {
if (it->second->isChecked()) {
alignment = it->first;
break;
}
}
if (alignment == form_->controller().alignDefault())
return LYX_ALIGN_LAYOUT;
else return alignment;
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -6,6 +6,7 @@
* *
* \author John Levon * \author John Levon
* \author Edwin Leuven * \author Edwin Leuven
* \author Richard Heck
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -17,6 +18,7 @@
#include <QDialog> #include <QDialog>
#include <QCloseEvent> #include <QCloseEvent>
#include "layout.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -27,13 +29,25 @@ class QParagraphDialog : public QDialog, public Ui::QParagraphUi {
Q_OBJECT Q_OBJECT
public: public:
QParagraphDialog(QParagraph * form); QParagraphDialog(QParagraph * form);
///
void checkAlignmentRadioButtons();
///
void alignmentToRadioButtons(LyXAlignment align = LYX_ALIGN_LAYOUT);
///
LyXAlignment getAlignmentFromDialog();
protected: protected:
void closeEvent (QCloseEvent * e); void closeEvent (QCloseEvent * e);
private: private:
QParagraph * form_; QParagraph * form_;
typedef std::map<LyXAlignment, QRadioButton *> QPRadioMap;
QPRadioMap radioMap;
protected Q_SLOTS: protected Q_SLOTS:
///
void change_adaptor(); void change_adaptor();
///
void enableLinespacingValue(int); void enableLinespacingValue(int);
///
void on_alignDefaultCB_toggled(bool);
}; };
} // namespace frontend } // namespace frontend

View File

@ -1,300 +1,369 @@
<ui version="4.0" > <ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>QParagraphUi</class> <class>QParagraphUi</class>
<widget class="QDialog" name="QParagraphUi" > <widget class="QDialog" name="QParagraphUi" >
<property name="windowModality" >
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>396</width> <width>493</width>
<height>237</height> <height>334</height>
</rect> </rect>
</property> </property>
<property name="focusPolicy" >
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle" > <property name="windowTitle" >
<string/> <string/>
</property> </property>
<property name="sizeGripEnabled" > <property name="sizeGripEnabled" >
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <widget class="QWidget" name="layoutWidget" >
<property name="margin" > <property name="geometry" >
<number>11</number> <rect>
<x>10</x>
<y>10</y>
<width>468</width>
<height>301</height>
</rect>
</property> </property>
<property name="spacing" > <layout class="QVBoxLayout" >
<number>6</number> <property name="margin" >
</property> <number>0</number>
<item row="1" column="1" > </property>
<widget class="QComboBox" name="linespacing" > <property name="spacing" >
<item> <number>6</number>
<property name="text" > </property>
<string>Default</string> <item>
</property> <layout class="QHBoxLayout" >
</item>
<item>
<property name="text" >
<string>Single</string>
</property>
</item>
<item>
<property name="text" >
<string>1.5</string>
</property>
</item>
<item>
<property name="text" >
<string>Double</string>
</property>
</item>
<item>
<property name="text" >
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="linespacingL" >
<property name="text" >
<string>L&amp;ine spacing:</string>
</property>
<property name="buddy" >
<cstring>linespacing</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="align" >
<item>
<property name="text" >
<string>Justified</string>
</property>
</item>
<item>
<property name="text" >
<string>Left</string>
</property>
</item>
<item>
<property name="text" >
<string>Right</string>
</property>
</item>
<item>
<property name="text" >
<string>Center</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="alignL" >
<property name="text" >
<string>Alig&amp;nment:</string>
</property>
<property name="buddy" >
<cstring>align</cstring>
</property>
</widget>
</item>
<item rowspan="2" row="0" column="2" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="linespacingValue" >
<property name="enabled" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="3" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="indentCB" >
<property name="text" >
<string>In&amp;dent paragraph</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0" colspan="3" >
<widget class="QGroupBox" name="labelwidthGB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="title" >
<string>Label Width</string>
</property>
<layout class="QGridLayout" >
<property name="margin" > <property name="margin" >
<number>11</number> <number>0</number>
</property> </property>
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<item row="0" column="1" > <item>
<widget class="QLineEdit" name="labelWidth" > <layout class="QVBoxLayout" >
<property name="toolTip" > <property name="margin" >
<string>This text defines the width of the paragraph label</string> <number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QGroupBox" name="aligmentGB" >
<property name="title" >
<string>Alignment</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="alignDefaultCB" >
<property name="font" >
<font>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text" >
<string>&amp;Default</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alignJustRB" >
<property name="text" >
<string>&amp;Justified</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alignLeftRB" >
<property name="text" >
<string>&amp;Left</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alignRightRB" >
<property name="text" >
<string>&amp;Right</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="alignCenterRB" >
<property name="text" >
<string>&amp;Center</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="linespacingL" >
<property name="text" >
<string>L&amp;ine spacing:</string>
</property>
<property name="buddy" >
<cstring>linespacing</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="linespacing" >
<item>
<property name="text" >
<string>Default</string>
</property>
</item>
<item>
<property name="text" >
<string>Single</string>
</property>
</item>
<item>
<property name="text" >
<string>1.5</string>
</property>
</item>
<item>
<property name="text" >
<string>Double</string>
</property>
</item>
<item>
<property name="text" >
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLineEdit" name="linespacingValue" >
<property name="enabled" >
<bool>false</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="QCheckBox" name="indentCB" >
<property name="text" >
<string>Indent &amp;Paragraph</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="labelwidthGB" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="title" >
<string>Label Width</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>11</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="QLineEdit" name="labelWidth" >
<property name="toolTip" >
<string>This text defines the width of the paragraph label</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="TextLabel2" >
<property name="toolTip" >
<string>This text defines the width of the paragraph label</string>
</property>
<property name="text" >
<string>&amp;Longest label</string>
</property>
<property name="buddy" >
<cstring>labelWidth</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<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>
<property name="autoDefault" >
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item>
<widget class="QLabel" name="TextLabel2" > <spacer>
<property name="toolTip" > <property name="orientation" >
<string>This text defines the width of the paragraph label</string> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" > <property name="text" >
<string>&amp;Longest label</string> <string>&amp;OK</string>
</property> </property>
<property name="buddy" > <property name="autoDefault" >
<cstring>labelWidth</cstring> <bool>false</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </item>
</item> </layout>
<item row="4" column="2" > </widget>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="3" >
<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>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>&amp;Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget> </widget>
<pixmapfunction></pixmapfunction>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<tabstops> <tabstops>
<tabstop>align</tabstop>
<tabstop>linespacing</tabstop> <tabstop>linespacing</tabstop>
<tabstop>linespacingValue</tabstop> <tabstop>linespacingValue</tabstop>
<tabstop>indentCB</tabstop> <tabstop>indentCB</tabstop>
@ -304,6 +373,9 @@
<tabstop>applyPB</tabstop> <tabstop>applyPB</tabstop>
<tabstop>closePB</tabstop> <tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>