commit 9a147255df735d35dd03c3279bdbb35e39678ce0
Author: Richard Kimberly Heck <rikih...@lyx.org>
Date:   Thu Apr 30 21:58:14 2020 -0400

    GUI for new counter inset.
---
 lib/ui/stdcontext.inc                  |    7 ++
 lib/ui/stdmenus.inc                    |    1 +
 src/LyXAction.cpp                      |    2 +-
 src/frontends/qt/GuiCounter.cpp        |  174 ++++++++++++++++++++++++++++++++
 src/frontends/qt/GuiCounter.h          |   53 ++++++++++
 src/frontends/qt/GuiView.cpp           |    2 +-
 src/frontends/qt/InsetParamsDialog.cpp |    4 +
 src/frontends/qt/InsetParamsDialog.h   |    4 +
 src/frontends/qt/Makefile.am           |    3 +
 src/frontends/qt/ui/CounterUi.ui       |   81 +++++++++++++++
 10 files changed, 329 insertions(+), 2 deletions(-)

diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index d4db1f4..bd27a60 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -670,6 +670,13 @@ Menuset
        End
 
 #
+# InsetCounter context menu
+#
+       Menu "context-counter"
+               Item "Settings...|S" "inset-settings"
+       End
+
+#
 # Toolbar context menu
 #
        Menu "context-toolbars"
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index b6071b8..29fdcef 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -398,6 +398,7 @@ Menuset
                Item "URL|U" "flex-insert URL"
                Item "Hyperlink...|k" "href-insert"
                Item "Footnote|F" "footnote-insert"
+               Item "Counter" "dialog-show-new-inset counter"
                Item "Marginal Note|M" "marginalnote-insert"
                Item "Program Listing[[Menu]]" "listing-insert"
                Separator
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index c9f7625..3de816a 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1461,7 +1461,7 @@ void LyXAction::init()
  * \li Action: Shows hidden dialog or creates new one for a given 
function/inset settings etc.
  * \li Syntax: dialog-show <NAME> [<DATA>]
  * \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
                
mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n
                
print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n
diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp
new file mode 100644
index 0000000..a4a5c4a
--- /dev/null
+++ b/src/frontends/qt/GuiCounter.cpp
@@ -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"
diff --git a/src/frontends/qt/GuiCounter.h b/src/frontends/qt/GuiCounter.h
new file mode 100644
index 0000000..7b13256
--- /dev/null
+++ b/src/frontends/qt/GuiCounter.h
@@ -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
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 382496e..ba2951e 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -4715,7 +4715,7 @@ namespace {
 char const * const dialognames[] = {
 
 "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",
 "href", "include", "index", "index_print", "info", "listings", "label", "line",
 "log", "lyxfiles", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature",
diff --git a/src/frontends/qt/InsetParamsDialog.cpp 
b/src/frontends/qt/InsetParamsDialog.cpp
index a36de56..5cb25ac 100644
--- a/src/frontends/qt/InsetParamsDialog.cpp
+++ b/src/frontends/qt/InsetParamsDialog.cpp
@@ -15,6 +15,7 @@
 #include "GuiBox.h"
 #include "GuiBranch.h"
 #include "GuiBibitem.h"
+#include "GuiCounter.h"
 #include "GuiERT.h"
 #include "GuiHSpace.h"
 #include "GuiHyperlink.h"
@@ -281,6 +282,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
        case HYPERLINK_CODE:
                widget = new GuiHyperlink;
                break;
+       case COUNTER_CODE:
+               widget = new GuiCounter(lv, nullptr);
+               break;
        case INFO_CODE:
                widget = new GuiInfo;
                break;
diff --git a/src/frontends/qt/InsetParamsDialog.h 
b/src/frontends/qt/InsetParamsDialog.h
index 2d876ba..48385e2 100644
--- a/src/frontends/qt/InsetParamsDialog.h
+++ b/src/frontends/qt/InsetParamsDialog.h
@@ -25,6 +25,10 @@ namespace frontend {
 
 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
 {
        Q_OBJECT
diff --git a/src/frontends/qt/Makefile.am b/src/frontends/qt/Makefile.am
index f5f75cb..eb933c7 100644
--- a/src/frontends/qt/Makefile.am
+++ b/src/frontends/qt/Makefile.am
@@ -87,6 +87,7 @@ SOURCEFILES = \
        GuiCompare.cpp \
        GuiCompareHistory.cpp \
        GuiCompleter.cpp \
+       GuiCounter.cpp \
        GuiDelimiter.cpp \
        GuiDialog.cpp \
        GuiDocument.cpp \
@@ -205,6 +206,7 @@ MOCHEADER = \
        GuiCompare.h \
        GuiCompareHistory.h \
        GuiCompleter.h \
+       GuiCounter.h \
        GuiDelimiter.h \
        GuiDialog.h \
        GuiDocument.h \
@@ -285,6 +287,7 @@ UIFILES = \
        ColorUi.ui \
        CompareUi.ui \
        CompareHistoryUi.ui \
+       CounterUi.ui \
        DelimiterUi.ui \
        DocumentUi.ui \
        ErrorListUi.ui \
diff --git a/src/frontends/qt/ui/CounterUi.ui b/src/frontends/qt/ui/CounterUi.ui
new file mode 100644
index 0000000..93298e4
--- /dev/null
+++ b/src/frontends/qt/ui/CounterUi.ui
@@ -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>
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to