Abdelrazak Younes wrote:
Abdelrazak Younes wrote:
Michael Gerz wrote:
BTW: "bottom" is ignored in 1.5.0svn/qt4. The tool bar is always
displayed at the top. Should I add a bugzilla report?
Yes, I am aware of it an I plaid guilty. Right now the toolbars are
hard-coded to be at the top because I didn't have the time to fix it
properly last christmas.
I am going to cleanup a bit the toolbars code.
This patch does so and should also fix the above bug.
Only qt4 for now... I am willing to adapt gtk to the Toolbars API change
but please, could we once and for all forget about qt3?
Abdel.
Log:
* LyXView.h:
- makeToolbar(): new pure virtual method
* qt4/GuiView.h:
- makeToolbar(): new method transferred from QLToolbar
* qt4/QLToolbar: derive from QToolBar instead of owning a QToolBar member.
* Toolbars.h: remove make_toolbar() prototype (use LyXView::makeToolbar
instead).
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 14911)
+++ frontends/LyXView.h (working copy)
@@ -13,6 +13,8 @@
#ifndef LYXVIEW_H
#define LYXVIEW_H
+#include "frontends/Toolbars.h"
+
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/signal.hpp>
@@ -20,7 +22,6 @@
#include <boost/utility.hpp>
class Buffer;
-class Toolbars;
class InsetBase;
class Intl;
class Menubar;
@@ -73,6 +74,8 @@
/// show busy cursor
virtual void busy(bool) const = 0;
+ virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const
& tbb) = 0;
+
//@{ generic accessor functions
/** return the current buffer view
Index: frontends/qt4/GuiView.C
===================================================================
--- frontends/qt4/GuiView.C (revision 14911)
+++ frontends/qt4/GuiView.C (working copy)
@@ -24,7 +24,6 @@
#include "debug.h"
-#include "frontends/Toolbars.h"
#include "frontends/WorkArea.h"
#include "support/filetools.h"
#include "support/convert.h"
@@ -36,6 +35,7 @@
#include "GuiView.h"
#include "QLMenubar.h"
+#include "QLToolbar.h"
#include "FontLoader.h"
#include "QCommandBuffer.h"
#include "qt_helpers.h"
@@ -245,6 +245,32 @@
QApplication::restoreOverrideCursor();
}
+
+Toolbars::ToolbarPtr GuiView::makeToolbar(ToolbarBackend::Toolbar const & tbb)
+{
+ QLToolbar * Tb = new QLToolbar(tbb, *this);
+ static QLToolbar * lastTb = 0;
+
+ if (tbb.flags & ToolbarBackend::TOP) {
+ addToolBar(Qt::TopToolBarArea, Tb);
+ addToolBarBreak(Qt::TopToolBarArea);
+ }
+ if (tbb.flags & ToolbarBackend::BOTTOM) {
+ addToolBar(Qt::BottomToolBarArea, Tb);
+ if (lastTb)
+ insertToolBarBreak(lastTb);
+ lastTb = Tb;
+ }
+ if (tbb.flags & ToolbarBackend::LEFT) {
+ addToolBar(Qt::LeftToolBarArea, Tb);
+ }
+ if (tbb.flags & ToolbarBackend::RIGHT) {
+ addToolBar(Qt::RightToolBarArea, Tb);
+ }
+
+ return Toolbars::ToolbarPtr(Tb);
+}
+
} // namespace frontend
} // namespace lyx
Index: frontends/qt4/GuiView.h
===================================================================
--- frontends/qt4/GuiView.h (revision 14911)
+++ frontends/qt4/GuiView.h (working copy)
@@ -60,6 +60,8 @@
/// show busy cursor
virtual void busy(bool) const;
+ Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb);
+
/// display a status message
virtual void message(std::string const & str);
Index: frontends/qt4/QLToolbar.C
===================================================================
--- frontends/qt4/QLToolbar.C (revision 14911)
+++ frontends/qt4/QLToolbar.C (working copy)
@@ -47,35 +47,7 @@
return lv.buffer()->params().getLyXTextClass();
}
-/*
-/// \todo Remove Qt::Dock getPosition(ToolbarBackend::Flags const & flags) if
not needed anymore
-Qt::Dock getPosition(ToolbarBackend::Flags const & flags)
-{
- if (flags & ToolbarBackend::TOP)
- return Qt::DockTop;
- if (flags & ToolbarBackend::BOTTOM)
- return Qt::DockBottom;
- if (flags & ToolbarBackend::LEFT)
- return Qt::DockLeft;
- if (flags & ToolbarBackend::RIGHT)
- return Qt::DockRight;
- return Qt::DockTop;
-}
-*/
-Qt::ToolBarArea getToolBarPosition(ToolbarBackend::Flags const & flags)
-{
- if (flags & ToolbarBackend::TOP)
- return Qt::TopToolBarArea;
- if (flags & ToolbarBackend::BOTTOM)
- return Qt::BottomToolBarArea;
- if (flags & ToolbarBackend::LEFT)
- return Qt::LeftToolBarArea;
- if (flags & ToolbarBackend::RIGHT)
- return Qt::RightToolBarArea;
- return Qt::TopToolBarArea;
-}
-
} // namespace anon
@@ -173,48 +145,17 @@
layoutSelected(owner_, sel);
}
-} // namespace frontend
-} // namespace lyx
-Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
- LyXView & owner)
+QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, GuiView & owner)
+ : owner_(owner),
+ QToolBar(qt_(tbb.gui_name), &owner)
{
- using lyx::frontend::QLToolbar;
- return Toolbars::ToolbarPtr(new QLToolbar(tbb, owner));
-}
-
-namespace lyx {
-namespace frontend {
-
-QLToolbar::QLToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
- : owner_(dynamic_cast<GuiView &>(owner)),
- toolbar_(new QToolBar(qt_(tbb.gui_name), (QWidget*) &owner_)) //,
getPosition(tbb.flags)))
-{
- /// \toto Move \a addToolBar call into QView because, in Qt4,
- /// the ToolBars placement is the duty of QMainWindow (aka QView)
- Qt::ToolBarArea tba = getToolBarPosition(tbb.flags);
- switch(tba) {
- case Qt::TopToolBarArea:
- owner_.addToolBar(tba, toolbar_);
- owner_.addToolBarBreak(tba);
- break;
-// case Qt::BottomToolBarArea:
- //bottomToolbarVector.push_back(toolbar_);
-// owner_.addToolBar(tba, toolbar_);
-// //if owner_.insertToolBarBreak(toolbar_);
- break;
- default:
- owner_.addToolBar(Qt::TopToolBarArea, toolbar_);
- owner_.addToolBarBreak(Qt::TopToolBarArea);
- break;
- }
-
// give visual separation between adjacent toolbars
- toolbar_->addSeparator();
+ addSeparator();
// allowing the toolbars to tear off is too easily done,
// and we don't save their orientation anyway. Disable the handle.
- toolbar_->setMovable(false);
+ setMovable(false);
ToolbarBackend::item_iterator it = tbb.items.begin();
ToolbarBackend::item_iterator end = tbb.items.end();
@@ -227,15 +168,15 @@
{
switch (func.action) {
case ToolbarBackend::SEPARATOR:
- toolbar_->addSeparator();
+ addSeparator();
break;
case ToolbarBackend::LAYOUTS:
- layout_.reset(new QLayoutBox(toolbar_, owner_));
+ layout_.reset(new QLayoutBox(this, owner_));
break;
case ToolbarBackend::MINIBUFFER:
- owner_.addCommandBuffer(toolbar_);
+ owner_.addCommandBuffer(this);
/// \todo find a Qt4 equivalent to
setHorizontalStretchable(true);
- //toolbar_->setHorizontalStretchable(true);
+ //setHorizontalStretchable(true);
break;
case LFUN_TABULAR_INSERT: {
QToolButton * tb = new QToolButton;
@@ -247,7 +188,7 @@
connect(tb, SIGNAL(toggled(bool)), iv, SLOT(show(bool)));
connect(iv, SIGNAL(visible(bool)), tb, SLOT(setChecked(bool)));
connect(this, SIGNAL(updated()), iv, SLOT(updateParent()));
- toolbar_->addWidget(tb);
+ addWidget(tb);
break;
}
default: {
@@ -255,7 +196,7 @@
break;
Action * action = new Action(owner_,
toolbarbackend.getIcon(func), "", func, tooltip);
- toolbar_->addAction(action);
+ addAction(action);
ActionVector.push_back(action);
break;
}
@@ -265,13 +206,13 @@
void QLToolbar::hide(bool)
{
- toolbar_->hide();
+ QToolBar::hide();
}
void QLToolbar::show(bool)
{
- toolbar_->show();
+ QToolBar::show();
}
Index: frontends/qt4/QLToolbar.h
===================================================================
--- frontends/qt4/QLToolbar.h (revision 14911)
+++ frontends/qt4/QLToolbar.h (working copy)
@@ -19,11 +19,10 @@
#include "frontends/Toolbars.h"
#include <boost/scoped_ptr.hpp>
-#include <QObject>
+#include <QToolBar>
#include <vector>
class QComboBox;
-class QToolBar;
namespace lyx {
namespace frontend {
@@ -58,10 +57,10 @@
};
-class QLToolbar : public QObject, public Toolbar {
+class QLToolbar : public QToolBar, public Toolbar {
Q_OBJECT
public:
- QLToolbar(ToolbarBackend::Toolbar const &, LyXView &);
+ QLToolbar(ToolbarBackend::Toolbar const &, GuiView &);
//~QLToolbar();
@@ -71,6 +70,8 @@
void update();
LayoutBox * layout() const { return layout_.get(); }
+
+
Q_SIGNALS:
void updated();
@@ -78,11 +79,8 @@
std::vector<Action *> ActionVector;
GuiView & owner_;
- QToolBar * toolbar_;
boost::scoped_ptr<QLayoutBox> layout_;
-
- Qt::ToolBarArea tba;
};
} // namespace frontend
Index: frontends/Toolbars.C
===================================================================
--- frontends/Toolbars.C (revision 14911)
+++ frontends/Toolbars.C (working copy)
@@ -116,7 +116,7 @@
void Toolbars::add(ToolbarBackend::Toolbar const & tbb)
{
- ToolbarPtr tb_ptr = make_toolbar(tbb, owner_);
+ ToolbarPtr tb_ptr = owner_.makeToolbar(tbb);
toolbars_[tbb.name] = tb_ptr;
if (tbb.flags & ToolbarBackend::ON)
Index: frontends/Toolbars.h
===================================================================
--- frontends/Toolbars.h (revision 14911)
+++ frontends/Toolbars.h (working copy)
@@ -131,8 +131,4 @@
/// Set the layout in the kernel when an entry has been selected
void layoutSelected(LyXView & lv, std::string const & name);
-/** Each GUI frontend should provide its own version of this.
- */
-Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const &, LyXView &);
-
#endif // NOT TOOLBARS_H