From 76e3fbcf7a245529df5049b0ccacc8c43803d295 Mon Sep 17 00:00:00 2001 From: Edwin Leuven Date: Sat, 15 Sep 2007 17:09:57 +0000 Subject: [PATCH] * new file formats panel that includes copier git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20292 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/qmake/qt4/qt4.pro | 1 - development/scons/scons_manifest.py | 1 - src/Format.h | 56 +-- src/frontends/qt4/GuiPrefs.cpp | 582 +++++++--------------- src/frontends/qt4/GuiPrefs.h | 70 ++- src/frontends/qt4/Makefile.am | 1 - src/frontends/qt4/ui/PrefCopiersUi.ui | 133 ----- src/frontends/qt4/ui/PrefFileformatsUi.ui | 369 ++++++-------- src/frontends/qt4/ui/compile_uic.sh | 1 - 9 files changed, 404 insertions(+), 810 deletions(-) delete mode 100644 src/frontends/qt4/ui/PrefCopiersUi.ui diff --git a/development/qmake/qt4/qt4.pro b/development/qmake/qt4/qt4.pro index d922829972..649aa6c768 100644 --- a/development/qmake/qt4/qt4.pro +++ b/development/qmake/qt4/qt4.pro @@ -212,7 +212,6 @@ UI += ParagraphUi.ui UI += PreambleUi.ui UI += PrefColorsUi.ui UI += PrefConvertersUi.ui -UI += PrefCopiersUi.ui UI += PrefCygwinPathUi.ui UI += PrefDateUi.ui UI += PrefDisplayUi.ui diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index f77a88d444..4a9e52335b 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -1051,7 +1051,6 @@ src_frontends_qt4_ui_files = Split(''' PreambleUi.ui PrefColorsUi.ui PrefConvertersUi.ui - PrefCopiersUi.ui PrefCygwinPathUi.ui PrefDateUi.ui PrefDisplayUi.ui diff --git a/src/Format.h b/src/Format.h index 295c5ab8bf..7b1bab8a94 100644 --- a/src/Format.h +++ b/src/Format.h @@ -47,45 +47,35 @@ public: /// Name fo the parent format std::string const parentFormat() const; /// - std::string const & name() const { - return name_; - } + std::string const & name() const { return name_; } /// - std::string const & extension() const { - return extension_; - } + void setName(std::string const & v) { name_ = v; } /// - std::string const & prettyname() const { - return prettyname_; - } + std::string const & extension() const { return extension_; } /// - std::string const & shortcut() const { - return shortcut_; - } + void setExtension(std::string const & v) { extension_ = v; } /// - std::string const & viewer() const { - return viewer_; - } + std::string const & prettyname() const { return prettyname_; } /// - void setViewer(std::string const & v) { - viewer_ = v; - } + void setPrettyname(std::string const & v) { prettyname_ = v; } /// - std::string const & editor() const { - return editor_; - } + std::string const & shortcut() const { return shortcut_; } /// - void setEditor(std::string const & v) { - editor_ = v; - } + void setShortcut(std::string const & v) { shortcut_ = v; } /// - bool documentFormat() const { - return flags_ & document; - } + std::string const & viewer() const { return viewer_; } /// - bool vectorFormat() const { - return flags_ & vector; - } + void setViewer(std::string const & v) { viewer_ = v; } + /// + std::string const & editor() const { return editor_; } + /// + void setEditor(std::string const & v) { editor_ = v; } + /// + bool documentFormat() const { return flags_ & document; } + /// + bool vectorFormat() const { return flags_ & vector; } + /// + void setFlags(int v) { flags_ = v; } private: /// Internal name. Needs to be unique. std::string name_; @@ -121,9 +111,9 @@ public: /// typedef FormatList::const_iterator const_iterator; /// - Format const & get(FormatList::size_type i) const { - return formatlist[i]; - } + Format const & get(FormatList::size_type i) const { return formatlist[i]; } + /// + Format & get(FormatList::size_type i) { return formatlist[i]; } /// \returns format named \p name if it exists, otherwise 0 Format const * getFormat(std::string const & name) const; /*! diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index ac4ecebc5e..28fc43e630 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1107,299 +1107,94 @@ void PrefConverters::on_cacheCB_stateChanged(int state) } -///////////////////////////////////////////////////////////////////// -// -// PrefCopiers -// -///////////////////////////////////////////////////////////////////// - -PrefCopiers::PrefCopiers(GuiPrefsDialog * form, QWidget * parent) - : PrefModule(_("Copiers"), form, parent) -{ - setupUi(this); - - connect(copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier())); - connect(copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier())); - connect(copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier())); - connect(AllCopiersLW, SIGNAL(currentRowChanged(int)), - this, SLOT(switch_copierLB(int))); - connect(copierFormatCO, SIGNAL(activated(int)), - this, SLOT(switch_copierCO(int))); - connect(copierNewPB, SIGNAL(clicked()), - this, SIGNAL(changed())); - connect(copierRemovePB, SIGNAL(clicked()), - this, SIGNAL(changed())); - connect(copierModifyPB, SIGNAL(clicked()), - this, SIGNAL(changed())); - connect(copierFormatCO, SIGNAL(activated(const QString &)), - this, SLOT(copiers_changed())); - connect(copierED, SIGNAL(textChanged(const QString &)), - this, SLOT(copiers_changed())); -} - - -void PrefCopiers::apply(LyXRC & /*rc*/) const -{ -} - - -void PrefCopiers::update(LyXRC const & /*rc*/) -{ - updateView(); -} - - -void PrefCopiers::updateView() -{ - // The choice widget - // save current selection - QString current = copierFormatCO->currentText(); - copierFormatCO->clear(); - - for (Formats::const_iterator it = form_->formats().begin(), - end = form_->formats().end(); - it != end; ++it) { - copierFormatCO->addItem(toqstr(it->prettyname())); - } - - // The browser widget - AllCopiersLW->clear(); - - for (Movers::const_iterator it = form_->movers().begin(), - end = form_->movers().end(); - it != end; ++it) { - std::string const & command = it->second.command(); - if (command.empty()) - continue; - QString const pretty = toqstr(form_->formats().prettyName(it->first)); - AllCopiersLW->addItem(pretty); - } - AllCopiersLW->sortItems(Qt::AscendingOrder); - - // restore selection - if (!current.isEmpty()) { - QList item = - AllCopiersLW->findItems(current, Qt::MatchExactly); - if (item.size()>0) - AllCopiersLW->setCurrentItem(item.at(0)); - } - // select first element if restoring failed - if (AllCopiersLW->currentRow() == -1) - AllCopiersLW->setCurrentRow(0); -} - - -namespace { - -class SamePrettyName { -public: - SamePrettyName(string const & n) : pretty_name_(n) {} - - bool operator()(Format const & fmt) const { - return fmt.prettyname() == pretty_name_; - } - -private: - string const pretty_name_; -}; - - -Format const * getFormat(std::string const & prettyname) -{ - Formats::const_iterator it = formats.begin(); - Formats::const_iterator const end = formats.end(); - it = std::find_if(it, end, SamePrettyName(prettyname)); - return it == end ? 0 : &*it; -} - -} // namespace anon - - -void PrefCopiers::switch_copierLB(int row) -{ - if (row < 0) - return; - - // FIXME UNICODE? - std::string const browser_text = - fromqstr(AllCopiersLW->currentItem()->text()); - Format const * fmt = getFormat(browser_text); - if (fmt == 0) - return; - - QString const gui_name = toqstr(fmt->prettyname()); - QString const command = toqstr(form_->movers().command(fmt->name())); - - copierED->clear(); - int const combo_size = copierFormatCO->count(); - for (int i = 0; i < combo_size; ++i) { - QString const text = copierFormatCO->itemText(i); - if (text == gui_name) { - copierFormatCO->setCurrentIndex(i); - copierED->setText(command); - break; - } - } - updateButtons(); -} - - -void PrefCopiers::switch_copierCO(int row) -{ - if (row<0) - return; - - std::string const combo_text = - fromqstr(copierFormatCO->currentText()); - Format const * fmt = getFormat(combo_text); - if (fmt == 0) - return; - - QString const command = toqstr(form_->movers().command(fmt->name())); - copierED->setText(command); - - QListWidgetItem * const index = AllCopiersLW->currentItem(); - if (index >= 0) - AllCopiersLW->setItemSelected(index, false); - - QString const gui_name = toqstr(fmt->prettyname()); - int const browser_size = AllCopiersLW->count(); - for (int i = 0; i < browser_size; ++i) { - QString const text = AllCopiersLW->item(i)->text(); - if (text == gui_name) { - QListWidgetItem * item = AllCopiersLW->item(i); - AllCopiersLW->setItemSelected(item, true); - break; - } - } -} - - -void PrefCopiers::copiers_changed() -{ - updateButtons(); -} - - -void PrefCopiers::updateButtons() -{ - QString selected = copierFormatCO->currentText(); - - bool known = false; - for (int i = 0; i < AllCopiersLW->count(); ++i) { - if (AllCopiersLW->item(i)->text() == selected) - known = true; - } - - bool const valid = !copierED->text().isEmpty(); - - Format const * fmt = getFormat(fromqstr(selected)); - string const old_command = form_->movers().command(fmt->name()); - string const new_command(fromqstr(copierED->text())); - - bool modified = (old_command != new_command); - - copierModifyPB->setEnabled(valid && known && modified); - copierNewPB->setEnabled(valid && !known); - copierRemovePB->setEnabled(known); -} - - -void PrefCopiers::new_copier() -{ - std::string const combo_text = - fromqstr(copierFormatCO->currentText()); - Format const * fmt = getFormat(combo_text); - if (fmt == 0) - return; - - string const command = fromqstr(copierED->text()); - if (command.empty()) - return; - - form_->movers().set(fmt->name(), command); - - updateView(); - int const last = AllCopiersLW->count() - 1; - AllCopiersLW->setCurrentRow(last); - - updateButtons(); -} - - -void PrefCopiers::modify_copier() -{ - std::string const combo_text = - fromqstr(copierFormatCO->currentText()); - Format const * fmt = getFormat(combo_text); - if (fmt == 0) - return; - - string const command = fromqstr(copierED->text()); - form_->movers().set(fmt->name(), command); - - updateView(); - updateButtons(); -} - - -void PrefCopiers::remove_copier() -{ - std::string const combo_text = - fromqstr(copierFormatCO->currentText()); - Format const * fmt = getFormat(combo_text); - if (fmt == 0) - return; - - string const & fmt_name = fmt->name(); - form_->movers().set(fmt_name, string()); - - updateView(); - updateButtons(); -} - - - ///////////////////////////////////////////////////////////////////// // // PrefFileformats // ///////////////////////////////////////////////////////////////////// +FormatValidator::FormatValidator(QWidget * parent, Formats const & f) + : QValidator(parent), formats_(f) +{ +} + + +void FormatValidator::fixup(QString & input) const +{ + Formats::const_iterator cit = formats_.begin(); + Formats::const_iterator end = formats_.end(); + for (; cit != end; ++cit) { + string const name = str(cit); + if (distance(formats_.begin(), cit) == nr()) { + input = toqstr(name); + return; + + } + } +} + + +QValidator::State FormatValidator::validate(QString & input, int & pos) const +{ + Formats::const_iterator cit = formats_.begin(); + Formats::const_iterator end = formats_.end(); + bool unknown = true; + for (; unknown && cit != end; ++cit) { + string const name = str(cit); + if (distance(formats_.begin(), cit) != nr()) + unknown = toqstr(name) != input; + } + + if (unknown && !input.isEmpty()) + return QValidator::Acceptable; + else + return QValidator::Intermediate; +} + + +int FormatValidator::nr() const +{ + QComboBox * p = qobject_cast(parent()); + return p->itemData(p->currentIndex()).toInt(); +} + + +FormatNameValidator::FormatNameValidator(QWidget * parent, Formats const & f) + : FormatValidator(parent, f) +{ +} + +std::string FormatNameValidator::str(Formats::const_iterator it) const +{ + return it->name(); +} + + +FormatPrettynameValidator::FormatPrettynameValidator(QWidget * parent, Formats const & f) + : FormatValidator(parent, f) +{ +} + + +std::string FormatPrettynameValidator::str(Formats::const_iterator it) const +{ + return it->prettyname(); +} + PrefFileformats::PrefFileformats(GuiPrefsDialog * form, QWidget * parent) : PrefModule(_("File formats"), form, parent) { setupUi(this); + formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats())); + formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats())); - connect(formatNewPB, SIGNAL(clicked()), - this, SLOT(new_format())); - connect(formatRemovePB, SIGNAL(clicked()), - this, SLOT(remove_format())); - connect(formatModifyPB, SIGNAL(clicked()), - this, SLOT(modify_format())); - connect(formatsLW, SIGNAL(currentRowChanged(int)), - this, SLOT(switch_format(int))); - connect(formatED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); - connect(guiNameED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); - connect(shortcutED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); - connect(extensionED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); - connect(viewerED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); - connect(editorED, SIGNAL(textChanged(const QString&)), - this, SLOT(fileformat_changed())); connect(documentCB, SIGNAL(clicked()), - this, SLOT(fileformat_changed())); + this, SLOT(setFlags())); connect(vectorCB, SIGNAL(clicked()), - this, SLOT(fileformat_changed())); - connect(formatNewPB, SIGNAL(clicked()), - this, SIGNAL(changed())); - connect(formatRemovePB, SIGNAL(clicked()), - this, SIGNAL(changed())); - connect(formatModifyPB, SIGNAL(clicked()), + this, SLOT(setFlags())); + connect(formatsCB->lineEdit(), SIGNAL(editingFinished()), + this, SLOT(updatePrettyname())); + connect(formatsCB->lineEdit(), SIGNAL(textEdited(const QString &)), this, SIGNAL(changed())); } @@ -1417,149 +1212,153 @@ void PrefFileformats::update(LyXRC const & /*rc*/) void PrefFileformats::updateView() { - // save current selection - QString current = guiNameED->text(); + QString const current = formatsCB->currentText(); - // update listwidget with formats - formatsLW->blockSignals(true); - formatsLW->clear(); + // update combobox with formats + formatsCB->blockSignals(true); + formatsCB->clear(); + form_->formats().sort(); Formats::const_iterator cit = form_->formats().begin(); Formats::const_iterator end = form_->formats().end(); - for (; cit != end; ++cit) { - new QListWidgetItem(toqstr(cit->prettyname()), - formatsLW, - form_->formats().getNumber(cit->name()) ); - } - formatsLW->sortItems(Qt::AscendingOrder); - formatsLW->blockSignals(false); + for (; cit != end; ++cit) + formatsCB->addItem(toqstr(cit->prettyname()), + QVariant(form_->formats().getNumber(cit->name())) ); // restore selection - if (!current.isEmpty()) { - QList item = formatsLW->findItems(current, Qt::MatchExactly); - if (item.size()>0) - formatsLW->setCurrentItem(item.at(0)); - } - // select first element if restoring failed - if (formatsLW->currentRow() == -1) - formatsLW->setCurrentRow(0); + int const item = formatsCB->findText(current, Qt::MatchExactly); + formatsCB->setCurrentIndex(item < 0 ? 0 : item); + on_formatsCB_currentIndexChanged(item < 0 ? 0 : item); + formatsCB->blockSignals(false); } -void PrefFileformats::switch_format(int nr) +void PrefFileformats::on_formatsCB_currentIndexChanged(int i) { - int const ftype = formatsLW->item(nr)->type(); - Format const f = form_->formats().get(ftype); + int const nr = formatsCB->itemData(i).toInt(); + Format const f = form_->formats().get(nr); formatED->setText(toqstr(f.name())); - guiNameED->setText(toqstr(f.prettyname())); + copierED->setText(toqstr(form_->movers().command(f.name()))); extensionED->setText(toqstr(f.extension())); shortcutED->setText(toqstr(f.shortcut())); viewerED->setText(toqstr(f.viewer())); editorED->setText(toqstr(f.editor())); documentCB->setChecked((f.documentFormat())); vectorCB->setChecked((f.vectorFormat())); - - updateButtons(); } -void PrefFileformats::fileformat_changed() +void PrefFileformats::setFlags() { - updateButtons(); -} - - -void PrefFileformats::updateButtons() -{ - QString const format = formatED->text(); - QString const gui_name = guiNameED->text(); - int const sel = form_->formats().getNumber(fromqstr(format)); - bool gui_name_known = false; - int where = sel; - for (int i = 0; i < formatsLW->count(); ++i) { - if (formatsLW->item(i)->text() == gui_name) { - gui_name_known = true; - where = formatsLW->item(i)->type(); - } - } - - // assure that a gui name cannot be chosen twice - bool const known_otherwise = gui_name_known && where != sel; - - bool const known = sel >= 0; - bool const valid = !formatED->text().isEmpty() - && !guiNameED->text().isEmpty(); - - int const ftype = formatsLW->currentItem()->type(); - Format const & f = form_->formats().get(ftype); - string const old_pretty = f.prettyname(); - string const old_shortcut = f.shortcut(); - string const old_extension = f.extension(); - string const old_viewer = f.viewer(); - string const old_editor = f.editor(); - bool const old_document = f.documentFormat(); - bool const old_vector = f.vectorFormat(); - - string const new_pretty = fromqstr(gui_name); - string const new_shortcut = fromqstr(shortcutED->text()); - string const new_extension = fromqstr(extensionED->text()); - string const new_viewer = fromqstr(viewerED->text()); - string const new_editor = fromqstr(editorED->text()); - bool const new_document = documentCB->isChecked(); - bool const new_vector = vectorCB->isChecked(); - - bool modified = old_pretty != new_pretty - || old_shortcut != new_shortcut - || old_extension != new_extension - || old_viewer != new_viewer - || old_editor != new_editor - || old_document != new_document - || old_vector != new_vector; - - formatModifyPB->setEnabled(valid && known && modified && !known_otherwise); - formatNewPB->setEnabled(valid && !known && !gui_name_known); - formatRemovePB->setEnabled(known); -} - - -void PrefFileformats::new_format() -{ - string const name = fromqstr(formatED->text()); - string const prettyname = fromqstr(guiNameED->text()); - string const extension = fromqstr(extensionED->text()); - string const shortcut = fromqstr(shortcutED->text()); - string const viewer = fromqstr(viewerED->text()); - string const editor = fromqstr(editorED->text()); int flags = Format::none; if (documentCB->isChecked()) flags |= Format::document; if (vectorCB->isChecked()) flags |= Format::vector; + currentFormat().setFlags(flags); + changed(); +} - form_->formats().add(name, extension, prettyname, shortcut, viewer, - editor, flags); - form_->formats().sort(); + +void PrefFileformats::on_copierED_textEdited(const QString & s) +{ + string const fmt = fromqstr(formatED->text()); + form_->movers().set(fmt, fromqstr(s)); + changed(); +} + + +void PrefFileformats::on_extensionED_textEdited(const QString & s) +{ + currentFormat().setExtension(fromqstr(s)); + changed(); +} + +void PrefFileformats::on_viewerED_textEdited(const QString & s) +{ + currentFormat().setViewer(fromqstr(s)); + changed(); +} + + +void PrefFileformats::on_editorED_textEdited(const QString & s) +{ + currentFormat().setEditor(fromqstr(s)); + changed(); +} + + +void PrefFileformats::on_shortcutED_textEdited(const QString & s) +{ + currentFormat().setShortcut(fromqstr(s)); + changed(); +} + + +void PrefFileformats::on_formatED_editingFinished() +{ + string const newname = fromqstr(formatED->displayText()); + if (newname == currentFormat().name()) + return; + + currentFormat().setName(newname); + changed(); +} + + +void PrefFileformats::on_formatED_textChanged(const QString &) +{ + QString t = formatED->text(); + int p = 0; + bool valid = formatED->validator()->validate(t, p) == QValidator::Acceptable; + setValid(formatLA, valid); +} + + +void PrefFileformats::on_formatsCB_editTextChanged(const QString &) +{ + QString t = formatsCB->currentText(); + int p = 0; + bool valid = formatsCB->validator()->validate(t, p) == QValidator::Acceptable; + setValid(formatsLA, valid); +} + + +void PrefFileformats::updatePrettyname() +{ + string const newname = fromqstr(formatsCB->currentText()); + if (newname == currentFormat().prettyname()) + return; + + currentFormat().setPrettyname(newname); form_->converters().update(form_->formats()); - - updateView(); - updateButtons(); formatsChanged(); + updateView(); + changed(); } -void PrefFileformats::modify_format() +Format & PrefFileformats::currentFormat() { - int const current_item = formatsLW->currentItem()->type(); - Format const & oldformat = form_->formats().get(current_item); - form_->formats().erase(oldformat.name()); - - new_format(); + int const i = formatsCB->currentIndex(); + int const nr = formatsCB->itemData(i).toInt(); + return form_->formats().get(nr); } -void PrefFileformats::remove_format() +void PrefFileformats::on_formatNewPB_clicked() { - int const nr = formatsLW->currentItem()->type(); + form_->formats().add("", "", "", "", "", "", Format::none); + updateView(); + formatsCB->setCurrentIndex(0); + formatsCB->setFocus(Qt::OtherFocusReason); +} + + +void PrefFileformats::on_formatRemovePB_clicked() +{ + int const i = formatsCB->currentIndex(); + int const nr = formatsCB->itemData(i).toInt(); string const current_text = form_->formats().get(nr).name(); if (form_->converters().formatIsUsed(current_text)) { Alert::error(_("Format in use"), @@ -1570,10 +1369,10 @@ void PrefFileformats::remove_format() form_->formats().erase(current_text); form_->converters().update(form_->formats()); - - updateView(); - updateButtons(); formatsChanged(); + updateView(); + on_formatsCB_editTextChanged(formatsCB->currentText()); + changed(); } @@ -1766,8 +1565,6 @@ PrefUserInterface::PrefUserInterface(GuiPrefsDialog * form, QWidget * parent) { setupUi(this); - connect(autoSaveCB, SIGNAL(toggled(bool)), - autoSaveLA, SLOT(setEnabled(bool))); connect(autoSaveCB, SIGNAL(toggled(bool)), autoSaveSB, SLOT(setEnabled(bool))); connect(autoSaveCB, SIGNAL(toggled(bool)), @@ -1950,9 +1747,6 @@ GuiPrefsDialog::GuiPrefsDialog(LyXView & lv) add(converters); add(formats); - add(new PrefCopiers(this)); - - prefsPS->setCurrentPanel(_("User interface")); // FIXME: hack to work around resizing bug in Qt >= 4.2 // bug verified with Qt 4.2.{0-3} (JSpitzm) diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index cc04b86bda..ab199d1f1d 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -16,6 +16,7 @@ #include "ControlPrefs.h" #include "Color.h" #include "LyXRC.h" +#include "Format.h" #include "ui_PrefsUi.h" @@ -29,7 +30,6 @@ #include "ui_PrefPathsUi.h" #include "ui_PrefSpellcheckerUi.h" #include "ui_PrefConvertersUi.h" -#include "ui_PrefCopiersUi.h" #include "ui_PrefFileformatsUi.h" #include "ui_PrefLanguageUi.h" #include "ui_PrefPrinterUi.h" @@ -37,6 +37,7 @@ #include "ui_PrefIdentityUi.h" #include +#include #include @@ -233,27 +234,33 @@ private: }; -class PrefCopiers : public PrefModule, public Ui::PrefCopiersUi +class FormatValidator : public QValidator { - Q_OBJECT public: - PrefCopiers(GuiPrefsDialog * form, QWidget * parent = 0); - - void apply(LyXRC & rc) const; - void update(LyXRC const & rc); - - void updateView(); - -private Q_SLOTS: - void switch_copierLB(int nr); - void switch_copierCO(int nr); - void copiers_changed(); - void new_copier(); - void modify_copier(); - void remove_copier(); - + FormatValidator(QWidget *, Formats const & f); + void fixup(QString & input) const; + QValidator::State validate(QString & input, int & pos) const; private: - void updateButtons(); + virtual std::string str(Formats::const_iterator it) const = 0; + int nr() const; + Formats const & formats_; +}; + + +class FormatNameValidator : public FormatValidator +{ +public: + FormatNameValidator(QWidget *, Formats const & f); +private: + std::string str(Formats::const_iterator it) const; +}; + +class FormatPrettynameValidator : public FormatValidator +{ +public: + FormatPrettynameValidator(QWidget *, Formats const & f); +private: + std::string str(Formats::const_iterator it) const; }; @@ -265,19 +272,28 @@ public: void apply(LyXRC & rc) const; void update(LyXRC const & rc); - void updateView(); + Q_SIGNALS: void formatsChanged(); -private: - void updateButtons(); private Q_SLOTS: - void switch_format(int); - void fileformat_changed(); - void new_format(); - void modify_format(); - void remove_format(); + void on_copierED_textEdited(const QString & s); + void on_extensionED_textEdited(const QString &); + void on_viewerED_textEdited(const QString &); + void on_editorED_textEdited(const QString &); + void on_shortcutED_textEdited(const QString &); + void on_formatED_editingFinished(); + void on_formatED_textChanged(const QString &); + void on_formatsCB_currentIndexChanged(int); + void on_formatsCB_editTextChanged(const QString &); + void on_formatNewPB_clicked(); + void on_formatRemovePB_clicked(); + void setFlags(); + void updatePrettyname(); + +private: + Format & currentFormat(); }; diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 6cf26d31e2..63c97c5b17 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -240,7 +240,6 @@ UIFILES = \ PreambleUi.ui \ PrefColorsUi.ui \ PrefConvertersUi.ui \ - PrefCopiersUi.ui \ PrefDateUi.ui \ PrefDisplayUi.ui \ PrefFileformatsUi.ui \ diff --git a/src/frontends/qt4/ui/PrefCopiersUi.ui b/src/frontends/qt4/ui/PrefCopiersUi.ui deleted file mode 100644 index d3dfaa4426..0000000000 --- a/src/frontends/qt4/ui/PrefCopiersUi.ui +++ /dev/null @@ -1,133 +0,0 @@ - - PrefCopiersUi - - - - 0 - 0 - 396 - 320 - - - - - - - - 9 - - - 6 - - - - - Qt::Horizontal - - - - 161 - 20 - - - - - - - - &Format: - - - copierFormatCO - - - - - - - - - - - - - - - - &Copier: - - - copierED - - - - - - - C&opiers - - - AllCopiersLW - - - - - - - 0 - - - 6 - - - - - &Add - - - - - - - &Modify - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - AllCopiersLW - copierFormatCO - copierED - copierNewPB - copierModifyPB - copierRemovePB - - - qt_helpers.h - - - - diff --git a/src/frontends/qt4/ui/PrefFileformatsUi.ui b/src/frontends/qt4/ui/PrefFileformatsUi.ui index a64638bd17..910820fdaa 100644 --- a/src/frontends/qt4/ui/PrefFileformatsUi.ui +++ b/src/frontends/qt4/ui/PrefFileformatsUi.ui @@ -5,253 +5,184 @@ 0 0 - 459 - 410 + 414 + 322 - + - 0 + 9 6 - - + + + + + + + + - &File formats - - - formatsLW + &New... - - - - 0 + + + + &Remove - - 6 - - - - - - - - 0 - - - 6 - - - - - &Add - - - - - - - &Modify - - - - - - - &Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - + - - - - 0 - - - 6 - - - - - &Document format - - - - - - - Vector graphi&cs format - - - - + + - - - - 0 + + + + + + + S&hort Name: - - 6 + + formatED - - - - 0 - - - 6 - - - - - F&ormat: - - - formatED - - - - - - - S&hortcut: - - - shortcutED - - - - - - - &Viewer: - - - viewerED - - - - - - - - - 0 - - - 6 - - - - - - - - - - - - - - - - 0 - - - 6 - - - - - &GUI name: - - - guiNameED - - - - - - - E&xtension: - - - extensionED - - - - - - - Ed&itor: - - - editorED - - - - - - - - - 0 - - - 6 - - - - - - - - - - - - - + + + + + + + 7 + 0 + 0 + 0 + + + + true + + + QComboBox::InsertAtCurrent + + + 1 + + + + + + + Vector graphi&cs format + + + + + + + &Format: + + + formatsCB + + + + + + + &Document format + + + + + + + &Viewer: + + + viewerED + + + + + + + + + + Ed&itor: + + + editorED + + + + + + + S&hortcut: + + + shortcutED + + + + + + + E&xtension: + + + extensionED + + + + + + + + + + Qt::Vertical + + + + 168 + 21 + + + + + + + + Co&pier: + + + copierED + + - formatsLW + formatsCB + formatNewPB + formatRemovePB documentCB vectorCB formatED - guiNameED - shortcutED extensionED - viewerED + shortcutED editorED - formatNewPB - formatModifyPB + viewerED + copierED qt_helpers.h diff --git a/src/frontends/qt4/ui/compile_uic.sh b/src/frontends/qt4/ui/compile_uic.sh index 0806939a26..30e3ba6a23 100644 --- a/src/frontends/qt4/ui/compile_uic.sh +++ b/src/frontends/qt4/ui/compile_uic.sh @@ -33,7 +33,6 @@ uic PageLayoutUi.ui -o PageLayoutUi.h uic ParagraphUi.ui -o ParagraphUi.h uic PrefColorsUi.ui -o PrefColorsUi.h uic PrefConvertersUi.ui -o PrefConvertersUi.h -uic PrefCopiersUi.ui -o PrefCopiersUi.h uic PrefDateUi.ui -o PrefDateUi.h uic PrefDisplayUi.ui -o PrefDisplayUi.h uic PrefFileformatsUi.ui -o PrefFileformatsUi.h