void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); Dimension const & dim1 = cell(1).dimension(*pi.base.bv); // define the binom brackets docstring const bra = kind_ == BRACE ? from_ascii("{") : kind_ == BRACK ? from_ascii("[") : from_ascii("("); docstring const ket = kind_ == BRACE ? from_ascii("}") : kind_ == BRACK ? from_ascii("]") : from_ascii(")"); int m = x + dim.width() / 2; // FIXME: for an unknown reason the cells must be drawn directly // after the StyleChanger and cannot be drawn after the if case if (kind_ == DBINOM) { StyleChanger dummy(pi.base, LM_ST_DISPLAY); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } else if (kind_ == TBINOM) { StyleChanger dummy(pi.base, LM_ST_SCRIPT); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } else { FracChanger dummy2(pi.base); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } // draw the brackets and the marker mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), bra); mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(), dw(dim.height()), dim.height(), ket); drawMarkers2(pi, x, y); }
void GuiCompleter::asyncUpdatePopup() { Cursor cur = gui_->bufferView().cursor(); if (!cur.inset().completionSupported(cur) || !cur.bv().paragraphVisible(cur)) { popupVisible_ = false; return; } // get dimensions of completion prefix Dimension dim; int x; int y; cur.inset().completionPosAndDim(cur, x, y, dim); // and calculate the rect of the popup QRect rect; if (popup()->layoutDirection() == Qt::RightToLeft) rect = QRect(x + dim.width() - 200, y - dim.ascent() - 3, 200, dim.height() + 6); else rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6); // Resize the columns in the popup. // This should really be in the constructor. But somehow the treeview // has a bad memory about it and we have to tell him again and again. QTreeView * listView = static_cast<QTreeView *>(popup()); listView->header()->setStretchLastSection(false); listView->header()->setResizeMode(0, QHeaderView::Stretch); listView->header()->setResizeMode(1, QHeaderView::Fixed); listView->header()->resizeSection(1, 22); // show/update popup complete(rect); }
void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const { // set edit mode for which we will have calculated metrics. But only editing_[mi.base.bv] = editMode(mi.base.bv); // calculate new metrics according to display mode if (displayMode_ == DISPLAY_INIT || displayMode_ == DISPLAY_INTERACTIVE_INIT) { mathed_string_dim(mi.base.font, from_ascii("\\") + name(), dim); } else if (displayMode_ == DISPLAY_UNFOLDED) { cell(0).metrics(mi, dim); Dimension bsdim; mathed_string_dim(mi.base.font, from_ascii("\\"), bsdim); dim.wid += bsdim.width() + 1; dim.asc = max(bsdim.ascent(), dim.ascent()); dim.des = max(bsdim.descent(), dim.descent()); metricsMarkers(dim); } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST && editing_[mi.base.bv]) { // Macro will be edited in a old-style list mode here: LASSERT(macro_ != 0, /**/); Dimension fontDim; FontInfo labelFont = sane_font; math_font_max_dim(labelFont, fontDim.asc, fontDim.des); // get dimension of components of list view Dimension nameDim; nameDim.wid = mathed_string_width(mi.base.font, from_ascii("Macro \\") + name() + ": "); nameDim.asc = fontDim.asc; nameDim.des = fontDim.des; Dimension argDim; argDim.wid = mathed_string_width(labelFont, from_ascii("#9: ")); argDim.asc = fontDim.asc; argDim.des = fontDim.des; Dimension defDim; definition_.metrics(mi, defDim); // add them up dim.wid = nameDim.wid + defDim.wid; dim.asc = max(nameDim.asc, defDim.asc); dim.des = max(nameDim.des, defDim.des); for (idx_type i = 0; i < nargs(); ++i) { Dimension cdim; cell(i).metrics(mi, cdim); dim.des += max(argDim.height(), cdim.height()) + 1; dim.wid = max(dim.wid, argDim.wid + cdim.wid); } // make space for box and markers, 2 pixels dim.asc += 1; dim.des += 1; dim.wid += 2; metricsMarkers2(dim); } else {
void InsetMathCases::draw(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{")); InsetMathGrid::drawWithMargin(pi, x, y, 8, 0); setPosCache(pi, x, y); }
void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const { Changer dummy2 = pi.base.changeEnsureMath(); Dimension const dim = dimension(*pi.base.bv); int const yy = y - dim.ascent(); // Drawing the deco after changeStyle does not work mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left())); mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right())); Changer dummy = pi.base.changeArray(); InsetMathGrid::draw(pi, x, y); }
void InsetMathBig::draw(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); // mathed_draw_deco does not use the leading backslash, so remove it // (but don't use ltrim if this is the backslash delimiter). // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco // would treat it as |. docstring const delim = (delim_ == "\\|") ? from_ascii("Vert") : (delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\"); mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(), delim); setPosCache(pi, x, y); }
void Inset::drawMarkers2(PainterInfo & pi, int x, int y) const { ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)? Color_mathframe : Color_mathcorners; drawMarkers(pi, x, y); Dimension const dim = dimension(*pi.base.bv); int const t = x + dim.width() - 1; int const a = y - dim.ascent(); pi.pain.line(x, a + 3, x, a, pen_color); pi.pain.line(t, a + 3, t, a, pen_color); pi.pain.line(x, a, x + 3, a, pen_color); pi.pain.line(t - 3, a, t, a, pen_color); setPosCache(pi, x, y); }
void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const { cell(0).draw(pi, x + 10, y); Dimension const dim = dimension(*pi.base.bv); int const a = dim.ascent(); int const d = dim.descent(); int xp[3]; int yp[3]; pi.pain.line(x + dim.width(), y - a + 1, x + 8, y - a + 1, pi.base.font.color()); xp[0] = x + 8; yp[0] = y - a + 1; xp[1] = x + 5; yp[1] = y + d - 1; xp[2] = x; yp[2] = y + (d - a)/2; pi.pain.lines(xp, yp, 3, pi.base.font.color()); drawMarkers(pi, x, y); }