mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Move most of the Gui specific code in Toolbars to its new qt4 specialization GuiToolbars.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20644 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ef925d8463
commit
3ca9ddb6ed
@ -253,9 +253,6 @@ public:
|
||||
boost::signal<void(std::string name,
|
||||
std::string data)> updateDialog;
|
||||
|
||||
/// This signal is emitted when the layout at the cursor is changed.
|
||||
boost::signal<void(docstring layout)> layoutChanged;
|
||||
|
||||
private:
|
||||
// the position relative to (0, baseline) of outermost paragraph
|
||||
Point coordOffset(DocIterator const & dit, bool boundary) const;
|
||||
|
@ -86,10 +86,6 @@ using cap::replaceSelection;
|
||||
using support::isStrUnsignedInt;
|
||||
using support::token;
|
||||
|
||||
namespace frontend {
|
||||
extern docstring current_layout;
|
||||
}
|
||||
|
||||
// globals...
|
||||
static Font freefont(Font::ALL_IGNORE);
|
||||
static bool toggleall = false;
|
||||
@ -772,6 +768,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
docstring layout = cmd.argument();
|
||||
LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) << endl;
|
||||
|
||||
docstring const old_layout = cur.paragraph().layout()->name();
|
||||
|
||||
// Derive layout number from given argument (string)
|
||||
// and current buffer's textclass (number)
|
||||
TextClass const & tclass = bv->buffer().params().getTextClass();
|
||||
@ -792,7 +790,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
}
|
||||
|
||||
bool change_layout = (frontend::current_layout != layout);
|
||||
bool change_layout = (old_layout != layout);
|
||||
|
||||
if (!change_layout && cur.selection() &&
|
||||
cur.selBegin().pit() != cur.selEnd().pit())
|
||||
@ -800,7 +798,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
pit_type spit = cur.selBegin().pit();
|
||||
pit_type epit = cur.selEnd().pit() + 1;
|
||||
while (spit != epit) {
|
||||
if (pars_[spit].layout()->name() != frontend::current_layout) {
|
||||
if (pars_[spit].layout()->name() != old_layout) {
|
||||
change_layout = true;
|
||||
break;
|
||||
}
|
||||
@ -808,11 +806,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
}
|
||||
|
||||
if (change_layout) {
|
||||
if (change_layout)
|
||||
setLayout(cur, layout);
|
||||
// inform the GUI that the layout has changed.
|
||||
bv->layoutChanged(layout);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -64,11 +64,8 @@ using support::onlyFilename;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
docstring current_layout;
|
||||
|
||||
LyXView::LyXView(int id)
|
||||
: toolbars_(new Toolbars(*this)),
|
||||
autosave_timeout_(new Timeout(5000)),
|
||||
: autosave_timeout_(new Timeout(5000)),
|
||||
dialogs_(new Dialogs(*this)),
|
||||
id_(id)
|
||||
{
|
||||
@ -86,7 +83,6 @@ LyXView::~LyXView()
|
||||
disconnectBuffer();
|
||||
disconnectBufferView();
|
||||
delete dialogs_;
|
||||
delete toolbars_;
|
||||
delete autosave_timeout_;
|
||||
}
|
||||
|
||||
@ -214,7 +210,6 @@ void LyXView::disconnectBuffer()
|
||||
titleConnection_.disconnect();
|
||||
timerConnection_.disconnect();
|
||||
readonlyConnection_.disconnect();
|
||||
layout_changed_connection_.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@ -230,8 +225,6 @@ void LyXView::connectBufferView(BufferView & bv)
|
||||
boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3));
|
||||
update_dialog_connection_ = bv.updateDialog.connect(
|
||||
boost::bind(&LyXView::updateDialog, this, _1, _2));
|
||||
layout_changed_connection_ = bv.layoutChanged.connect(
|
||||
boost::bind(&Toolbars::setLayout, toolbars_, _1));
|
||||
}
|
||||
|
||||
|
||||
@ -306,47 +299,6 @@ void LyXView::updateEmbeddedFiles()
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateToolbars()
|
||||
{
|
||||
WorkArea * wa = currentWorkArea();
|
||||
if (wa) {
|
||||
bool const math =
|
||||
wa->bufferView().cursor().inMathed();
|
||||
bool const table =
|
||||
lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
|
||||
bool const review =
|
||||
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
|
||||
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
|
||||
|
||||
toolbars_->update(math, table, review);
|
||||
} else
|
||||
toolbars_->update(false, false, false);
|
||||
|
||||
// update redaonly status of open dialogs.
|
||||
getDialogs().checkStatus();
|
||||
}
|
||||
|
||||
|
||||
ToolbarInfo * LyXView::getToolbarInfo(string const & name)
|
||||
{
|
||||
return toolbars_->getToolbarInfo(name);
|
||||
}
|
||||
|
||||
|
||||
void LyXView::toggleToolbarState(string const & name, bool allowauto)
|
||||
{
|
||||
// it is possible to get current toolbar status like this,...
|
||||
// but I decide to obey the order of ToolbarBackend::flags
|
||||
// and disregard real toolbar status.
|
||||
// toolbars_->saveToolbarInfo();
|
||||
//
|
||||
// toggle state on/off/auto
|
||||
toolbars_->toggleToolbarState(name, allowauto);
|
||||
// update toolbar
|
||||
updateToolbars();
|
||||
}
|
||||
|
||||
|
||||
void LyXView::autoSave()
|
||||
{
|
||||
LYXERR(Debug::INFO) << "Running autoSave()" << endl;
|
||||
@ -363,29 +315,6 @@ void LyXView::resetAutosaveTimer()
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateLayoutChoice()
|
||||
{
|
||||
// Don't show any layouts without a buffer
|
||||
if (!buffer()) {
|
||||
toolbars_->clearLayoutList();
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the layout display
|
||||
if (toolbars_->updateLayoutList(buffer()->params().getTextClassPtr())) {
|
||||
current_layout = buffer()->params().getTextClass().defaultLayoutName();
|
||||
}
|
||||
|
||||
docstring const & layout = currentWorkArea()->bufferView().cursor().
|
||||
innerParagraph().layout()->name();
|
||||
|
||||
if (layout != current_layout) {
|
||||
toolbars_->setLayout(layout);
|
||||
current_layout = layout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LyXView::updateWindowTitle()
|
||||
{
|
||||
docstring maximize_title = from_ascii("LyX");
|
||||
@ -438,16 +367,5 @@ Buffer const * LyXView::updateInset(Inset const * inset)
|
||||
}
|
||||
|
||||
|
||||
void LyXView::openLayoutList()
|
||||
{
|
||||
toolbars_->openLayoutList();
|
||||
}
|
||||
|
||||
|
||||
bool LyXView::isToolbarVisible(std::string const & id)
|
||||
{
|
||||
return toolbars_->visible(id);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
@ -38,8 +38,6 @@ namespace frontend {
|
||||
|
||||
class Dialogs;
|
||||
class WorkArea;
|
||||
class Toolbar;
|
||||
class Toolbars;
|
||||
|
||||
/**
|
||||
* LyXView - main LyX window
|
||||
@ -110,8 +108,6 @@ public:
|
||||
/// show busy cursor
|
||||
virtual void busy(bool) = 0;
|
||||
|
||||
virtual Toolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline) = 0;
|
||||
|
||||
//@{ generic accessor functions
|
||||
|
||||
/// \return the current buffer view.
|
||||
@ -122,9 +118,9 @@ public:
|
||||
Buffer const * buffer() const;
|
||||
|
||||
///
|
||||
void openLayoutList();
|
||||
virtual void openLayoutList() = 0;
|
||||
///
|
||||
bool isToolbarVisible(std::string const & id);
|
||||
virtual bool isToolbarVisible(std::string const & id) = 0;
|
||||
///
|
||||
virtual void showMiniBuffer(bool visible) = 0;
|
||||
virtual void openMenu(docstring const & name) = 0;
|
||||
@ -144,14 +140,14 @@ public:
|
||||
void setBuffer(Buffer * b); ///< \c Buffer to set.
|
||||
|
||||
/// updates the possible layouts selectable
|
||||
void updateLayoutChoice();
|
||||
virtual void updateLayoutChoice() = 0;
|
||||
|
||||
/// update the toolbar
|
||||
void updateToolbars();
|
||||
virtual void updateToolbars() = 0;
|
||||
/// get toolbar info
|
||||
ToolbarInfo * getToolbarInfo(std::string const & name);
|
||||
virtual ToolbarInfo * getToolbarInfo(std::string const & name) = 0;
|
||||
/// toggle toolbar state
|
||||
void toggleToolbarState(std::string const & name, bool allowauto);
|
||||
virtual void toggleToolbarState(std::string const & name, bool allowauto) = 0;
|
||||
/// update the status bar
|
||||
virtual void updateStatusBar() = 0;
|
||||
|
||||
@ -191,9 +187,6 @@ protected:
|
||||
/// disconnect from signals in the given buffer
|
||||
void disconnectBuffer();
|
||||
|
||||
/// view's toolbar
|
||||
Toolbars * toolbars_;
|
||||
|
||||
private:
|
||||
/**
|
||||
* setWindowTitle - set title of window
|
||||
@ -234,7 +227,6 @@ private:
|
||||
boost::signals::connection show_dialog_with_data_connection_;
|
||||
boost::signals::connection show_inset_dialog_connection_;
|
||||
boost::signals::connection update_dialog_connection_;
|
||||
boost::signals::connection layout_changed_connection_;
|
||||
//@}
|
||||
|
||||
/// Bind methods for BufferView messages signal connection
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
#include "frontends/Toolbars.h"
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "debug.h"
|
||||
@ -33,10 +31,7 @@ using std::string;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
Toolbars::Toolbars(LyXView & owner)
|
||||
: owner_(owner),
|
||||
layout_(0),
|
||||
last_textclass_(TextClassPtr())
|
||||
Toolbars::Toolbars()
|
||||
{}
|
||||
|
||||
#define TurnOnFlag(x) flags |= ToolbarInfo::x
|
||||
@ -145,7 +140,7 @@ void Toolbars::init()
|
||||
}
|
||||
|
||||
|
||||
Toolbar * Toolbars::display(string const & name, bool show)
|
||||
void Toolbars::display(string const & name, bool show)
|
||||
{
|
||||
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
||||
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
|
||||
@ -161,13 +156,12 @@ Toolbar * Toolbars::display(string const & name, bool show)
|
||||
else
|
||||
TurnOnFlag(OFF);
|
||||
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
||||
return displayToolbar(*cit, show);
|
||||
displayToolbar(*cit, show);
|
||||
}
|
||||
}
|
||||
|
||||
LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named "
|
||||
<< name << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -216,7 +210,7 @@ void Toolbars::toggleToolbarState(string const & name, bool allowauto)
|
||||
|
||||
void Toolbars::update(bool in_math, bool in_table, bool review)
|
||||
{
|
||||
update();
|
||||
updateIcons();
|
||||
|
||||
// extracts the toolbars from the backend
|
||||
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
|
||||
@ -237,147 +231,5 @@ void Toolbars::update(bool in_math, bool in_table, bool review)
|
||||
}
|
||||
|
||||
|
||||
bool Toolbars::visible(string const & name) const
|
||||
{
|
||||
std::map<string, ToolbarPtr>::const_iterator it =
|
||||
toolbars_.find(name);
|
||||
if (it == toolbars_.end())
|
||||
return false;
|
||||
return it->second.get()->isVisible();
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::saveToolbarInfo()
|
||||
{
|
||||
ToolbarSection & tb = LyX::ref().session().toolbars();
|
||||
|
||||
for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
||||
cit != toolbarbackend.end(); ++cit) {
|
||||
ToolbarsMap::iterator it = toolbars_.find(cit->name);
|
||||
BOOST_ASSERT(it != toolbars_.end());
|
||||
// get toolbar info from session.
|
||||
ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
|
||||
if (cit->flags & ToolbarInfo::ON)
|
||||
info.state = ToolbarSection::ToolbarInfo::ON;
|
||||
else if (cit->flags & ToolbarInfo::OFF)
|
||||
info.state = ToolbarSection::ToolbarInfo::OFF;
|
||||
else if (cit->flags & ToolbarInfo::AUTO)
|
||||
info.state = ToolbarSection::ToolbarInfo::AUTO;
|
||||
// save other information
|
||||
// if auto, frontend should *not* set on/off
|
||||
it->second->saveInfo(info);
|
||||
// maybe it is useful to update flags with real status. I do not know
|
||||
/*
|
||||
if (!(cit->flags & ToolbarInfo::AUTO)) {
|
||||
unsigned int flags = static_cast<unsigned int>(cit->flags);
|
||||
flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
|
||||
flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
|
||||
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
||||
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::setLayout(docstring const & layout)
|
||||
{
|
||||
if (layout_)
|
||||
layout_->set(layout);
|
||||
}
|
||||
|
||||
|
||||
bool Toolbars::updateLayoutList(TextClassPtr textclass)
|
||||
{
|
||||
// update the layout display
|
||||
if (last_textclass_ != textclass) {
|
||||
if (layout_)
|
||||
layout_->update();
|
||||
last_textclass_ = textclass;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::openLayoutList()
|
||||
{
|
||||
if (layout_)
|
||||
layout_->open();
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::clearLayoutList()
|
||||
{
|
||||
last_textclass_ = TextClassPtr();
|
||||
if (layout_)
|
||||
layout_->clear();
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
||||
{
|
||||
ToolbarPtr tb_ptr(owner_.makeToolbar(tbinfo, newline));
|
||||
toolbars_[tbinfo.name] = tb_ptr;
|
||||
|
||||
if (tbinfo.flags & ToolbarInfo::ON)
|
||||
tb_ptr->show(false);
|
||||
else
|
||||
tb_ptr->hide(false);
|
||||
|
||||
if (tb_ptr->layout())
|
||||
layout_ = tb_ptr->layout();
|
||||
}
|
||||
|
||||
|
||||
Toolbar * Toolbars::displayToolbar(ToolbarInfo const & tbinfo,
|
||||
bool show_it)
|
||||
{
|
||||
ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
|
||||
BOOST_ASSERT(it != toolbars_.end());
|
||||
|
||||
if (show_it)
|
||||
it->second->show(true);
|
||||
else
|
||||
it->second->hide(true);
|
||||
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
|
||||
void Toolbars::update()
|
||||
{
|
||||
ToolbarsMap::const_iterator it = toolbars_.begin();
|
||||
ToolbarsMap::const_iterator const end = toolbars_.end();
|
||||
for (; it != end; ++it)
|
||||
it->second->update();
|
||||
|
||||
bool const enable =
|
||||
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
|
||||
|
||||
if (layout_)
|
||||
layout_->setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
void layoutSelected(LyXView & lv, docstring const & name)
|
||||
{
|
||||
TextClass const & tc = lv.buffer()->params().getTextClass();
|
||||
|
||||
TextClass::const_iterator it = tc.begin();
|
||||
TextClass::const_iterator const end = tc.end();
|
||||
for (; it != end; ++it) {
|
||||
docstring const & itname = (*it)->name();
|
||||
if (translateIfPossible(itname) == name) {
|
||||
FuncRequest const func(LFUN_LAYOUT, itname,
|
||||
FuncRequest::TOOLBAR);
|
||||
lv.dispatch(func);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lyxerr << "ERROR (layoutSelected): layout not found!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
@ -27,74 +27,20 @@
|
||||
#include "ToolbarBackend.h"
|
||||
#include "Session.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class LyXView;
|
||||
|
||||
class LayoutBox {
|
||||
public:
|
||||
virtual ~LayoutBox() {}
|
||||
/// Select the correct layout in the combox.
|
||||
virtual void set(docstring const & layout) = 0;
|
||||
/// Populate the layout combox.
|
||||
virtual void update() = 0;
|
||||
/// Erase the layout list.
|
||||
virtual void clear() = 0;
|
||||
/// Display the layout list.
|
||||
virtual void open() = 0;
|
||||
/// Set the activation status of the combox.
|
||||
virtual void setEnabled(bool) = 0;
|
||||
};
|
||||
|
||||
|
||||
class Toolbar {
|
||||
public:
|
||||
virtual ~Toolbar() {}
|
||||
/// Add a button to the bar.
|
||||
virtual void add(ToolbarItem const & item) = 0;
|
||||
|
||||
/** Hide the bar.
|
||||
* \param update_metrics is a hint to the layout engine that the
|
||||
* metrics should be updated.
|
||||
*/
|
||||
virtual void hide(bool update_metrics) = 0;
|
||||
/** Show the bar.
|
||||
* \param update_metrics is a hint to the layout engine that the
|
||||
* metrics should be updated.
|
||||
*/
|
||||
virtual void show(bool update_metrics) = 0;
|
||||
/** update toolbar information
|
||||
* ToolbarInfo will then be saved by session
|
||||
*/
|
||||
virtual void saveInfo(ToolbarSection::ToolbarInfo & tbinfo) = 0;
|
||||
|
||||
/// whether toolbar is visible
|
||||
virtual bool isVisible() const = 0;
|
||||
/// Refresh the contents of the bar.
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
class Toolbars {
|
||||
public:
|
||||
///
|
||||
Toolbars(LyXView & owner);
|
||||
Toolbars();
|
||||
virtual ~Toolbars() {}
|
||||
|
||||
/// Initialize the toolbars using the backend database.
|
||||
void init();
|
||||
|
||||
/// Show/hide the named toolbar.
|
||||
Toolbar * display(std::string const & name, bool show);
|
||||
void display(std::string const & name, bool show);
|
||||
|
||||
/// get toolbar info
|
||||
ToolbarInfo * getToolbarInfo(std::string const & name);
|
||||
@ -108,62 +54,26 @@ public:
|
||||
void update(bool in_math, bool in_table, bool review);
|
||||
|
||||
/// Is the Toolbar currently visible?
|
||||
bool visible(std::string const & name) const;
|
||||
virtual bool visible(std::string const & name) const = 0;
|
||||
|
||||
/// save toolbar information
|
||||
void saveToolbarInfo();
|
||||
virtual void saveToolbarInfo() = 0;
|
||||
|
||||
/// Select the right layout in the combox.
|
||||
void setLayout(docstring const & layout);
|
||||
virtual void setLayout(docstring const & layout) = 0;
|
||||
|
||||
/** Populate the layout combox - returns whether we did a full
|
||||
* update or not
|
||||
*/
|
||||
bool updateLayoutList(TextClassPtr textclass);
|
||||
|
||||
/// Drop down the layout list.
|
||||
void openLayoutList();
|
||||
/// Erase the layout list.
|
||||
void clearLayoutList();
|
||||
|
||||
///
|
||||
typedef boost::shared_ptr<Toolbar> ToolbarPtr;
|
||||
|
||||
private:
|
||||
protected:
|
||||
/// Add a new toolbar. if newline==true, start from a new line
|
||||
void add(ToolbarInfo const & tbinfo, bool newline);
|
||||
virtual void add(ToolbarInfo const & tbinfo, bool newline) = 0;
|
||||
/// Show or hide a toolbar.
|
||||
Toolbar * displayToolbar(ToolbarInfo const & tbinfo, bool show);
|
||||
virtual void displayToolbar(ToolbarInfo const & tbinfo, bool show) = 0;
|
||||
/// Update the state of the icons
|
||||
void update();
|
||||
|
||||
/// The parent window.
|
||||
LyXView & owner_;
|
||||
|
||||
/** The layout box is actually owned by whichever toolbar
|
||||
* contains it. All the Toolbars class needs is a means of
|
||||
* accessing it.
|
||||
*
|
||||
* We don't need to use boost::weak_ptr here because the toolbars
|
||||
* are also stored here. There are, therefore, no lifetime issues.
|
||||
*/
|
||||
LayoutBox * layout_;
|
||||
|
||||
/// Toolbar store providing access to individual toolbars by name.
|
||||
typedef std::map<std::string, ToolbarPtr> ToolbarsMap;
|
||||
ToolbarsMap toolbars_;
|
||||
|
||||
/// The last textclass layout list in the layout choice selector
|
||||
TextClassPtr last_textclass_;
|
||||
virtual void updateIcons() = 0;
|
||||
|
||||
// load flags with saved values
|
||||
void initFlags(ToolbarInfo & tbinfo);
|
||||
};
|
||||
|
||||
/// Set the layout in the kernel when an entry has been selected
|
||||
void layoutSelected(LyXView & lv, docstring const & name);
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -104,7 +104,7 @@ void GuiLayoutBox::set(docstring const & layout)
|
||||
}
|
||||
|
||||
|
||||
void GuiLayoutBox::update()
|
||||
void GuiLayoutBox::updateContents()
|
||||
{
|
||||
TextClass const & tc = textClass(owner_);
|
||||
|
||||
@ -149,6 +149,29 @@ void GuiLayoutBox::setEnabled(bool enable)
|
||||
combo_->setEnabled(enable);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// FIXME: put that in frontends/LayoutBox class.
|
||||
void layoutSelected(LyXView & lv, docstring const & name)
|
||||
{
|
||||
TextClass const & tc = lv.buffer()->params().getTextClass();
|
||||
|
||||
TextClass::const_iterator it = tc.begin();
|
||||
TextClass::const_iterator const end = tc.end();
|
||||
for (; it != end; ++it) {
|
||||
docstring const & itname = (*it)->name();
|
||||
if (translateIfPossible(itname) == name) {
|
||||
FuncRequest const func(LFUN_LAYOUT, itname,
|
||||
FuncRequest::TOOLBAR);
|
||||
lv.dispatch(func);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lyxerr << "ERROR (layoutSelected): layout not found!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
|
||||
void GuiLayoutBox::selected(const QString & str)
|
||||
{
|
||||
@ -299,24 +322,6 @@ void GuiToolbar::add(ToolbarItem const & item)
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::hide(bool)
|
||||
{
|
||||
QToolBar::hide();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::show(bool)
|
||||
{
|
||||
QToolBar::show();
|
||||
}
|
||||
|
||||
|
||||
bool GuiToolbar::isVisible() const
|
||||
{
|
||||
return QToolBar::isVisible();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
|
||||
{
|
||||
// if tbinfo.state == auto *do not* set on/off
|
||||
@ -348,7 +353,7 @@ void GuiToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbar::update()
|
||||
void GuiToolbar::updateContents()
|
||||
{
|
||||
// update visible toolbars only
|
||||
if (!isVisible())
|
||||
|
@ -36,7 +36,7 @@ class GuiViewBase;
|
||||
class Action;
|
||||
|
||||
|
||||
class GuiLayoutBox : public QObject, public LayoutBox
|
||||
class GuiLayoutBox : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -45,12 +45,12 @@ public:
|
||||
/// select the right layout in the combobox.
|
||||
void set(docstring const & layout);
|
||||
/// Populate the layout combox.
|
||||
void update();
|
||||
void updateContents();
|
||||
/// Erase the layout list.
|
||||
void clear();
|
||||
/// Display the layout list.
|
||||
void open();
|
||||
///
|
||||
/// Set the activation status of the combox.
|
||||
void setEnabled(bool);
|
||||
|
||||
private Q_SLOTS:
|
||||
@ -62,20 +62,22 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class GuiToolbar : public QToolBar, public Toolbar
|
||||
class GuiToolbar : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GuiToolbar(ToolbarInfo const &, GuiViewBase &);
|
||||
|
||||
/// Add a button to the bar.
|
||||
void add(ToolbarItem const & item);
|
||||
void hide(bool);
|
||||
void show(bool);
|
||||
bool isVisible() const;
|
||||
/** update toolbar information
|
||||
* ToolbarInfo will then be saved by session
|
||||
*/
|
||||
void saveInfo(ToolbarSection::ToolbarInfo & info);
|
||||
void update();
|
||||
LayoutBox * layout() const { return layout_; }
|
||||
///
|
||||
/// Refresh the contents of the bar.
|
||||
void updateContents();
|
||||
GuiLayoutBox * layout() const { return layout_; }
|
||||
/// Set the focus on the command buffer, if any.
|
||||
void focusCommandBuffer();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
169
src/frontends/qt4/GuiToolbars.cpp
Normal file
169
src/frontends/qt4/GuiToolbars.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/**
|
||||
* \file GuiToolbars.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author Angus Leeming
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "GuiToolbars.h"
|
||||
|
||||
#include "GuiToolbar.h"
|
||||
#include "GuiView.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "debug.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "gettext.h"
|
||||
#include "Layout.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "TextClass.h"
|
||||
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiToolbars::GuiToolbars(GuiViewBase & owner)
|
||||
: owner_(owner),
|
||||
layout_(0),
|
||||
last_textclass_(TextClassPtr())
|
||||
{}
|
||||
|
||||
|
||||
bool GuiToolbars::visible(string const & name) const
|
||||
{
|
||||
std::map<string, GuiToolbar *>::const_iterator it =
|
||||
toolbars_.find(name);
|
||||
if (it == toolbars_.end())
|
||||
return false;
|
||||
return it->second->isVisible();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::saveToolbarInfo()
|
||||
{
|
||||
ToolbarSection & tb = LyX::ref().session().toolbars();
|
||||
|
||||
for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
||||
cit != toolbarbackend.end(); ++cit) {
|
||||
ToolbarsMap::iterator it = toolbars_.find(cit->name);
|
||||
BOOST_ASSERT(it != toolbars_.end());
|
||||
// get toolbar info from session.
|
||||
ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
|
||||
if (cit->flags & ToolbarInfo::ON)
|
||||
info.state = ToolbarSection::ToolbarInfo::ON;
|
||||
else if (cit->flags & ToolbarInfo::OFF)
|
||||
info.state = ToolbarSection::ToolbarInfo::OFF;
|
||||
else if (cit->flags & ToolbarInfo::AUTO)
|
||||
info.state = ToolbarSection::ToolbarInfo::AUTO;
|
||||
// save other information
|
||||
// if auto, frontend should *not* set on/off
|
||||
it->second->saveInfo(info);
|
||||
// maybe it is useful to update flags with real status. I do not know
|
||||
/*
|
||||
if (!(cit->flags & ToolbarInfo::AUTO)) {
|
||||
unsigned int flags = static_cast<unsigned int>(cit->flags);
|
||||
flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
|
||||
flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
|
||||
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
||||
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::setLayout(docstring const & layout)
|
||||
{
|
||||
if (layout_)
|
||||
layout_->set(layout);
|
||||
}
|
||||
|
||||
|
||||
bool GuiToolbars::updateLayoutList(TextClassPtr textclass)
|
||||
{
|
||||
// update the layout display
|
||||
if (last_textclass_ != textclass) {
|
||||
if (layout_)
|
||||
layout_->updateContents();
|
||||
last_textclass_ = textclass;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::openLayoutList()
|
||||
{
|
||||
if (layout_)
|
||||
layout_->open();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::clearLayoutList()
|
||||
{
|
||||
last_textclass_ = TextClassPtr();
|
||||
if (layout_)
|
||||
layout_->clear();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
||||
{
|
||||
GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline);
|
||||
toolbars_[tbinfo.name] = tb_ptr;
|
||||
|
||||
if (tbinfo.flags & ToolbarInfo::ON)
|
||||
tb_ptr->show();
|
||||
else
|
||||
tb_ptr->hide();
|
||||
|
||||
if (tb_ptr->layout())
|
||||
layout_ = tb_ptr->layout();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::displayToolbar(ToolbarInfo const & tbinfo,
|
||||
bool show_it)
|
||||
{
|
||||
ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
|
||||
BOOST_ASSERT(it != toolbars_.end());
|
||||
|
||||
if (show_it) {
|
||||
if (it->second->isVisible())
|
||||
return;
|
||||
it->second->show();
|
||||
}
|
||||
else if (it->second->isVisible())
|
||||
it->second->hide();
|
||||
}
|
||||
|
||||
|
||||
void GuiToolbars::updateIcons()
|
||||
{
|
||||
ToolbarsMap::const_iterator it = toolbars_.begin();
|
||||
ToolbarsMap::const_iterator const end = toolbars_.end();
|
||||
for (; it != end; ++it)
|
||||
it->second->updateContents();
|
||||
|
||||
bool const enable =
|
||||
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
|
||||
|
||||
if (layout_)
|
||||
layout_->setEnabled(enable);
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
77
src/frontends/qt4/GuiToolbars.h
Normal file
77
src/frontends/qt4/GuiToolbars.h
Normal file
@ -0,0 +1,77 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file GuiToolbars.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Lars Gullik Bjønnes
|
||||
* \author Angus Leeming
|
||||
* \author Abdelrazak Younes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef GUI_TOOLBARS_H
|
||||
#define GUI_TOOLBARS_H
|
||||
|
||||
#include "frontends/Toolbars.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class GuiLayoutBox;
|
||||
class GuiToolbar;
|
||||
class GuiViewBase;
|
||||
|
||||
class GuiToolbars : public Toolbars
|
||||
{
|
||||
public:
|
||||
///
|
||||
GuiToolbars(GuiViewBase & owner);
|
||||
|
||||
bool visible(std::string const & name) const;
|
||||
void saveToolbarInfo();
|
||||
void setLayout(docstring const & layout);
|
||||
|
||||
/** Populate the layout combox - returns whether we did a full
|
||||
* update or not
|
||||
*/
|
||||
bool updateLayoutList(TextClassPtr textclass);
|
||||
|
||||
/// Drop down the layout list.
|
||||
void openLayoutList();
|
||||
/// Erase the layout list.
|
||||
void clearLayoutList();
|
||||
|
||||
protected:
|
||||
void add(ToolbarInfo const & tbinfo, bool newline);
|
||||
void displayToolbar(ToolbarInfo const & tbinfo, bool show);
|
||||
void updateIcons();
|
||||
|
||||
/// The parent window.
|
||||
GuiViewBase & owner_;
|
||||
|
||||
/** The layout box is actually owned by whichever toolbar
|
||||
* contains it. All the Toolbars class needs is a means of
|
||||
* accessing it.
|
||||
*
|
||||
* We don't need to use boost::weak_ptr here because the toolbars
|
||||
* are also stored here. There are, therefore, no lifetime issues.
|
||||
*/
|
||||
GuiLayoutBox * layout_;
|
||||
|
||||
/// Toolbar store providing access to individual toolbars by name.
|
||||
typedef std::map<std::string, GuiToolbar *> ToolbarsMap;
|
||||
ToolbarsMap toolbars_;
|
||||
|
||||
/// The last textclass layout list in the layout choice selector
|
||||
TextClassPtr last_textclass_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
#endif // NOT GUI_TOOLBARS_H
|
@ -20,6 +20,7 @@
|
||||
#include "GuiKeySymbol.h"
|
||||
#include "GuiMenubar.h"
|
||||
#include "GuiToolbar.h"
|
||||
#include "GuiToolbars.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
@ -33,15 +34,18 @@
|
||||
#include "support/os.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "BufferList.h"
|
||||
#include "callback.h"
|
||||
#include "debug.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "Layout.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
#include "MenuBackend.h"
|
||||
#include "Paragraph.h"
|
||||
#include "Session.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -140,6 +144,10 @@ struct GuiViewBase::GuiViewPrivate
|
||||
BackgroundWidget * bg_widget_;
|
||||
/// view's menubar
|
||||
GuiMenubar * menubar_;
|
||||
/// view's toolbars
|
||||
GuiToolbars * toolbars_;
|
||||
///
|
||||
docstring current_layout;
|
||||
|
||||
GuiViewPrivate() : posx_offset(0), posy_offset(0) {}
|
||||
|
||||
@ -278,6 +286,7 @@ GuiViewBase::GuiViewBase(int id)
|
||||
GuiViewBase::~GuiViewBase()
|
||||
{
|
||||
delete d.menubar_;
|
||||
delete d.toolbars_;
|
||||
delete &d;
|
||||
}
|
||||
|
||||
@ -305,10 +314,14 @@ QMenu* GuiViewBase::createPopupMenu()
|
||||
|
||||
void GuiViewBase::init()
|
||||
{
|
||||
// GuiToolbars *must* be initialised before GuiMenubar.
|
||||
d.toolbars_ = new GuiToolbars(*this);
|
||||
// FIXME: GuiToolbars::init() cannot be integrated in the ctor
|
||||
// because LyXFunc::getStatus() needs a properly initialized
|
||||
// GuiToolbars object (for LFUN_TOOLBAR_TOGGLE).
|
||||
d.toolbars_->init();
|
||||
d.menubar_ = new GuiMenubar(this, menubackend);
|
||||
|
||||
toolbars_->init();
|
||||
|
||||
statusBar()->setSizeGripEnabled(true);
|
||||
|
||||
QObject::connect(&statusbar_timer_, SIGNAL(timeout()),
|
||||
@ -442,7 +455,7 @@ void GuiViewBase::saveGeometry()
|
||||
session.sessionInfo().save("WindowPosX", convert<string>(normal_geometry.x() + d.posx_offset));
|
||||
session.sessionInfo().save("WindowPosY", convert<string>(normal_geometry.y() + d.posy_offset));
|
||||
}
|
||||
toolbars_->saveToolbarInfo();
|
||||
d.toolbars_->saveToolbarInfo();
|
||||
}
|
||||
|
||||
|
||||
@ -776,7 +789,7 @@ void GuiViewBase::busy(bool yes)
|
||||
}
|
||||
|
||||
|
||||
Toolbar * GuiViewBase::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
|
||||
GuiToolbar * GuiViewBase::makeToolbar(ToolbarInfo const & tbinfo, bool newline)
|
||||
{
|
||||
GuiToolbar * toolBar = new GuiToolbar(tbinfo, *this);
|
||||
|
||||
@ -925,9 +938,11 @@ void GuiViewBase::removeWorkArea(WorkArea * work_area)
|
||||
|
||||
void GuiViewBase::showMiniBuffer(bool visible)
|
||||
{
|
||||
Toolbar * t = toolbars_->display("minibuffer", visible);
|
||||
if (t)
|
||||
t->focusCommandBuffer();
|
||||
d.toolbars_->display("minibuffer", visible);
|
||||
|
||||
// FIXME: do something about command buffer focus.
|
||||
// if (t)
|
||||
// t->focusCommandBuffer();
|
||||
}
|
||||
|
||||
|
||||
@ -936,6 +951,82 @@ void GuiViewBase::openMenu(docstring const & name)
|
||||
d.menubar_->openByName(toqstr(name));
|
||||
}
|
||||
|
||||
|
||||
void GuiViewBase::openLayoutList()
|
||||
{
|
||||
d.toolbars_->openLayoutList();
|
||||
}
|
||||
|
||||
|
||||
void GuiViewBase::updateLayoutChoice()
|
||||
{
|
||||
// Don't show any layouts without a buffer
|
||||
if (!buffer()) {
|
||||
d.toolbars_->clearLayoutList();
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the layout display
|
||||
if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr())) {
|
||||
d.current_layout = buffer()->params().getTextClass().defaultLayoutName();
|
||||
}
|
||||
|
||||
docstring const & layout = currentWorkArea()->bufferView().cursor().
|
||||
innerParagraph().layout()->name();
|
||||
|
||||
if (layout != d.current_layout) {
|
||||
d.toolbars_->setLayout(layout);
|
||||
d.current_layout = layout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GuiViewBase::isToolbarVisible(std::string const & id)
|
||||
{
|
||||
return d.toolbars_->visible(id);
|
||||
}
|
||||
|
||||
void GuiViewBase::updateToolbars()
|
||||
{
|
||||
WorkArea * wa = currentWorkArea();
|
||||
if (wa) {
|
||||
bool const math =
|
||||
wa->bufferView().cursor().inMathed();
|
||||
bool const table =
|
||||
lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
|
||||
bool const review =
|
||||
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).enabled() &&
|
||||
lyx::getStatus(FuncRequest(LFUN_CHANGES_TRACK)).onoff(true);
|
||||
|
||||
d.toolbars_->update(math, table, review);
|
||||
} else
|
||||
d.toolbars_->update(false, false, false);
|
||||
|
||||
// update read-only status of open dialogs.
|
||||
getDialogs().checkStatus();
|
||||
}
|
||||
|
||||
|
||||
ToolbarInfo * GuiViewBase::getToolbarInfo(string const & name)
|
||||
{
|
||||
return d.toolbars_->getToolbarInfo(name);
|
||||
}
|
||||
|
||||
|
||||
void GuiViewBase::toggleToolbarState(string const & name, bool allowauto)
|
||||
{
|
||||
// it is possible to get current toolbar status like this,...
|
||||
// but I decide to obey the order of ToolbarBackend::flags
|
||||
// and disregard real toolbar status.
|
||||
// toolbars_->saveToolbarInfo();
|
||||
//
|
||||
// toggle state on/off/auto
|
||||
d.toolbars_->toggleToolbarState(name, allowauto);
|
||||
// update toolbar
|
||||
updateToolbars();
|
||||
}
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -31,6 +31,8 @@ class QToolBar;
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class GuiToolbar;
|
||||
|
||||
QWidget * mainWindow();
|
||||
|
||||
/**
|
||||
@ -64,13 +66,19 @@ public:
|
||||
virtual void saveGeometry();
|
||||
virtual void busy(bool);
|
||||
/// add toolbar, if newline==true, add a toolbar break before the toolbar
|
||||
Toolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
|
||||
GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
|
||||
virtual void updateStatusBar();
|
||||
virtual void message(docstring const & str);
|
||||
virtual void clearMessage();
|
||||
virtual bool hasFocus() const;
|
||||
void showMiniBuffer(bool);
|
||||
void openMenu(docstring const &);
|
||||
void openLayoutList();
|
||||
void updateLayoutChoice();
|
||||
bool isToolbarVisible(std::string const & id);
|
||||
void updateToolbars();
|
||||
ToolbarInfo * getToolbarInfo(std::string const & name);
|
||||
void toggleToolbarState(std::string const & name, bool allowauto);
|
||||
|
||||
/// show - display the top-level window
|
||||
void showView();
|
||||
|
@ -99,6 +99,7 @@ SOURCEFILES = \
|
||||
GuiThesaurus.cpp \
|
||||
GuiToc.cpp \
|
||||
GuiToolbar.cpp \
|
||||
GuiToolbars.cpp \
|
||||
GuiURL.cpp \
|
||||
GuiView.cpp \
|
||||
GuiViewSource.cpp \
|
||||
@ -121,6 +122,7 @@ NOMOCHEADER = \
|
||||
GuiFontMetrics.h \
|
||||
GuiImage.h \
|
||||
GuiPainter.h \
|
||||
GuiToolbars.h \
|
||||
qt_helpers.h
|
||||
|
||||
MOCHEADER = \
|
||||
|
Loading…
Reference in New Issue
Block a user