From ebff6bd6fb5619fe25cfffe5eb316fd9f42009c0 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 24 Aug 2007 07:13:07 +0000 Subject: [PATCH] Transfer command buffer handling to QLToolbar. * Toolbar::focusCommandBuffer(): new pure virtual method. * Toolbars::display(): now return the address of the found toolbar. * GuiView: get rid of command_buffer_, transferred to QLToolbar. * QCommandBuffer: replace focus_command with setFocusProxy on edit_; git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19767 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/Toolbars.cpp | 10 ++++++---- src/frontends/Toolbars.h | 7 +++++-- src/frontends/qt4/GuiView.cpp | 18 ++++-------------- src/frontends/qt4/GuiView.h | 8 -------- src/frontends/qt4/QCommandBuffer.cpp | 8 +------- src/frontends/qt4/QCommandBuffer.h | 2 -- src/frontends/qt4/QLToolbar.cpp | 13 +++++++++++-- src/frontends/qt4/QLToolbar.h | 6 ++++-- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/frontends/Toolbars.cpp b/src/frontends/Toolbars.cpp index eae9f96ed3..49f3073e1b 100644 --- a/src/frontends/Toolbars.cpp +++ b/src/frontends/Toolbars.cpp @@ -144,7 +144,7 @@ void Toolbars::init() } -void Toolbars::display(string const & name, bool show) +Toolbar * Toolbars::display(string const & name, bool show) { ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin(); ToolbarBackend::Toolbars::iterator end = toolbarbackend.end(); @@ -160,13 +160,13 @@ void Toolbars::display(string const & name, bool show) else TurnOnFlag(OFF); cit->flags = static_cast(flags); - displayToolbar(*cit, show); - return; + return displayToolbar(*cit, show); } } LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named " << name << endl; + return 0; } @@ -329,7 +329,7 @@ void Toolbars::add(ToolbarInfo const & tbinfo, bool newline) } -void Toolbars::displayToolbar(ToolbarInfo const & tbinfo, +Toolbar * Toolbars::displayToolbar(ToolbarInfo const & tbinfo, bool show_it) { ToolbarsMap::iterator it = toolbars_.find(tbinfo.name); @@ -339,6 +339,8 @@ void Toolbars::displayToolbar(ToolbarInfo const & tbinfo, it->second->show(true); else it->second->hide(true); + + return it->second.get(); } diff --git a/src/frontends/Toolbars.h b/src/frontends/Toolbars.h index 1828bcf6bb..4255123d2f 100644 --- a/src/frontends/Toolbars.h +++ b/src/frontends/Toolbars.h @@ -79,6 +79,9 @@ public: virtual void update() = 0; /// Accessor to the layout combox, if any. virtual LayoutBox * layout() const = 0; + + /// Set the focus on the command buffer, if any. + virtual void focusCommandBuffer() = 0; }; @@ -91,7 +94,7 @@ public: void init(); /// Show/hide the named toolbar. - void display(std::string const & name, bool show); + Toolbar * display(std::string const & name, bool show); /// get toolbar info ToolbarInfo * getToolbarInfo(std::string const & name); @@ -130,7 +133,7 @@ private: /// Add a new toolbar. if newline==true, start from a new line void add(ToolbarInfo const & tbinfo, bool newline); /// Show or hide a toolbar. - void displayToolbar(ToolbarInfo const & tbinfo, bool show); + Toolbar * displayToolbar(ToolbarInfo const & tbinfo, bool show); /// Update the state of the icons void update(); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 8bf6a73abc..a8ebf88d77 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -20,7 +20,6 @@ #include "QKeySymbol.h" #include "QLMenubar.h" #include "QLToolbar.h" -#include "QCommandBuffer.h" #include "qt_helpers.h" #include "frontends/Application.h" @@ -216,7 +215,7 @@ unsigned int GuiView::GuiViewPrivate::lastIconSize = 0; GuiView::GuiView(int id) - : QMainWindow(), LyXView(id), commandbuffer_(0), quitting_by_menu_(false), + : QMainWindow(), LyXView(id), quitting_by_menu_(false), d(*new GuiViewPrivate) { // Qt bug? signal lastWindowClosed does not work @@ -571,13 +570,6 @@ void GuiView::setWindowTitle(docstring const & t, docstring const & it) } -void GuiView::addCommandBuffer(QToolBar * toolbar) -{ - commandbuffer_ = new QCommandBuffer(this); - toolbar->addWidget(commandbuffer_); -} - - void GuiView::message(docstring const & str) { statusBar()->showMessage(toqstr(str)); @@ -934,11 +926,9 @@ void GuiView::removeWorkArea(WorkArea * work_area) void GuiView::showMiniBuffer(bool visible) { - if (!commandbuffer_) - return; - - toolbars_->display("minibuffer", visible); - commandbuffer_->focus_command(); + Toolbar * t = toolbars_->display("minibuffer", visible); + if (t) + t->focusCommandBuffer(); } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index e4ab76331d..3f221e2b24 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -32,8 +32,6 @@ class QToolBar; namespace lyx { namespace frontend { -class QCommandBuffer; - QWidget* mainWindow(); /** @@ -77,9 +75,6 @@ public: /// show - display the top-level window void show(); - /// add the command buffer - void addCommandBuffer(QToolBar * toolbar); - /// menu item has been selected void activated(FuncRequest const &); @@ -142,9 +137,6 @@ private: QTimer statusbar_timer_; - /// command buffer - QCommandBuffer * commandbuffer_; - /// are we quitting by the menu? bool quitting_by_menu_; diff --git a/src/frontends/qt4/QCommandBuffer.cpp b/src/frontends/qt4/QCommandBuffer.cpp index edfb12b1a0..9789b40bb2 100644 --- a/src/frontends/qt4/QCommandBuffer.cpp +++ b/src/frontends/qt4/QCommandBuffer.cpp @@ -110,13 +110,7 @@ QCommandBuffer::QCommandBuffer(GuiView * view) layout->setMargin(0); top->addLayout(layout); top->setMargin(0); -} - - - -void QCommandBuffer::focus_command() -{ - edit_->setFocus(); + setFocusProxy(edit_); } diff --git a/src/frontends/qt4/QCommandBuffer.h b/src/frontends/qt4/QCommandBuffer.h index 14dd5ee8f8..f13426eb32 100644 --- a/src/frontends/qt4/QCommandBuffer.h +++ b/src/frontends/qt4/QCommandBuffer.h @@ -29,8 +29,6 @@ class QCommandBuffer : public QWidget { public: QCommandBuffer(GuiView * view); - /// focus the edit widget - void focus_command(); public Q_SLOTS: /// cancel command compose void cancel(); diff --git a/src/frontends/qt4/QLToolbar.cpp b/src/frontends/qt4/QLToolbar.cpp index 29c56ac459..d8ef423d95 100644 --- a/src/frontends/qt4/QLToolbar.cpp +++ b/src/frontends/qt4/QLToolbar.cpp @@ -24,6 +24,7 @@ #include "IconPalette.h" #include "GuiView.h" +#include "QCommandBuffer.h" #include "QLToolbar.h" #include "LyXAction.h" #include "Action.h" @@ -159,7 +160,7 @@ void QLayoutBox::selected(const QString & str) QLToolbar::QLToolbar(ToolbarInfo const & tbinfo, GuiView & owner) - : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner) + : QToolBar(qt_(tbinfo.gui_name), &owner), command_buffer_(0), owner_(owner) { // give visual separation between adjacent toolbars addSeparator(); @@ -174,6 +175,13 @@ QLToolbar::QLToolbar(ToolbarInfo const & tbinfo, GuiView & owner) } +void QLToolbar::focusCommandBuffer() +{ + if (command_buffer_) + command_buffer_->setFocus(); +} + + void QLToolbar::add(ToolbarItem const & item) { switch (item.type_) { @@ -184,7 +192,8 @@ void QLToolbar::add(ToolbarItem const & item) layout_.reset(new QLayoutBox(this, owner_)); break; case ToolbarItem::MINIBUFFER: - owner_.addCommandBuffer(this); + command_buffer_ = new QCommandBuffer(&owner_); + addWidget(command_buffer_); /// \todo find a Qt4 equivalent to setHorizontalStretchable(true); //setHorizontalStretchable(true); break; diff --git a/src/frontends/qt4/QLToolbar.h b/src/frontends/qt4/QLToolbar.h index 5e01cd5dd6..f2f97ce741 100644 --- a/src/frontends/qt4/QLToolbar.h +++ b/src/frontends/qt4/QLToolbar.h @@ -31,6 +31,7 @@ namespace lyx { class FuncRequest; namespace frontend { +class QCommandBuffer; class QLayoutBox; class GuiView; class Action; @@ -75,13 +76,14 @@ public: void saveInfo(ToolbarSection::ToolbarInfo & info); void update(); LayoutBox * layout() const { return layout_.get(); } - - + /// + void focusCommandBuffer(); Q_SIGNALS: void updated(); private: + QCommandBuffer * command_buffer_; std::vector ActionVector; GuiView & owner_;