3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Abdelrazak Younes
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
16 #include "qt_helpers.h"
19 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
25 #include "GuiApplication.h"
28 #include "insets/InsetInfo.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
36 using namespace lyx::support;
41 /////////////////////////////////////////////////////////////////
45 /////////////////////////////////////////////////////////////////
47 char const * info_types[] =
68 // GUI names (in combo)
69 char const * info_types_gui[] =
70 { N_("Date (current)"),// date
71 N_("Date (last modified)"),// moddate
72 N_("Date (fix)"),// fixdate
73 N_("Time (current)"),// time
74 N_("Time (last modified)"),// modtime
75 N_("Time (fix)"),// fixtime
76 N_("Document Information"),// buffer
77 N_("Version Control Information"),// vcs
78 N_("LaTeX Package Availability"),// package
79 N_("LaTeX Class Availability"),// textclass
80 N_("Last Assigned Keyboard Shortcut"),// shortcut
81 N_("All Keyboard Shortcuts"),// shortcuts
82 N_("LyX Menu Location"),// menu
83 N_("LyX Toolbar Icon"),// icon
84 N_("LyX Preferences Entry"),// lyxrc
85 N_("LyX Application Information"),// lyxinfo
86 N_("Unknown"),// unknown
91 char const * info_name_gui[] =
92 { N_("Custom Format"),// date
93 N_("Custom Format"),// moddate
94 N_("Custom Format"),// fixdate
95 N_("Custom Format"),// time
96 N_("Custom Format"),// modtime
97 N_("Custom Format"),// fixtime
98 N_("Not Applicable"),// buffer
99 N_("Not Applicable"),// vcs
100 N_("Package Name"),// package
101 N_("Class Name"),// textclass
102 N_("LyX Function"),// shortcut
103 N_("LyX Function"),// shortcuts
104 N_("LyX Function"),// menu
105 N_("LyX Function"),// icon
106 N_("Preferences Key"),// lyxrc
107 N_("Not Applicable"),// lyxinfo
108 N_("Not Applicable"),// unknown
113 char const * info_tooltip[] =
114 { N_("Enter date format specification, using the following placeholders:\n"
115 "* d: day as number without a leading zero\n"
116 "* dd: day as number with a leading zero\n"
117 "* ddd: abbreviated localized day name\n"
118 "* dddd: long localized day name\n"
119 "* M: month as number without a leading zero\n"
120 "* MM: month as number with a leading zero\n"
121 "* MMM: abbreviated localized month name\n"
122 "* MMMM: long localized month name\n"
123 "* yy: year as two digit number\n"
124 "* yyyy: year as four digit number"),// date
125 N_("Enter date format specification, using the following placeholders:\n"
126 "* d: day as number without a leading zero\n"
127 "* dd: day as number with a leading zero\n"
128 "* ddd: abbreviated localized day name\n"
129 "* dddd: long localized day name\n"
130 "* M: month as number without a leading zero\n"
131 "* MM: month as number with a leading zero\n"
132 "* MMM: abbreviated localized month name\n"
133 "* MMMM: long localized month name\n"
134 "* yy: year as two digit number\n"
135 "* yyyy: year as four digit number"),// moddate
136 N_("Enter date format specification, using the following placeholders:\n"
137 "* d: day as number without a leading zero\n"
138 "* dd: day as number with a leading zero\n"
139 "* ddd: abbreviated localized day name\n"
140 "* dddd: long localized day name\n"
141 "* M: month as number without a leading zero\n"
142 "* MM: month as number with a leading zero\n"
143 "* MMM: abbreviated localized month name\n"
144 "* MMMM: long localized month name\n"
145 "* yy: year as two digit number\n"
146 "* yyyy: year as four digit number"),// fixdate
147 N_("Enter time format specification, using the following placeholders:\n"
148 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
149 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
150 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
151 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
152 "* m: the minute without a leading zero\n"
153 "* mm: the minute with a leading zero\n"
154 "* s: the second without a leading zero\n"
155 "* ss: the second with a leading zero\n"
156 "* z: the milliseconds without leading zeroes\n"
157 "* zzz: the milliseconds with leading zeroes\n"
158 "* AP or A: use AM/PM display ('AM'/'PM')\n"
159 "* ap or a: use am/pm display ('am'/'pm')\n"
160 "* t: the timezone (e.g. CEST)"),// time
161 N_("Enter time format specification, using the following placeholders:\n"
162 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
163 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
164 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
165 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
166 "* m: the minute without a leading zero\n"
167 "* mm: the minute with a leading zero\n"
168 "* s: the second without a leading zero\n"
169 "* ss: the second with a leading zero\n"
170 "* z: the milliseconds without leading zeroes\n"
171 "* zzz: the milliseconds with leading zeroes\n"
172 "* AP or A: use AM/PM display ('AM'/'PM')\n"
173 "* ap or a: use am/pm display ('am'/'pm')\n"
174 "* t: the timezone (e.g. CEST)"),// modtime
175 N_("Enter time format specification, using the following placeholders:\n"
176 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
177 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
178 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
179 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
180 "* m: the minute without a leading zero\n"
181 "* mm: the minute with a leading zero\n"
182 "* s: the second without a leading zero\n"
183 "* ss: the second with a leading zero\n"
184 "* z: the milliseconds without leading zeroes\n"
185 "* zzz: the milliseconds with leading zeroes\n"
186 "* AP or A: use AM/PM display ('AM'/'PM')\n"
187 "* ap or a: use am/pm display ('am'/'pm')\n"
188 "* t: the timezone (e.g. CEST)"),// fixtime
189 N_("Please select a valid type above"),// buffer
190 N_("Please select a valid type above"),// vcs
191 N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
192 "The output will be 'Yes' (package available) or 'No' (package unavailable)."),// package
193 N_("Enter a LaTeX class name such as 'article' (extension is optional). "
194 "The output will be 'Yes' (class available) or 'No' (class unavailable)."),// textclass
195 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
196 "The output is the most recently assigned keyboard shortcut for this function"),// shortcut
197 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
198 "The output lists all possible keyboard shortcuts for this function"),// shortcuts
199 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
200 "The output is the path to the function in the menu (using the current localization)."),// menu
201 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
202 "The output is the toolbar icon for this function (using the active icon theme)."),// icon
203 N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "
204 "The output is the current setting of this preference."),// lyxrc
205 N_("Please select a valid type above"),// lyxinfo
206 N_("Please select a valid type above"),// unknown
210 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
214 typeCO->blockSignals(true);
215 for (int n = 0; info_types[n][0]; ++n)
216 typeCO->addItem(qt_(info_types_gui[n]), info_types[n]);
217 typeCO->blockSignals(false);
219 connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(updateArguments(int)));
220 connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
221 connect(fixDateLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
222 connect(infoLW, SIGNAL(currentTextChanged(QString)), this, SIGNAL(changed()));
226 void GuiInfo::paramsToDialog(Inset const * inset)
228 InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
229 params_ = ii->params();
230 QString const type = toqstr(params_.infoType());
231 QString name = toqstr(params_.name);
233 if (type == "fixdate" || type == "fixtime") {
234 fixdate = name.section('@', 1, 1);
235 name = name.section('@', 0, 0);
236 if (!fixdate.isEmpty())
237 fixDateLE->setText(fixdate);
239 if (type == "fixdate")
240 fixDateLE->setText(QDate::currentDate().toString(Qt::ISODate));
242 fixDateLE->setText(QTime::currentTime().toString(Qt::ISODate));
245 typeCO->blockSignals(true);
246 nameLE->blockSignals(true);
248 int const i = typeCO->findData(type);
249 typeCO->setCurrentIndex(i);
253 for (int i = 0 ; i < infoLW->count() ; ++i) {
254 if (infoLW->item(i)->data(Qt::UserRole).toString() == name)
256 else if (infoLW->item(i)->data(Qt::UserRole).toString() == "custom")
260 infoLW->setCurrentRow(argindex);
262 // Without this test, 'math-insert' (name) will replace 'math-insert '
263 // in nameLE and effectively disallow the input of spaces after a LFUN.
264 if (nameLE->text().trimmed() != name)
265 nameLE->setText(name);
266 infoLW->setCurrentRow(customindex);
268 typeCO->blockSignals(false);
269 nameLE->blockSignals(false);
273 docstring GuiInfo::dialogToParams() const
276 typeCO->itemData(typeCO->currentIndex()).toString();
277 QString name = infoLW->currentItem() ?
278 infoLW->currentItem()->data(Qt::UserRole).toString()
280 if (name == "custom")
281 name = nameLE->text();
282 if (type == "fixdate" || type == "fixtime") {
283 QString fd = fixDateLE->text();
285 fd = (type == "fixdate") ?
286 QDate::currentDate().toString(Qt::ISODate)
287 : QTime::currentTime().toString(Qt::ISODate);
290 return qstring_to_ucs4(type + ' ' + name);
294 bool GuiInfo::initialiseParams(std::string const & sdata)
296 Language const * lang = languages.getLanguage(sdata);
300 updateArguments(typeCO->currentIndex());
305 void GuiInfo::updateArguments(int i)
311 BufferView const * bv = guiApp->currentView()->currentBufferView();
312 vector<pair<string,docstring>> args = params_.getArguments(const_cast<Buffer *>(&bv->buffer()),
314 for (auto const & p : args) {
315 QListWidgetItem * li = new QListWidgetItem(toqstr(p.second));
316 li->setData(Qt::UserRole, toqstr(p.first));
317 if (p.first == "invalid")
318 // non-selectable, disabled item!
319 li->setFlags(Qt::NoItemFlags);
320 if (p.first == "custom")
321 li->setData(Qt::ToolTipRole, qt_("Enter a valid value below"));
324 if (infoLW->count() > 0)
325 infoLW->setCurrentRow(0);
330 bool GuiInfo::checkWidgets(bool readonly) const
332 nameLE->setReadOnly(readonly);
333 typeCO->setEnabled(!readonly);
334 nameLA->setText(qt_(info_name_gui[typeCO->currentIndex()]) + toqstr(":"));
336 QString const arg = infoLW->currentItem() ?
337 infoLW->currentItem()->data(Qt::UserRole).toString()
340 bool const type_enabled = (arg == "custom");
341 nameLA->setEnabled(type_enabled);
342 nameLE->setEnabled(type_enabled);
343 nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
345 string const typestr = info_types[typeCO->currentIndex()];
346 bool const fixdate_enabled = (typestr == "fixdate" || typestr == "fixtime");
347 fixDateLE->setVisible(fixdate_enabled);
348 fixDateLA->setVisible(fixdate_enabled);
349 if (typestr == "fixdate") {
350 fixDateLE->setToolTip(qt_("Here you can enter a fix date (in ISO format: YYYY-MM-DD)"));
351 fixDateLA->setText(qt_("&Fix Date:"));
353 else if (typestr == "fixtime") {
354 fixDateLE->setToolTip(qt_("Here you can enter a fix time (in ISO format: hh:mm:ss)"));
355 fixDateLA->setText(qt_("&Fix Time:"));
358 if (!InsetParamsWidget::checkWidgets())
360 return !arg.isEmpty() && (arg != "custom" || !nameLE->text().isEmpty());
365 } // namespace frontend
368 #include "moc_GuiInfo.cpp"