On Mon, Jun 13, 2005 at 02:36:32PM +0100, Angus Leeming wrote: > Angus Leeming wrote: > > > Andre Poenitz wrote: > >> Of course, creating a context menu on right-click which a combo box of > >> all available colors is a matter of 20 lines or so in 'pure' Qt, but I > >> really don't know how to set this up in LyX's GUII scheme. > > > > Shrug. Let me paint a picture: > > Actually, it's even simpler. One CSMenu per BufferView, I suppose. Here's > a complete but of course untested, implementation.
Ok...... > frontends/csmenu.h > ================== > class CSMenu { > public: > CSMenu() : impl_(Impl::build()) {} > > // Define the position of the CSM. > // Use a LyX type in real code. > typedef QPoint point_type; > > typedef std::vector<std::string> menu_data_type; > typedef menu_data_type::size_type size_type; > static const size_type npos = static_cast<size_type>(-1); > > /** \returns ID of the selected data item. > * \returns npos if nothing was selected. > */ > size_type show(point_type const & position, > menu_data_type const & data) const { > return impl_->show(position, data); > } > > protected: > class Impl { > public: > // Implemented in the frontend > static boost::shared_ptr<Impl> build(); > > virtual size_type show(point_type const & position, > menu_data_type const &) const = 0; > }; > > private: > boost::shared_ptr<Impl> impl_; > }; > > > frontends/qt_csmenu.[Ch] > ======================== > #include <qpopupmenu.h> > > class Qt_CSMenu : CSMenu::Impl { > public: > size_type show(point_type const & position, > menu_data_type const & data) const > { > typedef menu_data_type::const_iterator iterator; > iterator const end = data.end(); > for (iterator it = data.begin(); it != end; ++it) > menu_.insertItem(toqstr(*it)); > size_type const result menu_.exec(pos); > menu_.clear(); > return result; > } > private: > QPopupMenu menu_; > }; > > > boost::shared_ptr<CSMenu::Impl> CSMenu::Impl::build() > { > return boost::shared_ptr<CSMenu::Impl>(new Qt_CSMenu); > } > > > Do I miss anything? Not bad for starters. The obvious next candidate would be a context menu for the formula type. Or left/right delimiters... Well. You miss something that wasn't said: It would be nice if that context 'menu' 'scaled' up to a degree where macro definitions could be handled as well. This is more or less an arbitrary dialog popping up, not just a list of words to select from. Andre'