]> git.lyx.org Git - features.git/commitdiff
initial basic context menu support.
authorAbdelrazak Younes <younes@lyx.org>
Wed, 26 Dec 2007 12:40:58 +0000 (12:40 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Wed, 26 Dec 2007 12:40:58 +0000 (12:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22309 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/Menus.cpp
src/frontends/qt4/Menus.h
src/insets/Inset.cpp
src/insets/Inset.h

index 3cab67b0957b18b6f245daf88b38c312fb67f1e0..3fdb769ed792b49a9beb6d1cf710b61a1ac33c5f 100644 (file)
@@ -492,10 +492,15 @@ docstring BufferView::toolTip(int x, int y) const
 }
 
 
-Menu const & BufferView::contextMenu(int x, int y) const
+docstring BufferView::contextMenu(int x, int y) const
 {
+       // Get inset under mouse, if there is one.
+       Inset const * covering_inset = getCoveringInset(buffer_.text(), x, y);
+       if (covering_inset)
+               return covering_inset->contextMenu(*this, x, y);
+
        // FIXME: Do something more elaborate here.
-       return theApp()->menuBackend().getMenu(from_ascii("edit"));
+       return from_ascii("edit");
 }
 
 
index 53821b76931c1cecee2765e303a9f9a370a3edc8..f1897cb96449ddb3c9cdeaba07afe070a80b0c92 100644 (file)
@@ -108,7 +108,7 @@ public:
        /// \return Tool tip for the given position.
        docstring toolTip(int x, int y) const;
        /// \return the context menu for the given position.
-       Menu const & contextMenu(int x, int y) const;
+       docstring contextMenu(int x, int y) const;
 
        /// Save the current position as bookmark.
        /// if idx == 0, save to temp_bookmark
index 72df7a3e081d65a9f95474643cbe045a862bdf41..85890fed8e46cc0892434671d7aed338949573c1 100644 (file)
@@ -1365,7 +1365,8 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                        break;
 
                case LFUN_MENU_OPEN:
-                       guiApp->menus().openByName(toqstr(cmd.argument()));
+                       if (QMenu * menu = guiApp->menus().menu(toqstr(cmd.argument())))
+                               menu->exec(QCursor::pos());
                        break;
 
                case LFUN_FILE_INSERT:
index fe83308bc77d02be451abefdf7860f196e1f23c3..0f710371837bcf3be36d447195528fe05b9128d5 100644 (file)
@@ -519,12 +519,22 @@ bool GuiWorkArea::event(QEvent * e)
 void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
 {
        QPoint pos = e->pos();
-       Menu const & menu = buffer_view_->contextMenu(pos.x(), pos.y());
-       LYXERR(Debug::GUI, "context menu resquested: " << menu.name());
-
-       // FIXME: do something with GuiPopupMenu and MenuBackend.
-       // Some cleanups of GuiPopupMenu and GuiMenubar are needed
-       // before!
+       docstring name = buffer_view_->contextMenu(pos.x(), pos.y());
+       if (name.empty()) {
+               QAbstractScrollArea::contextMenuEvent(e);
+               return;
+       }
+       QMenu * menu = guiApp->menus().menu(toqstr(name));
+       if (!menu) {
+               QAbstractScrollArea::contextMenuEvent(e);
+               return;
+       }
+       // Position the menu to the right.
+       // FIXME: menu position should be different for RTL text.
+       pos.rx() += menu->width();
+       // FIXME: correct vertical position of the menu WRT screen espace.
+       //pos.ry() += menu->height();
+       menu->exec(pos);
        QAbstractScrollArea::contextMenuEvent(e);
 }
 
index f47d94d1aa68992686654d6a91fd35a85965aeea..9175d23cff0ac5e7ceada96c87d1996f3c54ed09 100644 (file)
@@ -86,10 +86,15 @@ void Menus::fillMenuBar(GuiView * view)
 }
 
 
-void Menus::openByName(QString const & name)
+QMenu * Menus::menu(QString const & name)
 {
-       if (QMenu * menu = name_map_.value(name))
-               menu->exec(QCursor::pos());
+       LYXERR(Debug::GUI, "Context menu requested: "
+               << qstring_to_ucs4(name));
+       GuiPopupMenu * menu = name_map_.value(name, 0);
+       if (!menu)
+               LYXERR0("resquested context menu not found: "
+                       << qstring_to_ucs4(name));
+       return menu;
 }
 
 
index 633cd721511a2df9576aea62c466e23c66e7ee40..6f67d1d5e141d26acdd84aa6c0e25bba97285fb1 100644 (file)
@@ -34,8 +34,8 @@ public:
        ///
        void fillMenuBar(GuiView * view);
 
-       /// opens a top-level submenu given its name
-       void openByName(QString const & name);
+       /// \return a top-level submenu given its name.
+       QMenu * menu(QString const & name);
 
        /// update the state of the menuitems - not needed
        void updateView();
@@ -46,7 +46,7 @@ private:
 
        typedef QHash<QString, GuiPopupMenu *> NameMap;
 
-       /// name to menu for openByName
+       /// name to menu for \c menu() method.
        NameMap name_map_;
 };
 
index 7e833e450b65bd9a362674b4fd20f04877c315d4..616c180c3a45f1be24c1e4a16901b3dec0e24a88 100644 (file)
@@ -131,6 +131,12 @@ docstring Inset::toolTip(BufferView const &, int, int) const
 }
 
 
+docstring Inset::contextMenu(BufferView const &, int, int) const
+{
+       return docstring();
+}
+
+
 Dimension const Inset::dimension(BufferView const & bv) const
 {
        return bv.coordCache().getInsets().dim(this);
index a519ec536f5dbab560a5aff778631c9dcfc5815b..c512abc27b09f74366bb93efc50abc464e48d0a5 100644 (file)
@@ -288,6 +288,10 @@ public:
        /// This default implementation returns an empty string.
        virtual docstring toolTip(BufferView const & bv, int x, int y) const;
        
+       /// \return Context menu identifier for this inset.
+       /// This default implementation returns an empty string.
+       virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
+
        // FIXME This should really disappear in favor of 
        //      docstring name() const { return from_ascii(insetName(lyxCode()))); }
        // There's no reason to be using different names in different places.