character dialog with auto-apply ...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2590 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2001-08-26 17:49:42 +00:00
parent b90b704bdd
commit 3c7fe2f407
7 changed files with 651 additions and 845 deletions

View File

@ -1,3 +1,11 @@
2001-08-26 John Levon <moz@compsoc.man.ac.uk>
* Dialogs.C:
* QCharacter.[Ch]:
* QCharacterDialog.[Ch]:
* ui/QcharacterDialog.ui: make work again,
add auto-apply feature
2001-08-26 John Levon <moz@compsoc.man.ac.uk>
* Dialogs.C:

View File

@ -15,6 +15,7 @@
#include "QAboutDialog.h"
#include "QBibitemDialog.h"
#include "QBibtexDialog.h"
#include "QCharacterDialog.h"
#include "QCitationDialog.h"
#include "QIndexDialog.h"
#include "QRefDialog.h"
@ -44,6 +45,7 @@
#include "controllers/ControlAboutlyx.h"
#include "controllers/ControlBibitem.h"
#include "controllers/ControlBibtex.h"
#include "controllers/ControlCharacter.h"
#include "controllers/ControlCitation.h"
#include "controllers/ControlIndex.h"
#include "controllers/ControlRef.h"
@ -51,7 +53,6 @@
#include "controllers/ControlUrl.h"
#if 0
#include "controllers/ControlButtons.h"
#include "controllers/ControlCharacter.h"
#include "controllers/ControlCitation.h"
#include "controllers/ControlERT.h"
#include "controllers/ControlError.h"
@ -88,6 +89,7 @@ Dialogs::Dialogs(LyXView * lv)
add(new GUIAboutlyx<QAbout, Qt2BC>(*lv, *this));
add(new GUIBibitem<QBibitem, Qt2BC>(*lv, *this));
add(new GUIBibtex<QBibtex, Qt2BC>(*lv, *this));
add(new GUICharacter<QCharacter, Qt2BC>(*lv, *this));
add(new GUIIndex<QIndex, Qt2BC>(*lv, *this));
add(new GUIRef<QRef, Qt2BC>(*lv, *this));
add(new GUIUrl<QURL, Qt2BC>(*lv, *this));

View File

@ -1,104 +1,141 @@
/**
* \file QCharacter.C
* Copyright 2001 The LyX Team.
* See the file COPYING.
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author Edwin Leuven, leuven@fee.uva.nl
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#include <config.h>
#include "gettext.h"
#include "support/lstrings.h"
#include "ControlCharacter.h"
#include "QCharacterDialog.h"
#include "QCharacter.h"
#include "bufferview_funcs.h"
#include "Dialogs.h"
#include "Liason.h"
#include "QtLyXView.h"
#include "buffer.h"
#include "lyxtext.h"
#include "language.h"
#include "support/lstrings.h"
#include "BufferView.h"
#include "Qt2BC.h"
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
using SigC::slot;
using Liason::setMinibuffer;
QCharacter::QCharacter(LyXView *v, Dialogs *d)
: dialog_(0), lv_(v), d_(d), h_(0), u_(0)
using namespace character;
using std::vector;
typedef Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> > base_class;
QCharacter::QCharacter(ControlCharacter & c)
: base_class(c, _("Character"))
{
d->showCharacter.connect(slot(this, &QCharacter::show));
// for LFUN_FREE
d->setUserFreeFont.connect(slot(this, &QCharacter::apply));
}
QCharacter::~QCharacter()
void QCharacter::build_dialog()
{
delete dialog_;
dialog_.reset(new QCharacterDialog(this));
family = getFamilyData();
series = getSeriesData();
shape = getShapeData();
size = getSizeData();
bar = getBarData();
color = getColorData();
language = getLanguageData();
for (vector<FamilyPair>::const_iterator cit = family.begin();
cit != family.end(); ++cit) {
dialog_->familyCO->insertItem(cit->first.c_str(), -1);
}
for (vector<SeriesPair>::const_iterator cit = series.begin();
cit != series.end(); ++cit) {
dialog_->seriesCO->insertItem(cit->first.c_str(), -1);
}
for (vector<ShapePair>::const_iterator cit = shape.begin();
cit != shape.end(); ++cit) {
dialog_->shapeCO->insertItem(cit->first.c_str(), -1);
}
for (vector<SizePair>::const_iterator cit = size.begin();
cit != size.end(); ++cit) {
dialog_->sizeCO->insertItem(cit->first.c_str(), -1);
}
for (vector<BarPair>::const_iterator cit = bar.begin();
cit != bar.end(); ++cit) {
dialog_->miscCO->insertItem(cit->first.c_str(), -1);
}
for (vector<ColorPair>::const_iterator cit = color.begin();
cit != color.end(); ++cit) {
dialog_->colorCO->insertItem(cit->first.c_str(), -1);
}
for (vector<string>::const_iterator cit = language.begin();
cit != language.end(); ++cit) {
dialog_->langCO->insertItem(cit->c_str(), -1);
}
bc().setOK(dialog_->okPB);
bc().setApply(dialog_->applyPB);
bc().setCancel(dialog_->closePB);
bc().addReadOnly(dialog_->familyCO);
bc().addReadOnly(dialog_->seriesCO);
bc().addReadOnly(dialog_->sizeCO);
bc().addReadOnly(dialog_->shapeCO);
bc().addReadOnly(dialog_->miscCO);
bc().addReadOnly(dialog_->langCO);
bc().addReadOnly(dialog_->colorCO);
bc().addReadOnly(dialog_->toggleallCB);
bc().addReadOnly(dialog_->autoapplyCB);
}
void QCharacter::apply()
namespace {
template<class A, class B>
int findPos2nd(vector<std::pair<A,B> > const & vec, B const & val)
{
if (!lv_->view()->available() || !dialog_)
return;
LyXFont font = dialog_->getChar();
if (dialog_->langItem()==1)
font.setLanguage(lv_->buffer()->params.language);
toggleAndShow(lv_->view(), font, dialog_->toggleAll());
lv_->view()->setState();
lv_->buffer()->markDirty();
setMinibuffer(lv_, _("Character set"));
vector<std::pair<A,B> >::const_iterator cit = vec.begin();
for (; cit != vec.end(); ++cit) {
if (cit->second == val)
return int(cit - vec.begin());
}
return 0;
}
void QCharacter::show()
{
if (!dialog_) {
dialog_ = new QCharacterDialog(this, 0, _("Character Settings"), false);
} // namespace anon
// add languages
for (Languages::const_iterator cit = languages.begin();
cit != languages.end(); ++cit) {
string const language = cit->second.lang();
dialog_->lang->insertItem(tostr(language).c_str(), -1);
void QCharacter::update_contents()
{
dialog_->familyCO->setCurrentItem(findPos2nd(family, controller().getFamily()));
dialog_->seriesCO->setCurrentItem(findPos2nd(series, controller().getSeries()));
dialog_->shapeCO->setCurrentItem(findPos2nd(shape, controller().getShape()));
dialog_->sizeCO->setCurrentItem(findPos2nd(size, controller().getSize()));
dialog_->miscCO->setCurrentItem(findPos2nd(bar, controller().getBar()));
dialog_->colorCO->setCurrentItem(findPos2nd(color, controller().getColor()));
dialog_->toggleallCB->setChecked(controller().getToggleAll());
string const thelanguage(controller().getLanguage());
int i = 0;
for (vector<string>::const_iterator cit = language.begin();
cit != language.end(); ++i, ++cit) {
if (*cit == thelanguage) {
dialog_->langCO->setCurrentItem(i);
break;
}
}
if (!dialog_->isVisible()) {
h_ = d_->hideBufferDependent.connect(slot(this, &QCharacter::hide));
u_ = d_->updateBufferDependent.connect(slot(this, &QCharacter::update));
}
dialog_->raise();
dialog_->setActiveWindow();
update();
dialog_->show();
}
void QCharacter::close()
void QCharacter::apply()
{
h_.disconnect();
u_.disconnect();
}
void QCharacter::hide()
{
dialog_->hide();
close();
}
void QCharacter::update(bool)
{
if (!lv_->view()->available())
return;
dialog_->setReadOnly(lv_->buffer()->isReadonly());
controller().setFamily(family[dialog_->familyCO->currentItem()].second);
controller().setSeries(series[dialog_->seriesCO->currentItem()].second);
controller().setShape(shape[dialog_->shapeCO->currentItem()].second);
controller().setSize(size[dialog_->sizeCO->currentItem()].second);
controller().setBar(bar[dialog_->miscCO->currentItem()].second);
controller().setColor(color[dialog_->colorCO->currentItem()].second);
controller().setLanguage(dialog_->langCO->currentText().latin1());
controller().setToggleAll(dialog_->toggleallCB->isChecked());
}

View File

@ -1,61 +1,50 @@
// -*- C++ -*-
/**
* \file QCharacter.h
* Copyright 2001 The LyX Team.
* See the file COPYING.
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author Edwin Leuven
* \author Edwin Leuven, leuven@fee.uva.nl
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QCHARACTER_H
#define QCHARACTER_H
#include "DialogBase.h"
#include <config.h>
#include <vector>
#include "LString.h"
#include "Qt2Base.h"
#include "controllers/character.h"
class LyXView;
class Dialogs;
class ControlCharacter;
class QCharacterDialog;
class QCharacter : public DialogBase {
public:
///
QCharacter(LyXView *, Dialogs *);
///
~QCharacter();
class QCharacter :
public Qt2CB<ControlCharacter, Qt2DB<QCharacterDialog> >
{
friend class QCharacterDialog;
public:
QCharacter(ControlCharacter &);
/// Apply changes.
void apply();
/// Close connections.
void close();
private:
/// Show the dialog.
void show();
/// Hide the dialog.
void hide();
/// Update the dialog.
void update(bool switched = false);
/// Real GUI implementation.
QCharacterDialog * dialog_;
/// the LyXView we belong to.
LyXView * lv_;
/** Which Dialogs do we belong to?
* Used so we can get at the signals we have to connect to.
*/
Dialogs * d_;
/// is the buffer readonly?
bool readonly;
/// Hide connection.
SigC::Connection h_;
/// Update connection.
SigC::Connection u_;
private:
/// Apply changes
virtual void apply();
/// update
virtual void update_contents();
/// build the dialog
virtual void build_dialog();
std::vector<character::FamilyPair> family;
std::vector<character::SeriesPair> series;
std::vector<character::ShapePair> shape;
std::vector<character::SizePair> size;
std::vector<character::BarPair> bar;
std::vector<character::ColorPair> color;
std::vector<string> language;
};
#endif // QCHARACTER_H

View File

@ -7,125 +7,49 @@
*/
#include "QCharacterDialog.h"
#include "lyxtext.h"
#include "language.h"
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
QCharacterDialog::QCharacterDialog(QCharacter * form, QWidget * parent, const char * name, bool modal, WFlags fl)
: QCharacterDialogBase(parent, name, modal, fl), form_(form)
QCharacterDialog::QCharacterDialog(QCharacter * form)
: QCharacterDialogBase(0, 0, false, 0),
form_(form)
{
setCaption(name);
connect(okPB, SIGNAL(clicked()),
form_, SLOT(slotOK()));
connect(applyPB, SIGNAL(clicked()),
form_, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose()));
}
QCharacterDialog::~QCharacterDialog()
void QCharacterDialog::change_adaptor()
{
}
form_->changed();
if (!autoapplyCB->isChecked())
return;
LyXFont QCharacterDialog::getChar()
{
LyXFont font(LyXFont::ALL_IGNORE);
switch (family->currentItem()) {
case 0: font.setFamily(LyXFont::IGNORE_FAMILY); break;
case 1: font.setFamily(LyXFont::INHERIT_FAMILY); break;
case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
}
switch (series->currentItem()) {
case 0: font.setSeries(LyXFont::IGNORE_SERIES); break;
case 1: font.setSeries(LyXFont::INHERIT_SERIES); break;
case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
}
switch (shape->currentItem()) {
case 0: font.setShape(LyXFont::IGNORE_SHAPE); break;
case 1: font.setShape(LyXFont::INHERIT_SHAPE); break;
case 2: font.setShape(LyXFont::UP_SHAPE); break;
case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
}
switch (size->currentItem()) {
case 0: font.setSize(LyXFont::IGNORE_SIZE); break;
case 1: font.setSize(LyXFont::INHERIT_SIZE); break;
case 2: font.setSize(LyXFont::SIZE_TINY); break;
case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
case 5: font.setSize(LyXFont::SIZE_SMALL); break;
case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
case 7: font.setSize(LyXFont::SIZE_LARGE); break;
case 8: font.setSize(LyXFont::SIZE_LARGER); break;
case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
case 10: font.setSize(LyXFont::SIZE_HUGE); break;
case 11: font.setSize(LyXFont::SIZE_HUGER); break;
case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
}
switch (misc->currentItem()) {
case 0: font.setEmph(LyXFont::IGNORE);
font.setUnderbar(LyXFont::IGNORE);
font.setNoun(LyXFont::IGNORE);
// FIXME font.setLatex(LyXFont::IGNORE);
break;
case 1: font.setEmph(LyXFont::INHERIT);
font.setUnderbar(LyXFont::INHERIT);
font.setNoun(LyXFont::INHERIT);
// FIXME font.setLatex(LyXFont::INHERIT);
break;
case 2: font.setEmph(LyXFont::TOGGLE); break;
case 3: font.setUnderbar(LyXFont::TOGGLE); break;
case 4: font.setNoun(LyXFont::TOGGLE); break;
case 5: break; // FIXMEfont.setLatex(LyXFont::TOGGLE); break;
}
switch (color->currentItem()) {
case 0: font.setColor(LColor::ignore); break;
case 1: font.setColor(LColor::inherit); break;
case 2: font.setColor(LColor::none); break;
case 3: font.setColor(LColor::black); break;
case 4: font.setColor(LColor::white); break;
case 5: font.setColor(LColor::red); break;
case 6: font.setColor(LColor::green); break;
case 7: font.setColor(LColor::blue); break;
case 8: font.setColor(LColor::cyan); break;
case 9: font.setColor(LColor::magenta); break;
case 10: font.setColor(LColor::yellow); break;
}
int const pos = lang->currentItem();
if (pos == 0) {
font.setLanguage(ignore_language);
} else if (pos != 1) {
font.setLanguage(languages.getLanguage(lang->currentText().latin1()));
};
return font;
// to be really good here, we should set the combos to the values of
// the current text, and make it appear as "no change" if the values
// stay the same between applys. Might be difficult though wrt to a
// moved cursor - jbl
form_->slotApply();
familyCO->setCurrentItem(0);
seriesCO->setCurrentItem(0);
sizeCO->setCurrentItem(0);
shapeCO->setCurrentItem(0);
miscCO->setCurrentItem(0);
langCO->setCurrentItem(0);
colorCO->setCurrentItem(0);
}
void QCharacterDialog::closeEvent(QCloseEvent * e)
{
form_->close();
form_->slotWMHide();
e->accept();
}
void QCharacterDialog::setReadOnly(bool readonly)
{
sizeGB->setEnabled(!readonly);
charGB->setEnabled(!readonly);
miscGB->setEnabled(!readonly);
okPB->setEnabled(!readonly);
applyPB->setEnabled(!readonly);
}

View File

@ -4,6 +4,7 @@
* see the file COPYING
*
* \author Edwin Leuven
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QCHARACTERDIALOG_H
@ -24,24 +25,7 @@ class QCharacterDialog : public QCharacterDialogBase
{ Q_OBJECT
public:
QCharacterDialog(QCharacter * form, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0);
~QCharacterDialog();
/// FIXME
LyXFont getChar();
/// return the currently selected language item
int langItem() {
return lang->currentItem();
};
/// return true if toggle all is selected
bool toggleAll() {
return toggleall->isChecked();
};
/// set dialog read only
void setReadOnly(bool);
QCharacterDialog(QCharacter * form);
protected:
void closeEvent(QCloseEvent * e);
@ -50,22 +34,7 @@ private:
QCharacter * form_;
protected slots:
void apply_adaptor() {
form_->apply();
}
void cancel_adaptor() {
form_->close();
hide();
}
void close_adaptor() {
form_->apply();
form_->close();
hide();
}
void change_adaptor();
};
#endif // QCHARACTERDIALOG_H

File diff suppressed because it is too large Load Diff