#include "LayoutBox.h"
-#include "Action.h"
#include "GuiView.h"
#include "qt_helpers.h"
-#include "Toolbars.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "Cursor.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "Layout.h"
-#include "LyXFunc.h"
+#include "LyX.h"
#include "LyXRC.h"
#include "Paragraph.h"
#include "TextClass.h"
#include "insets/InsetText.h"
#include "support/debug.h"
-#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
-#include <QAbstractItemDelegate>
#include <QAbstractTextDocumentLayout>
-#include <QApplication>
-#include <QComboBox>
-#include <QFontMetrics>
#include <QHeaderView>
#include <QItemDelegate>
-#include <QKeyEvent>
-#include <QList>
-#include <QListView>
#include <QPainter>
-#include <QPixmap>
-#include <QSettings>
#include <QSortFilterProxyModel>
-#include <QStandardItem>
#include <QStandardItemModel>
-#include <QString>
-#include <QTextDocument>
#include <QTextFrame>
-#include <QToolBar>
-#include <QVariant>
-
-#include "support/lassert.h"
using namespace std;
using namespace lyx::support;
struct LayoutBox::Private
{
Private(LayoutBox * parent, GuiView & gv) : p(parent), owner_(gv),
- lastSel_(-1), visibleCategories_(0), inShowPopup_(false),
- layoutItemDelegate_(new LayoutItemDelegate(parent)),
// set the layout model with two columns
// 1st: translated layout names
// 2nd: raw layout names
model_(new QStandardItemModel(0, 2, p)),
- filterModel_(new GuiLayoutFilterModel(p))
+ filterModel_(new GuiLayoutFilterModel(p)),
+ lastSel_(-1),
+ layoutItemDelegate_(new LayoutItemDelegate(parent)),
+ visibleCategories_(0), inShowPopup_(false)
{
filterModel_->setSourceModel(model_);
}
// on the QComboBox.
LASSERT(!inShowPopup_, /**/);
inShowPopup_ = true;
- p->showPopup();
+ p->QComboBox::showPopup();
inShowPopup_ = false;
// The item delegate hack is off again. So trigger a relayout of the popup.
}
-LayoutBox::LayoutBox(QToolBar * bar, GuiView & owner)
+LayoutBox::LayoutBox(GuiView & owner)
: d(new Private(this, owner))
{
setSizeAdjustPolicy(QComboBox::AdjustToContents);
QObject::connect(this, SIGNAL(activated(int)),
this, SLOT(selected(int)));
- QObject::connect(bar, SIGNAL(iconSizeChanged(QSize)),
- this, SLOT(setIconSize(QSize)));
- d->owner_.setLayoutDialog(this);
updateContents(true);
}
+LayoutBox::~LayoutBox() {
+ delete d;
+}
+
+
void LayoutBox::Private::countCategories()
{
int n = filterModel_->rowCount();
if (!d->text_class_)
return;
+ if (!(*d->text_class_).hasLayout(layout))
+ return;
+
Layout const & lay = (*d->text_class_)[layout];
QString newLayout = toqstr(lay.name());
void LayoutBox::updateContents(bool reset)
{
d->resetFilter();
-
- Buffer const * buffer = d->owner_.buffer();
- if (!buffer) {
+ BufferView const * bv = d->owner_.currentBufferView();
+ if (!bv) {
d->model_->clear();
setEnabled(false);
d->text_class_ = 0;
d->inset_ = 0;
return;
}
-
// we'll only update the layout list if the text class has changed
// or we've moved from one inset to another
- DocumentClass const * text_class = &buffer->params().documentClass();
- Inset const * inset =
- &(d->owner_.view()->cursor().innerText()->inset());
+ DocumentClass const * text_class = &(bv->buffer().params().documentClass());
+ Inset const * inset = &(bv->cursor().innerText()->inset());
if (!reset && d->text_class_ == text_class && d->inset_ == inset) {
- set(d->owner_.view()->cursor().innerParagraph().layout().name());
+ set(bv->cursor().innerParagraph().layout().name());
return;
}
lyxrc.group_layouts, lit->isUnknown());
}
- set(d->owner_.view()->cursor().innerParagraph().layout().name());
+ set(d->owner_.currentBufferView()->cursor().innerParagraph().layout().name());
d->countCategories();
// needed to recalculate size hint
hide();
setMinimumWidth(sizeHint().width());
- setEnabled(!buffer->isReadonly() &&
+ setEnabled(!bv->buffer().isReadonly() &&
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
show();
}
// find corresponding text class
if (d->text_class_->hasLayout(layoutName)) {
FuncRequest const func(LFUN_LAYOUT, layoutName, FuncRequest::TOOLBAR);
- theLyXFunc().setLyXView(&d->owner_);
lyx::dispatch(func);
updateContents(false);
d->resetFilter();