示例#1
0
Dali::Toolkit::Magnifier Magnifier::New()
{
  // Create the implementation
  MagnifierPtr magnifier(new Magnifier());

  // Pass ownership to CustomActor via derived handle
  Dali::Toolkit::Magnifier handle(*magnifier);

  // Second-phase init of the implementation
  // This can only be done after the CustomActor connection has been made...
  magnifier->Initialize();

  return handle;
}
Key magnifyKey(const Key &key,
               const StyleAttributes *attributes,
               LayoutHelper::Orientation orientation,
               const QRectF &key_area_rect)
{
    if (key.action() != Key::ActionInsert) {
        return Key();
    }

    const QRect adjusted_key_rect(adjustedRect(key.rect(), key.margins()));
    QRect magnifier_rect(adjusted_key_rect.topLeft(),
                         QSize(attributes->magnifierKeyWidth(orientation),
                               attributes->magnifierKeyHeight(orientation)));
    magnifier_rect.translate((adjusted_key_rect.width() - magnifier_rect.width()) / 2,
                             -1 * attributes->verticalOffset(orientation));

    const QRect &mapped(magnifier_rect.translated(key_area_rect.topLeft().toPoint()));

    const int delta_left(mapped.left()
                         - (key_area_rect.left()
                         + attributes->safetyMargin(orientation)));
    const int delta_right((key_area_rect.x()
                           + key_area_rect.width()
                           - attributes->safetyMargin(orientation))
                          - (mapped.x() + mapped.width()));

    if (delta_left < 0) {
        magnifier_rect.translate(qAbs<int>(delta_left), 0);
    } else if (delta_right < 0) {
        magnifier_rect.translate(delta_right, 0);
    }

    Key magnifier(key);
    magnifier.setOrigin(magnifier_rect.topLeft());
    magnifier.rArea().setBackground(attributes->magnifierKeyBackground());
    magnifier.rArea().setSize(magnifier_rect.size());
    magnifier.rArea().setBackgroundBorders(attributes->magnifierKeyBackgroundBorders());

    magnifier.setMargins(QMargins());

    return magnifier;
}
示例#3
0
void MaskWidget::paintEvent(QPaintEvent* e)
{
	if (!m_desktopPixmap.isNull())
	{
		m_curPos = QCursor::pos();		
		QPainter painter(this);

		painter.drawPixmap(0, 0, m_desktopPixmap);

		if (!m_bScreenShotDone)
		{
			if (!m_bDragging)
			{
				m_curRc.setRect(-9999, -9999, 19999, 19999);
				for (std::vector<RECT>::iterator it = g_winRects.begin(); it != g_winRects.end(); ++it)
				{
					QRect rect;
					rect.setRect(it->left, it->top, it->right - it->left, it->bottom - it->top);
					if (rect.contains(QCursor::pos()) && m_curRc.contains(rect)/* && rect.height() > 5 && rect.width() > 5*/)
					{
						m_curRc = rect;
						//break;
					}
				}
			}
			else
			{
				m_curRc = QRect(m_startPoint, QCursor::pos());
			}
		}

		painter.save();
		painter.setPen(Qt::NoPen);
		painter.setBrush(QColor(0, 0, 0, 120));
		QPolygon p1(QRect(0, 0, width(), height()));
		QPolygon p2(m_curRc, true);
		p1 = p1.subtracted(p2);
		painter.drawPolygon(p1);
		painter.restore();

		painter.save();
		QPen pen = painter.pen();
		if (m_bScreenShotDone || m_bMousePressing)
		{
			pen.setWidth(2);
			pen.setColor(QColor(6, 157, 213));
			pen.setStyle(Qt::DashDotDotLine);
		}
		else
		{
			pen.setWidth(4);
			pen.setColor(QColor(0, 255, 0));
			pen.setStyle(Qt::SolidLine);
		}
		painter.setPen(pen);
		painter.drawRect(m_curRc);
		painter.restore();

		painter.save();
		
		QRect ori(m_curPos.x() - 15, m_curPos.y() - 11, 30, 22);
		QPixmap magnifier(126, 122);
		QPainter painter2(&magnifier);
		painter2.save();
		painter2.fillRect(0, 0, 126, 122, QBrush(QColor(51, 51, 51, 200)));
		painter2.restore();

		QPen p = painter2.pen();
		p.setWidth(1);
		p.setColor(QColor(51, 51, 51));
		painter2.setPen(p);
		painter2.drawRect(0, 0, 125, 93);

		p.setWidth(2);
		p.setColor(QColor(255, 255, 255));
		painter2.setPen(p);
		painter2.drawRect(2, 2, 122, 90);

		painter2.drawPixmap(3, 3, m_desktopPixmap.copy(ori).scaled(120, 88));

		p.setWidth(4);
		p.setColor(QColor(0, 122, 179, 128));
		painter2.setPen(p);
		painter2.drawLine(5, 45, 121, 45);
		painter2.drawLine(61, 5, 61, 89);

		p.setWidth(1);
		p.setColor(QColor(255, 255, 255));
		painter2.setPen(p);
		painter2.drawText(6, 105, QString("%1 x %2").arg(m_curRc.width()).arg(m_curRc.height()));
		QImage image = m_desktopPixmap.toImage();
		QRgb rgb = image.pixel(m_curPos.x()-1, m_curPos.y()-1);
		painter2.drawText(6, 118, QString("rgb(%1,%2,%3").arg(qRed(rgb)).arg(qGreen(rgb)).arg(qBlue(rgb)));

		QPoint showPoint(m_curPos.x() + 10, m_curPos.y() + 10);
		if (m_curPos.y() + 130 > this->height())
			showPoint.setY(m_curPos.y() - 130);

		if (m_curPos.x() + 130 > this->width())
			showPoint.setX(m_curPos.x() - 130);

		painter.drawPixmap(showPoint, magnifier);
	}
}