]> git.lyx.org Git - features.git/commitdiff
Migrate GuiLabel to InsetParamsDialog.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 27 Oct 2010 17:25:55 +0000 (17:25 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 27 Oct 2010 17:25:55 +0000 (17:25 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35868 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiLabel.cpp
src/frontends/qt4/GuiLabel.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/InsetParamsDialog.cpp
src/frontends/qt4/ui/LabelUi.ui

index 8c46909f9eeed3640c0d2a7df4cbd6e989ba68a5..6d9ee79daee40e912f591210b08bc146d1655f68 100644 (file)
 
 #include "GuiLabel.h"
 
-#include "FuncRequest.h"
 #include "qt_helpers.h"
 
-#include "support/debug.h"
-#include "insets/InsetCommand.h"
+#include "insets/InsetLabel.h"
 
 #include <QLabel>
 #include <QPushButton>
@@ -33,82 +31,40 @@ namespace frontend {
 //
 /////////////////////////////////////////////////////////////////
 
-GuiLabel::GuiLabel(GuiView & lv)
-       : GuiDialog(lv, "label", qt_("Label")),
-         params_(insetCode("label"))
+GuiLabel::GuiLabel(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
        connect(keywordED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor()));
+               this, SIGNAL(changed()));
 
        setFocusProxy(keywordED);
-
-       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
-       bc().addReadOnly(keywordED);
 }
 
 
-void GuiLabel::change_adaptor()
+void GuiLabel::paramsToDialog(Inset const * inset)
 {
-       changed();
+       InsetLabel const * label = static_cast<InsetLabel const *>(inset);
+       InsetCommandParams const & params = label->params();
+       keywordED->setText(toqstr(params["name"]));
 }
 
 
-void GuiLabel::reject()
+docstring GuiLabel::dialogToParams() const
 {
-       slotClose();
+       InsetCommandParams params(insetCode());
+       params["name"] = qstring_to_ucs4(keywordED->text());
+       return from_ascii(InsetLabel::params2string("label", params));
 }
 
 
-void GuiLabel::updateContents()
-{
-       docstring const contents = params_["name"];
-       keywordED->setText(toqstr(contents));
-       bc().setValid(!contents.empty());
-}
-
-
-void GuiLabel::applyView()
-{
-       params_["name"] = qstring_to_ucs4(keywordED->text());
-}
-
-
-
-void GuiLabel::enableView(bool enable)
-{
-       keywordED->setEnabled(enable);
-}
-
-
-bool GuiLabel::isValid()
+bool GuiLabel::checkWidgets() const
 {
+       if (!InsetParamsWidget::checkWidgets())
+               return false;
        return !keywordED->text().isEmpty();
 }
 
-
-bool GuiLabel::initialiseParams(std::string const & data)
-{
-       InsetCommand::string2params("label", data, params_);
-       return true;
-}
-
-
-void GuiLabel::dispatchParams()
-{
-       std::string const lfun = InsetCommand::params2string("label", params_);
-       dispatch(FuncRequest(getLfun(), lfun));
-}
-
-
-Dialog * createGuiLabel(GuiView & lv) { return new GuiLabel(lv); }
-
-
 } // namespace frontend
 } // namespace lyx
 
index 64a9a0e8a1fa1bfb3a9ab9f86df474fd0bbf4f00..4e7a63f05d4bee0bdfce29872b01eaf16528713d 100644 (file)
 #ifndef GUILABEL_H
 #define GUILABEL_H
 
-#include "GuiDialog.h"
 #include "ui_LabelUi.h"
 
-#include "insets/InsetCommandParams.h"
+#include "InsetParamsWidget.h"
 
 namespace lyx {
 namespace frontend {
 
-class GuiLabel : public GuiDialog, public Ui::LabelUi
+class GuiLabel : public InsetParamsWidget, public Ui::LabelUi
 {
        Q_OBJECT
 
 public:
-       GuiLabel(GuiView & lv);
-
-private Q_SLOTS:
-       void change_adaptor();
-       void reject();
-
-private:
-       ///
-       bool isValid();
-       /// Apply changes
-       void applyView();
-       /// update
-       void updateContents();
-       ///
-       bool initialiseParams(std::string const & data);
-       /// clean-up on hide.
-       void clearParams() { params_.clear(); }
-       /// clean-up on hide.
-       void dispatchParams();
-       ///
-       bool isBufferDependent() const { return true; }
-       ///
-       void enableView(bool enable);
-       ///
-       bool canApply() const { return true; }
+       GuiLabel(QWidget * parent = 0);
 
 private:
-       ///
-       InsetCommandParams params_;
+       /// \name InsetParamsWidget inherited methods
+       //@{
+       InsetCode insetCode() const { return LABEL_CODE; }
+       FuncCode creationCode() const { return LFUN_INSET_INSERT; }
+       void paramsToDialog(Inset const *);
+       docstring dialogToParams() const;
+       bool checkWidgets() const;
+       //@}
 };
 
 } // namespace frontend
index 4cc75d365eaad1fb17e63b7371090b9033926b73..b20d38e22bcdaaab1fe47714239e7d8bff9617e4 100644 (file)
@@ -3771,7 +3771,6 @@ Dialog * createGuiExternal(GuiView & lv);
 Dialog * createGuiGraphics(GuiView & lv);
 Dialog * createGuiInclude(GuiView & lv);
 Dialog * createGuiIndex(GuiView & lv);
-Dialog * createGuiLabel(GuiView & lv);
 Dialog * createGuiListings(GuiView & lv);
 Dialog * createGuiLog(GuiView & lv);
 Dialog * createGuiMathMatrix(GuiView & lv);
@@ -3794,7 +3793,6 @@ Dialog * createGuiTabularCreate(GuiView & lv);
 Dialog * createGuiTexInfo(GuiView & lv);
 Dialog * createGuiToc(GuiView & lv);
 Dialog * createGuiThesaurus(GuiView & lv);
-Dialog * createGuiHyperlink(GuiView & lv);
 Dialog * createGuiViewSource(GuiView & lv);
 Dialog * createGuiWrap(GuiView & lv);
 Dialog * createGuiProgressView(GuiView & lv);
@@ -3843,8 +3841,6 @@ Dialog * GuiView::build(string const & name)
                return createGuiIndex(*this);
        if (name == "index_print")
                return createGuiPrintindex(*this);
-       if (name == "label")
-               return createGuiLabel(*this);
        if (name == "listings")
                return createGuiListings(*this);
        if (name == "log")
index bd7251bdd50b550408bb70ad600bc2fa812b0349..c262336f82c6983e97378e4264b682177bbb3715 100644 (file)
@@ -18,6 +18,7 @@
 #include "GuiERT.h"\r
 #include "GuiHyperlink.h"\r
 #include "GuiInfo.h"\r
+#include "GuiLabel.h"\r
 #include "GuiLine.h"\r
 #include "GuiHSpace.h"\r
 #include "GuiTabular.h"\r
@@ -239,6 +240,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
        case INFO_CODE:\r
                widget = new GuiInfo;\r
                break;\r
+       case LABEL_CODE:\r
+               widget = new GuiLabel;\r
+               break;\r
        case LINE_CODE:\r
                widget = new GuiLine;\r
                break;\r
index a32d96dda49cfed236f2e877f274c027f320322f..0679e2a6896e8958d6602755d57cadbd2b08d160 100644 (file)
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>LabelUi</class>
- <widget class="QDialog" name="LabelUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="LabelUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>300</width>
-    <height>82</height>
+    <height>71</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <property name="sizeGripEnabled" >
-   <bool>true</bool>
-  </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>11</number>
-   </property>
-   <property name="spacing" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
     <number>6</number>
    </property>
+   <property name="margin">
+    <number>11</number>
+   </property>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
+    <layout class="QHBoxLayout">
+     <property name="spacing">
       <number>6</number>
      </property>
-     <item>
-      <widget class="QLabel" name="keywordLA" >
-       <property name="toolTip" >
-        <string/>
-       </property>
-       <property name="text" >
-        <string>&amp;Label:</string>
-       </property>
-       <property name="buddy" >
-        <cstring>keywordED</cstring>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="keywordED" >
-       <property name="toolTip" >
-        <string/>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
+     <property name="margin">
       <number>0</number>
      </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
      <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::Expanding</enum>
+      <widget class="QLabel" name="keywordLA">
+       <property name="toolTip">
+       <string/>
        </property>
-       <property name="sizeHint" >
-        <size>
-         <width>20</width>
-         <height>20</height>
-        </size>
+       <property name="text">
+       <string>&amp;Label:</string>
        </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
-        <string>&amp;OK</string>
-       </property>
-       <property name="default" >
-        <bool>true</bool>
+       <property name="buddy">
+       <cstring>keywordED</cstring>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="closePB" >
-       <property name="text" >
-        <string>Cancel</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
-       </property>
-       <property name="default" >
-        <bool>false</bool>
+      <widget class="QLineEdit" name="keywordED">
+       <property name="toolTip">
+       <string/>
        </property>
       </widget>
      </item>
   </layout>
  </widget>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>