2 * \file GuiTabularCreate.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "GuiTabularCreate.h"
15 #include "EmptyTable.h"
16 #include "FuncRequest.h"
18 #include "support/debug.h"
19 #include "support/convert.h"
20 #include "support/filetools.h"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
23 #include "support/qstring_helpers.h"
24 #include "support/Package.h"
26 #include <QDirIterator>
28 #include <QPushButton>
31 using namespace lyx::support;
36 void GuiTabularCreate::getFiles()
38 // We look for lyx files in the subdirectory dir of
40 // 2) build_lyxdir (if not empty)
42 // in this order. Files with a given sub-hierarchy will
43 // only be listed once.
44 // We also consider i18n subdirectories and store them separately.
47 // The three locations to look at.
48 string const user = addPath(package().user_support().absFileName(), "tabletemplates");
49 string const build = addPath(package().build_support().absFileName(), "tabletemplates");
50 string const system = addPath(package().system_support().absFileName(), "tabletemplates");
56 for (int i = 0; i < dirs.size(); ++i) {
57 QString const dir = dirs.at(i);
58 QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);
59 while (it.hasNext()) {
60 QString fn = QFileInfo(it.next()).fileName();
61 if (!fn.endsWith(".lyx") || fn.contains("_1x"))
63 QString data = fn.left(fn.lastIndexOf(".lyx"));
64 QString guiname = data;
65 guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname.replace('_', ' '))));
66 QString relpath = toqstr(makeRelPath(qstring_to_ucs4(fn),
67 qstring_to_ucs4(dir)));
68 if (styleCO->findData(data) == -1)
69 styleCO->addItem(guiname, data);
74 GuiTabularCreate::GuiTabularCreate(GuiView & lv)
75 : GuiDialog(lv, "tabularcreate", qt_("Insert Table"))
80 columnsSB->setValue(5);
81 table->setMinimumSize(100, 100);
83 connect(table, SIGNAL(rowsChanged(int)),
84 rowsSB, SLOT(setValue(int)));
85 connect(table, SIGNAL(colsChanged(int)),
86 columnsSB, SLOT(setValue(int)));
87 connect(rowsSB, SIGNAL(valueChanged(int)),
88 table, SLOT(setNumberRows(int)));
89 connect(columnsSB, SIGNAL(valueChanged(int)),
90 table, SLOT(setNumberColumns(int)));
92 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
93 this, SLOT(slotButtonBox(QAbstractButton *)));
95 connect(rowsSB, SIGNAL(valueChanged(int)),
96 this, SLOT(rowsChanged(int)));
97 connect(columnsSB, SIGNAL(valueChanged(int)),
98 this, SLOT(columnsChanged(int)));
100 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
101 bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
102 bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
103 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
104 bc().setValid(isValid());
107 styleCO->addItem(qt_("Default"), toqstr("default"));
112 void GuiTabularCreate::on_styleCO_activated(int i)
114 style_ = styleCO->itemData(i).toString();
119 void GuiTabularCreate::columnsChanged(int)
125 void GuiTabularCreate::rowsChanged(int)
131 void GuiTabularCreate::applyView()
133 params_.first = ulong(rowsSB->value());
134 params_.second = ulong(columnsSB->value());
138 bool GuiTabularCreate::initialiseParams(string const &)
142 style_ = styleCO->itemData(styleCO->currentIndex()).toString();
148 void GuiTabularCreate::clearParams()
155 void GuiTabularCreate::dispatchParams()
158 if (style_ != "default")
159 sdata = fromqstr(style_) + ' ';
160 sdata += convert<string>(params().first) + ' ' + convert<string>(params().second);
161 dispatch(FuncRequest(getLfun(), sdata));
165 FuncCode GuiTabularCreate::getLfun() const
167 if (style_.isEmpty() || style_ == "default")
168 return LFUN_TABULAR_INSERT;
170 return LFUN_TABULAR_STYLE_INSERT;
174 Dialog * createGuiTabularCreate(GuiView & lv)
176 return new GuiTabularCreate(lv);
180 } // namespace frontend
183 #include "moc_GuiTabularCreate.cpp"