void RenderArea::paintEvent(QPaintEvent *)
{
    static const QPoint points[4] = {
        QPoint(10, 80),
        QPoint(20, 10),
        QPoint(80, 30),
        QPoint(90, 70)
    };

    QRect rect(10, 20, 80, 60);

    QPainterPath path;
    path.moveTo(20, 80);
    path.lineTo(20, 30);
    path.cubicTo(80, 0, 50, 50, 80, 80);

    int startAngle = 20 * 16;
    int arcLength = 120 * 16;

    QPainter painter(this);
    painter.setPen(pen);
    painter.setBrush(brush);
    if (antialiased)
        painter.setRenderHint(QPainter::Antialiasing, true);

    for (int x = 0; x < width(); x += 100)
    {
        for (int y = 0; y < height(); y += 100)
        {
            painter.save();
            painter.translate(x, y);

            if (transformed) {
                painter.translate(50, 50);
                painter.rotate(60.0);
                painter.scale(0.6, 0.9);
                painter.translate(-50, -50);
            }

            switch (shape) {
            case Line:
                painter.drawLine(rect.bottomLeft(), rect.topRight());
                break;
            case Points:
                painter.drawPoints(points, 4);
                break;
            case Polyline:
                painter.drawPolyline(points, 4);
                break;
            case Polygon:
                painter.drawPolygon(points, 4);
                break;
            case Rect:
                painter.drawRect(rect);
                break;
            case RoundedRect:
                painter.drawRoundedRect(rect, 25, 25, Qt::RelativeSize);
                break;
            case Ellipse:
                painter.drawEllipse(rect);
                break;
            case Arc:
                painter.drawArc(rect, startAngle, arcLength);
                break;
            case Chord:
                painter.drawChord(rect, startAngle, arcLength);
                break;
            case Pie:
                painter.drawPie(rect, startAngle, arcLength);
                break;
            case Path:
                painter.drawPath(path);
                break;
            case Text:
                painter.drawText(rect, Qt::AlignCenter, tr("Qt by\nDigia"));
                break;
            case Pixmap:
                painter.drawPixmap(10, 10, pixmap);
            } // end switch

            painter.restore();
        } // end for
    } // end for

    painter.setRenderHint(QPainter::Antialiasing, false);
    painter.setPen(palette().dark().color());
    painter.setBrush(Qt::NoBrush);
    painter.drawRect(QRect(0, 0, width() - 1, height() - 1));
}
Beispiel #2
0
void tst_QItemDelegate::editorEvent_data()
{
    QTest::addColumn<QRect>("rect");
    QTest::addColumn<QString>("text");
    QTest::addColumn<int>("checkState");
    QTest::addColumn<int>("flags");
    QTest::addColumn<bool>("inCheck");
    QTest::addColumn<int>("type");
    QTest::addColumn<int>("button");
    QTest::addColumn<bool>("edited");
    QTest::addColumn<int>("expectedCheckState");

    QTest::newRow("unchecked, checkable, release")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Unchecked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << true
        << (int)(QEvent::MouseButtonRelease)
        << (int)(Qt::LeftButton)
        << true
        << (int)(Qt::Checked);

    QTest::newRow("checked, checkable, release")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Checked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << true
        << (int)(QEvent::MouseButtonRelease)
        << (int)(Qt::LeftButton)
        << true
        << (int)(Qt::Unchecked);

    QTest::newRow("unchecked, checkable, release")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Unchecked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << true
        << (int)(QEvent::MouseButtonRelease)
        << (int)(Qt::LeftButton)
        << true
        << (int)(Qt::Checked);

    QTest::newRow("unchecked, checkable, release, right button")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Unchecked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << true
        << (int)(QEvent::MouseButtonRelease)
        << (int)(Qt::RightButton)
        << false
        << (int)(Qt::Unchecked);

    QTest::newRow("unchecked, checkable, release outside")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Unchecked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << false
        << (int)(QEvent::MouseButtonRelease)
        << (int)(Qt::LeftButton)
        << false
        << (int)(Qt::Unchecked);

    QTest::newRow("unchecked, checkable, dblclick")
        << QRect(0, 0, 20, 20)
        << QString("foo")
        << (int)(Qt::Unchecked)
        << (int)(Qt::ItemIsEditable
            |Qt::ItemIsSelectable
            |Qt::ItemIsUserCheckable
            |Qt::ItemIsEnabled
            |Qt::ItemIsDragEnabled
            |Qt::ItemIsDropEnabled)
        << true
        << (int)(QEvent::MouseButtonDblClick)
        << (int)(Qt::LeftButton)
        << true
        << (int)(Qt::Unchecked);
}
Beispiel #3
0
ImagePortOverlay::ImagePortOverlay(QString name)
    : MainOverlay(name), mScale(1.0), mPixmap()
{
    mFixedAspectRatio = true;
    mRect = QRect(0, 0, 640, 480);
}
Beispiel #4
0
void SessionsInner::paintEvent(QPaintEvent *e) {
    QRect r(e->rect());
    Painter p(this);

    p.fillRect(r, st::white->b);
    int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.iconPos.x();// st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
    int32 w = width();

    if (_current->active.isEmpty() && _list->isEmpty()) {
        p.setFont(st::noContactsFont->f);
        p.setPen(st::noContactsColor->p);
        p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
        return;
    }

    if (r.y() <= st::sessionCurrentHeight) {
        p.translate(0, st::sessionCurrentPadding.top());
        p.setFont(st::sessionNameFont->f);
        p.setPen(st::black->p);
        p.drawTextLeft(x, st::sessionPadding.top(), w, _current->name, _current->nameWidth);

        p.setFont(st::sessionActiveFont->f);
        p.setPen(st::sessionActiveColor->p);
        p.drawTextRight(x, st::sessionPadding.top(), w, _current->active, _current->activeWidth);

        p.setFont(st::sessionInfoFont->f);
        p.setPen(st::black->p);
        p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, _current->info, _current->infoWidth);
        p.setPen(st::sessionInfoColor->p);
        p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, _current->ip, _current->ipWidth);
    }
    p.translate(0, st::sessionCurrentHeight - st::sessionCurrentPadding.top());
    if (_list->isEmpty()) {
        p.setFont(st::sessionInfoFont->f);
        p.setPen(st::sessionInfoColor->p);
        p.drawText(QRect(st::sessionPadding.left(), 0, width() - st::sessionPadding.left() - st::sessionPadding.right(), st::noContactsHeight), lang(lng_sessions_other_desc), style::al_topleft);
        return;
    }

    p.setFont(st::linkFont->f);
    int32 count = _list->size();
    int32 from = floorclamp(r.y() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
    int32 to = ceilclamp(r.y() + r.height() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
    p.translate(0, from * st::sessionHeight);
    for (int32 i = from; i < to; ++i) {
        const SessionData &auth(_list->at(i));

        p.setFont(st::sessionNameFont->f);
        p.setPen(st::black->p);
        p.drawTextLeft(x, st::sessionPadding.top(), w, auth.name, auth.nameWidth);

        p.setFont(st::sessionActiveFont->f);
        p.setPen(st::sessionActiveColor->p);
        p.drawTextRight(xact, st::sessionPadding.top(), w, auth.active, auth.activeWidth);

        p.setFont(st::sessionInfoFont->f);
        p.setPen(st::black->p);
        p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, auth.info, auth.infoWidth);
        p.setPen(st::sessionInfoColor->p);
        p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, auth.ip, auth.ipWidth);

        p.translate(0, st::sessionHeight);
    }
}
Beispiel #5
0
bool KatePrinter::print (KateDocument *doc)
{
  QPrinter printer;
  readSettings(printer);

  // docname is now always there, including the right Untitled name
  printer.setDocName(doc->documentName());

  KatePrintTextSettings *kpts = new KatePrintTextSettings;
  KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter;
  KatePrintLayout *kpl = new KatePrintLayout;

  QList<QWidget*> tabs;
  tabs << kpts;
  tabs << kphf;
  tabs << kpl;

  QWidget *parentWidget=doc->widget();

  if ( !parentWidget )
    parentWidget=QApplication::activeWindow();

  QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(&printer, KdePrint::SystemSelectsPages, tabs, parentWidget));

  if ( doc->activeView()->selection() ) {
    printer.setPrintRange(QPrinter::Selection);
    printDialog->setOption(QAbstractPrintDialog::PrintSelection, true);
  }

  if ( printDialog->exec() )
  {
    writeSettings(printer);

    KateRenderer renderer(doc, doc->activeKateView());
    renderer.config()->setSchema (kpl->colorScheme());
    renderer.setPrinterFriendly(true);

    QPainter paint( &printer );
    /*
     *        We work in tree cycles:
     *        1) initialize variables and retrieve print settings
     *        2) prepare data according to those settings
     *        3) draw to the printer
     */
    uint pdmWidth = printer.width();
    uint pdmHeight = printer.height();
    int y = 0;
    uint xstart = 0; // beginning point for painting lines
    uint lineCount = 0;
    uint maxWidth = pdmWidth;
    int headerWidth = pdmWidth;
    int startCol = 0;
    int endCol = 0;
    bool pageStarted = true;
    int remainder = 0; // remaining sublines from a wrapped line (for the top of a new page)

    // Text Settings Page
    bool selectionOnly = (printDialog->printRange() == QAbstractPrintDialog::Selection);
    bool useGuide = kpts->printGuide();

    bool printLineNumbers = kpts->printLineNumbers();
    uint lineNumberWidth( 0 );

    // Header/Footer Page
    QFont headerFont(kphf->font()); // used for header/footer

    bool useHeader = kphf->useHeader();
    QColor headerBgColor(kphf->headerBackground());
    QColor headerFgColor(kphf->headerForeground());
    uint headerHeight( 0 ); // further init only if needed
    QStringList headerTagList; // do
    bool headerDrawBg = false; // do

    bool useFooter = kphf->useFooter();
    QColor footerBgColor(kphf->footerBackground());
    QColor footerFgColor(kphf->footerForeground());
    uint footerHeight( 0 ); // further init only if needed
    QStringList footerTagList; // do
    bool footerDrawBg = false; // do

    // Layout Page
    renderer.config()->setSchema( kpl->colorScheme() );
    bool useBackground = kpl->useBackground();
    bool useBox = kpl->useBox();
    int boxWidth(kpl->boxWidth());
    QColor boxColor(kpl->boxColor());
    int innerMargin = useBox ? kpl->boxMargin() : 6;

    // Post initialization
    int maxHeight = (useBox ? pdmHeight-innerMargin : pdmHeight);
    uint currentPage( 1 );
    uint lastline = doc->lastLine(); // necessary to print selection only
    uint firstline( 0 );
    const int fontHeight = renderer.fontHeight();
    KTextEditor::Range selectionRange;

    /*
    *        Now on for preparations...
    *        during preparations, variable names starting with a "_" means
    *        those variables are local to the enclosing block.
    */
    {
      if ( selectionOnly )
      {
        // set a line range from the first selected line to the last
        selectionRange = doc->activeView()->selectionRange();
        firstline = selectionRange.start().line();
        lastline = selectionRange.end().line();
        lineCount = firstline;
      }

      if ( printLineNumbers )
      {
        // figure out the horiizontal space required
        QString s( QString("%1 ").arg( doc->lines() ) );
        s.fill('5', -1); // some non-fixed fonts haven't equally wide numbers
        // FIXME calculate which is actually the widest...
        lineNumberWidth = renderer.currentFontMetrics().width( s );
        // a small space between the line numbers and the text
        int _adj = renderer.currentFontMetrics().width( "5" );
        // adjust available width and set horizontal start point for data
        maxWidth -= (lineNumberWidth + _adj);
        xstart += lineNumberWidth + _adj;
      }

      if ( useHeader || useFooter )
      {
        // Set up a tag map
        // This retrieves all tags, ued or not, but
        // none of theese operations should be expensive,
        // and searcing each tag in the format strings is avoided.
        QDateTime dt = QDateTime::currentDateTime();
        QMap<QString,QString> tags;

        KUser u (KUser::UseRealUserID);
        tags["u"] = u.loginName();

        tags["d"] = KGlobal::locale()->formatDateTime(dt, KLocale::ShortDate);
        tags["D"] =  KGlobal::locale()->formatDateTime(dt, KLocale::LongDate);
        tags["h"] =  KGlobal::locale()->formatTime(dt.time(), false);
        tags["y"] =  KGlobal::locale()->formatDate(dt.date(), KLocale::ShortDate);
        tags["Y"] =  KGlobal::locale()->formatDate(dt.date(), KLocale::LongDate);
        tags["f"] =  doc->url().fileName();
        tags["U"] =  doc->url().prettyUrl();
        if ( selectionOnly )
        {
          QString s( i18n("(Selection of) ") );
          tags["f"].prepend( s );
          tags["U"].prepend( s );
        }

        QRegExp reTags( "%([dDfUhuyY])" ); // TODO tjeck for "%%<TAG>"

        if (useHeader)
        {
          headerDrawBg = kphf->useHeaderBackground();
          headerHeight = QFontMetrics( headerFont ).height();
          if ( useBox || headerDrawBg )
            headerHeight += innerMargin * 2;
          else
            headerHeight += 1 + QFontMetrics( headerFont ).leading();

          headerTagList = kphf->headerFormat();
          QMutableStringListIterator it(headerTagList);
          while ( it.hasNext() ) {
            QString tag = it.next();
            int pos = reTags.indexIn( tag );
            QString rep;
            while ( pos > -1 )
            {
              rep = tags[reTags.cap( 1 )];
              tag.replace( (uint)pos, 2, rep );
              pos += rep.length();
              pos = reTags.indexIn( tag, pos );
            }
            it.setValue( tag );
          }

          if (!headerBgColor.isValid())
            headerBgColor = Qt::lightGray;
          if (!headerFgColor.isValid())
            headerFgColor = Qt::black;
        }

        if (useFooter)
        {
          footerDrawBg = kphf->useFooterBackground();
          footerHeight = QFontMetrics( headerFont ).height();
          if ( useBox || footerDrawBg )
            footerHeight += 2*innerMargin;
          else
            footerHeight += 1; // line only

          footerTagList = kphf->footerFormat();
          QMutableStringListIterator it(footerTagList);
          while ( it.hasNext() ) {
            QString tag = it.next();
            int pos = reTags.indexIn( tag );
            QString rep;
            while ( pos > -1 )
            {
              rep = tags[reTags.cap( 1 )];
              tag.replace( (uint)pos, 2, rep );
              pos += rep.length();
              pos = reTags.indexIn( tag, pos );
            }
            it.setValue( tag );
          }

          if (!footerBgColor.isValid())
            footerBgColor = Qt::lightGray;
          if (!footerFgColor.isValid())
            footerFgColor = Qt::black;
          // adjust maxheight, so we can know when/where to print footer
          maxHeight -= footerHeight;
        }
      } // if ( useHeader || useFooter )

      if ( useBackground )
      {
        if ( ! useBox )
        {
          xstart += innerMargin;
          maxWidth -= innerMargin * 2;
        }
      }

      if ( useBox )
      {
        if (!boxColor.isValid())
          boxColor = Qt::black;
        if (boxWidth < 1) // shouldn't be pssible no more!
          boxWidth = 1;
        // set maxwidth to something sensible
        maxWidth -= ( ( boxWidth + innerMargin )  * 2 );
        xstart += boxWidth + innerMargin;
        // maxheight too..
        maxHeight -= boxWidth;
      }
      else
        boxWidth = 0;

      // now that we know the vertical amount of space needed,
      // it is possible to calculate the total number of pages
      // if needed, that is if any header/footer tag contains "%P".
      if ( !headerTagList.filter("%P").isEmpty() || !footerTagList.filter("%P").isEmpty() )
      {
        kDebug(13020)<<"'%P' found! calculating number of pages...";
        int pageHeight = maxHeight;
        if ( useHeader )
          pageHeight -= ( headerHeight + innerMargin );
        if ( useFooter )
          pageHeight -= innerMargin;
        const int linesPerPage = pageHeight / fontHeight;
//         kDebug() << "Lines per page:" << linesPerPage;
        
        // calculate total layouted lines in the document
        int totalLines = 0;
        // TODO: right now ignores selection printing
        for (int i = firstline; i <= lastline; ++i) {
          KateLineLayoutPtr rangeptr(new KateLineLayout(doc));
          rangeptr->setLine(i);
          renderer.layoutLine(rangeptr, (int)maxWidth, false);
          totalLines += rangeptr->viewLineCount();
        }
        int totalPages = (totalLines / linesPerPage)
                      + ((totalLines % linesPerPage) > 0 ? 1 : 0);
//         kDebug() << "_______ pages:" << (totalLines / linesPerPage);
//         kDebug() << "________ rest:" << (totalLines % linesPerPage);

        // TODO: add space for guide if required
//         if ( useGuide )
//           _lt += (guideHeight + (fontHeight /2)) / fontHeight;

        // substitute both tag lists
        QString re("%P");
        QStringList::Iterator it;
        for ( it=headerTagList.begin(); it!=headerTagList.end(); ++it )
          (*it).replace( re, QString( "%1" ).arg( totalPages ) );
        for ( it=footerTagList.begin(); it!=footerTagList.end(); ++it )
          (*it).replace( re, QString( "%1" ).arg( totalPages ) );
      }
    } // end prepare block

     /*
        On to draw something :-)
     */
    while (  lineCount <= lastline  )
    {
      startCol = 0;
      endCol = 0;

      if ( y + fontHeight > maxHeight )
      {
        kDebug(13020)<<"Starting new page,"<<lineCount<<"lines up to now.";
        printer.newPage();
        paint.resetTransform();
        currentPage++;
        pageStarted = true;
        y=0;
      }

      if ( pageStarted )
      {
        if ( useHeader )
        {
          paint.setPen(headerFgColor);
          paint.setFont(headerFont);
          if ( headerDrawBg )
            paint.fillRect(0, 0, headerWidth, headerHeight, headerBgColor);
          if (headerTagList.count() == 3)
          {
            int valign = ( (useBox||headerDrawBg||useBackground) ?
            Qt::AlignVCenter : Qt::AlignTop );
            int align = valign|Qt::AlignLeft;
            int marg = ( useBox || headerDrawBg ) ? innerMargin : 0;
            if ( useBox ) marg += boxWidth;
            QString s;
            for (int i=0; i<3; i++)
            {
              s = headerTagList[i];
              if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
              paint.drawText(marg, 0, headerWidth-(marg*2), headerHeight, align, s);
              align = valign|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
            }
          }
          if ( ! ( headerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate header from contents
          {
            paint.drawLine( 0, headerHeight-1, headerWidth, headerHeight-1 );
            //y += 1; now included in headerHeight
          }
          y += headerHeight + innerMargin;
        }

        if ( useFooter )
        {
          paint.setPen(footerFgColor);
          if ( ! ( footerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate footer from contents
            paint.drawLine( 0, maxHeight + innerMargin - 1, headerWidth, maxHeight + innerMargin - 1 );
          if ( footerDrawBg )
            paint.fillRect(0, maxHeight+innerMargin+boxWidth, headerWidth, footerHeight, footerBgColor);
          if (footerTagList.count() == 3)
          {
            int align = Qt::AlignVCenter|Qt::AlignLeft;
            int marg = ( useBox || footerDrawBg ) ? innerMargin : 0;
            if ( useBox ) marg += boxWidth;
            QString s;
            for (int i=0; i<3; i++)
            {
              s = footerTagList[i];
              if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage));
              paint.drawText(marg, maxHeight+innerMargin, headerWidth-(marg*2), footerHeight, align, s);
              align = Qt::AlignVCenter|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight);
            }
          }
        } // done footer

        if ( useBackground )
        {
          // If we have a box, or the header/footer has backgrounds, we want to paint
          // to the border of those. Otherwise just the contents area.
          int _y = y, _h = maxHeight - y;
          if ( useBox )
          {
            _y -= innerMargin;
            _h += 2 * innerMargin;
          }
          else
          {
            if ( headerDrawBg )
            {
              _y -= innerMargin;
              _h += innerMargin;
            }
            if ( footerDrawBg )
            {
              _h += innerMargin;
            }
          }
          paint.fillRect( 0, _y, pdmWidth, _h, renderer.config()->backgroundColor());
        }

        if ( useBox )
        {
          paint.setPen(QPen(boxColor, boxWidth));
          paint.drawRect(0, 0, pdmWidth, pdmHeight);
          if (useHeader)
            paint.drawLine(0, headerHeight, headerWidth, headerHeight);
          else
            y += innerMargin;

          if ( useFooter ) // drawline is not trustable, grr.
            paint.fillRect( 0, maxHeight+innerMargin, headerWidth, boxWidth, boxColor );
        }

        if ( useGuide && currentPage == 1 )
        {  // FIXME - this may span more pages...
          // draw a box unless we have boxes, in which case we end with a box line
          int _ystart = y;
          QString _hlName = doc->highlight()->name();

          QList<KateExtendedAttribute::Ptr> _attributes; // list of highlight attributes for the legend
          doc->highlight()->getKateExtendedAttributeList(kpl->colorScheme(), _attributes);

          KateAttributeList _defaultAttributes;
          KateHlManager::self()->getDefaults ( renderer.config()->schema(), _defaultAttributes );

          QColor _defaultPen = _defaultAttributes.at(0)->foreground().color();
          paint.setPen(_defaultPen);

          int _marg = 0;
          if ( useBox )
            _marg += (2*boxWidth) + (2*innerMargin);
          else
          {
            if ( useBackground )
              _marg += 2*innerMargin;
            _marg += 1;
            y += 1 + innerMargin;
          }

          // draw a title string
          QFont _titleFont = renderer.config()->font();
          _titleFont.setBold(true);
          paint.setFont( _titleFont );
          QRect _r;
          paint.drawText( QRect(_marg, y, pdmWidth-(2*_marg), maxHeight - y),
            Qt::AlignTop|Qt::AlignHCenter,
            i18n("Typographical Conventions for %1", _hlName ), &_r );
          int _w = pdmWidth - (_marg*2) - (innerMargin*2);
          int _x = _marg + innerMargin;
          y += _r.height() + innerMargin;
          paint.drawLine( _x, y, _x + _w, y );
          y += 1 + innerMargin;

          int _widest( 0 );
          foreach (const KateExtendedAttribute::Ptr &attribute, _attributes)
            _widest = qMax(QFontMetrics(attribute->font()).width(attribute->name().section(':',1,1)), _widest);

          int _guideCols = _w/( _widest + innerMargin );

          // draw attrib names using their styles
          int _cw = _w/_guideCols;
          int _i(0);

          _titleFont.setUnderline(true);
          QString _currentHlName;
          foreach (const KateExtendedAttribute::Ptr &attribute, _attributes)
          {
            QString _hl = attribute->name().section(':',0,0);
            QString _name = attribute->name().section(':',1,1);
            if ( _hl != _hlName && _hl != _currentHlName ) {
              _currentHlName = _hl;
              if ( _i%_guideCols )
                y += fontHeight;
              y += innerMargin;
              paint.setFont(_titleFont);
              paint.setPen(_defaultPen);
              paint.drawText( _x, y, _w, fontHeight, Qt::AlignTop, _hl + ' ' + i18n("text") );
              y += fontHeight;
              _i = 0;
            }

            KTextEditor::Attribute _attr =  *_defaultAttributes[attribute->defaultStyleIndex()];
            _attr += *attribute;
            paint.setPen( _attr.foreground().color() );
            paint.setFont( _attr.font() );

            if (_attr.hasProperty(QTextFormat::BackgroundBrush) ) {
              QRect _rect = QFontMetrics(_attr.font()).boundingRect(_name);
              _rect.moveTo(_x + ((_i%_guideCols)*_cw), y);
               paint.fillRect(_rect, _attr.background() );
            }

            paint.drawText(( _x + ((_i%_guideCols)*_cw)), y, _cw, fontHeight, Qt::AlignTop, _name );

            _i++;
            if ( _i && ! ( _i%_guideCols ) )
              y += fontHeight;
          }

          if ( _i%_guideCols )
            y += fontHeight;// last row not full

          // draw a box around the legend
          paint.setPen ( _defaultPen );
          if ( useBox )
            paint.fillRect( 0, y+innerMargin, headerWidth, boxWidth, boxColor );
          else
          {
            _marg -=1;
            paint.drawRect( _marg, _ystart, pdmWidth-(2*_marg), y-_ystart+innerMargin );
          }

          y += ( useBox ? boxWidth : 1 ) + (innerMargin*2);
        } // useGuide

        paint.translate(xstart,y);
        pageStarted = false;
      } // pageStarted; move on to contents:)
Beispiel #6
0
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
{
    if (!validIndex(tabIndex)) {
        qWarning("invalid index");
        return;
    }
    painter->save();

    QRect rect = tabRect(tabIndex);
    bool selected = (tabIndex == m_currentIndex);
    bool enabled = isTabEnabled(tabIndex);

    if (selected) {
        //background
        painter->save();
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, QColor(255, 255, 255, 140));
        grad.setColorAt(1, QColor(255, 255, 255, 210));
        painter->fillRect(rect.adjusted(0, 0, 0, -1), grad);
        painter->restore();

        //shadows
        painter->setPen(QColor(0, 0, 0, 110));
        painter->drawLine(rect.topLeft() + QPoint(1,-1), rect.topRight() - QPoint(0,1));
        painter->drawLine(rect.bottomLeft(), rect.bottomRight());
        painter->setPen(QColor(0, 0, 0, 40));
        painter->drawLine(rect.topLeft(), rect.bottomLeft());

        //highlights
        painter->setPen(QColor(255, 255, 255, 50));
        painter->drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0,2));
        painter->drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0,1));
        painter->setPen(QColor(255, 255, 255, 40));
        painter->drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight());
        painter->drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1));
        painter->drawLine(rect.bottomLeft() + QPoint(0,-1), rect.bottomRight()-QPoint(0,1));
    }

    QString tabText(this->tabText(tabIndex));
    QRect tabTextRect(rect);
    const bool drawIcon = rect.height() > 36;
    QRect tabIconRect(tabTextRect);
    tabTextRect.translate(0, drawIcon ? -2 : 1);
    QFont boldFont(painter->font());
    boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
    boldFont.setBold(true);
    painter->setFont(boldFont);
    painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
    const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap;
    if (enabled) {
        painter->drawText(tabTextRect, textFlags, tabText);
        painter->setPen(selected ? QColor(60, 60, 60) : StyleHelper::panelTextColor());
    } else {
        painter->setPen(selected ? StyleHelper::panelTextColor() : QColor(255, 255, 255, 120));
    }
    if (/*!Utils::HostOsInfo::isMacHost()*/ true && !selected && enabled) {
        painter->save();
        int fader = int(m_tabs[tabIndex]->fader());
        QLinearGradient grad(rect.topLeft(), rect.topRight());
        grad.setColorAt(0, Qt::transparent);
        grad.setColorAt(0.5, QColor(255, 255, 255, fader));
        grad.setColorAt(1, Qt::transparent);
        painter->fillRect(rect, grad);
        painter->setPen(QPen(grad, 1.0));
        painter->drawLine(rect.topLeft(), rect.topRight());
        painter->drawLine(rect.bottomLeft(), rect.bottomRight());
        painter->restore();
    }

    if (!enabled)
        painter->setOpacity(0.7);

    if (drawIcon) {
        int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
        tabIconRect.adjust(0, 4, 0, -textHeight);
        StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, enabled ? QIcon::Normal : QIcon::Disabled);
    }

    painter->translate(0, -1);
    painter->drawText(tabTextRect, textFlags, tabText);
    painter->restore();
}
void SelectionView::mousePressEvent( QMouseEvent *e )
{
    if ( _drawLine ) {
        _drawLineHold = true;
        delete linePath;
        linePath = new QPainterPath;
        linePath->moveTo( e->posF() );
        e->accept();
        return;
    }

	//add
	QPoint expandingTopLeft;
	QPoint expandingTerminalPoint;

	int expandingWidth  = int(_snapWidth*_zoomRatio*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
	int expandingHeight = int(_snapHeight*_zoomRatio*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

	//add
	_selectionFinished = false;

	_originPoint = e->pos();

	// !* selfDefine selection, draw a rectangle with size of given pixel.
	if (_snapRatio == -1.0)
	{
		//!* from center
		if (_isFromCenter)
		{
			_pCenterRubberBand->show();
			_pCenterRubberBand->setGeometry(QRect(_originPoint-QPoint(3,3), _originPoint+QPoint(3,3)).normalized());
			_pRubberBand->setGeometry( _originPoint.x() - int(_snapWidth*_zoomRatio/2),	
				_originPoint.y() - int(_snapHeight*_zoomRatio/2), 
				_snapWidth*_zoomRatio, _snapHeight*_zoomRatio);	
			_pExpandingRubberBand->setGeometry( _originPoint.x() - int(_snapWidth*_zoomRatio/2) - expandingWidth,	
				_originPoint.y() - int(_snapHeight*_zoomRatio/2) - expandingWidth, 
				_snapWidth*_zoomRatio + expandingWidth*2, _snapHeight*_zoomRatio + expandingWidth*2);	
		}
		//!* from TopLeft
		else
		{
			_pCenterRubberBand->hide();
			_pRubberBand->setGeometry( _originPoint.x(), _originPoint.y(), 
				_snapWidth*_zoomRatio-1, _snapHeight*_zoomRatio-1);	
			_pExpandingRubberBand->setGeometry( _originPoint.x() - expandingWidth, _originPoint.y() - expandingWidth, 
				_snapWidth*_zoomRatio-1 + expandingWidth*2, _snapHeight*_zoomRatio-1 + expandingWidth*2);	
		}
	}
	else
	{
		//!* from center
		if (_isFromCenter)
		{
			_pCenterRubberBand->show();
			_pCenterRubberBand->setGeometry(QRect(_originPoint-QPoint(3,3), _originPoint+QPoint(3,3)).normalized());
		}
		else
			_pCenterRubberBand->hide();
		_pRubberBand->setGeometry(QRect(_originPoint, QSize()));
		_pExpandingRubberBand->setGeometry(QRect(_originPoint, QSize()));
	}

	_pExpandingRubberBand->show();
	_pRubberBand->show();
}	
Beispiel #8
0
void *SearchDialog::processEvent(Event *e)
{
    switch (e->type()){
    case EventClientsChanged:
    case EventClientChanged:
        fillClients();
        break;
	case EventCommandExec:{
		CommandDef *cmd = (CommandDef*)(e->param());
		if (cmd->menu_id == MenuSearchGroups){
			Group *grp = getContacts()->group(cmd->id - CmdContactGroup);
			if (grp){
				Contact *contact = NULL;
				if ((QWidget*)(cmd->param) == m_search->btnSearch){
            if (m_current){
                connect(this, SIGNAL(createContact(unsigned,Contact*&)), m_current, SLOT(createContact(unsigned,Contact*&)));
                emit createContact(CONTACT_TEMP, contact);
                disconnect(this, SIGNAL(createContact(unsigned,Contact*&)), m_current, SLOT(createContact(unsigned,Contact*&)));
            }
				}else{
					contact = createContact(CONTACT_TEMP);
				}
				if (contact){
					if ((contact->getFlags() & CONTACT_TEMP) == 0){
						QString err = i18n("%1 already in contact list") .arg(contact->getName());
						if ((QWidget*)(cmd->param) == m_search->btnAdd){
							BalloonMsg::message(err, m_search->btnAdd);
						}else if ((QWidget*)(cmd->param) == m_search->btnSearch){
							BalloonMsg::message(err, m_search->btnSearch);
						}else{
							QRect rc = m_result->itemRect((QListViewItem*)(e->param()));
							QPoint p = m_result->viewport()->mapToGlobal(QPoint(rc.left(), rc.top()));
							rc = QRect(p.x(), p.y(), rc.width(), rc.height());
							BalloonMsg::message(err, m_result, false, 150, &rc);
						}
						return e->param();
					}
					contact->setFlags(contact->getFlags() & ~CONTACT_TEMP);
					contact->setGroup(grp->id());
					Event e(EventContactChanged, contact);
					e.process();
				}
			}
			return e->param();
		}
		if (cmd->id == CmdSearchInfo){
	Contact *contact = createContact(CONTACT_TEMP);
	if (contact == NULL)
		return e->param();
	Command cmd;
	cmd->id		 = CmdInfo;
	cmd->menu_id = MenuContact;
	cmd->param   = (void*)(contact->id());
	CorePlugin::m_plugin->showInfo(cmd);
	return e->param();
		}
		if (cmd->id == CmdSearchMsg){
	Contact *contact = createContact(CONTACT_TEMP);
	if (contact == NULL)
		return e->param();
                Message *m = new Message(MessageGeneric);
                m->setContact(contact->id());
                Event e(EventOpenMessage, &m);
                e.process();
                delete m;
		}
		break;
		}
/*!
  Returns the region specified by \a decorationRegion for the
  top-level \a widget. \a rect specifies the rectangle the decoration
  wraps. The value of \a decorationRegion is a combination of the
  bitmask values of enum DecorationRegion.
 */
QRegion QDecorationDefault::region(const QWidget *widget,
                                   const QRect &rect,
                                   int decorationRegion)
{
    Qt::WindowFlags flags = widget->windowFlags();
    bool hasBorder = !widget->isMaximized();
    bool hasTitle = flags & Qt::WindowTitleHint;
    bool hasSysMenu = flags & Qt::WindowSystemMenuHint;
    bool hasContextHelp = flags & Qt::WindowContextHelpButtonHint;
    bool hasMinimize = flags & Qt::WindowMinimizeButtonHint;
    bool hasMaximize = flags & Qt::WindowMaximizeButtonHint;
    int state = widget->windowState();
    bool isMinimized = state & Qt::WindowMinimized;
    bool isMaximized = state & Qt::WindowMaximized;

    int titleHeight = hasTitle ? titleBarHeight(widget) : 0;
    int bw = hasBorder ? BORDER_WIDTH : 0;
    int bbw = hasBorder ? BOTTOM_BORDER_WIDTH : 0;

    QRegion region;
    switch (decorationRegion) {
        case All: {
                QRect r(rect.left() - bw,
                        rect.top() - titleHeight - bw,
                        rect.width() + 2 * bw,
                        rect.height() + titleHeight + bw + bbw);
                region = r;
                region -= rect;
            }
            break;

        case Title: {
                QRect r(rect.left()
                        + (hasSysMenu ? menu_width : 0),
                        rect.top() - titleHeight,
                        rect.width()
                        - (hasSysMenu ? menu_width : 0)
                        - close_width
                        - (hasMaximize ? maximize_width : 0)
                        - (hasMinimize ? minimize_width : 0)
                        - (hasContextHelp ? help_width : 0),

                        titleHeight);
                if (r.width() > 0)
                    region = r;
            }
            break;

        case Top: {
                QRect r(rect.left() + CORNER_GRAB,
                        rect.top() - titleHeight - bw,
                        rect.width() - 2 * CORNER_GRAB,
                        bw);
                region = r;
            }
            break;

        case Left: {
                QRect r(rect.left() - bw,
                        rect.top() - titleHeight + CORNER_GRAB,
                        bw,
                        rect.height() + titleHeight - 2 * CORNER_GRAB);
                region = r;
            }
            break;

        case Right: {
                QRect r(rect.right() + 1,
                        rect.top() - titleHeight + CORNER_GRAB,
                        bw,
                        rect.height() + titleHeight - 2 * CORNER_GRAB);
                region = r;
            }
            break;

        case Bottom: {
                QRect r(rect.left() + CORNER_GRAB,
                        rect.bottom() + 1,
                        rect.width() - 2 * CORNER_GRAB,
                        bw);
                region = r;
            }
            break;

        case TopLeft: {
                QRect r1(rect.left() - bw,
                        rect.top() - bw - titleHeight,
                        CORNER_GRAB + bw,
                        bw);

                QRect r2(rect.left() - bw,
                        rect.top() - bw - titleHeight,
                        bw,
                        CORNER_GRAB + bw);

                region = QRegion(r1) + r2;
            }
            break;

        case TopRight: {
                QRect r1(rect.right() - CORNER_GRAB,
                        rect.top() - bw - titleHeight,
                        CORNER_GRAB + bw,
                        bw);

                QRect r2(rect.right() + 1,
                        rect.top() - bw - titleHeight,
                        bw,
                        CORNER_GRAB + bw);

                region = QRegion(r1) + r2;
            }
            break;

        case BottomLeft: {
                QRect r1(rect.left() - bw,
                        rect.bottom() + 1,
                        CORNER_GRAB + bw,
                        bw);

                QRect r2(rect.left() - bw,
                        rect.bottom() - CORNER_GRAB,
                        bw,
                        CORNER_GRAB + bw);
                region = QRegion(r1) + r2;
            }
            break;

        case BottomRight: {
                QRect r1(rect.right() - CORNER_GRAB,
                        rect.bottom() + 1,
                        CORNER_GRAB + bw,
                        bw);

                QRect r2(rect.right() + 1,
                        rect.bottom() - CORNER_GRAB,
                        bw,
                        CORNER_GRAB + bw);
                region = QRegion(r1) + r2;
            }
            break;

        case Menu: {
                if (hasSysMenu) {
                    region = QRect(rect.left(), rect.top() - titleHeight,
                                   menu_width, titleHeight);
                }
            }
            break;

        case Help: {
                if (hasContextHelp) {
                    QRect r(rect.right()
                            - close_width
                            - (hasMaximize ? maximize_width : 0)
                            - (hasMinimize ? minimize_width : 0)
                            - help_width + 1, rect.top() - titleHeight,
                            help_width, titleHeight);
                    if (r.left() > rect.left() + titleHeight)
                        region = r;
                }
            }
            break;


        case Minimize: {
                if (hasMinimize && !isMinimized) {
                    QRect r(rect.right() - close_width
                            - (hasMaximize ? maximize_width : 0)
                            - minimize_width + 1, rect.top() - titleHeight,
                            minimize_width, titleHeight);
                    if (r.left() > rect.left() + titleHeight)
                        region = r;
                }
            }
            break;

        case Maximize: {
                if (hasMaximize && !isMaximized) {
                    QRect r(rect.right() - close_width - maximize_width + 1,
                            rect.top() - titleHeight, maximize_width, titleHeight);
                    if (r.left() > rect.left() + titleHeight)
                        region = r;
                }
            }
            break;

        case Normalize: {
                if (hasMinimize && isMinimized) {
                    QRect r(rect.right() - close_width
                            - (hasMaximize ? maximize_width : 0)
                            - minimize_width + 1, rect.top() - titleHeight,
                            minimize_width, titleHeight);
                    if (r.left() > rect.left() + titleHeight)
                        region = r;
                } else if (hasMaximize && isMaximized) {
                    QRect r(rect.right() - close_width - maximize_width + 1,
                            rect.top() - titleHeight, maximize_width, titleHeight);
                    if (r.left() > rect.left() + titleHeight)
                        region = r;
                }
            }
            break;

        case Close: {
                QRect r(rect.right() - close_width + 1, rect.top() - titleHeight,
                        close_width, titleHeight);
                if (r.left() > rect.left() + titleHeight)
                    region = r;
            }
            break;

    default: {
        int i = 1;
        while (i) {
            if (i & decorationRegion)
                region += this->region(widget, rect, i);
            i <<= 1;
        }
    }
            break;
    }

    return region;
}
static inline QRect shrinkRectToSquare(const QRect& rect)
{
    const int side = qMin(rect.height(), rect.width());
    return QRect(rect.topLeft(), QSize(side, side));
}
Beispiel #11
0
void ContainerAreaLayout::insertIntoFreeSpace(QWidget* widget, QPoint insertionPoint)
{
    if (!widget)
    {
        return;
    }

    add(widget);
    ContainerAreaLayoutItem* item = m_items.last();

    if (!item)
    {
        // this should never happen as we just added the item above
        // but we do this to be safe.
        return;
    }

    ItemList::iterator currentIt = m_items.begin();
    if (currentIt == m_items.end())
    {
        // this shouldn't happen either, but again... we try and be safe
        return;
    }

    ItemList::iterator nextIt = m_items.begin();
    ++nextIt;

    if (nextIt == m_items.end())
    {
        // first item in!
        item->setGeometryR(QRect(insertionPoint.x(), insertionPoint.y(), widget->width(), widget->height()));
        updateFreeSpaceValues();
        return;
    }

    int insPos = (orientation() == Horizontal) ? insertionPoint.x(): insertionPoint.y();
    Item* current = *currentIt;
    Item* next = *nextIt;

    for (; nextIt != m_items.end(); ++currentIt, ++nextIt)
    {
        next = *nextIt;
        current = *currentIt;
        if (current == item || next == item)
        {
            continue;
        }

        if (insPos == 0)
        {
            if (current->rightR() + 3 < next->leftR())
            {
                insPos = current->rightR();
                break;
            }
        }
        else
        {
            if (currentIt == m_items.begin() &&
                (current->leftR() > insPos ||
                 (current->leftR() <= insPos) &&
                 (current->rightR() > insPos)))
            {
                break;
            }

            if ((current->rightR() < insPos) && (next->leftR() > insPos))
            {
                // Free space available at insertion point!
                if (insPos + item->widthR() > next->leftR())
                {
                    // We have overlap on the right, move to the left
                    insPos = next->leftR() - item->widthR();
                    if (insPos < current->rightR())
                    {
                        // We have overlap on the left as well, move to the right
                        insPos = current->rightR();
                        // We don't fit entirely, let updateFreeSpaceValues sort it out
                    }
                }
                current = next;
                break;
            }

            if ((next->leftR() <= insPos) && (next->rightR() > insPos))
            {
                // Insert at the location of next
                current = next;
                insPos = next->leftR();
                break;
            }
        }
    }

    QRect geom = item->geometryR();
    geom.moveLeft(insPos);
    item->setGeometryR(geom);
    widget->setGeometry(transform(geom)); // widget isn't shown, layout not active yet

    if (current)
    {
        m_items.erase(m_items.fromLast());
        ItemList::iterator insertIt = m_items.find(current);

        if (insertIt == m_items.begin())
        {
            m_items.push_front(item);
        }
        else if (insertIt == m_items.end())
        {
            // yes, we just removed it from the end, but
            // if we remove it afterwards and it insertIt
            // was our item then we end up with a bad iterator
            m_items.append(item);
        }
        else
        {
            m_items.insert(insertIt, item);
        }
    }

    updateFreeSpaceValues();
}
Beispiel #12
0
void CodeEditor::resizeEvent(QResizeEvent *e) {
    QPlainTextEdit::resizeEvent(e);

    QRect cr = contentsRect();
    lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
Beispiel #13
0
int FlowLayout::heightForWidth(int width) const
{
    int height = doLayout(QRect(0, 0, width, 0), true);
    return height;
}
void CGadgetListBar::QuickCloseBar(void)
{
	setGeometry(QRect(FRAME_START_X, FRAME_START_Y, FRAME_WIDTH, FRAME_HEIGHT));
}
void googleweatherWidget::drawSet(QPainter *p)
{
    QString current,humidity,temp,wind,image,curr_date;
    current = weatherValues.at(0);
    humidity = weatherValues.at(1);
    temp = weatherValues.at(2);
    wind = weatherValues.at(3);
    curr_date = weatherValues.at(25);
    QStringList f_day,f_condition,f_lTemp,f_hTemp,f_image;

    f_day<<weatherValues.at(4)<<weatherValues.at(5)<<weatherValues.at(6)<<weatherValues.at(7);
    f_condition<<weatherValues.at(8)<<weatherValues.at(9)<<weatherValues.at(10)<<weatherValues.at(11);
    f_lTemp<<weatherValues.at(12)<<weatherValues.at(13)<<weatherValues.at(14)<<weatherValues.at(15);
    f_hTemp<<weatherValues.at(16)<<weatherValues.at(17)<<weatherValues.at(18)<<weatherValues.at(19);
    f_image<<weatherValues.at(21)<<weatherValues.at(22)<<weatherValues.at(23)<<weatherValues.at(24);
    image = weatherValues.at(20);


    p->setPen(QColor(255,255,255,255));
    p->setFont(QFont("SansSerif", 15, QFont::Bold));
    p->drawLine(clip.x()+w_ImageDock.width()+57,view.y()+45,clip.x()+w_ImageDock.width()+251,view.y()+45);
    p->drawText(clip.x()+w_ImageDock.width()+60, view.y()+40, "Google Weather");
    p->setPen(QColor(0,255,255,127));
    p->setFont(QFont("SansSerif", 10, QFont::Normal));
    if (current != "Data not recieved")
    {
        p->drawText(clip.x()+10, view.y()+65, "City: Colombo");
        p->setPen(QColor(200,255,100,127));

        //------------current conditions --------------
        QFont tempFont = QFont("OldEnglish", 14, QFont::DemiBold);
        tempFont.setStyleStrategy(QFont::OpenGLCompatible);
        p->setFont(tempFont);
        p->drawText(clip.x()+20, view.y()+155,current);
        p->setFont(QFont("SansSerif", 10, QFont::Normal));
        p->setPen(QColor(58,136,253));
        p->drawText(clip.x()+250, view.y()+90,"Today : " + curr_date);
        p->drawText(clip.x()+250, view.y()+130, humidity);
        p->drawText(clip.x()+250, view.y()+145,wind);
        tempInCel(p,temp,10,120,true,35);
        p->drawImage(QRect(clip.x()+140,view.y()+55,100,100),QImage(prefix+image+".png"));
        //-----------end of current conditions-----------

        //////////////// forecst information //////////////////////

        p->setFont(QFont("SansSerif", 10, QFont::Normal));
        p->setPen(QColor(50,50,50));
        p->drawLine(clip.x()+5,view.y()+175,clip.x()+402,view.y()+175);
        p->drawLine(clip.x()+140,view.y()+175,clip.x()+140,view.y()+270);
        p->drawLine(clip.x()+270,view.y()+175,clip.x()+270,view.y()+270);
        for (int i=1;i<4;i++)
        {
            p->setPen(QColor(0,234,255));
            p->drawText(clip.x()+15+(i-1)*130, view.y()+190, getDay(f_day.at(i)));
            p->setPen(QColor(56,193,124));
            p->drawText(clip.x()+15+(i-1)*130, view.y()+267,f_condition.at(i));
            p->setFont(QFont("SansSerif", 6, QFont::Normal));
            p->drawText(clip.x()+15+(i-1)*130,view.y()+280,"Lowest");            
            tempInCel(p,f_lTemp.at(i),15+(i-1)*130,300,false,12);
            p->setFont(QFont("SansSerif", 6, QFont::Normal));
            p->setPen(QColor(56,193,124));
            p->drawText(clip.x()+70+(i-1)*130,view.y()+280,"Highest");            
            tempInCel(p,f_hTemp.at(i),70+(i-1)*130,300,false,10);
            p->drawImage(QRect(clip.x()+20+(i-1)*130,view.y()+200,50,50),QImage(prefix+f_image.at(i)+".png"));
        }

        ///////////////// forecast information ///////////////////////
    }
    else
    {
        p->setPen(QColor(255,18,18,127));
        p->drawText(clip.x()+40,view.y()+85, "--Error----");
        p->setPen(QColor(24,200,198,127));
        p->drawText(clip.x()+40,view.y()+100, "Check network connection.");
        p->drawText(clip.x()+40,view.y()+115, "could not establish connection with google.");
        p->drawText(clip.x()+40,view.y()+130, "If problem persist, contact plexydesk dev team.");
        p->drawText(clip.x()+40,view.y()+145, "Online help available in IRC channel #plexydesk .");
        p->setPen(QColor(255,18,18,127));
        p->drawText(clip.x()+40,view.y()+160, "----------");

    }


}
QRect QITreeViewItem::rect() const
{
    /* Redirect call to parent-tree: */
    return parentTree() ? parentTree()->visualRect(modelIndex()) : QRect();
}
Beispiel #17
0
// Resets hover animation on mouse enter
void FancyTabBar::enterEvent(QEvent *e)
{
    Q_UNUSED(e)
    m_hoverRect = QRect();
    m_hoverIndex = -1;
}
Beispiel #18
0
Board::Board(QWidget *parent) :
    QGraphicsView(parent)
{
    scene = new QGraphicsScene(QRect(0, 0, 640, 360), this);

    scene->setBackgroundBrush(QBrush(bg));

    ball = scene->addRect(-6, -6, 12, 12, QPen(Qt::SolidLine), QBrush(fg));
    ball->setPos(Width/2-6, Height/2-6);

    // why is y -1...otherwise we have a gap...
    topWall = scene->addRect(0, -1, Width, 12, QPen(Qt::SolidLine), QBrush(fg));
    bottomWall = scene->addRect(0, Height-12, Width, 12, QPen(Qt::SolidLine), QBrush(fg));

    leftPaddle = scene->addRect(0, 12, 12, Paddle, QPen(Qt::SolidLine), QBrush(fg));
    rightPaddle = scene->addRect(Width-12, 12, 12, Paddle, QPen(Qt::SolidLine), QBrush(fg));

    QPen p;
    p.setWidth(2);
    p.setStyle(Qt::DotLine);
    p.setBrush(QBrush(fg));
    scene->addLine(Width/2, 0, Width/2, Height, p);

    QFont f;
    f.setStyleHint(QFont::OldEnglish);
    f.setPixelSize(50);
    f.setBold(true);
    leftScore = scene->addText(QString("0"), f);
    leftScore->setDefaultTextColor(fg);
//    leftScore->setPos(120, 50);

    rightScore = scene->addText(QString("0"), f);
//    rightScore->setPos(Width-140, 50);
    rightScore->setDefaultTextColor(fg);
    setScore(0, 0);

    f.setPixelSize(25);
    status = scene->addText(QString(), f);
    status->setDefaultTextColor(fg);

    ball->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    leftPaddle->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    rightPaddle->setCacheMode(QGraphicsItem::DeviceCoordinateCache);

    icon.load(QString(":/icons/connect.png"));
    icon = icon.scaled(100, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    qDebug() << "icon" << icon.isNull();
    connectIcon = scene->addPixmap(icon);
    connectIcon->setPos(440,200);
    connectIcon->setAcceptTouchEvents(true);
    connectIcon->setTransformOriginPoint(50,50);
    connectIcon->setTransformationMode(Qt::SmoothTransformation);

    connectAnimation = new QPropertyAnimation(this, "connectRotation");
    connectAnimation->setDuration(1000);
    connectAnimation->setLoopCount(-1);
    connectAnimation->setStartValue(0);
    connectAnimation->setEndValue(360);

    setCacheMode(QGraphicsView::CacheBackground);
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

//    connect(scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>)));

}
void SelectionView::keyPressEvent( QKeyEvent *e )
{
	if (_selectionFinished == true)
	{
		switch (e->key())
		{
		case Qt::Key_Space:
			{
				e->accept();
				emit cutoutSelectedRectangle();
				break;
			}

		case Qt::Key_Up:
			{
				_pCenterRubberBand->hide();
				_pRubberBand->hide();
				_pExpandingRubberBand->hide();
				e->accept();
				_originPoint.ry() = _originPoint.y()-1;
				_terminalPoint.ry() = _terminalPoint.y()-1;

				if (_isFromCenter)
				{

					QPoint center;
					center.rx() = _originPoint.x() + (_terminalPoint.x()-_originPoint.x())*0.5;
					center.ry() = _originPoint.y() + (_terminalPoint.y()-_originPoint.y())*0.5;

					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;

					//add
					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;
					
					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());

					//_pExpandingRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

					_pCenterRubberBand->setGeometry(QRect(center-QPoint(3,3), center+QPoint(3,3)).normalized());
					_pCenterRubberBand->show();

				}

				else
				{
					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

	/*				expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;*/

					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

				}

				emit rubberBandOnSelection();

				break;	

			}
		case Qt::Key_Down:
			{
				_pCenterRubberBand->hide();
				_pRubberBand->hide();
				_pExpandingRubberBand->hide();

				e->accept();
				//printf("Down!");


				_originPoint.ry() = _originPoint.y()+1;
				_terminalPoint.ry() = _terminalPoint.y()+1;

				if (_isFromCenter)
				{

					QPoint center;
					center.rx() = _originPoint.x() + (_terminalPoint.x()-_originPoint.x())*0.5;
					center.ry() = _originPoint.y() + (_terminalPoint.y()-_originPoint.y())*0.5;

					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;

					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());

					//_pExpandingRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

					_pCenterRubberBand->setGeometry(QRect(center-QPoint(3,3), center+QPoint(3,3)).normalized());
					_pCenterRubberBand->show();

				}

				else
				{
					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

				}

				emit rubberBandOnSelection();

				break;	
			}
		case Qt::Key_Left:
			{
				_pCenterRubberBand->hide();
				_pRubberBand->hide();
				_pExpandingRubberBand->hide();

				e->accept();
				//printf("Left!");


				_originPoint.rx() = _originPoint.x()-1;
				_terminalPoint.rx() = _terminalPoint.x()-1;

				if (_isFromCenter)
				{

					QPoint center;
					center.rx() = _originPoint.x() + (_terminalPoint.x()-_originPoint.x())*0.5;
					center.ry() = _originPoint.y() + (_terminalPoint.y()-_originPoint.y())*0.5;

					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;
					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());

					//_pExpandingRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

					_pCenterRubberBand->setGeometry(QRect(center-QPoint(3,3), center+QPoint(3,3)).normalized());
					_pCenterRubberBand->show();

				}

				else
				{
					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;

					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

				}

				emit rubberBandOnSelection();

				break;	
			}
		case Qt::Key_Right:
			{
				_pCenterRubberBand->hide();
				_pRubberBand->hide();
				_pExpandingRubberBand->hide();

				e->accept();
				//printf("Left!");


				_originPoint.rx() = _originPoint.x()+1;
				_terminalPoint.rx() = _terminalPoint.x()+1;

				if (_isFromCenter)
				{

					QPoint center;
					center.rx() = _originPoint.x() + (_terminalPoint.x()-_originPoint.x())*0.5;
					center.ry() = _originPoint.y() + (_terminalPoint.y()-_originPoint.y())*0.5;

					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;

					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());

					//_pExpandingRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

					_pCenterRubberBand->setGeometry(QRect(center-QPoint(3,3), center+QPoint(3,3)).normalized());
					_pCenterRubberBand->show();

				}

				else
				{
					//add
					QPoint expandingTopLeft;
					QPoint expandingTerminalPoint;

					int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
					int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

					//expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
					//expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
					//expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
					//expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;

					if ((_originPoint.x()-_terminalPoint.x())*(_originPoint.y()-_terminalPoint.y())<0)
					{
						int y;
						y = _originPoint.y();
						_originPoint.ry() = _terminalPoint.y();
						_terminalPoint.ry() = y;

					}

					if (_originPoint.x()<_terminalPoint.x())
					{
						expandingTopLeft.rx() = _originPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _originPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _terminalPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _terminalPoint.y()+expandingHeight;
					}

					else
					{
						expandingTopLeft.rx() = _terminalPoint.x()-expandingWidth;
						expandingTopLeft.ry() = _terminalPoint.y()-expandingHeight;
						expandingTerminalPoint.rx() = _originPoint.x()+expandingWidth;
						expandingTerminalPoint.ry() = _originPoint.y()+expandingHeight;
					}

					_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingTerminalPoint).normalized());
					_pExpandingRubberBand->show();

					_pRubberBand->setGeometry(QRect(_originPoint, _terminalPoint).normalized());
					_pRubberBand->show();

				}

				emit rubberBandOnSelection();

				break;	
			}
		default:
			{
				e->ignore();
				return;
			}
 
		}

	}

}
Beispiel #20
0
Magazine::Magazine(QWindow *parent, Base *base)
{
    if (parent == NULL)
    {
        qDebug() << "Error. parent == NULL.";
        exit(-1);
    }
    _parent = parent;
    if (base == NULL)
    {
        qDebug() << "Error. base == NULL.";
        exit(-1);
    }
    _base = base;
    _credits = QRect(10, 5, _parent->geometry().width()/2-10, 25);
    _gold = QRect(_parent->geometry().width()/2+10, 5, _parent->geometry().width()/2-20, 25);
    _one = QRect(10, 10+30, _parent->geometry().width()/2-10, _parent->geometry().height()/2-10-50);
    _capt_one = QRect(10, 10+30, _parent->geometry().width()/2-10, 30);
    _two = QRect(10, _parent->geometry().height()/2+10-50+30, _parent->geometry().width()/2-10, _parent->geometry().height()/2+10-50-30);
    _capt_two = QRect(10, _parent->geometry().height()/2+10-50+30, _parent->geometry().width()/2-10, 30);
    _three = QRect(_parent->geometry().width()/2+10, 10+30, _parent->geometry().width()/2-20, _parent->geometry().height()/2-10-50);
    _capt_three = QRect(_parent->geometry().width()/2+10, 10+30, _parent->geometry().width()/2-20, 30);
    _four = QRect(_parent->geometry().width()/2+10, _parent->geometry().height()/2+10-50+30, _parent->geometry().width()/2-20, _parent->geometry().height()/2+10-50-30);
    _capt_four = QRect(_parent->geometry().width()/2+10, _parent->geometry().height()/2+10-50+30, _parent->geometry().width()/2-20, 30);
    _prev = QRect(10, _parent->geometry().height()-20-50, _parent->geometry().width()/3-10, 60);
    _next = QRect(_parent->geometry().width()/3+10, _parent->geometry().height()-20-50, _parent->geometry().width()/3-20, 60);
    _back = QRect(_parent->geometry().width()/3*2, _parent->geometry().height()-20-50, _parent->geometry().width()/3-10, 60);
    _state = 0;
    _credits_num = "0";
    _gold_num = "0";
}
void SelectionView::mouseMoveEvent( QMouseEvent *e )
{
    if ( _drawLine && _drawLineHold ) {
        cur = e->posF();
        linePath->lineTo( e->posF() );
        qDebug() << "mid: " << e->posF();
        return;
    }

	QPoint topLeft;
	QPoint pointTemp;

	if ( _snapRatio == -1.0 )
		return;

	if (_pRubberBand)
	{
		if (_isFromCenter)
		{
			//*! free ratio
			if (_snapRatio == 0.0)
			{
				pointTemp = e ->pos();
			}
			
			//*!  a ratio is given
			if (_snapRatio != 0.0 && _snapRatio != -1.0 )
			{
				//!* keep the x coordinate the same as the current point while mouse is moving
				//!* make the perpendicular coordinate adjust to the ratio.
				pointTemp.rx() = e->pos().x();
				pointTemp.ry() = _originPoint.y() + (e->pos().x() - _originPoint.x()) * (_snapRatio);
			}
			
			topLeft = _originPoint + _originPoint - pointTemp;
		}
		//!* from the TopLeft
		else
		{
			//!* free ratio
			if (_snapRatio == 0.0)
			{

				topLeft = _originPoint;
				pointTemp = e->pos();
			}
			
			//!* specified ratio
			if (_snapRatio != 0.0 && _snapRatio != -1.0)
			{
				pointTemp.rx() = e->pos().x();
				pointTemp.ry() = _originPoint.y() + (e->pos().x() - _originPoint.x()) * _snapRatio;
				topLeft = _originPoint;
			}
		}


		//!* from center
		if (_isFromCenter)
		{
			_pCenterRubberBand->show();
			_pCenterRubberBand->setGeometry(QRect(_originPoint-QPoint(3,3), _originPoint+QPoint(3,3)).normalized());
		}
		else
			_pCenterRubberBand->hide();

		_pRubberBand->setGeometry(QRect(topLeft, pointTemp).normalized());

		//add
		QPoint expandingTopLeft;
		QPoint expandingpointTemp;

		int expandingWidth  = int(_pRubberBand->width()*(_expandingWidthRatio-1)*0.5)+_expandingWidth*_zoomRatio;
		int expandingHeight = int(_pRubberBand->height()*(_expandingHeightRatio-1)*0.5)+_expandingHeight*_zoomRatio;

		_terminalPoint = pointTemp;

		//add
		if ((topLeft.x()-pointTemp.x())*(topLeft.y()-pointTemp.y())<0)
		{
			int y;
			y = topLeft.y();
			topLeft.ry() = pointTemp.y();
			pointTemp.ry() = y;
		}

		if (topLeft.x()<pointTemp.x())
		{
			expandingTopLeft.rx() = topLeft.x()-expandingWidth;
			expandingTopLeft.ry() = topLeft.y()-expandingHeight;
			expandingpointTemp.rx() = pointTemp.x()+expandingWidth;
			expandingpointTemp.ry() = pointTemp.y()+expandingHeight;
		}

		else
		{
			expandingTopLeft.rx() = pointTemp.x()-expandingWidth;
			expandingTopLeft.ry() = pointTemp.y()-expandingHeight;
			expandingpointTemp.rx() = topLeft.x()+expandingWidth;
			expandingpointTemp.ry() = topLeft.y()+expandingHeight;
		}

		_pExpandingRubberBand->setGeometry(QRect(expandingTopLeft, expandingpointTemp).normalized());
	}

	emit rubberBandOnSelection();
}
Beispiel #22
0
void
QueryLabel::mouseMoveEvent( QMouseEvent* event )
{
    QFrame::mouseMoveEvent( event );
    int x = event->x();

    if ( event->buttons() & Qt::LeftButton &&
       ( m_dragPos - event->pos() ).manhattanLength() >= QApplication::startDragDistance() )
    {
        startDrag();
        leaveEvent( 0 );
        return;
    }

    if ( m_query.isNull() && m_result.isNull() )
    {
        m_hoverArea = QRect();
        m_hoverType = None;
        return;
    }

    QFontMetrics fm = fontMetrics();
    if ( m_useCustomFont )
        fm = QFontMetrics( m_font );

    int dashX = fm.width( DASH );
    int artistX = m_type & Artist ? fm.width( artist() ) : 0;
    int albumX = m_type & Album ? fm.width( album() ) : 0;
    int trackX = m_type & Track ? fm.width( track() ) : 0;

    if ( m_type & Track )
    {
        trackX += contentsMargins().left();
    }
    if ( m_type & Album )
    {
        trackX += albumX + dashX;
        albumX += contentsMargins().left();
    }
    if ( m_type & Artist )
    {
        albumX += artistX + dashX;
        trackX += artistX + dashX;
        artistX += contentsMargins().left();
    }

    QRect hoverArea;
    m_hoverType = None;
    if ( m_type & Artist && x < artistX )
    {
        m_hoverType = Artist;
        hoverArea.setLeft( 0 );
        hoverArea.setRight( artistX + contentsMargins().left() - 1 );
    }
    else if ( m_type & Album && x < albumX && x > artistX )
    {
        m_hoverType = Album;
        int spacing = ( m_type & Artist ) ? dashX : 0;
        hoverArea.setLeft( artistX + spacing );
        hoverArea.setRight( albumX + spacing + contentsMargins().left() - 1 );
    }
    else if ( m_type & Track && x < trackX && x > albumX )
    {
        m_hoverType = Track;
        int spacing = ( m_type & Album ) ? dashX : 0;
        hoverArea.setLeft( albumX + spacing );
        hoverArea.setRight( trackX + contentsMargins().left() - 1 );
    }

    if ( hoverArea.width() )
    {
        hoverArea.setY( 1 );
        hoverArea.setHeight( height() - 2 );
    }
    if ( hoverArea != m_hoverArea )
    {
        m_hoverArea = hoverArea;
        repaint();
    }
}
Beispiel #23
0
void
GcLabel::paintEvent(QPaintEvent *)
{
    static QIcon left = iconFromPNG(":images/mac/left.png");
    static QIcon right = iconFromPNG(":images/mac/right.png");

    QPainter painter(this);
    painter.save();
    painter.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing, true);

    // grr. some want a rect others want a rectf
    QRectF norm(0,0,width(),height());
    QRect all(0,0,width(),height());

    if (bg) {

        // setup a painter and the area to paint
        if (!underMouse()) {
            painter.fillRect(all, bgColor);
        } else {
            if (filtered) painter.fillRect(all, GColor(CCALCURRENT));
            else painter.fillRect(all, Qt::lightGray);
        }

        painter.setPen(Qt::gray);
        painter.drawRect(QRect(0,0,width(),height()));
    }

    if (selected) {
        painter.fillRect(all, GColor(CCALCURRENT));
    }

    if (text() != "<" && text() != ">") {
        painter.setFont(this->font());

        if (!GCColor::isFlat() && (xoff || yoff)) {

            // draw text in white behind...
            QRectF off(xoff,yoff,width(),height());
            painter.setPen(QColor(255,255,255,200));
            painter.drawText(off, alignment(), text());
        }

        if (filtered && !selected && !underMouse()) painter.setPen(GColor(CCALCURRENT));
        else {

            if (isChrome && GCColor::isFlat()) {

                if (GCColor::luminance(GColor(CCHROME)) < 127)
                    painter.setPen(QColor(Qt::white));
                else
                    painter.setPen(QColor(30,30,30,200));

            } else painter.setPen(palette().color(QPalette::WindowText));
        }

        painter.drawText(norm, alignment(), text());

        if (highlighted) {
            QColor over = GColor(CCALCURRENT);
            over.setAlpha(180);
            painter.setPen(over);

            painter.drawText(norm, alignment(), text());
        }

    } else {

        // use standard icons
        QIcon &icon = text() == "<" ?  left : right;
        Qt::AlignmentFlag alignment = text() == "<" ? Qt::AlignLeft : Qt::AlignRight;

        icon.paint(&painter, all, alignment|Qt::AlignVCenter);
    }

    if (text() != ""  && filtered) {
        QPen pen;
        pen.setColor(GColor(CCALCURRENT));
        pen.setWidth(3);
        painter.setPen(pen);
        painter.drawRect(QRect(0,0,width(),height()));
    }
    painter.restore();
}
Beispiel #24
0
void DBThread::TriggerMapRendering()
{
  RenderMapRequest request;
  {
    QMutexLocker locker(&mutex);

    request=currentRenderRequest;
    if (!doRender) {
      return;
    }

    doRender=false;

    renderBreaker->Reset();
  }

  if (currentImage==NULL ||
      currentImage->width()!=(int)request.width ||
      currentImage->height()!=(int)request.height) {
    delete currentImage;

    currentImage=new QImage(QSize(request.width,request.height),QImage::Format_RGB32);
  }

  currentLon=request.lon;
  currentLat=request.lat;
  currentAngle=request.angle;
  currentMagnification=request.magnification;

  if (database->IsOpen() &&
      styleConfig) {
/*
  if (database->IsOpen() && styleConfig) {
    osmscout::MercatorProjection  projection;
*/
    osmscout::MapParameter        drawParameter;
    osmscout::AreaSearchParameter searchParameter;

    searchParameter.SetBreaker(renderBreakerRef);
    searchParameter.SetMaximumAreaLevel(4);
    searchParameter.SetUseMultithreading(currentMagnification.GetMagnification()<=osmscout::Magnification::magCity);

    std::list<std::string>        paths;

    paths.push_back(iconDirectory.toLocal8Bit().data());

    drawParameter.SetIconPaths(paths);
    drawParameter.SetPatternPaths(paths);
    drawParameter.SetDebugPerformance(true);
    drawParameter.SetOptimizeWayNodes(osmscout::TransPolygon::quality);
    drawParameter.SetOptimizeAreaNodes(osmscout::TransPolygon::quality);
    drawParameter.SetRenderSeaLand(true);
    drawParameter.SetBreaker(renderBreakerRef);

    std::cout << std::endl;

    osmscout::StopClock overallTimer;

    projection.Set(currentLon,
                   currentLat,
                   currentAngle,
                   currentMagnification,
                   dpi,
                   request.width,
                   request.height);

    osmscout::StopClock dataRetrievalTimer;

    mapService->GetObjects(searchParameter,
                           *styleConfig,
                           projection,
                           data);

    if (drawParameter.GetRenderSeaLand()) {
      mapService->GetGroundTiles(projection,
                                 data.groundTiles);
    }

    dataRetrievalTimer.Stop();

    osmscout::StopClock drawTimer;

    QPainter p;

    p.begin(currentImage);
    p.setRenderHint(QPainter::Antialiasing);
    p.setRenderHint(QPainter::TextAntialiasing);
    p.setRenderHint(QPainter::SmoothPixmapTransform);

    painter->DrawMap(projection,
                     drawParameter,
                     data,
                     &p);

    p.end();

    drawTimer.Stop();
    overallTimer.Stop();

    std::cout << "All: " << overallTimer << " Data: " << dataRetrievalTimer << " Draw: " << drawTimer << std::endl;
  }
  else {
    std::cout << "Cannot draw map: " << database->IsOpen() << " " << styleConfig << std::endl;

    QPainter p;

    p.begin(currentImage);
    p.setRenderHint(QPainter::Antialiasing);
    p.setRenderHint(QPainter::TextAntialiasing);
    p.setRenderHint(QPainter::SmoothPixmapTransform);

    p.fillRect(0,0,request.width,request.height,
               QColor::fromRgbF(0.0,0.0,0.0,1.0));

    p.setPen(QColor::fromRgbF(1.0,1.0,1.0,1.0));

    QString text("not initialized (yet)");

    p.drawText(QRect(0,0,request.width,request.height),
               Qt::AlignCenter|Qt::AlignVCenter,
               text,
               NULL);

    p.end();
  }

  QMutexLocker locker(&mutex);

  if (renderBreaker->IsAborted()) {
    return;
  }

  std::swap(currentImage,finishedImage);
  std::swap(currentLon,finishedLon);
  std::swap(currentLat,finishedLat);
  std::swap(currentAngle,finishedAngle);
  std::swap(currentMagnification,finishedMagnification);

  emit HandleMapRenderingResult();
}
Beispiel #25
0
void SampleTCOView::paintEvent( QPaintEvent * pe )
{
	QPainter painter( this );

	if( !needsUpdate() )
	{
		painter.drawPixmap( 0, 0, m_paintPixmap );
		return;
	}

	setNeedsUpdate( false );

	if (m_paintPixmap.isNull() || m_paintPixmap.size() != size())
	{
		m_paintPixmap = QPixmap(size());
	}

	QPainter p( &m_paintPixmap );

	QLinearGradient lingrad( 0, 0, 0, height() );
	QColor c;
	bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();

	// state: selected, muted, normal
	c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
		: painter.background().color() );

	lingrad.setColorAt( 1, c.darker( 300 ) );
	lingrad.setColorAt( 0, c );

	// paint a black rectangle under the pattern to prevent glitches with transparent backgrounds
	p.fillRect( rect(), QColor( 0, 0, 0 ) );

	if( gradient() )
	{
		p.fillRect( rect(), lingrad );
	}
	else
	{
		p.fillRect( rect(), c );
	}

	p.setPen( !muted ? painter.pen().brush().color() : mutedColor() );

	const int spacing = TCO_BORDER_WIDTH + 1;
	const float ppt = fixedTCOs() ?
			( parentWidget()->width() - 2 * TCO_BORDER_WIDTH )
					/ (float) m_tco->length().getTact() :
								pixelsPerTact();

	float nom = Engine::getSong()->getTimeSigModel().getNumerator();
	float den = Engine::getSong()->getTimeSigModel().getDenominator();
	float ticksPerTact = DefaultTicksPerTact * nom / den;
	
	float offset =  m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact();
	QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing,
			qMax( static_cast<int>( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing );
	m_tco->m_sampleBuffer->visualize( p, r, pe->rect() );

	QFileInfo fileInfo(m_tco->m_sampleBuffer->audioFile());
	QString filename = fileInfo.fileName();
	paintTextLabel(filename, p);

	// disable antialiasing for borders, since its not needed
	p.setRenderHint( QPainter::Antialiasing, false );

	// inner border
	p.setPen( c.lighter( 160 ) );
	p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH,
		rect().bottom() - TCO_BORDER_WIDTH );

	// outer border
	p.setPen( c.darker( 300 ) );
	p.drawRect( 0, 0, rect().right(), rect().bottom() );

	// draw the 'muted' pixmap only if the pattern was manualy muted
	if( m_tco->isMuted() )
	{
		const int spacing = TCO_BORDER_WIDTH;
		const int size = 14;
		p.drawPixmap( spacing, height() - ( size + spacing ),
			embed::getIconPixmap( "muted", size, size ) );
	}

	// recording sample tracks is not possible at the moment

	/* if( m_tco->isRecord() )
	{
		p.setFont( pointSize<7>( p.font() ) );

		p.setPen( textShadowColor() );
		p.drawText( 10, p.fontMetrics().height()+1, "Rec" );
		p.setPen( textColor() );
		p.drawText( 9, p.fontMetrics().height(), "Rec" );

		p.setBrush( QBrush( textColor() ) );
		p.drawEllipse( 4, 5, 4, 4 );
	}*/

	p.end();

	painter.drawPixmap( 0, 0, m_paintPixmap );
}
bool CameraView::connectToCamera(bool dropFrameIfBufferFull, int capThreadPrio, int procThreadPrio, bool enableFrameProcessing, int width, int height)
{
    // Set frame label text
    if (m_sharedImageBuffer->isSyncEnabledForDeviceNumber(m_deviceNumber))
    {
        ui->frameLabel->setText(tr("Camera connected. Waiting..."));
    }
    else
    {
        ui->frameLabel->setText(tr("Connecting to camera..."));
    }

    // Create capture thread
    m_captureThread = new CaptureThread(m_sharedImageBuffer, m_deviceNumber, dropFrameIfBufferFull, width, height);
    // Attempt to connect to camera
    if (m_captureThread->connectToCamera())
    {
        // Create processing thread
        m_processingThread = new ProcessingThread(m_sharedImageBuffer, m_deviceNumber);
        // Create image processing settings dialog
        m_imageProcessingSettingsDialog = new ImageProcessingSettingsDialog(this);
        // Setup signal/slot connections
        connect(m_processingThread, &ProcessingThread::newFrame, this, &CameraView::updateFrame);
        connect(m_processingThread, &ProcessingThread::updateStatisticsInGUI, this, &CameraView::updateProcessingThreadStats);
        connect(m_captureThread, &CaptureThread::updateStatisticsInGUI, this, &CameraView::updateCaptureThreadStats);
        connect(m_imageProcessingSettingsDialog, &ImageProcessingSettingsDialog::newImageProcessingSettings, m_processingThread, &ProcessingThread::updateImageProcessingSettings);
        connect(this, &CameraView::newImageProcessingFlags, m_processingThread, &ProcessingThread::updateImageProcessingFlags);
        connect(this, &CameraView::setROI, m_processingThread, &ProcessingThread::setROI);
        // Only enable ROI setting/resetting if frame processing is enabled
        if(enableFrameProcessing)
        {
            connect(ui->frameLabel, &FrameLabel::newMouseData, this, &CameraView::newMouseData);
        }
        // Set initial data in processing thread
        emit setROI(QRect(0, 0, m_captureThread->getInputSourceWidth(), m_captureThread->getInputSourceHeight()));
        emit newImageProcessingFlags(m_imageProcessingFlags);
        m_imageProcessingSettingsDialog->updateStoredSettingsFromDialog();

        // Start capturing frames from camera
        m_captureThread->start((QThread::Priority)capThreadPrio);
        // Start processing captured frames (if enabled)
        if(enableFrameProcessing)
        {
            m_processingThread->start((QThread::Priority)procThreadPrio);
        }

        // Setup imageBufferBar with minimum and maximum values
        ui->imageBufferBar->setMinimum(0);
        ui->imageBufferBar->setMaximum(m_sharedImageBuffer->getByDeviceNumber(m_deviceNumber)->maxSize());
        // Enable "Clear Image Buffer" push button
        ui->clearImageBufferButton->setEnabled(true);
        // Set text in labels
        ui->deviceNumberLabel->setNum(m_deviceNumber);
        ui->cameraResolutionLabel->setText(QString::number(m_captureThread->getInputSourceWidth()) + QString("x") + QString::number(m_captureThread->getInputSourceHeight()));
        // Set internal flag and return
        m_isCameraConnected = true;
        // Set frame label text
        if(!enableFrameProcessing)
        {
            ui->frameLabel->setText(tr("Frame processing disabled."));
        }
        return true;
    }
    // Failed to connect to camera
    else
        return false;
}
Beispiel #27
0
void tst_QItemDelegate::doLayout_data()
{
    QTest::addColumn<int>("position");
    QTest::addColumn<int>("direction");
    QTest::addColumn<bool>("hint");
    QTest::addColumn<QRect>("itemRect");
    QTest::addColumn<QRect>("checkRect");
    QTest::addColumn<QRect>("pixmapRect");
    QTest::addColumn<QRect>("textRect");
    QTest::addColumn<QRect>("expectedCheckRect");
    QTest::addColumn<QRect>("expectedPixmapRect");
    QTest::addColumn<QRect>("expectedTextRect");

    int m = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
    //int item = 400;
    //int check = 50;
    //int pixmap = 1000;
    //int text = 400;

    QTest::newRow("top, left to right, hint")
        << (int)QStyleOptionViewItem::Top
        << (int)Qt::LeftToRight
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(m, 0, 50 + 2*m, 1000)
        << QRect(50 + 2*m, 0, 1000 + 2*m, 1000 + m)
        << QRect(50 + 2*m, 1000 + m, 1000 + 2*m, 400);
    /*
    QTest::newRow("top, left to right, limited")
        << (int)QStyleOptionViewItem::Top
        << (int)Qt::LeftToRight
        << false
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(m, (400/2) - (50/2), 50, 50)
        << QRect(50 + 2*m, 0, 1000, 1000)
        << QRect(50 + 2*m, 1000 + m, 400 - (50 + 2*m), 400 - 1000 - m);
    */
    QTest::newRow("top, right to left, hint")
        << (int)QStyleOptionViewItem::Top
        << (int)Qt::RightToLeft
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(1000 + 2 * m, 0, 50 + 2 * m, 1000)
        << QRect(0, 0, 1000 + 2 * m, 1000 + m)
        << QRect(0, 1000 + m, 1000 + 2 * m, 400);

    QTest::newRow("bottom, left to right, hint")
        << (int)QStyleOptionViewItem::Bottom
        << (int)Qt::LeftToRight
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(m, 0, 50 + 2 * m, 1000)
        << QRect(50 + 2 * m, 400 + m, 1000 + 2 * m, 1000)
        << QRect(50 + 2 * m, 0, 1000 + 2 * m, 400 + m);

    QTest::newRow("bottom, right to left, hint")
        << (int)QStyleOptionViewItem::Bottom
        << (int)Qt::RightToLeft
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(1000 + 2 * m, 0, 50 + 2 * m, 1000)
        << QRect(0, 400 + m, 1000 + 2 * m, 1000)
        << QRect(0, 0, 1000 + 2 * m, 400 + m);

    QTest::newRow("left, left to right, hint")
        << (int)QStyleOptionViewItem::Left
        << (int)Qt::LeftToRight
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(m, 0, 50 + 2 * m, 1000)
        << QRect(50 + 2 * m, 0, 1000 + 2 * m, 1000)
        << QRect(1050 + 4 * m, 0, 400 + 2 * m, 1000);

    QTest::newRow("left, right to left, hint")
        << (int)QStyleOptionViewItem::Left
        << (int)Qt::RightToLeft
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(1400 + 4 * m, 0, 50 + 2 * m, 1000)
        << QRect(400 + 2 * m, 0, 1000 + 2 * m, 1000)
        << QRect(0, 0, 400 + 2 * m, 1000);

    QTest::newRow("right, left to right, hint")
        << (int)QStyleOptionViewItem::Right
        << (int)Qt::LeftToRight
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(m, 0, 50 + 2 * m, 1000)
        << QRect(450 + 4 * m, 0, 1000 + 2 * m, 1000)
        << QRect(50 + 2 * m, 0, 400 + 2 * m, 1000);

    QTest::newRow("right, right to left, hint")
        << (int)QStyleOptionViewItem::Right
        << (int)Qt::RightToLeft
        << true
        << QRect(0, 0, 400, 400)
        << QRect(0, 0, 50, 50)
        << QRect(0, 0, 1000, 1000)
        << QRect(0, 0, 400, 400)
        << QRect(1400 + 4 * m, 0, 50 + 2 * m, 1000)
        << QRect(0, 0, 1000 + 2 * m, 1000)
        << QRect(1000 + 2 * m, 0, 400 + 2 * m, 1000);
}
void PlastikClient::paintEvent(QPaintEvent *e)
{
    QRegion region = e->region();

    PlastikHandler *handler = Handler();

    if (oldCaption != caption() )
        clearCaptionPixmaps();

    bool active = isActive();
    bool toolWindow = isToolWindow();

    QPainter painter(widget() );

    // often needed coordinates
    QRect r = widget()->rect();

    int r_w = r.width();
//     int r_h = r.height();
    int r_x, r_y, r_x2, r_y2;
    r.getCoords(&r_x, &r_y, &r_x2, &r_y2);
    const int borderLeft = layoutMetric(LM_BorderLeft);
    const int borderRight = layoutMetric(LM_BorderRight);
    const int borderBottom = layoutMetric(LM_BorderBottom);
    const int titleHeight = layoutMetric(LM_TitleHeight);
    const int titleEdgeTop = layoutMetric(LM_TitleEdgeTop);
    const int titleEdgeBottom = layoutMetric(LM_TitleEdgeBottom);
    const int titleEdgeLeft = layoutMetric(LM_TitleEdgeLeft);
    const int titleEdgeRight = layoutMetric(LM_TitleEdgeRight);

    const int borderBottomTop = r_y2-borderBottom+1;
    const int borderLeftRight = r_x+borderLeft-1;
    const int borderRightLeft = r_x2-borderRight+1;
    const int titleEdgeBottomBottom = r_y+titleEdgeTop+titleHeight+titleEdgeBottom-1;

    const int sideHeight = borderBottomTop-titleEdgeBottomBottom-1;

    QRect Rtitle = QRect(r_x+titleEdgeLeft+buttonsLeftWidth(), r_y+titleEdgeTop,
                         r_x2-titleEdgeRight-buttonsRightWidth()-(r_x+titleEdgeLeft+buttonsLeftWidth()),
                         titleEdgeBottomBottom-(r_y+titleEdgeTop) );

    QRect tempRect;

    // topSpacer
    if(titleEdgeTop > 0)
    {
        tempRect.setRect(r_x+2, r_y, r_w-2*2, titleEdgeTop );
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTileTop, active, toolWindow) );
        }
    }

    // leftTitleSpacer
    int titleMarginLeft = 0;
    int titleMarginRight = 0;
    if(titleEdgeLeft > 0)
    {
        tempRect.setRect(r_x, r_y, borderLeft, titleEdgeTop+titleHeight+titleEdgeBottom);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarLeft, active, toolWindow) );
            titleMarginLeft = borderLeft;
        }
    }

    // rightTitleSpacer
    if(titleEdgeRight > 0)
    {
        tempRect.setRect(borderRightLeft, r_y, borderRight, titleEdgeTop+titleHeight+titleEdgeBottom);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarRight, active, toolWindow) );
            titleMarginRight = borderRight;
        }
    }

    // titleSpacer
    const QPixmap &caption = captionPixmap();
    if(Rtitle.width() > 0)
    {
        m_captionRect = captionRect(); // also update m_captionRect!
        if (m_captionRect.isValid() && region.contains(m_captionRect) )
        {
            painter.drawTiledPixmap(m_captionRect, caption);
        }

        // left to the title
        tempRect.setRect(r_x+titleMarginLeft, m_captionRect.top(),
                         m_captionRect.left() - (r_x+titleMarginLeft), m_captionRect.height() );
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTile, active, toolWindow) );
        }

        // right to the title
        tempRect.setRect(m_captionRect.right()+1, m_captionRect.top(),
                         (r_x2-titleMarginRight) - m_captionRect.right(), m_captionRect.height() );
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, TitleBarTile, active, toolWindow) );
        }

    }

    // leftSpacer
    if(borderLeft > 0 && sideHeight > 0)
    {
        tempRect.setCoords(r_x, titleEdgeBottomBottom+1, borderLeftRight, borderBottomTop-1);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderLeftTile, active, toolWindow) );
        }
    }

    // rightSpacer
    if(borderRight > 0 && sideHeight > 0)
    {
        tempRect.setCoords(borderRightLeft, titleEdgeBottomBottom+1, r_x2, borderBottomTop-1);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderRightTile, active, toolWindow) );
        }
    }

    // bottomSpacer
    if(borderBottom > 0)
    {
        int l = r_x;
        int r = r_x2;

        tempRect.setRect(r_x, borderBottomTop, borderLeft, borderBottom);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomLeft, active, toolWindow) );
            l = tempRect.right()+1;
        }

        tempRect.setRect(borderRightLeft, borderBottomTop, borderLeft, borderBottom);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomRight, active, toolWindow) );
            r = tempRect.left()-1;
        }

        tempRect.setCoords(l, borderBottomTop, r, r_y2);
        if (tempRect.isValid() && region.contains(tempRect) ) {
            painter.drawTiledPixmap(tempRect, handler->pixmap(qubes_label, BorderBottomTile, active, toolWindow) );
        }
    }
}
Beispiel #29
0
void ImagePortOverlay::paintContent(QPainter& p)
{
    mMutex.lock();

    if (mLastValue.isValid()) {
        cv::Mat mat = port::Image::fromVariant(mLastValue);
        if(mat.data == 0) {
            DepthMap dm = port::DepthMap::fromVariant(mLastValue);
            if(dm.data != 0)
                mat = dm.toImage();
        }

        if (mat.size().width != 0 && mat.size().height != 0) {
            // Color conversion
            if (mat.type() == CV_8UC1 || mat.type() == CV_16UC1) {
                cv::cvtColor(mat, mConverted, CV_GRAY2BGRA);
            } else if (mat.type() == CV_8UC3 || mat.type() == CV_16UC3) {
                cv::cvtColor(mat, mConverted, CV_BGR2BGRA);
            } else if(mat.type() == CV_8UC4 || mat.type() == CV_16UC4) {
                mConverted = mat;
            } else {
                qCritical() << tr("VideoDisplayWidget: unknown image format received") << mat.type();
            }

            // Bit width conversion (if required)
            // We can only display 8Bit images
            if(mConverted.depth() == CV_16U){
                // Use a scale factor to bring 0 -> 65535 to 0 -> 255
                // otherwise convertTo will only chop of the highest bits
                mConverted.convertTo(mConverted, CV_8U, 1/255.0);
            }

            // Convert to QImage
            QImage::Format format = QImage::Format_ARGB32;
            QImage image = QImage(mConverted.data, mConverted.size().width, mConverted.size().height, mConverted.step, format);
            mPixmap = QPixmap::fromImage(image);
            mLastValue = QVariant();

            // Set ascpect ratio
            QSize imageSize = mPixmap.size();
            if (mState == Scaling){
                mScale = mRect.width() / (double) imageSize.width();
            } else {
                mRect.setSize(imageSize * mScale);
            }
        } else {
            qWarning() << tr("VideoDisplay: image without dimensions received");
        }
    }
    mMutex.unlock();

    QRect rect = (mRect.isEmpty() ? QRect(0, 0, 640, 480) : mRect);
    mPen.setColor(Qt::black);
    p.setPen(mPen);
    if (mPixmap.isNull()){
        p.setBrush(Qt::black);
    }
    p.drawRect(rect);
    if (!mPixmap.isNull()) {
        p.drawPixmap(rect, mPixmap);
    }
}
Beispiel #30
0
void QDesktopWidgetPrivate::init(QDesktopWidget *that)
{
    if (rects)
        return;

    rects = new QVector<QRect>();
    workrects = new QVector<QRect>();
    screenCount = 0;

#ifndef Q_OS_WINCE
    QSystemLibrary user32Lib(QLatin1String("user32"));
    enumDisplayMonitors = (EnumFunc)user32Lib.resolve("EnumDisplayMonitors");
    getMonitorInfo = (InfoFunc)user32Lib.resolve("GetMonitorInfoW");

    if (!enumDisplayMonitors || !getMonitorInfo) {
        screenCount = GetSystemMetrics(80);  // SM_CMONITORS
        rects->resize(screenCount);
        for (int i = 0; i < screenCount; ++i)
            rects->replace(i, that->rect());
        return;
    }
    // Calls enumCallback
    enumDisplayMonitors(0, 0, enumCallback, 0);
    enumDisplayMonitors = 0;
    getMonitorInfo = 0;
#else
    QSystemLibrary coreLib(QLatin1String("coredll"));
    // CE >= 4.0 case
    enumDisplayMonitors = (EnumFunc)coreLib.resolve("EnumDisplayMonitors");
    getMonitorInfo = (InfoFunc)coreLib.resolve("GetMonitorInfo");

    if ((!enumDisplayMonitors || !getMonitorInfo)) {
        screenCount = GetSystemMetrics(SM_CMONITORS);
        return;
    }

    if (!coreLib.isLoaded() || !enumDisplayMonitors || !getMonitorInfo) {
        rects->resize(screenCount);
        for (int i = 0; i < screenCount; ++i)
            (*rects)[i] = that->rect();

        RECT r;
        SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
        QRect qr = QRect(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));

#if defined(Q_WS_WINCE_WM)
        qt_get_sip_info(qr);
#endif

        workrects->resize(screenCount);
        for (int j = 0; j < screenCount; ++j)
            (*workrects)[j] = qr;
        return;
    }

    // Calls enumCallback
    enumDisplayMonitors(0, 0, enumCallback, 0);
    enumDisplayMonitors = 0;
    getMonitorInfo = 0;
#endif // Q_WS_WINCE
}