Item *GfxBlockItem::newImage(QImage img, QUrl src, QPointF pos) { ASSERT(data()->book()); ASSERT(data()->resManager()); double maxW = availableWidth(); double maxH = maxW; double scale = 1; if (scale*img.width()>maxW) scale = maxW/img.width(); if (scale*img.height()>maxH) scale = maxH/img.height(); if (allChildren().isEmpty()) pos = QPointF(0, 0); else pos -= QPointF(img.width(),img.height())*(scale/2); pos = constrainPointToRect(pos, boundingRect()); Resource *res = data()->resManager()->importImage(img, src); QString resName = res->tag(); GfxImageData *gid = new GfxImageData(resName, img, data()); gid->setScale(scale); gid->setPos(pos); GfxImageItem *gii = new GfxImageItem(gid, this); gii->makeWritable(); resetPosition(); sizeToFit(); return gii; }
////////////////////////////////////////////////////////////////////////// // high level scripting interface ////////////////////////////////////////////////////////////////////////// bool UIText::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) { ////////////////////////////////////////////////////////////////////////// // SizeToFit ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SizeToFit") == 0) { stack->correctParams(0); sizeToFit(); stack->pushNULL(); return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// // HeightToFit ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "HeightToFit") == 0) { stack->correctParams(0); if (_font && _text) { _height = _font->getTextHeight((byte *)_text, _width); } stack->pushNULL(); return STATUS_OK; } else { return UIObject::scCallMethod(script, stack, thisStack, name); } }
void Menu::destroyItems() { while (!m_items.empty()) { delete m_items.back(); m_items.pop_back(); } sizeToFit(); }
//------------------------------------------------------------------------ void CCheckBox::setFont (CFontRef newFont) { if (font) font->forget (); font = newFont; if (font) font->remember (); if (style & kAutoSizeToFit) sizeToFit (); }
//------------------------------------------------------------------------ void CCheckBox::setStyle (int32_t newStyle) { if (style != newStyle) { style = newStyle; if (style & kAutoSizeToFit) sizeToFit (); invalid (); } }
void Menu::addItem(Item& item) { auto i = std::find(m_items.begin(), m_items.end(), &item); if (i != m_items.end()) return; m_items.push_back(&item); sizeToFit(); }
void Menu::destroyItem(Item& item) { auto i = std::find(m_items.begin(), m_items.end(), &item); if (i != m_items.end()) { delete *i; m_items.erase(i); sizeToFit(); } }
void Menu::addItemAt(Item& item, uint index) { auto i = std::find(m_items.begin(), m_items.end(), &item); if (i != m_items.end()) return; i = m_items.begin(); std::advance(i, min(index, (uint) m_items.size())); m_items.insert(i, &item); sizeToFit(); }
//------------------------------------------------------------------------ void CCheckBox::setTitle (UTF8StringPtr newTitle) { if (title) delete [] title; title = 0; if (newTitle) { title = new char [strlen (newTitle) + 1]; strcpy (title, newTitle); } if (style & kAutoSizeToFit) sizeToFit (); }
//------------------------------------------------------------------------ //------------------------------------------------------------------------ CCheckBox::CCheckBox (const CRect& size, CControlListener* listener, int32_t tag, UTF8StringPtr title, CBitmap* bitmap, int32_t style) : CControl (size, listener, tag, bitmap) , title (0) , style (style) , font (0) , fontColor (kWhiteCColor) , hilight (false) { setTitle (title); setFont (kSystemFont); setBoxFillColor (kWhiteCColor); setBoxFrameColor (kBlackCColor); setCheckMarkColor (kRedCColor); font->remember (); setWantsFocus (true); if (style & kAutoSizeToFit) sizeToFit (); }
void GfxBlockItem::mousePressEvent(QGraphicsSceneMouseEvent *e) { Mode::M mod = mode()->mode(); // Qt::MouseButton but = e->button(); bool take = false; if (isWritable()) { switch (mod) { case Mode::Mark: GfxMarkItem::newMark(e->pos(), this); sizeToFit(); take = true; break; case Mode::Freehand: { if (mode()->isStraightLineMode()) { GfxLineItem *li = GfxLineItem::newLine(e->pos(), this); li->build(e); } else { GfxSketchItem *ski = GfxSketchItem::newSketch(e->pos(), this); ski->build(); } take = true; } break; case Mode::Type: if (e->modifiers() & Qt::ControlModifier) { take = perhapsSendMousePressToChild(e); } else { createGfxNote(e->pos()); take = true; } break; default: break; } } if (take) e->accept(); else BlockItem::mousePressEvent(e); }
void Menu::insertItem(Item& item, uint index) { m_items.insert(m_items.begin() + min(index, uint(m_items.size())), &item); sizeToFit(); }
void Menu::addItem(Item& item) { m_items.push_back(&item); sizeToFit(); }
//------------------------------------------------------------------------ void CCheckBox::setBackground (CBitmap *background) { CView::setBackground (background); if (style & kAutoSizeToFit) sizeToFit (); }