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

View File

@ -5,6 +5,7 @@
*
* \author John Levon
* \author Edwin Leuven
* \author Richard Heck
*
* Full author contact details are available in file CREDITS.
*/
@ -21,6 +22,11 @@
#include <QCloseEvent>
#include "qt_helpers.h"
#include "frontends/controllers/ControlParagraph.h"
#include "debug.h"
#include <map>
namespace lyx {
namespace frontend {
@ -36,7 +42,17 @@ QParagraphDialog::QParagraphDialog(QParagraph * form)
form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
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() ) );
connect(linespacing, SIGNAL( activated(int) ),
this, SLOT( change_adaptor() ) );
@ -62,6 +78,11 @@ QParagraphDialog::QParagraphDialog(QParagraph * form)
" items is used. But if you need to, you can"
" 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);
}
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 lyx

View File

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

View File

@ -1,300 +1,369 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>QParagraphUi</class>
<widget class="QDialog" name="QParagraphUi" >
<property name="windowModality" >
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>396</width>
<height>237</height>
<width>493</width>
<height>334</height>
</rect>
</property>
<property name="focusPolicy" >
<enum>Qt::NoFocus</enum>
</property>
<property name="windowTitle" >
<string/>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>11</number>
<widget class="QWidget" name="layoutWidget" >
<property name="geometry" >
<rect>
<x>10</x>
<y>10</y>
<width>468</width>
<height>301</height>
</rect>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="1" >
<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 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" >
<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>11</number>
<number>0</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>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<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>
</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>
<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;Longest label</string>
<string>&amp;OK</string>
</property>
<property name="buddy" >
<cstring>labelWidth</cstring>
<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>
</widget>
</item>
<item row="4" column="2" >
<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>
</item>
</layout>
</widget>
</widget>
<pixmapfunction></pixmapfunction>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<tabstops>
<tabstop>align</tabstop>
<tabstop>linespacing</tabstop>
<tabstop>linespacingValue</tabstop>
<tabstop>indentCB</tabstop>
@ -304,6 +373,9 @@
<tabstop>applyPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_helpers.h</include>
</includes>
<resources/>
<connections/>
</ui>