Jean-Marc Lasgouttes wrote: > This is supposed to work. What error message do you get?
patch attached. this allows tearing-off of the math panels with qt>= 4.2 (bugs 3839 and 3840) here the error: 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(61) : error C2352: 'QWidget::qt_metacast' : illegal call of non-static member function 1> c:\programs\qt\4.2.2\include\qtgui\../../src/gui/kernel/qwidget.h(117) : see declaration of 'QWidget::qt_metacast' 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(66) : error C2352: 'QWidget::qt_metacall' : illegal call of non-static member function 1> c:\programs\qt\4.2.2\include\qtgui\../../src/gui/kernel/qwidget.h(117) : see declaration of 'QWidget::qt_metacall' 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(72) : error C3861: 'visible': identifier not found 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(83) : error C2509: 'triggered' : member function not declared in 'lyx::frontend::IconPalette' 1> c:\lyx\build-msvc\src\frontends\qt4\../../../../trunk/src/frontends/qt4/IconPalette.h(32) : see declaration of 'lyx::frontend::IconPalette' 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(89) : error C2039: 'visible' : is not a member of 'lyx::frontend::IconPalette' 1> c:\lyx\build-msvc\src\frontends\qt4\../../../../trunk/src/frontends/qt4/IconPalette.h(32) : see declaration of 'lyx::frontend::IconPalette' 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(92) : error C2673: 'lyx::frontend::visible' : global functions do not have 'this' pointers 1>C:\lyx\build-msvc\src\frontends\qt4\IconPalette_moc.cpp(92) : error C2065: 'staticMetaObject' : undeclared identifier
Index: src/frontends/qt4/IconPalette.cpp =================================================================== --- src/frontends/qt4/IconPalette.cpp (revision 18748) +++ src/frontends/qt4/IconPalette.cpp (working copy) @@ -28,6 +28,69 @@ namespace lyx { namespace frontend { +#if QT_VERSION >= 0x040200 + +IconPalette::IconPalette(QObject * parent) + : QWidgetAction(parent) +{ +} + + +void IconPalette::addButton(QAction * action) +{ + actions_.push_back(action); +} + + +QWidget * IconPalette::createWidget(QWidget * parent) +{ + QWidget * panelwidget_ = new QWidget(parent); + QGridLayout * layout_ = new QGridLayout(panelwidget_); + layout_->setSpacing(0); + layout_->setMargin(3); + panelwidget_->setLayout(layout_); + + for (int i = 0; i < actions_.size(); ++i) { + QToolButton * tb = new QToolButton; + tb->setAutoRaise(true); + tb->setDefaultAction(actions_.at(i)); + connect(tb, SIGNAL(triggered(QAction *)), + this, SLOT(clicked(QAction *))); + QToolBar * toolbar = qobject_cast<QToolBar *>(parentWidget()->parentWidget()); + tb->setIconSize(toolbar->iconSize()); + connect(toolbar, SIGNAL(iconSizeChanged(const QSize &)), + tb, SLOT(setIconSize(const QSize &))); + + int const ncols = qMin(6, i + 1); + int const row = i/ncols + 1; + int const col = qMax(1, i + 1 - (row - 1) * 6); + layout_->addWidget(tb, row, col); + } + + return panelwidget_; +} + + +void IconPalette::clicked(QAction * action) +{ + QWidgetAction::activate(QAction::Trigger); +} + + +void IconPalette::updateParent() +{ + bool enable = false; + for (int i = 0; i < actions_.size(); ++i) + if (actions_.at(i)->isEnabled()) { + enable = true; + break; + } + + parentWidget()->setEnabled(enable); +} + +#else // QT_VERSION >= 0x040200 + IconPalette::IconPalette(QWidget * parent) : QWidget(parent, Qt::Popup) { @@ -151,6 +214,7 @@ // draw the rest (buttons) QWidget::paintEvent(event); } +#endif // QT_VERSION >= 0x040200 ButtonMenu::ButtonMenu(const QString & title, QWidget * parent) Index: src/frontends/qt4/IconPalette.h =================================================================== --- src/frontends/qt4/IconPalette.h (revision 18748) +++ src/frontends/qt4/IconPalette.h (working copy) @@ -17,12 +17,34 @@ #include <QLayout> #include "Action.h" +# if QT_VERSION >= 0x040200 +#include <QWidgetAction> +# endif + namespace lyx { namespace frontend { /** * For holding an arbitrary set of icons. */ +#if QT_VERSION >= 0x040200 + +class IconPalette : public QWidgetAction { + Q_OBJECT +public: + IconPalette(QObject * parent); + void addButton(QAction *); + QWidget * createWidget(QWidget * parent); +public Q_SLOTS: + void updateParent(); +private Q_SLOTS: + virtual void clicked(QAction *); +private: + QList<QAction *> actions_; +}; + +#else + class IconPalette : public QWidget { Q_OBJECT public: @@ -49,6 +71,8 @@ QList<QAction *> actions_; }; +#endif // QT_VERSION >= 0x040200 + /** * Popup menu for a toolbutton. * We need this to keep track whether Index: src/frontends/qt4/QLToolbar.cpp =================================================================== --- src/frontends/qt4/QLToolbar.cpp (revision 18748) +++ src/frontends/qt4/QLToolbar.cpp (working copy) @@ -207,7 +207,6 @@ } case ToolbarItem::ICONPALETTE: { QToolButton * tb = new QToolButton(this); - tb->setCheckable(true); tb->setToolTip(qt_(to_ascii(item.label_))); tb->setStatusTip(qt_(to_ascii(item.label_))); tb->setText(qt_(to_ascii(item.label_))); @@ -232,8 +231,20 @@ if (it == tbinfo.items.begin()) tb->setIcon(QPixmap(getIcon(it->func_).c_str())); } + +# if QT_VERSION >= 0x040200 + QMenu * m = new QMenu(tb); + m->addAction(panel); + m->setTearOffEnabled(true); + m->setWindowTitle(qt_(to_ascii(item.label_))); + tb->setPopupMode(QToolButton::InstantPopup); + tb->setMenu(m); +# else + tb->setCheckable(true); connect(tb, SIGNAL(clicked(bool)), panel, SLOT(setVisible(bool))); connect(panel, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool))); +# endif // QT_VERSION >= 0x040200 + addWidget(tb); break; } @@ -249,6 +260,8 @@ tb, SLOT(setIconSize(const QSize &))); ButtonMenu * m = new ButtonMenu(qt_(to_ascii(item.label_)), tb); + m->setWindowTitle(qt_(to_ascii(item.label_))); + m->setTearOffEnabled(true); connect(this, SIGNAL(updated()), m, SLOT(updateParent())); ToolbarInfo const & tbinfo = toolbarbackend.getToolbar(item.name_); ToolbarInfo::item_iterator it = tbinfo.items.begin();