コード例 #1
0
void ConsoleWidget::handleHistory(bool down)
{
    int index;
    moveCursor(QTextCursor::End);
    QTextCursor cursor = textCursor();

    if (m_history.size()==0)
        return;

    if (down)
        m_histIndex--;
    else
        m_histIndex++;

    if (m_histIndex>m_history.size()-1)
        m_histIndex = m_history.size()-1;
    if (m_histIndex<0)
        m_histIndex = 0;
    index = m_history.size()-1-m_histIndex;

    cursor.select(QTextCursor::LineUnderCursor);
    cursor.removeSelectedText();

    handleColor();
    insertPlainText(m_prompt + m_history[index]);
    moveCursor(QTextCursor::End);
}
コード例 #2
0
void ConsoleWidget::print(QString text, QColor color)
{
    if (text=="")
        return;
    m_histIndex = -1;
    moveCursor(QTextCursor::End);
#if 0
    m_mutexPrint.lock();
#endif
    if (text==m_lastLine)
    {
        if (!m_suppress)
        {
            handleColor(color);
            insertPlainText("...\n");
            m_suppress = true;
        }
    }
    else
    {
        QTextCursor cursor = textCursor();
#if 0
        if (cursor.block().text()==m_prompt)
        {
            cursor.select(QTextCursor::LineUnderCursor);
            cursor.removeSelectedText();
        }
#endif
#if 0
        if (cursor.block().text()!="")
            text = '\n' + text;
#endif
        handleColor(color);
        DBG("console: %s", text.toUtf8().constData());
        insertPlainText(text);
        moveCursor(QTextCursor::End);

        m_suppress = false;
    }
    m_lastLine = text;
#if 0
    m_waitPrint.wakeAll();
    m_mutexPrint.unlock();
#endif
    m_timer.start(CW_TIMEOUT);
}
コード例 #3
0
void ConsoleWidget::command(QString text)
{
    text.remove(QRegExp("^\\s+")); // remove leading whitespace
    if (text=="")
        return;
    handleColor(CW_DEFAULT_COLOR);
    prompt();
    if (!text.endsWith('\n'))
        text = text + '\n';
    insertPlainText(text);

    emit textLine(text);
}
コード例 #4
0
ファイル: ToyWindow.cpp プロジェクト: zoombapup/OSCWidgets
void EditFrame::paintEvent(QPaintEvent* /*event*/)
{
	QRect r( rect() );
	r.adjust(0, 0, -1, -1);
	
	QPainter painter(this);
	
	QColor color(m_Selected ? QColor(0,200,60) : QColor(255,255,255));
	
	if( m_Selected )
	{
		QColor fillColor(color);
		fillColor.setAlpha(40);
		painter.fillRect(r, fillColor);
		
		QWidget *pParent = parentWidget();
		if( pParent )
		{
			QRect g( pParent->geometry() );
			QString label = QString("(%1,%2)\n%3x%4").arg(g.x()).arg(g.y()).arg(g.width()).arg(g.height());
			painter.setPen( QColor(0,0,0) );
			painter.drawText(r.adjusted(1,1,1,1), Qt::AlignCenter, label);
			painter.setPen( QColor(255,255,255) );
			painter.drawText(r, Qt::AlignCenter, label);
		}
	}
	
	r.adjust(HANDLE_MARGIN, HANDLE_MARGIN, -HANDLE_MARGIN-1, -HANDLE_MARGIN-1);
	
	for(int i=0; i<2; i++)
	{
		QColor handleColor((i==0) ? QColor(0,0,0) : color);
		
		painter.setBrush(Qt::NoBrush);
		if(i == 0)
			painter.setPen( QPen(handleColor,3) );
		else
			painter.setPen(handleColor);
		painter.drawRect(r);
	
		QRect scaleRect(width()-HANDLE_SIZE-1, height()-HANDLE_SIZE-1, HANDLE_SIZE, HANDLE_SIZE);
		if(i == 0)
			scaleRect.adjust(-1, -1, 1, 1);
		painter.fillRect(scaleRect, handleColor);
	}
}
コード例 #5
0
void ConsoleWidget::prompt()
{
    moveCursor(QTextCursor::End);
    QTextCursor cursor = textCursor();
    if (cursor.block().text()!=m_prompt)
    {
        m_timer.stop();
        if (cursor.block().text()!="")
            insertPlainText("\n");
        handleColor(); // change to default color
        insertPlainText(m_prompt);
        moveCursor(QTextCursor::End);

    }
    m_lastLine = "";
    // if we have trouble keeping viewport
    //QScrollBar *sb = verticalScrollBar();
    //sb->setSliderPosition(sb->maximum());
}
コード例 #6
0
ファイル: console.cpp プロジェクト: CodeMonkey1959/pixy
void ConsoleWidget::prompt(QString text)
{
    QString text2 = text;

    moveCursor(QTextCursor::End);

    handleColor(); // change to default color

    // add space because it looks better
    text2 += " ";

    // go to new line if line isn't empty
    emptyLine();
    insertPlainText(text2);
    m_lastLine = "";
    // if we have trouble keeping viewport
    QScrollBar *sb = verticalScrollBar();
    sb->setSliderPosition(sb->maximum());

    m_prompt = text2;
}
コード例 #7
0
ファイル: console.cpp プロジェクト: CodeMonkey1959/pixy
void ConsoleWidget::print(QString text, QColor color)
{
    emptyLine();
    moveCursor(QTextCursor::End);
    handleColor(color);
    m_mutexPrint.lock();
    if (text==m_lastLine)
    {
        if (!m_suppress)
        {
            insertPlainText("...\n");
            m_suppress = true;
        }
    }
    else
    {
        insertPlainText(text);
        m_suppress = false;
    }
    m_lastLine = text;
    m_waitPrint.wakeAll();
    m_mutexPrint.unlock();
}
コード例 #8
0
ファイル: areadialog.cpp プロジェクト: rndstr/Lightscreen
void AreaDialog::paintEvent(QPaintEvent* e)
{
  Q_UNUSED(e);

  if (mGrabbing) // grabWindow() should just get the background
    return;

  QPainter painter(this);

  QPalette pal = palette();
  QFont font   = QToolTip::font();

  QColor handleColor(85, 160, 188, 220);
  QColor overlayColor(0, 0, 0, mOverlayAlpha);
  QColor textColor = pal.color(QPalette::Active, QPalette::Text);
  QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base);
  painter.drawPixmap(0, 0, mScreenshot->pixmap());
  painter.setFont(font);

  QRect r = mSelection.normalized().adjusted(0, 0, -1, -1);

  QRegion grey(rect());
  grey = grey.subtracted(r);
  painter.setPen(handleColor);
  painter.setBrush(overlayColor);
  painter.setClipRegion(grey);
  painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1);
  painter.setClipRect(rect());
  painter.setBrush(Qt::NoBrush);
  painter.drawRect(r);

  if (mShowHelp) {
    //Drawing the explanatory text.
    QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
    QString helpTxt = tr("Lightscreen area mode:\nUse your mouse to draw a rectangle to capture.\nPress any key or right click to exit.");

    helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered)

    // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have.
    painter.setPen(QPen(Qt::white));
    painter.setBrush(QBrush(QColor(255, 255, 255, 180), Qt::SolidPattern));
    QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);

    // These four calls provide padding for the rect
    bRect.setWidth(bRect.width() + 12);
    bRect.setHeight(bRect.height() + 10);
    bRect.setX(bRect.x() - 12);
    bRect.setY(bRect.y() - 10);

    painter.drawRoundedRect(bRect, 8, 8);

    // Draw the text:
    painter.setPen(QPen(Qt::black));
    painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
  }

  if (!mSelection.isNull()) {
    // The grabbed region is everything which is covered by the drawn
    // rectangles (border included). This means that there is no 0px
    // selection, since a 0px wide rectangle will always be drawn as a line.
    QString txt = QString("%1x%2").arg(mSelection.width() == 0 ? 2 : mSelection.width())
        .arg(mSelection.height() == 0 ? 2 : mSelection.height());
    QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt);
    QRect boundingRect = textRect.adjusted(-4, 0, 0, 0);

    if (textRect.width() < r.width() - 2*mHandleSize &&
       textRect.height() < r.height() - 2*mHandleSize &&
       (r.width() > 100 && r.height() > 100)) // center, unsuitable for small selections
    {
      boundingRect.moveCenter(r.center());
      textRect.moveCenter(r.center());
    }
    else if (r.y() - 3 > textRect.height() &&
      r.x() + textRect.width() < rect().right()) // on top, left aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3));
      textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3));
    }
    else if (r.x() - 3 > textRect.width()) // left, top aligned
    {
      boundingRect.moveTopRight(QPoint(r.x() - 3, r.y()));
      textRect.moveTopRight(QPoint(r.x() - 5, r.y()));
    }
    else if (r.bottom() + 3 + textRect.height() < rect().bottom() &&
      r.right() > textRect.width()) // at bottom, right aligned
    {
      boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3));
      textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3));
    }
    else if (r.right() + textRect.width() + 3 < rect().width()) // right, bottom aligned
    {
      boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom()));
      textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom()));
    }
    // if the above didn't catch it, you are running on a very tiny screen...
    painter.setPen(textColor);
    painter.setBrush(textBackgroundColor);
    painter.drawRect(boundingRect);
    painter.drawText(textRect, txt);

    if ((r.height() > mHandleSize*2 && r.width() > mHandleSize*2)
      || !mMouseDown)
    {
      updateHandles();
      painter.setPen(handleColor);
      handleColor.setAlpha(80);
      painter.setBrush(handleColor);
      painter.drawRects(handleMask().rects());
    }
  }

  if (!mScreenshot->options().magnify)
    return;

  // Drawing the magnified version
  QPoint magStart, magEnd, drawPosition;
  QRect newRect;

  QRect pixmapRect = mScreenshot->pixmap().rect();

  if (mMouseMagnifier) {
    drawPosition = mMousePos - QPoint(100, 100);

    magStart = mMousePos - QPoint(50, 50);
    magEnd = mMousePos + QPoint(50, 50);

    newRect = QRect(magStart, magEnd);
  }
  else {
    // So pretty.. oh so pretty.
    if (mMouseOverHandle == &mTLHandle)
      magStart = mSelection.topLeft();
    else if (mMouseOverHandle == &mTRHandle)
      magStart = mSelection.topRight();
    else if (mMouseOverHandle == &mBLHandle)
      magStart = mSelection.bottomLeft();
    else if (mMouseOverHandle == &mBRHandle)
      magStart = mSelection.bottomRight();
    else if (mMouseOverHandle == &mLHandle)
      magStart = QPoint(mSelection.left(), mSelection.center().y());
    else if (mMouseOverHandle == &mTHandle)
      magStart = QPoint(mSelection.center().x(), mSelection.top());
    else if (mMouseOverHandle == &mRHandle)
      magStart = QPoint(mSelection.right(), mSelection.center().y());
    else if (mMouseOverHandle == &mBHandle)
      magStart =  QPoint(mSelection.center().x(), mSelection.bottom());
    else if (mMouseOverHandle == 0)
      magStart = mMousePos;

    magEnd = magStart;
    drawPosition = mSelection.bottomRight();

    magStart -= QPoint(50, 50);
    magEnd   += QPoint(50, 50);

    newRect = QRect(magStart, magEnd);

    if ((drawPosition.x()+newRect.width()*2) > pixmapRect.width())
      drawPosition.setX(drawPosition.x()-newRect.width()*2);

    if ((drawPosition.y()+newRect.height()*2) > pixmapRect.height())
      drawPosition.setY(drawPosition.y()-newRect.height()*2);

    if (drawPosition.y() == mSelection.bottomRight().y()-newRect.height()*2
     && drawPosition.x() == mSelection.bottomRight().x()-newRect.width()*2)
      painter.setOpacity(0.7);
  }

  if (!pixmapRect.contains(newRect, true) || drawPosition.x() <= 0 || drawPosition.y() <= 0)  {
    return;
  }

  QPixmap magnified = mScreenshot->pixmap().copy(newRect).scaled(QSize(newRect.width()*2, newRect.height()*2));

  QPainter magPainter(&magnified);
  magPainter.setPen(QPen(QBrush(QColor(35, 35, 35)), 2)); // Same border pen
  magPainter.drawRect(magnified.rect());

  if (!mMouseMagnifier) {
    magPainter.drawText(magnified.rect().center()-QPoint(4, -4), "+"); //Center minus the 4 pixels wide and across of the "+" -- TODO: Test alternative DPI settings.
  }

  painter.drawPixmap(drawPosition, magnified);
}