Пример #1
0
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;
}
Пример #2
0
//////////////////////////////////////////////////////////////////////////
// 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);
	}
}
Пример #3
0
void Menu::destroyItems()
{
  while (!m_items.empty())
  {
    delete m_items.back();
    m_items.pop_back();
  }

  sizeToFit();
}
Пример #4
0
//------------------------------------------------------------------------
void CCheckBox::setFont (CFontRef newFont)
{
	if (font)
		font->forget ();
	font = newFont;
	if (font)
		font->remember ();
	if (style & kAutoSizeToFit)
		sizeToFit ();
}
Пример #5
0
//------------------------------------------------------------------------
void CCheckBox::setStyle (int32_t newStyle)
{
	if (style != newStyle)
	{
		style = newStyle;
		if (style & kAutoSizeToFit)
			sizeToFit ();
		invalid ();
	}
}
Пример #6
0
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();
}
Пример #7
0
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();
  }
}
Пример #8
0
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();
}
Пример #9
0
//------------------------------------------------------------------------
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 ();
}
Пример #10
0
//------------------------------------------------------------------------
//------------------------------------------------------------------------
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 ();
}
Пример #11
0
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);
}
Пример #12
0
void Menu::insertItem(Item& item, uint index)
{
  m_items.insert(m_items.begin() + min(index, uint(m_items.size())), &item);
  sizeToFit();
}
Пример #13
0
void Menu::addItem(Item& item)
{
  m_items.push_back(&item);
  sizeToFit();
}
Пример #14
0
//------------------------------------------------------------------------
void CCheckBox::setBackground (CBitmap *background)
{
	CView::setBackground (background);
	if (style & kAutoSizeToFit)
		sizeToFit ();
}