From f276338227547ffd7491bb7a1ec75cb0ce9336ad Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 5 Jun 2008 15:08:46 +0000 Subject: [PATCH] Preliminar InsetInfo dialog. This was done as an exercise to show Bo (an others) how easy it is to create a new dialog. This dialog needs to be filled in, right now, there is just an OK button. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25144 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 3 + lib/ui/stdcontext.inc | 9 +++ src/BufferView.cpp | 2 + src/frontends/qt4/GuiInfo.cpp | 104 ++++++++++++++++++++++++++++ src/frontends/qt4/GuiInfo.h | 51 ++++++++++++++ src/frontends/qt4/GuiView.cpp | 5 +- src/frontends/qt4/Makefile.am | 3 + src/frontends/qt4/ui/InfoUi.ui | 52 ++++++++++++++ src/insets/InsetInfo.cpp | 33 +++++++++ src/insets/InsetInfo.h | 6 ++ 10 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 src/frontends/qt4/GuiInfo.cpp create mode 100644 src/frontends/qt4/GuiInfo.h create mode 100644 src/frontends/qt4/ui/InfoUi.ui diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index 816b9b1172..ab30a4b0d0 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -718,6 +718,7 @@ src_frontends_qt4_header_files = Split(''' GuiIdListModel.h GuiImage.h GuiInclude.h + GuiInfo.h GuiKeySymbol.h GuiLabel.h GuiListings.h @@ -807,6 +808,7 @@ src_frontends_qt4_files = Split(''' GuiIdListModel.cpp GuiImage.cpp GuiInclude.cpp + GuiInfo.cpp GuiKeySymbol.cpp GuiLabel.cpp GuiListings.cpp @@ -887,6 +889,7 @@ src_frontends_qt4_ui_files = Split(''' HSpaceUi.ui HyperlinkUi.ui IncludeUi.ui + InfoUi.ui LabelUi.ui LaTeXUi.ui LanguageUi.ui diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 97f0cda1f7..784a3a7d7d 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -347,4 +347,13 @@ Menuset Item "Settings...|S" "inset-settings tabular" End + +# +# InsetInfo context menu +# + + Menu "context-info" + Item "Settings...|S" "inset-settings" + End + End diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 13e90d23f7..4ae5627279 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -943,6 +943,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) bool enable = false; InsetCode next_code = cur.nextInset() ? cur.nextInset()->lyxCode() : NO_CODE; + //FIXME: remove these special cases: switch (next_code) { case TABULAR_CODE: case ERT_CODE: @@ -952,6 +953,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case BRANCH_CODE: case BOX_CODE: case LISTINGS_CODE: + case INFO_CODE: enable = (cmd.argument().empty() || cmd.getArg(0) == insetName(next_code)); break; diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp new file mode 100644 index 0000000000..d8a104dda4 --- /dev/null +++ b/src/frontends/qt4/GuiInfo.cpp @@ -0,0 +1,104 @@ +/** + * \file GuiInfo.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GuiInfo.h" + +#include "qt_helpers.h" + +#include "Buffer.h" +#include "buffer_funcs.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "FuncRequest.h" + +#include "insets/InsetInfo.h" + +#include "support/debug.h" + + +using namespace std; + +namespace lyx { +namespace frontend { + +///////////////////////////////////////////////////////////////// +// +// GuiInfo +// +///////////////////////////////////////////////////////////////// + +GuiInfo::GuiInfo(GuiView & lv) + : DialogView(lv, "info", qt_("Info")) +{ + setupUi(this); +} + + +void GuiInfo::on_closePB_clicked() +{ + hide(); +} + + +InsetInfo * GuiInfo::inset() const +{ + return static_cast(bufferview()->cursor(). + innerInsetOfType(INFO_CODE)); +} + + +void GuiInfo::applyView() +{ + InsetInfo * ii = inset(); + if (!ii) + return; + + // FIXME: update the inset contents + + updateLabels(bufferview()->buffer()); + bufferview()->updateMetrics(); + bufferview()->buffer().changed(); +} + + +void GuiInfo::updateView() +{ + InsetInfo * ii = inset(); + if (!ii) { + // FIXME: A New button to create an InsetInfo at the cursor location + // would be nice. + enableView(false); + return; + } + //FIXME: update the controls. +} + + +void GuiInfo::enableView(bool enable) +{ + //FIXME: enable controls that need enabling. +} + + +void GuiInfo::dispatchParams() +{ +} + + +Dialog * createGuiInfo(GuiView & lv) { return new GuiInfo(lv); } + + +} // namespace frontend +} // namespace lyx + +#include "GuiInfo_moc.cpp" diff --git a/src/frontends/qt4/GuiInfo.h b/src/frontends/qt4/GuiInfo.h new file mode 100644 index 0000000000..c23525a9c4 --- /dev/null +++ b/src/frontends/qt4/GuiInfo.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +/** + * \file GuiInfo.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GUI_INFO_H +#define GUI_INFO_H + +#include "DialogView.h" +#include "ui_InfoUi.h" + +namespace lyx { + +class InsetInfo; + +namespace frontend { + +class GuiInfo : public DialogView, public Ui::InfoUi +{ + Q_OBJECT + +public: + GuiInfo(GuiView & lv); + + /// Dialog inherited methods + //@{ + void applyView(); + void updateView(); + void dispatchParams(); + void enableView(bool enable); + bool isBufferDependent() const { return true; } + //@} + +private Q_SLOTS: + void on_closePB_clicked(); + +private: + /// + InsetInfo * inset() const; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GUI_INFO_H diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 90e33c36ab..c71c7000ed 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2079,7 +2079,7 @@ namespace { char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", "citation", "document", "errorlist", "ert", "external", "file", -"findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log", +"findreplace", "float", "graphics", "include", "index", "info", "nomenclature", "label", "log", "mathdelimiter", "mathmatrix", "note", "paragraph", "prefs", "print", "ref", "sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate", @@ -2252,6 +2252,7 @@ Dialog * createGuiFloat(GuiView & lv); Dialog * createGuiGraphics(GuiView & lv); Dialog * createGuiHSpace(GuiView & lv); Dialog * createGuiInclude(GuiView & lv); +Dialog * createGuiInfo(GuiView & lv); Dialog * createGuiLabel(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); @@ -2316,6 +2317,8 @@ Dialog * GuiView::build(string const & name) return createGuiGraphics(*this); if (name == "include") return createGuiInclude(*this); + if (name == "info") + return createGuiInfo(*this); if (name == "nomenclature") return createGuiNomenclature(*this); if (name == "label") diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 6cba0cee25..14eeea81b2 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -89,6 +89,7 @@ SOURCEFILES = \ GuiIdListModel.cpp \ GuiImage.cpp \ GuiInclude.cpp \ + GuiInfo.cpp \ GuiKeySymbol.cpp \ GuiLabel.cpp \ GuiListings.cpp \ @@ -182,6 +183,7 @@ MOCHEADER = \ GuiHSpace.h \ GuiHyperlink.h \ GuiInclude.h \ + GuiInfo.h \ GuiLabel.h \ GuiListings.h \ GuiLog.h \ @@ -247,6 +249,7 @@ UIFILES = \ HSpaceUi.ui \ HyperlinkUi.ui \ IncludeUi.ui \ + InfoUi.ui \ LabelUi.ui \ LanguageUi.ui \ LaTeXUi.ui \ diff --git a/src/frontends/qt4/ui/InfoUi.ui b/src/frontends/qt4/ui/InfoUi.ui new file mode 100644 index 0000000000..8dc4650c28 --- /dev/null +++ b/src/frontends/qt4/ui/InfoUi.ui @@ -0,0 +1,52 @@ + + InfoUi + + + + 0 + 0 + 161 + 121 + + + + + + + true + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 84 + 20 + + + + + + + + &Close + + + true + + + + + + + qt_i18n.h + + + + diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 271539b4b6..2d09371421 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -16,6 +16,7 @@ #include "BufferParams.h" #include "BufferView.h" #include "FuncRequest.h" +#include "FuncStatus.h" #include "InsetGraphics.h" #include "InsetSpecialChar.h" #include "KeyMap.h" @@ -139,6 +140,32 @@ void InsetInfo::write(ostream & os) const } +bool InsetInfo::showInsetDialog(BufferView * bv) const +{ + bv->showDialog("info", "", const_cast(this)); + return true; +} + + +bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + switch (cmd.action) { + + case LFUN_INSET_MODIFY: + flag.setEnabled(true); + break; + //FIXME: do something. + /* + */ + + default: + return false; + } + return true; +} + + void InsetInfo::doDispatch(Cursor & cur, FuncRequest & cmd) { // FIXME: we should allow selection, copy etc... @@ -289,4 +316,10 @@ bool InsetInfo::setMouseHover(bool mouse_hover) return true; } + +docstring InsetInfo::contextMenu(BufferView const &, int, int) const +{ + return from_ascii("context-info"); +} + } // namespace lyx diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index 9ebe468500..f1e8ae65ab 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -105,6 +105,10 @@ public: /// void write(std::ostream & os) const; /// + bool showInsetDialog(BufferView * bv) const; + /// + bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; + /// void doDispatch(Cursor & cur, FuncRequest & cmd); /// InsetCode lyxCode() const { return INFO_CODE; } @@ -116,6 +120,8 @@ public: bool setMouseHover(bool mouse_hover); /// docstring toolTip(BufferView const & bv, int x, int y) const; + /// + docstring contextMenu(BufferView const &, int, int) const; private: /// The translator between the information type enum and corresponding string. -- 2.39.2