X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiTabularCreate.cpp;h=1f5e36ec4d25779c8c98405cf8ef0a6305676f8b;hb=2709c5fb5860d71216c388eb77ad0554cc5d43ed;hp=a4394388ab87bfecd03644974410beea09d71045;hpb=470aba2a0e552f27d55992372c09f15af9725fa8;p=lyx.git diff --git a/src/frontends/qt4/GuiTabularCreate.cpp b/src/frontends/qt4/GuiTabularCreate.cpp index a4394388ab..1f5e36ec4d 100644 --- a/src/frontends/qt4/GuiTabularCreate.cpp +++ b/src/frontends/qt4/GuiTabularCreate.cpp @@ -12,66 +12,172 @@ #include "GuiTabularCreate.h" -#include "ControlTabularCreate.h" #include "EmptyTable.h" +#include "FuncRequest.h" -#include +#include "support/debug.h" +#include "support/convert.h" +#include "support/filetools.h" +#include "support/gettext.h" +#include "support/lstrings.h" +#include "support/qstring_helpers.h" +#include "support/Package.h" + +#include #include #include +using namespace std; +using namespace lyx::support; namespace lyx { namespace frontend { -GuiTabularCreateDialog::GuiTabularCreateDialog(LyXView & lv) - : GuiDialog(lv, "tabularcreate") +void GuiTabularCreate::getFiles() +{ + // We look for lyx files in the subdirectory dir of + // 1) user_lyxdir + // 2) build_lyxdir (if not empty) + // 3) system_lyxdir + // in this order. Files with a given sub-hierarchy will + // only be listed once. + // We also consider i18n subdirectories and store them separately. + QStringList dirs; + + // The three locations to look at. + string const user = addPath(package().user_support().absFileName(), "tabletemplates"); + string const build = addPath(package().build_support().absFileName(), "tabletemplates"); + string const system = addPath(package().system_support().absFileName(), "tabletemplates"); + + dirs << toqstr(user) + << toqstr(build) + << toqstr(system); + + for (int i = 0; i < dirs.size(); ++i) { + QString const dir = dirs.at(i); + QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) { + QString fn = QFileInfo(it.next()).fileName(); + if (!fn.endsWith(".lyx") || fn.contains("_1x")) + continue; + QString data = fn.left(fn.lastIndexOf(".lyx")); + QString guiname = data; + guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname.replace('_', ' ')))); + QString relpath = toqstr(makeRelPath(qstring_to_ucs4(fn), + qstring_to_ucs4(dir))); + if (styleCO->findData(data) == -1) + styleCO->addItem(guiname, data); + } + } +} + +GuiTabularCreate::GuiTabularCreate(GuiView & lv) + : GuiDialog(lv, "tabularcreate", qt_("Insert Table")) { setupUi(this); - setViewTitle(_("Insert Table")); - setController(new ControlTabularCreate(*this)); rowsSB->setValue(5); columnsSB->setValue(5); + table->setMinimumSize(100, 100); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + connect(table, SIGNAL(rowsChanged(int)), + rowsSB, SLOT(setValue(int))); + connect(table, SIGNAL(colsChanged(int)), + columnsSB, SLOT(setValue(int))); + connect(rowsSB, SIGNAL(valueChanged(int)), + table, SLOT(setNumberRows(int))); + connect(columnsSB, SIGNAL(valueChanged(int)), + table, SLOT(setNumberColumns(int))); + + connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), + this, SLOT(slotButtonBox(QAbstractButton *))); connect(rowsSB, SIGNAL(valueChanged(int)), this, SLOT(rowsChanged(int))); connect(columnsSB, SIGNAL(valueChanged(int)), this, SLOT(columnsChanged(int))); - bc().setPolicy(ButtonPolicy::IgnorantPolicy); - bc().setOK(okPB); - bc().setCancel(closePB); + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(buttonBox->button(QDialogButtonBox::Ok)); + bc().setApply(buttonBox->button(QDialogButtonBox::Apply)); + bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel)); + bc().setValid(isValid()); + + // Fill styles combo + styleCO->addItem(qt_("Default"), toqstr("default")); + getFiles(); } -ControlTabularCreate & GuiTabularCreateDialog::controller() +void GuiTabularCreate::on_styleCO_activated(int i) { - return static_cast(GuiDialog::controller()); + style_ = styleCO->itemData(i).toString(); + changed(); } -void GuiTabularCreateDialog::columnsChanged(int) +void GuiTabularCreate::columnsChanged(int) { changed(); } -void GuiTabularCreateDialog::rowsChanged(int) +void GuiTabularCreate::rowsChanged(int) { changed(); } -void GuiTabularCreateDialog::applyView() +void GuiTabularCreate::applyView() +{ + params_.first = ulong(rowsSB->value()); + params_.second = ulong(columnsSB->value()); +} + + +bool GuiTabularCreate::initialiseParams(string const &) { - controller().params().first = rowsSB->value(); - controller().params().second = columnsSB->value(); + params_.first = 5; + params_.second = 5; + style_ = styleCO->itemData(styleCO->currentIndex()).toString(); + changed(); + return true; } + +void GuiTabularCreate::clearParams() +{ + params_.first = 0; + params_.second = 0; +} + + +void GuiTabularCreate::dispatchParams() +{ + string sdata; + if (style_ != "default") + sdata = fromqstr(style_) + ' '; + sdata += convert(params().first) + ' ' + convert(params().second); + dispatch(FuncRequest(getLfun(), sdata)); +} + + +FuncCode GuiTabularCreate::getLfun() const +{ + if (style_.isEmpty() || style_ == "default") + return LFUN_TABULAR_INSERT; + + return LFUN_TABULAR_STYLE_INSERT; +} + + +Dialog * createGuiTabularCreate(GuiView & lv) +{ + return new GuiTabularCreate(lv); +} + + } // namespace frontend } // namespace lyx -#include "GuiTabularCreate_moc.cpp" +#include "moc_GuiTabularCreate.cpp"