QVSpace dialog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8154 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2003-11-29 09:39:35 +00:00
parent 629bd3d17e
commit 2e1abd05a7
10 changed files with 787 additions and 1 deletions

View File

@ -86,6 +86,7 @@ src/frontends/qt2/QThesaurus.C
src/frontends/qt2/QToc.C
src/frontends/qt2/QURL.C
src/frontends/qt2/QVCLog.C
src/frontends/qt2/QVSpace.C
src/frontends/qt2/QWrap.C
src/frontends/qt2/Qt2BC.h
src/frontends/qt2/QtView.C
@ -106,6 +107,7 @@ src/frontends/xforms/FormCitation.C
src/frontends/xforms/FormColorpicker.C
src/frontends/xforms/FormDialogView.C
src/frontends/xforms/FormDocument.C
src/frontends/xforms/FormDocumentNew.C
src/frontends/xforms/FormERT.C
src/frontends/xforms/FormErrorList.C
src/frontends/xforms/FormExternal.C
@ -201,6 +203,7 @@ src/output_plaintext.C
src/paragraph.C
src/paragraph_funcs.C
src/rowpainter.C
src/support/path_defines.C
src/text.C
src/text2.C
src/text3.C

View File

@ -1,3 +1,12 @@
2003-11-29 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* QVSpace.[Ch]: (new)
* QVSpaceDialog.[Ch]: (new)
* ui/QVSpaceDialogBase.ui: (new)
* Makefile.am:
* Makefile.dialogs:
* Dialogs.C: new VSpace dialog.
2003-11-24 Alfredo Braunstein <abraunst@lyx.org>
* QContentpane.[Ch] (trackScrollbar): add

View File

@ -35,6 +35,7 @@
#include "ControlTabularCreate.h"
#include "ControlToc.h"
#include "ControlVCLog.h"
#include "ControlVSpace.h"
#include "ControlWrap.h"
#include "Qt2BC.h"
@ -70,6 +71,7 @@
#include "QToc.h"
#include "QURL.h"
#include "QVCLog.h"
#include "QVSpace.h"
#include "QWrap.h"
#ifdef HAVE_LIBAIKSAURUS
@ -94,7 +96,7 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch",
"thesaurus",
#endif
"toc", "url", "vclog", "wrap" };
"toc", "url", "vclog", "vspace", "wrap" };
char const * const * const end_dialognames =
dialognames + (sizeof(dialognames) / sizeof(char *));
@ -257,6 +259,10 @@ Dialog * Dialogs::build(string const & name)
dialog->setController(new ControlVCLog(*dialog));
dialog->setView(new QVCLog(*dialog));
dialog->bc().bp(new OkCancelPolicy);
} else if (name == "vspace") {
dialog->setController(new ControlVSpace(*dialog));
dialog->setView(new QVSpace(*dialog));
dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
} else if (name == "wrap") {
dialog->setController(new ControlWrap(*dialog));
dialog->setView(new QWrap(*dialog));

View File

@ -64,6 +64,7 @@ libqt2_la_SOURCES = \
QToc.C QToc.h \
QURL.C QURL.h \
QVCLog.C QVCLog.h \
QVSpace.C QVSpace.h \
QWorkArea.h QWorkArea.C \
QWrap.C QWrap.h \
Qt2BC.C Qt2BC.h \

View File

@ -66,6 +66,7 @@ UIFILES = \
QTocDialogBase.ui \
QURLDialogBase.ui \
QVCLogDialogBase.ui \
QVSpaceDialogBase.ui \
QWrapDialogBase.ui
MOCFILES = \
@ -124,6 +125,7 @@ MOCFILES = \
QtView.C QtView.h \
QURLDialog.C QURLDialog.h \
QVCLogDialog.C QVCLogDialog.h \
QVSpaceDialog.C QVSpaceDialog.h \
QWrapDialog.C QWrapDialog.h \
QLToolbar.C QLToolbar.h \
socket_callback.C socket_callback.h

233
src/frontends/qt2/QVSpace.C Normal file
View File

@ -0,0 +1,233 @@
/**
* \file QVSpace.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
* \author Jürgen Vigna
* \author Rob Lahaye
* \author Angus Leeming
* \author Edwin Leuven
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "debug.h"
#include "ControlVSpace.h"
#include "QVSpace.h"
#include "QVSpaceDialog.h"
#include "Qt2BC.h"
#include "lyxrc.h" // to set the deafult length values
#include "qt_helpers.h"
#include "helper_funcs.h"
#include "Spacing.h"
#include "vspace.h"
#include "support/lstrings.h"
#include "support/tostr.h"
#include <qcombobox.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.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;
namespace {
void setWidgetsFromVSpace(VSpace const & space,
QComboBox * spacing,
QLineEdit * value,
QComboBox * unit,
QCheckBox * keep, vector<string> units_)
{
value->setText("");
value->setEnabled(false);
unit->setEnabled(false);
int item = 0;
switch (space.kind()) {
case VSpace::NONE:
item = 0;
break;
case VSpace::DEFSKIP:
item = 1;
break;
case VSpace::SMALLSKIP:
item = 2;
break;
case VSpace::MEDSKIP:
item = 3;
break;
case VSpace::BIGSKIP:
item = 4;
break;
case VSpace::VFILL:
item = 5;
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());
}
VSpace setVSpaceFromWidgets(int spacing,
string value,
string unit,
bool keep)
{
VSpace space;
switch (spacing) {
case 0:
space = VSpace(VSpace::NONE);
break;
case 1:
space = VSpace(VSpace::DEFSKIP);
break;
case 2:
space = VSpace(VSpace::SMALLSKIP);
break;
case 3:
space = VSpace(VSpace::MEDSKIP);
break;
case 4:
space = VSpace(VSpace::BIGSKIP);
break;
case 5:
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));
break;
}
space.setKeep(keep);
return space;
}
} // namespace anon
typedef QController<ControlVSpace, QView<QVSpaceDialog> > base_class;
QVSpace::QVSpace(Dialog & parent)
: base_class(parent, _("LyX: VSpace Settings"))
{}
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);
bcview().setCancel(dialog_->closePB);
bcview().setRestore(dialog_->restorePB);
// disable for read-only documents
bcview().addReadOnly(dialog_->spacingCO);
bcview().addReadOnly(dialog_->valueLE);
bcview().addReadOnly(dialog_->unitCO);
bcview().addReadOnly(dialog_->keepCB);
}
void QVSpace::apply()
{
// spacing
// If a vspace choice is "Length" but there's no text in
// the input field, reset the choice to "None".
if (dialog_->spacingCO->currentItem() == 6
&& dialog_->valueLE->text().isEmpty())
dialog_->spacingCO->setCurrentItem(0);
VSpace const space =
setVSpaceFromWidgets(dialog_->spacingCO->currentItem(),
fromqstr(dialog_->valueLE->text()),
fromqstr(dialog_->unitCO->currentText()),
dialog_->keepCB->isChecked());
controller().params() = space;
}
void QVSpace::update_contents()
{
setWidgetsFromVSpace(controller().params(),
dialog_->spacingCO,
dialog_->valueLE,
dialog_->unitCO,
dialog_->keepCB, units_);
}

View File

@ -0,0 +1,45 @@
// -*- C++ -*-
/**
* \file QVSpace.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
* \author Angus Leeming
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#ifndef QVSPACE_H
#define QVSPACE_H
#include "QDialogView.h"
#include <vector>
class ControlVSpace;
class QVSpaceDialog;
/** This class provides an Qt implementation of the VSpace dialog.
*/
class QVSpace
: public QController<ControlVSpace, QView<QVSpaceDialog> >
{
public:
///
friend class QVSpaceDialog;
///
QVSpace(Dialog &);
private:
/// Build the dialog
virtual void build_dialog();
/// Apply from dialog
virtual void apply();
/// Update the dialog
virtual void update_contents();
std::vector<std::string> units_;
};
#endif //QVSPACE_H

View File

@ -0,0 +1,58 @@
/**
* \file QVSpaceDialog.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
* \author Edwin Leuven
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "QVSpaceDialog.h"
#include "QVSpace.h"
#include <qlineedit.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qvalidator.h>
#include "qt_helpers.h"
QVSpaceDialog::QVSpaceDialog(QVSpace * form)
: QVSpaceDialogBase(0, 0, false, 0),
form_(form)
{
connect(okPB, SIGNAL(clicked()),
form_, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()),
form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose()));
}
void QVSpaceDialog::closeEvent(QCloseEvent * e)
{
form_->slotWMHide();
e->accept();
}
void QVSpaceDialog::change_adaptor()
{
form_->changed();
}
void QVSpaceDialog::enableCustom(int)
{
bool const enable = spacingCO->currentItem()==6;
valueLE->setEnabled(enable);
unitCO->setEnabled(enable);
}

View File

@ -0,0 +1,38 @@
// -*- C++ -*-
/**
* \file QVSpaceDialog.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
* \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#ifndef QVSPACEDIALOG_H
#define QVSPACEDIALOG_H
#include "ui/QVSpaceDialogBase.h"
class QVSpace;
class QVSpaceDialog : public QVSpaceDialogBase {
Q_OBJECT
public:
QVSpaceDialog(QVSpace * form);
public slots:
void change_adaptor();
protected:
void closeEvent(QCloseEvent *);
void enableCustom(int);
private:
QVSpace * form_;
};
#endif // QVSPACEDIALOG_H

View File

@ -0,0 +1,391 @@
<!DOCTYPE UI><UI>
<class>QVSpaceDialogBase</class>
<include location="global">config.h</include>
<include location="local">qt_helpers.h</include>
<widget>
<class>QDialog</class>
<property stdset="1">
<name>name</name>
<cstring>QVSpaceDialogBase</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<height>140</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Form1</string>
</property>
<property stdset="1">
<name>sizeGripEnabled</name>
<bool>true</bool>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>spacingL</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Spacing:</string>
</property>
<property>
<name>buddy</name>
<cstring>spacingCO</cstring>
</property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>valueL</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Value:</string>
</property>
<property>
<name>buddy</name>
<cstring>valueLE</cstring>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>keepL</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Protect:</string>
</property>
<property>
<name>buddy</name>
<cstring>keepCB</cstring>
</property>
<property>
<name>toolTip</name>
<string></string>
</property>
</widget>
<widget row="2" column="1" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>keepCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string></string>
</property>
<property>
<name>toolTip</name>
<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">
<name>name</name>
<cstring>valueLE</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="0" column="1" >
<class>QComboBox</class>
<item>
<property>
<name>text</name>
<string>None</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>DefSkip</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>SmallSkip</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>MedSkip</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>BigSkip</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>VFill</string>
</property>
</item>
<item>
<property>
<name>text</name>
<string>Custom</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>spacingCO</cstring>
</property>
<property>
<name>toolTip</name>
<string>Supported spacing types</string>
</property>
</widget>
<spacer row="0" column="2" >
<property>
<name>name</name>
<cstring>Spacer8</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>
<spacer row="2" column="2" >
<property>
<name>name</name>
<cstring>Spacer9</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>
<widget row="4" column="0" rowspan="1" colspan="3" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout5</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>restorePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Restore</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer1</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>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>okPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;OK</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
<property stdset="1">
<name>default</name>
<bool>true</bool>
</property>
</widget>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>applyPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Apply</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
</widget>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>closePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Close</string>
</property>
<property stdset="1">
<name>autoDefault</name>
<bool>false</bool>
</property>
</widget>
</hbox>
</widget>
<spacer row="3" column="1" >
<property>
<name>name</name>
<cstring>Spacer28</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Vertical</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>
<connections>
<connection>
<sender>spacingCO</sender>
<signal>highlighted(const QString&amp;)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>valueLE</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>unitCO</sender>
<signal>highlighted(const QString&amp;)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>keepCB</sender>
<signal>checked()</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>change_adaptor()</slot>
</connection>
<connection>
<sender>spacingCO</sender>
<signal>activated(int)</signal>
<receiver>QVSpaceDialogBase</receiver>
<slot>enableCustom(int)</slot>
</connection>
<slot access="protected">change_adaptor()</slot>
<slot access="protected">enableCustom(int)</slot>
</connections>
<tabstops>
<tabstop>restorePB</tabstop>
<tabstop>okPB</tabstop>
<tabstop>applyPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
</UI>