mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
GUI for new counter inset.
This commit is contained in:
parent
9a1b26a156
commit
9a147255df
@ -669,6 +669,13 @@ Menuset
|
|||||||
Item "Settings...|S" "inset-settings"
|
Item "Settings...|S" "inset-settings"
|
||||||
End
|
End
|
||||||
|
|
||||||
|
#
|
||||||
|
# InsetCounter context menu
|
||||||
|
#
|
||||||
|
Menu "context-counter"
|
||||||
|
Item "Settings...|S" "inset-settings"
|
||||||
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
# Toolbar context menu
|
# Toolbar context menu
|
||||||
#
|
#
|
||||||
|
@ -398,6 +398,7 @@ Menuset
|
|||||||
Item "URL|U" "flex-insert URL"
|
Item "URL|U" "flex-insert URL"
|
||||||
Item "Hyperlink...|k" "href-insert"
|
Item "Hyperlink...|k" "href-insert"
|
||||||
Item "Footnote|F" "footnote-insert"
|
Item "Footnote|F" "footnote-insert"
|
||||||
|
Item "Counter" "dialog-show-new-inset counter"
|
||||||
Item "Marginal Note|M" "marginalnote-insert"
|
Item "Marginal Note|M" "marginalnote-insert"
|
||||||
Item "Program Listing[[Menu]]" "listing-insert"
|
Item "Program Listing[[Menu]]" "listing-insert"
|
||||||
Separator
|
Separator
|
||||||
|
@ -1461,7 +1461,7 @@ void LyXAction::init()
|
|||||||
* \li Action: Shows hidden dialog or creates new one for a given function/inset settings etc.
|
* \li Action: Shows hidden dialog or creates new one for a given function/inset settings etc.
|
||||||
* \li Syntax: dialog-show <NAME> [<DATA>]
|
* \li Syntax: dialog-show <NAME> [<DATA>]
|
||||||
* \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n
|
* \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n
|
||||||
compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n
|
compare|counter|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n
|
||||||
graphics|href|include|index|index_print|info|label|line|listings|log|mathdelimiter|\n
|
graphics|href|include|index|index_print|info|label|line|listings|log|mathdelimiter|\n
|
||||||
mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n
|
mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n
|
||||||
print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
|
print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
|
||||||
|
174
src/frontends/qt/GuiCounter.cpp
Normal file
174
src/frontends/qt/GuiCounter.cpp
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
/**
|
||||||
|
* \file GuiCounter.cpp
|
||||||
|
* This file is part of LyX, the document processor.
|
||||||
|
* Licence details can be found in the file COPYING.
|
||||||
|
*
|
||||||
|
* \author Richard Kimberly Heck
|
||||||
|
*
|
||||||
|
* Full author contact details are available in file CREDITS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "GuiCounter.h"
|
||||||
|
|
||||||
|
#include "qt_helpers.h"
|
||||||
|
|
||||||
|
#include "Buffer.h"
|
||||||
|
#include "BufferParams.h"
|
||||||
|
#include "BufferView.h"
|
||||||
|
#include "TextClass.h"
|
||||||
|
#include "insets/InsetCounter.h"
|
||||||
|
#include "insets/InsetCommandParams.h"
|
||||||
|
|
||||||
|
#include "support/convert.h"
|
||||||
|
#include "support/gettext.h"
|
||||||
|
#include "support/lstrings.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
//#include <vector>
|
||||||
|
|
||||||
|
namespace lyx {
|
||||||
|
namespace frontend {
|
||||||
|
|
||||||
|
GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) :
|
||||||
|
InsetParamsWidget(parent), guiview(lv)
|
||||||
|
{
|
||||||
|
setupUi(this);
|
||||||
|
|
||||||
|
connect(counterCB, SIGNAL(currentIndexChanged(int)),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
connect(actionCB, SIGNAL(currentIndexChanged(int)),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
connect(valueSB, SIGNAL(valueChanged(int)),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
connect(vtypeCB, SIGNAL(clicked()),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
connect(lyxonlyXB, SIGNAL(clicked()),
|
||||||
|
this, SIGNAL(changed()));
|
||||||
|
|
||||||
|
// These are hardcoded and do not change
|
||||||
|
std::map<std::string, std::string> const & ct =
|
||||||
|
InsetCounter::counterTable;
|
||||||
|
actionCB->clear();
|
||||||
|
for (auto const & c : ct) {
|
||||||
|
docstring guistring = translateIfPossible(from_ascii(c.second));
|
||||||
|
actionCB->addItem(toqstr(guistring), toqstr(c.first));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::string> const & vt =
|
||||||
|
InsetCounter::valueTable;
|
||||||
|
vtypeCB->clear();
|
||||||
|
vtypeCB->addItem("", "");
|
||||||
|
for (auto const & v : vt) {
|
||||||
|
docstring guistring = translateIfPossible(from_ascii(v.second));
|
||||||
|
vtypeCB->addItem(toqstr(guistring), toqstr(v.first));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiCounter::processParams(InsetCommandParams const & params)
|
||||||
|
{
|
||||||
|
QString const & counter = toqstr(params["counter"]);
|
||||||
|
int c = counterCB->findText(counter);
|
||||||
|
counterCB->setCurrentIndex(c);
|
||||||
|
|
||||||
|
QString cmd = toqstr(params.getCmdName());
|
||||||
|
c = actionCB->findData(cmd);
|
||||||
|
if (c < 0) {
|
||||||
|
c = 0;
|
||||||
|
LYXERR0("Unable to find " << cmd << " in GuiCounter!");
|
||||||
|
}
|
||||||
|
actionCB->setCurrentIndex(c);
|
||||||
|
|
||||||
|
int val = convert<int>(params["value"]);
|
||||||
|
valueSB->setValue(val);
|
||||||
|
|
||||||
|
cmd = toqstr(params["vtype"]);
|
||||||
|
c = cmd.isEmpty() ? 0 : vtypeCB->findData(cmd);
|
||||||
|
if (c < 0) {
|
||||||
|
c = 0;
|
||||||
|
LYXERR0("Unable to find " << cmd << " in GuiCounter!");
|
||||||
|
}
|
||||||
|
vtypeCB->setCurrentIndex(c);
|
||||||
|
lyxonlyXB->setChecked(support::lowercase(params["lyxonly"]) == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiCounter::fillCombos()
|
||||||
|
{
|
||||||
|
counterCB->clear();
|
||||||
|
BufferView * bv = guiview.documentBufferView();
|
||||||
|
// should not happen, but...
|
||||||
|
if (!bv)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::vector<docstring> counts =
|
||||||
|
bv->buffer().params().documentClass().counters().listOfCounters();
|
||||||
|
for (auto const & c : counts)
|
||||||
|
counterCB->addItem(toqstr(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiCounter::paramsToDialog(Inset const * ip)
|
||||||
|
{
|
||||||
|
InsetCounter const * inset = static_cast<InsetCounter const *>(ip);
|
||||||
|
InsetCommandParams const & params = inset->params();
|
||||||
|
|
||||||
|
fillCombos();
|
||||||
|
processParams(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiCounter::initialiseParams(std::string const & data)
|
||||||
|
{
|
||||||
|
InsetCommandParams params(insetCode());
|
||||||
|
if (!InsetCommand::string2params(data, params))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fillCombos();
|
||||||
|
processParams(params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
docstring GuiCounter::dialogToParams() const
|
||||||
|
{
|
||||||
|
InsetCommandParams params(insetCode());
|
||||||
|
|
||||||
|
params["counter"] = qstring_to_ucs4(counterCB->currentText());
|
||||||
|
params["value"] = convert<docstring>(valueSB->value());
|
||||||
|
params.setCmdName(fromqstr(actionCB->currentData().toString()));
|
||||||
|
params["vtype"] = qstring_to_ucs4(vtypeCB->currentData().toString());
|
||||||
|
params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false");
|
||||||
|
return from_utf8(InsetCounter::params2string(params));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GuiCounter::checkWidgets(bool readonly) const
|
||||||
|
{
|
||||||
|
bool const cmdIsValue = actionCB->currentData().toString() == "value";
|
||||||
|
bool const cmdIsSet = actionCB->currentData().toString() == "set";
|
||||||
|
bool const cmdIsAddTo = actionCB->currentData().toString() == "addto";
|
||||||
|
counterCB->setEnabled(!readonly);
|
||||||
|
actionCB->setEnabled(!readonly);
|
||||||
|
valueSB->setEnabled(!readonly && (cmdIsSet || cmdIsAddTo));
|
||||||
|
if (cmdIsAddTo)
|
||||||
|
valueSB->setRange(-10000, 10000);
|
||||||
|
else
|
||||||
|
valueSB->setRange(0, 10000);
|
||||||
|
vtypeCB->setEnabled(!readonly && cmdIsValue);
|
||||||
|
if (!InsetParamsWidget::checkWidgets())
|
||||||
|
return false;
|
||||||
|
return !readonly &&
|
||||||
|
!counterCB->currentText().isEmpty() &&
|
||||||
|
!actionCB->currentText().isEmpty() &&
|
||||||
|
!(cmdIsValue && vtypeCB->currentText().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace frontend
|
||||||
|
} // namespace lyx
|
||||||
|
|
||||||
|
|
||||||
|
#include "moc_GuiCounter.cpp"
|
53
src/frontends/qt/GuiCounter.h
Normal file
53
src/frontends/qt/GuiCounter.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
/**
|
||||||
|
* \file GuiCounter.h
|
||||||
|
* This file is part of LyX, the document processor.
|
||||||
|
* Licence details can be found in the file COPYING.
|
||||||
|
*
|
||||||
|
* \author Richard Kimberly Heck
|
||||||
|
*
|
||||||
|
* Full author contact details are available in file CREDITS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GUICOUNTER_H
|
||||||
|
#define GUICOUNTER_H
|
||||||
|
|
||||||
|
#include "InsetParamsWidget.h"
|
||||||
|
#include "ui_CounterUi.h"
|
||||||
|
#include "GuiView.h"
|
||||||
|
|
||||||
|
namespace lyx {
|
||||||
|
class InsetCommandParams;
|
||||||
|
|
||||||
|
namespace frontend {
|
||||||
|
|
||||||
|
class GuiCounter : public InsetParamsWidget, public Ui::CounterUi
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
GuiCounter(GuiView & lv, QWidget * parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// \name InsetParamsWidget inherited methods
|
||||||
|
//@{
|
||||||
|
InsetCode insetCode() const { return COUNTER_CODE; }
|
||||||
|
FuncCode creationCode() const { return LFUN_INSET_INSERT; }
|
||||||
|
QString dialogTitle() const { return qt_("Counters"); }
|
||||||
|
void paramsToDialog(Inset const *);
|
||||||
|
docstring dialogToParams() const;
|
||||||
|
bool checkWidgets(bool readonly) const;
|
||||||
|
bool initialiseParams(std::string const & data);
|
||||||
|
//@}
|
||||||
|
void processParams(InsetCommandParams const & icp);
|
||||||
|
///
|
||||||
|
void fillCombos();
|
||||||
|
///
|
||||||
|
GuiView & guiview;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace frontend
|
||||||
|
} // namespace lyx
|
||||||
|
|
||||||
|
#endif // GUICOUNTER_H
|
@ -4715,7 +4715,7 @@ namespace {
|
|||||||
char const * const dialognames[] = {
|
char const * const dialognames[] = {
|
||||||
|
|
||||||
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
|
"aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
|
||||||
"citation", "compare", "comparehistory", "document", "errorlist", "ert",
|
"citation", "compare", "comparehistory", "counter", "document", "errorlist", "ert",
|
||||||
"external", "file", "findreplace", "findreplaceadv", "float", "graphics",
|
"external", "file", "findreplace", "findreplaceadv", "float", "graphics",
|
||||||
"href", "include", "index", "index_print", "info", "listings", "label", "line",
|
"href", "include", "index", "index_print", "info", "listings", "label", "line",
|
||||||
"log", "lyxfiles", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
|
"log", "lyxfiles", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "GuiBox.h"
|
#include "GuiBox.h"
|
||||||
#include "GuiBranch.h"
|
#include "GuiBranch.h"
|
||||||
#include "GuiBibitem.h"
|
#include "GuiBibitem.h"
|
||||||
|
#include "GuiCounter.h"
|
||||||
#include "GuiERT.h"
|
#include "GuiERT.h"
|
||||||
#include "GuiHSpace.h"
|
#include "GuiHSpace.h"
|
||||||
#include "GuiHyperlink.h"
|
#include "GuiHyperlink.h"
|
||||||
@ -281,6 +282,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
|
|||||||
case HYPERLINK_CODE:
|
case HYPERLINK_CODE:
|
||||||
widget = new GuiHyperlink;
|
widget = new GuiHyperlink;
|
||||||
break;
|
break;
|
||||||
|
case COUNTER_CODE:
|
||||||
|
widget = new GuiCounter(lv, nullptr);
|
||||||
|
break;
|
||||||
case INFO_CODE:
|
case INFO_CODE:
|
||||||
widget = new GuiInfo;
|
widget = new GuiInfo;
|
||||||
break;
|
break;
|
||||||
|
@ -25,6 +25,10 @@ namespace frontend {
|
|||||||
|
|
||||||
class InsetParamsWidget;
|
class InsetParamsWidget;
|
||||||
|
|
||||||
|
/// An InsetParamsDialog wraps an InsetParamsWidget, which is what
|
||||||
|
/// will contain all the specific dialog parts for a given inset.
|
||||||
|
/// This class manages the OK, etc, buttons and immediate apply
|
||||||
|
/// checkbox, etc.
|
||||||
class InsetParamsDialog : public DialogView, public Ui::InsetParamsUi
|
class InsetParamsDialog : public DialogView, public Ui::InsetParamsUi
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -87,6 +87,7 @@ SOURCEFILES = \
|
|||||||
GuiCompare.cpp \
|
GuiCompare.cpp \
|
||||||
GuiCompareHistory.cpp \
|
GuiCompareHistory.cpp \
|
||||||
GuiCompleter.cpp \
|
GuiCompleter.cpp \
|
||||||
|
GuiCounter.cpp \
|
||||||
GuiDelimiter.cpp \
|
GuiDelimiter.cpp \
|
||||||
GuiDialog.cpp \
|
GuiDialog.cpp \
|
||||||
GuiDocument.cpp \
|
GuiDocument.cpp \
|
||||||
@ -205,6 +206,7 @@ MOCHEADER = \
|
|||||||
GuiCompare.h \
|
GuiCompare.h \
|
||||||
GuiCompareHistory.h \
|
GuiCompareHistory.h \
|
||||||
GuiCompleter.h \
|
GuiCompleter.h \
|
||||||
|
GuiCounter.h \
|
||||||
GuiDelimiter.h \
|
GuiDelimiter.h \
|
||||||
GuiDialog.h \
|
GuiDialog.h \
|
||||||
GuiDocument.h \
|
GuiDocument.h \
|
||||||
@ -285,6 +287,7 @@ UIFILES = \
|
|||||||
ColorUi.ui \
|
ColorUi.ui \
|
||||||
CompareUi.ui \
|
CompareUi.ui \
|
||||||
CompareHistoryUi.ui \
|
CompareHistoryUi.ui \
|
||||||
|
CounterUi.ui \
|
||||||
DelimiterUi.ui \
|
DelimiterUi.ui \
|
||||||
DocumentUi.ui \
|
DocumentUi.ui \
|
||||||
ErrorListUi.ui \
|
ErrorListUi.ui \
|
||||||
|
81
src/frontends/qt/ui/CounterUi.ui
Normal file
81
src/frontends/qt/ui/CounterUi.ui
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CounterUi</class>
|
||||||
|
<widget class="QWidget" name="CounterUi">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>290</width>
|
||||||
|
<height>197</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="vtypeLA">
|
||||||
|
<property name="text">
|
||||||
|
<string>Value Type</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="valueLA">
|
||||||
|
<property name="text">
|
||||||
|
<string>Value</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QComboBox" name="actionCB"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="counterLA">
|
||||||
|
<property name="text">
|
||||||
|
<string>Counter</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="counterCB"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="valueSB">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>10000</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="actionLA">
|
||||||
|
<property name="text">
|
||||||
|
<string>Action</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QComboBox" name="vtypeCB"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="lyxonlyXB">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Affect counters only in LyX, not in output</string>
|
||||||
|
</property>
|
||||||
|
<property name="layoutDirection">
|
||||||
|
<enum>Qt::RightToLeft</enum>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>LyX Only</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<includes>
|
||||||
|
<include location="local">qt_i18n.h</include>
|
||||||
|
</includes>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user